| 1 |
package dr.evomodel.antigenic.phyloclustering.misc.obsolete; |
| 2 |
|
| 3 |
import dr.inference.model.*; |
| 4 |
import dr.math.MathUtils; |
| 5 |
import dr.math.LogTricks; |
| 6 |
import dr.math.distributions.NormalDistribution; |
| 7 |
import dr.util.*; |
| 8 |
import dr.xml.*; |
| 9 |
|
| 10 |
import java.io.*; |
| 11 |
import java.util.*; |
| 12 |
import java.util.logging.Logger; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class AGLikelihoodCluster extends AbstractModelLikelihood implements Citable { |
| 28 |
private static final boolean CHECK_INFINITE = false; |
| 29 |
private static final boolean USE_THRESHOLDS = true; |
| 30 |
private static final boolean USE_INTERVALS = true; |
| 31 |
|
| 32 |
public final static String AG_LIKELIHOOD = "aglikelihoodcluster"; |
| 33 |
|
| 34 |
|
| 35 |
private static final int VIRUS_ISOLATE = 0; |
| 36 |
private static final int VIRUS_STRAIN = 1; |
| 37 |
private static final int VIRUS_DATE = 2; |
| 38 |
private static final int SERUM_ISOLATE = 3; |
| 39 |
private static final int SERUM_STRAIN = 4; |
| 40 |
private static final int SERUM_DATE = 5; |
| 41 |
private static final int TITRE = 6; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public enum MeasurementType { |
| 46 |
INTERVAL, |
| 47 |
POINT, |
| 48 |
THRESHOLD, |
| 49 |
MISSING |
| 50 |
} |
| 51 |
|
| 52 |
public AGLikelihoodCluster( |
| 53 |
int mdsDimension, |
| 54 |
Parameter mdsPrecisionParameter, |
| 55 |
Parameter locationDriftParameter, |
| 56 |
Parameter virusDriftParameter, |
| 57 |
Parameter serumDriftParameter, |
| 58 |
MatrixParameter virusLocationsParameter, |
| 59 |
MatrixParameter serumLocationsParameter, |
| 60 |
CompoundParameter tipTraitsParameter, |
| 61 |
Parameter virusOffsetsParameter, |
| 62 |
Parameter serumOffsetsParameter, |
| 63 |
Parameter serumPotenciesParameter, |
| 64 |
Parameter serumBreadthsParameter, |
| 65 |
Parameter virusAviditiesParameter, |
| 66 |
DataTable<String[]> dataTable, |
| 67 |
boolean mergeSerumIsolates, |
| 68 |
double intervalWidth, |
| 69 |
double driftInitialLocations, |
| 70 |
boolean clusterMeans, |
| 71 |
Parameter clusterOffsetsParameter) { |
| 72 |
|
| 73 |
super(AG_LIKELIHOOD); |
| 74 |
|
| 75 |
this.intervalWidth = intervalWidth; |
| 76 |
boolean useIntervals = USE_INTERVALS && intervalWidth > 0.0; |
| 77 |
|
| 78 |
int thresholdCount = 0; |
| 79 |
|
| 80 |
double earliestDate = Double.POSITIVE_INFINITY; |
| 81 |
for (int i = 0; i < dataTable.getRowCount(); i++) { |
| 82 |
|
| 83 |
String[] values = dataTable.getRow(i); |
| 84 |
|
| 85 |
String virusName = values[VIRUS_STRAIN]; |
| 86 |
double virusDate = Double.parseDouble(values[VIRUS_DATE]); |
| 87 |
int virus = virusNames.indexOf(virusName); |
| 88 |
if (virus == -1) { |
| 89 |
virusNames.add(virusName); |
| 90 |
virusDates.add(virusDate); |
| 91 |
virus = virusNames.size() - 1; |
| 92 |
} |
| 93 |
|
| 94 |
String serumName = ""; |
| 95 |
if (mergeSerumIsolates) { |
| 96 |
serumName = values[SERUM_STRAIN]; |
| 97 |
} else { |
| 98 |
serumName = values[SERUM_ISOLATE]; |
| 99 |
} |
| 100 |
double serumDate = Double.parseDouble(values[SERUM_DATE]); |
| 101 |
int serum = serumNames.indexOf(serumName); |
| 102 |
if (serum == -1) { |
| 103 |
serumNames.add(serumName); |
| 104 |
serumDates.add(serumDate); |
| 105 |
serum = serumNames.size() - 1; |
| 106 |
} |
| 107 |
|
| 108 |
boolean isThreshold = false; |
| 109 |
boolean isLowerThreshold = false; |
| 110 |
double rawTitre = Double.NaN; |
| 111 |
if (values[TITRE].length() > 0) { |
| 112 |
try { |
| 113 |
rawTitre = Double.parseDouble(values[TITRE]); |
| 114 |
} catch (NumberFormatException nfe) { |
| 115 |
|
| 116 |
if (values[TITRE].contains("<")) { |
| 117 |
rawTitre = Double.parseDouble(values[TITRE].replace("<","")); |
| 118 |
isThreshold = true; |
| 119 |
isLowerThreshold = true; |
| 120 |
thresholdCount++; |
| 121 |
} |
| 122 |
|
| 123 |
if (values[TITRE].contains(">")) { |
| 124 |
rawTitre = Double.parseDouble(values[TITRE].replace(">","")); |
| 125 |
isThreshold = true; |
| 126 |
isLowerThreshold = false; |
| 127 |
thresholdCount++; |
| 128 |
|
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if (serumDate < earliestDate) { |
| 134 |
earliestDate = serumDate; |
| 135 |
} |
| 136 |
|
| 137 |
if (virusDate < earliestDate) { |
| 138 |
earliestDate = virusDate; |
| 139 |
} |
| 140 |
|
| 141 |
MeasurementType type = (isThreshold ? MeasurementType.THRESHOLD : (useIntervals ? MeasurementType.INTERVAL : MeasurementType.POINT)); |
| 142 |
Measurement measurement = new Measurement(virus, serum, virusDate, serumDate, type, rawTitre, isLowerThreshold); |
| 143 |
|
| 144 |
if (USE_THRESHOLDS || !isThreshold) { |
| 145 |
measurements.add(measurement); |
| 146 |
} |
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
double[] maxColumnTitres = new double[serumNames.size()]; |
| 151 |
for (Measurement measurement : measurements) { |
| 152 |
double titre = measurement.log2Titre; |
| 153 |
if (Double.isNaN(titre)) { |
| 154 |
titre = measurement.log2Titre; |
| 155 |
} |
| 156 |
if (titre > maxColumnTitres[measurement.serum]) { |
| 157 |
maxColumnTitres[measurement.serum] = titre; |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
this.mdsDimension = mdsDimension; |
| 162 |
|
| 163 |
this.mdsPrecisionParameter = mdsPrecisionParameter; |
| 164 |
addVariable(mdsPrecisionParameter); |
| 165 |
|
| 166 |
this.locationDriftParameter = locationDriftParameter; |
| 167 |
if (this.locationDriftParameter != null) { |
| 168 |
addVariable(locationDriftParameter); |
| 169 |
} |
| 170 |
|
| 171 |
this.virusDriftParameter = virusDriftParameter; |
| 172 |
if (this.virusDriftParameter != null) { |
| 173 |
addVariable(virusDriftParameter); |
| 174 |
} |
| 175 |
|
| 176 |
this.serumDriftParameter = serumDriftParameter; |
| 177 |
if (this.serumDriftParameter != null) { |
| 178 |
addVariable(serumDriftParameter); |
| 179 |
} |
| 180 |
|
| 181 |
this.virusLocationsParameter = virusLocationsParameter; |
| 182 |
if (this.virusLocationsParameter != null) { |
| 183 |
setupLocationsParameter(virusLocationsParameter, virusNames); |
| 184 |
} |
| 185 |
|
| 186 |
this.serumLocationsParameter = serumLocationsParameter; |
| 187 |
if (this.serumLocationsParameter != null) { |
| 188 |
setupLocationsParameter(serumLocationsParameter, serumNames); |
| 189 |
} |
| 190 |
|
| 191 |
this.tipTraitsParameter = tipTraitsParameter; |
| 192 |
if (tipTraitsParameter != null) { |
| 193 |
setupTipTraitsParameter(this.tipTraitsParameter, virusNames); |
| 194 |
} |
| 195 |
|
| 196 |
this.virusOffsetsParameter = virusOffsetsParameter; |
| 197 |
if (virusOffsetsParameter != null) { |
| 198 |
setupOffsetsParameter(virusOffsetsParameter, virusNames, virusDates, earliestDate); |
| 199 |
} |
| 200 |
|
| 201 |
this.serumOffsetsParameter = serumOffsetsParameter; |
| 202 |
if (serumOffsetsParameter != null) { |
| 203 |
setupOffsetsParameter(serumOffsetsParameter, serumNames, serumDates, earliestDate); |
| 204 |
} |
| 205 |
|
| 206 |
this.serumPotenciesParameter = setupSerumPotencies(serumPotenciesParameter, maxColumnTitres); |
| 207 |
this.serumBreadthsParameter = setupSerumBreadths(serumBreadthsParameter); |
| 208 |
this.virusAviditiesParameter = setupVirusAvidities(virusAviditiesParameter); |
| 209 |
|
| 210 |
StringBuilder sb = new StringBuilder(); |
| 211 |
sb.append("\tAntigenicLikelihood:\n"); |
| 212 |
sb.append("\t\t" + virusNames.size() + " viruses\n"); |
| 213 |
sb.append("\t\t" + serumNames.size() + " sera\n"); |
| 214 |
sb.append("\t\t" + measurements.size() + " assay measurements\n"); |
| 215 |
if (USE_THRESHOLDS) { |
| 216 |
sb.append("\t\t" + thresholdCount + " thresholded measurements\n"); |
| 217 |
} |
| 218 |
if (useIntervals) { |
| 219 |
sb.append("\n\t\tAssuming a log 2 measurement interval width of " + intervalWidth + "\n"); |
| 220 |
} |
| 221 |
Logger.getLogger("dr.evomodel").info(sb.toString()); |
| 222 |
|
| 223 |
virusLocationChanged = new boolean[this.virusLocationsParameter.getParameterCount()]; |
| 224 |
serumLocationChanged = new boolean[this.serumLocationsParameter.getParameterCount()]; |
| 225 |
virusEffectChanged = new boolean[virusNames.size()]; |
| 226 |
serumEffectChanged = new boolean[serumNames.size()]; |
| 227 |
logLikelihoods = new double[measurements.size()]; |
| 228 |
storedLogLikelihoods = new double[measurements.size()]; |
| 229 |
|
| 230 |
|
| 231 |
setupInitialLocations(driftInitialLocations); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
if(clusterMeans){ |
| 243 |
this.clusterMeans = clusterMeans; |
| 244 |
this.clusterOffsetsParameter = clusterOffsetsParameter; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
if (clusterOffsetsParameter == null) { |
| 258 |
|
| 259 |
} else { |
| 260 |
|
| 261 |
addVariable(clusterOffsetsParameter); |
| 262 |
clusterOffsetsParameter.setDimension(virusNames.size()); |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
System.out.println(" clusterMeans = true"); |
| 268 |
|
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
makeDirty(); |
| 273 |
} |
| 274 |
|
| 275 |
private Parameter setupVirusAvidities(Parameter virusAviditiesParameter) { |
| 276 |
|
| 277 |
if (virusAviditiesParameter != null) { |
| 278 |
virusAviditiesParameter.addBounds(new Parameter.DefaultBounds(Double.MAX_VALUE, Double.MIN_VALUE, 1)); |
| 279 |
virusAviditiesParameter.setDimension(virusNames.size()); |
| 280 |
addVariable(virusAviditiesParameter); |
| 281 |
String[] labelArray = new String[virusNames.size()]; |
| 282 |
virusNames.toArray(labelArray); |
| 283 |
virusAviditiesParameter.setDimensionNames(labelArray); |
| 284 |
for (int i = 0; i < virusNames.size(); i++) { |
| 285 |
virusAviditiesParameter.setParameterValueQuietly(i, 0.0); |
| 286 |
} |
| 287 |
} |
| 288 |
return virusAviditiesParameter; |
| 289 |
} |
| 290 |
|
| 291 |
private Parameter setupSerumPotencies(Parameter serumPotenciesParameter, double[] maxColumnTitres) { |
| 292 |
|
| 293 |
if (serumPotenciesParameter == null) { |
| 294 |
serumPotenciesParameter = new Parameter.Default("serumPotencies"); |
| 295 |
} else { |
| 296 |
serumPotenciesParameter.addBounds(new Parameter.DefaultBounds(Double.MAX_VALUE, 0.0, 1)); |
| 297 |
addVariable(serumPotenciesParameter); |
| 298 |
} |
| 299 |
|
| 300 |
serumPotenciesParameter.setDimension(serumNames.size()); |
| 301 |
String[] labelArray = new String[serumNames.size()]; |
| 302 |
serumNames.toArray(labelArray); |
| 303 |
serumPotenciesParameter.setDimensionNames(labelArray); |
| 304 |
for (int i = 0; i < maxColumnTitres.length; i++) { |
| 305 |
serumPotenciesParameter.setParameterValueQuietly(i, maxColumnTitres[i]); |
| 306 |
} |
| 307 |
|
| 308 |
return serumPotenciesParameter; |
| 309 |
} |
| 310 |
|
| 311 |
private Parameter setupSerumBreadths(Parameter serumBreadthsParameter) { |
| 312 |
|
| 313 |
if (serumBreadthsParameter != null) { |
| 314 |
serumBreadthsParameter.addBounds(new Parameter.DefaultBounds(Double.MAX_VALUE, 0.0, 1)); |
| 315 |
serumBreadthsParameter.setDimension(serumNames.size()); |
| 316 |
addVariable(serumBreadthsParameter); |
| 317 |
String[] labelArray = new String[serumNames.size()]; |
| 318 |
serumNames.toArray(labelArray); |
| 319 |
serumBreadthsParameter.setDimensionNames(labelArray); |
| 320 |
for (int i = 0; i < serumNames.size(); i++) { |
| 321 |
serumBreadthsParameter.setParameterValueQuietly(i, 1.0); |
| 322 |
} |
| 323 |
} |
| 324 |
return serumBreadthsParameter; |
| 325 |
} |
| 326 |
|
| 327 |
protected void setupLocationsParameter(MatrixParameter locationsParameter, List<String> strains) { |
| 328 |
locationsParameter.setColumnDimension(mdsDimension); |
| 329 |
locationsParameter.setRowDimension(strains.size()); |
| 330 |
for (int i = 0; i < strains.size(); i++) { |
| 331 |
locationsParameter.getParameter(i).setId(strains.get(i)); |
| 332 |
} |
| 333 |
addVariable(locationsParameter); |
| 334 |
} |
| 335 |
|
| 336 |
private void setupOffsetsParameter(Parameter offsetsParameter, List<String> strainNames, List<Double> strainDates, double earliest) { |
| 337 |
|
| 338 |
offsetsParameter.setDimension(strainNames.size()); |
| 339 |
String[] labelArray = new String[strainNames.size()]; |
| 340 |
strainNames.toArray(labelArray); |
| 341 |
offsetsParameter.setDimensionNames(labelArray); |
| 342 |
for (int i = 0; i < strainNames.size(); i++) { |
| 343 |
Double offset = strainDates.get(i) - new Double(earliest); |
| 344 |
if (offset == null) { |
| 345 |
throw new IllegalArgumentException("Date missing for strain: " + strainNames.get(i)); |
| 346 |
} |
| 347 |
offsetsParameter.setParameterValue(i, offset); |
| 348 |
} |
| 349 |
addVariable(offsetsParameter); |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
private void setupTipTraitsParameter(CompoundParameter tipTraitsParameter, List<String> strainNames) { |
| 354 |
tipIndices = new int[strainNames.size()]; |
| 355 |
|
| 356 |
for (int i = 0; i < strainNames.size(); i++) { |
| 357 |
tipIndices[i] = -1; |
| 358 |
} |
| 359 |
|
| 360 |
for (int i = 0; i < tipTraitsParameter.getParameterCount(); i++) { |
| 361 |
Parameter tip = tipTraitsParameter.getParameter(i); |
| 362 |
String label = tip.getParameterName(); |
| 363 |
int index = findStrain(label, strainNames); |
| 364 |
if (index != -1) { |
| 365 |
if (tipIndices[index] != -1) { |
| 366 |
throw new IllegalArgumentException("Duplicated tip name: " + label); |
| 367 |
} |
| 368 |
|
| 369 |
tipIndices[index] = i; |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
} else { |
| 378 |
|
| 379 |
|
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
} |
| 385 |
|
| 386 |
private final int findStrain(String label, List<String> strainNames) { |
| 387 |
int index = 0; |
| 388 |
for (String strainName : strainNames) { |
| 389 |
if (label.startsWith(strainName)) { |
| 390 |
return index; |
| 391 |
} |
| 392 |
|
| 393 |
index ++; |
| 394 |
} |
| 395 |
return -1; |
| 396 |
} |
| 397 |
|
| 398 |
private void setupInitialLocations(double drift) { |
| 399 |
|
| 400 |
for (int i = 0; i < virusLocationsParameter.getParameterCount(); i++) { |
| 401 |
double offset = 0.0; |
| 402 |
if (virusOffsetsParameter != null) { |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
offset = drift * virusOffsetsParameter.getParameterValue(i); |
| 407 |
} |
| 408 |
else{ |
| 409 |
System.out.println("virus Offeset Parameter NOT present"); |
| 410 |
} |
| 411 |
double r = MathUtils.nextGaussian() + offset; |
| 412 |
virusLocationsParameter.getParameter(i).setParameterValue(0, r); |
| 413 |
|
| 414 |
if (mdsDimension > 1) { |
| 415 |
for (int j = 1; j < mdsDimension; j++) { |
| 416 |
r = MathUtils.nextGaussian(); |
| 417 |
virusLocationsParameter.getParameter(i).setParameterValue(j, r); |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
for (int i = 0; i < serumLocationsParameter.getParameterCount(); i++) { |
| 422 |
double offset = 0.0; |
| 423 |
if (serumOffsetsParameter != null) { |
| 424 |
offset = drift * serumOffsetsParameter.getParameterValue(i); |
| 425 |
} |
| 426 |
double r = MathUtils.nextGaussian() + offset; |
| 427 |
serumLocationsParameter.getParameter(i).setParameterValue(0, r); |
| 428 |
if (mdsDimension > 1) { |
| 429 |
for (int j = 1; j < mdsDimension; j++) { |
| 430 |
r = MathUtils.nextGaussian(); |
| 431 |
serumLocationsParameter.getParameter(i).setParameterValue(j, r); |
| 432 |
} |
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
private void loadInitialLocations(List<String> strainNames, List<String> serumNames) { |
| 439 |
|
| 440 |
FileReader fileReader; |
| 441 |
try { |
| 442 |
|
| 443 |
fileReader = new FileReader("/Users/charles/Documents/research/antigenic/GenoPheno/Gabriela/results/initialConditionWithInitialLocationDrift/lastIteration/H3N2_mds.virusLocs.log"); |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
BufferedReader bReader = new BufferedReader( fileReader); |
| 448 |
|
| 449 |
String line; |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
line = bReader.readLine(); |
| 455 |
System.out.println(line); |
| 456 |
String namevalue[] = line.split("\t"); |
| 457 |
|
| 458 |
|
| 459 |
line = bReader.readLine(); |
| 460 |
System.out.println(line); |
| 461 |
|
| 462 |
String datavalue[] = line.split("\t"); |
| 463 |
|
| 464 |
for (int i = 0; i < virusLocationsParameter.getParameterCount(); i++) { |
| 465 |
|
| 466 |
int index = findStrain( namevalue[i*2+1], strainNames); |
| 467 |
|
| 468 |
|
| 469 |
virusLocationsParameter.getParameter(index).setParameterValue(0, Double.parseDouble(datavalue[i*2+1])); |
| 470 |
virusLocationsParameter.getParameter(index).setParameterValue(1, Double.parseDouble(datavalue[i*2+2])); |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
} |
| 476 |
bReader.close(); |
| 477 |
|
| 478 |
} catch (FileNotFoundException e) { |
| 479 |
|
| 480 |
e.printStackTrace(); |
| 481 |
} catch (IOException e) { |
| 482 |
|
| 483 |
e.printStackTrace(); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
FileReader fileReader2; |
| 488 |
try { |
| 489 |
|
| 490 |
fileReader2 = new FileReader("/Users/charles/Documents/research/antigenic/GenoPheno/Gabriela/results/initialConditionWithInitialLocationDrift/lastIteration/H3N2.serumLocs.log"); |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
BufferedReader bReader2 = new BufferedReader( fileReader2); |
| 496 |
|
| 497 |
String line; |
| 498 |
|
| 499 |
line = bReader2.readLine(); |
| 500 |
System.out.println(line); |
| 501 |
String namevalue[] = line.split("\t"); |
| 502 |
|
| 503 |
|
| 504 |
line = bReader2.readLine(); |
| 505 |
System.out.println(line); |
| 506 |
|
| 507 |
String datavalue[] = line.split("\t"); |
| 508 |
|
| 509 |
for (int i = 0; i < serumLocationsParameter.getParameterCount(); i++) { |
| 510 |
int index = findStrain( namevalue[i*2+1], serumNames); |
| 511 |
|
| 512 |
|
| 513 |
serumLocationsParameter.getParameter(index).setParameterValue(0, Double.parseDouble(datavalue[i*2+1])); |
| 514 |
serumLocationsParameter.getParameter(index).setParameterValue(1, Double.parseDouble(datavalue[i*2+2])); |
| 515 |
|
| 516 |
|
| 517 |
} |
| 518 |
bReader2.close(); |
| 519 |
|
| 520 |
} catch (FileNotFoundException e) { |
| 521 |
|
| 522 |
e.printStackTrace(); |
| 523 |
} catch (IOException e) { |
| 524 |
|
| 525 |
e.printStackTrace(); |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
@Override |
| 534 |
protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 535 |
} |
| 536 |
|
| 537 |
@Override |
| 538 |
protected void handleVariableChangedEvent(Variable variable, int index, Variable.ChangeType type) { |
| 539 |
if (variable == virusLocationsParameter) { |
| 540 |
int loc = index / mdsDimension; |
| 541 |
virusLocationChanged[loc] = true; |
| 542 |
if (tipTraitsParameter != null && tipIndices[loc] != -1) { |
| 543 |
Parameter location = virusLocationsParameter.getParameter(loc); |
| 544 |
Parameter tip = tipTraitsParameter.getParameter(tipIndices[loc]); |
| 545 |
int dim = index % mdsDimension; |
| 546 |
tip.setParameterValue(dim, location.getParameterValue(dim)); |
| 547 |
} |
| 548 |
} else if (variable == serumLocationsParameter) { |
| 549 |
int loc = index / mdsDimension; |
| 550 |
serumLocationChanged[loc] = true; |
| 551 |
} else if (variable == mdsPrecisionParameter) { |
| 552 |
setLocationChangedFlags(true); |
| 553 |
} else if (variable == locationDriftParameter) { |
| 554 |
setLocationChangedFlags(true); |
| 555 |
} else if (variable == virusDriftParameter) { |
| 556 |
setLocationChangedFlags(true); |
| 557 |
} else if (variable == serumDriftParameter) { |
| 558 |
setLocationChangedFlags(true); |
| 559 |
} else if (variable == serumPotenciesParameter) { |
| 560 |
serumEffectChanged[index] = true; |
| 561 |
} else if (variable == serumBreadthsParameter) { |
| 562 |
serumEffectChanged[index] = true; |
| 563 |
} else if (variable == virusAviditiesParameter) { |
| 564 |
virusEffectChanged[index] = true; |
| 565 |
} else { |
| 566 |
|
| 567 |
|
| 568 |
} |
| 569 |
likelihoodKnown = false; |
| 570 |
} |
| 571 |
|
| 572 |
@Override |
| 573 |
protected void storeState() { |
| 574 |
System.arraycopy(logLikelihoods, 0, storedLogLikelihoods, 0, logLikelihoods.length); |
| 575 |
} |
| 576 |
|
| 577 |
@Override |
| 578 |
protected void restoreState() { |
| 579 |
double[] tmp = logLikelihoods; |
| 580 |
logLikelihoods = storedLogLikelihoods; |
| 581 |
storedLogLikelihoods = tmp; |
| 582 |
|
| 583 |
likelihoodKnown = false; |
| 584 |
} |
| 585 |
|
| 586 |
@Override |
| 587 |
protected void acceptState() { |
| 588 |
} |
| 589 |
|
| 590 |
public Model getModel() { |
| 591 |
return this; |
| 592 |
} |
| 593 |
|
| 594 |
public double getLogLikelihood() { |
| 595 |
|
| 596 |
|
| 597 |
if (!likelihoodKnown) { |
| 598 |
logLikelihood = computeLogLikelihood(); |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
return logLikelihood; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
private double computeLogLikelihood() { |
| 608 |
|
| 609 |
|
| 610 |
double precision = mdsPrecisionParameter.getParameterValue(0); |
| 611 |
double sd = 1.0 / Math.sqrt(precision); |
| 612 |
|
| 613 |
logLikelihood = 0.0; |
| 614 |
int i = 0; |
| 615 |
|
| 616 |
for (Measurement measurement : measurements) { |
| 617 |
|
| 618 |
if (virusLocationChanged[measurement.virus] || serumLocationChanged[measurement.serum] || virusEffectChanged[measurement.virus] || serumEffectChanged[measurement.serum]) { |
| 619 |
|
| 620 |
double expectation = calculateBaseline(measurement.virus, measurement.serum) - computeDistance(measurement.virus, measurement.serum); |
| 621 |
|
| 622 |
switch (measurement.type) { |
| 623 |
case INTERVAL: { |
| 624 |
double minTitre = measurement.log2Titre; |
| 625 |
double maxTitre = measurement.log2Titre + intervalWidth; |
| 626 |
logLikelihoods[i] = computeMeasurementIntervalLikelihood(minTitre, maxTitre, expectation, sd); |
| 627 |
} break; |
| 628 |
case POINT: { |
| 629 |
logLikelihoods[i] = computeMeasurementLikelihood(measurement.log2Titre, expectation, sd); |
| 630 |
} break; |
| 631 |
case THRESHOLD: { |
| 632 |
if(measurement.isLowerThreshold){ |
| 633 |
logLikelihoods[i] = computeMeasurementThresholdLikelihood(measurement.log2Titre, expectation, sd); |
| 634 |
} |
| 635 |
else{ |
| 636 |
logLikelihoods[i] = computeMeasurementUpperThresholdLikelihood(measurement.log2Titre, expectation, sd); |
| 637 |
} |
| 638 |
} break; |
| 639 |
case MISSING: |
| 640 |
break; |
| 641 |
} |
| 642 |
} |
| 643 |
logLikelihood += logLikelihoods[i]; |
| 644 |
i++; |
| 645 |
} |
| 646 |
|
| 647 |
likelihoodKnown = true; |
| 648 |
|
| 649 |
setLocationChangedFlags(false); |
| 650 |
setSerumEffectChangedFlags(false); |
| 651 |
setVirusEffectChangedFlags(false); |
| 652 |
|
| 653 |
return logLikelihood; |
| 654 |
} |
| 655 |
|
| 656 |
private void setLocationChangedFlags(boolean flag) { |
| 657 |
for (int i = 0; i < virusLocationChanged.length; i++) { |
| 658 |
virusLocationChanged[i] = flag; |
| 659 |
} |
| 660 |
for (int i = 0; i < serumLocationChanged.length; i++) { |
| 661 |
serumLocationChanged[i] = flag; |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
private void setSerumEffectChangedFlags(boolean flag) { |
| 666 |
for (int i = 0; i < serumEffectChanged.length; i++) { |
| 667 |
serumEffectChanged[i] = flag; |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
private void setVirusEffectChangedFlags(boolean flag) { |
| 672 |
for (int i = 0; i < virusEffectChanged.length; i++) { |
| 673 |
virusEffectChanged[i] = flag; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
protected double computeDistance(int virus, int serum) { |
| 679 |
Parameter vLoc = virusLocationsParameter.getParameter(virus); |
| 680 |
Parameter sLoc = serumLocationsParameter.getParameter(serum); |
| 681 |
double sum = 0.0; |
| 682 |
|
| 683 |
|
| 684 |
double vxOffset = 0.0; |
| 685 |
double sxOffset = 0.0; |
| 686 |
if(clusterMeans == true){ |
| 687 |
|
| 688 |
|
| 689 |
if(virusDriftParameter!= null && virusOffsetsParameter != null && serumOffsetsParameter != null && clusterOffsetsParameter!=null){ |
| 690 |
vxOffset = virusDriftParameter.getParameterValue(0)* clusterOffsetsParameter.getParameterValue(virus); |
| 691 |
sxOffset = virusDriftParameter.getParameterValue(0) * serumOffsetsParameter.getParameterValue(serum); |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
if (serumDriftParameter != null && serumOffsetsParameter != null) { |
| 700 |
|
| 701 |
sxOffset = serumDriftParameter.getParameterValue(0) * serumOffsetsParameter.getParameterValue(serum); |
| 702 |
} |
| 703 |
|
| 704 |
} |
| 705 |
else{ |
| 706 |
if (locationDriftParameter != null && virusOffsetsParameter != null && serumOffsetsParameter != null) { |
| 707 |
vxOffset = locationDriftParameter.getParameterValue(0) * virusOffsetsParameter.getParameterValue(virus); |
| 708 |
sxOffset = locationDriftParameter.getParameterValue(0) * serumOffsetsParameter.getParameterValue(serum); |
| 709 |
} |
| 710 |
if (virusDriftParameter != null && virusOffsetsParameter != null) { |
| 711 |
vxOffset = virusDriftParameter.getParameterValue(0) * virusOffsetsParameter.getParameterValue(virus); |
| 712 |
} |
| 713 |
if (serumDriftParameter != null && serumOffsetsParameter != null) { |
| 714 |
sxOffset = serumDriftParameter.getParameterValue(0) * serumOffsetsParameter.getParameterValue(serum); |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
double vxLoc = vLoc.getParameterValue(0) + vxOffset; |
| 719 |
double sxLoc = sLoc.getParameterValue(0) + sxOffset; |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
double difference = vxLoc - sxLoc; |
| 726 |
sum += difference * difference; |
| 727 |
|
| 728 |
|
| 729 |
for (int i = 1; i < mdsDimension; i++) { |
| 730 |
difference = vLoc.getParameterValue(i) - sLoc.getParameterValue(i); |
| 731 |
sum += difference * difference; |
| 732 |
} |
| 733 |
|
| 734 |
double dist = Math.sqrt(sum); |
| 735 |
|
| 736 |
if (serumBreadthsParameter != null) { |
| 737 |
double serumBreadth = serumBreadthsParameter.getParameterValue(serum); |
| 738 |
dist /= serumBreadth; |
| 739 |
} |
| 740 |
|
| 741 |
return dist; |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
private double calculateBaseline(int virus, int serum) { |
| 747 |
double baseline = serumPotenciesParameter.getParameterValue(serum); |
| 748 |
if (virusAviditiesParameter != null) { |
| 749 |
baseline += virusAviditiesParameter.getParameterValue(virus); |
| 750 |
} |
| 751 |
return baseline; |
| 752 |
} |
| 753 |
|
| 754 |
private static double computeMeasurementLikelihood(double titre, double expectation, double sd) { |
| 755 |
|
| 756 |
double lnL = NormalDistribution.logPdf(titre, expectation, sd); |
| 757 |
|
| 758 |
if (CHECK_INFINITE && Double.isNaN(lnL) || Double.isInfinite(lnL)) { |
| 759 |
throw new RuntimeException("infinite point measurement"); |
| 760 |
} |
| 761 |
return lnL; |
| 762 |
} |
| 763 |
|
| 764 |
private static double computeMeasurementThresholdLikelihood(double titre, double expectation, double sd) { |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
double lnL = NormalDistribution.cdf(titre, expectation, sd, true); |
| 770 |
|
| 771 |
if (CHECK_INFINITE && Double.isNaN(lnL) || Double.isInfinite(lnL)) { |
| 772 |
throw new RuntimeException("infinite threshold measurement"); |
| 773 |
} |
| 774 |
return lnL; |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
private static double computeMeasurementUpperThresholdLikelihood(double titre, double expectation, double sd) { |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
double L = NormalDistribution.cdf(titre, expectation, sd, false); |
| 783 |
double lnL = Math.log(1-L); |
| 784 |
|
| 785 |
if (CHECK_INFINITE && Double.isNaN(lnL) || Double.isInfinite(lnL)) { |
| 786 |
throw new RuntimeException("infinite threshold measurement"); |
| 787 |
} |
| 788 |
return lnL; |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
private static double computeMeasurementIntervalLikelihood(double minTitre, double maxTitre, double expectation, double sd) { |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
double cdf1 = NormalDistribution.cdf(maxTitre, expectation, sd, true); |
| 797 |
double cdf2 = NormalDistribution.cdf(minTitre, expectation, sd, true); |
| 798 |
double lnL = LogTricks.logDiff(cdf1, cdf2); |
| 799 |
|
| 800 |
if (CHECK_INFINITE && Double.isNaN(lnL) || Double.isInfinite(lnL)) { |
| 801 |
|
| 802 |
|
| 803 |
lnL = NormalDistribution.logPdf(minTitre, expectation, sd); |
| 804 |
if (CHECK_INFINITE && Double.isNaN(lnL) || Double.isInfinite(lnL)) { |
| 805 |
throw new RuntimeException("infinite interval measurement"); |
| 806 |
} |
| 807 |
} |
| 808 |
return lnL; |
| 809 |
} |
| 810 |
|
| 811 |
public void makeDirty() { |
| 812 |
likelihoodKnown = false; |
| 813 |
setLocationChangedFlags(true); |
| 814 |
} |
| 815 |
|
| 816 |
private class Measurement { |
| 817 |
private Measurement(final int virus, final int serum, final double virusDate, final double serumDate, final MeasurementType type, final double titre, final boolean isLowerThreshold) { |
| 818 |
this.virus = virus; |
| 819 |
this.serum = serum; |
| 820 |
this.virusDate = virusDate; |
| 821 |
this.serumDate = serumDate; |
| 822 |
this.type = type; |
| 823 |
this.titre = titre; |
| 824 |
this.log2Titre = Math.log(titre) / Math.log(2); |
| 825 |
this.isLowerThreshold = isLowerThreshold; |
| 826 |
} |
| 827 |
|
| 828 |
final int virus; |
| 829 |
final int serum; |
| 830 |
final double virusDate; |
| 831 |
final double serumDate; |
| 832 |
final MeasurementType type; |
| 833 |
final double titre; |
| 834 |
final double log2Titre; |
| 835 |
final boolean isLowerThreshold; |
| 836 |
|
| 837 |
}; |
| 838 |
|
| 839 |
private final List<Measurement> measurements = new ArrayList<Measurement>(); |
| 840 |
private final List<String> virusNames = new ArrayList<String>(); |
| 841 |
private final List<String> serumNames = new ArrayList<String>(); |
| 842 |
private final List<Double> virusDates = new ArrayList<Double>(); |
| 843 |
private final List<Double> serumDates = new ArrayList<Double>(); |
| 844 |
|
| 845 |
private final int mdsDimension; |
| 846 |
private final double intervalWidth; |
| 847 |
private final Parameter mdsPrecisionParameter; |
| 848 |
private final Parameter locationDriftParameter; |
| 849 |
private final Parameter virusDriftParameter; |
| 850 |
private final Parameter serumDriftParameter; |
| 851 |
|
| 852 |
private final MatrixParameter virusLocationsParameter; |
| 853 |
private final MatrixParameter serumLocationsParameter; |
| 854 |
|
| 855 |
private final Parameter virusOffsetsParameter; |
| 856 |
private final Parameter serumOffsetsParameter; |
| 857 |
|
| 858 |
private final CompoundParameter tipTraitsParameter; |
| 859 |
private int[] tipIndices; |
| 860 |
|
| 861 |
private final Parameter virusAviditiesParameter; |
| 862 |
private final Parameter serumPotenciesParameter; |
| 863 |
private final Parameter serumBreadthsParameter; |
| 864 |
|
| 865 |
private double logLikelihood = 0.0; |
| 866 |
private boolean likelihoodKnown = false; |
| 867 |
|
| 868 |
private final boolean[] virusLocationChanged; |
| 869 |
private final boolean[] serumLocationChanged; |
| 870 |
private final boolean[] serumEffectChanged; |
| 871 |
private final boolean[] virusEffectChanged; |
| 872 |
private double[] logLikelihoods; |
| 873 |
private double[] storedLogLikelihoods; |
| 874 |
|
| 875 |
private boolean clusterMeans = false; |
| 876 |
private Parameter clusterOffsetsParameter; |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 883 |
|
| 884 |
public final static String FILE_NAME = "fileName"; |
| 885 |
public final static String TIP_TRAIT = "tipTrait"; |
| 886 |
public final static String VIRUS_LOCATIONS = "virusLocations"; |
| 887 |
public final static String SERUM_LOCATIONS = "serumLocations"; |
| 888 |
public static final String MDS_DIMENSION = "mdsDimension"; |
| 889 |
public static final String MERGE_SERUM_ISOLATES = "mergeSerumIsolates"; |
| 890 |
public static final String DRIFT_INITIAL_LOCATIONS = "driftInitialLocations"; |
| 891 |
public static final String INTERVAL_WIDTH = "intervalWidth"; |
| 892 |
public static final String MDS_PRECISION = "mdsPrecision"; |
| 893 |
public static final String LOCATION_DRIFT = "locationDrift"; |
| 894 |
public static final String VIRUS_DRIFT = "virusDrift"; |
| 895 |
public static final String SERUM_DRIFT = "serumDrift"; |
| 896 |
public static final String VIRUS_AVIDITIES = "virusAvidities"; |
| 897 |
public static final String SERUM_POTENCIES = "serumPotencies"; |
| 898 |
public static final String SERUM_BREADTHS = "serumBreadths"; |
| 899 |
public final static String VIRUS_OFFSETS = "virusOffsets"; |
| 900 |
public final static String SERUM_OFFSETS = "serumOffsets"; |
| 901 |
public final static String CLUSTER_MEANS = "clusterMeans"; |
| 902 |
public final static String CLUSTER_OFFSETS = "clusterOffsetsParameter"; |
| 903 |
|
| 904 |
public String getParserName() { |
| 905 |
return AG_LIKELIHOOD; |
| 906 |
} |
| 907 |
|
| 908 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 909 |
|
| 910 |
String fileName = xo.getStringAttribute(FILE_NAME); |
| 911 |
DataTable<String[]> assayTable; |
| 912 |
try { |
| 913 |
assayTable = DataTable.Text.parse(new FileReader(fileName), true, false); |
| 914 |
} catch (IOException e) { |
| 915 |
throw new XMLParseException("Unable to read assay data from file: " + e.getMessage()); |
| 916 |
} |
| 917 |
System.out.println("Loaded HI table file: " + fileName); |
| 918 |
|
| 919 |
boolean mergeSerumIsolates = xo.getAttribute(MERGE_SERUM_ISOLATES, false); |
| 920 |
|
| 921 |
boolean cluster_means = xo.getAttribute(CLUSTER_MEANS, false); |
| 922 |
|
| 923 |
int mdsDimension = xo.getIntegerAttribute(MDS_DIMENSION); |
| 924 |
double intervalWidth = 0.0; |
| 925 |
if (xo.hasAttribute(INTERVAL_WIDTH)) { |
| 926 |
intervalWidth = xo.getDoubleAttribute(INTERVAL_WIDTH); |
| 927 |
} |
| 928 |
|
| 929 |
double driftInitialLocations = 0.0; |
| 930 |
if (xo.hasAttribute(DRIFT_INITIAL_LOCATIONS)) { |
| 931 |
driftInitialLocations = xo.getDoubleAttribute(DRIFT_INITIAL_LOCATIONS); |
| 932 |
} |
| 933 |
|
| 934 |
CompoundParameter tipTraitParameter = null; |
| 935 |
if (xo.hasChildNamed(TIP_TRAIT)) { |
| 936 |
tipTraitParameter = (CompoundParameter) xo.getElementFirstChild(TIP_TRAIT); |
| 937 |
} |
| 938 |
|
| 939 |
MatrixParameter virusLocationsParameter = null; |
| 940 |
if (xo.hasChildNamed(VIRUS_LOCATIONS)) { |
| 941 |
virusLocationsParameter = (MatrixParameter) xo.getElementFirstChild(VIRUS_LOCATIONS); |
| 942 |
} |
| 943 |
|
| 944 |
MatrixParameter serumLocationsParameter = null; |
| 945 |
if (xo.hasChildNamed(SERUM_LOCATIONS)) { |
| 946 |
serumLocationsParameter = (MatrixParameter) xo.getElementFirstChild(SERUM_LOCATIONS); |
| 947 |
} |
| 948 |
|
| 949 |
Parameter mdsPrecision = (Parameter) xo.getElementFirstChild(MDS_PRECISION); |
| 950 |
|
| 951 |
Parameter locationDrift = null; |
| 952 |
if (xo.hasChildNamed(LOCATION_DRIFT)) { |
| 953 |
locationDrift = (Parameter) xo.getElementFirstChild(LOCATION_DRIFT); |
| 954 |
} |
| 955 |
|
| 956 |
Parameter virusDrift = null; |
| 957 |
if (xo.hasChildNamed(VIRUS_DRIFT)) { |
| 958 |
virusDrift = (Parameter) xo.getElementFirstChild(VIRUS_DRIFT); |
| 959 |
} |
| 960 |
|
| 961 |
Parameter serumDrift = null; |
| 962 |
if (xo.hasChildNamed(SERUM_DRIFT)) { |
| 963 |
serumDrift = (Parameter) xo.getElementFirstChild(SERUM_DRIFT); |
| 964 |
} |
| 965 |
|
| 966 |
Parameter virusOffsetsParameter = null; |
| 967 |
if (xo.hasChildNamed(VIRUS_OFFSETS)) { |
| 968 |
virusOffsetsParameter = (Parameter) xo.getElementFirstChild(VIRUS_OFFSETS); |
| 969 |
} |
| 970 |
|
| 971 |
Parameter serumOffsetsParameter = null; |
| 972 |
if (xo.hasChildNamed(SERUM_OFFSETS)) { |
| 973 |
serumOffsetsParameter = (Parameter) xo.getElementFirstChild(SERUM_OFFSETS); |
| 974 |
} |
| 975 |
|
| 976 |
Parameter serumPotenciesParameter = null; |
| 977 |
if (xo.hasChildNamed(SERUM_POTENCIES)) { |
| 978 |
serumPotenciesParameter = (Parameter) xo.getElementFirstChild(SERUM_POTENCIES); |
| 979 |
} |
| 980 |
|
| 981 |
Parameter serumBreadthsParameter = null; |
| 982 |
if (xo.hasChildNamed(SERUM_BREADTHS)) { |
| 983 |
serumBreadthsParameter = (Parameter) xo.getElementFirstChild(SERUM_BREADTHS); |
| 984 |
} |
| 985 |
|
| 986 |
Parameter virusAviditiesParameter = null; |
| 987 |
if (xo.hasChildNamed(VIRUS_AVIDITIES)) { |
| 988 |
virusAviditiesParameter = (Parameter) xo.getElementFirstChild(VIRUS_AVIDITIES); |
| 989 |
} |
| 990 |
|
| 991 |
Parameter clusterOffsetsParameter = null; |
| 992 |
if (xo.hasChildNamed(CLUSTER_OFFSETS)) { |
| 993 |
clusterOffsetsParameter = (Parameter) xo.getElementFirstChild(CLUSTER_OFFSETS); |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
AGLikelihoodCluster AGL = new AGLikelihoodCluster( |
| 998 |
mdsDimension, |
| 999 |
mdsPrecision, |
| 1000 |
locationDrift, |
| 1001 |
virusDrift, |
| 1002 |
serumDrift, |
| 1003 |
virusLocationsParameter, |
| 1004 |
serumLocationsParameter, |
| 1005 |
tipTraitParameter, |
| 1006 |
virusOffsetsParameter, |
| 1007 |
serumOffsetsParameter, |
| 1008 |
serumPotenciesParameter, |
| 1009 |
serumBreadthsParameter, |
| 1010 |
virusAviditiesParameter, |
| 1011 |
assayTable, |
| 1012 |
mergeSerumIsolates, |
| 1013 |
intervalWidth, |
| 1014 |
driftInitialLocations, |
| 1015 |
cluster_means, |
| 1016 |
clusterOffsetsParameter); |
| 1017 |
|
| 1018 |
|
| 1019 |
Logger.getLogger("dr.evomodel").info("Using EvolutionaryCartography model. Please cite:\n" + Utils.getCitationString(AGL)); |
| 1020 |
|
| 1021 |
return AGL; |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
public String getParserDescription() { |
| 1029 |
return "Provides the likelihood of immunological assay data such as Hemagglutinin inhibition (HI) given vectors of coordinates" + |
| 1030 |
"for viruses and sera/antisera in some multidimensional 'antigenic' space."; |
| 1031 |
} |
| 1032 |
|
| 1033 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 1034 |
return rules; |
| 1035 |
} |
| 1036 |
|
| 1037 |
private final XMLSyntaxRule[] rules = { |
| 1038 |
AttributeRule.newStringRule(FILE_NAME, false, "The name of the file containing the assay table"), |
| 1039 |
AttributeRule.newIntegerRule(MDS_DIMENSION, false, "The dimension of the space for MDS"), |
| 1040 |
AttributeRule.newBooleanRule(MERGE_SERUM_ISOLATES, true, "Should multiple serum isolates from the same strain have their locations merged (defaults to false)"), |
| 1041 |
AttributeRule.newDoubleRule(INTERVAL_WIDTH, true, "The width of the titre interval in log 2 space"), |
| 1042 |
AttributeRule.newDoubleRule(DRIFT_INITIAL_LOCATIONS, true, "The degree to drift initial virus and serum locations, defaults to 0.0"), |
| 1043 |
new ElementRule(TIP_TRAIT, CompoundParameter.class, "Optional parameter of tip locations from the tree", true), |
| 1044 |
new ElementRule(VIRUS_LOCATIONS, MatrixParameter.class, "Parameter of locations of all virus"), |
| 1045 |
new ElementRule(SERUM_LOCATIONS, MatrixParameter.class, "Parameter of locations of all sera"), |
| 1046 |
new ElementRule(VIRUS_OFFSETS, Parameter.class, "Optional parameter for virus dates to be stored", true), |
| 1047 |
new ElementRule(SERUM_OFFSETS, Parameter.class, "Optional parameter for serum dates to be stored", true), |
| 1048 |
new ElementRule(SERUM_POTENCIES, Parameter.class, "Optional parameter for serum potencies", true), |
| 1049 |
new ElementRule(SERUM_BREADTHS, Parameter.class, "Optional parameter for serum breadths", true), |
| 1050 |
new ElementRule(VIRUS_AVIDITIES, Parameter.class, "Optional parameter for virus avidities", true), |
| 1051 |
new ElementRule(MDS_PRECISION, Parameter.class, "Parameter for precision of MDS embedding"), |
| 1052 |
new ElementRule(LOCATION_DRIFT, Parameter.class, "Optional parameter for drifting locations with time", true), |
| 1053 |
new ElementRule(VIRUS_DRIFT, Parameter.class, "Optional parameter for drifting only virus locations, overrides locationDrift", true), |
| 1054 |
new ElementRule(SERUM_DRIFT, Parameter.class, "Optional parameter for drifting only serum locations, overrides locationDrift", true), |
| 1055 |
AttributeRule.newBooleanRule(CLUSTER_MEANS, true, "Should we use cluster means to control the virus locations"), |
| 1056 |
new ElementRule(CLUSTER_OFFSETS, Parameter.class, "Parameter of cluster offsets of all virus"), |
| 1057 |
}; |
| 1058 |
|
| 1059 |
public Class getReturnType() { |
| 1060 |
return AGLikelihoodCluster.class; |
| 1061 |
} |
| 1062 |
}; |
| 1063 |
|
| 1064 |
@Override |
| 1065 |
public Citation.Category getCategory() { |
| 1066 |
return Citation.Category.TRAIT_MODELS; |
| 1067 |
} |
| 1068 |
|
| 1069 |
@Override |
| 1070 |
public String getDescription() { |
| 1071 |
return "Bayesian Antigenic Cartography framework"; |
| 1072 |
} |
| 1073 |
|
| 1074 |
public List<Citation> getCitations() { |
| 1075 |
return Arrays.asList(new Citation( |
| 1076 |
new Author[]{ |
| 1077 |
new Author("C", "Cheung"), |
| 1078 |
new Author("A", "Rambaut"), |
| 1079 |
new Author("P", "Lemey"), |
| 1080 |
new Author("MA", "Suchard"), |
| 1081 |
new Author("T", "Bedford") |
| 1082 |
}, |
| 1083 |
Citation.Status.IN_PREPARATION |
| 1084 |
), |
| 1085 |
CommonCitations.BEDFORD_2015_INTEGRATING); |
| 1086 |
} |
| 1087 |
} |