Clover icon

jalviewX

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

File ExonerateHelperTest.java

 

Code metrics

0
126
7
1
325
212
7
0.06
18
7
1

Classes

Class Line # Actions
ExonerateHelperTest 51 126 7 0
1.0100%
 

Contributing tests

This file is covered by 6 tests. .

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.assertNull;
25    import static org.testng.AssertJUnit.assertSame;
26    import static org.testng.AssertJUnit.assertTrue;
27    import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
28   
29    import jalview.datamodel.AlignedCodonFrame;
30    import jalview.datamodel.Alignment;
31    import jalview.datamodel.AlignmentI;
32    import jalview.datamodel.Mapping;
33    import jalview.datamodel.MappingType;
34    import jalview.datamodel.Sequence;
35    import jalview.datamodel.SequenceDummy;
36    import jalview.datamodel.SequenceI;
37    import jalview.gui.AlignFrame;
38    import jalview.gui.JvOptionPane;
39    import jalview.io.DataSourceType;
40    import jalview.io.FileLoader;
41   
42    import java.io.IOException;
43    import java.util.ArrayList;
44    import java.util.Iterator;
45    import java.util.List;
46    import java.util.Map;
47   
48    import org.testng.annotations.BeforeClass;
49    import org.testng.annotations.Test;
50   
 
51    public class ExonerateHelperTest
52    {
53   
 
54  1 toggle @BeforeClass(alwaysRun = true)
55    public void setUpJvOptionPane()
56    {
57  1 JvOptionPane.setInteractiveMode(false);
58  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
59    }
60   
 
61  1 toggle @Test(groups = "Functional")
62    public void testGetMappingType()
63    {
64    // protein-to-dna:
65  1 assertSame(MappingType.PeptideToNucleotide,
66    ExonerateHelper
67    .getMappingType("exonerate:protein2genome:local"));
68  1 assertSame(MappingType.PeptideToNucleotide,
69    ExonerateHelper.getMappingType("exonerate:protein2dna:local"));
70   
71    // dna-to-dna:
72  1 assertSame(MappingType.NucleotideToNucleotide,
73    ExonerateHelper.getMappingType("coding2coding"));
74  1 assertSame(MappingType.NucleotideToNucleotide,
75    ExonerateHelper.getMappingType("coding2genome"));
76  1 assertSame(MappingType.NucleotideToNucleotide,
77    ExonerateHelper.getMappingType("cdna2genome"));
78  1 assertSame(MappingType.NucleotideToNucleotide,
79    ExonerateHelper.getMappingType("genome2genome"));
80  1 assertNull(ExonerateHelper.getMappingType("affine:local"));
81    }
82   
83    /**
84    * Test processing one exonerate GFF line for the case where the mapping is
85    * protein2dna, similarity feature is on the query (the protein), match to the
86    * forward strand, target sequence is in neither the alignment nor the 'new
87    * sequences'
88    *
89    * @throws IOException
90    */
 
91  1 toggle @Test(groups = "Functional")
92    public void testProcessGffSimilarity_protein2dna_forward_querygff()
93    throws IOException
94    {
95  1 ExonerateHelper testee = new ExonerateHelper();
96  1 List<SequenceI> newseqs = new ArrayList<SequenceI>();
97  1 String[] gff = "Seq\texonerate:protein2dna:local\tsimilarity\t3\t10\t.\t+\t.\talignment_id 0 ; Target dna1 ; Align 3 400 8"
98    .split("\\t");
99  1 SequenceI seq = new Sequence("Seq", "PQRASTGKEEDVMIWCHQN");
100  1 seq.createDatasetSequence();
101  1 AlignmentI align = new Alignment(new SequenceI[] {});
102  1 Map<String, List<String>> set = Gff2Helper.parseNameValuePairs(gff[8]);
103   
104    /*
105    * this should create a mapping from Seq2/3-10 to virtual sequence
106    * dna1 (added to newseqs) positions 400-423
107    */
108  1 testee.processGffSimilarity(set, seq, gff, align, newseqs, false);
109  1 assertEquals(1, newseqs.size());
110  1 assertTrue(newseqs.get(0) instanceof SequenceDummy);
111  1 assertEquals("dna1", newseqs.get(0).getName());
112  1 assertEquals(1, align.getCodonFrames().size());
113  1 AlignedCodonFrame mapping = align.getCodonFrames().iterator().next();
114  1 assertEquals(1, mapping.getAaSeqs().length);
115  1 assertSame(seq.getDatasetSequence(), mapping.getAaSeqs()[0]);
116  1 assertEquals(1, mapping.getdnaSeqs().length);
117  1 assertSame(newseqs.get(0), mapping.getdnaSeqs()[0]);
118  1 assertEquals(1, mapping.getdnaToProt().length);
119  1 assertEquals(1, mapping.getdnaToProt()[0].getFromRanges().size());
120  1 assertArrayEquals(new int[] { 400, 423 }, mapping.getdnaToProt()[0]
121    .getFromRanges().get(0));
122  1 assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
123  1 assertArrayEquals(new int[] { 3, 10 }, mapping.getdnaToProt()[0]
124    .getToRanges().get(0));
125    }
126   
127    /**
128    * Test processing one exonerate GFF line for the case where the mapping is
129    * protein2dna, similarity feature is on the query (the protein), match to the
130    * reverse strand
131    *
132    * @throws IOException
133    */
 
134  1 toggle @Test(groups = "Functional")
135    public void testProcessGffSimilarity_protein2dna_reverse_querygff()
136    throws IOException
137    {
138  1 ExonerateHelper testee = new ExonerateHelper();
139  1 List<SequenceI> newseqs = new ArrayList<SequenceI>();
140  1 String[] gff = "Seq\texonerate:protein2dna:local\tsimilarity\t3\t10\t0\t-\t.\talignment_id 0 ; Target dna1 ; Align 3 400 8"
141    .split("\\t");
142  1 SequenceI seq = new Sequence("Seq", "PQRASTGKEEDVMIWCHQN");
143  1 seq.createDatasetSequence();
144  1 AlignmentI align = new Alignment(new SequenceI[] {});
145  1 Map<String, List<String>> set = Gff2Helper.parseNameValuePairs(gff[8]);
146   
147    /*
148    * this should create a mapping from Seq2/3-10 to virtual sequence
149    * dna1 (added to newseqs) positions 400-377 (reverse)
150    */
151  1 testee.processGffSimilarity(set, seq, gff, align, newseqs, false);
152  1 assertEquals(1, newseqs.size());
153  1 assertTrue(newseqs.get(0) instanceof SequenceDummy);
154  1 assertEquals("dna1", newseqs.get(0).getName());
155  1 assertEquals(1, align.getCodonFrames().size());
156  1 AlignedCodonFrame mapping = align.getCodonFrames().iterator().next();
157  1 assertEquals(1, mapping.getAaSeqs().length);
158  1 assertSame(seq.getDatasetSequence(), mapping.getAaSeqs()[0]);
159  1 assertEquals(1, mapping.getdnaSeqs().length);
160  1 assertSame(newseqs.get(0), mapping.getdnaSeqs()[0]);
161  1 assertEquals(1, mapping.getdnaToProt().length);
162  1 assertEquals(1, mapping.getdnaToProt()[0].getFromRanges().size());
163  1 assertArrayEquals(new int[] { 400, 377 }, mapping.getdnaToProt()[0]
164    .getFromRanges().get(0));
165  1 assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
166  1 assertArrayEquals(new int[] { 3, 10 }, mapping.getdnaToProt()[0]
167    .getToRanges().get(0));
168    }
169   
170    /**
171    * Test processing one exonerate GFF line for the case where the mapping is
172    * protein2dna, similarity feature is on the target (the dna), match to the
173    * forward strand
174    *
175    * @throws IOException
176    */
 
177  1 toggle @Test(groups = "Functional")
178    public void testProcessGffSimilarity_protein2dna_forward_targetgff()
179    throws IOException
180    {
181  1 ExonerateHelper testee = new ExonerateHelper();
182  1 List<SequenceI> newseqs = new ArrayList<SequenceI>();
183  1 String[] gff = "dna1\texonerate:protein2dna:local\tsimilarity\t400\t423\t0\t+\t.\talignment_id 0 ; Query Prot1 ; Align 400 3 24"
184    .split("\\t");
185  1 SequenceI seq = new Sequence("dna1/391-430",
186    "CGATCCGATCCGATCCGATCCGATCCGATCCGATCCGATC");
187  1 seq.createDatasetSequence();
188  1 AlignmentI align = new Alignment(new SequenceI[] { seq });
189    // GFF feature on the target describes mapping from base 400 for
190    // count 24 to position 3
191  1 Map<String, List<String>> set = Gff2Helper.parseNameValuePairs(gff[8]);
192   
193    /*
194    * this should create a mapping from virtual sequence dna1 (added to
195    * newseqs) positions 400-423 to Prot1/3-10
196    */
197  1 testee.processGffSimilarity(set, seq, gff, align, newseqs, false);
198  1 assertEquals(1, newseqs.size());
199  1 assertTrue(newseqs.get(0) instanceof SequenceDummy);
200  1 assertEquals("Prot1", newseqs.get(0).getName());
201  1 assertEquals(1, align.getCodonFrames().size());
202  1 AlignedCodonFrame mapping = align.getCodonFrames().iterator().next();
203  1 assertEquals(1, mapping.getAaSeqs().length);
204  1 assertSame(newseqs.get(0), mapping.getAaSeqs()[0]);
205  1 assertSame(seq.getDatasetSequence(), mapping.getdnaSeqs()[0]);
206  1 assertEquals(1, mapping.getdnaSeqs().length);
207  1 assertEquals(1, mapping.getdnaToProt().length);
208  1 assertEquals(1, mapping.getdnaToProt()[0].getFromRanges().size());
209  1 assertArrayEquals(new int[] { 400, 423 }, mapping.getdnaToProt()[0]
210    .getFromRanges().get(0));
211  1 assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
212  1 assertArrayEquals(new int[] { 3, 10 }, mapping.getdnaToProt()[0]
213    .getToRanges().get(0));
214    }
215   
216    /**
217    * Test processing one exonerate GFF line for the case where the mapping is
218    * protein2dna, similarity feature is on the target (the dna), match to the
219    * reverse strand
220    *
221    * @throws IOException
222    */
 
223  1 toggle @Test(groups = "Functional")
224    public void testProcessGffSimilarity_protein2dna_reverse_targetgff()
225    throws IOException
226    {
227  1 ExonerateHelper testee = new ExonerateHelper();
228  1 List<SequenceI> newseqs = new ArrayList<SequenceI>();
229  1 String[] gff = "dna1\texonerate:protein2dna:local\tsimilarity\t377\t400\t0\t-\t.\talignment_id 0 ; Query Prot1 ; Align 400 3 24"
230    .split("\\t");
231  1 SequenceI seq = new Sequence("dna1/371-410",
232    "CGATCCGATCCGATCCGATCCGATCCGATCCGATCCGATC");
233  1 seq.createDatasetSequence();
234  1 AlignmentI align = new Alignment(new SequenceI[] { seq });
235    // GFF feature on the target describes mapping from base 400 for
236    // count 24 to position 3
237  1 Map<String, List<String>> set = Gff2Helper.parseNameValuePairs(gff[8]);
238   
239    /*
240    * this should create a mapping from virtual sequence dna1 (added to
241    * newseqs) positions 400-377 (reverse) to Prot1/3-10
242    */
243  1 testee.processGffSimilarity(set, seq, gff, align, newseqs, false);
244  1 assertEquals(1, newseqs.size());
245  1 assertTrue(newseqs.get(0) instanceof SequenceDummy);
246  1 assertEquals("Prot1", newseqs.get(0).getName());
247  1 assertEquals(1, align.getCodonFrames().size());
248  1 AlignedCodonFrame mapping = align.getCodonFrames().iterator().next();
249  1 assertEquals(1, mapping.getAaSeqs().length);
250  1 assertSame(newseqs.get(0), mapping.getAaSeqs()[0]);
251  1 assertSame(seq.getDatasetSequence(), mapping.getdnaSeqs()[0]);
252  1 assertEquals(1, mapping.getdnaSeqs().length);
253  1 assertEquals(1, mapping.getdnaToProt().length);
254  1 assertEquals(1, mapping.getdnaToProt()[0].getFromRanges().size());
255  1 assertArrayEquals(new int[] { 400, 377 }, mapping.getdnaToProt()[0]
256    .getFromRanges().get(0));
257  1 assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
258  1 assertArrayEquals(new int[] { 3, 10 }, mapping.getdnaToProt()[0]
259    .getToRanges().get(0));
260    }
261   
262    /**
263    * Tests loading exonerate GFF2 output, including 'similarity' alignment
264    * feature, on to sequences
265    */
 
266  1 toggle @Test(groups = { "Functional" })
267    public void testAddExonerateGffToAlignment()
268    {
269  1 FileLoader loader = new FileLoader(false);
270  1 AlignFrame af = loader.LoadFileWaitTillLoaded(
271    "examples/testdata/exonerateseqs.fa",
272    DataSourceType.FILE);
273   
274  1 af.loadJalviewDataFile("examples/testdata/exonerateoutput.gff",
275    DataSourceType.FILE, null, null);
276   
277    /*
278    * verify one mapping to a dummy sequence, one to a real one
279    */
280  1 List<AlignedCodonFrame> mappings = af
281    .getViewport().getAlignment().getDataset().getCodonFrames();
282  1 assertEquals(2, mappings.size());
283  1 Iterator<AlignedCodonFrame> iter = mappings.iterator();
284   
285    // first mapping is to dummy sequence
286  1 AlignedCodonFrame mapping = iter.next();
287  1 Mapping[] mapList = mapping.getProtMappings();
288  1 assertEquals(1, mapList.length);
289  1 assertTrue(mapList[0].getTo() instanceof SequenceDummy);
290  1 assertEquals("DDB_G0269124", mapList[0].getTo().getName());
291   
292    // 143 in protein should map to codon [11270, 11269, 11268] in dna
293  1 int[] mappedRegion = mapList[0].getMap().locateInFrom(143, 143);
294  1 assertArrayEquals(new int[] { 11270, 11268 }, mappedRegion);
295   
296    // second mapping is to a sequence in the alignment
297  1 mapping = iter.next();
298  1 mapList = mapping.getProtMappings();
299  1 assertEquals(1, mapList.length);
300  1 SequenceI proteinSeq = af.getViewport().getAlignment()
301    .findName("DDB_G0280897");
302  1 assertSame(proteinSeq.getDatasetSequence(), mapList[0].getTo());
303  1 assertEquals(1, mapping.getdnaToProt().length);
304   
305    // 143 in protein should map to codon [11270, 11269, 11268] in dna
306  1 mappedRegion = mapList[0].getMap().locateInFrom(143, 143);
307  1 assertArrayEquals(new int[] { 11270, 11268 }, mappedRegion);
308   
309    // 182 in protein should map to codon [11153, 11152, 11151] in dna
310  1 mappedRegion = mapList[0].getMap().locateInFrom(182, 182);
311  1 assertArrayEquals(new int[] { 11153, 11151 }, mappedRegion);
312   
313    // and the reverse mapping:
314  1 mappedRegion = mapList[0].getMap().locateInTo(11151, 11153);
315  1 assertArrayEquals(new int[] { 182, 182 }, mappedRegion);
316   
317    // 11150 in dna should _not_ map to protein
318  1 mappedRegion = mapList[0].getMap().locateInTo(11150, 11150);
319  1 assertNull(mappedRegion);
320   
321    // similarly 183 in protein should _not_ map to dna
322  1 mappedRegion = mapList[0].getMap().locateInFrom(183, 183);
323  1 assertNull(mappedRegion);
324    }
325    }