Debian Codegraph @

src/dr/oldevomodelxml/MSSD/ALSSiteModelParser.java

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