Debian Codegraph @

src/dr/evomodelxml/branchmodel/RandomBranchModelParser.java

raw symbols SCIP
1 /*
2 * RandomBranchModelParser.java
3 *
4 * Copyright (c) 2002-2016 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.branchmodel;
27
28 import java.util.logging.Logger;
29
30 import dr.evomodel.branchmodel.RandomBranchModel;
31 import dr.evomodel.substmodel.codon.GY94CodonModel;
32 import dr.evomodel.substmodel.SubstitutionModel;
33 import dr.evomodel.tree.TreeModel;
34 import dr.xml.AbstractXMLObjectParser;
35 import dr.xml.AttributeRule;
36 import dr.xml.ElementRule;
37 import dr.xml.XMLObject;
38 import dr.xml.XMLParseException;
39 import dr.xml.XMLSyntaxRule;
40
41 /**
42 * @author Filip Bielejec
43 * @version $Id$
44 *
45 */
46
47 public class RandomBranchModelParser extends AbstractXMLObjectParser {
48
49 public static final String BASE_MODEL = "baseSubstitutionModel";
50 public static final String SEED = "seed";
51
52 public static final String RATE = "rate";
53
54 @Override
55 public String getParserName() {
56 return RandomBranchModel.RANDOM_BRANCH_MODEL;
57 }
58
59 @Override
60 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
61
62 Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model.");
63
64 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
65 GY94CodonModel baseSubstitutionModel = (GY94CodonModel) xo .getElementFirstChild(BASE_MODEL);
66
67
68 long seed = -1;
69 boolean hasSeed = false;
70 if (xo.hasAttribute(SEED)) {
71 seed = xo.getLongIntegerAttribute(SEED);
72 hasSeed = true;
73 }
74
75
76 double rate = 1;
77 if (xo.hasAttribute(RATE)) {
78 rate = xo.getDoubleAttribute(RATE);
79 }
80
81
82 return new RandomBranchModel(treeModel, baseSubstitutionModel, rate, hasSeed, seed);
83 }//END: parseXMLObject
84
85 @Override
86 public XMLSyntaxRule[] getSyntaxRules() {
87
88 return new XMLSyntaxRule[] {
89
90 AttributeRule.newDoubleRule(RATE, true, "Rate of the exponentially distributed random component."), //
91 new ElementRule(TreeModel.class, false), //
92 new ElementRule(BASE_MODEL,
93 new XMLSyntaxRule[]{ new ElementRule(SubstitutionModel.class, 1, 1) })
94
95 };
96 }// END: XMLSyntaxRule
97
98 @Override
99 public String getParserDescription() {
100 return RandomBranchModel.RANDOM_BRANCH_MODEL;
101 }
102
103 @Override
104 public Class getReturnType() {
105 return RandomBranchModel.class;
106 }
107
108
109 }//END: class