| 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.*; |
| 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 LatentStateBranchRateModelParser extends AbstractXMLObjectParser { |
| 38 |
public static final String LATENT_TRANSITION_RATE = "latentTransitionRate"; |
| 39 |
public static final String LATENT_TRANSITION_FREQUENCY = "latentTransitionFrequency"; |
| 40 |
public static final String LATENT_STATE_PROPORTIONS = "latentStateProportions"; |
| 41 |
|
| 42 |
|
| 43 |
public String getParserName() { |
| 44 |
return SericolaLatentStateBranchRateModel.LATENT_STATE_BRANCH_RATE_MODEL; |
| 45 |
} |
| 46 |
|
| 47 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 48 |
BranchRateModel nonLatentRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class); |
| 49 |
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class); |
| 50 |
Parameter latentTransitionRateParameter = (Parameter) xo.getElementFirstChild(LATENT_TRANSITION_RATE); |
| 51 |
Parameter latentTransitionFrequencyParameter = (Parameter) xo.getElementFirstChild(LATENT_TRANSITION_FREQUENCY); |
| 52 |
|
| 53 |
CountableBranchCategoryProvider branchCategoryProvider = (CountableBranchCategoryProvider)xo.getChild(CountableBranchCategoryProvider.class); |
| 54 |
|
| 55 |
Parameter latentStateProportionParameter = null; |
| 56 |
if (xo.hasChildNamed(LATENT_STATE_PROPORTIONS)) { |
| 57 |
latentStateProportionParameter = (Parameter) xo.getElementFirstChild(LATENT_STATE_PROPORTIONS); |
| 58 |
} |
| 59 |
|
| 60 |
Logger.getLogger("dr.evomodel").info("\nCreating a latent state branch rate model"); |
| 61 |
|
| 62 |
return new LatentStateBranchRateModel(LatentStateBranchRateModel.LATENT_STATE_BRANCH_RATE_MODEL, |
| 63 |
tree, nonLatentRateModel, |
| 64 |
latentTransitionRateParameter, latentTransitionFrequencyParameter, |
| 65 |
latentStateProportionParameter, branchCategoryProvider); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public String getParserDescription() { |
| 77 |
return "This element provides a model with a latent state where no evolution occurs but condition on being non-latent at the nodes."; |
| 78 |
} |
| 79 |
|
| 80 |
public Class getReturnType() { |
| 81 |
return SericolaLatentStateBranchRateModel.class; |
| 82 |
} |
| 83 |
|
| 84 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 85 |
return rules; |
| 86 |
} |
| 87 |
|
| 88 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 89 |
|
| 90 |
new ElementRule(BranchRateModel.class, "A branch rate model to provide the rates for the non-latent state"), |
| 91 |
new ElementRule(TreeModel.class, "The tree on which this will operate"), |
| 92 |
new ElementRule(CountableBranchCategoryProvider.class, true), |
| 93 |
new ElementRule(LATENT_TRANSITION_RATE, Parameter.class, "A parameter which gives the instantaneous rate of switching to and from the latent state", false), |
| 94 |
new ElementRule(LATENT_TRANSITION_FREQUENCY, Parameter.class, "A parameter which gives the rate bias of switching to and from the latent state", false), |
| 95 |
new ElementRule(LATENT_STATE_PROPORTIONS, Parameter.class, "The proportion of each branch which is spend in a latent state", true) |
| 96 |
|
| 97 |
}; |
| 98 |
|
| 99 |
} |