+
+ /**
+ * Test the method that adds mapped positions to SearchResults
+ */
+ @Test(groups = { "Functional" })
+ public void testMarkMappedRegion()
+ {
+ // introns lower case, exons upper case
+ final Sequence dna1 = new Sequence("Seq1/10-18", "c-G-TA-gC-gT-T");
+ dna1.createDatasetSequence();
+ final Sequence dna2 = new Sequence("Seq2/20-28", "-TA-gG-Gg-CG-a");
+ dna2.createDatasetSequence();
+
+ final Sequence pep1 = new Sequence("Seq1/3-4", "-P-R");
+ pep1.createDatasetSequence();
+ final Sequence pep2 = new Sequence("Seq2/7-9", "-LY-Q");
+ pep2.createDatasetSequence();
+
+ /*
+ * First with no mappings
+ */
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+ SearchResults sr = new SearchResults();
+ acf.markMappedRegion(dna1, 12, sr);
+ assertTrue(sr.isEmpty());
+
+ /*
+ * Set up the mappings for the exons (upper-case bases)
+ * Note residue Q is unmapped
+ */
+ MapList map1 = new MapList(new int[] { 11, 13, 15, 15, 17, 18 }, new int[] {
+ 3, 4 }, 3, 1);
+ acf.addMap(dna1.getDatasetSequence(), pep1.getDatasetSequence(), map1);
+ MapList map2 = new MapList(new int[] { 20, 21, 23, 24, 26, 27 }, new int[] { 7, 8 },
+ 3, 1);
+ acf.addMap(dna2.getDatasetSequence(), pep2.getDatasetSequence(), map2);
+
+ /*
+ * intron bases are not mapped
+ */
+ acf.markMappedRegion(dna1, 10, sr);
+ assertTrue(sr.isEmpty());
+
+ /*
+ * Q is not mapped
+ */
+ acf.markMappedRegion(pep2, 9, sr);
+ assertTrue(sr.isEmpty());
+
+ /*
+ * mark peptide position for exon position (of aligned sequence)
+ */
+ acf.markMappedRegion(dna1, 11, sr);
+ SearchResults expected = new SearchResults();
+ expected.addResult(pep1.getDatasetSequence(), 3, 3);
+ assertEquals(sr, expected);
+
+ /*
+ * mark peptide position for exon position of dataset sequence - same result
+ */
+ sr = new SearchResults();
+ acf.markMappedRegion(dna1.getDatasetSequence(), 11, sr);
+ assertEquals(sr, expected);
+
+ /*
+ * marking the same position a second time should not create a duplicate match
+ */
+ acf.markMappedRegion(dna1.getDatasetSequence(), 12, sr);
+ assertEquals(sr, expected);
+
+ /*
+ * mark exon positions for peptide position (of aligned sequence)
+ */
+ sr = new SearchResults();
+ acf.markMappedRegion(pep2, 7, sr); // codon positions 20, 21, 23
+ expected = new SearchResults();
+ expected.addResult(dna2.getDatasetSequence(), 20, 21);
+ expected.addResult(dna2.getDatasetSequence(), 23, 23);
+ assertEquals(sr, expected);
+
+ /*
+ * add another codon to the same SearchResults
+ */
+ acf.markMappedRegion(pep1.getDatasetSequence(), 4, sr); // codon positions 15, 17, 18
+ expected.addResult(dna1.getDatasetSequence(), 15, 15);
+ expected.addResult(dna1.getDatasetSequence(), 17, 18);
+ assertEquals(sr, expected);
+ }