purgeOutOfScopeRecords();
} else {
// ooops, we are past the end of all loaded records - kill them all at once,
// load next record and reinitialize by fastforwarding current position to the start of next record
records.clear();
GATKFeature r = it.next(); // if hasNext() previously returned true, we are guaranteed that this call to reader.next() is safe
records.add( r );
curr_contig = r.getLocation().getContig();
curr_position = r.getLocation().getStart();
max_position = r.getLocation().getStop();
}
// current position is ste and at this point 'records' only keeps those annotations, on which we did not reach the end yet
// (we might have reloaded records completely if it was necessary); but we are not guaranteed yet that we
// hold ALL the records overlapping with the current position. Time to check if we just walked into the interval(s)
// covered by new records, so we need to load them too:
while ( it.hasNext() ) {
GATKFeature r = it.element();
if ( r == null ) {
it.next();
continue;
}
GenomeLoc currentContig = parser.createOverEntireContig(curr_contig);
GenomeLoc thatContig = r.getLocation();
if ( currentContig.isPast(thatContig) )
throw new UserException("LocationAwareSeekableRODIterator: contig " +r.getLocation().getContig() +
" occurs out of order in track " + r.getName() );
if ( currentContig.isBefore(thatContig) ) break; // next record is on a higher contig, we do not need it yet...
if ( r.getLocation().getStart() < curr_position )
throw new UserException("LocationAwareSeekableRODIterator: track "+r.getName() +
" is out of coordinate order on contig "+r.getLocation() + " compared to " + curr_contig + ":" + curr_position);
if ( r.getLocation().getStart() > curr_position ) break; // next record starts after the current position; we do not need it yet
r = it.next(); // we got here only if we do need next record, time to load it for real
int stop = r.getLocation().getStop();
if ( stop < curr_position ) throw new ReviewedGATKException("DEBUG: encountered contig that should have been loaded earlier"); // this should never happen
if ( stop > max_position ) max_position = stop; // max_position keeps the rightmost stop position across all loaded records
records.add(r);
}