Debian Codegraph @

src/dr/oldevomodel/indel/TKF91Likelihood.java

raw symbols SCIP
1 /*
2 * TKF91Likelihood.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.oldevomodel.indel;
27
28 import dr.evolution.alignment.Alignment;
29 import dr.oldevomodel.sitemodel.GammaSiteModel;
30 import dr.evomodel.tree.TreeModel;
31 import dr.oldevomodelxml.indel.TKF91LikelihoodParser;
32 import dr.inference.model.*;
33
34
35 /**
36 * Calculates the likelihood of a set of continuous attributes on a tree.
37 *
38 * @author Alexei Drummond
39 * @version $Id: TKF91Likelihood.java,v 1.17 2005/06/20 07:24:25 rambaut Exp $
40 */
41 public class TKF91Likelihood extends AbstractModelLikelihood {
42
43 public TKF91Likelihood(TreeModel treeModel, Alignment alignment, GammaSiteModel siteModel, TKF91Model tkfModel) {
44
45 super(TKF91LikelihoodParser.TKF91_LIKELIHOOD);
46
47 if (siteModel.getAlphaParameter() != null)
48 throw new IllegalArgumentException("TKF91 model cannot handle gamma-distributed rates");
49 if (siteModel.getPInvParameter() != null)
50 throw new IllegalArgumentException("TKF91 model cannot handle invariant sites");
51
52 addModel(siteModel);
53 addModel(tkfModel);
54 addModel(treeModel);
55
56 this.treeModel = treeModel;
57 this.alignment = alignment;
58 this.siteModel = siteModel;
59 this.tkfModel = tkfModel;
60
61 recursion = new HomologyRecursion();
62 recursion.init(
63 treeModel,
64 alignment,
65 siteModel.getSubstitutionModel(),
66 siteModel.getMutationRateParameter().getParameterValue(0),
67 tkfModel.getLengthDistributionValue(),
68 tkfModel.getDeathRate(1));
69
70 addStatistic(new AlignmentLengthStatistic());
71 }
72
73 public class AlignmentLengthStatistic extends Statistic.Abstract {
74
75 public double getStatisticValue(int dim) {
76 return alignment.getSiteCount();
77 }
78
79 public int getDimension() {
80 return 1;
81 }
82
83 public String getStatisticName() {
84 return "alignmentLength";
85 }
86 }
87
88 public void acceptState() {
89 //throw new RuntimeException("Not implemented!");
90 }
91
92 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
93 //throw new RuntimeException("Not implemented!");
94 }
95
96 public void handleModelChangedEvent(Model m, Object o, int i) {
97 //throw new RuntimeException("Not implemented!");
98 }
99
100 /**
101 * Sets the alignment of this tkf91likelihood
102 */
103 public void setAlignment(Alignment a) {
104 alignment = a;
105 //System.out.println("Set new alignment");
106 }
107
108 protected void storeState() {
109 //super.storeState();
110 //storedAlignment = alignment;
111 //System.out.println("Stored alignment");
112
113 }
114
115 protected void restoreState() {
116 //super.restoreState();
117 //alignment = storedAlignment;
118 //System.out.println("restored alignment");
119 }
120
121 public Alignment getAlignment() {
122 return alignment;
123 }
124
125 public GammaSiteModel getSiteModel() {
126 return siteModel;
127 }
128
129 public TreeModel getTreeModel() {
130 return treeModel;
131 }
132
133 public void makeDirty() { // this is always dirty
134 }
135
136 public Model getModel() {
137 return this;
138 }
139
140 /**
141 * Get the log likelihood.
142 *
143 * @return the log likelihood.
144 */
145 public double getLogLikelihood() {
146
147 recursion.init(
148 treeModel,
149 alignment,
150 siteModel.getSubstitutionModel(),
151 siteModel.getMutationRateParameter().getParameterValue(0),
152 tkfModel.getLengthDistributionValue(),
153 tkfModel.getDeathRate(1));
154
155 double logL = recursion.recursion();
156
157 //System.out.println("logL = " + logL);
158 return logL;
159 }
160
161 // **************************************************************
162 // Identifiable IMPLEMENTATION
163 // **************************************************************
164
165 private String id = null;
166
167 public void setId(String id) {
168 this.id = id;
169 }
170
171 public String getId() {
172 return id;
173 }
174
175
176 public String toString() {
177 if (id != null) {
178 return id;
179 }
180 return super.toString();
181 }
182
183 protected boolean getLikelihoodKnown() {
184 return false;
185 }
186
187 private final TreeModel treeModel;
188 private Alignment alignment;
189 //private Alignment storedAlignment;
190 private final GammaSiteModel siteModel;
191 private final TKF91Model tkfModel;
192 private HomologyRecursion recursion = null;
193 }