Debian Codegraph @

src/dr/evomodelxml/branchratemodel/ContinuousTraitBranchRateModelParser.java

raw symbols SCIP
1 /*
2 * ContinuousTraitBranchRateModelParser.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.BranchRateModel;
29 import dr.evomodel.branchratemodel.ContinuousTraitBranchRateModel;
30 import dr.evomodel.continuous.SampledMultivariateTraitLikelihood;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 import java.util.logging.Logger;
35
36 public class ContinuousTraitBranchRateModelParser extends AbstractXMLObjectParser {
37
38 public static final String TRAIT_BRANCH_RATES = "continuousTraitRateModel";
39 public static final String TRAIT = "trait";
40 public static final String DIMENSION = "dimension";
41 public static final String RATE = BranchRateModel.RATE;
42 public static final String RATIO = "ratio";
43
44 public String getParserName() {
45 return TRAIT_BRANCH_RATES;
46 }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50 String trait = xo.getAttribute(TRAIT, "");
51 int dimension = 0;
52 if (xo.hasAttribute(DIMENSION)) {
53 dimension = xo.getIntegerAttribute(DIMENSION) - 1;
54 }
55
56 SampledMultivariateTraitLikelihood traitLikelihood = (SampledMultivariateTraitLikelihood)
57 xo.getChild(SampledMultivariateTraitLikelihood.class);
58 if (traitLikelihood != null)
59 trait = traitLikelihood.getTraitName();
60
61 Logger.getLogger("dr.evomodel").info("\nUsing trait '" + trait + "' as log rate estimates.");
62
63 if (xo.hasChildNamed(RATE)) {
64 Parameter rateParameter = (Parameter) xo.getElementFirstChild(RATE);
65 Parameter ratioParameter = (Parameter) xo.getElementFirstChild(RATIO);
66
67 return new ContinuousTraitBranchRateModel(trait, rateParameter, ratioParameter);
68 } else {
69
70 return new ContinuousTraitBranchRateModel(traitLikelihood, dimension);
71 }
72 }
73
74 //************************************************************************
75 // AbstractXMLObjectParser implementation
76 //************************************************************************
77
78 public String getParserDescription() {
79 return "This element returns an trait rate model." +
80 "The branch rates are an average of the rates provided by a node trait.";
81 }
82
83 public Class getReturnType() {
84 return ContinuousTraitBranchRateModel.class;
85 }
86
87 public XMLSyntaxRule[] getSyntaxRules() {
88 return rules;
89 }
90
91 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
92 // AttributeRule.newStringRule(TRAIT, false, "The name of the trait that provides the log rates at nodes"),
93 AttributeRule.newIntegerRule(DIMENSION, true, "The dimension that supplies the rate"),
94 new ElementRule(RATE, Parameter.class, "The rate parameter", true),
95 new ElementRule(RATIO, Parameter.class, "The ratio parameter", true),
96 new ElementRule(SampledMultivariateTraitLikelihood.class, true),
97 };
98
99
100 }