Debian Codegraph @

src/dr/evomodelxml/substmodel/MarkovModulatedGY94CodonModelParser.java

raw symbols SCIP
1 /*
2 * MarkovModulatedGY94CodonModelParser.java
3 *
4 * Copyright (c) 2002-2016 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.evomodelxml.substmodel;
27
28 import dr.evomodel.substmodel.ColtEigenSystem;
29 import dr.evomodel.substmodel.FrequencyModel;
30 import dr.evomodel.substmodel.codon.MarkovModulatedGY94CodonModel;
31 import dr.evolution.datatype.DataType;
32 import dr.evolution.datatype.GeneticCode;
33 import dr.evolution.datatype.HiddenCodons;
34 import dr.evomodel.substmodel.DefaultEigenSystem;
35 import dr.evomodel.substmodel.EigenSystem;
36 import dr.evoxml.util.DataTypeUtils;
37 import dr.inference.model.Parameter;
38 import dr.xml.*;
39
40 /**
41 * @author Marc A. Suchard
42 */
43 public class MarkovModulatedGY94CodonModelParser extends GY94CodonModelParser {
44
45 public static final String MARKOV_MODULATED_YANG_MODEL = "markovModulatedYangCodonModel";
46 public static final String HIDDEN_COUNT = "hiddenCount";
47 public static final String SWITCHING_RATES = "switchingRates";
48 public static final String DIAGONALIZATION = "diagonalization";
49
50 public String getParserName() {
51 return MARKOV_MODULATED_YANG_MODEL;
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55
56 DataType dataType = DataTypeUtils.getDataType(xo);
57 HiddenCodons codons;
58 if (dataType instanceof HiddenCodons)
59 codons = (HiddenCodons) dataType;
60 else
61 throw new XMLParseException("Must construct " + MARKOV_MODULATED_YANG_MODEL + " with hidden codons");
62
63 Parameter omegaParam = (Parameter) xo.getElementFirstChild(OMEGA);
64 Parameter kappaParam = (Parameter) xo.getElementFirstChild(KAPPA);
65 Parameter switchingParam = (Parameter) xo.getElementFirstChild(SWITCHING_RATES);
66 FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
67
68 EigenSystem eigenSystem;
69 if (xo.getAttribute(DIAGONALIZATION, "default").compareToIgnoreCase("colt") == 0)
70 eigenSystem = new ColtEigenSystem(dataType.getStateCount());
71 else
72 eigenSystem = new DefaultEigenSystem(dataType.getStateCount());
73
74 return new MarkovModulatedGY94CodonModel(codons, switchingParam, omegaParam, kappaParam, freqModel, eigenSystem);
75 }
76
77 public String getParserDescription() {
78 return "This element represents the a Markov-modulated Yang model of codon evolution.";
79 }
80
81 public Class getReturnType() {
82 return MarkovModulatedGY94CodonModel.class;
83 }
84
85 public XMLSyntaxRule[] getSyntaxRules() {
86 return rules;
87 }
88
89 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
90
91 AttributeRule.newStringRule(DataType.DATA_TYPE),
92 AttributeRule.newStringRule(GeneticCode.GENETIC_CODE),
93 new ElementRule(OMEGA,
94 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
95 new ElementRule(KAPPA,
96 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
97 new ElementRule(SWITCHING_RATES,
98 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
99 new ElementRule(FrequencyModel.class),
100 AttributeRule.newStringRule(DIAGONALIZATION),
101 };
102
103 }