Debian Codegraph @

src/dr/evomodelxml/branchratemodel/LatentStateBranchRateModelParser.java

raw symbols SCIP
1 /*
2 * LatentStateBranchRateModelParser.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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, /* 0/1 CTMC have two parameters */
65 latentStateProportionParameter, branchCategoryProvider);
66 // return new SericolaLatentStateBranchRateModel(SericolaLatentStateBranchRateModel.LATENT_STATE_BRANCH_RATE_MODEL,
67 // tree, nonLatentRateModel,
68 // latentTransitionRateParameter, latentTransitionFrequencyParameter, /* 0/1 CTMC have two parameters */
69 // latentStateProportionParameter, branchCategoryProvider);
70 }
71
72 //************************************************************************
73 // AbstractXMLObjectParser implementation
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 }