| 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 |
|
| 29 |
import dr.evolution.datatype.Microsatellite; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.inference.model.Variable; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class AsymmetricQuadraticModel extends OnePhaseModel{ |
| 39 |
|
| 40 |
public static final String ASYMQUAD_MODEL = "ASYMQUADModel"; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
private Variable<Double> expanConst; |
| 46 |
private Variable<Double> expanLin; |
| 47 |
private Variable<Double> expanQuad; |
| 48 |
private Variable<Double> contractConst; |
| 49 |
private Variable<Double> contractLin; |
| 50 |
private Variable<Double> contractQuad; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public AsymmetricQuadraticModel(Microsatellite microsatellite, FrequencyModel freqModel){ |
| 60 |
this( |
| 61 |
microsatellite, |
| 62 |
freqModel, |
| 63 |
null, null, null, null, null, null, |
| 64 |
false); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public AsymmetricQuadraticModel(Microsatellite microsatellite, FrequencyModel freqModel, boolean isNested){ |
| 70 |
this( |
| 71 |
microsatellite, |
| 72 |
freqModel, |
| 73 |
null, null, null, null, null, null, |
| 74 |
isNested |
| 75 |
); |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public AsymmetricQuadraticModel( |
| 94 |
Microsatellite microsatellite, |
| 95 |
FrequencyModel freqModel, |
| 96 |
Variable<Double> expanConst, |
| 97 |
Variable<Double> expanLin, |
| 98 |
Variable<Double> expanQuad, |
| 99 |
Variable<Double> contractConst, |
| 100 |
Variable<Double> contractLin, |
| 101 |
Variable<Double> contractQuad, |
| 102 |
boolean isNested){ |
| 103 |
|
| 104 |
super(ASYMQUAD_MODEL, microsatellite, freqModel,null); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
this.expanConst = overrideDefault(new Parameter.Default(1.0), expanConst); |
| 110 |
this.expanLin = overrideDefault(new Parameter.Default(0.0), expanLin); |
| 111 |
this.expanQuad = overrideDefault(new Parameter.Default(0.0), expanQuad); |
| 112 |
this.contractConst = overrideDefault(this.expanConst, contractConst); |
| 113 |
this.contractLin = overrideDefault(this.expanLin, contractLin); |
| 114 |
this.contractQuad = overrideDefault(this.expanQuad, contractQuad); |
| 115 |
this.isNested = isNested; |
| 116 |
addParameters(); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
setupInfinitesimalRates(); |
| 121 |
|
| 122 |
|
| 123 |
if(freqModel == null){ |
| 124 |
useStationaryFreqs = true; |
| 125 |
computeStationaryDistribution(); |
| 126 |
}else{ |
| 127 |
this.freqModel = freqModel; |
| 128 |
} |
| 129 |
|
| 130 |
addModel(this.freqModel); |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
private void addParameters(){ |
| 135 |
addParam(this.expanConst); |
| 136 |
addParam(this.expanLin); |
| 137 |
addParam(this.expanQuad); |
| 138 |
if(this.contractConst != this.expanConst) |
| 139 |
addParam(this.contractConst); |
| 140 |
if(this.contractLin != this.expanLin) |
| 141 |
addParam(this.contractLin); |
| 142 |
if(this.contractQuad != this.expanQuad) |
| 143 |
addParam(this.contractQuad); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
private Variable<Double> overrideDefault(Variable<Double> defaultParam, Variable<Double> providedParam){ |
| 153 |
if(providedParam != null && providedParam != defaultParam) |
| 154 |
return providedParam; |
| 155 |
return defaultParam; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public void setupInfinitesimalRates(){ |
| 166 |
|
| 167 |
|
| 168 |
double u0 = expanConst.getValue(0); |
| 169 |
double u1 = expanLin.getValue(0); |
| 170 |
double u2 = expanQuad.getValue(0); |
| 171 |
|
| 172 |
double d0 = contractConst.getValue(0); |
| 173 |
double d1 = contractLin.getValue(0); |
| 174 |
double d2 = contractQuad.getValue(0); |
| 175 |
|
| 176 |
double rowSum; |
| 177 |
for(int i = 0; i < stateCount;i++){ |
| 178 |
rowSum = 0.0; |
| 179 |
if(i - 1 > -1){ |
| 180 |
infinitesimalRateMatrix[i][i - 1] =d0+d1*i+d2*i*i; |
| 181 |
rowSum = rowSum + infinitesimalRateMatrix[i][i - 1]; |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
if(i + 1 < stateCount){ |
| 186 |
infinitesimalRateMatrix[i][i + 1] = u0+u1*i+u2*i*i; |
| 187 |
rowSum = rowSum + infinitesimalRateMatrix[i][i + 1]; |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
infinitesimalRateMatrix[i][i] = rowSum*-1; |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
public Variable<Double> getExpansionConstant(){ |
| 200 |
return expanConst; |
| 201 |
} |
| 202 |
|
| 203 |
public Variable<Double> getExpansionLinear(){ |
| 204 |
return expanLin; |
| 205 |
} |
| 206 |
|
| 207 |
public Variable<Double> getExpansionQuad(){ |
| 208 |
return expanQuad; |
| 209 |
} |
| 210 |
|
| 211 |
public Variable<Double> getContractionConstant(){ |
| 212 |
return contractConst; |
| 213 |
} |
| 214 |
|
| 215 |
public Variable<Double> getContractionLinear(){ |
| 216 |
return contractLin; |
| 217 |
} |
| 218 |
|
| 219 |
public Variable<Double> getContractionQuad(){ |
| 220 |
return contractQuad; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
public void printDetails(){ |
| 226 |
System.out.println("\n"); |
| 227 |
System.out.println("Details of the asymmetric quadratic model and its parameters:"); |
| 228 |
System.out.println("expansion constant: "+expanConst.getValue(0)); |
| 229 |
System.out.println("expansion linear: "+ expanLin.getValue(0)); |
| 230 |
System.out.println("expansion quadratic: "+expanQuad.getValue(0)); |
| 231 |
System.out.println("contraction constant: "+contractConst.getValue(0)); |
| 232 |
System.out.println("contraction linear: "+contractLin.getValue(0)); |
| 233 |
System.out.println("contraction quadratc: "+contractQuad.getValue(0)); |
| 234 |
System.out.println("a submodel: "+isNested); |
| 235 |
System.out.println("\n"); |
| 236 |
} |
| 237 |
|
| 238 |
} |