void seekMatchingRead ( ) { while ( ! isAtEnd ( ) ) { if ( iterator == null || ! iterator . hasNext ( ) ) { LOG . info ( "Getting " + ( iterator == null ? "first" : "next" ) + " interval from the API" ) ; // We have hit an end (or this is first time) so we need to go fish // to the API. ReadIteratorResource < Read , ReadGroupSet , Reference > resource = queryNextInterval ( ) ; if ( resource != null ) { LOG . info ( "Got next interval from the API" ) ; header = resource . getSAMFileHeader ( ) ; iterator = resource . getSAMRecordIterable ( ) . iterator ( ) ; } else { LOG . info ( "Failed to get next interval from the API" ) ; header = null ; iterator = null ; } } else { nextRead = iterator . next ( ) ; if ( currentInterval ( ) . matches ( nextRead ) ) { return ; // Happy case, otherwise we keep spinning in the loop. } else { LOG . info ( "Skipping non matching read" ) ; } } } }
Ensures next returned read will match the currently requested interval . Since the API always returns overlapping reads we might need to skip some reads if the interval asks for included or starts at types . Also deals with the case of iterator being at an end and needing to query for the next interval .