| 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.evolution.tree.TreeTraitProvider; |
| 29 |
import dr.evomodel.branchratemodel.ArbitraryBranchRates; |
| 30 |
import dr.evomodel.branchratemodel.RelaxedDriftModel; |
| 31 |
import dr.evomodel.tree.TreeModel; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
import java.util.logging.Logger; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class RelaxedDriftModelParser extends AbstractXMLObjectParser { |
| 45 |
|
| 46 |
public static final String RELAXED_DRIFT = "relaxedDriftModel"; |
| 47 |
public static final String RATES = "rates"; |
| 48 |
public static final String RATE_IND = "rateIndicator"; |
| 49 |
public static final String DRIFT_RATES = "driftRates"; |
| 50 |
public static final String BRANCH_CHANGES = "branchChanges"; |
| 51 |
|
| 52 |
public String getParserName() { |
| 53 |
return RELAXED_DRIFT; |
| 54 |
} |
| 55 |
|
| 56 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 57 |
|
| 58 |
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class); |
| 59 |
|
| 60 |
Parameter ratesParameter = (Parameter) xo.getElementFirstChild(RATES); |
| 61 |
|
| 62 |
Parameter rateIndicatorParameter = (Parameter) xo.getElementFirstChild(RATE_IND); |
| 63 |
|
| 64 |
Parameter driftRates = null; |
| 65 |
if (xo.hasChildNamed(DRIFT_RATES)) { |
| 66 |
driftRates = (Parameter) xo.getElementFirstChild(DRIFT_RATES); |
| 67 |
} |
| 68 |
|
| 69 |
ArbitraryBranchRates branchChanges = null; |
| 70 |
if (xo.hasChildNamed(BRANCH_CHANGES)){ |
| 71 |
branchChanges = (ArbitraryBranchRates) xo.getElementFirstChild(BRANCH_CHANGES); |
| 72 |
} |
| 73 |
|
| 74 |
Logger.getLogger("dr.evomodel").info("Using relaxed drift model."); |
| 75 |
|
| 76 |
|
| 77 |
return new RelaxedDriftModel(tree, rateIndicatorParameter, |
| 78 |
ratesParameter, driftRates, branchChanges); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public String getParserDescription() { |
| 86 |
return |
| 87 |
"This element returns a relaxed drift model."; |
| 88 |
} |
| 89 |
|
| 90 |
public Class getReturnType() { |
| 91 |
return RelaxedDriftModel.class; |
| 92 |
} |
| 93 |
|
| 94 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 95 |
return rules; |
| 96 |
} |
| 97 |
|
| 98 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 99 |
new ElementRule(TreeModel.class), |
| 100 |
new ElementRule(RATES, Parameter.class, "The rates parameter", false), |
| 101 |
new ElementRule(RATE_IND, Parameter.class, "The indicator parameter", false), |
| 102 |
new ElementRule(DRIFT_RATES, Parameter.class, "The drift rates parameter", true), |
| 103 |
new ElementRule(BRANCH_CHANGES, ArbitraryBranchRates.class, "Branch specific rate change indicators", true) |
| 104 |
}; |
| 105 |
} |