Debian Codegraph @

src/dr/oldevomodelxml/substmodel/CovarionGTRParser.java

raw symbols SCIP
1 /*
2 * CovarionGTRParser.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.substmodel;
27
28 import dr.evolution.datatype.OldHiddenNucleotides;
29 import dr.oldevomodel.substmodel.AbstractCovarionDNAModel;
30 import dr.oldevomodel.substmodel.CovarionGTR;
31 import dr.oldevomodel.substmodel.FrequencyModel;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 /**
36 * Parses an element from an DOM document into a TwoStateCovarionModel
37 */
38 public class CovarionGTRParser extends AbstractXMLObjectParser {
39 public static final String GTR_COVARION_MODEL = "gtrCovarionModel";
40
41 public String getParserName() {
42 return GTR_COVARION_MODEL;
43 }
44
45 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
46
47 XMLObject cxo = xo.getChild(AbstractCovarionDNAModel.FREQUENCIES);
48 FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
49
50 OldHiddenNucleotides dataType = (OldHiddenNucleotides) freqModel.getDataType();
51
52 Parameter hiddenRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.HIDDEN_CLASS_RATES);
53 Parameter switchingRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.SWITCHING_RATES);
54
55 Parameter rateACParameter = null;
56 if (xo.hasChildNamed(GTRParser.A_TO_C)) {
57 rateACParameter = (Parameter) xo.getElementFirstChild(GTRParser.A_TO_C);
58 }
59 Parameter rateAGParameter = null;
60 if (xo.hasChildNamed(GTRParser.A_TO_G)) {
61 rateAGParameter = (Parameter) xo.getElementFirstChild(GTRParser.A_TO_G);
62 }
63 Parameter rateATParameter = null;
64 if (xo.hasChildNamed(GTRParser.A_TO_T)) {
65 rateATParameter = (Parameter) xo.getElementFirstChild(GTRParser.A_TO_T);
66 }
67 Parameter rateCGParameter = null;
68 if (xo.hasChildNamed(GTRParser.C_TO_G)) {
69 rateCGParameter = (Parameter) xo.getElementFirstChild(GTRParser.C_TO_G);
70 }
71 Parameter rateCTParameter = null;
72 if (xo.hasChildNamed(GTRParser.C_TO_T)) {
73 rateCTParameter = (Parameter) xo.getElementFirstChild(GTRParser.C_TO_T);
74 }
75 Parameter rateGTParameter = null;
76 if (xo.hasChildNamed(GTRParser.G_TO_T)) {
77 rateGTParameter = (Parameter) xo.getElementFirstChild(GTRParser.G_TO_T);
78 }
79
80
81 if (dataType != freqModel.getDataType()) {
82 throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its frequencyModel.");
83 }
84
85 return new CovarionGTR(
86 dataType,
87 hiddenRates,
88 switchingRates,
89 rateACParameter,
90 rateAGParameter,
91 rateATParameter,
92 rateCGParameter,
93 rateCTParameter,
94 rateGTParameter,
95 freqModel);
96 }
97
98 //************************************************************************
99 // AbstractXMLObjectParser implementation
100 //************************************************************************
101
102 public String getParserDescription() {
103 return "A covarion substitution model of langauge evolution with binary data and a hidden rate state with two rates.";
104 }
105
106 public Class getReturnType() {
107 return CovarionGTR.class;
108 }
109
110 public XMLSyntaxRule[] getSyntaxRules() {
111 return rules;
112 }
113
114 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
115 new ElementRule(GTRParser.A_TO_C, Parameter.class, "relative rate of A<->C substitution", true),
116 new ElementRule(GTRParser.A_TO_G, Parameter.class, "relative rate of A<->G substitution", true),
117 new ElementRule(GTRParser.A_TO_T, Parameter.class, "relative rate of A<->T substitution", true),
118 new ElementRule(GTRParser.C_TO_G, Parameter.class, "relative rate of C<->G substitution", true),
119 new ElementRule(GTRParser.C_TO_T, Parameter.class, "relative rate of C<->T substitution", true),
120 new ElementRule(GTRParser.G_TO_T, Parameter.class, "relative rate of G<->T substitution", true),
121 new ElementRule(AbstractCovarionDNAModel.HIDDEN_CLASS_RATES, Parameter.class),
122 new ElementRule(AbstractCovarionDNAModel.SWITCHING_RATES, Parameter.class),
123 new ElementRule(AbstractCovarionDNAModel.FREQUENCIES, FrequencyModel.class),
124 };
125
126
127
128 }