Debian Codegraph @

src/dr/evomodel/branchmodel/lineagespecific/LineageSpecificBranchModelParser.java

raw symbols SCIP
1 /*
2 * LineageSpecificBranchModelParser.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.evomodel.branchmodel.lineagespecific;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import dr.evomodel.substmodel.FrequencyModel;
32 import dr.evomodel.substmodel.SubstitutionModel;
33 import dr.evomodel.tree.TreeModel;
34 import dr.inference.model.AbstractModel;
35 import dr.inference.model.Parameter;
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 /**
43 * @author Filip Bielejec
44 * @version $Id$
45 *
46 */
47 public class LineageSpecificBranchModelParser extends AbstractXMLObjectParser {
48
49 public static final String MODELS = "models";
50 public static final String CATEGORIES = "categories";
51
52 @Override
53 public String getParserName() {
54 return LineageSpecificBranchModel.LINEAGE_SPECIFIC_BRANCH_MODEL;
55 }
56
57 @Override
58 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
59
60 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
61 FrequencyModel rootFrequencyModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
62
63 List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
64
65 XMLObject cxo = xo.getChild(MODELS);
66 for (int i = 0; i < cxo.getChildCount(); i++) {
67
68 SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i);
69 substitutionModels.add(substModel);
70
71 }//END: models loop
72
73 // TODO: check if categories numbering starts from zero
74 Parameter categories = (Parameter) xo.getElementFirstChild(CATEGORIES);
75
76 // CountableBranchCategoryProvider.CladeBranchCategoryModel provider = new CountableBranchCategoryProvider.CladeBranchCategoryModel(treeModel, categories);// false);
77
78 return new LineageSpecificBranchModel(treeModel, rootFrequencyModel, substitutionModels, //provider,
79 categories);
80 }
81
82 @Override
83 public XMLSyntaxRule[] getSyntaxRules() {
84 return new XMLSyntaxRule[]{
85
86 new ElementRule(TreeModel.class, false), //
87 new ElementRule(FrequencyModel.class, false), //
88 new ElementRule(MODELS,
89 new XMLSyntaxRule[] {
90 new ElementRule(AbstractModel.class, 1, Integer.MAX_VALUE),
91 }
92 ), //
93 new ElementRule(CATEGORIES,
94 new XMLSyntaxRule[] {
95 new ElementRule(Parameter.class, 1, 1),
96 }
97 ) //
98
99
100 };
101 }
102
103 @Override
104 public String getParserDescription() {
105 return "This element provides a branch model which has branches assigned to specific substitution models." +
106 "These assignments can then be changed in course of MCMC.";
107 }
108
109 @Override
110 public Class getReturnType() {
111 return LineageSpecificBranchModel.class;
112 }
113
114 }//END: class