| 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.oldevomodelxml.substmodel; |
| 27 |
|
| 28 |
import dr.evolution.datatype.Microsatellite; |
| 29 |
import dr.oldevomodel.substmodel.AsymmetricQuadraticModel; |
| 30 |
import dr.oldevomodel.substmodel.FrequencyModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class AsymQuadModelParser extends AbstractXMLObjectParser{ |
| 40 |
|
| 41 |
public static final String EXPANSION_CONSTANT = "ExpansionConstant"; |
| 42 |
public static final String CONTRACTION_CONSTANT = "ContractionConstant"; |
| 43 |
public static final String EXPANSION_LIN = "ExpansionLinear"; |
| 44 |
public static final String CONTRACTION_LIN = "ContractionLinear"; |
| 45 |
public static final String EXPANSION_QUAD = "ExpansionQuad"; |
| 46 |
public static final String CONTRACTION_QUAD = "ContractionQuad"; |
| 47 |
public static final String IS_SUBMODEL = "isSubmodel"; |
| 48 |
|
| 49 |
public String getParserName() { |
| 50 |
return AsymmetricQuadraticModel.ASYMQUAD_MODEL; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 56 |
|
| 57 |
Microsatellite microsatellite = (Microsatellite) xo.getChild(Microsatellite.class); |
| 58 |
|
| 59 |
Parameter expanConst = processModelParameter(xo, EXPANSION_CONSTANT); |
| 60 |
|
| 61 |
Parameter expanLin = processModelParameter(xo, EXPANSION_LIN); |
| 62 |
|
| 63 |
Parameter expanQuad = processModelParameter(xo, EXPANSION_QUAD); |
| 64 |
|
| 65 |
Parameter contractConst = processModelParameter(xo, CONTRACTION_CONSTANT); |
| 66 |
|
| 67 |
Parameter contractLin = processModelParameter(xo, CONTRACTION_LIN); |
| 68 |
|
| 69 |
Parameter contractQuad = processModelParameter(xo, CONTRACTION_QUAD); |
| 70 |
|
| 71 |
|
| 72 |
FrequencyModel freqModel = null; |
| 73 |
if(xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)){ |
| 74 |
freqModel = (FrequencyModel)xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES); |
| 75 |
} |
| 76 |
|
| 77 |
boolean isSubmodel = xo.getAttribute(IS_SUBMODEL, false); |
| 78 |
|
| 79 |
return new AsymmetricQuadraticModel( |
| 80 |
microsatellite, |
| 81 |
freqModel, |
| 82 |
expanConst, |
| 83 |
expanLin, |
| 84 |
expanQuad, |
| 85 |
contractConst, |
| 86 |
contractLin, |
| 87 |
contractQuad, |
| 88 |
isSubmodel |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
private Parameter processModelParameter(XMLObject xo, |
| 93 |
String parameterName)throws XMLParseException{ |
| 94 |
Parameter param = null; |
| 95 |
if(xo.hasChildNamed(parameterName)){ |
| 96 |
XMLObject paramXO = xo.getChild(parameterName); |
| 97 |
param =(Parameter) paramXO.getChild(Parameter.class); |
| 98 |
} |
| 99 |
return param; |
| 100 |
} |
| 101 |
|
| 102 |
public String getParserDescription() { |
| 103 |
return "This element represents an instance of the stepwise mutation model of microsatellite evolution."; |
| 104 |
} |
| 105 |
|
| 106 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 107 |
return rules; |
| 108 |
} |
| 109 |
|
| 110 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 111 |
new ElementRule(Microsatellite.class), |
| 112 |
new ElementRule(FrequencyModel.class,true), |
| 113 |
new ElementRule(EXPANSION_CONSTANT,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 114 |
new ElementRule(CONTRACTION_CONSTANT,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 115 |
new ElementRule(EXPANSION_LIN,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 116 |
new ElementRule(CONTRACTION_LIN,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 117 |
new ElementRule(EXPANSION_QUAD,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 118 |
new ElementRule(CONTRACTION_QUAD,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 119 |
AttributeRule.newBooleanRule(IS_SUBMODEL,true) |
| 120 |
}; |
| 121 |
|
| 122 |
public Class getReturnType() { |
| 123 |
return AsymmetricQuadraticModel.class; |
| 124 |
} |
| 125 |
|
| 126 |
public static boolean requirePattern(){ |
| 127 |
return true; |
| 128 |
} |
| 129 |
} |
| 130 |
|