Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * AlloppNetworkPriorModelParser.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 import dr.evolution.util.Units;
29 import dr.evomodel.alloppnet.speciation.AlloppNetworkPriorModel;
30 import dr.evoxml.util.XMLUnits;
31 import dr.inference.model.Parameter;
32 import dr.inference.distribution.ParametricDistributionModel;
33 import dr.xml.AbstractXMLObjectParser;
34 import dr.xml.ElementRule;
35 import dr.xml.XMLObject;
36 import dr.xml.XMLParseException;
37 import dr.xml.XMLSyntaxRule;
38
39
40 /**
41 *
42 * @author Graham Jones
43 * Date: 01/07/2011
44 */
45
46 /*
47 <alloppNetworkPriorModel id="network.prior.model" units="substitutions" >
48 <eventRate>
49 <parameter id="apspnetwork.prior.eventRate" value="100" lower="0" upper="Infinity" />
50 </eventRate>
51 <populationScalingFactor>
52 <parameter id="population.scaling.factor" value="0.2" lower="0" upper="Infinity" />
53 </populationScalingFactor>
54 <tipPopulationDistribution>
55 <gammaDistributionModel>
56 <shape>
57 4
58 </shape>
59 <scale>
60 <parameter idref="population.scaling.factor" />
61 </scale>
62 </gammaDistributionModel>
63 </tipPopulationDistribution>
64 <rootPopulationDistribution>
65 <gammaDistributionModel>
66 <shape>
67 2
68 </shape>
69 <scale>
70 <parameter idref="population.scaling.factor" />
71 </scale>
72 </gammaDistributionModel>
73 </rootPopulationDistribution>
74 <hybridPopulationDistribution>
75 <gammaDistributionModel>
76 <shape>
77 1
78 </shape>
79 <scale>
80 <parameter idref="population.scaling.factor" />
81 </scale>
82 </gammaDistributionModel>
83 </hybridPopulationDistribution>
84 </alloppNetworkPriorModel>
85 */
86 public class AlloppNetworkPriorModelParser extends AbstractXMLObjectParser {
87
88 public static final String ALLOPPNETWORKPRIORMODEL = "alloppNetworkPriorModel";
89 public static final String EVENTRATE = "eventRate";
90 public static final String POPULATION_SCALING_FACTOR = "populationScalingFactor";
91 public static final String TIP_POPULATION_DISTRIBUTION = "tipPopulationDistribution";
92 public static final String ROOT_POPULATION_DISTRIBUTION = "rootPopulationDistribution";
93 public static final String HYBRID_POPULATION_DISTRIBUTION = "hybridPopulationDistribution";
94
95
96 public String getParserName() {
97 return ALLOPPNETWORKPRIORMODEL;
98 }
99
100
101
102 @Override
103 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
104 final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
105 final XMLObject erXo = xo.getChild(EVENTRATE);
106 final Parameter eventrate = (Parameter) erXo.getChild(Parameter.class);
107 final XMLObject psfXo = xo.getChild(POPULATION_SCALING_FACTOR);
108 final Parameter popscalingfactor = (Parameter) psfXo.getChild(Parameter.class);
109 final XMLObject tpdXo = xo.getChild(TIP_POPULATION_DISTRIBUTION);
110 ParametricDistributionModel tippopmodel = (ParametricDistributionModel) tpdXo.getChild(ParametricDistributionModel.class);
111 final XMLObject rpdXo = xo.getChild(ROOT_POPULATION_DISTRIBUTION);
112 ParametricDistributionModel rootpopmodel = (ParametricDistributionModel) rpdXo.getChild(ParametricDistributionModel.class);
113 final XMLObject hpdXo = xo.getChild(HYBRID_POPULATION_DISTRIBUTION);
114 ParametricDistributionModel hybpopmodel = (ParametricDistributionModel) hpdXo.getChild(ParametricDistributionModel.class);
115 return new AlloppNetworkPriorModel(eventrate, popscalingfactor, tippopmodel, rootpopmodel, hybpopmodel, units);
116 }
117
118
119
120 private XMLSyntaxRule[] eventrateRules() {
121 return new XMLSyntaxRule[]{
122 new ElementRule(Parameter.class)
123 };
124 }
125
126
127 private XMLSyntaxRule[] popscalingfactorRules() {
128 return new XMLSyntaxRule[]{
129 new ElementRule(Parameter.class)
130 };
131 }
132
133
134 private XMLSyntaxRule[] tippopmodelRules() {
135 return new XMLSyntaxRule[]{
136 new ElementRule(ParametricDistributionModel.class)
137 };
138 }
139
140
141
142 private XMLSyntaxRule[] rootpopmodelRules() {
143 return new XMLSyntaxRule[]{
144 new ElementRule(ParametricDistributionModel.class)
145 };
146 }
147
148
149 private XMLSyntaxRule[] hybpopmodelRules() {
150 return new XMLSyntaxRule[]{
151 new ElementRule(ParametricDistributionModel.class)
152 };
153 }
154
155
156 @Override
157 public XMLSyntaxRule[] getSyntaxRules() {
158 return new XMLSyntaxRule[]{
159 XMLUnits.SYNTAX_RULES[0],
160 new ElementRule(EVENTRATE, eventrateRules()),
161 new ElementRule(POPULATION_SCALING_FACTOR, popscalingfactorRules()),
162 new ElementRule(TIP_POPULATION_DISTRIBUTION, tippopmodelRules()),
163 new ElementRule(ROOT_POPULATION_DISTRIBUTION, rootpopmodelRules()),
164 new ElementRule(HYBRID_POPULATION_DISTRIBUTION, hybpopmodelRules())
165 };
166 }
167
168 @Override
169 public String getParserDescription() {
170 return "Model for speciation, extinction, hybridization in allopolyploid network.";
171 }
172
173 @Override
174 public Class getReturnType() {
175 return AlloppNetworkPriorModel.class;
176 }
177
178 }