From a8bbc720db3cd21f59ca508ed71185dc9931241c Mon Sep 17 00:00:00 2001 From: Henry D Date: Tue, 18 Dec 2018 14:25:11 -0800 Subject: [PATCH] Propagate read negative flag to SAM records for unmapped reads --- .../adam/converters/AlignmentRecordConverter.scala | 6 ++++-- .../converters/AlignmentRecordConverterSuite.scala | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala b/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala index 8fe2b610e9..2f46413967 100644 --- a/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala +++ b/adam-core/src/main/scala/org/bdgenomics/adam/converters/AlignmentRecordConverter.scala @@ -290,6 +290,10 @@ class AlignmentRecordConverter extends Serializable { .foreach(m => { builder.setReadUnmappedFlag(!m.booleanValue) + // Sometimes aligners like BWA-MEM mark a read as negative even if it's not mapped + Option(adamRecord.getReadNegativeStrand) + .foreach(v => builder.setReadNegativeStrandFlag(v.booleanValue)) + // only set alignment flags if read is aligned if (m) { // if we are aligned, we must have a reference @@ -301,8 +305,6 @@ class AlignmentRecordConverter extends Serializable { // set the old cigar, if provided Option(adamRecord.getOldCigar).foreach(v => builder.setAttribute("OC", v)) // set mapping flags - Option(adamRecord.getReadNegativeStrand) - .foreach(v => builder.setReadNegativeStrandFlag(v.booleanValue)) Option(adamRecord.getPrimaryAlignment) .foreach(v => builder.setNotPrimaryAlignmentFlag(!v.booleanValue)) Option(adamRecord.getSupplementaryAlignment) diff --git a/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala b/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala index 45167cc9b3..f812192733 100644 --- a/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala +++ b/adam-core/src/test/scala/org/bdgenomics/adam/converters/AlignmentRecordConverterSuite.scala @@ -326,5 +326,15 @@ class AlignmentRecordConverterSuite extends FunSuite { assert(read.getQual === "?????*****") assert(read.getContigName === "1") } + + test("read negative strand is propagated even when not mapped") { + val record = AlignmentRecord.newBuilder() + .setReadMapped(false) + .setReadNegativeStrand(true) + .build() + val fragment = Fragment.newBuilder().setAlignments(List(record)).build() + val converted = adamRecordConverter.convertFragment(fragment) + assert(converted.head.getReadNegativeStrand) + } }