Debian Codegraph @

src/dr/oldevomodelxml/substmodel/YangCodonModelParser.java

raw symbols SCIP
1 /*
2 * YangCodonModelParser.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.Codons;
29 import dr.evolution.datatype.GeneticCode;
30 import dr.oldevomodel.substmodel.FrequencyModel;
31 import dr.oldevomodel.substmodel.YangCodonModel;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 /**
36 * Reads a the model from an XMLObject.
37 */
38 public class YangCodonModelParser extends AbstractXMLObjectParser {
39 public static final String YANG_CODON_MODEL = "yangCodonModel";
40 public static final String OMEGA = "omega";
41 public static final String KAPPA = "kappa";
42
43
44 public String getParserName() { return YANG_CODON_MODEL; }
45
46 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
47
48 Codons codons = Codons.UNIVERSAL;
49 if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
50 String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE);
51 if (codeStr.equals(GeneticCode.UNIVERSAL.getName())) {
52 codons = Codons.UNIVERSAL;
53 } else if (codeStr.equals(GeneticCode.VERTEBRATE_MT.getName())) {
54 codons = Codons.VERTEBRATE_MT;
55 } else if (codeStr.equals(GeneticCode.YEAST.getName())) {
56 codons = Codons.YEAST;
57 } else if (codeStr.equals(GeneticCode.MOLD_PROTOZOAN_MT.getName())) {
58 codons = Codons.MOLD_PROTOZOAN_MT;
59 } else if (codeStr.equals(GeneticCode.INVERTEBRATE_MT.getName())) {
60 codons = Codons.INVERTEBRATE_MT;
61 } else if (codeStr.equals(GeneticCode.CILIATE.getName())) {
62 codons = Codons.CILIATE;
63 } else if (codeStr.equals(GeneticCode.ECHINODERM_MT.getName())) {
64 codons = Codons.ECHINODERM_MT;
65 } else if (codeStr.equals(GeneticCode.EUPLOTID_NUC.getName())) {
66 codons = Codons.EUPLOTID_NUC;
67 } else if (codeStr.equals(GeneticCode.BACTERIAL.getName())) {
68 codons = Codons.BACTERIAL;
69 } else if (codeStr.equals(GeneticCode.ALT_YEAST.getName())) {
70 codons = Codons.ALT_YEAST;
71 } else if (codeStr.equals(GeneticCode.ASCIDIAN_MT.getName())) {
72 codons = Codons.ASCIDIAN_MT;
73 } else if (codeStr.equals(GeneticCode.FLATWORM_MT.getName())) {
74 codons = Codons.FLATWORM_MT;
75 } else if (codeStr.equals(GeneticCode.BLEPHARISMA_NUC.getName())) {
76 codons = Codons.BLEPHARISMA_NUC;
77 } else if (codeStr.equals(GeneticCode.NO_STOPS.getName())) {
78 codons = Codons.NO_STOPS;
79 }
80 }
81
82 Parameter omegaParam = (Parameter)xo.getElementFirstChild(OMEGA);
83 Parameter kappaParam = (Parameter)xo.getElementFirstChild(KAPPA);
84 FrequencyModel freqModel = (FrequencyModel)xo.getChild(FrequencyModel.class);
85
86 // codonModel.printRateMap();
87
88 return new YangCodonModel(codons, omegaParam, kappaParam, freqModel);
89 }
90
91 //************************************************************************
92 // AbstractXMLObjectParser implementation
93 //************************************************************************
94
95 public String getParserDescription() {
96 return "This element represents the Yang model of codon evolution.";
97 }
98
99 public Class getReturnType() { return YangCodonModel.class; }
100
101 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
102
103 private XMLSyntaxRule[] rules = new XMLSyntaxRule[] {
104 new StringAttributeRule(GeneticCode.GENETIC_CODE,
105 "The genetic code to use",
106 new String[] {
107 GeneticCode.UNIVERSAL.getName(),
108 GeneticCode.VERTEBRATE_MT.getName(),
109 GeneticCode.YEAST.getName(),
110 GeneticCode.MOLD_PROTOZOAN_MT.getName(),
111 GeneticCode.INVERTEBRATE_MT.getName(),
112 GeneticCode.CILIATE.getName(),
113 GeneticCode.ECHINODERM_MT.getName(),
114 GeneticCode.EUPLOTID_NUC.getName(),
115 GeneticCode.BACTERIAL.getName(),
116 GeneticCode.ALT_YEAST.getName(),
117 GeneticCode.ASCIDIAN_MT.getName(),
118 GeneticCode.FLATWORM_MT.getName(),
119 GeneticCode.BLEPHARISMA_NUC.getName(),
120 GeneticCode.NO_STOPS.getName()}, true),
121 new ElementRule(OMEGA,
122 new XMLSyntaxRule[] { new ElementRule(Parameter.class) }),
123 new ElementRule(KAPPA,
124 new XMLSyntaxRule[] { new ElementRule(Parameter.class) }),
125 new ElementRule(FrequencyModel.class)
126 };
127 }