Debian Codegraph @

src/dr/evomodelxml/coalescent/EmergingEpidemicModelParser.java

raw symbols SCIP
1 /*
2 * EmergingEpidemicModelParser.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.tree.Tree;
29 import dr.evolution.util.Units;
30 import dr.evomodel.coalescent.EmergingEpidemicModel;
31 import dr.evomodel.coalescent.ExponentialGrowthModel;
32 import dr.evomodel.tree.TreeModel;
33 import dr.evoxml.util.XMLUnits;
34 import dr.inference.model.Parameter;
35 import dr.xml.*;
36
37 /**
38 * Parser for the EmergingEpidemic exponential model.
39 */
40 public class EmergingEpidemicModelParser extends AbstractXMLObjectParser {
41
42 public static String EMERGING_EPIDEMIC_MODEL = "emergingEpidemic";
43
44 // the parameters
45 public static String GROWTH_RATE = "growthRate";
46 public static String GENERATION_TIME = "generationTime";
47 public static String GENERATION_DISTRIBUTION_SHAPE = "generationShape";
48 public static String OFFSPRING_DISPERSION = "offspringDispersion";
49
50 public static String TREE = "epidemicTree";
51
52
53 public String getParserName() {
54 return EMERGING_EPIDEMIC_MODEL;
55 }
56
57 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
58
59 Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
60
61 Parameter growthRateParameter = (Parameter)xo.getElementFirstChild(GROWTH_RATE);
62 Parameter generationTimeParameter = (Parameter)xo.getElementFirstChild(GENERATION_TIME);
63 Parameter generationShapeParameter = (Parameter)xo.getElementFirstChild(GENERATION_DISTRIBUTION_SHAPE);
64 Parameter offspringDispersionParameter = (Parameter)xo.getElementFirstChild(OFFSPRING_DISPERSION);
65 TreeModel tree = (TreeModel)xo.getElementFirstChild(TREE);
66
67 return new EmergingEpidemicModel(growthRateParameter, generationTimeParameter, generationShapeParameter, offspringDispersionParameter, tree, units);
68 }
69
70 //************************************************************************
71 // AbstractXMLObjectParser implementation
72 //************************************************************************
73
74 public String getParserDescription() {
75 return "A self-consistent model of emerging epidemics.";
76 }
77
78 public Class getReturnType() {
79 return EmergingEpidemicModel.class;
80 }
81
82 public XMLSyntaxRule[] getSyntaxRules() {
83 return rules;
84 }
85
86 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
87 new ElementRule(GROWTH_RATE, Parameter.class),
88 new ElementRule(GENERATION_TIME, Parameter.class),
89 new ElementRule(GENERATION_DISTRIBUTION_SHAPE, Parameter.class),
90 new ElementRule(OFFSPRING_DISPERSION, Parameter.class),
91 new ElementRule(TREE, Tree.class),
92
93 XMLUnits.SYNTAX_RULES[0]
94 };
95
96
97 }