package jalview.ws.phyre2; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolParser; import jalview.io.DataSourceType; import jalview.io.StructureFile; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import org.testng.Assert; import org.testng.annotations.Test; public class Phyre2ClientTest { private Phyre2Client phyre2Client = null; @Test(groups = { "Functional" }) public void getPhyre2FastaMappingTest() { String phyre2ModelFile = "examples/testdata/phyre2results/56da5616b4559c93/c4n58A_.1.pdb"; String fastaMappingFile = "examples/testdata/phyre2results/56da5616b4559c93/c4n58A_.1.fasta"; SequenceI testSeq = new Sequence( "FER_CAPAN", "MASVSATMISTSFMPRKPAVTSLKPIPNVGEALFGLKSANGGKVTCMASYKVKLITPDGPIEF" + "DCPDNVYILDQAEEAGHDLPYSCRAGSCSSCAGKIAGGAVDQTDGNFLDDDQL" + "EEGWVLTCVAYPQSDVTIETHKEAELVG", 1, 144); HashMap expectedMapping = new HashMap(); // PDB sequence starts with residue 48 expectedMapping.put(48, new int[] { 48, 1 }); expectedMapping.put(49, new int[] { 49, 6 }); expectedMapping.put(50, new int[] { 50, 12 }); expectedMapping.put(51, new int[] { 51, 24 }); expectedMapping.put(52, new int[] { 52, 33 }); expectedMapping.put(53, new int[] { 53, 40 }); expectedMapping.put(54, new int[] { 54, 49 }); expectedMapping.put(55, new int[] { 55, 57 }); expectedMapping.put(56, new int[] { 56, 65 }); expectedMapping.put(57, new int[] { 57, 72 }); expectedMapping.put(58, new int[] { 58, 79 }); expectedMapping.put(59, new int[] { 59, 87 }); // residues 60, 61 absent in PDB file // residues 62, 63 also skipped in map (is this right?) expectedMapping.put(64, new int[] { 62, 91 }); expectedMapping.put(65, new int[] { 63, 100 }); expectedMapping.put(66, new int[] { 64, 111 }); expectedMapping.put(67, new int[] { 65, 119 }); expectedMapping.put(68, new int[] { 66, 125 }); expectedMapping.put(69, new int[] { 67, 132 }); expectedMapping.put(70, new int[] { 68, 140 }); expectedMapping.put(71, new int[] { 69, 148 }); expectedMapping.put(72, new int[] { 70, 155 }); expectedMapping.put(73, new int[] { 71, 167 }); expectedMapping.put(74, new int[] { 72, 175 }); expectedMapping.put(75, new int[] { 73, 183 }); expectedMapping.put(76, new int[] { 74, 191 }); expectedMapping.put(77, new int[] { 75, 200 }); expectedMapping.put(78, new int[] { 76, 205 }); expectedMapping.put(79, new int[] { 77, 214 }); expectedMapping.put(80, new int[] { 78, 223 }); expectedMapping.put(81, new int[] { 79, 228 }); expectedMapping.put(82, new int[] { 80, 232 }); expectedMapping.put(83, new int[] { 81, 242 }); expectedMapping.put(84, new int[] { 82, 250 }); expectedMapping.put(85, new int[] { 83, 258 }); expectedMapping.put(86, new int[] { 84, 265 }); expectedMapping.put(87, new int[] { 85, 277 }); expectedMapping.put(88, new int[] { 86, 283 }); expectedMapping.put(89, new int[] { 87, 289 }); expectedMapping.put(90, new int[] { 88, 300 }); expectedMapping.put(91, new int[] { 89, 305 }); expectedMapping.put(92, new int[] { 90, 309 }); expectedMapping.put(93, new int[] { 91, 315 }); expectedMapping.put(94, new int[] { 92, 321 }); expectedMapping.put(95, new int[] { 93, 327 }); expectedMapping.put(96, new int[] { 94, 333 }); expectedMapping.put(97, new int[] { 95, 339 }); expectedMapping.put(98, new int[] { 96, 344 }); expectedMapping.put(99, new int[] { 97, 348 }); expectedMapping.put(100, new int[] { 98, 357 }); expectedMapping.put(101, new int[] { 99, 365 }); expectedMapping.put(102, new int[] { 100, 370 }); expectedMapping.put(103, new int[] { 101, 374 }); expectedMapping.put(104, new int[] { 102, 378 }); expectedMapping.put(105, new int[] { 103, 383 }); expectedMapping.put(106, new int[] { 104, 390 }); expectedMapping.put(107, new int[] { 105, 398 }); expectedMapping.put(108, new int[] { 106, 407 }); expectedMapping.put(109, new int[] { 107, 414 }); expectedMapping.put(110, new int[] { 108, 422 }); expectedMapping.put(111, new int[] { 109, 426 }); expectedMapping.put(112, new int[] { 110, 434 }); expectedMapping.put(113, new int[] { 111, 445 }); expectedMapping.put(114, new int[] { 112, 453 }); expectedMapping.put(115, new int[] { 113, 461 }); // residue 116 absent in PDB file expectedMapping.put(117, new int[] { 114, 469 }); expectedMapping.put(118, new int[] { 115, 477 }); // residue 119 gets removed as mapped to 116 - is this right? expectedMapping.put(120, new int[] { 117, 486 }); expectedMapping.put(121, new int[] { 118, 495 }); expectedMapping.put(122, new int[] { 119, 504 }); expectedMapping.put(123, new int[] { 120, 508 }); expectedMapping.put(124, new int[] { 121, 522 }); expectedMapping.put(125, new int[] { 122, 529 }); expectedMapping.put(126, new int[] { 123, 537 }); expectedMapping.put(127, new int[] { 124, 544 }); expectedMapping.put(128, new int[] { 125, 550 }); expectedMapping.put(129, new int[] { 126, 557 }); expectedMapping.put(130, new int[] { 127, 562 }); expectedMapping.put(131, new int[] { 128, 574 }); expectedMapping.put(132, new int[] { 129, 581 }); expectedMapping.put(133, new int[] { 130, 590 }); expectedMapping.put(134, new int[] { 131, 596 }); expectedMapping.put(135, new int[] { 132, 604 }); expectedMapping.put(136, new int[] { 133, 611 }); expectedMapping.put(137, new int[] { 134, 618 }); expectedMapping.put(138, new int[] { 135, 626 }); expectedMapping.put(139, new int[] { 136, 635 }); expectedMapping.put(140, new int[] { 137, 642 }); expectedMapping.put(141, new int[] { 138, 652 }); expectedMapping.put(142, new int[] { 139, 661 }); expectedMapping.put(143, new int[] { 140, 670 }); // residue 144 absent in PDB file StructureFile structureFile; try { structureFile = new JmolParser(phyre2ModelFile, DataSourceType.FILE); phyre2Client = new Phyre2Client(structureFile); phyre2Client.setFastaMappingFile(fastaMappingFile); } catch (IOException e1) { e1.printStackTrace(); } Assert.assertNotNull(phyre2Client); Assert.assertNotNull(testSeq); Assert.assertNotNull(expectedMapping); try { HashMap actualMapping = phyre2Client .getPhyre2FastaMapping(testSeq, null); Assert.assertEquals(testSeq.getStart(), 1); Assert.assertEquals(testSeq.getEnd(), 144); testMappings(actualMapping, expectedMapping); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown while performing Phyre2 model mapping..."); } } @Test(groups = { "Functional" }) public void getPhyre2FastaMappingTest2() { String phyre2ModelFile = "examples/testdata/phyre2results/56da5616b4559c93/d1a70a_.pdb"; String fastaMappingFile = "examples/testdata/phyre2results/56da5616b4559c93/d1a70a_.fasta"; SequenceI testSeq = new Sequence( "FER_CAPAN", "APPPCFSSPLRLRVAVAKPLAAPMRRQLLRAQATYNVKLITPEGEVELQVPDDVYILDFAEEEGIDLPFSCRAGSCSSCAGKVVSGSVDQSDQSFLNDNQVADGWVLTCAAYPTSDVVIETHKEDDL", 13, 139); HashMap expectedMapping = new HashMap(); // PDB sequence starts with residue 33 expectedMapping.put(45, new int[] { 33, 1 }); expectedMapping.put(46, new int[] { 34, 6 }); expectedMapping.put(47, new int[] { 35, 13 }); expectedMapping.put(48, new int[] { 36, 25 }); expectedMapping.put(49, new int[] { 37, 33 }); expectedMapping.put(50, new int[] { 38, 40 }); expectedMapping.put(51, new int[] { 39, 49 }); expectedMapping.put(52, new int[] { 40, 57 }); expectedMapping.put(53, new int[] { 41, 65 }); expectedMapping.put(54, new int[] { 42, 72 }); expectedMapping.put(55, new int[] { 43, 79 }); expectedMapping.put(56, new int[] { 44, 88 }); expectedMapping.put(57, new int[] { 45, 92 }); expectedMapping.put(58, new int[] { 46, 101 }); expectedMapping.put(59, new int[] { 47, 108 }); expectedMapping.put(60, new int[] { 48, 117 }); expectedMapping.put(61, new int[] { 49, 125 }); expectedMapping.put(62, new int[] { 50, 134 }); expectedMapping.put(63, new int[] { 51, 141 }); expectedMapping.put(64, new int[] { 52, 148 }); expectedMapping.put(65, new int[] { 53, 156 }); expectedMapping.put(66, new int[] { 54, 164 }); expectedMapping.put(67, new int[] { 55, 171 }); expectedMapping.put(68, new int[] { 56, 183 }); expectedMapping.put(69, new int[] { 57, 191 }); expectedMapping.put(70, new int[] { 58, 199 }); expectedMapping.put(71, new int[] { 59, 207 }); expectedMapping.put(72, new int[] { 60, 218 }); expectedMapping.put(73, new int[] { 61, 223 }); expectedMapping.put(74, new int[] { 62, 232 }); expectedMapping.put(75, new int[] { 63, 241 }); expectedMapping.put(76, new int[] { 64, 250 }); expectedMapping.put(77, new int[] { 65, 254 }); expectedMapping.put(78, new int[] { 66, 262 }); expectedMapping.put(79, new int[] { 67, 270 }); expectedMapping.put(80, new int[] { 68, 278 }); expectedMapping.put(81, new int[] { 69, 285 }); expectedMapping.put(82, new int[] { 70, 296 }); expectedMapping.put(83, new int[] { 71, 302 }); expectedMapping.put(84, new int[] { 72, 308 }); expectedMapping.put(85, new int[] { 73, 319 }); expectedMapping.put(86, new int[] { 74, 324 }); expectedMapping.put(87, new int[] { 75, 328 }); expectedMapping.put(88, new int[] { 76, 334 }); expectedMapping.put(89, new int[] { 77, 340 }); expectedMapping.put(90, new int[] { 78, 346 }); expectedMapping.put(91, new int[] { 79, 352 }); expectedMapping.put(92, new int[] { 80, 358 }); expectedMapping.put(93, new int[] { 81, 363 }); expectedMapping.put(94, new int[] { 82, 367 }); expectedMapping.put(95, new int[] { 83, 376 }); expectedMapping.put(96, new int[] { 84, 383 }); expectedMapping.put(97, new int[] { 85, 390 }); expectedMapping.put(98, new int[] { 86, 396 }); expectedMapping.put(99, new int[] { 87, 400 }); expectedMapping.put(100, new int[] { 88, 406 }); expectedMapping.put(101, new int[] { 89, 413 }); expectedMapping.put(102, new int[] { 90, 421 }); expectedMapping.put(103, new int[] { 91, 430 }); expectedMapping.put(104, new int[] { 92, 436 }); expectedMapping.put(105, new int[] { 93, 444 }); expectedMapping.put(106, new int[] { 94, 453 }); expectedMapping.put(107, new int[] { 95, 459 }); expectedMapping.put(108, new int[] { 96, 470 }); expectedMapping.put(109, new int[] { 97, 478 }); expectedMapping.put(110, new int[] { 98, 486 }); expectedMapping.put(111, new int[] { 99, 494 }); expectedMapping.put(112, new int[] { 100, 502 }); expectedMapping.put(113, new int[] { 101, 511 }); expectedMapping.put(114, new int[] { 102, 518 }); expectedMapping.put(115, new int[] { 103, 523 }); expectedMapping.put(116, new int[] { 104, 531 }); expectedMapping.put(117, new int[] { 105, 535 }); expectedMapping.put(118, new int[] { 106, 549 }); expectedMapping.put(119, new int[] { 107, 556 }); expectedMapping.put(120, new int[] { 108, 564 }); expectedMapping.put(121, new int[] { 109, 571 }); expectedMapping.put(122, new int[] { 110, 577 }); expectedMapping.put(123, new int[] { 111, 582 }); expectedMapping.put(124, new int[] { 112, 587 }); expectedMapping.put(125, new int[] { 113, 599 }); expectedMapping.put(126, new int[] { 114, 606 }); expectedMapping.put(127, new int[] { 115, 613 }); expectedMapping.put(128, new int[] { 116, 619 }); expectedMapping.put(129, new int[] { 117, 627 }); expectedMapping.put(130, new int[] { 118, 634 }); expectedMapping.put(131, new int[] { 119, 641 }); expectedMapping.put(132, new int[] { 120, 649 }); expectedMapping.put(133, new int[] { 121, 658 }); expectedMapping.put(134, new int[] { 122, 665 }); expectedMapping.put(135, new int[] { 123, 675 }); expectedMapping.put(136, new int[] { 124, 684 }); expectedMapping.put(137, new int[] { 125, 693 }); expectedMapping.put(138, new int[] { 126, 701 }); expectedMapping.put(139, new int[] { 127, 709 }); StructureFile structureFile; try { structureFile = new JmolParser(phyre2ModelFile, DataSourceType.FILE); phyre2Client = new Phyre2Client(structureFile); phyre2Client.setFastaMappingFile(fastaMappingFile); } catch (IOException e1) { e1.printStackTrace(); } Assert.assertNotNull(phyre2Client); Assert.assertNotNull(testSeq); Assert.assertNotNull(expectedMapping); try { HashMap actualMapping = phyre2Client .getPhyre2FastaMapping(testSeq, null); Assert.assertEquals(testSeq.getStart(), 13); Assert.assertEquals(testSeq.getEnd(), 139); Assert.assertEquals(actualMapping, expectedMapping); testMappings(actualMapping, expectedMapping); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown while performing Phyre2 model mapping..."); } } public void testMappings(HashMap actualMapping, HashMap expectedMapping) { System.out.println("Expected Mapping size: " + expectedMapping.size()); System.out.println("Actual Mapping size: " + actualMapping.size()); // Test size Assert.assertEquals(actualMapping.size(), expectedMapping.size()); // Test key set Assert.assertEquals(actualMapping.keySet(), expectedMapping.keySet()); // Test entry set for (int key : expectedMapping.keySet()) { System.out.println(key + " ---> [" + expectedMapping.get(key)[0] + ", " + expectedMapping.get(key)[1] + "] = [" + actualMapping.get(key)[0] + ", " + actualMapping.get(key)[1] + "]"); Assert.assertTrue(Arrays.equals(expectedMapping.get(key), actualMapping.get(key))); } } }