From: gmungoc Date: Thu, 8 Jun 2017 15:14:43 +0000 (+0100) Subject: JAL-2526 correct boundary conditions for sequence left/right of cursor X-Git-Tag: Release_2_10_3b1~205 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c70905eb5589c7622a2c7cf8a008ba0863b5c010;p=jalview.git JAL-2526 correct boundary conditions for sequence left/right of cursor --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 8ea6ca3..a442cf0 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -909,7 +909,7 @@ public class Sequence extends ASequence implements SequenceI return curs.residuePosition; // easy case :-) } - if (curs.lastColumnPosition > 0 && curs.lastColumnPosition <= col) + if (curs.lastColumnPosition > 0 && curs.lastColumnPosition < col) { /* * sequence lies entirely to the left of col @@ -918,7 +918,7 @@ public class Sequence extends ASequence implements SequenceI return end + 1; } - if (curs.firstColumnPosition > 0 && curs.firstColumnPosition >= col) + if (curs.firstColumnPosition > 0 && curs.firstColumnPosition > col) { /* * sequence lies entirely to the right of col diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index e657599..90856e8 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -438,6 +438,24 @@ public class SequenceTest assertEquals(14, sq.findPosition(99)); assertEquals("test:Pos13:Col10:startCol3:endCol10:tok12", PA.getValue(sq, "cursor").toString()); + + /* + * gapped sequence ending in non-gap + */ + sq = new Sequence("test/8-13", "--AB-C-DEF"); + assertEquals(13, sq.findPosition(9)); + assertEquals("test:Pos13:Col10:startCol3:endCol10:tok0", + PA.getValue(sq, "cursor").toString()); + sq.sequenceChanged(); + assertEquals(12, sq.findPosition(8)); + cursor = (SequenceCursor) PA.getValue(sq, "cursor"); + assertEquals("test:Pos12:Col9:startCol3:endCol10:tok1", + cursor.toString()); + // findPosition with cursor accepts base 1 column values + assertEquals(13, ((Sequence) sq).findPosition(10, cursor)); + assertEquals(13, sq.findPosition(9)); + assertEquals("test:Pos13:Col10:startCol3:endCol10:tok1", + PA.getValue(sq, "cursor").toString()); } @Test(groups = { "Functional" })