Debian Codegraph @

src/dr/evomodelxml/branchratemodel/ArbitraryBranchRatesParser.java

raw symbols SCIP
1 /*
2 * ArbitraryBranchRatesParser.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.ArbitraryBranchRates;
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 ArbitraryBranchRatesParser extends AbstractXMLObjectParser {
38
39 public static final String ARBITRARY_BRANCH_RATES = "arbitraryBranchRates";
40 public static final String RATES = "rates";
41 public static final String RECIPROCAL = "reciprocal";
42 public static final String EXP = "exp";
43 public static final String CENTER_AT_ONE = "centerAtOne";
44
45 public String getParserName() {
46 return ARBITRARY_BRANCH_RATES;
47 }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
52
53 XMLObject cxo = xo.getChild(RATES);
54
55 Parameter rateCategoryParameter = (Parameter) cxo.getChild(Parameter.class);
56
57 boolean reciprocal = xo.getAttribute(RECIPROCAL, false);
58 boolean centerAtOne = xo.getAttribute(CENTER_AT_ONE, true);
59 boolean exp = xo.getAttribute(EXP, false);
60
61 final int numBranches = tree.getNodeCount() - 1;
62 if (rateCategoryParameter.getDimension() != numBranches) {
63 rateCategoryParameter.setDimension(numBranches);
64 // throw new XMLParseException("Invalid length for '" + rateCategoryParameter.getId() + "'\n" +
65 // "Should have length = " + numBranches);
66 }
67
68 Logger.getLogger("dr.evomodel").info("\nUsing an scaled mixture of normals model.");
69 Logger.getLogger("dr.evomodel").info(" rates = " + rateCategoryParameter.getDimension());
70 Logger.getLogger("dr.evomodel").info(" NB: Make sure you have a prior on " + rateCategoryParameter.getId() + " and do not use this model in a treeLikelihood for sequence data");
71 Logger.getLogger("dr.evomodel").info(" reciprocal = " + reciprocal);
72
73 return new ArbitraryBranchRates(tree, rateCategoryParameter, reciprocal, exp, centerAtOne);
74 }
75
76 //************************************************************************
77 // AbstractXMLObjectParser implementation
78 //************************************************************************
79
80 public String getParserDescription() {
81 return "This element returns an arbitrary rate model." +
82 "The branch rates are drawn from an arbitrary distribution determine by the prior.";
83 }
84
85 public Class getReturnType() {
86 return ArbitraryBranchRates.class;
87 }
88
89 public XMLSyntaxRule[] getSyntaxRules() {
90 return rules;
91 }
92
93 private final XMLSyntaxRule[] rules = {
94 new ElementRule(TreeModel.class),
95 new ElementRule(RATES, Parameter.class, "The rate parameter"),
96 AttributeRule.newBooleanRule(RECIPROCAL, true),
97 AttributeRule.newBooleanRule(CENTER_AT_ONE, true),
98 AttributeRule.newBooleanRule(EXP, true),
99 };
100
101
102 }