Debian Codegraph @

src/dr/evomodel/branchratemodel/PassageBranchRateModel.java

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