Skip to content

Commit

Permalink
[ADAM-1196] Add support for open ReferenceRegions.
Browse files Browse the repository at this point in the history
Resolves #1196.
  • Loading branch information
fnothaft authored and heuermh committed Nov 10, 2016
1 parent be94c90 commit 748b952
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,44 @@ object ReferenceRegion {
implicit def orderingForPositions = RegionOrdering
implicit def orderingForOptionalPositions = OptionalRegionOrdering

/**
* Creates a reference region that starts at the beginning of a contig.
*
* @param referenceName The name of the reference contig that this region is
* on.
* @param end The end position for this region.
* @return Returns a reference region that goes from the start of a contig to
* a user provided end point.
*/
def fromStart(referenceName: String,
end: Long): ReferenceRegion = {
ReferenceRegion(referenceName, 0L, end)
}

/**
* Creates a reference region that has an open end point.
*
* @param referenceName The name of the reference contig that this region is
* on.
* @param start The start position for this region.
* @return Returns a reference region that goes from a user provided starting
* point to the end of a contig.
*/
def toEnd(referenceName: String,
start: Long): ReferenceRegion = {
ReferenceRegion(referenceName, start, Long.MaxValue)
}

/**
* Creates a reference region that covers the entirety of a contig.
*
* @param referenceName The name of the reference contig to cover.
* @return Returns a reference region that covers the entirety of a contig.
*/
def all(referenceName: String): ReferenceRegion = {
ReferenceRegion(referenceName, 0L, Long.MaxValue)
}

/**
* Generates a reference region from read data. Returns None if the read is not mapped;
* else, returns the inclusive region from the start to the end of the read alignment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,27 @@ class ReferenceRegionSuite extends FunSuite {
assert(padded.start === 0L)
assert(padded.end === 5L)
}

test("can build an open ended reference region") {
val openEnded = ReferenceRegion.toEnd("myCtg", 45L)

assert(!openEnded.overlaps(ReferenceRegion("myCtg", 44L, 45L)))
assert(openEnded.overlaps(ReferenceRegion("myCtg", 44L, 46L)))
assert(openEnded.overlaps(ReferenceRegion("myCtg", Long.MaxValue - 1L, Long.MaxValue)))
}

test("can build a reference region with an open start position") {
val openStart = ReferenceRegion.fromStart("myCtg", 45L)

assert(openStart.overlaps(ReferenceRegion("myCtg", 0L, 1L)))
assert(openStart.overlaps(ReferenceRegion("myCtg", 44L, 46L)))
assert(!openStart.overlaps(ReferenceRegion("myCtg", 45L, 46L)))
}

test("can build a reference region that covers the entirety of a contig") {
val all = ReferenceRegion.all("myCtg")

assert(all.overlaps(ReferenceRegion("myCtg", 0L, 1L)))
assert(all.overlaps(ReferenceRegion("myCtg", Long.MaxValue - 1L, Long.MaxValue)))
}
}

0 comments on commit 748b952

Please sign in to comment.