Debian Codegraph @

src/dr/oldevomodel/substmodel/GTR.java

raw symbols SCIP
1 /*
2 * GTR.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.substmodel;
27
28 import dr.oldevomodelxml.substmodel.GTRParser;
29 import dr.inference.model.Parameter;
30 import dr.inference.model.Variable;
31 import dr.util.Author;
32 import dr.util.Citable;
33 import dr.util.Citation;
34
35 import java.util.Collections;
36 import java.util.List;
37
38 /**
39 * General Time Reversible model of nucleotide evolution
40 * This is really just a place-holder because all the implementation
41 * already exists in NucleotideModel and GeneralModel, its base classes.
42 *
43 * @author Andrew Rambaut
44 * @author Alexei Drummond
45 * @version $Id: GTR.java,v 1.19 2005/05/24 20:25:58 rambaut Exp $
46 */
47 public class GTR extends AbstractNucleotideModel implements Citable {
48
49 private Variable<Double> rateACValue = null;
50 private Variable<Double> rateAGValue = null;
51 private Variable<Double> rateATValue = null;
52 private Variable<Double> rateCGValue = null;
53 private Variable<Double> rateCTValue = null;
54 private Variable<Double> rateGTValue = null;
55
56 /**
57 * @param rateACValue rate of A<->C substitutions
58 * @param rateAGValue rate of A<->G substitutions
59 * @param rateATValue rate of A<->T substitutions
60 * @param rateCGValue rate of C<->G substitutions
61 * @param rateCTValue rate of C<->T substitutions
62 * @param rateGTValue rate of G<->T substitutions
63 * @param freqModel frequencies
64 */
65 public GTR(
66 Variable rateACValue,
67 Variable rateAGValue,
68 Variable rateATValue,
69 Variable rateCGValue,
70 Variable rateCTValue,
71 Variable rateGTValue,
72 FrequencyModel freqModel) {
73
74 super(GTRParser.GTR_MODEL, freqModel);
75
76 if (rateACValue != null) {
77 addVariable(rateACValue);
78 rateACValue.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
79 this.rateACValue = rateACValue;
80 }
81
82 if (rateAGValue != null) {
83 addVariable(rateAGValue);
84 rateAGValue.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
85 this.rateAGValue = rateAGValue;
86 }
87
88 if (rateATValue != null) {
89 addVariable(rateATValue);
90 rateATValue.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
91 this.rateATValue = rateATValue;
92 }
93
94 if (rateCGValue != null) {
95 addVariable(rateCGValue);
96 rateCGValue.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
97 this.rateCGValue = rateCGValue;
98 }
99
100 if (rateCTValue != null) {
101 addVariable(rateCTValue);
102 rateCTValue.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
103 this.rateCTValue = rateCTValue;
104 }
105
106 if (rateGTValue != null) {
107 addVariable(rateGTValue);
108 rateGTValue.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
109 this.rateGTValue = rateGTValue;
110 }
111
112 }
113
114 public void setAbsoluteRates(double[] rates, int relativeTo) {
115 for (int i = 0; i < relativeRates.length; i++) {
116 relativeRates[i] = rates[i] / rates[relativeTo];
117 }
118 updateMatrix = true;
119 fireModelChanged();
120 }
121
122 public void setRelativeRates(double[] rates) {
123 System.arraycopy(rates, 0, relativeRates, 0, relativeRates.length);
124 updateMatrix = true;
125 fireModelChanged();
126 }
127
128 protected void setupRelativeRates() {
129
130 if (rateACValue != null) {
131 relativeRates[0] = rateACValue.getValue(0);
132 }
133 if (rateAGValue != null) {
134 relativeRates[1] = rateAGValue.getValue(0);
135 }
136 if (rateATValue != null) {
137 relativeRates[2] = rateATValue.getValue(0);
138 }
139 if (rateCGValue != null) {
140 relativeRates[3] = rateCGValue.getValue(0);
141 }
142 if (rateCTValue != null) {
143 relativeRates[4] = rateCTValue.getValue(0);
144 }
145 if (rateGTValue != null) {
146 relativeRates[5] = rateGTValue.getValue(0);
147 }
148 }
149
150 // **************************************************************
151 // XHTMLable IMPLEMENTATION
152 // **************************************************************
153
154 public String toXHTML() {
155 StringBuffer buffer = new StringBuffer();
156
157 buffer.append("<em>GTR Model</em> Instantaneous Rate Matrix = <table><tr><td></td><td>A</td><td>C</td><td>G</td><td>T</td></tr>");
158 buffer.append("<tr><td>A</td><td></td><td>");
159 buffer.append(relativeRates[0]);
160 buffer.append("</td><td>");
161 buffer.append(relativeRates[1]);
162 buffer.append("</td><td>");
163 buffer.append(relativeRates[2]);
164 buffer.append("</td></tr>");
165
166 buffer.append("<tr><td>C</td><td></td><td></td><td>");
167 buffer.append(relativeRates[3]);
168 buffer.append("</td><td>");
169 buffer.append(relativeRates[4]);
170 buffer.append("</td></tr>");
171
172 buffer.append("<tr><td>G</td><td></td><td></td><td></td><td>");
173 buffer.append(relativeRates[5]);
174 buffer.append("</td></tr>");
175
176 buffer.append("<tr><td>G</td><td></td><td></td><td></td><td></td></tr></table>");
177
178 return buffer.toString();
179 }
180
181 @Override
182 public Citation.Category getCategory() {
183 return Citation.Category.SUBSTITUTION_MODELS;
184 }
185
186 @Override
187 public String getDescription() {
188 return "GTR nucleotide substitution model";
189 }
190
191 @Override
192 public List<Citation> getCitations() {
193 return Collections.singletonList(CITATION);
194 }
195
196
197 public static Citation CITATION = new Citation(
198 new Author[]{
199 new Author("S", "Tavaré")
200 },
201 "Some probabilistic and statistical problems in the analysis of DNA sequences",
202 1985,
203 "In: Miura R. M., editor. Lectures on mathematics in the life sciences.",
204 17, 57, 86
205 );
206
207 }