Debian Codegraph @

src/dr/evomodelxml/substmodel/GY94CodonModelParser.java

raw symbols SCIP
1 /*
2 * GY94CodonModelParser.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.inference.model.Parameter;
29 import dr.xml.*;
30 import dr.evomodel.substmodel.FrequencyModel;
31 import dr.evomodel.substmodel.codon.GY94CodonModel;
32 import dr.evolution.datatype.Codons;
33 import dr.evolution.datatype.GeneticCode;
34
35 /**
36 * @author Alexei Drummond
37 * @author Andrew Rambaut
38 */
39 public class GY94CodonModelParser extends AbstractXMLObjectParser {
40
41 public static final String YANG_CODON_MODEL = "yangCodonModel";
42 public static final String OMEGA = "omega";
43 public static final String KAPPA = "kappa";
44
45
46 public String getParserName() { return YANG_CODON_MODEL; }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50 Codons codons = Codons.UNIVERSAL;
51 if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
52 String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE);
53 codons = Codons.findByName(codeStr);
54 }
55
56 Parameter omegaParameter = (Parameter)xo.getElementFirstChild(OMEGA);
57
58 int dim = omegaParameter.getDimension();
59 double value = omegaParameter.getParameterValue(dim - 1);
60 if(value < 0) {
61 throw new RuntimeException("Negative Omega parameter value " + value);
62 }//END: negative check
63
64 Parameter kappaParameter = (Parameter)xo.getElementFirstChild(KAPPA);
65
66 dim = kappaParameter.getDimension();
67 value = kappaParameter.getParameterValue(dim - 1);
68 if(value < 0) {
69 throw new RuntimeException("Negative kappa parameter value value " + value);
70 }//END: negative check
71
72 FrequencyModel freqModel = (FrequencyModel)xo.getChild(FrequencyModel.class);
73 GY94CodonModel codonModel = new GY94CodonModel(codons, omegaParameter, kappaParameter, freqModel);
74
75 // codonModel.printRateMap();
76
77 return codonModel;
78 }
79
80 //************************************************************************
81 // AbstractXMLObjectParser implementation
82 //************************************************************************
83
84 public String getParserDescription() {
85 return "This element represents the Yang model of codon evolution.";
86 }
87
88 public Class getReturnType() { return GY94CodonModel.class; }
89
90 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
91
92 private XMLSyntaxRule[] rules = new XMLSyntaxRule[] {
93 new StringAttributeRule(GeneticCode.GENETIC_CODE,
94 "The genetic code to use",
95 GeneticCode.GENETIC_CODE_NAMES, true),
96 new ElementRule(OMEGA,
97 new XMLSyntaxRule[] { new ElementRule(Parameter.class) }),
98 new ElementRule(KAPPA,
99 new XMLSyntaxRule[] { new ElementRule(Parameter.class) }),
100 new ElementRule(FrequencyModel.class)
101 };
102
103 }