Debian Codegraph @

src/dr/oldevomodelxml/substmodel/EmpiricalAminoAcidModelParser.java

raw symbols SCIP
1 /*
2 * EmpiricalAminoAcidModelParser.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.evomodel.substmodel.*;
29 import dr.evomodel.substmodel.aminoacid.*;
30 import dr.xml.*;
31
32 /**
33 * Parses an element from an DOM document into a DemographicModel. Recognises
34 * ConstantPopulation and ExponentialGrowth.
35 */
36 public class EmpiricalAminoAcidModelParser extends AbstractXMLObjectParser {
37
38 public static final String EMPIRICAL_AMINO_ACID_MODEL = "aminoAcidModel";
39 public static final String FREQUENCIES = "frequencies";
40 public static final String TYPE = "type";
41
42
43 public String getParserName() {
44 return EMPIRICAL_AMINO_ACID_MODEL;
45 }
46
47 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
48
49 FrequencyModel freqModel = null;
50
51 if (xo.hasAttribute(FREQUENCIES)) {
52 XMLObject cxo = xo.getChild(FREQUENCIES);
53 freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
54 }
55
56 EmpiricalRateMatrix rateMatrix = null;
57
58 String type = xo.getStringAttribute(TYPE);
59
60 if (type.equals(AminoAcidModelType.BLOSUM_62.getXMLName())) {
61 rateMatrix = Blosum62.INSTANCE;
62 } else if (type.equals(AminoAcidModelType.DAYHOFF.getXMLName())) {
63 rateMatrix = Dayhoff.INSTANCE;
64 } else if (type.equals(AminoAcidModelType.JTT.getXMLName())) {
65 rateMatrix = JTT.INSTANCE;
66 } else if (type.equals(AminoAcidModelType.MT_REV_24.getXMLName())) {
67 rateMatrix = MTREV.INSTANCE;
68 } else if (type.equals(AminoAcidModelType.CP_REV_45.getXMLName())) {
69 rateMatrix = CPREV.INSTANCE;
70 } else if (type.equals(AminoAcidModelType.WAG.getXMLName())) {
71 rateMatrix = WAG.INSTANCE;
72 } else if (type.equals(AminoAcidModelType.FLU.getXMLName())) {
73 rateMatrix = FLU.INSTANCE;
74 } else if (type.equals(AminoAcidModelType.LG.getXMLName())) {
75 rateMatrix = LG.INSTANCE;
76 }
77
78 return new EmpiricalAminoAcidModel(rateMatrix, freqModel);
79 }
80
81 //************************************************************************
82 // AbstractXMLObjectParser implementation
83 //************************************************************************
84
85 public XMLSyntaxRule[] getSyntaxRules() {
86 return rules;
87 }
88
89 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
90 new StringAttributeRule(TYPE, "The type of empirical amino-acid rate matrix", AminoAcidModelType.xmlNames(), false),
91 new ElementRule(FREQUENCIES, FrequencyModel.class, "If the frequencies are omitted than the empirical frequencies associated with the selected model are used.", true)
92 };
93
94 public String getParserDescription() {
95 return "An empirical amino acid substitution model.";
96 }
97
98 public Class getReturnType() {
99 return EmpiricalAminoAcidModel.class;
100 }
101
102
103 }