Debian Codegraph @

src/dr/evomodelxml/coalescent/ExponentialLogisticModelParser.java

raw symbols SCIP
1 /*
2 * ExponentialLogisticModelParser.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.ConstantLogisticModel;
30 import dr.evomodel.coalescent.ExponentialLogisticModel;
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 ExponentialGrowth.
37 */
38 public class ExponentialLogisticModelParser extends AbstractXMLObjectParser {
39
40 public static final String EXPONENTIAL_LOGISTIC_MODEL = "exponentialLogistic";
41 public static final String POPULATION_SIZE = "populationSize";
42 public static final String TRANSITION_TIME = "transitionTime";
43
44 public static final String LOGISTIC_GROWTH_RATE = "logisticGrowthRate";
45 public static final String LOGISTIC_SHAPE = "logisticShape";
46 public static final String EXPONENTIAL_GROWTH_RATE = "exponentialGrowthRate";
47
48 public static final String ALPHA = "alpha";
49
50 public String getParserName() {
51 return EXPONENTIAL_LOGISTIC_MODEL;
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55
56 Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
57
58 XMLObject cxo = xo.getChild(POPULATION_SIZE);
59 Parameter N0Param = (Parameter) cxo.getChild(Parameter.class);
60
61 cxo = xo.getChild(LOGISTIC_GROWTH_RATE);
62 Parameter logGrowthParam = (Parameter) cxo.getChild(Parameter.class);
63
64 cxo = xo.getChild(LOGISTIC_SHAPE);
65 Parameter shapeParam = (Parameter) cxo.getChild(Parameter.class);
66
67 cxo = xo.getChild(EXPONENTIAL_GROWTH_RATE);
68 Parameter expGrowthParam = (Parameter) cxo.getChild(Parameter.class);
69
70 cxo = xo.getChild(TRANSITION_TIME);
71 Parameter timeParam = (Parameter) cxo.getChild(Parameter.class);
72
73 double alpha = xo.getDoubleAttribute(ALPHA);
74
75 return new ExponentialLogisticModel(N0Param, logGrowthParam, shapeParam, expGrowthParam, timeParam, alpha, units);
76 }
77
78 //************************************************************************
79 // AbstractXMLObjectParser implementation
80 //************************************************************************
81
82 public String getParserDescription() {
83 return "A demographic model of exponential growth followed by logistic growth.";
84 }
85
86 public Class getReturnType() {
87 return ExponentialLogisticModel.class;
88 }
89
90 public XMLSyntaxRule[] getSyntaxRules() {
91 return rules;
92 }
93
94 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
95 XMLUnits.SYNTAX_RULES[0],
96 new ElementRule(POPULATION_SIZE,
97 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
98 new ElementRule(LOGISTIC_GROWTH_RATE,
99 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
100 new ElementRule(LOGISTIC_SHAPE,
101 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
102 new ElementRule(EXPONENTIAL_GROWTH_RATE,
103 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
104 new ElementRule(TRANSITION_TIME,
105 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
106 AttributeRule.newDoubleRule(ALPHA)
107 };
108 }