| 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.coalescent; |
| 27 |
|
| 28 |
import dr.evomodel.coalescent.BMPriorLikelihood; |
| 29 |
import dr.evomodel.coalescent.VariableDemographicModel; |
| 30 |
import dr.inference.distribution.ParametricDistributionModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class BMPriorLikelihoodParser extends AbstractXMLObjectParser { |
| 37 |
public static final String BM = "BrownianMotion"; |
| 38 |
public static final String LOG_SPACE = "logUnits"; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static final String SIGMA = "sigma"; |
| 46 |
|
| 47 |
|
| 48 |
public String getParserDescription() { |
| 49 |
return ""; |
| 50 |
} |
| 51 |
|
| 52 |
public Class getReturnType() { |
| 53 |
return BMPriorLikelihood.class; |
| 54 |
} |
| 55 |
|
| 56 |
public String getParserName() { |
| 57 |
return BM; |
| 58 |
} |
| 59 |
|
| 60 |
private Parameter getParam(XMLObject xo, String name) throws XMLParseException { |
| 61 |
final XMLObject object = xo.getChild(name); |
| 62 |
|
| 63 |
if (object == null) { |
| 64 |
return null; |
| 65 |
} |
| 66 |
final Object child = object.getChild(0); |
| 67 |
if (child instanceof Parameter) { |
| 68 |
return (Parameter) child; |
| 69 |
} |
| 70 |
|
| 71 |
double x = object.getDoubleChild(0); |
| 72 |
return new Parameter.Default(x); |
| 73 |
} |
| 74 |
|
| 75 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 76 |
|
| 77 |
|
| 78 |
Parameter sigma = getParam(xo, SIGMA); |
| 79 |
|
| 80 |
|
| 81 |
final boolean logSpace = xo.getAttribute(LOG_SPACE, false); |
| 82 |
|
| 83 |
|
| 84 |
VariableDemographicModel m = (VariableDemographicModel) xo.getChild(VariableDemographicModel.class); |
| 85 |
|
| 86 |
ParametricDistributionModel popMeanPrior = (ParametricDistributionModel) xo.getChild(ParametricDistributionModel.class); |
| 87 |
return new BMPriorLikelihood(sigma, m, logSpace, popMeanPrior); |
| 88 |
} |
| 89 |
|
| 90 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 91 |
|
| 92 |
|
| 93 |
return new XMLSyntaxRule[]{ |
| 94 |
AttributeRule.newBooleanRule(LOG_SPACE, true), |
| 95 |
|
| 96 |
new XORRule( |
| 97 |
new ElementRule(SIGMA, Double.class), |
| 98 |
new ElementRule(SIGMA, Parameter.class) |
| 99 |
), |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
new ElementRule(VariableDemographicModel.class), |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
}; |
| 109 |
} |
| 110 |
} |