Debian Codegraph @

src/dr/evomodelxml/speciation/BirthDeathSerialSamplingModelParser.java

raw symbols SCIP
1 /*
2 * BirthDeathSerialSamplingModelParser.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 Alexei Drummond
38 * @author Joseph Heled
39 */
40 public class BirthDeathSerialSamplingModelParser extends AbstractXMLObjectParser {
41
42 public static final String BIRTH_DEATH_SERIAL_MODEL = "birthDeathSerialSampling";
43 public static final String LAMBDA = "birthRate";
44 public static final String MU = "deathRate";
45 public static final String RELATIVE_MU = "relativeDeathRate";
46 public static final String PSI = "psi";
47 public static final String SAMPLE_PROBABILITY = "sampleProbability"; // default to fix to 0
48 public static final String SAMPLE_BECOMES_NON_INFECTIOUS = "sampleBecomesNonInfectiousProb";
49 public static final String R = "r";
50 // public static final String FINAL_TIME_INTERVAL = "finalTimeInterval";
51 public static final String ORIGIN = "origin";
52 public static final String TREE_TYPE = "type";
53 public static final String BDSS = "bdss";
54 public static final String HAS_FINAL_SAMPLE = "hasFinalSample";
55
56 public String getParserName() {
57 return BIRTH_DEATH_SERIAL_MODEL;
58 }
59
60 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
61
62 final String modelName = xo.getId();
63 final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
64
65 boolean hasFinalSample = xo.getAttribute(HAS_FINAL_SAMPLE, false);
66
67 final Parameter lambda = (Parameter) xo.getElementFirstChild(LAMBDA);
68
69 boolean relativeDeath = xo.hasChildNamed(RELATIVE_MU);
70 Parameter mu;
71 if (relativeDeath) {
72 mu = (Parameter) xo.getElementFirstChild(RELATIVE_MU);
73 } else {
74 mu = (Parameter) xo.getElementFirstChild(MU);
75 }
76
77 final Parameter psi = (Parameter) xo.getElementFirstChild(PSI);
78 //Issue 656: fix p=0
79 final Parameter p = xo.hasChildNamed(SAMPLE_PROBABILITY) ?
80 (Parameter) xo.getElementFirstChild(SAMPLE_PROBABILITY) : new Parameter.Default(0.0);
81
82 Parameter origin = null;
83 if (xo.hasChildNamed(ORIGIN)) {
84 origin = (Parameter) xo.getElementFirstChild(ORIGIN);
85 }
86
87 final Parameter r = xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ?
88 (Parameter) xo.getElementFirstChild(SAMPLE_BECOMES_NON_INFECTIOUS) : new Parameter.Default(0.0);
89 // r.setParameterValueQuietly(0, 1 - r.getParameterValue(0)); // donot use it, otherwise log is changed improperly
90
91 // final Parameter finalTimeInterval = xo.hasChildNamed(FINAL_TIME_INTERVAL) ?
92 // (Parameter) xo.getElementFirstChild(FINAL_TIME_INTERVAL) : new Parameter.Default(0.0);
93
94 Logger.getLogger("dr.evomodel").info(xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? getCitationRT() : getCitationPsiOrg());
95
96 return new BirthDeathSerialSamplingModel(modelName, lambda, mu, psi, p, relativeDeath,
97 r, hasFinalSample, origin, units);
98 }
99
100 //************************************************************************
101 // AbstractXMLObjectParser implementation
102 //************************************************************************
103
104 public static String getCitationPsiOrg() {
105 // return "Stadler, T; Sampling-through-time in birth-death trees; JOURNAL OF THEORETICAL BIOLOGY (2010) 267:396-404";
106 return "Stadler T (2010) J Theor Biol 267, 396-404 [Birth-Death with Serial Samples].";
107 }
108
109 public static String getCitationRT() {
110 return "Stadler et al (2011) : Estimating the basic reproductive number from viral sequence data, " +
111 "Mol.Biol.Evol., doi: 10.1093/molbev/msr217, 2011";
112 }
113
114 public String getParserDescription() {
115 return "Stadler et al (2010) model of speciation.";
116 }
117
118 public Class getReturnType() {
119 return BirthDeathSerialSamplingModel.class;
120 }
121
122 public XMLSyntaxRule[] getSyntaxRules() {
123 return rules;
124 }
125
126 private final XMLSyntaxRule[] rules = {
127 AttributeRule.newStringRule(TREE_TYPE, true),
128 AttributeRule.newBooleanRule(HAS_FINAL_SAMPLE, true),
129 // new ElementRule(FINAL_TIME_INTERVAL, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true),
130 new ElementRule(ORIGIN, Parameter.class, "The origin of the infection, x0 > tree.rootHeight", true),
131 new ElementRule(LAMBDA, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
132 new XORRule(
133 new ElementRule(MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
134 new ElementRule(RELATIVE_MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)})),
135 new ElementRule(PSI, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
136 new ElementRule(SAMPLE_BECOMES_NON_INFECTIOUS, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true),
137 //Issue 656
138 // new ElementRule(SAMPLE_PROBABILITY, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
139 // XMLUnits.SYNTAX_RULES[0]
140 };
141 }