| 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.SampleStateModel; |
| 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 |
public class SampleStateModelParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String SAMPLE_STATE_MODEL = "sampleStateModel"; |
| 40 |
public static final String MUTATION_RATE = "mutationRate"; |
| 41 |
public static final String PROPORTIONS = "proportions"; |
| 42 |
|
| 43 |
public String getParserName() { |
| 44 |
return SAMPLE_STATE_MODEL; |
| 45 |
} |
| 46 |
|
| 47 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 48 |
|
| 49 |
XMLObject cxo = xo.getChild(MUTATION_RATE); |
| 50 |
Parameter muParam = (Parameter) cxo.getChild(Parameter.class); |
| 51 |
|
| 52 |
cxo = xo.getChild(PROPORTIONS); |
| 53 |
Parameter proportionParameter = (Parameter) cxo.getChild(Parameter.class); |
| 54 |
|
| 55 |
Vector<Object> subModels = new Vector<Object>(); |
| 56 |
|
| 57 |
for (int i = 0; i < xo.getChildCount(); i++) { |
| 58 |
if (xo.getChild(i) instanceof SubstitutionModel) { |
| 59 |
subModels.addElement(xo.getChild(i)); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return new SampleStateModel(muParam, proportionParameter, subModels); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public String getParserDescription() { |
| 71 |
return "A SiteModel that has a discrete distribution of substitution models over sites, " + |
| 72 |
"designed for sampling of internal states."; |
| 73 |
} |
| 74 |
|
| 75 |
public Class getReturnType() { |
| 76 |
return SampleStateModel.class; |
| 77 |
} |
| 78 |
|
| 79 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 80 |
return rules; |
| 81 |
} |
| 82 |
|
| 83 |
private final XMLSyntaxRule[] rules = { |
| 84 |
new ElementRule(MUTATION_RATE, |
| 85 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 86 |
new ElementRule(PROPORTIONS, |
| 87 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 88 |
new ElementRule(SubstitutionModel.class, 1, Integer.MAX_VALUE) |
| 89 |
}; |
| 90 |
} |