From c70905eb5589c7622a2c7cf8a008ba0863b5c010 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 8 Jun 2017 16:14:43 +0100 Subject: [PATCH] JAL-2526 correct boundary conditions for sequence left/right of cursor --- src/jalview/datamodel/Sequence.java | 4 ++-- test/jalview/datamodel/SequenceTest.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) 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" }) -- 1.7.10.2