| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodel.substmodel.nucleotide; |
| 27 |
|
| 28 |
import dr.evomodel.substmodel.BaseSubstitutionModel; |
| 29 |
import dr.evomodel.substmodel.FrequencyModel; |
| 30 |
import dr.evolution.datatype.Nucleotides; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.inference.model.Variable; |
| 33 |
import dr.util.Author; |
| 34 |
import dr.util.Citable; |
| 35 |
import dr.util.Citation; |
| 36 |
|
| 37 |
import java.util.Collections; |
| 38 |
import java.util.List; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public class GTR extends BaseSubstitutionModel implements Citable { |
| 50 |
|
| 51 |
public static final String A_TO_C = "AC"; |
| 52 |
public static final String A_TO_G = "AG"; |
| 53 |
public static final String A_TO_T = "AT"; |
| 54 |
public static final String C_TO_G = "CG"; |
| 55 |
public static final String C_TO_T = "CT"; |
| 56 |
public static final String G_TO_T = "GT"; |
| 57 |
|
| 58 |
private Parameter ratesParameter = null; |
| 59 |
|
| 60 |
private Variable<Double> rateACVariable = null; |
| 61 |
private Variable<Double> rateAGVariable = null; |
| 62 |
private Variable<Double> rateATVariable = null; |
| 63 |
private Variable<Double> rateCGVariable = null; |
| 64 |
private Variable<Double> rateCTVariable = null; |
| 65 |
private Variable<Double> rateGTVariable = null; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public GTR( |
| 72 |
Parameter rates, |
| 73 |
FrequencyModel freqModel) { |
| 74 |
super("GTR", Nucleotides.INSTANCE, freqModel); |
| 75 |
this.ratesParameter = rates; |
| 76 |
this.ratesParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, rates.getDimension())); |
| 77 |
addVariable(rates); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public GTR( |
| 90 |
Variable<Double> rateACVariable, |
| 91 |
Variable<Double> rateAGVariable, |
| 92 |
Variable<Double> rateATVariable, |
| 93 |
Variable<Double> rateCGVariable, |
| 94 |
Variable<Double> rateCTVariable, |
| 95 |
Variable<Double> rateGTVariable, |
| 96 |
FrequencyModel freqModel) { |
| 97 |
|
| 98 |
super("GTR", Nucleotides.INSTANCE, freqModel); |
| 99 |
|
| 100 |
if (rateACVariable != null) { |
| 101 |
addVariable(rateACVariable); |
| 102 |
rateACVariable.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 103 |
this.rateACVariable = rateACVariable; |
| 104 |
} |
| 105 |
|
| 106 |
if (rateAGVariable != null) { |
| 107 |
addVariable(rateAGVariable); |
| 108 |
rateAGVariable.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 109 |
this.rateAGVariable = rateAGVariable; |
| 110 |
} |
| 111 |
|
| 112 |
if (rateATVariable != null) { |
| 113 |
addVariable(rateATVariable); |
| 114 |
rateATVariable.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 115 |
this.rateATVariable = rateATVariable; |
| 116 |
} |
| 117 |
|
| 118 |
if (rateCGVariable != null) { |
| 119 |
addVariable(rateCGVariable); |
| 120 |
rateCGVariable.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 121 |
this.rateCGVariable = rateCGVariable; |
| 122 |
} |
| 123 |
|
| 124 |
if (rateCTVariable != null) { |
| 125 |
addVariable(rateCTVariable); |
| 126 |
rateCTVariable.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 127 |
this.rateCTVariable = rateCTVariable; |
| 128 |
} |
| 129 |
|
| 130 |
if (rateGTVariable != null) { |
| 131 |
addVariable(rateGTVariable); |
| 132 |
rateGTVariable.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 133 |
this.rateGTVariable = rateGTVariable; |
| 134 |
} |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
public void setAbsoluteRates(double[] rates, int relativeTo) { |
| 139 |
for (int i = 0; i < relativeRates.length; i++) { |
| 140 |
relativeRates[i] = rates[i] / rates[relativeTo]; |
| 141 |
} |
| 142 |
updateMatrix = true; |
| 143 |
fireModelChanged(); |
| 144 |
} |
| 145 |
|
| 146 |
public void setRelativeRates(double[] rates) { |
| 147 |
System.arraycopy(rates, 0, relativeRates, 0, relativeRates.length); |
| 148 |
updateMatrix = true; |
| 149 |
fireModelChanged(); |
| 150 |
} |
| 151 |
|
| 152 |
protected void frequenciesChanged() { |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
protected void ratesChanged() { |
| 157 |
|
| 158 |
} |
| 159 |
|
| 160 |
protected void setupRelativeRates(double[] rates) { |
| 161 |
if (ratesParameter == null) { |
| 162 |
if (rateACVariable != null) { |
| 163 |
rates[0] = rateACVariable.getValue(0); |
| 164 |
} |
| 165 |
if (rateAGVariable != null) { |
| 166 |
rates[1] = rateAGVariable.getValue(0); |
| 167 |
} |
| 168 |
if (rateATVariable != null) { |
| 169 |
rates[2] = rateATVariable.getValue(0); |
| 170 |
} |
| 171 |
if (rateCGVariable != null) { |
| 172 |
rates[3] = rateCGVariable.getValue(0); |
| 173 |
} |
| 174 |
if (rateCTVariable != null) { |
| 175 |
rates[4] = rateCTVariable.getValue(0); |
| 176 |
} |
| 177 |
if (rateGTVariable != null) { |
| 178 |
rates[5] = rateGTVariable.getValue(0); |
| 179 |
} |
| 180 |
} else { |
| 181 |
System.arraycopy(this.ratesParameter.getParameterValues(), 0, rates, 0, rates.length); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public String toXHTML() { |
| 190 |
StringBuffer buffer = new StringBuffer(); |
| 191 |
|
| 192 |
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>"); |
| 193 |
buffer.append("<tr><td>A</td><td></td><td>"); |
| 194 |
buffer.append(relativeRates[0]); |
| 195 |
buffer.append("</td><td>"); |
| 196 |
buffer.append(relativeRates[1]); |
| 197 |
buffer.append("</td><td>"); |
| 198 |
buffer.append(relativeRates[2]); |
| 199 |
buffer.append("</td></tr>"); |
| 200 |
|
| 201 |
buffer.append("<tr><td>C</td><td></td><td></td><td>"); |
| 202 |
buffer.append(relativeRates[3]); |
| 203 |
buffer.append("</td><td>"); |
| 204 |
buffer.append(relativeRates[4]); |
| 205 |
buffer.append("</td></tr>"); |
| 206 |
|
| 207 |
buffer.append("<tr><td>G</td><td></td><td></td><td></td><td>"); |
| 208 |
buffer.append(relativeRates[5]); |
| 209 |
buffer.append("</td></tr>"); |
| 210 |
|
| 211 |
buffer.append("<tr><td>G</td><td></td><td></td><td></td><td></td></tr></table>"); |
| 212 |
|
| 213 |
return buffer.toString(); |
| 214 |
} |
| 215 |
|
| 216 |
@Override |
| 217 |
public Citation.Category getCategory() { |
| 218 |
return Citation.Category.SUBSTITUTION_MODELS; |
| 219 |
} |
| 220 |
|
| 221 |
@Override |
| 222 |
public String getDescription() { |
| 223 |
return "GTR nucleotide substitution model"; |
| 224 |
} |
| 225 |
|
| 226 |
@Override |
| 227 |
public List<Citation> getCitations() { |
| 228 |
return Collections.singletonList(CITATION); |
| 229 |
} |
| 230 |
|
| 231 |
public static Citation CITATION = new Citation( |
| 232 |
new Author[]{ |
| 233 |
new Author("S", "Tavaré") |
| 234 |
}, |
| 235 |
"Some probabilistic and statistical problems in the analysis of DNA sequences", |
| 236 |
1985, |
| 237 |
"In: Miura R. M., editor. Lectures on Mathematics in the Life Sciences", |
| 238 |
17, 57, 86 |
| 239 |
); |
| 240 |
|
| 241 |
} |