From: kiramt Date: Fri, 10 Mar 2017 16:11:58 +0000 (+0000) Subject: JAL-2437 Fixed reordering of sequences when hiding and revealing X-Git-Tag: Release_2_10_2~3^2~92^2~43 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f3f90b8d541ef383d4f1d4cb3c1947200d6983ed;p=jalview.git JAL-2437 Fixed reordering of sequences when hiding and revealing --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 33f30cf..db6195a 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -335,24 +335,12 @@ public class Alignment implements AlignmentI } } - /** - * DOCUMENT ME! - * - * @param s - * DOCUMENT ME! - */ @Override public void deleteSequence(SequenceI s) { deleteSequence(findIndex(s)); } - /** - * DOCUMENT ME! - * - * @param i - * DOCUMENT ME! - */ @Override public void deleteSequence(int i) { @@ -366,6 +354,18 @@ public class Alignment implements AlignmentI } } + @Override + public void deleteHiddenSequence(int i) + { + if (i > -1 && i < getHeight()) + { + synchronized (sequences) + { + sequences.remove(i); + } + } + } + /* * (non-Javadoc) * diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 1ecff9a..2abb1f8 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -147,7 +147,9 @@ public interface AlignmentI extends AnnotatedCollectionI SequenceI replaceSequenceAt(int i, SequenceI seq); /** - * Deletes a sequence from the alignment + * Deletes a sequence from the alignment. Updates hidden sequences to account + * for the removed sequence. Do NOT use this method to delete sequences which + * are just hidden. * * @param s * Sequence to be deleted. @@ -155,7 +157,9 @@ public interface AlignmentI extends AnnotatedCollectionI void deleteSequence(SequenceI s); /** - * Deletes a sequence from the alignment. + * Deletes a sequence from the alignment. Updates hidden sequences to account + * for the removed sequence. Do NOT use this method to delete sequences which + * are just hidden. * * @param i * Index of sequence to be deleted. @@ -163,6 +167,14 @@ public interface AlignmentI extends AnnotatedCollectionI void deleteSequence(int i); /** + * Deletes a sequence in the alignment which has been hidden. + * + * @param i + * Index of sequence to be deleted + */ + void deleteHiddenSequence(int i); + + /** * Finds sequence in alignment using sequence name as query. * * @param name @@ -574,4 +586,5 @@ public interface AlignmentI extends AnnotatedCollectionI * @return */ public int[] getVisibleStartAndEndIndex(List hiddenCols); + } diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index 588e5ed..aca0be6 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -154,8 +154,8 @@ public class HiddenSequences hiddenSequences = new SequenceI[alignment.getHeight()]; } - int alignmentIndex = alignment.findIndex(sequence); - alignmentIndex = adjustForHiddenSeqs(alignmentIndex); + int absAlignmentIndex = alignment.findIndex(sequence); + int alignmentIndex = adjustForHiddenSeqs(absAlignmentIndex); if (hiddenSequences[alignmentIndex] != null) { @@ -164,7 +164,7 @@ public class HiddenSequences hiddenSequences[alignmentIndex] = sequence; - alignment.deleteSequence(sequence); + alignment.deleteHiddenSequence(absAlignmentIndex); } public List showAll( diff --git a/test/jalview/datamodel/HiddenSequencesTest.java b/test/jalview/datamodel/HiddenSequencesTest.java index cae3536..b41b98f 100644 --- a/test/jalview/datamodel/HiddenSequencesTest.java +++ b/test/jalview/datamodel/HiddenSequencesTest.java @@ -326,6 +326,53 @@ public class HiddenSequencesTest assertEquals(10, al.getHeight()); } + /** + * Test the method that adds a sequence to the hidden sequences and deletes it + * from the alignment, and its converse, where the first hidden sequences are + * at the bottom of the alignment (JAL-2437) + */ + @Test(groups = "Functional") + public void testHideShowLastSequences() + { + AlignmentI al = new Alignment(seqs); + assertTrue(al.getSequences().contains(seqs[1])); + HiddenSequences hs = al.getHiddenSequences(); + assertEquals(0, hs.getSize()); + assertEquals(10, al.getHeight()); + + /* + * hide the last sequence in the alignment + */ + hs.hideSequence(seqs[9]); + assertFalse(hs.isHidden(seqs[8])); + assertTrue(hs.isHidden(seqs[9])); + assertFalse(al.getSequences().contains(seqs[9])); + assertEquals(1, hs.getSize()); + assertEquals(9, al.getHeight()); + + /* + * hide the third last sequence in the alignment + */ + hs.hideSequence(seqs[7]); + assertFalse(hs.isHidden(seqs[8])); + assertTrue(hs.isHidden(seqs[7])); + assertFalse(al.getSequences().contains(seqs[7])); + assertEquals(2, hs.getSize()); + assertEquals(8, al.getHeight()); + + /* + * reveal all the sequences, which should be reinstated in the same order as they started in + */ + hs.showAll(null); + assertFalse(hs.isHidden(seqs[7])); + assertFalse(hs.isHidden(seqs[9])); + assertEquals(seqs[7], al.getSequences().get(7)); + assertEquals(seqs[8], al.getSequences().get(8)); + assertEquals(seqs[9], al.getSequences().get(9)); + assertEquals(0, hs.getSize()); + assertEquals(10, al.getHeight()); + } + @Test(groups = "Functional") public void testIsHidden() {