Debian Codegraph @

src/dr/evomodelxml/speciation/BirthDeathModelParser.java

raw symbols SCIP
1 /*
2 * BirthDeathModelParser.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.BirthDeathGernhard08Model;
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 BirthDeathModelParser extends AbstractXMLObjectParser {
41
42 public static final String BIRTH_DEATH_MODEL = "birthDeathModel";
43 public static final String BIRTHDIFF_RATE = "birthMinusDeathRate";
44 public static final String RELATIVE_DEATH_RATE = "relativeDeathRate";
45 public static final String SAMPLE_PROB = "sampleProbability";
46 public static final String TREE_TYPE = "type";
47 public static final String CONDITIONAL_ON_ROOT = "conditionalOnRoot";
48
49 public static final String BIRTH_DEATH = "birthDeath";
50 public static final String MEAN_GROWTH_RATE_PARAM_NAME = BIRTH_DEATH + ".meanGrowthRate";
51 public static final String RELATIVE_DEATH_RATE_PARAM_NAME = BIRTH_DEATH + "." + RELATIVE_DEATH_RATE;
52
53 public String getParserName() {
54 return BIRTH_DEATH_MODEL;
55 }
56
57 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
58
59 final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
60
61 final String s = xo.getAttribute(TREE_TYPE, BirthDeathGernhard08Model.TreeType.UNSCALED.toString());
62 final BirthDeathGernhard08Model.TreeType treeType = BirthDeathGernhard08Model.TreeType.valueOf(s);
63 final boolean conditonalOnRoot = xo.getAttribute(CONDITIONAL_ON_ROOT, false);
64
65 final Parameter birthParameter = (Parameter) xo.getElementFirstChild(BIRTHDIFF_RATE);
66 final Parameter deathParameter = (Parameter) xo.getElementFirstChild(RELATIVE_DEATH_RATE);
67 final Parameter sampleProbability = xo.hasChildNamed(SAMPLE_PROB) ?
68 (Parameter) xo.getElementFirstChild(SAMPLE_PROB) : null;
69
70 Logger.getLogger("dr.evomodel").info(xo.hasChildNamed(SAMPLE_PROB) ? getCitationRHO() : getCitation());
71
72 final String modelName = xo.getId();
73
74 return new BirthDeathGernhard08Model(modelName, birthParameter, deathParameter, sampleProbability,
75 treeType, units, conditonalOnRoot);
76 }
77
78 //************************************************************************
79 // AbstractXMLObjectParser implementation
80 //************************************************************************
81 public static String getCitationRHO() {
82 return "Stadler, T; On incomplete sampling under birth-death models and connections to the sampling-based coalescent;\n" +
83 "JOURNAL OF THEORETICAL BIOLOGY (2009) 261:58-66";
84 }
85
86 public static String getCitation() {
87 return "Using birth-death model on tree: Gernhard T (2008) J Theor Biol, Volume 253, Issue 4, Pages 769-778 In press";
88 }
89
90 public String getParserDescription() {
91 return "Gernhard (2008) model of speciation (equation at bottom of page 19 of draft).";
92 }
93
94 public Class getReturnType() {
95 return BirthDeathGernhard08Model.class;
96 }
97
98 public XMLSyntaxRule[] getSyntaxRules() {
99 return rules;
100 }
101
102 private final XMLSyntaxRule[] rules = {
103 AttributeRule.newStringRule(TREE_TYPE, true),
104 AttributeRule.newBooleanRule(CONDITIONAL_ON_ROOT, true),
105 new ElementRule(BIRTHDIFF_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
106 new ElementRule(RELATIVE_DEATH_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
107 new ElementRule(SAMPLE_PROB, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true),
108 XMLUnits.SYNTAX_RULES[0]
109 };
110 }