2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.io.gff;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertSame;
25 import static org.testng.AssertJUnit.assertTrue;
26 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
28 import jalview.datamodel.AlignedCodonFrame;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Mapping;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceDummy;
34 import jalview.datamodel.SequenceI;
35 import jalview.gui.AlignFrame;
36 import jalview.io.FileLoader;
37 import jalview.io.FormatAdapter;
39 import java.util.List;
41 import org.testng.annotations.Test;
44 * Tests of use cases that include parsing GFF (version 2 or 3) features that
45 * describe mappings between protein and cDNA. The format of the GFF varies
46 * depending on which tool generated it.
51 * Test the case where we load a protein ('query') sequence, then exonerateGff
52 * describing its mapping to cDNA, and then a DNA sequence including the
55 @Test(groups = "Functional")
56 public void testResolveExonerateGff()
58 String proteinSeq = ">prot1/10-16\nYCWRSGA";
59 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
60 proteinSeq, FormatAdapter.PASTE);
63 * exonerate GFF output mapping residues 11-15 (CWRSG)
64 * to bases 24-10 in sequence 'dna1' (reverse strand)
66 String exonerateGff = "##gff-version 2\n"
67 + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t-\t.\talignment_id 0 ; Target dna1 ; Align 11 24 5";
68 af.loadJalviewDataFile(exonerateGff, FormatAdapter.PASTE, null, null);
71 * check we have a mapping from prot1 to SequenceDummy 'dna1'
73 AlignmentI dataset = af.getViewport().getAlignment().getDataset();
74 assertEquals(1, dataset.getSequences().size());
75 assertEquals("prot1", dataset.getSequenceAt(0).getName());
76 assertEquals("YCWRSGA", dataset.getSequenceAt(0).getSequenceAsString());
77 List<AlignedCodonFrame> mappings = dataset.getCodonFrames();
78 assertEquals(1, mappings.size());
79 AlignedCodonFrame mapping = mappings.iterator().next();
80 SequenceI mappedDna = mapping.getDnaForAaSeq(dataset.getSequenceAt(0));
81 assertTrue(mappedDna instanceof SequenceDummy);
82 assertEquals("dna1", mappedDna.getName());
83 Mapping[] mapList = mapping.getProtMappings();
84 assertEquals(1, mapList.length);
85 // 11 in protein should map to codon [24, 23, 22] in dna
86 int[] mappedRegion = mapList[0].getMap().locateInFrom(11, 11);
87 assertArrayEquals(new int[] { 24, 22 }, mappedRegion);
88 // 15 in protein should map to codon [12, 11, 10] in dna
89 mappedRegion = mapList[0].getMap().locateInFrom(15, 15);
90 assertArrayEquals(new int[] { 12, 10 }, mappedRegion);
92 SequenceI dna1 = new Sequence("dna1", "AAACCCGGGTTTAAACCCGGGTTT");
93 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
97 * Now 'realise' the virtual mapping to the real DNA sequence;
98 * interactively this could be by a drag or fetch of the sequence data
101 mapping.realiseWith(dna1);
102 // verify the mapping is now from the real, not the dummy sequence
103 assertSame(dna1.getDatasetSequence(),
104 mapping.getDnaForAaSeq(dataset.getSequenceAt(0)));