I owe Doug a beer for finding this:

don't print out intervals to be merged if they're not within the global -L intervals


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1615 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2009-09-14 20:22:30 +00:00
parent 7d6d114ab5
commit 436f543b3b
1 changed files with 20 additions and 17 deletions

View File

@ -33,7 +33,6 @@ import org.broadinstitute.sting.utils.*;
import org.broadinstitute.sting.utils.cmdLine.Argument; import org.broadinstitute.sting.utils.cmdLine.Argument;
import java.util.*; import java.util.*;
import java.io.*;
/** /**
@ -52,42 +51,46 @@ public class IntervalMergerWalker extends ReadWalker<Integer,Integer> {
int maxIntervalSize = 500; int maxIntervalSize = 500;
private LinkedList<GenomeLoc> intervals; private LinkedList<GenomeLoc> intervals;
private GenomeLoc firstInterval = null; private GenomeLoc currentInterval = null;
private boolean currentIntervalIsUsed = false;
@Override @Override
public void initialize() { public void initialize() {
intervals = parseIntervals(intervalsSource); intervals = parseIntervals(intervalsSource);
firstInterval = intervals.removeFirst(); currentInterval = intervals.removeFirst();
} }
@Override @Override
public Integer map(char[] ref, SAMRecord read) { public Integer map(char[] ref, SAMRecord read) {
if ( firstInterval == null || if ( currentInterval == null ||
(!allow454 && Utils.is454Read(read)) ) (!allow454 && Utils.is454Read(read)) )
return 0; return 0;
GenomeLoc loc = GenomeLocParser.createGenomeLoc(read); GenomeLoc loc = GenomeLocParser.createGenomeLoc(read);
// emit all intervals which we've passed // ignore all intervals which we've passed
while ( loc.isPast(firstInterval) ) { while ( loc.isPast(currentInterval) ) {
if ( firstInterval.getStop() - firstInterval.getStart() < maxIntervalSize) if ( currentIntervalIsUsed && currentInterval.getStop() - currentInterval.getStart() < maxIntervalSize) {
out.println(firstInterval); out.println(currentInterval);
currentIntervalIsUsed = false;
}
if ( intervals.size() > 0 ) { if ( intervals.size() > 0 ) {
firstInterval = intervals.removeFirst(); currentInterval = intervals.removeFirst();
} else { } else {
firstInterval = null; currentInterval = null;
return 0; return 0;
} }
} }
// if we're not yet in the first interval, we're done // if we're not yet in the current interval, we're done
if ( !loc.overlapsP(firstInterval)) if ( !loc.overlapsP(currentInterval))
return 0; return 0;
// at this point, we're in the first interval. // at this point, we're in the current interval.
// now we can merge any other intervals which we overlap // now we can merge any other intervals which we overlap
currentIntervalIsUsed = true;
while ( intervals.size() > 0 && loc.overlapsP(intervals.getFirst()) ) while ( intervals.size() > 0 && loc.overlapsP(intervals.getFirst()) )
firstInterval = GenomeLocParser.setStop(firstInterval,intervals.removeFirst().getStop()); currentInterval = GenomeLocParser.setStop(currentInterval, intervals.removeFirst().getStop());
return 1; return 1;
} }
@ -102,9 +105,9 @@ public class IntervalMergerWalker extends ReadWalker<Integer,Integer> {
@Override @Override
public void onTraversalDone( Integer value ) { public void onTraversalDone( Integer value ) {
if ( firstInterval != null && if ( currentInterval != null && currentIntervalIsUsed &&
firstInterval.getStop() - firstInterval.getStart() < maxIntervalSize) currentInterval.getStop() - currentInterval.getStart() < maxIntervalSize)
out.println(firstInterval); out.println(currentInterval);
} }
/** /**