Debian Codegraph @

src/dr/evomodel/alloppnet/parsers/AlloppSpeciesNetworkModelParser.java

raw symbols SCIP
1 /*
2 * AlloppSpeciesNetworkModelParser.java
3 *
4 * Copyright (c) 2002-2017 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evomodel.alloppnet.parsers;
27
28
29 import dr.evomodel.alloppnet.speciation.AlloppSpeciesBindings;
30 import dr.evomodel.alloppnet.speciation.AlloppSpeciesNetworkModel;
31 import dr.inference.model.Parameter;
32 import dr.inference.model.ParameterParser;
33 import dr.util.Attributable;
34 import dr.xml.*;
35
36
37 /**
38 *
39 * Parses a AlloppSpeciesNetworkModel.
40 *
41 * @author Graham Jones
42 * Date: 19/04/2011
43 */
44
45
46
47 /*
48 *
49 * Parses a MulLabSpeciesTreeModel which might look like this.
50 *
51 <alloppSpeciesNetwork id="apspnetwork" oneHybridization="true">
52 <alloppSpecies idref="alloppSpecies"/>
53 <sppSplitPopulations value="0.018">
54 <parameter id="apspnetwork.splitPopSize"/>
55 </sppSplitPopulations>
56 <preRootHeights>
57 <parameter id="pre.root.heights"/>
58 </preRootHeights>
59 </alloppSpeciesNetwork>
60 *
61 */
62
63
64 /*
65 * 2011-07-07 decided to remove preRootHeights, and therefore these bits of code.
66 * (instead, incorporate into AlloppNetworkNodeSlide)
67 *
68 *
69 * public static final String PRE_ROOT_HEIGHTS = "preRootHeights";
70 *
71 *
72 * final XMLObject prhxo = xo.getChild(PRE_ROOT_HEIGHTS);
73 *
74 *
75 * ParameterParser.replaceParameter(prhxo, asnm.prHeights);
76 * final Parameter.DefaultBounds prhbounds =
77 * new Parameter.DefaultBounds(Double.MAX_VALUE, 0, asnm.prHeights.getDimension());
78 * asnm.prHeights.addBounds(prhbounds);
79 *
80 * private ElementRule prhElementRule() {
81 * return new ElementRule(PRE_ROOT_HEIGHTS, new XMLSyntaxRule[]{
82 * new ElementRule(Parameter.class)});
83 * }
84 *
85 * also code in AlloppSpeciesNetworkModel
86 *
87 */
88
89
90
91 public class AlloppSpeciesNetworkModelParser extends AbstractXMLObjectParser {
92 public static final String ALLOPPSPECIESNETWORK = "alloppSpeciesNetwork";
93 public static final String ONEHYBRIDIZATION = "oneHybridization";
94 public static final String DIPLOIDROOT_ISROOT = "diploidRootIsRoot";
95 public static final String TIP_POPULATIONS = "tipPopulations";
96 public static final String ROOT_POPULATIONS = "rootPopulations";
97 public static final String HYBRID_POPULATIONS = "hybridPopulations";
98
99
100
101
102 public String getParserName() {
103 return ALLOPPSPECIESNETWORK;
104 }
105
106 @Override
107 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
108 AlloppSpeciesBindings apspb = (AlloppSpeciesBindings) xo.getChild(AlloppSpeciesBindings.class);
109 boolean onehyb = xo.getBooleanAttribute(ONEHYBRIDIZATION);
110 boolean diprootisroot = xo.getBooleanAttribute(DIPLOIDROOT_ISROOT);
111
112 final XMLObject tippopxo = xo.getChild(TIP_POPULATIONS);
113 final double tippopvalue = tippopxo.getAttribute(Attributable.VALUE, 1.0);
114 final XMLObject rootpopxo = xo.getChild(ROOT_POPULATIONS);
115 final double rootpopvalue = rootpopxo.getAttribute(Attributable.VALUE, 1.0);
116 final XMLObject hybpopxo = xo.getChild(HYBRID_POPULATIONS);
117 final double hybpopvalue = hybpopxo.getAttribute(Attributable.VALUE, 1.0);
118
119 AlloppSpeciesNetworkModel asnm = new AlloppSpeciesNetworkModel(apspb,
120 tippopvalue, rootpopvalue, hybpopvalue, onehyb, diprootisroot);
121 // don't know dimensionality until network created, so replace parameters
122 ParameterParser.replaceParameter(tippopxo, asnm.tippopvalues);
123 final Parameter.DefaultBounds tippopbounds =
124 new Parameter.DefaultBounds(Double.MAX_VALUE, 0, asnm.tippopvalues.getDimension());
125 asnm.tippopvalues.addBounds(tippopbounds);
126
127 ParameterParser.replaceParameter(rootpopxo, asnm.rootpopvalues);
128 final Parameter.DefaultBounds rootpopbounds =
129 new Parameter.DefaultBounds(Double.MAX_VALUE, 0, asnm.rootpopvalues.getDimension());
130 asnm.rootpopvalues.addBounds(rootpopbounds);
131
132 ParameterParser.replaceParameter(hybpopxo, asnm.logginghybpopvalues);
133 final Parameter.DefaultBounds hybpopbounds =
134 new Parameter.DefaultBounds(Double.MAX_VALUE, 0, asnm.logginghybpopvalues.getDimension());
135 asnm.logginghybpopvalues.addBounds(hybpopbounds);
136 // note hybpopvalues are different and only work for logging.
137 return asnm;
138 }
139
140
141 private ElementRule tippopElementRule() {
142 return new ElementRule(TIP_POPULATIONS, new XMLSyntaxRule[]{
143 AttributeRule.newDoubleRule(Attributable.VALUE, true),
144 new ElementRule(Parameter.class)});
145 }
146
147 private ElementRule rootpopElementRule() {
148 return new ElementRule(ROOT_POPULATIONS, new XMLSyntaxRule[]{
149 AttributeRule.newDoubleRule(Attributable.VALUE, true),
150 new ElementRule(Parameter.class)});
151 }
152 private ElementRule hybpopElementRule() {
153 return new ElementRule(HYBRID_POPULATIONS, new XMLSyntaxRule[]{
154 AttributeRule.newDoubleRule(Attributable.VALUE, true),
155 new ElementRule(Parameter.class)});
156 }
157
158
159
160 @Override
161 public XMLSyntaxRule[] getSyntaxRules() {
162 return new XMLSyntaxRule[]{
163 AttributeRule.newBooleanRule(ONEHYBRIDIZATION, true),
164 AttributeRule.newBooleanRule(DIPLOIDROOT_ISROOT, true),
165 new ElementRule(AlloppSpeciesBindings.class),
166 tippopElementRule(),
167 rootpopElementRule(),
168 hybpopElementRule()
169 };
170 }
171
172 @Override
173 public String getParserDescription() {
174 return "Species network with population sizes along branches";
175 }
176
177 @Override
178 public Class getReturnType() {
179 return AlloppSpeciesNetworkModel.class;
180 }
181
182 }