Debian Codegraph @

src/dr/oldevomodelxml/sitemodel/GammaSiteModelParser.java

raw symbols SCIP
1 /*
2 * GammaSiteModelParser.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.GammaSiteModel;
29 import dr.oldevomodel.sitemodel.SiteModel;
30 import dr.oldevomodel.substmodel.SubstitutionModel;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 import java.util.logging.Logger;
35
36 /**
37 */
38 public class GammaSiteModelParser extends AbstractXMLObjectParser {
39
40 public static final String SUBSTITUTION_MODEL = "substitutionModel";
41 public static final String MUTATION_RATE = "mutationRate";
42 public static final String SUBSTITUTION_RATE = "substitutionRate";
43 public static final String RELATIVE_RATE = "relativeRate";
44 public static final String GAMMA_SHAPE = "gammaShape";
45 public static final String GAMMA_CATEGORIES = "gammaCategories";
46 public static final String PROPORTION_INVARIANT = "proportionInvariant";
47
48
49 public String[] getParserNames() {
50 return new String[]{
51 getParserName(), "beast_" + getParserName()
52 };
53 }
54
55 public String getParserName() {
56 return SiteModel.SITE_MODEL;
57 }
58
59 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
60 SubstitutionModel substitutionModel = (SubstitutionModel) xo.getElementFirstChild(SUBSTITUTION_MODEL);
61
62 String msg = "";
63
64 Parameter muParam = null;
65 if (xo.hasChildNamed(SUBSTITUTION_RATE)) {
66 muParam = (Parameter) xo.getElementFirstChild(SUBSTITUTION_RATE);
67
68 msg += "\n with initial substitution rate = " + muParam.getParameterValue(0);
69 } else if (xo.hasChildNamed(MUTATION_RATE)) {
70 muParam = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
71
72 msg += "\n with initial substitution rate = " + muParam.getParameterValue(0);
73 } else if (xo.hasChildNamed(RELATIVE_RATE)) {
74 muParam = (Parameter) xo.getElementFirstChild(RELATIVE_RATE);
75
76 msg += "\n with initial relative rate = " + muParam.getParameterValue(0);
77 }
78
79 Parameter shapeParam = null;
80 int catCount = 4;
81 if (xo.hasChildNamed(GAMMA_SHAPE)) {
82 final XMLObject cxo = xo.getChild(GAMMA_SHAPE);
83 catCount = cxo.getIntegerAttribute(GAMMA_CATEGORIES);
84 shapeParam = (Parameter) cxo.getChild(Parameter.class);
85
86 msg += "\n " + catCount + " category discrete gamma with initial shape = " + shapeParam.getParameterValue(0);
87 }
88
89 Parameter invarParam = null;
90 if (xo.hasChildNamed(PROPORTION_INVARIANT)) {
91 invarParam = (Parameter) xo.getElementFirstChild(PROPORTION_INVARIANT);
92 msg += "\n initial proportion of invariant sites = " + invarParam.getParameterValue(0);
93 }
94
95 Logger.getLogger("dr.evomodel").info("Creating site model." + (msg.length() > 0 ? msg : ""));
96
97 return new GammaSiteModel(substitutionModel, muParam, shapeParam, catCount, invarParam);
98 }
99
100 //************************************************************************
101 // AbstractXMLObjectParser implementation
102 //************************************************************************
103
104 public String getParserDescription() {
105 return "A SiteModel that has a gamma distributed rates across sites";
106 }
107
108 public Class getReturnType() {
109 return GammaSiteModel.class;
110 }
111
112 public XMLSyntaxRule[] getSyntaxRules() {
113 return rules;
114 }
115
116 private final XMLSyntaxRule[] rules = {
117 new ElementRule(SUBSTITUTION_MODEL, new XMLSyntaxRule[]{
118 new ElementRule(SubstitutionModel.class)
119 }),
120 new XORRule(
121 new XORRule(
122 new ElementRule(SUBSTITUTION_RATE, new XMLSyntaxRule[]{
123 new ElementRule(Parameter.class)
124 }),
125 new ElementRule(MUTATION_RATE, new XMLSyntaxRule[]{
126 new ElementRule(Parameter.class)
127 })
128 ),
129 new ElementRule(RELATIVE_RATE, new XMLSyntaxRule[]{
130 new ElementRule(Parameter.class)
131 }), true
132 ),
133 new ElementRule(GAMMA_SHAPE, new XMLSyntaxRule[]{
134 AttributeRule.newIntegerRule(GAMMA_CATEGORIES, true),
135 new ElementRule(Parameter.class)
136 }, true),
137 new ElementRule(PROPORTION_INVARIANT, new XMLSyntaxRule[]{
138 new ElementRule(Parameter.class)
139 }, true)
140 };
141 }