Debian Codegraph @

src/dr/oldevomodelxml/sitemodel/CategorySiteModelParser.java

raw symbols SCIP
1 /*
2 * CategorySiteModelParser.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.CategorySiteModel;
29 import dr.oldevomodel.substmodel.SubstitutionModel;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32
33 /**
34 */
35 public class CategorySiteModelParser extends AbstractXMLObjectParser {
36
37 public static final String SITE_MODEL = "categorySiteModel";
38 public static final String SUBSTITUTION_MODEL = "substitutionModel";
39 public static final String MUTATION_RATE = "mutationRate";
40 public static final String RATE_PARAMETER = "rates";
41 public static final String CATEGORIES = "categories";
42 public static final String CATEGORY_STATES = "states";
43 public static final String CATEGORY_STRING = "values";
44 public static final String RELATIVE_TO = "relativeTo";
45
46 public String getParserName() {
47 return SITE_MODEL;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 XMLObject cxo = xo.getChild(SUBSTITUTION_MODEL);
53 SubstitutionModel substitutionModel = (SubstitutionModel) cxo.getChild(SubstitutionModel.class);
54
55 cxo = xo.getChild(MUTATION_RATE);
56 Parameter muParam = (Parameter) cxo.getChild(Parameter.class);
57
58 cxo = xo.getChild(RATE_PARAMETER);
59 Parameter rateParam = null;
60 int relativeTo = 0;
61 if (cxo != null) {
62 rateParam = (Parameter) cxo.getChild(Parameter.class);
63 relativeTo = cxo.getIntegerAttribute(RELATIVE_TO);
64 }
65
66 cxo = xo.getChild(CATEGORIES);
67 String categories = "";
68 String states = "";
69 if (cxo != null) {
70 categories = cxo.getStringAttribute(CATEGORY_STRING);
71 states = cxo.getStringAttribute(CATEGORY_STATES);
72 }
73
74 return new CategorySiteModel(substitutionModel, muParam, rateParam, categories, states, relativeTo);
75
76 }
77
78 //************************************************************************
79 // AbstractXMLObjectParser implementation
80 //************************************************************************
81
82 public String getParserDescription() {
83 return "A SiteModel that has a gamma distributed rates across sites";
84 }
85
86 public Class getReturnType() {
87 return CategorySiteModel.class;
88 }
89
90 public XMLSyntaxRule[] getSyntaxRules() {
91 return rules;
92 }
93
94 private final XMLSyntaxRule[] rules = {
95 new ElementRule(SUBSTITUTION_MODEL, new XMLSyntaxRule[]{
96 new ElementRule(SubstitutionModel.class)
97 }),
98 new ElementRule(MUTATION_RATE, new XMLSyntaxRule[]{
99 new ElementRule(Parameter.class)
100 }),
101 new ElementRule(RATE_PARAMETER, new XMLSyntaxRule[]{
102 AttributeRule.newIntegerRule(RELATIVE_TO, true),
103 new ElementRule(Parameter.class)
104 }, true),
105 new ElementRule(CATEGORIES, new XMLSyntaxRule[]{
106 AttributeRule.newStringRule(CATEGORY_STRING, true),
107 AttributeRule.newStringRule(CATEGORY_STATES, true)
108 }, true),
109 };
110
111 }