Debian Codegraph @

src/dr/oldevomodelxml/sitemodel/SampleStateAndCategoryModelParser.java

raw symbols SCIP
1 /*
2 * SampleStateAndCategoryModelParser.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.oldevomodelxml.sitemodel;
27
28 import dr.oldevomodel.sitemodel.SampleStateAndCategoryModel;
29 import dr.oldevomodel.substmodel.SubstitutionModel;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32
33 import java.util.Vector;
34
35 /**
36 *
37 */
38 public class SampleStateAndCategoryModelParser extends AbstractXMLObjectParser {
39
40 public static final String SAMPLE_STATE_AND_CATEGORY_MODEL = "sampleStateAndCategoryModel";
41 public static final String MUTATION_RATE = "mutationRate";
42 public static final String CATEGORY_PARAMETER = "categoriesParameter";
43
44 public String getParserName() {
45 return SAMPLE_STATE_AND_CATEGORY_MODEL;
46 }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50 XMLObject cxo = xo.getChild(MUTATION_RATE);
51 Parameter muParam = (Parameter) cxo.getChild(Parameter.class);
52
53 cxo = xo.getChild(CATEGORY_PARAMETER);
54 Parameter catParam = (Parameter) cxo.getChild(Parameter.class);
55
56 Vector subModels = new Vector();
57 for (int i = 0; i < xo.getChildCount(); i++) {
58
59 if (xo.getChild(i) instanceof SubstitutionModel) {
60 subModels.addElement(xo.getChild(i));
61 }
62
63 }
64
65 return new SampleStateAndCategoryModel(muParam, catParam, subModels);
66
67 }
68 //************************************************************************
69 // AbstractXMLObjectParser implementation
70 //************************************************************************
71
72 public String getParserDescription() {
73 return "A SiteModel that has a discrete distribution of substitution models over sites, " +
74 "designed for sampling of rate categories and internal states.";
75 }
76
77 public Class getReturnType() {
78 return SampleStateAndCategoryModel.class;
79 }
80
81 public XMLSyntaxRule[] getSyntaxRules() {
82 return rules;
83 }
84
85 private final XMLSyntaxRule[] rules = {
86 new ElementRule(MUTATION_RATE,
87 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
88 new ElementRule(CATEGORY_PARAMETER,
89 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
90 new ElementRule(SubstitutionModel.class, 1, Integer.MAX_VALUE)
91 };
92
93 }