From d716c9b072f989bef39c6eba038f779ce98396a8 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 11 May 2018 12:19:52 +0100 Subject: [PATCH] JAL-2986 corrected findIndex for out of range residue value --- src/jalview/datamodel/Sequence.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 59c3fb1..33de452 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -445,7 +445,7 @@ public class Sequence extends ASequence implements SequenceI @Override public Vector getAllPDBEntries() { - return pdbIds == null ? new Vector() : pdbIds; + return pdbIds == null ? new Vector<>() : pdbIds; } /** @@ -815,7 +815,7 @@ public class Sequence extends ASequence implements SequenceI * @param curs * @return */ - protected int findIndex(int pos, SequenceCursor curs) + protected int findIndex(final int pos, SequenceCursor curs) { if (!isValidCursor(curs)) { @@ -841,10 +841,15 @@ public class Sequence extends ASequence implements SequenceI while (newPos != pos) { col += delta; // shift one column left or right - if (col < 0 || col == sequence.length) + if (col < 0) { break; } + if (col == sequence.length) + { + col--; // return last column if we failed to reach pos + break; + } if (!Comparison.isGap(sequence[col])) { newPos += delta; @@ -852,7 +857,14 @@ public class Sequence extends ASequence implements SequenceI } col++; // convert back to base 1 - updateCursor(pos, col, curs.firstColumnPosition); + + /* + * only update cursor if we found the target position + */ + if (newPos == pos) + { + updateCursor(pos, col, curs.firstColumnPosition); + } return col; } -- 1.7.10.2