Debian Codegraph @

src/dr/oldevomodelxml/sitemodel/GammaSiteBMAParser.java

raw symbols SCIP
1 /*
2 * GammaSiteBMAParser.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.xml.*;
29 import dr.oldevomodel.sitemodel.GammaSiteBMA;
30 import dr.oldevomodel.substmodel.SubstitutionModel;
31 import dr.inference.model.Parameter;
32 import dr.inference.model.Variable;
33
34 /**
35 * @author Chieh-Hsi Wu
36 *
37 * Parser for Gamma site BMA.
38 *
39 */
40 public class GammaSiteBMAParser extends AbstractXMLObjectParser {
41
42 public static final String SUBSTITUTION_MODEL = "substitutionModel";
43 public static final String MUTATION_RATE = "mutationRate";
44 public static final String LOG_GAMMA_SHAPE = "logGammaShape";
45 public static final String GAMMA_CATEGORIES = "gammaCategories";
46 public static final String LOGIT_PROPORTION_INVARIANT = "logitProportionInvariant";
47 public static final String MODEL_CHOOSE = "modelChoose";
48 public static final String GAMMA_SITE_BMA = "gammaSiteBMA";
49
50 public String getParserName() {
51 return GAMMA_SITE_BMA;
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55 SubstitutionModel substitutionModel = (SubstitutionModel) xo.getElementFirstChild(SUBSTITUTION_MODEL);
56
57 Parameter muParam = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
58
59 Parameter logitInvar = (Parameter) xo.getElementFirstChild(LOGIT_PROPORTION_INVARIANT);
60
61 final XMLObject cxo = xo.getChild(LOG_GAMMA_SHAPE);
62 Parameter logShape = (Parameter) cxo.getChild(Parameter.class);
63
64 int catCount = cxo.getIntegerAttribute(GAMMA_CATEGORIES);
65
66 Variable<Integer> modelChoose = (Variable<Integer>) xo.getElementFirstChild(MODEL_CHOOSE);
67
68 return new GammaSiteBMA(substitutionModel, muParam, logitInvar, logShape, catCount, modelChoose);
69 }
70
71 public String getParserDescription() {
72 return "A SiteModel that does BMA for a gamma distributed rates across sites";
73 }
74
75 public Class getReturnType() {
76 return GammaSiteBMA.class;
77 }
78
79 public XMLSyntaxRule[] getSyntaxRules() {
80 return rules;
81 }
82
83 private final XMLSyntaxRule[] rules = {
84 new ElementRule(SUBSTITUTION_MODEL, new XMLSyntaxRule[]{
85 new ElementRule(SubstitutionModel.class)
86 }),
87 new ElementRule(MUTATION_RATE, new XMLSyntaxRule[]{
88 new ElementRule(Parameter.class)
89 }),
90 new ElementRule(LOG_GAMMA_SHAPE, new XMLSyntaxRule[]{
91 AttributeRule.newIntegerRule(GAMMA_CATEGORIES),
92 new ElementRule(Parameter.class)
93 }),
94 new ElementRule(LOGIT_PROPORTION_INVARIANT, new XMLSyntaxRule[]{
95 new ElementRule(Parameter.class)
96 }),
97 new ElementRule(MODEL_CHOOSE, new XMLSyntaxRule[]{
98 new ElementRule(Variable.class)
99 })
100 };
101
102 }