| 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.xml.*; |
| 29 |
import dr.oldevomodel.sitemodel.GammaSiteBMA; |
| 30 |
import dr.oldevomodel.substmodel.SubstitutionModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.inference.model.Variable; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class GammaSiteBMAParser extends AbstractXMLObjectParser { |
| 41 |
|
| 42 |
public static final String SUBSTITUTION_MODEL = "substitutionModel"; |
| 43 |
public static final String MUTATION_RATE = "mutationRate"; |
| 44 |
public static final String LOG_GAMMA_SHAPE = "logGammaShape"; |
| 45 |
public static final String GAMMA_CATEGORIES = "gammaCategories"; |
| 46 |
public static final String LOGIT_PROPORTION_INVARIANT = "logitProportionInvariant"; |
| 47 |
public static final String MODEL_CHOOSE = "modelChoose"; |
| 48 |
public static final String GAMMA_SITE_BMA = "gammaSiteBMA"; |
| 49 |
|
| 50 |
public String getParserName() { |
| 51 |
return GAMMA_SITE_BMA; |
| 52 |
} |
| 53 |
|
| 54 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 55 |
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getElementFirstChild(SUBSTITUTION_MODEL); |
| 56 |
|
| 57 |
Parameter muParam = (Parameter) xo.getElementFirstChild(MUTATION_RATE); |
| 58 |
|
| 59 |
Parameter logitInvar = (Parameter) xo.getElementFirstChild(LOGIT_PROPORTION_INVARIANT); |
| 60 |
|
| 61 |
final XMLObject cxo = xo.getChild(LOG_GAMMA_SHAPE); |
| 62 |
Parameter logShape = (Parameter) cxo.getChild(Parameter.class); |
| 63 |
|
| 64 |
int catCount = cxo.getIntegerAttribute(GAMMA_CATEGORIES); |
| 65 |
|
| 66 |
Variable<Integer> modelChoose = (Variable<Integer>) xo.getElementFirstChild(MODEL_CHOOSE); |
| 67 |
|
| 68 |
return new GammaSiteBMA(substitutionModel, muParam, logitInvar, logShape, catCount, modelChoose); |
| 69 |
} |
| 70 |
|
| 71 |
public String getParserDescription() { |
| 72 |
return "A SiteModel that does BMA for a gamma distributed rates across sites"; |
| 73 |
} |
| 74 |
|
| 75 |
public Class getReturnType() { |
| 76 |
return GammaSiteBMA.class; |
| 77 |
} |
| 78 |
|
| 79 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 80 |
return rules; |
| 81 |
} |
| 82 |
|
| 83 |
private final XMLSyntaxRule[] rules = { |
| 84 |
new ElementRule(SUBSTITUTION_MODEL, new XMLSyntaxRule[]{ |
| 85 |
new ElementRule(SubstitutionModel.class) |
| 86 |
}), |
| 87 |
new ElementRule(MUTATION_RATE, new XMLSyntaxRule[]{ |
| 88 |
new ElementRule(Parameter.class) |
| 89 |
}), |
| 90 |
new ElementRule(LOG_GAMMA_SHAPE, new XMLSyntaxRule[]{ |
| 91 |
AttributeRule.newIntegerRule(GAMMA_CATEGORIES), |
| 92 |
new ElementRule(Parameter.class) |
| 93 |
}), |
| 94 |
new ElementRule(LOGIT_PROPORTION_INVARIANT, new XMLSyntaxRule[]{ |
| 95 |
new ElementRule(Parameter.class) |
| 96 |
}), |
| 97 |
new ElementRule(MODEL_CHOOSE, new XMLSyntaxRule[]{ |
| 98 |
new ElementRule(Variable.class) |
| 99 |
}) |
| 100 |
}; |
| 101 |
|
| 102 |
} |