Debian Codegraph @

src/dr/evomodel/substmodel/codon/GY94CodonModel.java

raw symbols SCIP
1 /*
2 * GY94CodonModel.java
3 *
4 * Copyright (c) 2002-2016 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.substmodel.codon;
27
28 import dr.evomodel.substmodel.DefaultEigenSystem;
29 import dr.evomodel.substmodel.EigenSystem;
30 import dr.evomodel.substmodel.FrequencyModel;
31 import dr.evolution.datatype.Codons;
32 import dr.inference.model.Parameter;
33 import dr.inference.model.Statistic;
34 import dr.util.Author;
35 import dr.util.Citable;
36 import dr.util.Citation;
37
38 import java.util.Collections;
39 import java.util.List;
40
41 /**
42 * Yang model of codon evolution
43 *
44 * @author Andrew Rambaut
45 * @author Alexei Drummond
46 * @author Marc A. Suchard
47 * @version $Id: YangCodonModel.java,v 1.21 2005/05/24 20:25:58 rambaut Exp $
48 */
49 public class GY94CodonModel extends AbstractCodonModel implements Citable {
50 /**
51 * kappa
52 */
53 protected Parameter kappaParameter;
54
55 /**
56 * omega
57 */
58 protected Parameter omegaParameter;
59
60 public GY94CodonModel(Codons codonDataType, Parameter omegaParameter, Parameter kappaParameter,
61 FrequencyModel freqModel) {
62 this(codonDataType, omegaParameter, kappaParameter, freqModel,
63 new DefaultEigenSystem(codonDataType.getStateCount()));
64 }
65
66 public GY94CodonModel(Codons codonDataType,
67 Parameter omegaParameter,
68 Parameter kappaParameter,
69 FrequencyModel freqModel, EigenSystem eigenSystem) {
70
71 super("GY94", codonDataType, freqModel, eigenSystem);
72
73 this.omegaParameter = omegaParameter;
74
75 int dim = omegaParameter.getDimension();
76 double value = omegaParameter.getParameterValue(dim - 1);
77 if(value < 0) {
78 throw new RuntimeException("Negative Omega parameter value " + value);
79 }//END: negative check
80
81 addVariable(omegaParameter);
82 omegaParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0,
83 omegaParameter.getDimension()));
84
85 this.kappaParameter = kappaParameter;
86
87 dim = kappaParameter.getDimension();
88 value = kappaParameter.getParameterValue(dim - 1);
89 if(value < 0) {
90 throw new RuntimeException("Negative kappa parameter value value " + value);
91 }//END: negative check
92
93 addVariable(kappaParameter);
94 kappaParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0,
95 kappaParameter.getDimension()));
96
97 // Assuming it's always the same dim
98
99
100 addStatistic(synonymousRateStatistic);
101 }
102
103 /**
104 * set kappa
105 *
106 * @param kappa kappa
107 */
108 public void setKappa(double kappa) {
109 kappaParameter.setParameterValue(0, kappa);
110 updateMatrix = true;
111 }
112
113 /**
114 * @return kappa
115 */
116 public double getKappa() {
117 return kappaParameter.getParameterValue(0);
118 }
119
120 /**
121 * set dN/dS
122 *
123 * @param omega omega
124 */
125 public void setOmega(double omega) {
126 omegaParameter.setParameterValue(0, omega);
127 updateMatrix = true;
128 }
129
130 /**
131 * @return dN/dS
132 */
133 public double getOmega() {
134 return omegaParameter.getParameterValue(0);
135 }
136
137 public double getSynonymousRate() {
138 double k = getKappa();
139 double o = getOmega();
140 return ((31.0 * k) + 36.0) / ((31.0 * k) + 36.0 + (138.0 * o) + (58.0 * o * k));
141 }
142
143 public double getNonSynonymousRate() {
144 return 0;
145 }
146
147 protected void setupRelativeRates(double[] rates) {
148
149 double kappa = getKappa();
150 double omega = getOmega();
151 for (int i = 0; i < rateCount; i++) {
152 switch (rateMap[i]) {
153 case 0:
154 rates[i] = 0.0;
155 break; // codon changes in more than one codon position
156 case 1:
157 rates[i] = kappa;
158 break; // synonymous transition
159 case 2:
160 rates[i] = 1.0;
161 break; // synonymous transversion
162 case 3:
163 rates[i] = kappa * omega;
164 break;// non-synonymous transition
165 case 4:
166 rates[i] = omega;
167 break; // non-synonymous transversion
168 }
169 }
170 }
171
172 // **************************************************************
173 // XHTMLable IMPLEMENTATION
174 // **************************************************************
175
176 public String toXHTML() {
177 StringBuffer buffer = new StringBuffer();
178
179 buffer.append("<em>Goldman Yang 94 Codon Model</em> kappa = ");
180 buffer.append(getKappa());
181 buffer.append(", omega = ");
182 buffer.append(getOmega());
183
184 return buffer.toString();
185 }
186
187 public Statistic synonymousRateStatistic = new Statistic.Abstract() {
188
189 public String getStatisticName() {
190 return "synonymousRate";
191 }
192
193 public int getDimension() {
194 return 1;
195 }
196
197 public double getStatisticValue(int dim) {
198 return getSynonymousRate();
199 }
200
201 };
202
203 /* private Statistic nonsynonymousRateStatistic = new Statistic.Abstract() {
204
205 public String getStatisticName() {
206 return "nonSynonymousRate";
207 }
208
209 public int getDimension() { return 1; }
210
211 public double getStatisticValue(int dim) {
212 return getNonSynonymousRate();
213 }
214
215 };*/
216
217 @Override
218 public Citation.Category getCategory() {
219 return Citation.Category.SUBSTITUTION_MODELS;
220 }
221
222 @Override
223 public String getDescription() {
224 return "Goldman-Yang codon substitution model";
225 }
226
227 @Override
228 public List<Citation> getCitations() {
229 return Collections.singletonList(CITATION);
230 }
231
232
233 public static Citation CITATION = new Citation(
234 new Author[]{
235 new Author("N", "Goldman"),
236 new Author("Z", "Yang")
237 },
238 "A codon-based model of nucleotide substitution for protein-coding DNA sequences",
239 1994,
240 "Mol Biol Evol",
241 11, 725, 736
242 );
243
244 }