Debian Codegraph @

src/dr/evomodelxml/branchratemodel/ContinuousBranchRatesParser.java

raw symbols SCIP
1 /*
2 * ContinuousBranchRatesParser.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.branchratemodel;
27
28 import dr.evomodel.branchratemodel.ContinuousBranchRates;
29 import dr.evomodel.tree.TreeModel;
30 import dr.inference.distribution.ParametricDistributionModel;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 import java.util.logging.Logger;
35
36 /**
37 * @author Wai Lok Sibon Li
38 */
39 public class ContinuousBranchRatesParser extends AbstractXMLObjectParser {
40
41 public static final String CONTINUOUS_BRANCH_RATES = "continuousBranchRates";
42 public static final String DISTRIBUTION = "distribution";
43 public static final String RATE_CATEGORY_QUANTILES = "rateCategoryQuantiles";
44 public static final String RATE_QUANTILES = "rateQuantiles";
45 public static final String SINGLE_ROOT_RATE = "singleRootRate";
46 public static final String NORMALIZE = "normalize";
47 public static final String NORMALIZE_BRANCH_RATE_TO = "normalizeBranchRateTo";
48
49
50 public String getParserName() {
51 return CONTINUOUS_BRANCH_RATES;
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55
56 final boolean normalize = xo.getAttribute(NORMALIZE, false);
57 final double normalizeBranchRateTo = xo.getAttribute(NORMALIZE_BRANCH_RATE_TO, Double.NaN);
58
59 TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
60 ParametricDistributionModel distributionModel = (ParametricDistributionModel) xo.getElementFirstChild(DISTRIBUTION);
61
62 Parameter rateQuantilesParameter;
63 if (xo.hasChildNamed(RATE_QUANTILES)) {
64 rateQuantilesParameter = (Parameter) xo.getElementFirstChild(RATE_QUANTILES);
65 } else {
66 rateQuantilesParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORY_QUANTILES);
67 }
68
69 Logger.getLogger("dr.evomodel").info("Using continuous relaxed clock model.");
70 Logger.getLogger("dr.evomodel").info(" parametric model = " + distributionModel.getModelName());
71 Logger.getLogger("dr.evomodel").info(" rate categories = " + rateQuantilesParameter.getDimension());
72 if(normalize) {
73 Logger.getLogger("dr.evomodel").info(" mean rate is normalized to " + normalizeBranchRateTo);
74 }
75
76 if (xo.hasAttribute(SINGLE_ROOT_RATE)) {
77 Logger.getLogger("dr.evomodel").warning(" WARNING: single root rate is not implemented!");
78 }
79
80 return new ContinuousBranchRates(tree, rateQuantilesParameter, distributionModel, normalize, normalizeBranchRateTo);
81 }
82
83 //************************************************************************
84 // AbstractXMLObjectParser implementation
85 //************************************************************************
86
87 public String getParserDescription() {
88 return
89 "This element returns a continuous quantile uncorrelated relaxed clock model.";
90 }
91
92 public Class getReturnType() {
93 return ContinuousBranchRates.class;
94 }
95
96 public XMLSyntaxRule[] getSyntaxRules() {
97 return rules;
98 }
99
100 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
101 AttributeRule.newBooleanRule(SINGLE_ROOT_RATE, true, "Whether only a single rate should be used for the two children branches of the root"),
102 AttributeRule.newBooleanRule(NORMALIZE, true, "Whether the mean rate has to be normalized to a particular value"),
103 AttributeRule.newDoubleRule(NORMALIZE_BRANCH_RATE_TO, true, "The mean rate to normalize to, if normalizing"),
104 new ElementRule(TreeModel.class),
105 new ElementRule(DISTRIBUTION, ParametricDistributionModel.class, "The distribution model for rates among branches", false),
106 new XORRule(
107 new ElementRule(RATE_QUANTILES, Parameter.class, "The quantiles for each branch", false),
108 new ElementRule(RATE_CATEGORY_QUANTILES, Parameter.class, "The quantiles for each branch", false)
109 )
110 };
111 }