Debian Codegraph @

src/dr/evomodelxml/speciation/BirthDeathSerialSkylineModelParser.java

raw symbols SCIP
1 /*
2 * BirthDeathSerialSkylineModelParser.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.evomodel.speciation.BirthDeathSerialSkylineModel;
31 import dr.evoxml.util.XMLUnits;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 import java.util.logging.Logger;
36
37 /**
38 * @author Alexei Drummond
39 */
40 public class BirthDeathSerialSkylineModelParser extends AbstractXMLObjectParser {
41
42 public static final String BIRTH_DEATH_SKYLINE_MODEL = "birthDeathSkyline";
43 public static final String TIMES = "times";
44 public static final String LAMBDA = "birthRate";
45 public static final String MU = "deathRate";
46 public static final String RELATIVE_MU = "relativeDeathRate";
47 public static final String PSI = "psi";
48 public static final String SAMPLE_PROBABILITY = "sampleProbability";
49 public static final String SAMPLE_BECOMES_NON_INFECTIOUS = "sampleBecomesNonInfectiousProb";
50 public static final String TIMES_START_FROM_ORIGIN = "timesStartFromOrigin";
51 public static final String R = "r";
52 public static final String ORIGIN = "origin";
53 public static final String TREE_TYPE = "type";
54
55 public String getParserName() {
56 return BIRTH_DEATH_SKYLINE_MODEL;
57 }
58
59 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
60
61 final String modelName = xo.getId();
62 final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
63
64 final Parameter times = (Parameter) xo.getElementFirstChild(TIMES);
65 final Parameter lambda = (Parameter) xo.getElementFirstChild(LAMBDA);
66
67
68 boolean relativeDeath = xo.hasChildNamed(RELATIVE_MU);
69 Parameter mu;
70 if (relativeDeath) {
71 mu = (Parameter) xo.getElementFirstChild(RELATIVE_MU);
72 } else {
73 mu = (Parameter) xo.getElementFirstChild(MU);
74 }
75
76 final Parameter psi = (Parameter) xo.getElementFirstChild(PSI);
77 final Parameter p = (Parameter) xo.getElementFirstChild(SAMPLE_PROBABILITY);
78
79 final boolean timesStartFromOrigin = xo.getAttribute(TIMES_START_FROM_ORIGIN, false);
80
81 Parameter origin = null;
82 if (xo.hasChildNamed(ORIGIN)) {
83 origin = (Parameter) xo.getElementFirstChild(ORIGIN);
84 }
85
86 final Parameter r = xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ?
87 (Parameter) xo.getElementFirstChild(SAMPLE_BECOMES_NON_INFECTIOUS) : new Parameter.Default(0.0);
88 // r.setParameterValueQuietly(0, 1 - r.getParameterValue(0)); // donot use it, otherwise log is changed improperly
89
90 Logger.getLogger("dr.evomodel").info(xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? getCitationRT() : getCitationPsiOrg());
91
92 return new BirthDeathSerialSkylineModel(modelName, times, lambda, mu, psi, p, origin, relativeDeath,
93 false, timesStartFromOrigin, units);
94 }
95
96 //************************************************************************
97 // AbstractXMLObjectParser implementation
98 //************************************************************************
99
100 public static String getCitationPsiOrg() {
101 // return "Stadler, T; Sampling-through-time in birth-death trees; JOURNAL OF THEORETICAL BIOLOGY (2010) 267:396-404";
102 return "Stadler T et al (2011, in prep)";
103 }
104
105 public static String getCitationRT() {
106 return "Stadler T et al (2011, in prep)";
107 }
108
109 public String getParserDescription() {
110 return "Stadler T et al (2011, in prep)";
111 }
112
113 public Class getReturnType() {
114 return BirthDeathSerialSamplingModel.class;
115 }
116
117 public XMLSyntaxRule[] getSyntaxRules() {
118 return rules;
119 }
120
121 private final XMLSyntaxRule[] rules = {
122 AttributeRule.newStringRule(TREE_TYPE, true),
123 AttributeRule.newBooleanRule(TIMES_START_FROM_ORIGIN, false, "if true, then the time vector represents the " +
124 "epoch widths in times starting from the origin and moving tipwards. " +
125 "Note that the birth/death/sampling rate vectors still specify the parameters starting from tips " +
126 "and moving to root."),
127 new ElementRule(ORIGIN, Parameter.class, "The origin of the infection, x0 > tree.rootHeight", true),
128 new ElementRule(TIMES, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
129 new ElementRule(LAMBDA, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
130 new XORRule(
131 new ElementRule(MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
132 new ElementRule(RELATIVE_MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)})),
133 new ElementRule(PSI, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
134 new ElementRule(SAMPLE_BECOMES_NON_INFECTIOUS, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true),
135 new ElementRule(SAMPLE_PROBABILITY, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
136 XMLUnits.SYNTAX_RULES[0]
137 };
138 }