Fix for Tim. It was possible for the constrained mate fixer to dump its cache in them middle of a given realignment (so the IndelRealigner was playing by the rules). No longer possible.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5785 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2011-05-10 16:48:24 +00:00
parent fbe7974094
commit 8d47d2e813
2 changed files with 29 additions and 15 deletions

View File

@ -7,10 +7,7 @@ import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.GenomeLocParser;
import org.broadinstitute.sting.utils.exceptions.UserException;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.*;
/*
* Copyright (c) 2009 The Broad Institute
@ -169,16 +166,17 @@ public class ConstrainedMateFixingManager {
return pos + 2 * MAX_POS_MOVE_ALLOWED < addedRead.getAlignmentStart();
}
private void writeRead(SAMRecord read) {
try {
writer.addAlignment(read);
} catch (IllegalArgumentException e) {
throw new UserException("If the maximum allowable reads in memory is too small, it may cause reads to be written out of order when trying to write the BAM; please see the --maxReadsInMemory argument for details. " + e.getMessage(), e);
}
public void addRead(SAMRecord newRead, boolean readWasModified) {
addRead(newRead, readWasModified, true);
}
public void addRead(SAMRecord newRead, boolean readWasModified) {
if ( DEBUG ) logger.info("New read pos " + newRead.getAlignmentStart() + " OP = " + newRead.getAttribute("OP"));
public void addReads(List<SAMRecord> newReads, Set<SAMRecord> modifiedReads) {
for ( SAMRecord newRead : newReads )
addRead(newRead, modifiedReads.contains(newRead), false);
}
private void addRead(SAMRecord newRead, boolean readWasModified, boolean canFlush) {
if ( DEBUG ) logger.info("New read pos " + newRead.getAlignmentStart() + " OP = " + newRead.getAttribute("OP") + " " + readWasModified);
//final long curTime = timer.currentTime();
//if ( curTime - lastProgressPrintTime > PROGRESS_PRINT_FREQUENCY ) {
@ -188,7 +186,7 @@ public class ConstrainedMateFixingManager {
// if the new read is on a different contig or we have too many reads, then we need to flush the queue and clear the map
boolean tooManyReads = getNReadsInQueue() >= MAX_RECORDS_IN_MEMORY;
if ( tooManyReads || (getNReadsInQueue() > 0 && !waitingReads.peek().getReferenceIndex().equals(newRead.getReferenceIndex())) ) {
if ( canFlush && (tooManyReads || (getNReadsInQueue() > 0 && !waitingReads.peek().getReferenceIndex().equals(newRead.getReferenceIndex()))) ) {
if ( DEBUG ) logger.warn("Flushing queue on " + (tooManyReads ? "too many reads" : ("move to new contig: " + newRead.getReferenceName() + " from " + waitingReads.peek().getReferenceName())) + " at " + newRead.getAlignmentStart());
while ( getNReadsInQueue() > 1 ) {
@ -279,6 +277,14 @@ public class ConstrainedMateFixingManager {
}
}
private void writeRead(SAMRecord read) {
try {
writer.addAlignment(read);
} catch (IllegalArgumentException e) {
throw new UserException("If the maximum allowable reads in memory is too small, it may cause reads to be written out of order when trying to write the BAM; please see the --maxReadsInMemory argument for details. " + e.getMessage(), e);
}
}
/**
* @param read the read
* @return true if the read shouldn't be moved given the constraints of this SAMFileWriter

View File

@ -416,8 +416,16 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
// pre-merge lists to sort them in preparation for constrained SAMFileWriter
readsNotToClean.addAll(readsToClean.getReads());
ReadUtils.coordinateSortReads(readsNotToClean);
for ( SAMRecord read : readsNotToClean )
emit(read);
if ( N_WAY_OUT == null ) {
manager.addReads(readsNotToClean, readsActuallyCleaned);
} else {
// in this case, it is possible to have the following scenario: the realigner gets permission to realign,
// the cache in the ConstrainedMateFixingManager gets filled up while emitting reads, and then the
// first-of-pair mates of realigned reads don't get fixed because they were flushed out of the queue too early.
// Since the N-way option is @hidden, I'm not interested in fixing this right now.
for ( SAMRecord read : readsNotToClean )
emit(read);
}
readsToClean.clear();
readsNotToClean.clear();
readsActuallyCleaned.clear();