Skip to content

Commit

Permalink
Propagate read negative flag to SAM records for unmapped reads
Browse files Browse the repository at this point in the history
  • Loading branch information
henrydavidge authored and heuermh committed Dec 18, 2018
1 parent c4fa300 commit a8bbc72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit a8bbc72

Please sign in to comment.