diff --git a/adam-core/src/main/scala/org/bdgenomics/adam/rdd/fragment/InterleavedFASTQInFormatter.scala b/adam-core/src/main/scala/org/bdgenomics/adam/rdd/fragment/InterleavedFASTQInFormatter.scala index 44a4deeb17..5a74aa3928 100644 --- a/adam-core/src/main/scala/org/bdgenomics/adam/rdd/fragment/InterleavedFASTQInFormatter.scala +++ b/adam-core/src/main/scala/org/bdgenomics/adam/rdd/fragment/InterleavedFASTQInFormatter.scala @@ -80,8 +80,18 @@ class InterleavedFASTQInFormatter private ( outputOriginalBaseQualities = writeOriginalQualities) + "\n" // write both to the output stream - os.write(fastq1.getBytes) - os.write(fastq2.getBytes) + // ensure that reads are ordered properly if ordering is known (see #1702) + if (read1.getReadInFragment == 0 && + read2.getReadInFragment == 1) { + os.write(fastq1.getBytes) + os.write(fastq2.getBytes) + } else if (read1.getReadInFragment == 1 && + read2.getReadInFragment == 0) { + os.write(fastq2.getBytes) + os.write(fastq1.getBytes) + } else { + log.warn("Improper pair of reads in fragment %s. Dropping...".format(p)) + } }) } } diff --git a/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/AnySAMOutFormatter.scala b/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/AnySAMOutFormatter.scala index 09b308a4d0..754d622569 100644 --- a/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/AnySAMOutFormatter.scala +++ b/adam-core/src/main/scala/org/bdgenomics/adam/rdd/read/AnySAMOutFormatter.scala @@ -29,7 +29,9 @@ import scala.collection.mutable.ListBuffer * An OutFormatter that automatically infers whether the piped input is SAM or * BAM. Autodetecting streamed CRAM is not currently supported. */ -class AnySAMOutFormatter extends OutFormatter[AlignmentRecord] { +case class AnySAMOutFormatter(stringency: ValidationStringency) extends OutFormatter[AlignmentRecord] { + + def this() = this(ValidationStringency.STRICT) /** * Reads alignment records from an input stream. Autodetects SAM/BAM format. @@ -41,6 +43,7 @@ class AnySAMOutFormatter extends OutFormatter[AlignmentRecord] { // make reader val reader = SamReaderFactory.makeDefault() + .validationStringency(stringency) .open(SamInputResource.of(is)) SAMIteratorConverter(reader)