Debian Codegraph @

src/dr/evomodelxml/branchratemodel/RandomLocalClockModelParser.java

raw symbols SCIP
1 /*
2 * RandomLocalClockModelParser.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.RandomLocalClockModel;
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 public class RandomLocalClockModelParser extends AbstractXMLObjectParser {
38
39 public static final String LOCAL_BRANCH_RATES = "randomLocalClockModel";
40 public static final String RATE_INDICATORS = "rateIndicator";
41 public static final String RATES = "rates";
42 public static final String CLOCK_RATE = "clockRate";
43 public static final String RATES_ARE_MULTIPLIERS = "ratesAreMultipliers";
44 public static final String THRESHOLD = "threshold";
45
46 public String getParserName() {
47 return LOCAL_BRANCH_RATES;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
53
54 Parameter rateIndicatorParameter = (Parameter) xo.getElementFirstChild(RATE_INDICATORS);
55 Parameter ratesParameter = (Parameter) xo.getElementFirstChild(RATES);
56 Parameter meanRateParameter = null;
57
58 if (xo.hasChildNamed(CLOCK_RATE)) {
59 meanRateParameter = (Parameter) xo.getElementFirstChild(CLOCK_RATE);
60 }
61
62 boolean ratesAreMultipliers = xo.getAttribute(RATES_ARE_MULTIPLIERS, false);
63
64 Logger.getLogger("dr.evomodel").info("\nUsing random local clock (RLC) model.");
65 Logger.getLogger("dr.evomodel").info(" rates at change points are parameterized to be " +
66 (ratesAreMultipliers ? " relative to parent rates." : "independent of parent rates."));
67
68 double threshold = xo.getAttribute(THRESHOLD, Double.NaN); // NaN == binary values
69
70 return new RandomLocalClockModel(tree, meanRateParameter, rateIndicatorParameter,
71 ratesParameter, ratesAreMultipliers, threshold);
72 }
73
74 //************************************************************************
75 // AbstractXMLObjectParser implementation
76 //************************************************************************
77
78 public String getParserDescription() {
79 return
80 "This element returns an random local clock (RLC) model." +
81 "Each branch either has a new rate or " +
82 "inherits the rate of the branch above it depending on the indicator vector, " +
83 "which is itself sampled.";
84 }
85
86 public Class getReturnType() {
87 return RandomLocalClockModel.class;
88 }
89
90 public XMLSyntaxRule[] getSyntaxRules() {
91 return rules;
92 }
93
94 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
95 new ElementRule(TreeModel.class),
96 new ElementRule(RATE_INDICATORS, Parameter.class, "The rate change indicators parameter", false),
97 new ElementRule(RATES, Parameter.class, "The rates parameter", false),
98 new ElementRule(CLOCK_RATE, Parameter.class, "The mean rate across all local clocks", true),
99 AttributeRule.newBooleanRule(RATES_ARE_MULTIPLIERS, false),
100 AttributeRule.newDoubleRule(THRESHOLD, true),
101 };
102 }