Prevent out of bound error in case read span > reference context + indel length. Can happen in RNAseq reads with long N CIGAR operators in the middle.

This commit is contained in:
Guillermo del Angel 2011-11-22 13:57:24 -05:00
parent c62082ba1b
commit 32a77a8a56
1 changed files with 38 additions and 31 deletions

View File

@ -555,41 +555,48 @@ public class PairHMMIndelErrorModel {
// cut haplotype bases // cut haplotype bases
long indStart = start - haplotype.getStartPosition(); long indStart = start - haplotype.getStartPosition();
long indStop = stop - haplotype.getStartPosition(); long indStop = stop - haplotype.getStartPosition();
final byte[] haplotypeBases = Arrays.copyOfRange(haplotype.getBasesAsBytes(),
(int)indStart, (int)indStop);
double readLikelihood; double readLikelihood;
if (matchMetricArray == null) {
final int X_METRIC_LENGTH = readBases.length+1;
final int Y_METRIC_LENGTH = haplotypeBases.length+1;
matchMetricArray = new double[X_METRIC_LENGTH][Y_METRIC_LENGTH]; if (indStart < 0 || indStop >= haplotype.getBasesAsBytes().length) {
XMetricArray = new double[X_METRIC_LENGTH][Y_METRIC_LENGTH]; // read spanned more than allowed reference context: we currently can't deal with this
YMetricArray = new double[X_METRIC_LENGTH][Y_METRIC_LENGTH]; readLikelihood =0;
} } else
final double[] currentContextGOP = Arrays.copyOfRange(gapOpenProbabilityMap.get(a), (int)indStart, (int)indStop); {
final double[] currentContextGCP = Arrays.copyOfRange(gapContProbabilityMap.get(a), (int)indStart, (int)indStop); final byte[] haplotypeBases = Arrays.copyOfRange(haplotype.getBasesAsBytes(),
if (previousHaplotypeSeen == null) (int)indStart, (int)indStop);
startIdx = 0;
else { if (matchMetricArray == null) {
final int s1 = computeFirstDifferingPosition(haplotypeBases, previousHaplotypeSeen); final int X_METRIC_LENGTH = readBases.length+1;
final int s2 = computeFirstDifferingPosition(currentContextGOP, previousGOP); final int Y_METRIC_LENGTH = haplotypeBases.length+1;
final int s3 = computeFirstDifferingPosition(currentContextGCP, previousGCP);
startIdx = Math.min(Math.min(s1, s2), s3); matchMetricArray = new double[X_METRIC_LENGTH][Y_METRIC_LENGTH];
} XMetricArray = new double[X_METRIC_LENGTH][Y_METRIC_LENGTH];
previousHaplotypeSeen = haplotypeBases.clone(); YMetricArray = new double[X_METRIC_LENGTH][Y_METRIC_LENGTH];
previousGOP = currentContextGOP.clone(); }
previousGCP = currentContextGCP.clone(); final double[] currentContextGOP = Arrays.copyOfRange(gapOpenProbabilityMap.get(a), (int)indStart, (int)indStop);
final double[] currentContextGCP = Arrays.copyOfRange(gapContProbabilityMap.get(a), (int)indStart, (int)indStop);
if (previousHaplotypeSeen == null)
startIdx = 0;
else {
final int s1 = computeFirstDifferingPosition(haplotypeBases, previousHaplotypeSeen);
final int s2 = computeFirstDifferingPosition(currentContextGOP, previousGOP);
final int s3 = computeFirstDifferingPosition(currentContextGCP, previousGCP);
startIdx = Math.min(Math.min(s1, s2), s3);
}
previousHaplotypeSeen = haplotypeBases.clone();
previousGOP = currentContextGOP.clone();
previousGCP = currentContextGCP.clone();
readLikelihood = computeReadLikelihoodGivenHaplotypeAffineGaps(haplotypeBases, readBases, readQuals, readLikelihood = computeReadLikelihoodGivenHaplotypeAffineGaps(haplotypeBases, readBases, readQuals,
currentContextGOP, currentContextGCP, startIdx, matchMetricArray, XMetricArray, YMetricArray); currentContextGOP, currentContextGCP, startIdx, matchMetricArray, XMetricArray, YMetricArray);
if (DEBUG) {
System.out.println("H:"+new String(haplotypeBases)); if (DEBUG) {
System.out.println("R:"+new String(readBases)); System.out.println("H:"+new String(haplotypeBases));
System.out.format("L:%4.2f\n",readLikelihood); System.out.println("R:"+new String(readBases));
System.out.format("StPos:%d\n", startIdx); System.out.format("L:%4.2f\n",readLikelihood);
System.out.format("StPos:%d\n", startIdx);
}
} }
readEl.put(a,readLikelihood); readEl.put(a,readLikelihood);
readLikelihoods[readIdx][j++] = readLikelihood; readLikelihoods[readIdx][j++] = readLikelihood;