Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io.gff

File GffTests.java

 

Code metrics

0
27
2
1
116
60
2
0.07
13.5
2
1

Classes

Class Line # Actions
GffTests 50 27 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.io.gff;
22   
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;
27   
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.gui.JvOptionPane;
37    import jalview.io.DataSourceType;
38    import jalview.io.FileLoader;
39   
40    import java.util.List;
41   
42    import org.testng.annotations.BeforeClass;
43    import org.testng.annotations.Test;
44   
45    /**
46    * Tests of use cases that include parsing GFF (version 2 or 3) features that
47    * describe mappings between protein and cDNA. The format of the GFF varies
48    * depending on which tool generated it.
49    */
 
50    public class GffTests
51    {
52   
 
53  1 toggle @BeforeClass(alwaysRun = true)
54    public void setUpJvOptionPane()
55    {
56  1 JvOptionPane.setInteractiveMode(false);
57  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
58    }
59   
60    /**
61    * Test the case where we load a protein ('query') sequence, then exonerateGff
62    * describing its mapping to cDNA, and then a DNA sequence including the
63    * mapped region
64    */
 
65  1 toggle @Test(groups = "Functional")
66    public void testResolveExonerateGff()
67    {
68  1 String proteinSeq = ">prot1/10-16\nYCWRSGA";
69  1 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
70    proteinSeq, DataSourceType.PASTE);
71   
72    /*
73    * exonerate GFF output mapping residues 11-15 (CWRSG)
74    * to bases 24-10 in sequence 'dna1' (reverse strand)
75    */
76  1 String exonerateGff = "##gff-version 2\n"
77    + "prot1\tprotein2genome\tsimilarity\t11\t15\t99\t-\t.\talignment_id 0 ; Target dna1 ; Align 11 24 5";
78  1 af.loadJalviewDataFile(exonerateGff, DataSourceType.PASTE, null, null);
79   
80    /*
81    * check we have a mapping from prot1 to SequenceDummy 'dna1'
82    */
83  1 AlignmentI dataset = af.getViewport().getAlignment().getDataset();
84  1 assertEquals(1, dataset.getSequences().size());
85  1 assertEquals("prot1", dataset.getSequenceAt(0).getName());
86  1 assertEquals("YCWRSGA", dataset.getSequenceAt(0).getSequenceAsString());
87  1 List<AlignedCodonFrame> mappings = dataset.getCodonFrames();
88  1 assertEquals(1, mappings.size());
89  1 AlignedCodonFrame mapping = mappings.iterator().next();
90  1 SequenceI mappedDna = mapping.getDnaForAaSeq(dataset.getSequenceAt(0));
91  1 assertTrue(mappedDna instanceof SequenceDummy);
92  1 assertEquals("dna1", mappedDna.getName());
93  1 Mapping[] mapList = mapping.getProtMappings();
94  1 assertEquals(1, mapList.length);
95    // 11 in protein should map to codon [24, 23, 22] in dna
96  1 int[] mappedRegion = mapList[0].getMap().locateInFrom(11, 11);
97  1 assertArrayEquals(new int[] { 24, 22 }, mappedRegion);
98    // 15 in protein should map to codon [12, 11, 10] in dna
99  1 mappedRegion = mapList[0].getMap().locateInFrom(15, 15);
100  1 assertArrayEquals(new int[] { 12, 10 }, mappedRegion);
101   
102  1 SequenceI dna1 = new Sequence("dna1", "AAACCCGGGTTTAAACCCGGGTTT");
103  1 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
104  1 al.setDataset(null);
105   
106    /*
107    * Now 'realise' the virtual mapping to the real DNA sequence;
108    * interactively this could be by a drag or fetch of the sequence data
109    * on to the alignment
110    */
111  1 mapping.realiseWith(dna1);
112    // verify the mapping is now from the real, not the dummy sequence
113  1 assertSame(dna1.getDatasetSequence(),
114    mapping.getDnaForAaSeq(dataset.getSequenceAt(0)));
115    }
116    }