| 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.ColtEigenSystem; |
| 29 |
import dr.evomodel.substmodel.FrequencyModel; |
| 30 |
import dr.evomodel.substmodel.codon.MarkovModulatedGY94CodonModel; |
| 31 |
import dr.evolution.datatype.DataType; |
| 32 |
import dr.evolution.datatype.GeneticCode; |
| 33 |
import dr.evolution.datatype.HiddenCodons; |
| 34 |
import dr.evomodel.substmodel.DefaultEigenSystem; |
| 35 |
import dr.evomodel.substmodel.EigenSystem; |
| 36 |
import dr.evoxml.util.DataTypeUtils; |
| 37 |
import dr.inference.model.Parameter; |
| 38 |
import dr.xml.*; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public class MarkovModulatedGY94CodonModelParser extends GY94CodonModelParser { |
| 44 |
|
| 45 |
public static final String MARKOV_MODULATED_YANG_MODEL = "markovModulatedYangCodonModel"; |
| 46 |
public static final String HIDDEN_COUNT = "hiddenCount"; |
| 47 |
public static final String SWITCHING_RATES = "switchingRates"; |
| 48 |
public static final String DIAGONALIZATION = "diagonalization"; |
| 49 |
|
| 50 |
public String getParserName() { |
| 51 |
return MARKOV_MODULATED_YANG_MODEL; |
| 52 |
} |
| 53 |
|
| 54 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 55 |
|
| 56 |
DataType dataType = DataTypeUtils.getDataType(xo); |
| 57 |
HiddenCodons codons; |
| 58 |
if (dataType instanceof HiddenCodons) |
| 59 |
codons = (HiddenCodons) dataType; |
| 60 |
else |
| 61 |
throw new XMLParseException("Must construct " + MARKOV_MODULATED_YANG_MODEL + " with hidden codons"); |
| 62 |
|
| 63 |
Parameter omegaParam = (Parameter) xo.getElementFirstChild(OMEGA); |
| 64 |
Parameter kappaParam = (Parameter) xo.getElementFirstChild(KAPPA); |
| 65 |
Parameter switchingParam = (Parameter) xo.getElementFirstChild(SWITCHING_RATES); |
| 66 |
FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class); |
| 67 |
|
| 68 |
EigenSystem eigenSystem; |
| 69 |
if (xo.getAttribute(DIAGONALIZATION, "default").compareToIgnoreCase("colt") == 0) |
| 70 |
eigenSystem = new ColtEigenSystem(dataType.getStateCount()); |
| 71 |
else |
| 72 |
eigenSystem = new DefaultEigenSystem(dataType.getStateCount()); |
| 73 |
|
| 74 |
return new MarkovModulatedGY94CodonModel(codons, switchingParam, omegaParam, kappaParam, freqModel, eigenSystem); |
| 75 |
} |
| 76 |
|
| 77 |
public String getParserDescription() { |
| 78 |
return "This element represents the a Markov-modulated Yang model of codon evolution."; |
| 79 |
} |
| 80 |
|
| 81 |
public Class getReturnType() { |
| 82 |
return MarkovModulatedGY94CodonModel.class; |
| 83 |
} |
| 84 |
|
| 85 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 86 |
return rules; |
| 87 |
} |
| 88 |
|
| 89 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 90 |
|
| 91 |
AttributeRule.newStringRule(DataType.DATA_TYPE), |
| 92 |
AttributeRule.newStringRule(GeneticCode.GENETIC_CODE), |
| 93 |
new ElementRule(OMEGA, |
| 94 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 95 |
new ElementRule(KAPPA, |
| 96 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 97 |
new ElementRule(SWITCHING_RATES, |
| 98 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 99 |
new ElementRule(FrequencyModel.class), |
| 100 |
AttributeRule.newStringRule(DIAGONALIZATION), |
| 101 |
}; |
| 102 |
|
| 103 |
} |