Debian Codegraph @

src/dr/evomodelxml/speciation/TaxonRichnessBirthDeathModelParser.java

raw symbols SCIP
1 /*
2 * TaxonRichnessBirthDeathModelParser.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.TaxonRichnessBirthDeathModel;
30 import dr.evoxml.util.XMLUnits;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 /**
35 * @author Marc A. Suchard
36 */
37 public class TaxonRichnessBirthDeathModelParser extends AbstractXMLObjectParser {
38
39 public static final String TAXON_RICHNESS_MODEL = "randomLocalYuleModel";
40 public static final String MEAN_RATE = "meanRate";
41 public static final String BIRTH_RATE = "birthRates";
42 public static final String BIRTH_RATE_INDICATORS = "indicators";
43 public static final String RATES_AS_MULTIPLIERS = "ratesAsMultipliers";
44
45 public String getParserName() {
46 return TAXON_RICHNESS_MODEL;
47 }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
52
53 XMLObject cxo = xo.getChild(BIRTH_RATE);
54 Parameter brParameter = (Parameter) cxo.getChild(Parameter.class);
55
56 cxo = xo.getChild(BIRTH_RATE_INDICATORS);
57 Parameter indicatorsParameter = (Parameter) cxo.getChild(Parameter.class);
58
59 Parameter meanRate = (Parameter) xo.getElementFirstChild(MEAN_RATE);
60
61 boolean ratesAsMultipliers = xo.getBooleanAttribute(RATES_AS_MULTIPLIERS);
62
63 int dp = xo.getAttribute("dp", 4);
64
65 return new TaxonRichnessBirthDeathModel(brParameter, indicatorsParameter, meanRate, ratesAsMultipliers, units, dp);
66 }
67
68 //************************************************************************
69 // AbstractXMLObjectParser implementation
70 //************************************************************************
71
72 public String getParserDescription() {
73 return "A speciation model of a Yule process whose rate can change at random nodes in the tree.";
74 }
75
76 public Class getReturnType() {
77 return TaxonRichnessBirthDeathModel.class;
78 }
79
80 public XMLSyntaxRule[] getSyntaxRules() {
81 return rules;
82 }
83
84 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
85 new ElementRule(BIRTH_RATE,
86 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
87 new ElementRule(BIRTH_RATE_INDICATORS,
88 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
89 new ElementRule(MEAN_RATE,
90 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
91 AttributeRule.newBooleanRule(RATES_AS_MULTIPLIERS),
92 AttributeRule.newIntegerRule("dp", true),
93 XMLUnits.SYNTAX_RULES[0]
94 };
95 }