Debian Codegraph @

src/dr/evomodelxml/coalescent/VariableSkylineLikelihoodParser.java

raw symbols SCIP
1 /*
2 * VariableSkylineLikelihoodParser.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.coalescent;
27
28 import dr.evomodel.coalescent.VariableSkylineLikelihood;
29 import dr.evomodel.tree.TreeModel;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32
33 import java.util.logging.Logger;
34
35
36 /**
37 */
38 public class VariableSkylineLikelihoodParser extends AbstractXMLObjectParser {
39
40 public static final String SKYLINE_LIKELIHOOD = "ovariableSkyLineLikelihood";
41 public static final String POPULATION_SIZES = "populationSizes";
42 public static final String INDICATOR_PARAMETER = "indicators";
43 public static final String LOG_SPACE = "logUnits";
44
45 public static final String TYPE = "type";
46 public static final String STEPWISE = "stepwise";
47 public static final String LINEAR = "linear";
48 public static final String EXPONENTIAL = "exponential";
49
50 public String getParserName() {
51 return SKYLINE_LIKELIHOOD;
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55
56 XMLObject cxo = xo.getChild(POPULATION_SIZES);
57 Parameter param = (Parameter) cxo.getChild(Parameter.class);
58
59 cxo = xo.getChild(INDICATOR_PARAMETER);
60 Parameter param2 = (Parameter) cxo.getChild(Parameter.class);
61
62 cxo = xo.getChild(CoalescentLikelihoodParser.POPULATION_TREE);
63 TreeModel treeModel = (TreeModel) cxo.getChild(TreeModel.class);
64
65 VariableSkylineLikelihood.Type type = VariableSkylineLikelihood.Type.STEPWISE;
66 /* if (xo.hasAttribute(LINEAR) && !xo.getBooleanAttribute(LINEAR))
67 {
68 type = VariableSkylineLikelihood.Type.STEPWISE;
69 }*/
70
71 if (xo.hasAttribute(TYPE)) {
72 final String s = xo.getStringAttribute(TYPE);
73 if (s.equalsIgnoreCase(STEPWISE)) {
74 type = VariableSkylineLikelihood.Type.STEPWISE;
75 } else if (s.equalsIgnoreCase(LINEAR)) {
76 type = VariableSkylineLikelihood.Type.LINEAR;
77 } else if (s.equalsIgnoreCase(EXPONENTIAL)) {
78 type = VariableSkylineLikelihood.Type.EXPONENTIAL;
79 } else {
80 throw new XMLParseException("Unknown Bayesian Skyline type: " + s);
81 }
82 }
83
84 boolean logSpace = xo.getBooleanAttribute(LOG_SPACE);
85
86 Logger.getLogger("dr.evomodel").info("Variable skyline plot: " + type.toString() + " control points");
87
88 return new VariableSkylineLikelihood(treeModel, param, param2, type, logSpace);
89 }
90
91 //************************************************************************
92 // AbstractXMLObjectParser implementation
93 //************************************************************************
94
95 public String getParserDescription() {
96 return "This element represents the likelihood of the tree given the population size vector.";
97 }
98
99 public Class getReturnType() {
100 return VariableSkylineLikelihood.class;
101 }
102
103 public XMLSyntaxRule[] getSyntaxRules() {
104 return rules;
105 }
106
107 private final XMLSyntaxRule[] rules = {
108 AttributeRule.newBooleanRule(TYPE, true),
109 new ElementRule(POPULATION_SIZES, new XMLSyntaxRule[]{
110 new ElementRule(Parameter.class)
111 }),
112 new ElementRule(INDICATOR_PARAMETER, new XMLSyntaxRule[]{
113 new ElementRule(Parameter.class)
114 }),
115 new ElementRule(CoalescentLikelihoodParser.POPULATION_TREE, new XMLSyntaxRule[]{
116 new ElementRule(TreeModel.class)
117 }),
118 AttributeRule.newBooleanRule(LOG_SPACE)
119 };
120
121 }