Debian Codegraph @

src/dr/evomodelxml/tree/UniformNodeHeightPriorParser.java

raw symbols SCIP
1 /*
2 * UniformNodeHeightPriorParser.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.tree;
27
28 import dr.evomodel.tree.TreeModel;
29 import dr.evomodel.tree.UniformNodeHeightPrior;
30 import dr.xml.*;
31
32 import java.util.logging.Logger;
33
34 /**
35 */
36 public class UniformNodeHeightPriorParser extends AbstractXMLObjectParser {
37
38 public static final String UNIFORM_ROOT_PRIOR = "uniformRootPrior";
39 public static final String UNIFORM_NODE_HEIGHT_PRIOR = "uniformNodeHeightPrior";
40 public static final String MAX_ROOT_HEIGHT = "maxRootHeight";
41 public static final String ANALYTIC = "analytic";
42 public static final String MC_SAMPLE = "mcSampleSize";
43 public static final String MARGINAL = "marginal";
44 public static final String LEADING_TERM = "approximate";
45
46 public String getParserName() {
47 return UNIFORM_NODE_HEIGHT_PRIOR;
48 }
49
50 public String[] getParserNames() {
51 return new String[] {UNIFORM_ROOT_PRIOR, UNIFORM_NODE_HEIGHT_PRIOR};
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55
56 Logger.getLogger("dr.evomodel").info("\nConstructing a uniform node height prior:");
57
58 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
59 if (xo.hasAttribute(MAX_ROOT_HEIGHT)) {
60 // the Nicholls & Gray variant
61 double maxRootHeight = xo.getDoubleAttribute(MAX_ROOT_HEIGHT);
62 Logger.getLogger("dr.evomodel").info("\tUsing joint variant with a max root height = "+maxRootHeight+"\n");
63 return new UniformNodeHeightPrior(treeModel, maxRootHeight);
64 } else {
65 // the Bloomquist & Suchard variant or Welch, Rambaut & Suchard variant
66 boolean useAnalytic = xo.getAttribute(ANALYTIC,true);
67 boolean marginal = xo.getAttribute(MARGINAL,true);
68 boolean leadingTerm = xo.getAttribute(LEADING_TERM,false);
69 Logger.getLogger("dr.evomodel").info("\tUsing conditional variant with "+(useAnalytic ? "analytic" : "Monte Carlo integrated")+" expressions");
70 if (useAnalytic) {
71 Logger.getLogger("dr.evomodel").info("\t\tSubvariant: "+(marginal ? "marginal" : "conditional"));
72 Logger.getLogger("dr.evomodel").info("\t\tApproximation: "+leadingTerm);
73 }
74 Logger.getLogger("dr.evomodel").info("\tPlease reference:");
75 Logger.getLogger("dr.evomodel").info("\t\t (1) Welch, Rambaut and Suchard (in preparation) and");
76 Logger.getLogger("dr.evomodel").info("\t\t (2) Bloomquist and Suchard (in press) Systematic Biology\n");
77 if (!useAnalytic) {
78 // if( treeModel.getExternalNodeCount() > MAX_ANALYTIC_TIPS)
79 // throw new XMLParseException("Analytic evaluation of UniformNodeHeight is unreliable for > "+MAX_ANALYTIC_TIPS+" taxa");
80 int mcSampleSize = xo.getAttribute(MC_SAMPLE, UniformNodeHeightPrior.DEFAULT_MC_SAMPLE);
81 return new UniformNodeHeightPrior(treeModel,useAnalytic,mcSampleSize);
82 }
83
84 return new UniformNodeHeightPrior(treeModel, useAnalytic, marginal,leadingTerm);
85 }
86 }
87
88 //************************************************************************
89 // AbstractXMLObjectParser implementation
90 //************************************************************************
91
92 public String getParserDescription() {
93 return "This element represents the likelihood of the tree given the demographic function.";
94 }
95
96 public Class getReturnType() {
97 return UniformNodeHeightPrior.class;
98 }
99
100 public XMLSyntaxRule[] getSyntaxRules() {
101 return rules;
102 }
103
104 private final XMLSyntaxRule[] rules = {
105 AttributeRule.newBooleanRule(ANALYTIC, true),
106 AttributeRule.newDoubleRule(MAX_ROOT_HEIGHT, true),
107 AttributeRule.newIntegerRule(MC_SAMPLE,true),
108 AttributeRule.newBooleanRule(MARGINAL,true),
109 AttributeRule.newBooleanRule(LEADING_TERM,true),
110 new ElementRule(TreeModel.class)
111 };
112
113 }