| 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.inference.model.Parameter; |
| 29 |
import dr.xml.*; |
| 30 |
import dr.evomodel.substmodel.FrequencyModel; |
| 31 |
import dr.evomodel.substmodel.codon.GY94CodonModel; |
| 32 |
import dr.evolution.datatype.Codons; |
| 33 |
import dr.evolution.datatype.GeneticCode; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class GY94CodonModelParser extends AbstractXMLObjectParser { |
| 40 |
|
| 41 |
public static final String YANG_CODON_MODEL = "yangCodonModel"; |
| 42 |
public static final String OMEGA = "omega"; |
| 43 |
public static final String KAPPA = "kappa"; |
| 44 |
|
| 45 |
|
| 46 |
public String getParserName() { return YANG_CODON_MODEL; } |
| 47 |
|
| 48 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 49 |
|
| 50 |
Codons codons = Codons.UNIVERSAL; |
| 51 |
if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) { |
| 52 |
String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE); |
| 53 |
codons = Codons.findByName(codeStr); |
| 54 |
} |
| 55 |
|
| 56 |
Parameter omegaParameter = (Parameter)xo.getElementFirstChild(OMEGA); |
| 57 |
|
| 58 |
int dim = omegaParameter.getDimension(); |
| 59 |
double value = omegaParameter.getParameterValue(dim - 1); |
| 60 |
if(value < 0) { |
| 61 |
throw new RuntimeException("Negative Omega parameter value " + value); |
| 62 |
} |
| 63 |
|
| 64 |
Parameter kappaParameter = (Parameter)xo.getElementFirstChild(KAPPA); |
| 65 |
|
| 66 |
dim = kappaParameter.getDimension(); |
| 67 |
value = kappaParameter.getParameterValue(dim - 1); |
| 68 |
if(value < 0) { |
| 69 |
throw new RuntimeException("Negative kappa parameter value value " + value); |
| 70 |
} |
| 71 |
|
| 72 |
FrequencyModel freqModel = (FrequencyModel)xo.getChild(FrequencyModel.class); |
| 73 |
GY94CodonModel codonModel = new GY94CodonModel(codons, omegaParameter, kappaParameter, freqModel); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
return codonModel; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public String getParserDescription() { |
| 85 |
return "This element represents the Yang model of codon evolution."; |
| 86 |
} |
| 87 |
|
| 88 |
public Class getReturnType() { return GY94CodonModel.class; } |
| 89 |
|
| 90 |
public XMLSyntaxRule[] getSyntaxRules() { return rules; } |
| 91 |
|
| 92 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[] { |
| 93 |
new StringAttributeRule(GeneticCode.GENETIC_CODE, |
| 94 |
"The genetic code to use", |
| 95 |
GeneticCode.GENETIC_CODE_NAMES, true), |
| 96 |
new ElementRule(OMEGA, |
| 97 |
new XMLSyntaxRule[] { new ElementRule(Parameter.class) }), |
| 98 |
new ElementRule(KAPPA, |
| 99 |
new XMLSyntaxRule[] { new ElementRule(Parameter.class) }), |
| 100 |
new ElementRule(FrequencyModel.class) |
| 101 |
}; |
| 102 |
|
| 103 |
} |