| 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.FrequencyModel; |
| 29 |
import dr.evomodel.substmodel.codon.MG94CodonModel; |
| 30 |
import dr.evomodel.substmodel.codon.MG94HKYCodonModel; |
| 31 |
import dr.evolution.datatype.Codons; |
| 32 |
import dr.evolution.datatype.GeneticCode; |
| 33 |
import dr.evomodel.substmodel.nucleotide.GTR; |
| 34 |
import dr.inference.model.Parameter; |
| 35 |
import dr.xml.*; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class MG94CodonModelParser extends AbstractXMLObjectParser { |
| 43 |
|
| 44 |
public static final String MUSE_CODON_MODEL = "museGautCodonModel"; |
| 45 |
public static final String ALPHA = "alpha"; |
| 46 |
public static final String BETA = "beta"; |
| 47 |
public static final String KAPPA = GY94CodonModelParser.KAPPA; |
| 48 |
public static final String NORMALIZED = ComplexSubstitutionModelParser.NORMALIZED; |
| 49 |
|
| 50 |
|
| 51 |
public static final String GTR_MODEL = GTRParser.GTR_MODEL; |
| 52 |
public static final String A_TO_C = GTRParser.A_TO_C; |
| 53 |
public static final String A_TO_G = GTRParser.A_TO_G; |
| 54 |
public static final String A_TO_T = GTRParser.A_TO_T; |
| 55 |
public static final String C_TO_G = GTRParser.C_TO_G; |
| 56 |
public static final String C_TO_T = GTRParser.C_TO_T; |
| 57 |
public static final String G_TO_T = GTRParser.G_TO_T; |
| 58 |
|
| 59 |
|
| 60 |
public String getParserName() { |
| 61 |
return MUSE_CODON_MODEL; |
| 62 |
} |
| 63 |
|
| 64 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 65 |
|
| 66 |
Codons codons = Codons.UNIVERSAL; |
| 67 |
if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) { |
| 68 |
String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE); |
| 69 |
codons = Codons.findByName(codeStr); |
| 70 |
} |
| 71 |
|
| 72 |
Parameter alphaParam = (Parameter) xo.getElementFirstChild(ALPHA); |
| 73 |
Parameter betaParam = (Parameter) xo.getElementFirstChild(BETA); |
| 74 |
FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class); |
| 75 |
|
| 76 |
MG94CodonModel codonModel; |
| 77 |
if (xo.hasChildNamed(GTR_MODEL)) { |
| 78 |
|
| 79 |
codonModel = new MG94CodonModel(codons, alphaParam, betaParam, freqModel); |
| 80 |
|
| 81 |
Parameter rateACValue = null; |
| 82 |
if (xo.hasChildNamed(A_TO_C)) { |
| 83 |
rateACValue = (Parameter) xo.getElementFirstChild(A_TO_C); |
| 84 |
} |
| 85 |
Parameter rateAGValue = null; |
| 86 |
if (xo.hasChildNamed(A_TO_G)) { |
| 87 |
rateAGValue = (Parameter) xo.getElementFirstChild(A_TO_G); |
| 88 |
} |
| 89 |
Parameter rateATValue = null; |
| 90 |
if (xo.hasChildNamed(A_TO_T)) { |
| 91 |
rateATValue = (Parameter) xo.getElementFirstChild(A_TO_T); |
| 92 |
} |
| 93 |
Parameter rateCGValue = null; |
| 94 |
if (xo.hasChildNamed(C_TO_G)) { |
| 95 |
rateCGValue = (Parameter) xo.getElementFirstChild(C_TO_G); |
| 96 |
} |
| 97 |
Parameter rateCTValue = null; |
| 98 |
if (xo.hasChildNamed(C_TO_T)) { |
| 99 |
rateCTValue = (Parameter) xo.getElementFirstChild(C_TO_T); |
| 100 |
} |
| 101 |
Parameter rateGTValue = null; |
| 102 |
if (xo.hasChildNamed(G_TO_T)) { |
| 103 |
rateGTValue = (Parameter) xo.getElementFirstChild(G_TO_T); |
| 104 |
} |
| 105 |
int countNull = 0; |
| 106 |
if (rateACValue == null) countNull++; |
| 107 |
if (rateAGValue == null) countNull++; |
| 108 |
if (rateATValue == null) countNull++; |
| 109 |
if (rateCGValue == null) countNull++; |
| 110 |
if (rateCTValue == null) countNull++; |
| 111 |
if (rateGTValue == null) countNull++; |
| 112 |
|
| 113 |
if (countNull != 1) |
| 114 |
throw new XMLParseException("Only five parameters may be specified in GTR, leave exactly one out, the others will be specifed relative to the one left out."); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
if (xo.hasAttribute(KAPPA)){ |
| 119 |
System.err.print("using GTR rates -- overrides KAPPA"); |
| 120 |
} |
| 121 |
|
| 122 |
} else if (xo.hasChildNamed(KAPPA)) { |
| 123 |
Parameter kappaParam = (Parameter)xo.getElementFirstChild(KAPPA); |
| 124 |
codonModel = new MG94HKYCodonModel(codons, alphaParam, betaParam, kappaParam, freqModel); |
| 125 |
|
| 126 |
} else { |
| 127 |
|
| 128 |
codonModel = new MG94CodonModel(codons, alphaParam, betaParam, freqModel); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
if (!xo.getAttribute(NORMALIZED, true)) { |
| 133 |
|
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
return codonModel; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public String getParserDescription() { |
| 145 |
return "This element represents the Yang model of codon evolution."; |
| 146 |
} |
| 147 |
|
| 148 |
public Class getReturnType() { |
| 149 |
return MG94CodonModel.class; |
| 150 |
} |
| 151 |
|
| 152 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 153 |
return rules; |
| 154 |
} |
| 155 |
|
| 156 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 157 |
new StringAttributeRule(GeneticCode.GENETIC_CODE, |
| 158 |
"The genetic code to use", |
| 159 |
GeneticCode.GENETIC_CODE_NAMES, true), |
| 160 |
new ElementRule(ALPHA, |
| 161 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 162 |
new ElementRule(BETA, |
| 163 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 164 |
new ElementRule(KAPPA, |
| 165 |
new XMLSyntaxRule[] { new ElementRule(Parameter.class) }, true), |
| 166 |
new ElementRule(A_TO_C, |
| 167 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 168 |
new ElementRule(A_TO_G, |
| 169 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 170 |
new ElementRule(A_TO_T, |
| 171 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 172 |
new ElementRule(C_TO_G, |
| 173 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 174 |
new ElementRule(C_TO_T, |
| 175 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 176 |
new ElementRule(G_TO_T, |
| 177 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 178 |
|
| 179 |
new ElementRule(FrequencyModel.class), |
| 180 |
AttributeRule.newBooleanRule(NORMALIZED, true), |
| 181 |
}; |
| 182 |
|
| 183 |
} |