+
+ @Test(groups = { "Functional" })
+ public void testSetName()
+ {
+ SequenceI sq = new Sequence("test", "-ABC---DE-F--");
+ assertEquals("test", sq.getName());
+ assertEquals(1, sq.getStart());
+ assertEquals(6, sq.getEnd());
+
+ sq.setName("testing");
+ assertEquals("testing", sq.getName());
+
+ sq.setName("test/8-10");
+ assertEquals("test", sq.getName());
+ assertEquals(8, sq.getStart());
+ assertEquals(13, sq.getEnd()); // note end is recomputed
+
+ sq.setName("testing/7-99");
+ assertEquals("testing", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd()); // end may be beyond physical end
+
+ sq.setName("/2-3");
+ assertEquals("", sq.getName());
+ assertEquals(2, sq.getStart());
+ assertEquals(7, sq.getEnd());
+
+ sq.setName("test/"); // invalid
+ assertEquals("test/", sq.getName());
+ assertEquals(2, sq.getStart());
+ assertEquals(7, sq.getEnd());
+
+ sq.setName("test/6-13/7-99");
+ assertEquals("test/6-13", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName("test/0-5"); // 0 is invalid - ignored
+ assertEquals("test/0-5", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName("test/a-5"); // a is invalid - ignored
+ assertEquals("test/a-5", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName("test/6-5"); // start > end is invalid - ignored
+ assertEquals("test/6-5", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName("test/5"); // invalid - ignored
+ assertEquals("test/5", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName("test/-5"); // invalid - ignored
+ assertEquals("test/-5", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName("test/5-"); // invalid - ignored
+ assertEquals("test/5-", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName("test/5-6-7"); // invalid - ignored
+ assertEquals("test/5-6-7", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+
+ sq.setName(null); // invalid, gets converted to space
+ assertEquals("", sq.getName());
+ assertEquals(7, sq.getStart());
+ assertEquals(99, sq.getEnd());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCheckValidRange()
+ {
+ Sequence sq = new Sequence("test/7-12", "-ABC---DE-F--");
+ assertEquals(7, sq.getStart());
+ assertEquals(12, sq.getEnd());
+
+ /*
+ * checkValidRange ensures end is at least the last residue position
+ */
+ PA.setValue(sq, "end", 2);
+ sq.checkValidRange();
+ assertEquals(12, sq.getEnd());
+
+ /*
+ * end may be beyond the last residue position
+ */
+ PA.setValue(sq, "end", 22);
+ sq.checkValidRange();
+ assertEquals(22, sq.getEnd());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testDeleteChars_withGaps()
+ {
+ /*
+ * delete gaps only
+ */
+ SequenceI sq = new Sequence("test/8-10", "A-B-C");
+ sq.createDatasetSequence();
+ assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
+ sq.deleteChars(1, 2); // delete first gap
+ assertEquals("AB-C", sq.getSequenceAsString());
+ assertEquals(8, sq.getStart());
+ assertEquals(10, sq.getEnd());
+ assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
+
+ /*
+ * delete gaps and residues at start (no new dataset sequence)
+ */
+ sq = new Sequence("test/8-10", "A-B-C");
+ sq.createDatasetSequence();
+ sq.deleteChars(0, 3); // delete A-B
+ assertEquals("-C", sq.getSequenceAsString());
+ assertEquals(10, sq.getStart());
+ assertEquals(10, sq.getEnd());
+ assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
+
+ /*
+ * delete gaps and residues at end (no new dataset sequence)
+ */
+ sq = new Sequence("test/8-10", "A-B-C");
+ sq.createDatasetSequence();
+ sq.deleteChars(2, 5); // delete B-C
+ assertEquals("A-", sq.getSequenceAsString());
+ assertEquals(8, sq.getStart());
+ assertEquals(8, sq.getEnd());
+ assertEquals("ABC", sq.getDatasetSequence().getSequenceAsString());
+
+ /*
+ * delete gaps and residues internally (new dataset sequence)
+ * first delete from gap to residue
+ */
+ sq = new Sequence("test/8-10", "A-B-C");
+ sq.createDatasetSequence();
+ sq.deleteChars(1, 3); // delete -B
+ assertEquals("A-C", sq.getSequenceAsString());
+ assertEquals(8, sq.getStart());
+ assertEquals(9, sq.getEnd());
+ assertEquals("AC", sq.getDatasetSequence().getSequenceAsString());
+ assertEquals(8, sq.getDatasetSequence().getStart());
+ assertEquals(9, sq.getDatasetSequence().getEnd());
+
+ /*
+ * internal delete from gap to gap
+ */
+ sq = new Sequence("test/8-10", "A-B-C");
+ sq.createDatasetSequence();
+ sq.deleteChars(1, 4); // delete -B-
+ assertEquals("AC", sq.getSequenceAsString());
+ assertEquals(8, sq.getStart());
+ assertEquals(9, sq.getEnd());
+ assertEquals("AC", sq.getDatasetSequence().getSequenceAsString());
+ assertEquals(8, sq.getDatasetSequence().getStart());
+ assertEquals(9, sq.getDatasetSequence().getEnd());
+
+ /*
+ * internal delete from residue to residue
+ */
+ sq = new Sequence("test/8-10", "A-B-C");
+ sq.createDatasetSequence();
+ sq.deleteChars(2, 3); // delete B
+ assertEquals("A--C", sq.getSequenceAsString());
+ assertEquals(8, sq.getStart());
+ assertEquals(9, sq.getEnd());
+ assertEquals("AC", sq.getDatasetSequence().getSequenceAsString());
+ assertEquals(8, sq.getDatasetSequence().getStart());
+ assertEquals(9, sq.getDatasetSequence().getEnd());
+ }
+
+ /**
+ * Test the code used to locate the reference sequence ruler origin
+ */
+ @Test(groups = { "Functional" })
+ public void testLocateVisibleStartofSequence()
+ {
+ // create random alignment
+ AlignmentGenerator gen = new AlignmentGenerator(false);
+ AlignmentI al = gen.generate(50, 20, 123, 5, 5);
+
+ HiddenColumns cs = al.getHiddenColumns();
+ ColumnSelection colsel = new ColumnSelection();
+
+ SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
+ assertEquals(2, seq.findIndex(seq.getStart()));
+
+ // no hidden columns
+ assertEquals(seq.findIndex(seq.getStart()) - 1,
+ seq.firstResidueOutsideIterator(cs.iterator()));
+
+ // hidden column on gap after end of sequence - should not affect bounds
+ colsel.hideSelectedColumns(13, al.getHiddenColumns());
+ assertEquals(seq.findIndex(seq.getStart()) - 1,
+ seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ // hidden column on gap before beginning of sequence - should vis bounds by
+ // one
+ colsel.hideSelectedColumns(0, al.getHiddenColumns());
+ assertEquals(seq.findIndex(seq.getStart()) - 2,
+ cs.absoluteToVisibleColumn(
+ seq.firstResidueOutsideIterator(cs.iterator())));
+
+ cs.revealAllHiddenColumns(colsel);
+ // hide columns around most of sequence - leave one residue remaining
+ cs.hideColumns(1, 3);
+ cs.hideColumns(6, 11);
+
+ Iterator<int[]> it = cs.getVisContigsIterator(0, 6, false);
+
+ assertEquals("-D", seq.getSequenceStringFromIterator(it));
+ // cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
+ // { seq })[0]);
+
+ assertEquals(4, seq.firstResidueOutsideIterator(cs.iterator()));
+ cs.revealAllHiddenColumns(colsel);
+
+ // hide whole sequence - should just get location of hidden region
+ // containing sequence
+ cs.hideColumns(1, 11);
+ assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 15);
+ assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ SequenceI seq2 = new Sequence("RefSeq2", "-------A-SD-ASD--E---");
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(7, 17);
+ assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(3, 17);
+ assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(3, 19);
+ assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 0);
+ assertEquals(1, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 1);
+ assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 2);
+ assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(1, 1);
+ assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(1, 2);
+ assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(1, 3);
+ assertEquals(4, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 2);
+ cs.hideColumns(5, 6);
+ assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 2);
+ cs.hideColumns(5, 6);
+ cs.hideColumns(9, 10);
+ assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 2);
+ cs.hideColumns(7, 11);
+ assertEquals(3, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(2, 4);
+ cs.hideColumns(7, 11);
+ assertEquals(1, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(2, 4);
+ cs.hideColumns(7, 12);
+ assertEquals(1, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(1, 11);
+ assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 12);
+ assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 4);
+ cs.hideColumns(6, 12);
+ assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 1);
+ cs.hideColumns(3, 12);
+ assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(3, 14);
+ cs.hideColumns(17, 19);
+ assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(3, 7);
+ cs.hideColumns(9, 14);
+ cs.hideColumns(17, 19);
+ assertEquals(0, seq2.firstResidueOutsideIterator(cs.iterator()));
+
+ cs.revealAllHiddenColumns(colsel);
+ cs.hideColumns(0, 1);
+ cs.hideColumns(3, 4);
+ cs.hideColumns(6, 8);
+ cs.hideColumns(10, 12);
+ assertEquals(0, seq.firstResidueOutsideIterator(cs.iterator()));
+
+ }
+
+ @Test(groups = { "Functional" })
+ public void testTransferAnnotation()
+ {
+ Sequence origSeq = new Sequence("MYSEQ", "THISISASEQ");
+ Sequence toSeq = new Sequence("MYSEQ", "THISISASEQ");
+ origSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q12345", null, true));
+ toSeq.transferAnnotation(origSeq, null);
+ assertTrue(toSeq.getDBRefs().size() == 1);
+
+ assertTrue(toSeq.getDBRefs().get(0).isCanonical());
+
+ // check for promotion of non-canonical
+ // to canonical (e.g. fetch-db-refs on a jalview project pre 2.11.2)
+ toSeq.setDBRefs(null);
+ toSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q12345", null, false));
+ toSeq.transferAnnotation(origSeq, null);
+ assertTrue(toSeq.getDBRefs().size() == 1);
+
+ assertTrue("Promotion of non-canonical DBRefEntry failed",
+ toSeq.getDBRefs().get(0).isCanonical());
+
+ }