811ddd067a041d3caf698a3ef2025850b144aec8
[jalview.git] / test / jalview / ws / phyre2 / Phyre2ClientTest.java
1 package jalview.ws.phyre2;
2
3 import jalview.datamodel.Sequence;
4 import jalview.datamodel.SequenceI;
5 import jalview.ext.jmol.JmolParser;
6 import jalview.io.DataSourceType;
7 import jalview.io.StructureFile;
8
9 import java.io.IOException;
10 import java.util.Arrays;
11 import java.util.HashMap;
12
13 import org.testng.Assert;
14 import org.testng.annotations.Test;
15
16 public class Phyre2ClientTest
17 {
18   private Phyre2Client phyre2Client = null;
19
20
21
22
23   @Test(groups = { "Functional" })
24   public void getPhyre2FastaMappingTest()
25   {
26     String phyre2ModelFile = "examples/testdata/phyre2results/56da5616b4559c93/c4n58A_.pdb";
27
28     SequenceI testSeq = new Sequence(
29             "FER_CAPAN",
30             "MASVSATMISTSFMPRKPAVTSLKPIPNVGEALFGLKSANGGKVTCMASYKVKLITPDGPIEF"
31                     + "DCPDNVYILDQAEEAGHDLPYSCRAGSCSSCAGKIAGGAVDQTDGNFLDDDQL"
32                     + "EEGWVLTCVAYPQSDVTIETHKEAELVG", 1, 144);
33
34     HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
35
36     expectedMapping.put(1, new int[] { -1, -1 });
37     expectedMapping.put(2, new int[] { -1, -1 });
38     expectedMapping.put(3, new int[] { -1, -1 });
39     expectedMapping.put(4, new int[] { -1, -1 });
40     expectedMapping.put(5, new int[] { -1, -1 });
41     expectedMapping.put(6, new int[] { -1, -1 });
42     expectedMapping.put(7, new int[] { -1, -1 });
43     expectedMapping.put(8, new int[] { -1, -1 });
44     expectedMapping.put(9, new int[] { -1, -1 });
45     expectedMapping.put(10, new int[] { -1, -1 });
46     expectedMapping.put(11, new int[] { -1, -1 });
47     expectedMapping.put(12, new int[] { -1, -1 });
48     expectedMapping.put(13, new int[] { -1, -1 });
49     expectedMapping.put(14, new int[] { -1, -1 });
50     expectedMapping.put(15, new int[] { -1, -1 });
51     expectedMapping.put(16, new int[] { -1, -1 });
52     expectedMapping.put(17, new int[] { -1, -1 });
53     expectedMapping.put(18, new int[] { -1, -1 });
54     expectedMapping.put(19, new int[] { -1, -1 });
55     expectedMapping.put(20, new int[] { -1, -1 });
56     expectedMapping.put(21, new int[] { -1, -1 });
57     expectedMapping.put(22, new int[] { -1, -1 });
58     expectedMapping.put(23, new int[] { -1, -1 });
59     expectedMapping.put(24, new int[] { -1, -1 });
60     expectedMapping.put(25, new int[] { -1, -1 });
61     expectedMapping.put(26, new int[] { -1, -1 });
62     expectedMapping.put(27, new int[] { -1, -1 });
63     expectedMapping.put(28, new int[] { -1, -1 });
64     expectedMapping.put(29, new int[] { -1, -1 });
65     expectedMapping.put(30, new int[] { -1, -1 });
66     expectedMapping.put(31, new int[] { -1, -1 });
67     expectedMapping.put(32, new int[] { -1, -1 });
68     expectedMapping.put(33, new int[] { -1, -1 });
69     expectedMapping.put(34, new int[] { -1, -1 });
70     expectedMapping.put(35, new int[] { -1, -1 });
71     expectedMapping.put(36, new int[] { -1, -1 });
72     expectedMapping.put(37, new int[] { -1, -1 });
73     expectedMapping.put(38, new int[] { -1, -1 });
74     expectedMapping.put(39, new int[] { -1, -1 });
75     expectedMapping.put(40, new int[] { -1, -1 });
76     expectedMapping.put(41, new int[] { -1, -1 });
77     expectedMapping.put(42, new int[] { -1, -1 });
78     expectedMapping.put(43, new int[] { -1, -1 });
79     expectedMapping.put(44, new int[] { -1, -1 });
80     expectedMapping.put(45, new int[] { -1, -1 });
81     expectedMapping.put(46, new int[] { -1, -1 });
82     expectedMapping.put(47, new int[] { -1, -1 });
83     // forty eight gaps in PDB sequence
84     expectedMapping.put(48, new int[] { 48, 1 });
85     expectedMapping.put(49, new int[] { 49, 6 });
86     expectedMapping.put(50, new int[] { 50, 12 });
87     expectedMapping.put(51, new int[] { 51, 24 });
88     expectedMapping.put(52, new int[] { 52, 33 });
89     expectedMapping.put(53, new int[] { 53, 40 });
90     expectedMapping.put(54, new int[] { 54, 49 });
91     expectedMapping.put(55, new int[] { 55, 57 });
92     expectedMapping.put(56, new int[] { 56, 65 });
93     expectedMapping.put(57, new int[] { 57, 72 });
94     expectedMapping.put(58, new int[] { 58, 79 });
95     expectedMapping.put(59, new int[] { 59, 87 });
96     expectedMapping.put(60, new int[] { -1, -1 });
97     expectedMapping.put(61, new int[] { -1, -1 });
98     // two gaps in PDB sequence
99     expectedMapping.put(62, new int[] { 60, -1 });
100     expectedMapping.put(63, new int[] { 61, -1 });
101     expectedMapping.put(64, new int[] { 62, 91 });
102     expectedMapping.put(65, new int[] { 63, 100 });
103     expectedMapping.put(66, new int[] { 64, 111 });
104     expectedMapping.put(67, new int[] { 65, 119 });
105     expectedMapping.put(68, new int[] { 66, 125 });
106     expectedMapping.put(69, new int[] { 67, 132 });
107     expectedMapping.put(70, new int[] { 68, 140 });
108     expectedMapping.put(71, new int[] { 69, 148 });
109     expectedMapping.put(72, new int[] { 70, 155 });
110     expectedMapping.put(73, new int[] { 71, 167 });
111     expectedMapping.put(74, new int[] { 72, 175 });
112     expectedMapping.put(75, new int[] { 73, 183 });
113     expectedMapping.put(76, new int[] { 74, 191 });
114     expectedMapping.put(77, new int[] { 75, 200 });
115     expectedMapping.put(78, new int[] { 76, 205 });
116     expectedMapping.put(79, new int[] { 77, 214 });
117     expectedMapping.put(80, new int[] { 78, 223 });
118     expectedMapping.put(81, new int[] { 79, 228 });
119     expectedMapping.put(82, new int[] { 80, 232 });
120     expectedMapping.put(83, new int[] { 81, 242 });
121     expectedMapping.put(84, new int[] { 82, 250 });
122     expectedMapping.put(85, new int[] { 83, 258 });
123     expectedMapping.put(86, new int[] { 84, 265 });
124     expectedMapping.put(87, new int[] { 85, 277 });
125     expectedMapping.put(88, new int[] { 86, 283 });
126     expectedMapping.put(89, new int[] { 87, 289 });
127     expectedMapping.put(90, new int[] { 88, 300 });
128     expectedMapping.put(91, new int[] { 89, 305 });
129     expectedMapping.put(92, new int[] { 90, 309 });
130     expectedMapping.put(93, new int[] { 91, 315 });
131     expectedMapping.put(94, new int[] { 92, 321 });
132     expectedMapping.put(95, new int[] { 93, 327 });
133     expectedMapping.put(96, new int[] { 94, 333 });
134     expectedMapping.put(97, new int[] { 95, 339 });
135     expectedMapping.put(98, new int[] { 96, 344 });
136     expectedMapping.put(99, new int[] { 97, 348 });
137     expectedMapping.put(100, new int[] { 98, 357 });
138     expectedMapping.put(101, new int[] { 99, 365 });
139     expectedMapping.put(102, new int[] { 100, 370 });
140     expectedMapping.put(103, new int[] { 101, 374 });
141     expectedMapping.put(104, new int[] { 102, 378 });
142     expectedMapping.put(105, new int[] { 103, 383 });
143     expectedMapping.put(106, new int[] { 104, 390 });
144     expectedMapping.put(107, new int[] { 105, 398 });
145     expectedMapping.put(108, new int[] { 106, 407 });
146     expectedMapping.put(109, new int[] { 107, 414 });
147     expectedMapping.put(110, new int[] { 108, 422 });
148     expectedMapping.put(111, new int[] { 109, 426 });
149     expectedMapping.put(112, new int[] { 110, 434 });
150     expectedMapping.put(113, new int[] { 111, 445 });
151     expectedMapping.put(114, new int[] { 112, 453 });
152     expectedMapping.put(115, new int[] { 113, 461 });
153     // one gap in PDB sequence
154     expectedMapping.put(116, new int[] { -1, -1 });
155     expectedMapping.put(117, new int[] { 114, 469 });
156     expectedMapping.put(118, new int[] { 115, 477 });
157     expectedMapping.put(119, new int[] { 116, -1 });
158     expectedMapping.put(120, new int[] { 117, 486 });
159     expectedMapping.put(121, new int[] { 118, 495 });
160     expectedMapping.put(122, new int[] { 119, 504 });
161     expectedMapping.put(123, new int[] { 120, 508 });
162     expectedMapping.put(124, new int[] { 121, 522 });
163     expectedMapping.put(125, new int[] { 122, 529 });
164     expectedMapping.put(126, new int[] { 123, 537 });
165     expectedMapping.put(127, new int[] { 124, 544 });
166     expectedMapping.put(128, new int[] { 125, 550 });
167     expectedMapping.put(129, new int[] { 126, 557 });
168     expectedMapping.put(130, new int[] { 127, 562 });
169     expectedMapping.put(131, new int[] { 128, 574 });
170     expectedMapping.put(132, new int[] { 129, 581 });
171     expectedMapping.put(133, new int[] { 130, 590 });
172     expectedMapping.put(134, new int[] { 131, 596 });
173     expectedMapping.put(135, new int[] { 132, 604 });
174     expectedMapping.put(136, new int[] { 133, 611 });
175     expectedMapping.put(137, new int[] { 134, 618 });
176     expectedMapping.put(138, new int[] { 135, 626 });
177     expectedMapping.put(139, new int[] { 136, 635 });
178     expectedMapping.put(140, new int[] { 137, 642 });
179     expectedMapping.put(141, new int[] { 138, 652 });
180     expectedMapping.put(142, new int[] { 139, 661 });
181     expectedMapping.put(143, new int[] { 140, 670 });
182     expectedMapping.put(144, new int[] { -1, -1 });
183
184     StructureFile structureFile;
185     try
186     {
187       structureFile = new JmolParser(phyre2ModelFile, DataSourceType.FILE);
188       phyre2Client = new Phyre2Client(structureFile);
189     } catch (IOException e1)
190     {
191       e1.printStackTrace();
192     }
193     Assert.assertNotNull(phyre2Client);
194     Assert.assertNotNull(testSeq);
195     Assert.assertNotNull(expectedMapping);
196     try
197     {
198       HashMap<Integer, int[]> actualMapping = phyre2Client
199               .getPhyre2FastaMapping(testSeq, null);
200
201       Assert.assertEquals(testSeq.getStart(), 1);
202       Assert.assertEquals(testSeq.getEnd(), 144);
203       testMappings(actualMapping, expectedMapping);
204     } catch (Exception e)
205     {
206       e.printStackTrace();
207       Assert.fail("Exception thrown while performing Phyre2 model mapping...");
208     }
209   }
210
211   @Test(groups = { "Functional" })
212   public void getPhyre2FastaMappingTest2()
213   {
214     String phyre2ModelFile = "examples/testdata/phyre2results/56da5616b4559c93/d1a70a_.pdb";
215
216     SequenceI testSeq = new Sequence(
217             "FER_CAPAN",
218             "APPPCFSSPLRLRVAVAKPLAAPMRRQLLRAQATYNVKLITPEGEVELQVPDDVYILDFAEEEGIDLPFSCRAGSCSSCAGKVVSGSVDQSDQSFLNDNQVADGWVLTCAAYPTSDVVIETHKEDDL",
219             13, 139);
220
221     HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
222
223     expectedMapping.put(13, new int[] { -1, -1 });
224     expectedMapping.put(14, new int[] { -1, -1 });
225     expectedMapping.put(15, new int[] { -1, -1 });
226     expectedMapping.put(16, new int[] { -1, -1 });
227     expectedMapping.put(17, new int[] { -1, -1 });
228     expectedMapping.put(18, new int[] { -1, -1 });
229     expectedMapping.put(19, new int[] { -1, -1 });
230     expectedMapping.put(20, new int[] { -1, -1 });
231     expectedMapping.put(21, new int[] { -1, -1 });
232     expectedMapping.put(22, new int[] { -1, -1 });
233     expectedMapping.put(23, new int[] { -1, -1 });
234     expectedMapping.put(24, new int[] { -1, -1 });
235     expectedMapping.put(25, new int[] { -1, -1 });
236     expectedMapping.put(26, new int[] { -1, -1 });
237     expectedMapping.put(27, new int[] { -1, -1 });
238     expectedMapping.put(28, new int[] { -1, -1 });
239     expectedMapping.put(29, new int[] { -1, -1 });
240     expectedMapping.put(30, new int[] { -1, -1 });
241     expectedMapping.put(31, new int[] { -1, -1 });
242     expectedMapping.put(32, new int[] { -1, -1 });
243     expectedMapping.put(33, new int[] { -1, -1 });
244     expectedMapping.put(34, new int[] { -1, -1 });
245     expectedMapping.put(35, new int[] { -1, -1 });
246     expectedMapping.put(36, new int[] { -1, -1 });
247     expectedMapping.put(37, new int[] { -1, -1 });
248     expectedMapping.put(38, new int[] { -1, -1 });
249     expectedMapping.put(39, new int[] { -1, -1 });
250     expectedMapping.put(40, new int[] { -1, -1 });
251     expectedMapping.put(41, new int[] { -1, -1 });
252     expectedMapping.put(42, new int[] { -1, -1 });
253     expectedMapping.put(43, new int[] { -1, -1 });
254     expectedMapping.put(44, new int[] { -1, -1 });
255     // thirty two gaps in PDB sequence
256     expectedMapping.put(45, new int[] { 33, 1 });
257     expectedMapping.put(46, new int[] { 34, 6 });
258     expectedMapping.put(47, new int[] { 35, 13 });
259     expectedMapping.put(48, new int[] { 36, 25 });
260     expectedMapping.put(49, new int[] { 37, 33 });
261     expectedMapping.put(50, new int[] { 38, 40 });
262     expectedMapping.put(51, new int[] { 39, 49 });
263     expectedMapping.put(52, new int[] { 40, 57 });
264     expectedMapping.put(53, new int[] { 41, 65 });
265     expectedMapping.put(54, new int[] { 42, 72 });
266     expectedMapping.put(55, new int[] { 43, 79 });
267     expectedMapping.put(56, new int[] { 44, 88 });
268     expectedMapping.put(57, new int[] { 45, 92 });
269     expectedMapping.put(58, new int[] { 46, 101 });
270     expectedMapping.put(59, new int[] { 47, 108 });
271     expectedMapping.put(60, new int[] { 48, 117 });
272     expectedMapping.put(61, new int[] { 49, 125 });
273     expectedMapping.put(62, new int[] { 50, 134 });
274     expectedMapping.put(63, new int[] { 51, 141 });
275     expectedMapping.put(64, new int[] { 52, 148 });
276     expectedMapping.put(65, new int[] { 53, 156 });
277     expectedMapping.put(66, new int[] { 54, 164 });
278     expectedMapping.put(67, new int[] { 55, 171 });
279     expectedMapping.put(68, new int[] { 56, 183 });
280     expectedMapping.put(69, new int[] { 57, 191 });
281     expectedMapping.put(70, new int[] { 58, 199 });
282     expectedMapping.put(71, new int[] { 59, 207 });
283     expectedMapping.put(72, new int[] { 60, 218 });
284     expectedMapping.put(73, new int[] { 61, 223 });
285     expectedMapping.put(74, new int[] { 62, 232 });
286     expectedMapping.put(75, new int[] { 63, 241 });
287     expectedMapping.put(76, new int[] { 64, 250 });
288     expectedMapping.put(77, new int[] { 65, 254 });
289     expectedMapping.put(78, new int[] { 66, 262 });
290     expectedMapping.put(79, new int[] { 67, 270 });
291     expectedMapping.put(80, new int[] { 68, 278 });
292     expectedMapping.put(81, new int[] { 69, 285 });
293     expectedMapping.put(82, new int[] { 70, 296 });
294     expectedMapping.put(83, new int[] { 71, 302 });
295     expectedMapping.put(84, new int[] { 72, 308 });
296     expectedMapping.put(85, new int[] { 73, 319 });
297     expectedMapping.put(86, new int[] { 74, 324 });
298     expectedMapping.put(87, new int[] { 75, 328 });
299     expectedMapping.put(88, new int[] { 76, 334 });
300     expectedMapping.put(89, new int[] { 77, 340 });
301     expectedMapping.put(90, new int[] { 78, 346 });
302     expectedMapping.put(91, new int[] { 79, 352 });
303     expectedMapping.put(92, new int[] { 80, 358 });
304     expectedMapping.put(93, new int[] { 81, 363 });
305     expectedMapping.put(94, new int[] { 82, 367 });
306     expectedMapping.put(95, new int[] { 83, 376 });
307     expectedMapping.put(96, new int[] { 84, 383 });
308     expectedMapping.put(97, new int[] { 85, 390 });
309     expectedMapping.put(98, new int[] { 86, 396 });
310     expectedMapping.put(99, new int[] { 87, 400 });
311     expectedMapping.put(100, new int[] { 88, 406 });
312     expectedMapping.put(101, new int[] { 89, 413 });
313     expectedMapping.put(102, new int[] { 90, 421 });
314     expectedMapping.put(103, new int[] { 91, 430 });
315     expectedMapping.put(104, new int[] { 92, 436 });
316     expectedMapping.put(105, new int[] { 93, 444 });
317     expectedMapping.put(106, new int[] { 94, 453 });
318     expectedMapping.put(107, new int[] { 95, 459 });
319     expectedMapping.put(108, new int[] { 96, 470 });
320     expectedMapping.put(109, new int[] { 97, 478 });
321     expectedMapping.put(110, new int[] { 98, 486 });
322     expectedMapping.put(111, new int[] { 99, 494 });
323     expectedMapping.put(112, new int[] { 100, 502 });
324     expectedMapping.put(113, new int[] { 101, 511 });
325     expectedMapping.put(114, new int[] { 102, 518 });
326     expectedMapping.put(115, new int[] { 103, 523 });
327     expectedMapping.put(116, new int[] { 104, 531 });
328     expectedMapping.put(117, new int[] { 105, 535 });
329     expectedMapping.put(118, new int[] { 106, 549 });
330     expectedMapping.put(119, new int[] { 107, 556 });
331     expectedMapping.put(120, new int[] { 108, 564 });
332     expectedMapping.put(121, new int[] { 109, 571 });
333     expectedMapping.put(122, new int[] { 110, 577 });
334     expectedMapping.put(123, new int[] { 111, 582 });
335     expectedMapping.put(124, new int[] { 112, 587 });
336     expectedMapping.put(125, new int[] { 113, 599 });
337     expectedMapping.put(126, new int[] { 114, 606 });
338     expectedMapping.put(127, new int[] { 115, 613 });
339     expectedMapping.put(128, new int[] { 116, 619 });
340     expectedMapping.put(129, new int[] { 117, 627 });
341     expectedMapping.put(130, new int[] { 118, 634 });
342     expectedMapping.put(131, new int[] { 119, 641 });
343     expectedMapping.put(132, new int[] { 120, 649 });
344     expectedMapping.put(133, new int[] { 121, 658 });
345     expectedMapping.put(134, new int[] { 122, 665 });
346     expectedMapping.put(135, new int[] { 123, 675 });
347     expectedMapping.put(136, new int[] { 124, 684 });
348     expectedMapping.put(137, new int[] { 125, 693 });
349     expectedMapping.put(138, new int[] { 126, 701 });
350     expectedMapping.put(139, new int[] { 127, 709 });
351
352     StructureFile structureFile;
353     try
354     {
355       structureFile = new JmolParser(phyre2ModelFile, DataSourceType.FILE);
356       phyre2Client = new Phyre2Client(structureFile);
357     } catch (IOException e1)
358     {
359       e1.printStackTrace();
360     }
361     Assert.assertNotNull(phyre2Client);
362     Assert.assertNotNull(testSeq);
363     Assert.assertNotNull(expectedMapping);
364     try
365     {
366       HashMap<Integer, int[]> actualMapping = phyre2Client
367               .getPhyre2FastaMapping(testSeq, null);
368
369       Assert.assertEquals(testSeq.getStart(), 13);
370       Assert.assertEquals(testSeq.getEnd(), 139);
371       testMappings(actualMapping, expectedMapping);
372     } catch (Exception e)
373     {
374       e.printStackTrace();
375       Assert.fail("Exception thrown while performing Phyre2 model mapping...");
376     }
377   }
378
379   public void testMappings(HashMap<Integer, int[]> actualMapping,
380           HashMap<Integer, int[]> expectedMapping)
381   {
382     System.out.println("Expected Mapping size: " + expectedMapping.size());
383     System.out.println("Actual   Mapping size: " + actualMapping.size());
384     // Test size
385     Assert.assertEquals(actualMapping.size(), expectedMapping.size());
386     // Test key set
387     Assert.assertEquals(actualMapping.keySet(), expectedMapping.keySet());
388     // Test entry set
389     for (int key : expectedMapping.keySet())
390     {
391       Assert.assertTrue(Arrays.equals(expectedMapping.get(key),
392               actualMapping.get(key)));
393     }
394   }
395
396
397 }