Debian Codegraph @

src/dr/evomodelxml/speciation/BirthDeathEpidemiologyModelParser.java

raw symbols SCIP
1 /*
2 * BirthDeathEpidemiologyModelParser.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.speciation;
27
28 import dr.evolution.util.Units;
29 import dr.evomodel.speciation.BirthDeathSerialSamplingModel;
30 import dr.evoxml.util.XMLUnits;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 import java.util.logging.Logger;
35
36 /**
37 * @author Andrew Rambaut
38 * @author Tanja Stadler
39 * @author Alexei Drummond
40 * @author Joseph Heled
41 */
42 public class BirthDeathEpidemiologyModelParser extends AbstractXMLObjectParser {
43
44 public static final String BIRTH_DEATH_EPIDEMIOLOGY = "birthDeathEpidemiology";
45 public static final String R0 = "R0";
46 public static final String RECOVERY_RATE = "recoveryRate";
47 public static final String SAMPLING_PROBABILITY = "samplingProbability";
48 public static final String ORIGIN = BirthDeathSerialSamplingModelParser.ORIGIN;
49
50 public String getParserName() {
51 return BIRTH_DEATH_EPIDEMIOLOGY;
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55
56 final String modelName = xo.getId();
57 final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
58
59 final Parameter R0Parameter = (Parameter) xo.getElementFirstChild(R0);
60 final Parameter recoveryRateParameter = (Parameter) xo.getElementFirstChild(RECOVERY_RATE);
61 final Parameter samplingProbabiltyParameter = (Parameter) xo.getElementFirstChild(SAMPLING_PROBABILITY);
62
63 Parameter origin = null;
64 if (xo.hasChildNamed(ORIGIN)) {
65 origin = (Parameter) xo.getElementFirstChild(ORIGIN);
66 }
67
68 Logger.getLogger("dr.evomodel").info("Using epidemiological parameterization of " + getCitationRT());
69
70 return new BirthDeathSerialSamplingModel(modelName, R0Parameter, recoveryRateParameter, samplingProbabiltyParameter, origin, units);
71 }
72
73 //************************************************************************
74 // AbstractXMLObjectParser implementation
75 //************************************************************************
76
77 public static String getCitationPsiOrg() {
78 // return "Stadler, T; Sampling-through-time in birth-death trees; JOURNAL OF THEORETICAL BIOLOGY (2010) 267:396-404";
79 return "Stadler T (2010) J Theor Biol 267, 396-404 [Birth-Death with Serial Samples].";
80 }
81
82 public static String getCitationRT() {
83 return "Stadler et al (2011) : Estimating the basic reproductive number from viral sequence data, " +
84 "Mol.Biol.Evol., doi: 10.1093/molbev/msr217, 2011";
85 }
86
87 public String getParserDescription() {
88 return "Stadler et al (2011) model of epidemiology.";
89 }
90
91 public Class getReturnType() {
92 return BirthDeathSerialSamplingModel.class;
93 }
94
95 public XMLSyntaxRule[] getSyntaxRules() {
96 return rules;
97 }
98
99 private final XMLSyntaxRule[] rules = {
100 new ElementRule(ORIGIN, Parameter.class, "The origin of the infection, x0 > tree.rootHeight", true),
101 new ElementRule(R0, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
102 new ElementRule(RECOVERY_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
103 new ElementRule(SAMPLING_PROBABILITY, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
104 XMLUnits.SYNTAX_RULES[0]
105 };
106 }