| 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.VariableSkylineLikelihood; |
| 29 |
import dr.evomodel.tree.TreeModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
import java.util.logging.Logger; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class VariableSkylineLikelihoodParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String SKYLINE_LIKELIHOOD = "ovariableSkyLineLikelihood"; |
| 41 |
public static final String POPULATION_SIZES = "populationSizes"; |
| 42 |
public static final String INDICATOR_PARAMETER = "indicators"; |
| 43 |
public static final String LOG_SPACE = "logUnits"; |
| 44 |
|
| 45 |
public static final String TYPE = "type"; |
| 46 |
public static final String STEPWISE = "stepwise"; |
| 47 |
public static final String LINEAR = "linear"; |
| 48 |
public static final String EXPONENTIAL = "exponential"; |
| 49 |
|
| 50 |
public String getParserName() { |
| 51 |
return SKYLINE_LIKELIHOOD; |
| 52 |
} |
| 53 |
|
| 54 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 55 |
|
| 56 |
XMLObject cxo = xo.getChild(POPULATION_SIZES); |
| 57 |
Parameter param = (Parameter) cxo.getChild(Parameter.class); |
| 58 |
|
| 59 |
cxo = xo.getChild(INDICATOR_PARAMETER); |
| 60 |
Parameter param2 = (Parameter) cxo.getChild(Parameter.class); |
| 61 |
|
| 62 |
cxo = xo.getChild(CoalescentLikelihoodParser.POPULATION_TREE); |
| 63 |
TreeModel treeModel = (TreeModel) cxo.getChild(TreeModel.class); |
| 64 |
|
| 65 |
VariableSkylineLikelihood.Type type = VariableSkylineLikelihood.Type.STEPWISE; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
if (xo.hasAttribute(TYPE)) { |
| 72 |
final String s = xo.getStringAttribute(TYPE); |
| 73 |
if (s.equalsIgnoreCase(STEPWISE)) { |
| 74 |
type = VariableSkylineLikelihood.Type.STEPWISE; |
| 75 |
} else if (s.equalsIgnoreCase(LINEAR)) { |
| 76 |
type = VariableSkylineLikelihood.Type.LINEAR; |
| 77 |
} else if (s.equalsIgnoreCase(EXPONENTIAL)) { |
| 78 |
type = VariableSkylineLikelihood.Type.EXPONENTIAL; |
| 79 |
} else { |
| 80 |
throw new XMLParseException("Unknown Bayesian Skyline type: " + s); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
boolean logSpace = xo.getBooleanAttribute(LOG_SPACE); |
| 85 |
|
| 86 |
Logger.getLogger("dr.evomodel").info("Variable skyline plot: " + type.toString() + " control points"); |
| 87 |
|
| 88 |
return new VariableSkylineLikelihood(treeModel, param, param2, type, logSpace); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public String getParserDescription() { |
| 96 |
return "This element represents the likelihood of the tree given the population size vector."; |
| 97 |
} |
| 98 |
|
| 99 |
public Class getReturnType() { |
| 100 |
return VariableSkylineLikelihood.class; |
| 101 |
} |
| 102 |
|
| 103 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 104 |
return rules; |
| 105 |
} |
| 106 |
|
| 107 |
private final XMLSyntaxRule[] rules = { |
| 108 |
AttributeRule.newBooleanRule(TYPE, true), |
| 109 |
new ElementRule(POPULATION_SIZES, new XMLSyntaxRule[]{ |
| 110 |
new ElementRule(Parameter.class) |
| 111 |
}), |
| 112 |
new ElementRule(INDICATOR_PARAMETER, new XMLSyntaxRule[]{ |
| 113 |
new ElementRule(Parameter.class) |
| 114 |
}), |
| 115 |
new ElementRule(CoalescentLikelihoodParser.POPULATION_TREE, new XMLSyntaxRule[]{ |
| 116 |
new ElementRule(TreeModel.class) |
| 117 |
}), |
| 118 |
AttributeRule.newBooleanRule(LOG_SPACE) |
| 119 |
}; |
| 120 |
|
| 121 |
} |