protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
final SAMFileReader reader = new SAMFileReader(IOUtil.openFileForReading(INPUT));
final Map<String, SAMRecord> firstSeenMates = new HashMap<String, SAMRecord>();
final FastqWriterFactory factory = new FastqWriterFactory();
factory.setCreateMd5(CREATE_MD5_FILE);
final Map<SAMReadGroupRecord, FastqWriters> writers = generateWriters(reader.getFileHeader().getReadGroups(), factory);
final ProgressLogger progress = new ProgressLogger(log);
for (final SAMRecord currentRecord : reader) {
if (currentRecord.isSecondaryOrSupplementary() && !INCLUDE_NON_PRIMARY_ALIGNMENTS)