Debian Codegraph @

src/dr/evomodel/alloppnet/parsers/BirthDeathCollapseModelParser.java

raw symbols SCIP
1 /*
2 * BirthDeathCollapseModelParser.java
3 *
4 * Copyright (c) 2002-2017 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.evomodel.alloppnet.parsers;
27
28 /**
29 * @author Graham Jones
30 * Date: 01/09/2013
31 */
32
33
34 import dr.evolution.tree.Tree;
35 import dr.evolution.util.Units;
36 import dr.evomodel.alloppnet.speciation.BirthDeathCollapseModel;
37 import dr.evoxml.util.XMLUnits;
38 import dr.inference.model.Parameter;
39 import dr.xml.*;
40
41
42 import static dr.xml.AttributeRule.newDoubleRule;
43
44
45 public class BirthDeathCollapseModelParser extends AbstractXMLObjectParser {
46
47 public static final String BIRTH_DEATH_COLLAPSE_MODEL = "birthDeathCollapseModel";
48
49 public static final String COLLAPSE_HEIGHT = "collapseHeight";
50
51 public static final String TREE = "speciesTree";
52
53 public static final String BIRTHDIFF_RATE = "birthMinusDeathRate";
54 public static final String RELATIVE_DEATH_RATE = "relativeDeathRate";
55 public static final String ORIGIN_HEIGHT = "originHeight";
56 public static final String COLLAPSE_WEIGHT = "collapseWeight";
57
58
59
60 public String getParserName() {
61 return BIRTH_DEATH_COLLAPSE_MODEL;
62 }
63
64
65 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
66
67 final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
68
69 final double collH = xo.getDoubleAttribute(COLLAPSE_HEIGHT);
70
71 XMLObject cxo = xo.getChild(TREE);
72 final Tree tree = (Tree) cxo.getChild(Tree.class);
73
74 final Parameter birthMinusDeath = (Parameter) xo.getElementFirstChild(BIRTHDIFF_RATE);
75 final Parameter relativeDeathRate = (Parameter) xo.getElementFirstChild(RELATIVE_DEATH_RATE);
76 final Parameter originHeight = (Parameter) xo.getElementFirstChild(ORIGIN_HEIGHT);
77 final Parameter collapseWeight = (Parameter) xo.getElementFirstChild(COLLAPSE_WEIGHT);
78
79 final String modelName = xo.getId();
80
81 return new BirthDeathCollapseModel(modelName, tree, units,
82 birthMinusDeath, relativeDeathRate, originHeight, collapseWeight, collH);
83 }
84
85 //************************************************************************
86 // AbstractXMLObjectParser implementation
87 //************************************************************************
88
89 public Class getReturnType() {
90 return BirthDeathCollapseModel.class;
91 }
92
93 public String getParserDescription() {
94 return "A speciation model aimed at species delimitation, mixing birth-death model with spike near zero for node heights.";
95 }
96
97
98 public XMLSyntaxRule[] getSyntaxRules() {
99 return rules;
100 }
101
102 private final XMLSyntaxRule[] rules = {
103 new ElementRule(TREE, new XMLSyntaxRule[]{new ElementRule(Tree.class)}),
104 new ElementRule(BIRTHDIFF_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
105 new ElementRule(RELATIVE_DEATH_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
106 new ElementRule(ORIGIN_HEIGHT, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
107 new ElementRule(COLLAPSE_WEIGHT, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
108 XMLUnits.SYNTAX_RULES[0],
109 newDoubleRule(COLLAPSE_HEIGHT),
110 };
111 }
112
113
114
115
116