| 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.BinaryCovarionModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class BinaryCovarionModelParser extends AbstractXMLObjectParser { |
| 37 |
public static final String COVARION_MODEL = "binaryCovarionModel"; |
| 38 |
public static final String ALPHA = "alpha"; |
| 39 |
public static final String SWITCHING_RATE = "switchingRate"; |
| 40 |
public static final String FREQUENCIES = "frequencies"; |
| 41 |
public static final String HIDDEN_FREQUENCIES = "hiddenFrequencies"; |
| 42 |
public static final String VERSION = "version"; |
| 43 |
public static final BinaryCovarionModel.Version DEFAULT_VERSION = BinaryCovarionModel.Version.VERSION1; |
| 44 |
|
| 45 |
public String getParserName() { |
| 46 |
return COVARION_MODEL; |
| 47 |
} |
| 48 |
|
| 49 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 50 |
|
| 51 |
Parameter alphaParameter; |
| 52 |
Parameter switchingRateParameter; |
| 53 |
|
| 54 |
XMLObject cxo = xo.getChild(FREQUENCIES); |
| 55 |
Parameter frequencies = (Parameter) cxo.getChild(Parameter.class); |
| 56 |
|
| 57 |
cxo = xo.getChild(HIDDEN_FREQUENCIES); |
| 58 |
Parameter hiddenFrequencies = (Parameter) cxo.getChild(Parameter.class); |
| 59 |
|
| 60 |
cxo = xo.getChild(ALPHA); |
| 61 |
alphaParameter = (Parameter) cxo.getChild(Parameter.class); |
| 62 |
|
| 63 |
|
| 64 |
alphaParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1)); |
| 65 |
hiddenFrequencies.addBounds(new Parameter.DefaultBounds(1.0, 0.0, hiddenFrequencies.getDimension())); |
| 66 |
frequencies.addBounds(new Parameter.DefaultBounds(1.0, 0.0, frequencies.getDimension())); |
| 67 |
|
| 68 |
cxo = xo.getChild(SWITCHING_RATE); |
| 69 |
switchingRateParameter = (Parameter) cxo.getChild(Parameter.class); |
| 70 |
|
| 71 |
BinaryCovarionModel.Version version = DEFAULT_VERSION; |
| 72 |
if (xo.hasAttribute(VERSION)) { |
| 73 |
version = BinaryCovarionModel.Version.parseFromString(xo.getStringAttribute(VERSION)); |
| 74 |
} |
| 75 |
|
| 76 |
BinaryCovarionModel model = new BinaryCovarionModel(TwoStateCovarion.INSTANCE, |
| 77 |
frequencies, hiddenFrequencies, alphaParameter, switchingRateParameter, version); |
| 78 |
|
| 79 |
System.out.println(model); |
| 80 |
|
| 81 |
return model; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public String getParserDescription() { |
| 89 |
return "A covarion substitution model on binary data and a hidden rate state with two rates."; |
| 90 |
} |
| 91 |
|
| 92 |
public Class getReturnType() { |
| 93 |
return BinaryCovarionModel.class; |
| 94 |
} |
| 95 |
|
| 96 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 97 |
return rules; |
| 98 |
} |
| 99 |
|
| 100 |
private final XMLSyntaxRule[] rules = { |
| 101 |
new ElementRule(FREQUENCIES, Parameter.class), |
| 102 |
new ElementRule(HIDDEN_FREQUENCIES, Parameter.class), |
| 103 |
new ElementRule(ALPHA, |
| 104 |
new XMLSyntaxRule[]{ |
| 105 |
new ElementRule(Parameter.class, true)} |
| 106 |
), |
| 107 |
new ElementRule(SWITCHING_RATE, |
| 108 |
new XMLSyntaxRule[]{ |
| 109 |
new ElementRule(Parameter.class, true)} |
| 110 |
), |
| 111 |
AttributeRule.newStringRule(VERSION, true), |
| 112 |
}; |
| 113 |
|
| 114 |
|
| 115 |
} |