nextFilePointer = new FilePointer(intervalMergingRule);
int coveredRegionStart = 1;
int coveredRegionStop = Integer.MAX_VALUE;
GenomeLoc coveredRegion = null;
BAMScheduleEntry scheduleEntry = getNextOverlappingBAMScheduleEntry(currentLocus);
// No overlapping data at all.
if(scheduleEntry != null) {
coveredRegionStart = Math.max(coveredRegionStart,scheduleEntry.start);
coveredRegionStop = Math.min(coveredRegionStop,scheduleEntry.stop);
coveredRegion = loci.getGenomeLocParser().createGenomeLoc(currentLocus.getContig(),coveredRegionStart,coveredRegionStop);
nextFilePointer.addFileSpans(scheduleEntry.fileSpans);
}
else {
// Always create a file span, whether there was covered data or not. If there was no covered data, then the binTree is empty.
for(SAMReaderID reader: indexFiles.keySet())
nextFilePointer.addFileSpans(reader,new GATKBAMFileSpan());
}
// Early exit if no bins were found.
if(coveredRegion == null) {
// for debugging only: maximum split is 16384.
nextFilePointer.addLocation(currentLocus);
currentLocus = locusIterator.hasNext() ? locusIterator.next() : null;
continue;
}
// Early exit if only part of the first interval was found.
if(currentLocus.startsBefore(coveredRegion)) {
int splitPoint = Math.min(coveredRegion.getStart()-currentLocus.getStart(),16384)+currentLocus.getStart();
GenomeLoc[] splitContigs = currentLocus.split(splitPoint);
nextFilePointer.addLocation(splitContigs[0]);
currentLocus = splitContigs[1];
continue;
}
// Define the initial range of the file pointer, aka the region where the locus currently being processed intersects the BAM list.
GenomeLoc initialLocation = currentLocus.intersect(coveredRegion);
nextFilePointer.addLocation(initialLocation);
// See whether the BAM regions discovered overlap the next set of intervals in the interval list. If so, include every overlapping interval.
if(!nextFilePointer.locations.isEmpty()) {
while(locusIterator.hasNext() && locusIterator.peek().overlapsP(coveredRegion)) {