From ca38821c63596c7f3ed2ff379e4430cc43d88484 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 3 Dec 2015 16:27:57 +0000 Subject: [PATCH] JAL-653 code tidy / tests for 'realise gff mappings' --- src/jalview/gui/AlignViewport.java | 20 ++----- test/jalview/datamodel/AlignedCodonFrameTest.java | 63 ++++++++++++++++++--- test/jalview/io/ExonerateGffTest.java | 30 +++++++--- 3 files changed, 82 insertions(+), 31 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 5944b80..9ee88db 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -863,17 +863,6 @@ public class AlignViewport extends AlignmentViewport implements */ if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) { - // if (toAdd.getDataset() == null) - // { - // // need to create ds seqs - // for (SequenceI sq : toAdd.getSequences()) - // { - // if (sq.getDatasetSequence() == null) - // { - // sq.createDatasetSequence(); - // } - // } - // } if (AlignmentUtils.isMappable(toAdd, getAlignment())) { if (openLinkedAlignment(toAdd, title)) @@ -919,9 +908,9 @@ public class AlignViewport extends AlignmentViewport implements } /** - * If the alignment holds any mappings to a dummy (placeholder) sequence that - * matches the given sequence, then update the mapping to point to the - * sequence. Returns the number of mappings updated. + * If the alignment holds any mappings to a virtual (placeholder) sequence + * that matches all or part of the given sequence, then update the mapping to + * point to the sequence. Returns the number of mappings updated. * * @param al * @param seq @@ -930,8 +919,7 @@ public class AlignViewport extends AlignmentViewport implements protected int realiseMappingsTo(AlignmentI al, SequenceI seq) { int count = 0; - Set mappings = al.getDataset().getCodonFrames(); - // TODO are mappings on alignment or alignment dataset?!? + Set mappings = al.getCodonFrames(); for (AlignedCodonFrame mapping : mappings) { /* diff --git a/test/jalview/datamodel/AlignedCodonFrameTest.java b/test/jalview/datamodel/AlignedCodonFrameTest.java index 69e584a..4984e5e 100644 --- a/test/jalview/datamodel/AlignedCodonFrameTest.java +++ b/test/jalview/datamodel/AlignedCodonFrameTest.java @@ -23,6 +23,7 @@ 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; @@ -213,6 +214,10 @@ public class AlignedCodonFrameTest 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() { @@ -238,27 +243,69 @@ public class AlignedCodonFrameTest seq1proxy.setName("Seq1a"); assertFalse(acf.isRealisableWith(seq1)); seq1proxy.setName("Seq1"); - seq1.setName("Seq1a"); + + SequenceI seq1ds = seq1.getDatasetSequence(); + seq1ds.setName("Seq1a"); assertFalse(acf.isRealisableWith(seq1)); - seq1.setName("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 */ - seq1.setStart(1); - seq1.setEnd(6); + seq1ds.setStart(1); + seq1ds.setEnd(6); // seq1 precedes mapped region: assertFalse(acf.isRealisableWith(seq1)); - seq1.setEnd(7); + seq1ds.setEnd(7); // seq1 includes first mapped base: assertTrue(acf.isRealisableWith(seq1)); - seq1.setStart(13); - seq1.setEnd(18); + seq1ds.setStart(13); + seq1ds.setEnd(18); // seq1 follows mapped region: assertFalse(acf.isRealisableWith(seq1)); - seq1.setStart(12); + 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]); + } } diff --git a/test/jalview/io/ExonerateGffTest.java b/test/jalview/io/ExonerateGffTest.java index 799eeed..70c0ec2 100644 --- a/test/jalview/io/ExonerateGffTest.java +++ b/test/jalview/io/ExonerateGffTest.java @@ -1,12 +1,15 @@ package jalview.io; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; import jalview.datamodel.AlignedCodonFrame; +import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.Mapping; +import jalview.datamodel.Sequence; import jalview.datamodel.SequenceDummy; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; @@ -36,12 +39,13 @@ public class ExonerateGffTest String proteinSeq = ">prot1/10-16\nYCWRSGA"; AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( proteinSeq, FormatAdapter.PASTE); + /* - * exonerate map of residues 11-15 (CWRSG) to bases 10-24 in sequence 'dna1' - * starting at position 10 (forward strand) + * exonerate GFF output mapping residues 11-15 (CWRSG) + * to bases 24-10 in sequence 'dna1' (reverse strand) */ String exonerateGff = "##gff-version 2\n" - + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t+\t.\talignment_id 0 ; Target dna1 ; Align 11 10 5"; + + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t-\t.\talignment_id 0 ; Target dna1 ; Align 11 24 5"; af.loadJalviewDataFile(exonerateGff, FormatAdapter.PASTE, null, null); /* @@ -59,14 +63,26 @@ public class ExonerateGffTest assertEquals("dna1", mappedDna.getName()); Mapping[] mapList = mapping.getProtMappings(); assertEquals(1, mapList.length); - // 11 in protein should map to codon [10, 11, 12] in dna + // 11 in protein should map to codon [24, 23, 22] in dna int[] mappedRegion = mapList[0].getMap().locateInFrom(11, 11); - assertArrayEquals(new int[] { 10, 12 }, mappedRegion); - // 15 in protein should map to codon [22, 23, 24] in dna + assertArrayEquals(new int[] { 24, 22 }, mappedRegion); + // 15 in protein should map to codon [12, 11, 10] in dna mappedRegion = mapList[0].getMap().locateInFrom(15, 15); - assertArrayEquals(new int[] { 22, 24 }, mappedRegion); + assertArrayEquals(new int[] { 12, 10 }, mappedRegion); // so far so good; TODO: programmatically add mapped sequences // and verify the mappings are 'realised' + SequenceI dna1 = new Sequence("dna1", "AAACCCGGGTTTAAACCCGGGTTT"); + AlignmentI al = new Alignment(new SequenceI[] { dna1 }); + al.setDataset(null); + + /* + * Now 'realise' the virtual mapping to the real DNA sequence; + * interactively this could be by a drag or fetch of the sequence data + */ + mapping.realiseWith(dna1); + // verify the mapping is now from the real, not the dummy sequence + assertSame(dna1.getDatasetSequence(), + mapping.getDnaForAaSeq(dataset.getSequenceAt(0))); } } -- 1.7.10.2