while (backingIterator.hasNext()) {
// NB: we could get rid of this if we made nextRecord into a list...
// NB: we do not actually remove this record from the backing iterator until much later, to help with processing unmapped reads at the EOF
SAMRecord record = backingIterator.peek(); // peek: used for unmapped reads
final SamRecordWithOrdinal samRecordWithOrdinal = new SamRecordWithOrdinalAndSetDuplicateReadFlag(record, backingIteratorRecordIndex);
ReadEndsForMateCigar readEnds = null;
boolean performedChunkAndMarkTheDuplicates = false;
// remove duplicate information
record.setDuplicateReadFlag(false);
/** Check for pairs that have both ends mapped and missing mate cigar. */
if (ignoreDueToMissingMateCigar(samRecordWithOrdinal)) {
continue;
}
// check for an unmapped read
if (record.getReadUnmappedFlag()) {
// unmapped reads at the end of the file!
if (-1 == record.getReferenceIndex()) {
// NB: this may call markDuplicatesAndGetTheNextAvailable if this is the first time a EOF unmapped record has been seen
return nextIfRecordIsUnmappedAtEOF(record);
} else if (!record.isSecondaryOrSupplementary()) {
// update metrics
final DuplicationMetrics metrics = getMetrics(record);
++metrics.UNMAPPED_READS;
}
// we will check for unmapped reads later so as not to add them to mark queue
} else {
// If not already set, this sets the minimum distance to twice the read length, or 100, whichever is larger
if (-1 == toMarkQueue.getToMarkQueueMinimumDistance()) {
// use twice the first read's length
toMarkQueue.setToMarkQueueMinimumDistance(Math.max(2 * record.getReadBases().length, 100));
}
// build a read end for use in the toMarkQueue
readEnds = new ReadEndsForMateCigar(header, samRecordWithOrdinal, opticalDuplicateFinder, libraryIdGenerator.getLibraryId(samRecordWithOrdinal.getRecord()));
// check that the minimumDistance was not too small
checkForMinimumDistanceFailure(readEnds);
/**