+ BitSet tbs = new BitSet();
+ assertEquals("Group start/end didn't select columns to mark", 1,
+ sr.markColumns(s2g, tbs));
+ assertEquals("Group start/end didn't select columns to mark", 1,
+ sr.markColumns(sallg, tbs));
+ assertEquals(
+ "Didn't set expected number of columns in total for two successive marks",
+ 2, tbs.cardinality());
+ }
+
+ /**
+ * Test to verify adding doesn't create duplicate results
+ */
+ @Test(groups = { "Functional" })
+ public void testAddResult()
+ {
+ SequenceI seq1 = new Sequence("", "abcdefghijklm");
+ SearchResultsI sr = new SearchResults();
+ sr.addResult(seq1, 3, 5);
+ assertEquals(1, sr.getCount());
+ sr.addResult(seq1, 3, 5);
+ assertEquals(1, sr.getCount());
+ sr.addResult(seq1, 3, 6);
+ assertEquals(2, sr.getCount());
+ }
+
+ /**
+ * Test for method that checks if search results matches a sequence region
+ */
+ @Test(groups = { "Functional" })
+ public void testInvolvesSequence()
+ {
+ SequenceI dataset = new Sequence("genome", "ATGGCCCTTTAAGCAACATTT");
+ // first 'exon':
+ SequenceI cds1 = new Sequence("cds1/1-12", "ATGGCCCTTTAA");
+ cds1.setDatasetSequence(dataset);
+ // overlapping second 'exon':
+ SequenceI cds2 = new Sequence("cds2/7-18", "CTTTAAGCAACA");
+ cds2.setDatasetSequence(dataset);
+ // unrelated sequence
+ SequenceI cds3 = new Sequence("cds3", "ATGGCCCTTTAAGCAACA");
+
+ SearchResults sr = new SearchResults();
+ assertFalse(sr.involvesSequence(cds1));
+
+ /*
+ * cds1 and cds2 share the same dataset sequence, but
+ * only cds1 overlaps match 4:6 (fixes bug JAL-3613)
+ */
+ sr.addResult(dataset, 4, 6);
+ assertTrue(sr.involvesSequence(cds1));
+ assertFalse(sr.involvesSequence(cds2));
+ assertFalse(sr.involvesSequence(cds3));
+
+ /*
+ * search results overlap cds2 only
+ */
+ sr = new SearchResults();
+ sr.addResult(dataset, 18, 18);
+ assertFalse(sr.involvesSequence(cds1));
+ assertTrue(sr.involvesSequence(cds2));
+
+ /*
+ * add a search result overlapping cds1
+ */
+ sr.addResult(dataset, 1, 1);
+ assertTrue(sr.involvesSequence(cds1));
+ assertTrue(sr.involvesSequence(cds2));
+
+ /*
+ * single search result overlapping both
+ */
+ sr = new SearchResults();
+ sr.addResult(dataset, 10, 12);
+ assertTrue(sr.involvesSequence(cds1));
+ assertTrue(sr.involvesSequence(cds2));
+
+ /*
+ * search results matching aligned sequence
+ */
+ sr = new SearchResults();
+ sr.addResult(cds1, 10, 12);
+ assertTrue(sr.involvesSequence(cds1));
+ assertFalse(sr.involvesSequence(cds2));
+ sr.addResult(cds2, 1, 3); // no start-end overlap
+ assertFalse(sr.involvesSequence(cds2));
+ sr.addResult(cds2, 7, 9); // start-end overlap
+ assertTrue(sr.involvesSequence(cds2));
+ }
+
+ /**
+ * Test extraction of Sequence objects for matched ranges on a sequence
+ */
+ @Test(groups = { "Functional" })
+ public void testGetSequences()
+ {
+ SequenceI seq1 = new Sequence("", "abcdefghijklm");
+ SequenceI seq2 = new Sequence("", "nopqrstuvwxyz");
+ seq2.setStart(23);
+ seq2.setEnd(35);
+ List<SequenceI> seqres = null;
+
+ SearchResultsI sr = new SearchResults();
+ seqres = sr.getMatchingSubSequences();
+ assertEquals(0, seqres.size());
+
+ sr.addResult(seq1, 3, 5);
+ seqres = sr.getMatchingSubSequences();
+
+ assertEquals(1, seqres.size());
+ assertEquals("cde", seqres.get(0).getSequenceAsString());
+ assertEquals(3, seqres.get(0).getStart());
+ assertEquals(seq1, seqres.get(0).getDatasetSequence());
+
+ sr.addResult(seq1, 3, 6);
+ seqres = sr.getMatchingSubSequences();
+
+ assertEquals(2, seqres.size());
+ assertEquals("cdef", seqres.get(1).getSequenceAsString());
+ assertEquals(3, seqres.get(1).getStart());
+
+ // this is a quirk - match on 26-29 yields subsequence 27-30
+ sr.addResult(seq2, 26, 29);
+ seqres = sr.getMatchingSubSequences();
+ assertEquals(3, seqres.size());
+ assertEquals("qrst", seqres.get(2).getSequenceAsString());
+ assertEquals(26, seqres.get(2).getStart());