2009-04-03 06:08:10 +08:00
|
|
|
package org.broadinstitute.sting.playground.fourbasecaller;
|
|
|
|
|
|
2009-04-07 06:00:58 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
|
2009-04-04 03:19:17 +08:00
|
|
|
/**
|
|
|
|
|
* BasecallingReadModel represents the statistical models for
|
|
|
|
|
* all bases in all cycles. It allows for easy, one-pass
|
|
|
|
|
* training via the addTrainingPoint() method, and for the
|
|
|
|
|
* computation of the 4x4 likelihood matrix or the 1x4
|
|
|
|
|
* probability vector (with contextual components marginalized
|
|
|
|
|
* out of the likelihood matrix).
|
|
|
|
|
*
|
|
|
|
|
* @author Kiran Garimella
|
|
|
|
|
*/
|
2009-04-03 06:08:10 +08:00
|
|
|
public class BasecallingReadModel {
|
|
|
|
|
private BasecallingBaseModel[] basemodels = null;
|
|
|
|
|
|
2009-04-04 03:19:17 +08:00
|
|
|
/**
|
|
|
|
|
* Constructor for BasecallingReadModel.
|
|
|
|
|
*
|
|
|
|
|
* @param readLength the length of the read that this model will support
|
|
|
|
|
*/
|
2009-04-03 06:08:10 +08:00
|
|
|
public BasecallingReadModel(int readLength) {
|
|
|
|
|
basemodels = new BasecallingBaseModel[readLength];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < readLength; i++) {
|
|
|
|
|
basemodels[i] = new BasecallingBaseModel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-04 03:19:17 +08:00
|
|
|
/**
|
|
|
|
|
* Add a single training point to the model.
|
2009-04-07 06:00:58 +08:00
|
|
|
*
|
2009-04-04 03:19:17 +08:00
|
|
|
* @param cycle the cycle for which this point should be added
|
|
|
|
|
* @param baseCur the current base
|
|
|
|
|
* @param qualCur the current base's quality
|
|
|
|
|
* @param fourintensity the four intensities of the current base
|
|
|
|
|
*/
|
2009-04-07 09:20:15 +08:00
|
|
|
public void addMeanPoint(int cycle, char baseCur, byte qualCur, double[] fourintensity) {
|
|
|
|
|
basemodels[cycle].addMeanPoint(baseCur, qualCur, fourintensity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addCovariancePoint(int cycle, char baseCur, byte qualCur, double[] fourintensity) {
|
|
|
|
|
basemodels[cycle].addCovariancePoint(baseCur, qualCur, fourintensity);
|
2009-04-03 06:08:10 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-04 03:19:17 +08:00
|
|
|
/**
|
|
|
|
|
* Compute the likelihood matrix for a given cycle.
|
|
|
|
|
*
|
|
|
|
|
* @param cycle the cycle number for the current base
|
|
|
|
|
* @param fourintensity the four intensities for the current cycle's base
|
|
|
|
|
* @return 4x4 matrix of likelihoods
|
|
|
|
|
*/
|
2009-04-07 10:18:13 +08:00
|
|
|
public double[] computeLikelihoods(int cycle, double[] fourintensity) {
|
|
|
|
|
return basemodels[cycle].computeLikelihoods(cycle, fourintensity);
|
2009-04-03 06:08:10 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-04 03:19:17 +08:00
|
|
|
/**
|
|
|
|
|
* Compute the probability distribution for the base at a given cycle.
|
|
|
|
|
*
|
|
|
|
|
* @param cycle the cycle number for the current base
|
|
|
|
|
* @param fourintensity the four intensities for the current cycle's base
|
|
|
|
|
* @return an instance of FourProb, which encodes a base hypothesis, its probability,
|
|
|
|
|
* and the ranking among the other hypotheses
|
|
|
|
|
*/
|
2009-04-07 10:18:13 +08:00
|
|
|
public FourProb computeProbabilities(int cycle, double[] fourintensity) {
|
|
|
|
|
double[] likes = computeLikelihoods(cycle, fourintensity);
|
2009-04-03 06:08:10 +08:00
|
|
|
|
|
|
|
|
double total = 0;
|
|
|
|
|
|
2009-04-07 10:18:13 +08:00
|
|
|
for (int baseCurIndex = 0; baseCurIndex < 4; baseCurIndex++) { total += likes[baseCurIndex]; }
|
|
|
|
|
for (int baseCurIndex = 0; baseCurIndex < 4; baseCurIndex++) { likes[baseCurIndex] /= total; }
|
2009-04-03 06:08:10 +08:00
|
|
|
|
2009-04-07 10:18:13 +08:00
|
|
|
return new FourProb(likes);
|
2009-04-03 06:08:10 +08:00
|
|
|
}
|
2009-04-07 06:00:58 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes model parameters to a file per cycle.
|
|
|
|
|
*
|
|
|
|
|
* @param dir the directory where the parameters should be written
|
|
|
|
|
*/
|
|
|
|
|
public void write(File dir) {
|
|
|
|
|
for (int cycle = 0; cycle < basemodels.length; cycle++) {
|
|
|
|
|
File outparam = new File(dir.getPath() + "/param." + cycle);
|
|
|
|
|
basemodels[cycle].write(outparam);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-03 06:08:10 +08:00
|
|
|
}
|