| 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.SampleStateAndCategoryModel; |
| 29 |
import dr.oldevomodel.substmodel.SubstitutionModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
import java.util.Vector; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class SampleStateAndCategoryModelParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String SAMPLE_STATE_AND_CATEGORY_MODEL = "sampleStateAndCategoryModel"; |
| 41 |
public static final String MUTATION_RATE = "mutationRate"; |
| 42 |
public static final String CATEGORY_PARAMETER = "categoriesParameter"; |
| 43 |
|
| 44 |
public String getParserName() { |
| 45 |
return SAMPLE_STATE_AND_CATEGORY_MODEL; |
| 46 |
} |
| 47 |
|
| 48 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 49 |
|
| 50 |
XMLObject cxo = xo.getChild(MUTATION_RATE); |
| 51 |
Parameter muParam = (Parameter) cxo.getChild(Parameter.class); |
| 52 |
|
| 53 |
cxo = xo.getChild(CATEGORY_PARAMETER); |
| 54 |
Parameter catParam = (Parameter) cxo.getChild(Parameter.class); |
| 55 |
|
| 56 |
Vector subModels = new Vector(); |
| 57 |
for (int i = 0; i < xo.getChildCount(); i++) { |
| 58 |
|
| 59 |
if (xo.getChild(i) instanceof SubstitutionModel) { |
| 60 |
subModels.addElement(xo.getChild(i)); |
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
return new SampleStateAndCategoryModel(muParam, catParam, subModels); |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public String getParserDescription() { |
| 73 |
return "A SiteModel that has a discrete distribution of substitution models over sites, " + |
| 74 |
"designed for sampling of rate categories and internal states."; |
| 75 |
} |
| 76 |
|
| 77 |
public Class getReturnType() { |
| 78 |
return SampleStateAndCategoryModel.class; |
| 79 |
} |
| 80 |
|
| 81 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 82 |
return rules; |
| 83 |
} |
| 84 |
|
| 85 |
private final XMLSyntaxRule[] rules = { |
| 86 |
new ElementRule(MUTATION_RATE, |
| 87 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 88 |
new ElementRule(CATEGORY_PARAMETER, |
| 89 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 90 |
new ElementRule(SubstitutionModel.class, 1, Integer.MAX_VALUE) |
| 91 |
}; |
| 92 |
|
| 93 |
} |