Debian Codegraph @

src/dr/evomodelxml/speciation/SpeciesTreeModelParser.java

raw symbols SCIP
1 /*
2 * SpeciesTreeModelParser.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.tree.Tree;
29 import dr.evomodel.speciation.SpeciesBindings;
30 import dr.evomodel.speciation.SpeciesTreeModel;
31 import dr.inference.model.Parameter;
32 import dr.inference.model.ParameterParser;
33 import dr.util.Attributable;
34 import dr.xml.*;
35
36 /**
37 */
38 public class SpeciesTreeModelParser extends AbstractXMLObjectParser {
39 public static final String SPECIES_TREE = "speciesTree";
40
41 public static final String SPP_SPLIT_POPULATIONS = "sppSplitPopulations";
42 public static final String COALESCENT_POINTS_POPULATIONS = "coalescentPointsPopulations";
43 public static final String COALESCENT_POINTS_INDICATORS = "coalescentPointsIndicators";
44
45 public static final String BMPRIOR = "bmPrior";
46 public static final String CONST_ROOT_POPULATION = "constantRoot";
47 public static final String CONSTANT_POPULATION = "constantPopulation";
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50 SpeciesBindings spb = (SpeciesBindings) xo.getChild(SpeciesBindings.class);
51
52 Parameter coalPointsPops = null;
53 Parameter coalPointsIndicators = null;
54 final Boolean cr = xo.getAttribute(CONST_ROOT_POPULATION, false);
55 final Boolean cp = xo.getAttribute(CONSTANT_POPULATION, false);
56
57 final Boolean bmp = xo.getAttribute(BMPRIOR, false);
58 {
59 XMLObject cxo = xo.getChild(COALESCENT_POINTS_POPULATIONS);
60 if( cxo != null ) {
61 final double value = cxo.getAttribute(Attributable.VALUE, 1.0);
62 coalPointsPops = SpeciesTreeModel.createCoalPointsPopParameter(spb, cxo.getAttribute(Attributable.VALUE, value), bmp);
63 ParameterParser.replaceParameter(cxo, coalPointsPops);
64 coalPointsPops.addBounds(
65 new Parameter.DefaultBounds(Double.MAX_VALUE, 0, coalPointsPops.getDimension()));
66
67 cxo = xo.getChild(COALESCENT_POINTS_INDICATORS);
68 if( cxo == null ) {
69 throw new XMLParseException("Must have indicators");
70 }
71 coalPointsIndicators = new Parameter.Default(coalPointsPops.getDimension(), 0);
72 ParameterParser.replaceParameter(cxo, coalPointsIndicators);
73 } else {
74 // assert ! bmp;
75 }
76 }
77
78 final XMLObject cxo = xo.getChild(SPP_SPLIT_POPULATIONS);
79
80 final double value = cxo.getAttribute(Attributable.VALUE, 1.0);
81 final boolean nonConstRootPopulation = coalPointsPops == null && !cr;
82 final Parameter sppSplitPopulations = SpeciesTreeModel.createSplitPopulationsParameter(spb, value, nonConstRootPopulation, cp);
83 ParameterParser.replaceParameter(cxo, sppSplitPopulations);
84
85 final Parameter.DefaultBounds bounds =
86 new Parameter.DefaultBounds(Double.MAX_VALUE, 0, sppSplitPopulations.getDimension());
87 sppSplitPopulations.addBounds(bounds);
88
89 final Tree startTree = (Tree) xo.getChild(Tree.class);
90
91 return new SpeciesTreeModel(spb, sppSplitPopulations, coalPointsPops, coalPointsIndicators, startTree, bmp,
92 nonConstRootPopulation, cp);
93 }
94
95 public XMLSyntaxRule[] getSyntaxRules() {
96 return new XMLSyntaxRule[]{
97 AttributeRule.newBooleanRule(BMPRIOR, true),
98 AttributeRule.newBooleanRule(CONST_ROOT_POPULATION, true),
99 AttributeRule.newBooleanRule(CONSTANT_POPULATION, true),
100 new ElementRule(SpeciesBindings.class),
101 // A starting tree. Can be very minimal, i.e. no branch lengths and not resolved
102 new ElementRule(Tree.class, true),
103 new ElementRule(SPP_SPLIT_POPULATIONS, new XMLSyntaxRule[]{
104 AttributeRule.newDoubleRule(Attributable.VALUE, true),
105 new ElementRule(Parameter.class)}),
106
107 new ElementRule(COALESCENT_POINTS_POPULATIONS, new XMLSyntaxRule[]{
108 AttributeRule.newDoubleRule(Attributable.VALUE, true),
109 new ElementRule(Parameter.class)}, true),
110
111 new ElementRule(COALESCENT_POINTS_INDICATORS, new XMLSyntaxRule[]{
112 new ElementRule(Parameter.class)}, true),
113 };
114 }
115
116 public String getParserDescription() {
117 return "Species tree which includes demographic function per branch.";
118 }
119
120 public Class getReturnType() {
121 return SpeciesTreeModel.class;
122 }
123
124 public String getParserName() {
125 return SPECIES_TREE;
126 }
127
128
129 }