Skip to content

Commit

Permalink
Small fix to how leading insertions are handled during subsetting of …
Browse files Browse the repository at this point in the history
…alignments.
  • Loading branch information
tfenne committed Oct 5, 2017
1 parent faa16a8 commit 0739241
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ case class Alignment(query: Array[Byte],
// If the current element consumes the chosen sequence, calculate the end, else set to the same as start

val elementConsumes = consumes(elem)
val currEnd = if (elementConsumes) currStart + elem.length - 1 else currStart
val currEnd = if (elementConsumes) currStart + elem.length - 1 else currStart-1

if (currEnd < start) {
// Element before the desired window, need to bump start positions
Expand Down
12 changes: 11 additions & 1 deletion src/test/scala/com/fulcrumgenomics/alignment/AlignmentTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class AlignmentTest extends UnitSpec {
it should "drop insertions and deletions that are adjacent to the desired region" in {
val sub = Alignment("AACCAAAAAAAA", "AAAAAAAATTAA", 1, 1, Cigar("2=2I6=2D2="), 10).subByTarget(3, 8)
sub.targetStart shouldBe 3
sub.queryStart shouldBe 3
sub.queryStart shouldBe 5
sub.cigar.toString() shouldBe "6="
}

Expand All @@ -221,6 +221,16 @@ class AlignmentTest extends UnitSpec {
an[Exception] shouldBe thrownBy { Alignment("AAAAA", "TAAAT", 2, 2, Cigar("3="), 0).subByTarget(2, 5) }
}

it should "handle a real world test case" in {
val query = "GGCCAGAGTCCACAGATTAACCAGGGGATATGCTAGAAA"
val target = "CAGAGGCCACAGATTAACCAGGGGATATGCTAGAAA"
val ali = Alignment(query, target, 1, 1, Cigar("3I5=1X30="), 0)
val sub = ali.subByTarget(1, 20)
sub.queryStart shouldBe 4
sub.targetStart shouldBe 1
sub.cigar.toString shouldBe "5=1X14="
}

"Alignment.subByQuery" should "yield appropriate sub-alignment when all bases are aligned" in {
val sub = Alignment("AAAAAAAAAA", "AAAAAAAAAA", 1, 1, Cigar("10M"), 10).subByQuery(5, 6)
sub.targetStart shouldBe 5
Expand Down

0 comments on commit 0739241

Please sign in to comment.