| 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.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 |
public class MG94CodonModel extends AbstractCodonModel implements Citable { |
| 48 |
|
| 49 |
protected Parameter alphaParameter; |
| 50 |
protected Parameter betaParameter; |
| 51 |
|
| 52 |
protected final int numSynTransitions; |
| 53 |
protected final int numNonsynTransitions; |
| 54 |
|
| 55 |
public MG94CodonModel(Codons codonDataType, Parameter alphaParameter, Parameter betaParameter, |
| 56 |
FrequencyModel freqModel) { |
| 57 |
this(codonDataType, alphaParameter, betaParameter, freqModel, |
| 58 |
new DefaultEigenSystem(codonDataType.getStateCount())); |
| 59 |
} |
| 60 |
|
| 61 |
public MG94CodonModel(Codons codonDataType, |
| 62 |
Parameter alphaParameter, |
| 63 |
Parameter betaParameter, |
| 64 |
FrequencyModel freqModel, EigenSystem eigenSystem) { |
| 65 |
super("MG94", codonDataType, freqModel, eigenSystem); |
| 66 |
|
| 67 |
this.alphaParameter = alphaParameter; |
| 68 |
addVariable(alphaParameter); |
| 69 |
alphaParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, |
| 70 |
alphaParameter.getDimension())); |
| 71 |
|
| 72 |
this.betaParameter = betaParameter; |
| 73 |
addVariable(betaParameter); |
| 74 |
betaParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, |
| 75 |
betaParameter.getDimension())); |
| 76 |
|
| 77 |
numSynTransitions = getNumSynTransitions(); |
| 78 |
numNonsynTransitions = getNumNonsynTransitions(); |
| 79 |
} |
| 80 |
|
| 81 |
private int countRates(int i, int j) { |
| 82 |
int count = 0; |
| 83 |
|
| 84 |
for (byte rate : rateMap) { |
| 85 |
if (rate == i || rate == j) { |
| 86 |
count++; |
| 87 |
} |
| 88 |
} |
| 89 |
return count; |
| 90 |
} |
| 91 |
|
| 92 |
protected int getNumSynTransitions() { |
| 93 |
return 2 * countRates(1, 2); |
| 94 |
} |
| 95 |
|
| 96 |
protected int getNumNonsynTransitions() { |
| 97 |
return 2 * countRates(3, 4); |
| 98 |
} |
| 99 |
|
| 100 |
protected double getNormalizationValue(double[][] matrix, double[] pi) { |
| 101 |
double norm = 1.0; |
| 102 |
if (doNormalization) { |
| 103 |
double ratio = |
| 104 |
getAlpha() + getBeta(); |
| 105 |
|
| 106 |
norm = super.getNormalizationValue(matrix, pi) / ratio; |
| 107 |
} |
| 108 |
return norm; |
| 109 |
} |
| 110 |
|
| 111 |
public double getAlpha() { |
| 112 |
return alphaParameter.getParameterValue(0); |
| 113 |
} |
| 114 |
|
| 115 |
public double getBeta() { |
| 116 |
return betaParameter.getParameterValue(0); |
| 117 |
} |
| 118 |
|
| 119 |
protected void setupRelativeRates(double[] rates) { |
| 120 |
|
| 121 |
double alpha = getAlpha() / numSynTransitions; |
| 122 |
double beta = getBeta() / numNonsynTransitions; |
| 123 |
for (int i = 0; i < rateCount; i++) { |
| 124 |
switch (rateMap[i]) { |
| 125 |
case 0: |
| 126 |
rates[i] = 0.0; |
| 127 |
break; |
| 128 |
case 1: |
| 129 |
rates[i] = alpha; |
| 130 |
break; |
| 131 |
case 2: |
| 132 |
rates[i] = alpha; |
| 133 |
break; |
| 134 |
case 3: |
| 135 |
rates[i] = beta; |
| 136 |
break; |
| 137 |
case 4: |
| 138 |
rates[i] = beta; |
| 139 |
break; |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
public void setNormalization(boolean normalize) { |
| 145 |
this.doNormalization = normalize; |
| 146 |
} |
| 147 |
|
| 148 |
private boolean doNormalization = true; |
| 149 |
|
| 150 |
@Override |
| 151 |
public Citation.Category getCategory() { |
| 152 |
return Citation.Category.SUBSTITUTION_MODELS; |
| 153 |
} |
| 154 |
|
| 155 |
@Override |
| 156 |
public String getDescription() { |
| 157 |
return "Muse-Gaut codon substitution model"; |
| 158 |
} |
| 159 |
|
| 160 |
@Override |
| 161 |
public List<Citation> getCitations() { |
| 162 |
return Collections.singletonList(CITATION); |
| 163 |
} |
| 164 |
|
| 165 |
public static Citation CITATION = new Citation( |
| 166 |
new Author[]{ |
| 167 |
new Author("SV", "Muse"), |
| 168 |
new Author("BS", "Gaut") |
| 169 |
}, |
| 170 |
"A likelihood approach for comparing synonymous and nonsynonymous nucleotide substitution rates, with application to the chloroplast genome", |
| 171 |
1994, |
| 172 |
"Mol Biol Evol", |
| 173 |
11, 715, 724 |
| 174 |
); |
| 175 |
} |