JAL-653 test for 'resolving GFF mappings to sequences' (wip)
[jalview.git] / test / jalview / io / ExonerateGffTest.java
1 package jalview.io;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertTrue;
5 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
6
7 import jalview.datamodel.AlignedCodonFrame;
8 import jalview.datamodel.AlignmentI;
9 import jalview.datamodel.Mapping;
10 import jalview.datamodel.SequenceDummy;
11 import jalview.datamodel.SequenceI;
12 import jalview.gui.AlignFrame;
13
14 import java.util.Set;
15
16 import org.testng.annotations.Test;
17
18 /**
19  * Tests of use cases that include parsing exonerate GFF 'similarity' features.
20  * These describe mappings between protein and cDNA
21  * 
22  * @author gmcarstairs
23  *
24  */
25 public class ExonerateGffTest
26 {
27
28   /**
29    * Test the case where we load a protein ('query') sequence, then exonerateGff
30    * describing its mapping to cDNA, and then a DNA sequence including the
31    * mapped region
32    */
33   @Test(groups = "Functional")
34   public void testLoadProteinGffCdna()
35   {
36     String proteinSeq = ">prot1/10-16\nYCWRSGA";
37     AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
38             proteinSeq, FormatAdapter.PASTE);
39     /*
40      * exonerate map of residues 11-15 (CWRSG) to bases 10-24 in sequence 'dna1'
41      * starting at position 10 (forward strand)
42      */
43     String exonerateGff = "##gff-version 2\n"
44             + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t+\t.\talignment_id 0 ; Target dna1 ; Align 11 10 5";
45     af.loadJalviewDataFile(exonerateGff, FormatAdapter.PASTE, null, null);
46
47     /*
48      * check we have a mapping from prot1 to SequenceDummy 'dna1'
49      */
50     AlignmentI dataset = af.getViewport().getAlignment().getDataset();
51     assertEquals(1, dataset.getSequences().size());
52     assertEquals("prot1", dataset.getSequenceAt(0).getName());
53     assertEquals("YCWRSGA", dataset.getSequenceAt(0).getSequenceAsString());
54     Set<AlignedCodonFrame> mappings = dataset.getCodonFrames();
55     assertEquals(1, mappings.size());
56     AlignedCodonFrame mapping = mappings.iterator().next();
57     SequenceI mappedDna = mapping.getDnaForAaSeq(dataset.getSequenceAt(0));
58     assertTrue(mappedDna instanceof SequenceDummy);
59     assertEquals("dna1", mappedDna.getName());
60     Mapping[] mapList = mapping.getProtMappings();
61     assertEquals(1, mapList.length);
62     // 11 in protein should map to codon [10, 11, 12] in dna
63     int[] mappedRegion = mapList[0].getMap().locateInFrom(11, 11);
64     assertArrayEquals(new int[] { 10, 12 }, mappedRegion);
65     // 15 in protein should map to codon [22, 23, 24] in dna
66     mappedRegion = mapList[0].getMap().locateInFrom(15, 15);
67     assertArrayEquals(new int[] { 22, 24 }, mappedRegion);
68
69     // so far so good; TODO: programmatically add mapped sequences
70     // and verify the mappings are 'realised'
71   }
72 }