Debian Codegraph @

src/dr/evomodel/branchratemodel/TipBranchRateModel.java

raw symbols SCIP
1 /*
2 * TipBranchRateModel.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.evomodel.branchratemodel;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.evolution.tree.Tree;
30 import dr.inference.model.Model;
31 import dr.inference.model.Parameter;
32 import dr.inference.model.Variable;
33 import dr.xml.*;
34
35 /**
36 * @author Andrew Rambaut
37 * @version $Id: TipBranchRateModel.java,v 1.1 2005/12/14 16:46:20 rambaut Exp $
38 */
39 public class TipBranchRateModel extends AbstractBranchRateModel {
40
41 public static final String TIP_BRANCH_RATE_MODEL = "tipBranchRateModel";
42 public static final String EXTERNAL_RATE = "externalRate";
43 public static final String INTERNAL_RATE = "internalRate";
44
45 private Parameter internalRateParameter;
46 private Parameter externalRateParameter;
47
48 public TipBranchRateModel(Parameter externalRateParameter, Parameter internalRateParameter) {
49
50 super(TIP_BRANCH_RATE_MODEL);
51
52 this.internalRateParameter = internalRateParameter;
53 addVariable(internalRateParameter);
54
55 this.externalRateParameter = externalRateParameter;
56 addVariable(externalRateParameter);
57 }
58
59 public void handleModelChangedEvent(Model model, Object object, int index) {
60 fireModelChanged();
61 }
62
63 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
64 fireModelChanged();
65 }
66
67 protected void storeState() {
68 }
69
70 protected void restoreState() {
71 }
72
73 protected void acceptState() {
74 }
75
76 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
77
78 public String getParserName() {
79 return TIP_BRANCH_RATE_MODEL;
80 }
81
82 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
83
84 Parameter externalRateParameter = (Parameter) xo.getElementFirstChild(EXTERNAL_RATE);
85 Parameter internalRateParameter = (Parameter) xo.getElementFirstChild(INTERNAL_RATE);
86
87 TipBranchRateModel tipBranchRateModel = new TipBranchRateModel(externalRateParameter, internalRateParameter);
88
89 System.out.println("Using tip branch rate model.");
90
91 return tipBranchRateModel;
92 }
93
94 //************************************************************************
95 // AbstractXMLObjectParser implementation
96 //************************************************************************
97
98 public String getParserDescription() {
99 return
100 "This element returns a branch rate model that has a different rate for external branches than internal.";
101 }
102
103 public Class getReturnType() {
104 return TipBranchRateModel.class;
105 }
106
107 public XMLSyntaxRule[] getSyntaxRules() {
108 return rules;
109 }
110
111 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
112 new ElementRule(EXTERNAL_RATE, Parameter.class, "The molecular evolutionary rate parameter for external branches", false),
113 new ElementRule(INTERNAL_RATE, Parameter.class, "The molecular evolutionary rate parameter for internal branches", false)
114 };
115 };
116
117 public double getBranchRate(final Tree tree, final NodeRef node) {
118 if (tree.isExternal(node)) {
119 return externalRateParameter.getParameterValue(0);
120 } else {
121 return internalRateParameter.getParameterValue(0);
122
123 }
124 }
125
126 }