Debian Codegraph @

src/dr/evomodelxml/coalescent/ConstExpConstModelParser.java

raw symbols SCIP
1 /*
2 * ConstExpConstModelParser.java
3 *
4 * Copyright (c) 2002-2015 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.evomodelxml.coalescent;
27
28 import dr.evolution.util.Units;
29 import dr.evomodel.coalescent.ConstExpConstModel;
30 import dr.evomodel.coalescent.ConstantExponentialModel;
31 import dr.evoxml.util.XMLUnits;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 /**
36 * Parses an element from an DOM document into a ConstantExponentialModel.
37 *
38 * There are 2 parameterization depending on whether a growth rate parameter
39 * or an ancestral population size parameter are specified.
40 */
41 public class ConstExpConstModelParser extends AbstractXMLObjectParser {
42
43 public static String CONST_EXP_CONST_MODEL = "constExpConst";
44 public static String POPULATION_SIZE = "populationSize";
45 public static String GROWTH_RATE = "growthRate";
46 public static String ANCESTRAL_POPULATION_SIZE = "ancestralPopulationSize";
47 public static String FINAL_PHASE_START_TIME = "finalPhaseStartTime";
48 public static String GROWTH_PHASE_TIME = "growthPhaseTime";
49 public static String USE_NUMERICAL_INTEGRATION = "useNumericalIntegration";
50
51 public String getParserName() {
52 return CONST_EXP_CONST_MODEL;
53 }
54
55 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
56
57 Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
58
59 XMLObject cxo = xo.getChild(POPULATION_SIZE);
60 Parameter N0Param = (Parameter) cxo.getChild(Parameter.class);
61
62 Parameter N1Param = null;
63 Parameter growthRateParam = null;
64
65 if (xo.hasChildNamed(ANCESTRAL_POPULATION_SIZE)) {
66 cxo = xo.getChild(ANCESTRAL_POPULATION_SIZE);
67 N1Param = (Parameter) cxo.getChild(Parameter.class);
68 } else {
69 cxo = xo.getChild(GROWTH_RATE);
70 growthRateParam = (Parameter) cxo.getChild(Parameter.class);
71 }
72
73 cxo = xo.getChild(FINAL_PHASE_START_TIME);
74 Parameter timeParam = (Parameter) cxo.getChild(Parameter.class);
75
76 cxo = xo.getChild(GROWTH_PHASE_TIME);
77 Parameter epochParam = (Parameter) cxo.getChild(Parameter.class);
78
79 boolean useNumericalIntegrator = false;
80 if (xo.hasAttribute(USE_NUMERICAL_INTEGRATION)) {
81 useNumericalIntegrator = xo.getBooleanAttribute(USE_NUMERICAL_INTEGRATION);
82 }
83
84 return new ConstExpConstModel(N0Param, N1Param, growthRateParam, timeParam, epochParam, useNumericalIntegrator, units);
85 }
86
87 //************************************************************************
88 // AbstractXMLObjectParser implementation
89 //************************************************************************
90
91 public String getParserDescription() {
92 return "A demographic model of constant population size followed by exponential growth.";
93 }
94
95 public Class getReturnType() {
96 return ConstantExponentialModel.class;
97 }
98
99 public XMLSyntaxRule[] getSyntaxRules() {
100 return rules;
101 }
102
103 private final XMLSyntaxRule[] rules = {
104 XMLUnits.SYNTAX_RULES[0],
105 AttributeRule.newBooleanRule(USE_NUMERICAL_INTEGRATION, true),
106 new ElementRule(POPULATION_SIZE,
107 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
108 new XORRule(
109 new ElementRule(ANCESTRAL_POPULATION_SIZE,
110 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
111 new ElementRule(GROWTH_RATE,
112 new XMLSyntaxRule[]{new ElementRule(Parameter.class)})
113 ),
114 new ElementRule(FINAL_PHASE_START_TIME,
115 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
116 new ElementRule(GROWTH_PHASE_TIME,
117 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
118 };
119
120
121 }