| 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.branchratemodel; |
| 27 |
|
| 28 |
import dr.evomodel.branchratemodel.ArbitraryBranchRates; |
| 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 |
public class ArbitraryBranchRatesParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String ARBITRARY_BRANCH_RATES = "arbitraryBranchRates"; |
| 40 |
public static final String RATES = "rates"; |
| 41 |
public static final String RECIPROCAL = "reciprocal"; |
| 42 |
public static final String EXP = "exp"; |
| 43 |
public static final String CENTER_AT_ONE = "centerAtOne"; |
| 44 |
|
| 45 |
public String getParserName() { |
| 46 |
return ARBITRARY_BRANCH_RATES; |
| 47 |
} |
| 48 |
|
| 49 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 50 |
|
| 51 |
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class); |
| 52 |
|
| 53 |
XMLObject cxo = xo.getChild(RATES); |
| 54 |
|
| 55 |
Parameter rateCategoryParameter = (Parameter) cxo.getChild(Parameter.class); |
| 56 |
|
| 57 |
boolean reciprocal = xo.getAttribute(RECIPROCAL, false); |
| 58 |
boolean centerAtOne = xo.getAttribute(CENTER_AT_ONE, true); |
| 59 |
boolean exp = xo.getAttribute(EXP, false); |
| 60 |
|
| 61 |
final int numBranches = tree.getNodeCount() - 1; |
| 62 |
if (rateCategoryParameter.getDimension() != numBranches) { |
| 63 |
rateCategoryParameter.setDimension(numBranches); |
| 64 |
|
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
Logger.getLogger("dr.evomodel").info("\nUsing an scaled mixture of normals model."); |
| 69 |
Logger.getLogger("dr.evomodel").info(" rates = " + rateCategoryParameter.getDimension()); |
| 70 |
Logger.getLogger("dr.evomodel").info(" NB: Make sure you have a prior on " + rateCategoryParameter.getId() + " and do not use this model in a treeLikelihood for sequence data"); |
| 71 |
Logger.getLogger("dr.evomodel").info(" reciprocal = " + reciprocal); |
| 72 |
|
| 73 |
return new ArbitraryBranchRates(tree, rateCategoryParameter, reciprocal, exp, centerAtOne); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public String getParserDescription() { |
| 81 |
return "This element returns an arbitrary rate model." + |
| 82 |
"The branch rates are drawn from an arbitrary distribution determine by the prior."; |
| 83 |
} |
| 84 |
|
| 85 |
public Class getReturnType() { |
| 86 |
return ArbitraryBranchRates.class; |
| 87 |
} |
| 88 |
|
| 89 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 90 |
return rules; |
| 91 |
} |
| 92 |
|
| 93 |
private final XMLSyntaxRule[] rules = { |
| 94 |
new ElementRule(TreeModel.class), |
| 95 |
new ElementRule(RATES, Parameter.class, "The rate parameter"), |
| 96 |
AttributeRule.newBooleanRule(RECIPROCAL, true), |
| 97 |
AttributeRule.newBooleanRule(CENTER_AT_ONE, true), |
| 98 |
AttributeRule.newBooleanRule(EXP, true), |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
} |