+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.datamodel;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertSame;
+import static org.testng.AssertJUnit.assertTrue;
import jalview.util.MapList;
/**
* Test the method that locates the first aligned sequence that has a mapping.
*/
- @Test
+ @Test(groups = { "Functional" })
public void testFindAlignedSequence()
{
- AlignmentI cdna = new Alignment(new SequenceI[]
- {});
+ AlignmentI cdna = new Alignment(new SequenceI[] {});
final Sequence seq1 = new Sequence("Seq1", "C-G-TA-GC");
seq1.createDatasetSequence();
cdna.addSequence(seq1);
seq2.createDatasetSequence();
cdna.addSequence(seq2);
- AlignmentI aa = new Alignment(new SequenceI[]
- {});
+ AlignmentI aa = new Alignment(new SequenceI[] {});
final Sequence aseq1 = new Sequence("Seq1", "-P-R");
aseq1.createDatasetSequence();
aa.addSequence(aseq1);
assertNull(acf.findAlignedSequence(seq1, aa));
- MapList map = new MapList(new int[]
- { 1, 6 }, new int[]
- { 1, 2 }, 3, 1);
+ MapList map = new MapList(new int[] { 1, 6 }, new int[] { 1, 2 }, 3, 1);
acf.addMap(seq1.getDatasetSequence(), aseq2.getDatasetSequence(), map);
/*
* DNA seq1 maps to AA seq2
*/
- assertEquals(aa.getSequenceAt(1),
- acf.findAlignedSequence(cdna
+ assertEquals(aa.getSequenceAt(1), acf.findAlignedSequence(cdna
.getSequenceAt(0).getDatasetSequence(), aa));
- assertEquals(cdna.getSequenceAt(0),
- acf.findAlignedSequence(aa
+ assertEquals(cdna.getSequenceAt(0), acf.findAlignedSequence(aa
.getSequenceAt(1).getDatasetSequence(), cdna));
}
/**
* Test the method that locates the mapped codon for a protein position.
*/
- @Test
+ @Test(groups = { "Functional" })
public void testGetMappedRegion()
{
// introns lower case, exons upper case
/*
* Set up the mappings for the exons (upper-case bases)
*/
- MapList map = new MapList(new int[]
- { 2, 4, 6, 6, 8, 9 }, new int[]
- { 1, 2 }, 3, 1);
+ MapList map = new MapList(new int[] { 2, 4, 6, 6, 8, 9 }, new int[] {
+ 1, 2 }, 3, 1);
acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
- map = new MapList(new int[]
- { 1, 2, 4, 5, 7, 8 }, new int[]
- { 1, 2 }, 3, 1);
+ map = new MapList(new int[] { 1, 2, 4, 5, 7, 8 }, new int[] { 1, 2 },
+ 3, 1);
acf.addMap(seq2.getDatasetSequence(), aseq2.getDatasetSequence(), map);
assertEquals("[2, 4]",
assertNull(acf.getMappedRegion(seq1, aseq2, 1));
}
- @Test
+ @Test(groups = { "Functional" })
public void testGetMappedCodon()
{
final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
/*
* Set up the mappings for the exons (upper-case bases)
*/
- MapList map = new MapList(new int[]
- { 2, 4, 6, 6, 8, 9 }, new int[]
- { 1, 2 }, 3, 1);
+ MapList map = new MapList(new int[] { 2, 4, 6, 6, 8, 9 }, new int[] {
+ 1, 2 }, 3, 1);
acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
-
+
assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon(
aseq1.getDatasetSequence(), 1)));
assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon(
aseq1.getDatasetSequence(), 2)));
}
+
+ /**
+ * Test for the case where sequences have start > 1
+ */
+ @Test(groups = { "Functional" })
+ public void testGetMappedCodon_forSubSequences()
+ {
+ final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T", 27, 35);
+ seq1.createDatasetSequence();
+
+ final Sequence aseq1 = new Sequence("Seq1", "-P-R", 12, 13);
+ aseq1.createDatasetSequence();
+
+ /*
+ * Set up the mappings for the exons (upper-case bases)
+ */
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+ MapList map = new MapList(new int[] { 28, 30, 32, 32, 34, 35 },
+ new int[] { 12, 13 }, 3, 1);
+ acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
+
+ assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon(
+ aseq1.getDatasetSequence(), 12)));
+ assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon(
+ aseq1.getDatasetSequence(), 13)));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCouldReplaceSequence()
+ {
+ SequenceI seq1 = new Sequence("Seq1/10-21", "aaacccgggttt");
+ SequenceI seq2 = new Sequence("Seq2", "PG");
+ SequenceI seq1proxy = new SequenceDummy("Seq1");
+
+ // map to region within sequence is ok
+ assertTrue(AlignedCodonFrame.couldReplaceSequence(seq1proxy, seq1, 12,
+ 17));
+ // map to region overlapping sequence is ok
+ assertTrue(AlignedCodonFrame.couldReplaceSequence(seq1proxy, seq1, 5,
+ 10));
+ assertTrue(AlignedCodonFrame.couldReplaceSequence(seq1proxy, seq1, 21,
+ 26));
+ // map to region before sequence is not ok
+ assertFalse(AlignedCodonFrame.couldReplaceSequence(seq1proxy, seq1, 4,
+ 9));
+ // map to region after sequence is not ok
+ assertFalse(AlignedCodonFrame.couldReplaceSequence(seq1proxy, seq1, 22,
+ 27));
+
+ /*
+ * test should fail if name doesn't match
+ */
+ seq1proxy.setName("Seq1a");
+ assertFalse(AlignedCodonFrame.couldReplaceSequence(seq1proxy, seq1, 12,
+ 17));
+ seq1proxy.setName("Seq1");
+ seq1.setName("Seq1a");
+ assertFalse(AlignedCodonFrame.couldReplaceSequence(seq1proxy, seq1, 12,
+ 17));
+ }
+
+ /**
+ * Tests for the method that tests whether any mapping to a dummy sequence can
+ * be 'realised' to a given real sequence
+ */
+ @Test(groups = { "Functional" })
+ public void testIsRealisableWith()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "tttaaaCCCGGGtttaaa");
+ SequenceI seq2 = new Sequence("Seq2", "PG");
+ SequenceI seq1proxy = new SequenceDummy("Seq1");
+ seq1.createDatasetSequence();
+ seq2.createDatasetSequence();
+ MapList mapList = new MapList(new int[] { 7, 12 }, new int[] { 2, 3 },
+ 3, 1);
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+ acf.addMap(seq1proxy, seq2, mapList);
+
+ /*
+ * Seq2 is mapped to SequenceDummy seq1proxy bases 4-9
+ * This is 'realisable' from real sequence Seq1
+ */
+ assertTrue(acf.isRealisableWith(seq1));
+
+ /*
+ * test should fail if name doesn't match
+ */
+ seq1proxy.setName("Seq1a");
+ assertFalse(acf.isRealisableWith(seq1));
+ seq1proxy.setName("Seq1");
+
+ SequenceI seq1ds = seq1.getDatasetSequence();
+ seq1ds.setName("Seq1a");
+ assertFalse(acf.isRealisableWith(seq1));
+ seq1ds.setName("Seq1");
+
+ /*
+ * test should fail if no sequence overlap with mapping of bases 7-12
+ * use artificial start/end values to test this
+ */
+ seq1ds.setStart(1);
+ seq1ds.setEnd(6);
+ // seq1 precedes mapped region:
+ assertFalse(acf.isRealisableWith(seq1));
+ seq1ds.setEnd(7);
+ // seq1 includes first mapped base:
+ assertTrue(acf.isRealisableWith(seq1));
+ seq1ds.setStart(13);
+ seq1ds.setEnd(18);
+ // seq1 follows mapped region:
+ assertFalse(acf.isRealisableWith(seq1));
+ seq1ds.setStart(12);
+ // seq1 includes last mapped base:
+ assertTrue(acf.isRealisableWith(seq1));
+ }
+
+ /**
+ * Tests for the method that converts mappings to a dummy sequence to mappings
+ * to a compatible real sequence
+ */
+ @Test(groups = { "Functional" })
+ public void testRealiseWith()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "tttCAACCCGGGtttaaa");
+ SequenceI seq2 = new Sequence("Seq2", "QPG");
+ SequenceI seq1proxy = new SequenceDummy("Seq1");
+ seq1.createDatasetSequence();
+ seq2.createDatasetSequence();
+
+ /*
+ * Make two mappings from Seq2 peptide to dummy sequence Seq1
+ */
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+
+ // map PG to codons 7-12 (CCCGGG)
+ MapList mapping1 = new MapList(new int[] { 7, 12 }, new int[] { 2, 3 },
+ 3, 1);
+ acf.addMap(seq1proxy, seq2, mapping1);
+
+ // map QP to codons 4-9 (CAACCC)
+ MapList mapping2 = new MapList(new int[] { 4, 9 }, new int[] { 1, 2 },
+ 3, 1);
+ acf.addMap(seq1proxy, seq2, mapping2);
+
+ assertEquals(2, acf.getdnaSeqs().length);
+ assertSame(seq1proxy, acf.getdnaSeqs()[0]);
+ assertSame(seq1proxy, acf.getdnaSeqs()[1]);
+ assertEquals(2, acf.getProtMappings().length);
+
+ // 'realise' these mappings with the compatible sequence seq1
+ // two mappings should be updated:
+ assertEquals(2, acf.realiseWith(seq1));
+ assertSame(seq1.getDatasetSequence(), acf.getdnaSeqs()[0]);
+ assertSame(seq1.getDatasetSequence(), acf.getdnaSeqs()[1]);
+ }
}