| 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.sitemodel; |
| 27 |
|
| 28 |
import dr.oldevomodel.sitemodel.CategorySiteModel; |
| 29 |
import dr.oldevomodel.substmodel.SubstitutionModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class CategorySiteModelParser extends AbstractXMLObjectParser { |
| 36 |
|
| 37 |
public static final String SITE_MODEL = "categorySiteModel"; |
| 38 |
public static final String SUBSTITUTION_MODEL = "substitutionModel"; |
| 39 |
public static final String MUTATION_RATE = "mutationRate"; |
| 40 |
public static final String RATE_PARAMETER = "rates"; |
| 41 |
public static final String CATEGORIES = "categories"; |
| 42 |
public static final String CATEGORY_STATES = "states"; |
| 43 |
public static final String CATEGORY_STRING = "values"; |
| 44 |
public static final String RELATIVE_TO = "relativeTo"; |
| 45 |
|
| 46 |
public String getParserName() { |
| 47 |
return SITE_MODEL; |
| 48 |
} |
| 49 |
|
| 50 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 51 |
|
| 52 |
XMLObject cxo = xo.getChild(SUBSTITUTION_MODEL); |
| 53 |
SubstitutionModel substitutionModel = (SubstitutionModel) cxo.getChild(SubstitutionModel.class); |
| 54 |
|
| 55 |
cxo = xo.getChild(MUTATION_RATE); |
| 56 |
Parameter muParam = (Parameter) cxo.getChild(Parameter.class); |
| 57 |
|
| 58 |
cxo = xo.getChild(RATE_PARAMETER); |
| 59 |
Parameter rateParam = null; |
| 60 |
int relativeTo = 0; |
| 61 |
if (cxo != null) { |
| 62 |
rateParam = (Parameter) cxo.getChild(Parameter.class); |
| 63 |
relativeTo = cxo.getIntegerAttribute(RELATIVE_TO); |
| 64 |
} |
| 65 |
|
| 66 |
cxo = xo.getChild(CATEGORIES); |
| 67 |
String categories = ""; |
| 68 |
String states = ""; |
| 69 |
if (cxo != null) { |
| 70 |
categories = cxo.getStringAttribute(CATEGORY_STRING); |
| 71 |
states = cxo.getStringAttribute(CATEGORY_STATES); |
| 72 |
} |
| 73 |
|
| 74 |
return new CategorySiteModel(substitutionModel, muParam, rateParam, categories, states, relativeTo); |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public String getParserDescription() { |
| 83 |
return "A SiteModel that has a gamma distributed rates across sites"; |
| 84 |
} |
| 85 |
|
| 86 |
public Class getReturnType() { |
| 87 |
return CategorySiteModel.class; |
| 88 |
} |
| 89 |
|
| 90 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 91 |
return rules; |
| 92 |
} |
| 93 |
|
| 94 |
private final XMLSyntaxRule[] rules = { |
| 95 |
new ElementRule(SUBSTITUTION_MODEL, new XMLSyntaxRule[]{ |
| 96 |
new ElementRule(SubstitutionModel.class) |
| 97 |
}), |
| 98 |
new ElementRule(MUTATION_RATE, new XMLSyntaxRule[]{ |
| 99 |
new ElementRule(Parameter.class) |
| 100 |
}), |
| 101 |
new ElementRule(RATE_PARAMETER, new XMLSyntaxRule[]{ |
| 102 |
AttributeRule.newIntegerRule(RELATIVE_TO, true), |
| 103 |
new ElementRule(Parameter.class) |
| 104 |
}, true), |
| 105 |
new ElementRule(CATEGORIES, new XMLSyntaxRule[]{ |
| 106 |
AttributeRule.newStringRule(CATEGORY_STRING, true), |
| 107 |
AttributeRule.newStringRule(CATEGORY_STATES, true) |
| 108 |
}, true), |
| 109 |
}; |
| 110 |
|
| 111 |
} |