| 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.GeneralSubstitutionModel; |
| 30 |
import dr.evolution.datatype.DataType; |
| 31 |
import dr.evolution.datatype.TwoStates; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class BinarySubstitutionModelParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String BINARY_SUBSTITUTION_MODEL = "binarySubstitutionModel"; |
| 41 |
|
| 42 |
public String getParserName() { |
| 43 |
return BINARY_SUBSTITUTION_MODEL; |
| 44 |
} |
| 45 |
|
| 46 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 47 |
|
| 48 |
Parameter ratesParameter; |
| 49 |
|
| 50 |
XMLObject cxo = xo.getChild(dr.oldevomodelxml.substmodel.GeneralSubstitutionModelParser.FREQUENCIES); |
| 51 |
FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class); |
| 52 |
|
| 53 |
DataType dataType = freqModel.getDataType(); |
| 54 |
|
| 55 |
if (dataType != TwoStates.INSTANCE) |
| 56 |
throw new XMLParseException("Frequency model must have binary (two state) data type."); |
| 57 |
|
| 58 |
int relativeTo = 0; |
| 59 |
|
| 60 |
ratesParameter = new Parameter.Default(0); |
| 61 |
|
| 62 |
return new GeneralSubstitutionModel(getParserName(), dataType, freqModel, ratesParameter, relativeTo); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public String getParserDescription() { |
| 70 |
return "A general reversible model of sequence substitution for binary data type."; |
| 71 |
} |
| 72 |
|
| 73 |
public Class getReturnType() { |
| 74 |
return GeneralSubstitutionModel.class; |
| 75 |
} |
| 76 |
|
| 77 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 78 |
return rules; |
| 79 |
} |
| 80 |
|
| 81 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 82 |
new ElementRule(GeneralSubstitutionModelParser.FREQUENCIES, FrequencyModel.class), |
| 83 |
}; |
| 84 |
|
| 85 |
} |