Fixes for constrained movement Indel Realigner. Now sorts all of the reads in the interval before handing them to ConstrainedMateFixingSAMFileWriter to maintain correct contract between the two pieces of software

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5329 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
depristo 2011-02-28 03:52:18 +00:00
parent d216830b92
commit 1dedfdb11b
3 changed files with 28 additions and 7 deletions

View File

@ -406,8 +406,9 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
private void emitReadLists() {
// pre-merge lists with priority queue for constrained SAMFileWriter
logger.warn("EMIT currentInterval " + currentInterval);
readsNotToClean.addAll(readsToClean.getReads());
emit(readsNotToClean);
emit(ReadUtils.coordinateSortReads(readsNotToClean));
readsToClean.clear();
readsNotToClean.clear();
}

View File

@ -156,7 +156,7 @@ public class ConstrainedMateFixingSAMFileWriter implements SAMFileWriter {
* @{inheritDoc}
*/
public void addAlignment( SAMRecord newRead ) {
if ( DEBUG ) logger.info("New read pos " + newRead.getAlignmentStart());
if ( DEBUG ) logger.info("New read pos " + newRead.getAlignmentStart() + " OP = " + newRead.getAttribute("OP"));
//final long curTime = timer.currentTime();
//if ( curTime - lastProgressPrintTime > PROGRESS_PRINT_FREQUENCY ) {
@ -217,8 +217,9 @@ public class ConstrainedMateFixingSAMFileWriter implements SAMFileWriter {
forMateMatching.remove(read.getReadName());
if ( DEBUG )
logger.warn(String.format("EMIT! At %d: read %s at %d with isize %d, mate start %d",
newRead.getAlignmentStart(), read.getReadName(), read.getAlignmentStart(), read.getInferredInsertSize(), read.getMateAlignmentStart()));
logger.warn(String.format("EMIT! At %d: read %s at %d with isize %d, mate start %d, op = %s",
newRead.getAlignmentStart(), read.getReadName(), read.getAlignmentStart(),
read.getInferredInsertSize(), read.getMateAlignmentStart(), read.getAttribute("OP")));
// emit to disk
finalDestination.addAlignment(waitingReads.remove());
} else {

View File

@ -27,8 +27,7 @@ package org.broadinstitute.sting.utils.sam;
import net.sf.samtools.*;
import java.util.Map;
import java.util.HashMap;
import java.util.*;
import java.io.File;
/**
@ -208,5 +207,25 @@ public class ReadUtils {
}
}
return flags;
}
}
/**
* Returns the collections of reads sorted in coordinate order, according to the order defined
* in the reads themselves
*
* @param reads
* @return
*/
public final static List<SAMRecord> coordinateSortReads(Collection<SAMRecord> reads) {
final int n = reads.size();
if ( n > 0 ) {
final SAMRecordComparator comparer = new SAMRecordCoordinateComparator();
final Queue<SAMRecord> sorted = new PriorityQueue<SAMRecord>(reads.size(), comparer);
sorted.addAll(reads);
return new ArrayList<SAMRecord>(sorted);
} else {
return Collections.emptyList();
}
}
}