+ @Test(groups = "Functional")
+ public void testPropagateInsertions()
+ {
+ // create an alignment with no gaps - this will be the profile seq and other
+ // JPRED seqs
+ AlignmentGenerator gen = new AlignmentGenerator(false);
+ AlignmentI al = gen.generate(25, 10, 1234, 0, 0);
+
+ // get the profileseq
+ SequenceI profileseq = al.getSequenceAt(0);
+ SequenceI gappedseq = new Sequence(profileseq);
+ gappedseq.insertCharAt(5, al.getGapCharacter());
+ gappedseq.insertCharAt(6, al.getGapCharacter());
+ gappedseq.insertCharAt(7, al.getGapCharacter());
+ gappedseq.insertCharAt(8, al.getGapCharacter());
+
+ // create an alignment view with the gapped sequence
+ SequenceI[] seqs = new SequenceI[1];
+ seqs[0] = gappedseq;
+ AlignmentI newal = new Alignment(seqs);
+ HiddenColumns hidden = new HiddenColumns();
+ hidden.hideColumns(15, 17);
+
+ AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
+ false);
+
+ // confirm that original contigs are as expected
+ int[] oldcontigs = hidden.getVisibleContigs(0, 25);
+ int[] testcontigs = { 0, 14, 18, 24 };
+ assertTrue(Arrays.equals(oldcontigs, testcontigs));
+
+ // propagate insertions
+ HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
+ view);
+
+ // confirm that the contigs have changed to account for the gaps
+ int[] newcontigs = result.getVisibleContigs(0, 25);
+ testcontigs[1] = 10;
+ testcontigs[2] = 14;
+ assertTrue(Arrays.equals(newcontigs, testcontigs));
+
+ // confirm the alignment has been changed so that the other sequences have
+ // gaps inserted where the columns are hidden
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[10]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[11]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[12]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[13]));
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[14]));
+
+ }
+
+ @Test(groups = "Functional")
+ public void testPropagateInsertionsOverlap()
+ {
+ // test propagateInsertions where gaps and hiddenColumns overlap
+
+ // create an alignment with no gaps - this will be the profile seq and other
+ // JPRED seqs
+ AlignmentGenerator gen = new AlignmentGenerator(false);
+ AlignmentI al = gen.generate(20, 10, 1234, 0, 0);
+
+ // get the profileseq
+ SequenceI profileseq = al.getSequenceAt(0);
+ SequenceI gappedseq = new Sequence(profileseq);
+ gappedseq.insertCharAt(5, al.getGapCharacter());
+ gappedseq.insertCharAt(6, al.getGapCharacter());
+ gappedseq.insertCharAt(7, al.getGapCharacter());
+ gappedseq.insertCharAt(8, al.getGapCharacter());
+
+ // create an alignment view with the gapped sequence
+ SequenceI[] seqs = new SequenceI[1];
+ seqs[0] = gappedseq;
+ AlignmentI newal = new Alignment(seqs);
+
+ // hide columns so that some overlap with the gaps
+ HiddenColumns hidden = new HiddenColumns();
+ hidden.hideColumns(7, 10);
+
+ AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
+ false);
+
+ // confirm that original contigs are as expected
+ int[] oldcontigs = hidden.getVisibleContigs(0, 20);
+ int[] testcontigs = { 0, 6, 11, 19 };
+ assertTrue(Arrays.equals(oldcontigs, testcontigs));
+
+ // propagate insertions
+ HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
+ view);
+
+ // confirm that the contigs have changed to account for the gaps
+ int[] newcontigs = result.getVisibleContigs(0, 20);
+ testcontigs[1] = 4;
+ testcontigs[2] = 7;
+ assertTrue(Arrays.equals(newcontigs, testcontigs));
+
+ // confirm the alignment has been changed so that the other sequences have
+ // gaps inserted where the columns are hidden
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[4]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[5]));
+ assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[6]));
+ assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[7]));
+ }
+
+ @Test(groups = "Functional")
+ public void testHasHiddenColumns()
+ {
+ HiddenColumns h = new HiddenColumns();
+
+ // new HiddenColumns2 has no hidden cols
+ assertFalse(h.hasHiddenColumns());
+
+ // some columns hidden, returns true
+ h.hideColumns(5, 10);
+ assertTrue(h.hasHiddenColumns());
+
+ // reveal columns, no hidden cols again
+ ColumnSelection sel = new ColumnSelection();
+ h.revealAllHiddenColumns(sel);
+ assertFalse(h.hasHiddenColumns());
+ }
+
+ @Test(groups = "Functional")
+ public void testHasManyHiddenColumns()
+ {
+ HiddenColumns h = new HiddenColumns();
+
+ // new HiddenColumns2 has no hidden cols
+ assertFalse(h.hasManyHiddenColumns());
+
+ // one set of columns hidden, returns false
+ h.hideColumns(5, 10);
+ assertFalse(h.hasManyHiddenColumns());
+
+ // two sets hidden, returns true
+ h.hideColumns(15, 17);
+ assertTrue(h.hasManyHiddenColumns());
+
+ // back to one block, asserts false
+ h.hideColumns(11, 14);
+ assertFalse(h.hasManyHiddenColumns());
+ }
+
+ @Test(groups = "Functional")
+ public void testAdjustForHiddenColumns()
+ {
+ HiddenColumns h = new HiddenColumns();
+ // returns input value when there are no hidden columns
+ assertEquals(10, h.adjustForHiddenColumns(10));
+
+ h.hideColumns(20, 30);
+ assertEquals(10, h.adjustForHiddenColumns(10));
+ assertEquals(20 + 11, h.adjustForHiddenColumns(20));
+ assertEquals(35 + 11, h.adjustForHiddenColumns(35));
+
+ h.hideColumns(5, 7);
+ assertEquals(10 + 3, h.adjustForHiddenColumns(10));
+ assertEquals(20 + 14, h.adjustForHiddenColumns(20));
+ assertEquals(35 + 14, h.adjustForHiddenColumns(35));
+
+ ColumnSelection sel = new ColumnSelection();
+ h.revealAllHiddenColumns(sel);
+ h.hideColumns(0, 1);
+ assertEquals(4, h.adjustForHiddenColumns(2));
+ }
+
+ @Test(groups = "Functional")
+ public void testGetHiddenBoundaryLeft()
+ {
+ HiddenColumns h = new HiddenColumns();
+
+ // returns same value if no hidden cols
+ assertEquals(3, h.getHiddenBoundaryLeft(3));
+
+ h.hideColumns(5, 10);
+ assertEquals(10, h.getHiddenBoundaryLeft(15));
+ assertEquals(3, h.getHiddenBoundaryLeft(3));
+ assertEquals(7, h.getHiddenBoundaryLeft(7));
+
+ h.hideColumns(15, 20);
+ assertEquals(10, h.getHiddenBoundaryLeft(15));
+ assertEquals(20, h.getHiddenBoundaryLeft(21));
+ }
+
+ @Test(groups = "Functional")
+ public void testGetHiddenBoundaryRight()
+ {
+ HiddenColumns h = new HiddenColumns();
+
+ // returns same value if no hidden cols
+ assertEquals(3, h.getHiddenBoundaryRight(3));
+
+ h.hideColumns(5, 10);
+ assertEquals(5, h.getHiddenBoundaryRight(3));
+ assertEquals(15, h.getHiddenBoundaryRight(15));
+ assertEquals(7, h.getHiddenBoundaryRight(7));
+
+ h.hideColumns(15, 20);
+ assertEquals(15, h.getHiddenBoundaryRight(7));
+ assertEquals(15, h.getHiddenBoundaryRight(14));
+ }
+
+ @Test(groups = "Functional")
+ public void testGetHiddenColumnsCopy()
+ {
+ HiddenColumns h = new HiddenColumns();
+ ArrayList<int[]> result = h.getHiddenColumnsCopy();
+ assertTrue(result.isEmpty());
+
+ h.hideColumns(5, 10);
+ result = h.getHiddenColumnsCopy();
+ assertEquals(1, result.size());
+ assertEquals(5, result.get(0)[0]);
+ assertEquals(10, result.get(0)[1]);
+
+ h.hideColumns(22, 23);
+ result = h.getHiddenColumnsCopy();
+ assertEquals(2, result.size());
+ assertEquals(5, result.get(0)[0]);
+ assertEquals(10, result.get(0)[1]);
+ assertEquals(22, result.get(1)[0]);
+ assertEquals(23, result.get(1)[1]);
+
+ // test for only one hidden region at start of alignment
+ ColumnSelection sel = new ColumnSelection();
+ h.revealAllHiddenColumns(sel);
+ h.hideColumns(0, 1);
+ result = h.getHiddenColumnsCopy();
+ assertEquals(1, result.size());
+ assertEquals(0, result.get(0)[0]);
+ assertEquals(1, result.get(0)[1]);
+ }
+
+ @Test(groups = "Functional")
+ public void testGetVisibleSequenceStrings()
+ {
+ HiddenColumns h = new HiddenColumns();
+ SequenceI seq1 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
+ SequenceI seq2 = new Sequence("TEST2", "VICYHRNDTGA");
+ SequenceI[] seqs = new SequenceI[2];
+ seqs[0] = seq1;
+ seqs[1] = seq2;
+ String[] result = h.getVisibleSequenceStrings(5, 10, seqs);
+ assertEquals(2, result.length);
+ assertEquals("WKQES", result[0]);
+ assertEquals("RNDTG", result[1]);
+
+ h.hideColumns(6, 8);
+ result = h.getVisibleSequenceStrings(5, 10, seqs);
+ assertEquals(2, result.length);
+ assertEquals("WS", result[0]);
+ assertEquals("RG", result[1]);
+
+ SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
+ ColumnSelection sel = new ColumnSelection();
+ h.revealAllHiddenColumns(sel);
+ h.hideColumns(1, 3);
+ h.hideColumns(6, 11);
+ assertEquals("-D",
+ h.getVisibleSequenceStrings(0, 5, new SequenceI[]
+ { seq })[0]);
+ }
+
+ @Test(groups = "Functional")
+ public void testHideInsertionsFor()
+ {
+ HiddenColumns h = new HiddenColumns();
+ HiddenColumns h2 = new HiddenColumns();
+ SequenceI seq1 = new Sequence("TEST1", "GAL---MFW-KQESPVICY--HRNDT");
+ SequenceI seq2 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
+
+ h.hideInsertionsFor(seq2);
+ assertTrue(h.equals(h2));
+
+ h.hideInsertionsFor(seq1);
+ h2.hideColumns(3, 5);
+ h2.hideColumns(9, 9);
+ h2.hideColumns(19, 20);
+ assertTrue(h.equals(h2));
+ }
+
+ @Test(groups = "Functional")
+ public void testHideMarkedBits()
+ {
+ HiddenColumns h = new HiddenColumns();
+ HiddenColumns h2 = new HiddenColumns();
+
+ BitSet tohide = new BitSet(21);
+ h.hideMarkedBits(tohide);
+ assertTrue(h.equals(h2));
+
+ // NB in hideMarkedBits, the last bit is not set to hidden
+ tohide.set(3, 6);
+ tohide.set(9);
+ tohide.set(19, 21);
+ h.hideMarkedBits(tohide);
+
+ h2.hideColumns(3, 5);
+ h2.hideColumns(9, 9);
+ h2.hideColumns(19, 20);
+ assertTrue(h.equals(h2));
+ }
+
+ @Test(groups = "Functional")
+ public void testMakeVisibleAnnotation()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Annotation[] anns = new Annotation[] { null, null, new Annotation(1),
+ new Annotation(2), new Annotation(3), null, null, new Annotation(4),
+ new Annotation(5), new Annotation(6), new Annotation(7),
+ new Annotation(8) };
+ AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an",
+ anns);
+
+ // without hidden cols, just truncates
+ h.makeVisibleAnnotation(3, 5, ann);
+ assertEquals(3, ann.annotations.length);
+ assertEquals(2.0f, ann.annotations[0].value);
+ assertEquals(3.0f, ann.annotations[1].value);
+ assertNull(ann.annotations[2]);
+
+ anns = new Annotation[] { null, null, new Annotation(1),
+ new Annotation(2), new Annotation(3), null, null, new Annotation(4),
+ new Annotation(5), new Annotation(6), new Annotation(7),
+ new Annotation(8) };
+ ann = new AlignmentAnnotation("an", "some an", anns);
+ h.hideColumns(4, 7);
+ h.makeVisibleAnnotation(1, 9, ann);
+ assertEquals(5, ann.annotations.length);
+ assertNull(ann.annotations[0]);
+ assertEquals(1.0f, ann.annotations[1].value);
+ assertEquals(2.0f, ann.annotations[2].value);
+ assertEquals(5.0f, ann.annotations[3].value);
+ assertEquals(6.0f, ann.annotations[4].value);
+
+ anns = new Annotation[] { null, null, new Annotation(1),
+ new Annotation(2), new Annotation(3), null, null, new Annotation(4),
+ new Annotation(5), new Annotation(6), new Annotation(7),
+ new Annotation(8) };
+ ann = new AlignmentAnnotation("an", "some an", anns);
+ h.hideColumns(1, 2);
+ h.makeVisibleAnnotation(1, 9, ann);
+ assertEquals(3, ann.annotations.length);
+ assertEquals(2.0f, ann.annotations[0].value);
+ assertEquals(5.0f, ann.annotations[1].value);
+ assertEquals(6.0f, ann.annotations[2].value);
+ }
+
+ @Test(groups = "Functional")
+ public void testSubtractVisibleColumns()
+ {
+ HiddenColumns h = new HiddenColumns();
+ int result = h.subtractVisibleColumns(1, 10);
+ assertEquals(9, result);
+
+ h.hideColumns(7, 9);
+ result = h.subtractVisibleColumns(4, 10);
+ assertEquals(3, result);
+
+ h.hideColumns(14, 15);
+ result = h.subtractVisibleColumns(4, 10);
+ assertEquals(3, result);
+
+ result = h.subtractVisibleColumns(10, 17);
+ assertEquals(2, result);
+
+ result = h.subtractVisibleColumns(1, 7);
+ assertEquals(5, result);
+
+ result = h.subtractVisibleColumns(1, 8);
+ assertEquals(5, result);
+
+ result = h.subtractVisibleColumns(3, 15);
+ assertEquals(10, result);
+
+ ColumnSelection sel = new ColumnSelection();
+ h.revealAllHiddenColumns(sel);
+ h.hideColumns(0, 30);
+ result = h.subtractVisibleColumns(31, 0);
+ assertEquals(-31, result);
+ }
+
+ @Test(groups = "Functional")
+ public void testBoundedIterator()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Iterator<int[]> it = h.getBoundedIterator(0, 10, false);
+
+ // no hidden columns = nothing to iterate over
+ assertFalse(it.hasNext());
+
+ // [start,end] contains all hidden columns
+ // all regions are returned
+ h.hideColumns(3, 10);
+ h.hideColumns(14, 16);
+ it = h.getBoundedIterator(0, 20, false);
+ assertTrue(it.hasNext());
+ int[] next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ next = it.next();
+ assertEquals(14, next[0]);
+ assertEquals(16, next[1]);
+ assertFalse(it.hasNext());
+
+ // [start,end] overlaps a region
+ // 1 region returned
+ it = h.getBoundedIterator(5, 7, false);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ assertFalse(it.hasNext());
+
+ // [start,end] fully contains 1 region and start of last
+ // - 2 regions returned
+ it = h.getBoundedIterator(3, 15, false);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ next = it.next();
+ assertEquals(14, next[0]);
+ assertEquals(16, next[1]);
+ assertFalse(it.hasNext());
+
+ // [start,end] contains end of first region and whole of last region
+ // - 2 regions returned
+ it = h.getBoundedIterator(4, 20, false);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next[0]);
+ assertEquals(10, next[1]);
+ next = it.next();
+ assertEquals(14, next[0]);
+ assertEquals(16, next[1]);
+ assertFalse(it.hasNext());
+ }
+
+ @Test(groups = "Functional")
+ public void testBoundedStartIterator()
+ {
+ HiddenColumns h = new HiddenColumns();
+ Iterator<Integer> it = h.getBoundedStartIterator(0, 10, false);
+
+ // no hidden columns = nothing to iterate over
+ assertFalse(it.hasNext());
+
+ // [start,end] contains all hidden columns
+ // all regions are returned
+ h.hideColumns(3, 10);
+ h.hideColumns(14, 16);
+ it = h.getBoundedStartIterator(0, 20, false);
+ assertTrue(it.hasNext());
+ int next = it.next();
+ assertEquals(3, next);
+ next = it.next();
+ assertEquals(6, next);
+ assertFalse(it.hasNext());
+
+ // [start,end] does not contain a start of a region
+ // no regions to iterate over
+ it = h.getBoundedStartIterator(4, 5, false);
+ assertFalse(it.hasNext());
+
+ // [start,end] fully contains 1 region and start of last
+ // - 2 regions returned
+ it = h.getBoundedStartIterator(3, 7, false);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(3, next);
+ next = it.next();
+ assertEquals(6, next);
+ assertFalse(it.hasNext());
+
+ // [start,end] contains whole of last region
+ // - 1 region returned
+ it = h.getBoundedStartIterator(4, 20, false);
+ assertTrue(it.hasNext());
+ next = it.next();
+ assertEquals(6, next);
+ assertFalse(it.hasNext());
+ }