Debian Codegraph @

src/dr/evomodelxml/branchmodel/RandomBranchAssignmentModelParser.java

raw symbols SCIP
1 /*
2 * RandomBranchAssignmentModelParser.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.ArrayList;
29 import java.util.List;
30 import java.util.logging.Logger;
31
32 import dr.evomodel.branchmodel.RandomBranchAssignmentModel;
33 import dr.evomodel.branchmodel.RandomBranchModel;
34 import dr.evomodel.substmodel.SubstitutionModel;
35 import dr.evomodel.tree.TreeModel;
36 import dr.xml.AbstractXMLObjectParser;
37 import dr.xml.ElementRule;
38 import dr.xml.XMLObject;
39 import dr.xml.XMLParseException;
40 import dr.xml.XMLSyntaxRule;
41
42 public class RandomBranchAssignmentModelParser extends AbstractXMLObjectParser {
43
44 public static final String MODELS = "models";
45
46 @Override
47 public String getParserName() {
48 return RandomBranchAssignmentModel.RANDOM_BRANCH_ASSIGNMENT_MODEL;
49 }
50
51 @Override
52 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
53
54 Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model.");
55 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
56
57 XMLObject cxo = xo.getChild(MODELS);
58 List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
59 for (int i = 0; i < cxo.getChildCount(); i++) {
60
61 SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i);
62 substitutionModels.add(substModel);
63
64 }//END: models loop
65
66 return new RandomBranchAssignmentModel(treeModel, substitutionModels);
67 }//END: parseXMLObject
68
69 @Override
70 public XMLSyntaxRule[] getSyntaxRules() {
71
72 return new XMLSyntaxRule[]{
73
74 new ElementRule(TreeModel.class, false), //
75 new ElementRule(MODELS,
76 new XMLSyntaxRule[] {
77 new ElementRule(SubstitutionModel.class, 1, Integer.MAX_VALUE),
78 }
79 )
80
81 };
82 }//END: XMLSyntaxRule
83
84 @Override
85 public String getParserDescription() {
86 return "This element provides a branch model which randomly assigns " +
87 "substitution models to branches on the tree by sampling " +
88 "with replacement from the provided list of substitution models. ";
89 }
90
91 @Override
92 public Class getReturnType() {
93 return RandomBranchModel.class;
94 }
95
96
97 }//END: class