| 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.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 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public class GY94CodonModel extends AbstractCodonModel implements Citable { |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
protected Parameter kappaParameter; |
| 54 |
|
| 55 |
|
| 56 |
|
| 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 |
} |
| 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 |
} |
| 92 |
|
| 93 |
addVariable(kappaParameter); |
| 94 |
kappaParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, |
| 95 |
kappaParameter.getDimension())); |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
addStatistic(synonymousRateStatistic); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public void setKappa(double kappa) { |
| 109 |
kappaParameter.setParameterValue(0, kappa); |
| 110 |
updateMatrix = true; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public double getKappa() { |
| 117 |
return kappaParameter.getParameterValue(0); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public void setOmega(double omega) { |
| 126 |
omegaParameter.setParameterValue(0, omega); |
| 127 |
updateMatrix = true; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 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; |
| 156 |
case 1: |
| 157 |
rates[i] = kappa; |
| 158 |
break; |
| 159 |
case 2: |
| 160 |
rates[i] = 1.0; |
| 161 |
break; |
| 162 |
case 3: |
| 163 |
rates[i] = kappa * omega; |
| 164 |
break; |
| 165 |
case 4: |
| 166 |
rates[i] = omega; |
| 167 |
break; |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 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 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 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 |
} |