| 1 |
package test.dr.evomodel.sitemodel; |
| 2 |
|
| 3 |
import junit.framework.TestCase; |
| 4 |
import dr.inference.model.Variable; |
| 5 |
import dr.inference.model.Parameter; |
| 6 |
import dr.oldevomodel.substmodel.SubstitutionModel; |
| 7 |
import dr.oldevomodel.substmodel.FrequencyModel; |
| 8 |
import dr.oldevomodel.substmodel.HKY; |
| 9 |
import dr.oldevomodel.sitemodel.GammaSiteBMA; |
| 10 |
import dr.evolution.datatype.Nucleotides; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public class testGammaSiteBMA extends TestCase { |
| 17 |
interface Instance { |
| 18 |
SubstitutionModel getSubstModel (); |
| 19 |
|
| 20 |
double getMu(); |
| 21 |
|
| 22 |
double getLogitInvar(); |
| 23 |
|
| 24 |
double getLogShape(); |
| 25 |
|
| 26 |
int getCategoryCount(); |
| 27 |
|
| 28 |
Variable<Integer> getModelChoose(); |
| 29 |
|
| 30 |
double[] getCategoryRates(); |
| 31 |
|
| 32 |
double[] getCategoryProportions(); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
Instance test0 = new Instance(){ |
| 37 |
public SubstitutionModel getSubstModel (){ |
| 38 |
|
| 39 |
|
| 40 |
Parameter kappa = new Parameter.Default(1, 1); |
| 41 |
double[] pi = new double[]{0.25, 0.25, 0.25, 0.25}; |
| 42 |
|
| 43 |
Parameter freqs = new Parameter.Default(pi); |
| 44 |
FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs); |
| 45 |
HKY jc = new HKY(kappa, f); |
| 46 |
return jc; |
| 47 |
} |
| 48 |
|
| 49 |
public double getMu(){ |
| 50 |
return 1.5; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
public double getLogitInvar(){ |
| 55 |
|
| 56 |
return -1.38629436112; |
| 57 |
} |
| 58 |
|
| 59 |
public double getLogShape(){ |
| 60 |
|
| 61 |
return 0.69314718056; |
| 62 |
} |
| 63 |
|
| 64 |
public int getCategoryCount(){ |
| 65 |
return 4; |
| 66 |
} |
| 67 |
|
| 68 |
public Variable<Integer> getModelChoose(){ |
| 69 |
return new Variable.I(new int[]{0, 0}); |
| 70 |
} |
| 71 |
|
| 72 |
public double[] getCategoryRates(){ |
| 73 |
return new double[]{0.0, 1.5, 1.5, 1.5, 1.5}; |
| 74 |
} |
| 75 |
|
| 76 |
public double[] getCategoryProportions(){ |
| 77 |
return new double[]{0, 0.25, 0.25, 0.25, 0.25}; |
| 78 |
} |
| 79 |
|
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
Instance test1 = new Instance(){ |
| 84 |
public SubstitutionModel getSubstModel (){ |
| 85 |
|
| 86 |
|
| 87 |
Parameter kappa = new Parameter.Default(1, 1); |
| 88 |
double[] pi = new double[]{0.25, 0.25, 0.25, 0.25}; |
| 89 |
|
| 90 |
Parameter freqs = new Parameter.Default(pi); |
| 91 |
FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs); |
| 92 |
HKY jc = new HKY(kappa, f); |
| 93 |
return jc; |
| 94 |
} |
| 95 |
|
| 96 |
public double getMu(){ |
| 97 |
return 1.5; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
public double getLogitInvar(){ |
| 102 |
|
| 103 |
return -1.38629436112; |
| 104 |
} |
| 105 |
|
| 106 |
public double getLogShape(){ |
| 107 |
|
| 108 |
return 0.69314718056; |
| 109 |
} |
| 110 |
|
| 111 |
public int getCategoryCount(){ |
| 112 |
return 4; |
| 113 |
} |
| 114 |
|
| 115 |
public Variable<Integer> getModelChoose(){ |
| 116 |
return new Variable.I(new int[]{0, 1}); |
| 117 |
} |
| 118 |
|
| 119 |
public double[] getCategoryRates(){ |
| 120 |
return new double[]{0.0, 1.875, 1.875, 1.875, 1.875}; |
| 121 |
} |
| 122 |
|
| 123 |
public double[] getCategoryProportions(){ |
| 124 |
return new double[]{0.2, 0.2, 0.2, 0.2, 0.2}; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
Instance test2 = new Instance(){ |
| 132 |
public SubstitutionModel getSubstModel (){ |
| 133 |
|
| 134 |
|
| 135 |
Parameter kappa = new Parameter.Default(1, 1); |
| 136 |
double[] pi = new double[]{0.25, 0.25, 0.25, 0.25}; |
| 137 |
|
| 138 |
Parameter freqs = new Parameter.Default(pi); |
| 139 |
FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs); |
| 140 |
HKY jc = new HKY(kappa, f); |
| 141 |
return jc; |
| 142 |
} |
| 143 |
|
| 144 |
public double getMu(){ |
| 145 |
return 1.5; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
public double getLogitInvar(){ |
| 150 |
|
| 151 |
return -1.38629436112; |
| 152 |
} |
| 153 |
|
| 154 |
public double getLogShape(){ |
| 155 |
|
| 156 |
return 0.69314718056; |
| 157 |
} |
| 158 |
|
| 159 |
public int getCategoryCount(){ |
| 160 |
return 4; |
| 161 |
} |
| 162 |
|
| 163 |
public Variable<Integer> getModelChoose(){ |
| 164 |
return new Variable.I(new int[]{1, 1}); |
| 165 |
} |
| 166 |
|
| 167 |
public double[] getCategoryRates(){ |
| 168 |
return new double[]{0.0, 0.59824693778, 1.28130225333, 2.07933195980, 3.54111884909}; |
| 169 |
} |
| 170 |
|
| 171 |
public double[] getCategoryProportions(){ |
| 172 |
return new double[]{0.2, 0.2, 0.2, 0.2, 0.2}; |
| 173 |
} |
| 174 |
}; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
Instance test3 = new Instance(){ |
| 179 |
public SubstitutionModel getSubstModel (){ |
| 180 |
|
| 181 |
|
| 182 |
Parameter kappa = new Parameter.Default(1, 1); |
| 183 |
double[] pi = new double[]{0.25, 0.25, 0.25, 0.25}; |
| 184 |
|
| 185 |
Parameter freqs = new Parameter.Default(pi); |
| 186 |
FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs); |
| 187 |
HKY jc = new HKY(kappa, f); |
| 188 |
return jc; |
| 189 |
} |
| 190 |
|
| 191 |
public double getMu(){ |
| 192 |
return 1.5; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
public double getLogitInvar(){ |
| 197 |
|
| 198 |
return -1.38629436112; |
| 199 |
} |
| 200 |
|
| 201 |
public double getLogShape(){ |
| 202 |
|
| 203 |
return 0.69314718056; |
| 204 |
} |
| 205 |
|
| 206 |
public int getCategoryCount(){ |
| 207 |
return 8; |
| 208 |
} |
| 209 |
|
| 210 |
public Variable<Integer> getModelChoose(){ |
| 211 |
return new Variable.I(new int[]{1, 1}); |
| 212 |
} |
| 213 |
|
| 214 |
public double[] getCategoryRates(){ |
| 215 |
return new double[]{0.0, |
| 216 |
0.387224876120, 0.757770190732, 1.085824675833, 1.426031312891, |
| 217 |
1.810616868095, 2.285251426765, 2.955667305794, 4.291613343768}; |
| 218 |
} |
| 219 |
|
| 220 |
public double[] getCategoryProportions(){ |
| 221 |
return new double[]{0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; |
| 222 |
} |
| 223 |
}; |
| 224 |
Instance[] all = {test0,test1,test2,test3}; |
| 225 |
public void testGammaSiteBMA(){ |
| 226 |
|
| 227 |
for(Instance test: all){ |
| 228 |
SubstitutionModel substModel = test.getSubstModel(); |
| 229 |
Parameter mu = new Parameter.Default(test.getMu()); |
| 230 |
Parameter logitInvar = new Parameter.Default(test.getLogitInvar()); |
| 231 |
Parameter logShape = new Parameter.Default(test.getLogShape()); |
| 232 |
int catCount = test.getCategoryCount(); |
| 233 |
Variable<Integer> modelChoose = test.getModelChoose(); |
| 234 |
GammaSiteBMA gammaSiteBMA = new GammaSiteBMA( |
| 235 |
substModel, |
| 236 |
mu, |
| 237 |
logitInvar, |
| 238 |
logShape, |
| 239 |
catCount, |
| 240 |
modelChoose |
| 241 |
); |
| 242 |
|
| 243 |
double[] catRates = gammaSiteBMA.getCategoryRates(); |
| 244 |
double[] expectedCatRates = test.getCategoryRates(); |
| 245 |
|
| 246 |
for(int i = 0; i < catRates.length; i++){ |
| 247 |
assertEquals(catRates[i], expectedCatRates[i], 8e-10); |
| 248 |
} |
| 249 |
|
| 250 |
double[] catProps = gammaSiteBMA.getCategoryProportions(); |
| 251 |
double[] expectedCatProps = test.getCategoryProportions(); |
| 252 |
for(int i = 0; i < catProps.length; i++){ |
| 253 |
assertEquals(catProps[i], expectedCatProps[i], 1e-10); |
| 254 |
} |
| 255 |
|
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
} |