| 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.tree; |
| 27 |
|
| 28 |
import dr.evomodel.tree.TreeModel; |
| 29 |
import dr.evomodel.tree.UniformNodeHeightPrior; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
import java.util.logging.Logger; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class UniformNodeHeightPriorParser extends AbstractXMLObjectParser { |
| 37 |
|
| 38 |
public static final String UNIFORM_ROOT_PRIOR = "uniformRootPrior"; |
| 39 |
public static final String UNIFORM_NODE_HEIGHT_PRIOR = "uniformNodeHeightPrior"; |
| 40 |
public static final String MAX_ROOT_HEIGHT = "maxRootHeight"; |
| 41 |
public static final String ANALYTIC = "analytic"; |
| 42 |
public static final String MC_SAMPLE = "mcSampleSize"; |
| 43 |
public static final String MARGINAL = "marginal"; |
| 44 |
public static final String LEADING_TERM = "approximate"; |
| 45 |
|
| 46 |
public String getParserName() { |
| 47 |
return UNIFORM_NODE_HEIGHT_PRIOR; |
| 48 |
} |
| 49 |
|
| 50 |
public String[] getParserNames() { |
| 51 |
return new String[] {UNIFORM_ROOT_PRIOR, UNIFORM_NODE_HEIGHT_PRIOR}; |
| 52 |
} |
| 53 |
|
| 54 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 55 |
|
| 56 |
Logger.getLogger("dr.evomodel").info("\nConstructing a uniform node height prior:"); |
| 57 |
|
| 58 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 59 |
if (xo.hasAttribute(MAX_ROOT_HEIGHT)) { |
| 60 |
|
| 61 |
double maxRootHeight = xo.getDoubleAttribute(MAX_ROOT_HEIGHT); |
| 62 |
Logger.getLogger("dr.evomodel").info("\tUsing joint variant with a max root height = "+maxRootHeight+"\n"); |
| 63 |
return new UniformNodeHeightPrior(treeModel, maxRootHeight); |
| 64 |
} else { |
| 65 |
|
| 66 |
boolean useAnalytic = xo.getAttribute(ANALYTIC,true); |
| 67 |
boolean marginal = xo.getAttribute(MARGINAL,true); |
| 68 |
boolean leadingTerm = xo.getAttribute(LEADING_TERM,false); |
| 69 |
Logger.getLogger("dr.evomodel").info("\tUsing conditional variant with "+(useAnalytic ? "analytic" : "Monte Carlo integrated")+" expressions"); |
| 70 |
if (useAnalytic) { |
| 71 |
Logger.getLogger("dr.evomodel").info("\t\tSubvariant: "+(marginal ? "marginal" : "conditional")); |
| 72 |
Logger.getLogger("dr.evomodel").info("\t\tApproximation: "+leadingTerm); |
| 73 |
} |
| 74 |
Logger.getLogger("dr.evomodel").info("\tPlease reference:"); |
| 75 |
Logger.getLogger("dr.evomodel").info("\t\t (1) Welch, Rambaut and Suchard (in preparation) and"); |
| 76 |
Logger.getLogger("dr.evomodel").info("\t\t (2) Bloomquist and Suchard (in press) Systematic Biology\n"); |
| 77 |
if (!useAnalytic) { |
| 78 |
|
| 79 |
|
| 80 |
int mcSampleSize = xo.getAttribute(MC_SAMPLE, UniformNodeHeightPrior.DEFAULT_MC_SAMPLE); |
| 81 |
return new UniformNodeHeightPrior(treeModel,useAnalytic,mcSampleSize); |
| 82 |
} |
| 83 |
|
| 84 |
return new UniformNodeHeightPrior(treeModel, useAnalytic, marginal,leadingTerm); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public String getParserDescription() { |
| 93 |
return "This element represents the likelihood of the tree given the demographic function."; |
| 94 |
} |
| 95 |
|
| 96 |
public Class getReturnType() { |
| 97 |
return UniformNodeHeightPrior.class; |
| 98 |
} |
| 99 |
|
| 100 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 101 |
return rules; |
| 102 |
} |
| 103 |
|
| 104 |
private final XMLSyntaxRule[] rules = { |
| 105 |
AttributeRule.newBooleanRule(ANALYTIC, true), |
| 106 |
AttributeRule.newDoubleRule(MAX_ROOT_HEIGHT, true), |
| 107 |
AttributeRule.newIntegerRule(MC_SAMPLE,true), |
| 108 |
AttributeRule.newBooleanRule(MARGINAL,true), |
| 109 |
AttributeRule.newBooleanRule(LEADING_TERM,true), |
| 110 |
new ElementRule(TreeModel.class) |
| 111 |
}; |
| 112 |
|
| 113 |
} |