////////////////////////////////////////////////////////////////////////
// Main loop that consumes reads, clips them and writes them to the output
////////////////////////////////////////////////////////////////////////
final ProgressLogger progress = new ProgressLogger(log, 1000000, "Read");
final SAMRecordIterator iterator = in.iterator();
final AdapterMarker adapterMarker = new AdapterMarker(ADAPTER_TRUNCATION_LENGTH, adapters).
setMaxPairErrorRate(MAX_ERROR_RATE_PE).setMinPairMatchBases(MIN_MATCH_BASES_PE).
setMaxSingleEndErrorRate(MAX_ERROR_RATE_SE).setMinSingleEndMatchBases(MIN_MATCH_BASES_SE).
setNumAdaptersToKeep(NUM_ADAPTERS_TO_KEEP).
setThresholdForSelectingAdaptersToKeep(PRUNE_ADAPTER_LIST_AFTER_THIS_MANY_ADAPTERS_SEEN);
while (iterator.hasNext()) {
final SAMRecord rec = iterator.next();
final SAMRecord rec2 = rec.getReadPairedFlag() && iterator.hasNext() ? iterator.next() : null;
rec.setAttribute(ReservedTagConstants.XT, null);
// Do the clipping one way for PE and another for SE reads
if (rec.getReadPairedFlag()) {
// Assert that the input file is in query name order only if we see some PE reads