1 package jalview.io.gff;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertSame;
5 import static org.testng.AssertJUnit.assertTrue;
6 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
8 import jalview.datamodel.AlignedCodonFrame;
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.Mapping;
12 import jalview.datamodel.Sequence;
13 import jalview.datamodel.SequenceDummy;
14 import jalview.datamodel.SequenceI;
15 import jalview.gui.AlignFrame;
16 import jalview.io.FileLoader;
17 import jalview.io.FormatAdapter;
19 import java.util.List;
21 import org.testng.annotations.Test;
24 * Tests of use cases that include parsing GFF (version 2 or 3) features that
25 * describe mappings between protein and cDNA. The format of the GFF varies
26 * depending on which tool generated it.
31 * Test the case where we load a protein ('query') sequence, then exonerateGff
32 * describing its mapping to cDNA, and then a DNA sequence including the
35 @Test(groups = "Functional")
36 public void testResolveExonerateGff()
38 String proteinSeq = ">prot1/10-16\nYCWRSGA";
39 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
40 proteinSeq, FormatAdapter.PASTE);
43 * exonerate GFF output mapping residues 11-15 (CWRSG)
44 * to bases 24-10 in sequence 'dna1' (reverse strand)
46 String exonerateGff = "##gff-version 2\n"
47 + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t-\t.\talignment_id 0 ; Target dna1 ; Align 11 24 5";
48 af.loadJalviewDataFile(exonerateGff, FormatAdapter.PASTE, null, null);
51 * check we have a mapping from prot1 to SequenceDummy 'dna1'
53 AlignmentI dataset = af.getViewport().getAlignment().getDataset();
54 assertEquals(1, dataset.getSequences().size());
55 assertEquals("prot1", dataset.getSequenceAt(0).getName());
56 assertEquals("YCWRSGA", dataset.getSequenceAt(0).getSequenceAsString());
57 List<AlignedCodonFrame> mappings = dataset.getCodonFrames();
58 assertEquals(1, mappings.size());
59 AlignedCodonFrame mapping = mappings.iterator().next();
60 SequenceI mappedDna = mapping.getDnaForAaSeq(dataset.getSequenceAt(0));
61 assertTrue(mappedDna instanceof SequenceDummy);
62 assertEquals("dna1", mappedDna.getName());
63 Mapping[] mapList = mapping.getProtMappings();
64 assertEquals(1, mapList.length);
65 // 11 in protein should map to codon [24, 23, 22] in dna
66 int[] mappedRegion = mapList[0].getMap().locateInFrom(11, 11);
67 assertArrayEquals(new int[] { 24, 22 }, mappedRegion);
68 // 15 in protein should map to codon [12, 11, 10] in dna
69 mappedRegion = mapList[0].getMap().locateInFrom(15, 15);
70 assertArrayEquals(new int[] { 12, 10 }, mappedRegion);
72 SequenceI dna1 = new Sequence("dna1", "AAACCCGGGTTTAAACCCGGGTTT");
73 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
77 * Now 'realise' the virtual mapping to the real DNA sequence;
78 * interactively this could be by a drag or fetch of the sequence data
81 mapping.realiseWith(dna1);
82 // verify the mapping is now from the real, not the dummy sequence
83 assertSame(dna1.getDatasetSequence(),
84 mapping.getDnaForAaSeq(dataset.getSequenceAt(0)));