Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * MulSpeciesTreeModelParser.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 import dr.evolution.tree.Tree;
29 import dr.evomodel.alloppnet.speciation.MulSpeciesBindings;
30 import dr.evomodel.alloppnet.speciation.MulSpeciesTreeModel;
31 import dr.inference.model.Parameter;
32 import dr.inference.model.ParameterParser;
33 import dr.util.Attributable;
34 import dr.xml.*;
35
36 /**
37 * Very similar for JH's SpeciesTreeModelParser but no support for bmp prior,
38 * piece-wise pop sizes, or user starting tree.
39 *
40 * @author Graham Jones
41 * Date: 20/12/2011
42 */
43 public class MulSpeciesTreeModelParser extends AbstractXMLObjectParser {
44 public static final String MUL_SPECIES_TREE = "mulSpeciesTree";
45
46 public static final String SPP_SPLIT_POPULATIONS = "sppSplitPopulations";
47
48 public static final String CONST_ROOT_POPULATION = "constantRoot";
49 public static final String CONSTANT_POPULATION = "constantPopulation";
50
51 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
52 MulSpeciesBindings spb = (MulSpeciesBindings) xo.getChild(MulSpeciesBindings.class);
53
54 final Boolean cr = xo.getAttribute(CONST_ROOT_POPULATION, false);
55 final Boolean cp = xo.getAttribute(CONSTANT_POPULATION, false);
56
57 final XMLObject cxo = xo.getChild(SPP_SPLIT_POPULATIONS);
58
59 final double value = cxo.getAttribute(Attributable.VALUE, 1.0);
60 final boolean nonConstRootPopulation = !cr;
61 final Parameter sppSplitPopulations = MulSpeciesTreeModel.createSplitPopulationsParameter(spb, value, nonConstRootPopulation, cp);
62 ParameterParser.replaceParameter(cxo, sppSplitPopulations);
63
64 final Parameter.DefaultBounds bounds =
65 new Parameter.DefaultBounds(Double.MAX_VALUE, 0, sppSplitPopulations.getDimension());
66 sppSplitPopulations.addBounds(bounds);
67
68 final Tree startTree = null; //(Tree) xo.getChild(Tree.class);
69
70 return new MulSpeciesTreeModel(spb, sppSplitPopulations, null, null, startTree, false, nonConstRootPopulation, cp);
71 }
72
73 public XMLSyntaxRule[] getSyntaxRules() {
74 return new XMLSyntaxRule[]{
75 AttributeRule.newBooleanRule(CONST_ROOT_POPULATION, true),
76 AttributeRule.newBooleanRule(CONSTANT_POPULATION, true),
77 new ElementRule(MulSpeciesBindings.class),
78 // A starting tree. Can be very minimal, i.e. no branch lengths and not resolved
79 new ElementRule(Tree.class, true),
80 new ElementRule(SPP_SPLIT_POPULATIONS, new XMLSyntaxRule[]{
81 AttributeRule.newDoubleRule(Attributable.VALUE, true),
82 new ElementRule(Parameter.class)})
83 };
84 }
85
86 public String getParserDescription() {
87 return "Multiply-labelled species tree which includes demographic function per branch.";
88 }
89
90 public Class getReturnType() {
91 return MulSpeciesTreeModel.class;
92 }
93
94 public String getParserName() {
95 return MUL_SPECIES_TREE;
96 }
97
98
99 }
100