Skip to content

Commit

Permalink
[ADAM-1099] Make reference region not throw NPE.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnothaft committed Aug 14, 2016
1 parent 273d57f commit fd1b6b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,10 @@ object ReferenceRegion {
*/
def opt(record: AlignmentRecord): Option[ReferenceRegion] = {
if (record.getReadMapped) {
Some(
ReferenceRegion(
record.getContigName,
record.getStart,
record.getEnd
)
)
} else
Some(apply(record))
} else {
None
}
}

/**
Expand Down Expand Up @@ -117,6 +112,12 @@ object ReferenceRegion {
}

def apply(record: AlignmentRecord): ReferenceRegion = {
require(record.getReadMapped,
"Cannot build reference region for unmapped read %s.".format(record))
require(record.getContigName != null &&
record.getStart != null &&
record.getEnd != null,
"Read %s contains required fields that are null.".format(record))
ReferenceRegion(record.getContigName, record.getStart, record.getEnd)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,23 @@ class ReferenceRegionSuite extends FunSuite {
}

test("create region from unmapped read fails") {
intercept[NullPointerException] {
intercept[IllegalArgumentException] {
val read = AlignmentRecord.newBuilder()
.setReadMapped(false)
.build()
ReferenceRegion(read)
}
}

test("create region from read with null alignment positions fails") {
intercept[IllegalArgumentException] {
val read = AlignmentRecord.newBuilder()
.setReadMapped(true)
.build()
ReferenceRegion(read)
}
}

test("create region from mapped read contains read start and end") {
val read = AlignmentRecord.newBuilder()
.setReadMapped(true)
Expand Down

0 comments on commit fd1b6b4

Please sign in to comment.