Debian Codegraph @

src/dr/evomodel/epidemiology/LogisticGrowthN0ModelParser.java

raw symbols SCIP
1 /*
2 * LogisticGrowthN0ModelParser.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.evomodel.epidemiology;
27
28 import dr.evolution.util.Units;
29 import dr.evoxml.util.XMLUnits;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32
33 /**
34 * Parses an element from an XMLObject into LogisticGrowthN0Model.
35 * @author Daniel Wilson
36 */
37 public class LogisticGrowthN0ModelParser extends AbstractXMLObjectParser
38 {
39
40 public static String POPULATION_SIZE = "populationSize";
41 public static String LOGISTIC_GROWTH_MODEL = "logisticGrowthN0";
42
43 public static String GROWTH_RATE = "growthRate";
44 public static String DOUBLING_TIME = "doublingTime";
45 public static String TIME_50 = "t50";
46
47 public String getParserName() { return LOGISTIC_GROWTH_MODEL; }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50 Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
51
52 XMLObject cxo = (XMLObject)xo.getChild(POPULATION_SIZE);
53 Parameter N0Param = (Parameter)cxo.getChild(Parameter.class);
54
55 boolean usingGrowthRate = true;
56 Parameter rParam = null;
57 if (xo.getChild(GROWTH_RATE) != null) {
58 cxo = (XMLObject)xo.getChild(GROWTH_RATE);
59 rParam = (Parameter)cxo.getChild(Parameter.class);
60 } else {
61 cxo = (XMLObject)xo.getChild(DOUBLING_TIME);
62 rParam = (Parameter)cxo.getChild(Parameter.class);
63 usingGrowthRate = false;
64 }
65
66 cxo = (XMLObject)xo.getChild(TIME_50);
67 Parameter t50Param = (Parameter)cxo.getChild(Parameter.class);
68
69 return new LogisticGrowthN0Model(N0Param, rParam, t50Param, units, usingGrowthRate);
70 }
71
72 //************************************************************************
73 // AbstractXMLObjectParser implementation
74 //************************************************************************
75
76 public String getParserDescription() {
77 return "Logistic growth demographic model.";
78 }
79
80 public Class getReturnType() { return LogisticGrowthN0Model.class; }
81
82 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
83
84 private XMLSyntaxRule[] rules = new XMLSyntaxRule[] {
85 XMLUnits.SYNTAX_RULES[0],
86 new ElementRule(POPULATION_SIZE,
87 new XMLSyntaxRule[] { new ElementRule(Parameter.class) },
88 "This parameter represents the present day population size."),
89 new XORRule(
90 new ElementRule(GROWTH_RATE,
91 new XMLSyntaxRule[] { new ElementRule(Parameter.class) },
92 "This parameter determines the rate of growth during the exponential phase. " +
93 "See exponentialGrowth for details."),
94 new ElementRule(DOUBLING_TIME,
95 new XMLSyntaxRule[] { new ElementRule(Parameter.class) },
96 "This parameter determines the doubling time at peak growth rate.")
97 ),
98 new ElementRule(TIME_50,
99 new XMLSyntaxRule[] { new ElementRule(Parameter.class) },
100 "This parameter represents the time in the past (or future) when the population had (or will have) " +
101 "half of the carrying capacity (maximum population size). " +
102 "It is a positive number if half the carrying capacity was attained in the past " +
103 "or a negative number if it will be attained in the future.")
104 };
105 }