| 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.RandomLocalClockModel; |
| 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 RandomLocalClockModelParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String LOCAL_BRANCH_RATES = "randomLocalClockModel"; |
| 40 |
public static final String RATE_INDICATORS = "rateIndicator"; |
| 41 |
public static final String RATES = "rates"; |
| 42 |
public static final String CLOCK_RATE = "clockRate"; |
| 43 |
public static final String RATES_ARE_MULTIPLIERS = "ratesAreMultipliers"; |
| 44 |
public static final String THRESHOLD = "threshold"; |
| 45 |
|
| 46 |
public String getParserName() { |
| 47 |
return LOCAL_BRANCH_RATES; |
| 48 |
} |
| 49 |
|
| 50 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 51 |
|
| 52 |
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class); |
| 53 |
|
| 54 |
Parameter rateIndicatorParameter = (Parameter) xo.getElementFirstChild(RATE_INDICATORS); |
| 55 |
Parameter ratesParameter = (Parameter) xo.getElementFirstChild(RATES); |
| 56 |
Parameter meanRateParameter = null; |
| 57 |
|
| 58 |
if (xo.hasChildNamed(CLOCK_RATE)) { |
| 59 |
meanRateParameter = (Parameter) xo.getElementFirstChild(CLOCK_RATE); |
| 60 |
} |
| 61 |
|
| 62 |
boolean ratesAreMultipliers = xo.getAttribute(RATES_ARE_MULTIPLIERS, false); |
| 63 |
|
| 64 |
Logger.getLogger("dr.evomodel").info("\nUsing random local clock (RLC) model."); |
| 65 |
Logger.getLogger("dr.evomodel").info(" rates at change points are parameterized to be " + |
| 66 |
(ratesAreMultipliers ? " relative to parent rates." : "independent of parent rates.")); |
| 67 |
|
| 68 |
double threshold = xo.getAttribute(THRESHOLD, Double.NaN); |
| 69 |
|
| 70 |
return new RandomLocalClockModel(tree, meanRateParameter, rateIndicatorParameter, |
| 71 |
ratesParameter, ratesAreMultipliers, threshold); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public String getParserDescription() { |
| 79 |
return |
| 80 |
"This element returns an random local clock (RLC) model." + |
| 81 |
"Each branch either has a new rate or " + |
| 82 |
"inherits the rate of the branch above it depending on the indicator vector, " + |
| 83 |
"which is itself sampled."; |
| 84 |
} |
| 85 |
|
| 86 |
public Class getReturnType() { |
| 87 |
return RandomLocalClockModel.class; |
| 88 |
} |
| 89 |
|
| 90 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 91 |
return rules; |
| 92 |
} |
| 93 |
|
| 94 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 95 |
new ElementRule(TreeModel.class), |
| 96 |
new ElementRule(RATE_INDICATORS, Parameter.class, "The rate change indicators parameter", false), |
| 97 |
new ElementRule(RATES, Parameter.class, "The rates parameter", false), |
| 98 |
new ElementRule(CLOCK_RATE, Parameter.class, "The mean rate across all local clocks", true), |
| 99 |
AttributeRule.newBooleanRule(RATES_ARE_MULTIPLIERS, false), |
| 100 |
AttributeRule.newDoubleRule(THRESHOLD, true), |
| 101 |
}; |
| 102 |
} |