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);
/**
* If we can do some duplicate marking, lets do it!
* IMPORTANT: this does not flush the to-mark-queue, so the minimum distance needs to be set for us to infer
* which records will never be supplemented (i.e. are non-duplicate).
*/
performedChunkAndMarkTheDuplicates = tryPollingTheToMarkQueue(false, readEnds);
}
// We can now remove the record from the input
backingIterator.next();
// Add this to the outputBuffer so it can be tracked. It will not be available to emit until it has been through duplicate marking.
addRecordToTheOutputBuffer(samRecordWithOrdinal);
backingIteratorRecordIndex++; // Each record is has an index and is emitted in the same order. This helps that.
// We do not consider secondary, supplementary, or unmapped alignments for duplicate marking. We can thus mark that duplicate marking on them has been completed.
if (record.isSecondaryOrSupplementary() || record.getReadUnmappedFlag()) {
outputBuffer.setResultState(samRecordWithOrdinal, false);
} else {
// Bring the simple metrics up to date
final DuplicationMetrics metrics = getMetrics(record);
if (!record.getReadPairedFlag() || record.getMateUnmappedFlag()) {
++metrics.UNPAIRED_READS_EXAMINED;
} else {
++metrics.READ_PAIRS_EXAMINED; // will need to be divided by 2 at the end
}