| 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.TwoStateCovarion; |
| 29 |
import dr.oldevomodel.substmodel.AbstractCovarionDNAModel; |
| 30 |
import dr.oldevomodel.substmodel.FrequencyModel; |
| 31 |
import dr.oldevomodel.substmodel.TwoStateCovarionModel; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class TwoStateCovarionModelParser extends AbstractXMLObjectParser { |
| 39 |
public static final String COVARION_MODEL = "covarionModel"; |
| 40 |
public static final String ALPHA = "alpha"; |
| 41 |
public static final String SWITCHING_RATE = "switchingRate"; |
| 42 |
|
| 43 |
public String getParserName() { |
| 44 |
return COVARION_MODEL; |
| 45 |
} |
| 46 |
|
| 47 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 48 |
|
| 49 |
Parameter alphaParameter; |
| 50 |
Parameter switchingRateParameter; |
| 51 |
|
| 52 |
XMLObject cxo = xo.getChild(AbstractCovarionDNAModel.FREQUENCIES); |
| 53 |
FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class); |
| 54 |
|
| 55 |
TwoStateCovarion dataType = TwoStateCovarion.INSTANCE; |
| 56 |
|
| 57 |
cxo = xo.getChild(ALPHA); |
| 58 |
alphaParameter = (Parameter) cxo.getChild(Parameter.class); |
| 59 |
|
| 60 |
|
| 61 |
alphaParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1)); |
| 62 |
|
| 63 |
cxo = xo.getChild(SWITCHING_RATE); |
| 64 |
switchingRateParameter = (Parameter) cxo.getChild(Parameter.class); |
| 65 |
|
| 66 |
if (dataType != freqModel.getDataType()) { |
| 67 |
throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its frequencyModel."); |
| 68 |
} |
| 69 |
|
| 70 |
TwoStateCovarionModel model = new TwoStateCovarionModel(dataType, freqModel, alphaParameter, switchingRateParameter); |
| 71 |
|
| 72 |
System.out.println(model); |
| 73 |
|
| 74 |
return model; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public String getParserDescription() { |
| 82 |
return "A covarion substitution model on binary data and a hidden rate state with two rates."; |
| 83 |
} |
| 84 |
|
| 85 |
public Class getReturnType() { |
| 86 |
return TwoStateCovarionModel.class; |
| 87 |
} |
| 88 |
|
| 89 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 90 |
return rules; |
| 91 |
} |
| 92 |
|
| 93 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 94 |
new ElementRule(AbstractCovarionDNAModel.FREQUENCIES, FrequencyModel.class), |
| 95 |
new ElementRule(ALPHA, new XMLSyntaxRule[]{ |
| 96 |
new ElementRule(Parameter.class, true)} |
| 97 |
), |
| 98 |
new ElementRule(SWITCHING_RATE, new XMLSyntaxRule[]{ |
| 99 |
new ElementRule(Parameter.class, true)} |
| 100 |
), |
| 101 |
}; |
| 102 |
} |