Debian Codegraph @

src/dr/evomodelxml/substmodel/EmpiricalAminoAcidModelParser.java

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