| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 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 |
|
| 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 |
} |