1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (133) |
Complexity: 7 |
Complexity Density: 0.06 |
|
51 |
|
public class ExonerateHelperTest |
52 |
|
{ |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
54 |
1 |
@BeforeClass(alwaysRun = true)... |
55 |
|
public void setUpJvOptionPane() |
56 |
|
{ |
57 |
1 |
JvOptionPane.setInteractiveMode(false); |
58 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
61 |
1 |
@Test(groups = "Functional")... |
62 |
|
public void testGetMappingType() |
63 |
|
{ |
64 |
|
|
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 |
|
|
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 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@throws |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
91 |
1 |
@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 |
|
|
106 |
|
|
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 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
@throws |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
134 |
1 |
@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 |
|
|
149 |
|
|
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 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@throws |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
177 |
1 |
@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 |
|
|
190 |
|
|
191 |
1 |
Map<String, List<String>> set = Gff2Helper.parseNameValuePairs(gff[8]); |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
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 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
@throws |
222 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
223 |
1 |
@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 |
|
|
236 |
|
|
237 |
1 |
Map<String, List<String>> set = Gff2Helper.parseNameValuePairs(gff[8]); |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
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 |
|
|
264 |
|
|
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
266 |
1 |
@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 |
|
|
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 |
|
|
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 |
|
|
293 |
1 |
int[] mappedRegion = mapList[0].getMap().locateInFrom(143, 143); |
294 |
1 |
assertArrayEquals(new int[] { 11270, 11268 }, mappedRegion); |
295 |
|
|
296 |
|
|
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 |
|
|
306 |
1 |
mappedRegion = mapList[0].getMap().locateInFrom(143, 143); |
307 |
1 |
assertArrayEquals(new int[] { 11270, 11268 }, mappedRegion); |
308 |
|
|
309 |
|
|
310 |
1 |
mappedRegion = mapList[0].getMap().locateInFrom(182, 182); |
311 |
1 |
assertArrayEquals(new int[] { 11153, 11151 }, mappedRegion); |
312 |
|
|
313 |
|
|
314 |
1 |
mappedRegion = mapList[0].getMap().locateInTo(11151, 11153); |
315 |
1 |
assertArrayEquals(new int[] { 182, 182 }, mappedRegion); |
316 |
|
|
317 |
|
|
318 |
1 |
mappedRegion = mapList[0].getMap().locateInTo(11150, 11150); |
319 |
1 |
assertNull(mappedRegion); |
320 |
|
|
321 |
|
|
322 |
1 |
mappedRegion = mapList[0].getMap().locateInFrom(183, 183); |
323 |
1 |
assertNull(mappedRegion); |
324 |
|
} |
325 |
|
} |