JAL-653 test for 'resolving GFF mappings to sequences' (wip)
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 30 Nov 2015 10:04:40 +0000 (10:04 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 30 Nov 2015 10:04:40 +0000 (10:04 +0000)
test/jalview/io/ExonerateGffTest.java [new file with mode: 0644]

diff --git a/test/jalview/io/ExonerateGffTest.java b/test/jalview/io/ExonerateGffTest.java
new file mode 100644 (file)
index 0000000..799eeed
--- /dev/null
@@ -0,0 +1,72 @@
+package jalview.io;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
+
+import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Mapping;
+import jalview.datamodel.SequenceDummy;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+
+import java.util.Set;
+
+import org.testng.annotations.Test;
+
+/**
+ * Tests of use cases that include parsing exonerate GFF 'similarity' features.
+ * These describe mappings between protein and cDNA
+ * 
+ * @author gmcarstairs
+ *
+ */
+public class ExonerateGffTest
+{
+
+  /**
+   * Test the case where we load a protein ('query') sequence, then exonerateGff
+   * describing its mapping to cDNA, and then a DNA sequence including the
+   * mapped region
+   */
+  @Test(groups = "Functional")
+  public void testLoadProteinGffCdna()
+  {
+    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)
+     */
+    String exonerateGff = "##gff-version 2\n"
+            + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t+\t.\talignment_id 0 ; Target dna1 ; Align 11 10 5";
+    af.loadJalviewDataFile(exonerateGff, FormatAdapter.PASTE, null, null);
+
+    /*
+     * check we have a mapping from prot1 to SequenceDummy 'dna1'
+     */
+    AlignmentI dataset = af.getViewport().getAlignment().getDataset();
+    assertEquals(1, dataset.getSequences().size());
+    assertEquals("prot1", dataset.getSequenceAt(0).getName());
+    assertEquals("YCWRSGA", dataset.getSequenceAt(0).getSequenceAsString());
+    Set<AlignedCodonFrame> mappings = dataset.getCodonFrames();
+    assertEquals(1, mappings.size());
+    AlignedCodonFrame mapping = mappings.iterator().next();
+    SequenceI mappedDna = mapping.getDnaForAaSeq(dataset.getSequenceAt(0));
+    assertTrue(mappedDna instanceof SequenceDummy);
+    assertEquals("dna1", mappedDna.getName());
+    Mapping[] mapList = mapping.getProtMappings();
+    assertEquals(1, mapList.length);
+    // 11 in protein should map to codon [10, 11, 12] 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
+    mappedRegion = mapList[0].getMap().locateInFrom(15, 15);
+    assertArrayEquals(new int[] { 22, 24 }, mappedRegion);
+
+    // so far so good; TODO: programmatically add mapped sequences
+    // and verify the mappings are 'realised'
+  }
+}