| 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.clock; |
| 27 |
|
| 28 |
import dr.oldevomodel.clock.ACLikelihood; |
| 29 |
import dr.oldevomodel.clock.RateEvolutionLikelihood; |
| 30 |
import dr.evomodel.tree.TreeModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class ACLikelihoodParser extends AbstractXMLObjectParser { |
| 37 |
|
| 38 |
public static final String AC_LIKELIHOOD = "ACLikelihood"; |
| 39 |
|
| 40 |
public static final String VARIANCE = "variance"; |
| 41 |
public static final String SHAPE = "shape"; |
| 42 |
|
| 43 |
public static final String DISTRIBUTION = "distribution"; |
| 44 |
|
| 45 |
public String getParserName() { |
| 46 |
return AC_LIKELIHOOD; |
| 47 |
} |
| 48 |
|
| 49 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 50 |
|
| 51 |
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class); |
| 52 |
|
| 53 |
Parameter ratesParameter = (Parameter) xo.getElementFirstChild(RateEvolutionLikelihood.RATES); |
| 54 |
|
| 55 |
Parameter rootRate = (Parameter) xo.getElementFirstChild(RateEvolutionLikelihood.ROOTRATE); |
| 56 |
|
| 57 |
Parameter variance = (Parameter) xo.getElementFirstChild(VARIANCE); |
| 58 |
|
| 59 |
boolean isEpisodic = xo.getBooleanAttribute(RateEvolutionLikelihood.EPISODIC); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
String distribution = xo.getStringAttribute(DISTRIBUTION); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
return new ACLikelihood(tree, ratesParameter, variance, rootRate, isEpisodic, distribution); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public String getParserDescription() { |
| 76 |
return |
| 77 |
"This element returns an object that can calculate the likelihood " + |
| 78 |
"of rate changes in a tree under the assumption of " + |
| 79 |
"distributed rate changes among lineages. " + |
| 80 |
|
| 81 |
"Specifically, each branch is assumed to draw a rate from a " + |
| 82 |
"distribution with mean of the rate in the " + |
| 83 |
|
| 84 |
"parent branch and the given standard deviation (the variance can be optionally proportional to " + |
| 85 |
"branch length)."; |
| 86 |
} |
| 87 |
|
| 88 |
public Class getReturnType() { |
| 89 |
return ACLikelihood.class; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 94 |
return rules; |
| 95 |
} |
| 96 |
|
| 97 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 98 |
new ElementRule(TreeModel.class), |
| 99 |
new ElementRule(RateEvolutionLikelihood.RATES, Parameter.class, "The branch rates parameter", false), |
| 100 |
AttributeRule.newBooleanRule(RateEvolutionLikelihood.EPISODIC, false, "true if model is branch length independent, false if length-dependent."), |
| 101 |
AttributeRule.newStringRule(DISTRIBUTION, false, "The distribution to use"), |
| 102 |
|
| 103 |
new ElementRule(RateEvolutionLikelihood.ROOTRATE, Parameter.class, "The root rate parameter"), |
| 104 |
new ElementRule(VARIANCE, Parameter.class, "The standard deviation of the distribution"), |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
}; |
| 109 |
} |