| 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.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 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 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 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 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 |
|
| 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 |
} |