2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ws.sifts;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
26 import jalview.api.DBRefEntryI;
27 import jalview.bin.Cache;
28 import jalview.datamodel.DBRefEntry;
29 import jalview.datamodel.DBRefSource;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceI;
32 import jalview.gui.JvOptionPane;
33 import jalview.io.DataSourceType;
34 import jalview.structure.StructureMapping;
35 import jalview.structure.StructureMappingClient.StructureMappingException;
36 import jalview.xml.binding.sifts.Entry.Entity;
39 import java.io.IOException;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.HashMap;
43 import java.util.Iterator;
46 import org.testng.Assert;
47 import org.testng.FileAssert;
48 import org.testng.annotations.AfterTest;
49 import org.testng.annotations.BeforeClass;
50 import org.testng.annotations.BeforeTest;
51 import org.testng.annotations.Test;
54 import MCview.PDBfile;
56 public class SiftsClientTest
59 @BeforeClass(alwaysRun = true)
60 public void setUpJvOptionPane()
62 JvOptionPane.setInteractiveMode(false);
63 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
66 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
67 .getProperty("user.home")
69 + ".sifts_downloads" + File.separatorChar;
71 private String testPDBId = "1a70";
73 private SiftsClient siftsClient = null;
75 SequenceI testSeq = new Sequence(
77 "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
78 + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
79 + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
81 int u = SiftsClient.UNASSIGNED;
83 HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
85 @BeforeTest(alwaysRun = true)
86 public void populateExpectedMapping() throws SiftsException
88 expectedMapping.put(51, new int[] { 1, 2 });
89 expectedMapping.put(52, new int[] { 2, 7 });
90 expectedMapping.put(53, new int[] { 3, 12 });
91 expectedMapping.put(54, new int[] { 4, 24 });
92 expectedMapping.put(55, new int[] { 5, 33 });
93 expectedMapping.put(56, new int[] { 6, 40 });
94 expectedMapping.put(57, new int[] { 7, 47 });
95 expectedMapping.put(58, new int[] { 8, 55 });
96 expectedMapping.put(59, new int[] { 9, 62 });
97 expectedMapping.put(60, new int[] { 10, 69 });
98 expectedMapping.put(61, new int[] { 11, 76 });
99 expectedMapping.put(62, new int[] { 12, 83 });
100 expectedMapping.put(63, new int[] { 13, 87 });
101 expectedMapping.put(64, new int[] { 14, 95 });
102 expectedMapping.put(65, new int[] { 15, 102 });
103 expectedMapping.put(66, new int[] { 16, 111 });
104 expectedMapping.put(67, new int[] { 17, 122 });
105 expectedMapping.put(68, new int[] { 18, 131 });
106 expectedMapping.put(69, new int[] { 19, 137 });
107 expectedMapping.put(70, new int[] { 20, 144 });
108 expectedMapping.put(71, new int[] { 21, 152 });
109 expectedMapping.put(72, new int[] { 22, 160 });
110 expectedMapping.put(73, new int[] { 23, 167 });
111 expectedMapping.put(74, new int[] { 24, 179 });
112 expectedMapping.put(75, new int[] { 25, 187 });
113 expectedMapping.put(76, new int[] { 26, 195 });
114 expectedMapping.put(77, new int[] { 27, 203 });
115 expectedMapping.put(78, new int[] { 28, 208 });
116 expectedMapping.put(79, new int[] { 29, 213 });
117 expectedMapping.put(80, new int[] { 30, 222 });
118 expectedMapping.put(81, new int[] { 31, 231 });
119 expectedMapping.put(82, new int[] { 32, 240 });
120 expectedMapping.put(83, new int[] { 33, 244 });
121 expectedMapping.put(84, new int[] { 34, 252 });
122 expectedMapping.put(85, new int[] { 35, 260 });
123 expectedMapping.put(86, new int[] { 36, 268 });
124 expectedMapping.put(87, new int[] { 37, 275 });
125 expectedMapping.put(88, new int[] { 38, 287 });
126 expectedMapping.put(89, new int[] { 39, 293 });
127 expectedMapping.put(90, new int[] { 40, 299 });
128 expectedMapping.put(91, new int[] { 41, 310 });
129 expectedMapping.put(92, new int[] { 42, 315 });
130 expectedMapping.put(93, new int[] { 43, 319 });
131 expectedMapping.put(94, new int[] { 44, 325 });
132 expectedMapping.put(95, new int[] { 45, 331 });
133 expectedMapping.put(96, new int[] { 46, 337 });
134 expectedMapping.put(97, new int[] { 47, 343 });
135 expectedMapping.put(98, new int[] { 48, 349 });
136 expectedMapping.put(99, new int[] { 49, 354 });
137 expectedMapping.put(100, new int[] { 50, 358 });
138 expectedMapping.put(101, new int[] { 51, 367 });
139 expectedMapping.put(102, new int[] { 52, 375 });
140 expectedMapping.put(103, new int[] { 53, 384 });
141 expectedMapping.put(104, new int[] { 54, 391 });
142 expectedMapping.put(105, new int[] { 55, 395 });
143 expectedMapping.put(106, new int[] { 56, 401 });
144 expectedMapping.put(107, new int[] { 57, 409 });
145 expectedMapping.put(108, new int[] { 58, 417 });
146 expectedMapping.put(109, new int[] { 59, 426 });
147 expectedMapping.put(110, new int[] { 60, 434 });
148 expectedMapping.put(111, new int[] { 61, 442 });
149 expectedMapping.put(112, new int[] { 62, 451 });
150 expectedMapping.put(113, new int[] { 63, 457 });
151 expectedMapping.put(114, new int[] { 64, 468 });
152 expectedMapping.put(115, new int[] { 65, 476 });
153 expectedMapping.put(116, new int[] { 66, 484 });
154 expectedMapping.put(117, new int[] { 67, 492 });
155 expectedMapping.put(118, new int[] { 68, 500 });
156 expectedMapping.put(119, new int[] { 69, 509 });
157 expectedMapping.put(120, new int[] { 70, 517 });
158 expectedMapping.put(121, new int[] { 71, 525 });
159 expectedMapping.put(122, new int[] { 72, 534 });
160 expectedMapping.put(123, new int[] { 73, 538 });
161 expectedMapping.put(124, new int[] { 74, 552 });
162 expectedMapping.put(125, new int[] { 75, 559 });
163 expectedMapping.put(126, new int[] { 76, 567 });
164 expectedMapping.put(127, new int[] { 77, 574 });
165 expectedMapping.put(128, new int[] { 78, 580 });
166 expectedMapping.put(129, new int[] { 79, 585 });
167 expectedMapping.put(130, new int[] { 80, 590 });
168 expectedMapping.put(131, new int[] { 81, 602 });
169 expectedMapping.put(132, new int[] { 82, 609 });
170 expectedMapping.put(133, new int[] { 83, 616 });
171 expectedMapping.put(134, new int[] { 84, 622 });
172 expectedMapping.put(135, new int[] { 85, 630 });
173 expectedMapping.put(136, new int[] { 86, 637 });
174 expectedMapping.put(137, new int[] { 87, 644 });
175 expectedMapping.put(138, new int[] { 88, 652 });
176 expectedMapping.put(139, new int[] { 89, 661 });
177 expectedMapping.put(140, new int[] { 90, 668 });
178 expectedMapping.put(141, new int[] { 91, 678 });
179 expectedMapping.put(142, new int[] { 92, 687 });
180 expectedMapping.put(143, new int[] { 93, 696 });
181 expectedMapping.put(144, new int[] { 94, 705 });
182 expectedMapping.put(145, new int[] { 95, 714 });
183 expectedMapping.put(146, new int[] { 96, 722 });
184 expectedMapping.put(147, new int[] { 97, 729 });
187 @BeforeTest(alwaysRun = true)
188 public void setUpSiftsClient() throws SiftsException, IOException
190 // read test props before manipulating config
191 Cache.loadProperties("test/jalview/io/testProps.jvprops");
192 // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
193 // test reproducibility
195 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
196 "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
197 SiftsSettings.setMapWithSifts(true);
198 SiftsSettings.setCacheThresholdInDays("2");
199 SiftsSettings.setFailSafePIDThreshold("70");
201 pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
202 + testPDBId + ".pdb", DataSourceType.FILE);
203 siftsClient = new SiftsClient(pdbFile);
206 @AfterTest(alwaysRun = true)
207 public void cleanUpSiftsClient()
212 @Test(groups = { "Network" })
213 public void getSIFTsFileTest() throws SiftsException, IOException
216 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
217 FileAssert.assertFile(siftsFile);
218 long t1 = siftsFile.lastModified();
220 // re-read file should be returned from cache
221 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
222 FileAssert.assertFile(siftsFile);
223 long t2 = siftsFile.lastModified();
224 assertEquals(t1, t2);
227 * force fetch by having 0 expiry of cache
228 * also wait one second, because file timestamp does not
229 * give millisecond resolution :-(
236 } catch (InterruptedException e)
240 SiftsSettings.setCacheThresholdInDays("0");
241 siftsFile = SiftsClient.getSiftsFile(testPDBId);
242 FileAssert.assertFile(siftsFile);
243 long t3 = siftsFile.lastModified();
244 assertTrue(t3 > t2, "file timestamp unchanged at " + t3);
246 SiftsSettings.setCacheThresholdInDays("2");
249 @Test(groups = { "Network" })
250 public void downloadSiftsFileTest() throws SiftsException, IOException
252 // Assert that file isn't yet downloaded - if already downloaded, assert it
254 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
256 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
257 FileAssert.assertFile(siftsFile);
258 SiftsClient.downloadSiftsFile(testPDBId);
261 @Test(groups = { "Network" })
262 public void getAllMappingAccessionTest()
264 Assert.assertNotNull(siftsClient);
265 Assert.assertNotNull(siftsClient.getAllMappingAccession());
266 Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
269 @Test(groups = { "Network" })
270 public void getGreedyMappingTest()
272 Assert.assertNotNull(siftsClient);
273 Assert.assertNotNull(testSeq);
274 Assert.assertNotNull(expectedMapping);
276 // TODO delete when auto-fetching of DBRefEntry is implemented
277 DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
278 testSeq.addDBRef(dbRef);
279 // testSeq.setSourceDBRef(dbRef);
283 HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
285 Assert.assertEquals(testSeq.getStart(), 1);
286 Assert.assertEquals(testSeq.getEnd(), 147);
288 // Can't do Assert.assertEquals(actualMapping, expectedMapping);
289 // because this fails in our version of TestNG
290 Assert.assertEquals(actualMapping.size(), expectedMapping.size());
291 Iterator<Map.Entry<Integer, int[]>> it = expectedMapping.entrySet()
295 Map.Entry<Integer, int[]> pair = it.next();
296 Assert.assertTrue(actualMapping.containsKey(pair.getKey()));
297 Assert.assertEquals(actualMapping.get(pair.getKey()),
302 // Assert.assertEquals(actualMapping, expectedMapping);
303 Assert.assertEquals(actualMapping.size(), expectedMapping.size());
305 Assert.assertEquals(actualMapping.keySet(), expectedMapping.keySet());
307 for (int key : expectedMapping.keySet())
309 Assert.assertTrue(Arrays.equals(expectedMapping.get(key),
310 actualMapping.get(key)));
312 >>>>>>> f80180a53bf16dc72ecdd4ace0f70c83cb0d274a
313 } catch (Exception e)
316 Assert.fail("Exception thrown while generating mapping...");
320 @Test(groups = { "Network" })
321 private void getAtomIndexTest()
323 ArrayList<Atom> atoms = new ArrayList<Atom>();
324 Atom atom = new Atom(u, u, u);
328 int actualAtomIndex = siftsClient.getAtomIndex(1, atoms);
329 Assert.assertEquals(actualAtomIndex, -1);
330 actualAtomIndex = siftsClient.getAtomIndex(43, atoms);
331 Assert.assertEquals(actualAtomIndex, 7);
335 groups = { "Network" },
336 expectedExceptions = IllegalArgumentException.class)
337 private void getAtomIndexNullTest()
339 siftsClient.getAtomIndex(1, null);
342 @Test(groups = { "Network" })
343 private void padWithGapsTest()
349 groups = { "Network" },
350 expectedExceptions = StructureMappingException.class)
351 private void populateAtomPositionsNullTest1()
352 throws IllegalArgumentException, StructureMappingException
354 siftsClient.populateAtomPositions(null, null);
358 groups = { "Network" },
359 expectedExceptions = StructureMappingException.class)
360 private void populateAtomPositionsNullTest2()
361 throws IllegalArgumentException, StructureMappingException
363 siftsClient.populateAtomPositions("A", null);
366 @Test(groups = { "Network" })
367 public void getValidSourceDBRefTest() throws SiftsException
369 DBRefEntryI actualValidSrcDBRef = siftsClient
370 .getValidSourceDBRef(testSeq);
371 DBRefEntryI expectedDBRef = new DBRefEntry();
372 expectedDBRef.setSource(DBRefSource.UNIPROT);
373 expectedDBRef.setAccessionId("P00221");
374 expectedDBRef.setVersion("");
375 Assert.assertEquals(actualValidSrcDBRef, expectedDBRef);
379 groups = { "Network" },
380 expectedExceptions = SiftsException.class)
381 public void getValidSourceDBRefExceptionTest() throws SiftsException
383 SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
384 siftsClient.getValidSourceDBRef(invalidTestSeq);
388 groups = { "Network" },
389 expectedExceptions = SiftsException.class)
390 public void getValidSourceDBRefExceptionXTest() throws SiftsException
392 SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
393 DBRefEntry invalidDBRef = new DBRefEntry();
394 invalidDBRef.setAccessionId("BLAR");
395 invalidTestSeq.addDBRef(invalidDBRef);
396 siftsClient.getValidSourceDBRef(invalidTestSeq);
399 @Test(groups = { "Network" })
400 public void isValidDBRefEntryTest()
402 DBRefEntryI validDBRef = new DBRefEntry();
403 validDBRef.setSource(DBRefSource.UNIPROT);
404 validDBRef.setAccessionId("P00221");
405 validDBRef.setVersion("");
406 Assert.assertTrue(siftsClient.isValidDBRefEntry(validDBRef));
409 @Test(groups = { "Network" })
410 public void getSiftsStructureMappingTest()
411 throws StructureMappingException, Exception
413 Assert.assertTrue(SiftsSettings.isMapWithSifts());
414 StructureMapping strucMapping = siftsClient.getStructureMapping(
415 testSeq, testPDBId, "A");
416 String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
417 + "Method: SIFTS\n\n"
418 + "P00221 : 51 - 147 Maps to \n"
419 + "1A70|A : 1 - 97\n\n"
420 + "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
421 + " |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
422 + "1A70|A AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n\n"
424 + "P00221 DDQIDEGWVLTCAAYPVSDVTIETHKEEELTA\n"
425 + " |||||||||||||||||||||||||| |||||\n"
426 + "1A70|A DDQIDEGWVLTCAAYPVSDVTIETHKKEELTA\n\n" +
428 "Length of alignment = 97\n" + "Percentage ID = 98.97\n";
430 Assert.assertEquals(strucMapping.getMappingDetailsOutput(),
431 expectedMappingOutput);
434 // Can't do Assert.assertEquals(strucMapping.getMapping(), expectedMapping);
435 // because this fails in our version of TestNG
436 Assert.assertEquals(strucMapping.getMapping().size(),
437 expectedMapping.size());
438 Iterator<Map.Entry<Integer, int[]>> it = expectedMapping.entrySet()
442 Map.Entry<Integer, int[]> pair = it.next();
443 Assert.assertTrue(strucMapping.getMapping()
444 .containsKey(pair.getKey()));
445 Assert.assertEquals(strucMapping.getMapping().get(pair.getKey()),
448 // Assert.assertEquals(strucMapping.getMapping(), expectedMapping);
449 Assert.assertEquals(strucMapping.getMapping().size(),
450 expectedMapping.size());
452 Assert.assertEquals(strucMapping.getMapping().keySet(),
453 expectedMapping.keySet());
455 for (int key : expectedMapping.keySet())
457 Assert.assertTrue(Arrays.equals(expectedMapping.get(key),
458 strucMapping.getMapping().get(key)));
459 >>>>>>> f80180a53bf16dc72ecdd4ace0f70c83cb0d274a
463 @Test(groups = { "Network" })
464 public void getEntityCountTest()
466 int actualEntityCount = siftsClient.getEntityCount();
467 System.out.println("actual entity count : " + actualEntityCount);
468 Assert.assertEquals(actualEntityCount, 1);
471 @Test(groups = { "Network" })
472 public void getDbAccessionIdTest()
474 String actualDbAccId = siftsClient.getDbAccessionId();
475 System.out.println("Actual Db Accession Id: " + actualDbAccId);
476 Assert.assertEquals(actualDbAccId, "1a70");
479 @Test(groups = { "Network" })
480 public void getDbCoordSysTest()
482 String actualDbCoordSys = siftsClient.getDbCoordSys();
483 System.out.println("Actual DbCoordSys: " + actualDbCoordSys);
484 Assert.assertEquals(actualDbCoordSys, "PDBe");
487 @Test(groups = { "Network" })
488 public void getDbSourceTest()
490 String actualDbSource = siftsClient.getDbSource();
491 System.out.println("Actual DbSource: " + actualDbSource);
492 Assert.assertEquals(actualDbSource, "PDBe");
495 @Test(groups = { "Network" })
496 public void getDbVersionTest()
498 String actualDbVersion = siftsClient.getDbVersion();
499 System.out.println("Actual DbVersion: " + actualDbVersion);
500 Assert.assertEquals(actualDbVersion, "2.0");
503 @Test(groups = { "Network" })
504 public void getEntityByMostOptimalMatchedIdTest1() throws IOException,
507 SiftsClient siftsClientX = null;
509 pdbFile = new PDBfile(false, false, false, "test/jalview/io/2nq2"
510 + ".pdb", DataSourceType.FILE);
511 siftsClientX = new SiftsClient(pdbFile);
512 Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("A");
513 Assert.assertEquals(entityA.getEntityId(), "A");
514 Entity entityB = siftsClientX.getEntityByMostOptimalMatchedId("B");
515 Assert.assertEquals(entityB.getEntityId(), "C");
516 Entity entityC = siftsClientX.getEntityByMostOptimalMatchedId("C");
517 Assert.assertEquals(entityC.getEntityId(), "B");
518 Entity entityD = siftsClientX.getEntityByMostOptimalMatchedId("D");
519 Assert.assertEquals(entityD.getEntityId(), "D");
523 @Test(groups = { "Network" })
524 public void getEntityByMostOptimalMatchedIdTest2() throws IOException,
527 // This test is for a SIFTS file in which entity A should map to chain P for
528 // the given PDB Id. All the other chains shouldn't be mapped as there are
529 // no SIFTS entity records for them.
530 SiftsClient siftsClientX = null;
532 pdbFile = new PDBfile(false, false, false, "test/jalview/io/3ucu.cif",
533 DataSourceType.FILE);
534 siftsClientX = new SiftsClient(pdbFile);
535 Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("P");
536 Entity entityP = siftsClientX.getEntityByMostOptimalMatchedId("A");
537 Entity entityR = siftsClientX.getEntityByMostOptimalMatchedId("R");
538 Assert.assertEquals(entityA.getEntityId(), "A");
539 Assert.assertNotEquals(entityR, "A");
540 Assert.assertNotEquals(entityP, "A");
541 Assert.assertNotEquals(entityR, "R");
542 Assert.assertNotEquals(entityP, "P");
543 Assert.assertNull(entityR);
544 Assert.assertNull(entityP);