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 jalview.api.DBRefEntryI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.DBRefEntry;
26 import jalview.datamodel.DBRefSource;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.JvOptionPane;
30 import jalview.io.DataSourceType;
31 import jalview.structure.StructureMapping;
32 import jalview.xml.binding.sifts.Entry.Entity;
35 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.HashMap;
39 import org.testng.Assert;
40 import org.testng.FileAssert;
41 import org.testng.annotations.AfterTest;
42 import org.testng.annotations.BeforeClass;
43 import org.testng.annotations.BeforeTest;
44 import org.testng.annotations.Test;
47 import MCview.PDBfile;
49 public class SiftsClientTest
52 @BeforeClass(alwaysRun = true)
53 public void setUpJvOptionPane()
55 JvOptionPane.setInteractiveMode(false);
56 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
59 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
60 .getProperty("user.home")
62 + ".sifts_downloads" + File.separatorChar;
64 private String testPDBId = "1a70";
66 private SiftsClient siftsClient = null;
68 SequenceI testSeq = new Sequence(
70 "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
71 + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
72 + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
74 int u = SiftsClient.UNASSIGNED;
76 HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
78 @BeforeTest(alwaysRun = true)
79 public void populateExpectedMapping() throws SiftsException
81 expectedMapping.put(51, new int[] { 1, 2 });
82 expectedMapping.put(52, new int[] { 2, 7 });
83 expectedMapping.put(53, new int[] { 3, 12 });
84 expectedMapping.put(54, new int[] { 4, 24 });
85 expectedMapping.put(55, new int[] { 5, 33 });
86 expectedMapping.put(56, new int[] { 6, 40 });
87 expectedMapping.put(57, new int[] { 7, 47 });
88 expectedMapping.put(58, new int[] { 8, 55 });
89 expectedMapping.put(59, new int[] { 9, 62 });
90 expectedMapping.put(60, new int[] { 10, 69 });
91 expectedMapping.put(61, new int[] { 11, 76 });
92 expectedMapping.put(62, new int[] { 12, 83 });
93 expectedMapping.put(63, new int[] { 13, 87 });
94 expectedMapping.put(64, new int[] { 14, 95 });
95 expectedMapping.put(65, new int[] { 15, 102 });
96 expectedMapping.put(66, new int[] { 16, 111 });
97 expectedMapping.put(67, new int[] { 17, 122 });
98 expectedMapping.put(68, new int[] { 18, 131 });
99 expectedMapping.put(69, new int[] { 19, 137 });
100 expectedMapping.put(70, new int[] { 20, 144 });
101 expectedMapping.put(71, new int[] { 21, 152 });
102 expectedMapping.put(72, new int[] { 22, 160 });
103 expectedMapping.put(73, new int[] { 23, 167 });
104 expectedMapping.put(74, new int[] { 24, 179 });
105 expectedMapping.put(75, new int[] { 25, 187 });
106 expectedMapping.put(76, new int[] { 26, 195 });
107 expectedMapping.put(77, new int[] { 27, 203 });
108 expectedMapping.put(78, new int[] { 28, 208 });
109 expectedMapping.put(79, new int[] { 29, 213 });
110 expectedMapping.put(80, new int[] { 30, 222 });
111 expectedMapping.put(81, new int[] { 31, 231 });
112 expectedMapping.put(82, new int[] { 32, 240 });
113 expectedMapping.put(83, new int[] { 33, 244 });
114 expectedMapping.put(84, new int[] { 34, 252 });
115 expectedMapping.put(85, new int[] { 35, 260 });
116 expectedMapping.put(86, new int[] { 36, 268 });
117 expectedMapping.put(87, new int[] { 37, 275 });
118 expectedMapping.put(88, new int[] { 38, 287 });
119 expectedMapping.put(89, new int[] { 39, 293 });
120 expectedMapping.put(90, new int[] { 40, 299 });
121 expectedMapping.put(91, new int[] { 41, 310 });
122 expectedMapping.put(92, new int[] { 42, 315 });
123 expectedMapping.put(93, new int[] { 43, 319 });
124 expectedMapping.put(94, new int[] { 44, 325 });
125 expectedMapping.put(95, new int[] { 45, 331 });
126 expectedMapping.put(96, new int[] { 46, 337 });
127 expectedMapping.put(97, new int[] { 47, 343 });
128 expectedMapping.put(98, new int[] { 48, 349 });
129 expectedMapping.put(99, new int[] { 49, 354 });
130 expectedMapping.put(100, new int[] { 50, 358 });
131 expectedMapping.put(101, new int[] { 51, 367 });
132 expectedMapping.put(102, new int[] { 52, 375 });
133 expectedMapping.put(103, new int[] { 53, 384 });
134 expectedMapping.put(104, new int[] { 54, 391 });
135 expectedMapping.put(105, new int[] { 55, 395 });
136 expectedMapping.put(106, new int[] { 56, 401 });
137 expectedMapping.put(107, new int[] { 57, 409 });
138 expectedMapping.put(108, new int[] { 58, 417 });
139 expectedMapping.put(109, new int[] { 59, 426 });
140 expectedMapping.put(110, new int[] { 60, 434 });
141 expectedMapping.put(111, new int[] { 61, 442 });
142 expectedMapping.put(112, new int[] { 62, 451 });
143 expectedMapping.put(113, new int[] { 63, 457 });
144 expectedMapping.put(114, new int[] { 64, 468 });
145 expectedMapping.put(115, new int[] { 65, 476 });
146 expectedMapping.put(116, new int[] { 66, 484 });
147 expectedMapping.put(117, new int[] { 67, 492 });
148 expectedMapping.put(118, new int[] { 68, 500 });
149 expectedMapping.put(119, new int[] { 69, 509 });
150 expectedMapping.put(120, new int[] { 70, 517 });
151 expectedMapping.put(121, new int[] { 71, 525 });
152 expectedMapping.put(122, new int[] { 72, 534 });
153 expectedMapping.put(123, new int[] { 73, 538 });
154 expectedMapping.put(124, new int[] { 74, 552 });
155 expectedMapping.put(125, new int[] { 75, 559 });
156 expectedMapping.put(126, new int[] { 76, 567 });
157 expectedMapping.put(127, new int[] { 77, 574 });
158 expectedMapping.put(128, new int[] { 78, 580 });
159 expectedMapping.put(129, new int[] { 79, 585 });
160 expectedMapping.put(130, new int[] { 80, 590 });
161 expectedMapping.put(131, new int[] { 81, 602 });
162 expectedMapping.put(132, new int[] { 82, 609 });
163 expectedMapping.put(133, new int[] { 83, 616 });
164 expectedMapping.put(134, new int[] { 84, 622 });
165 expectedMapping.put(135, new int[] { 85, 630 });
166 expectedMapping.put(136, new int[] { 86, 637 });
167 expectedMapping.put(137, new int[] { 87, 644 });
168 expectedMapping.put(138, new int[] { 88, 652 });
169 expectedMapping.put(139, new int[] { 89, 661 });
170 expectedMapping.put(140, new int[] { 90, 668 });
171 expectedMapping.put(141, new int[] { 91, 678 });
172 expectedMapping.put(142, new int[] { 92, 687 });
173 expectedMapping.put(143, new int[] { 93, 696 });
174 expectedMapping.put(144, new int[] { 94, 705 });
175 expectedMapping.put(145, new int[] { 95, 714 });
176 expectedMapping.put(146, new int[] { 96, 722 });
177 expectedMapping.put(147, new int[] { 97, 729 });
180 @BeforeTest(alwaysRun = true)
181 public void setUpSiftsClient() throws SiftsException
183 // read test props before manipulating config
184 Cache.loadProperties("test/jalview/io/testProps.jvprops");
185 // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
186 // test reproducibility
188 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
189 "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
190 SiftsSettings.setMapWithSifts(true);
191 SiftsSettings.setCacheThresholdInDays("2");
192 SiftsSettings.setFailSafePIDThreshold("70");
196 pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
197 + testPDBId + ".pdb", DataSourceType.FILE);
198 siftsClient = new SiftsClient(pdbFile);
199 } catch (Exception e)
205 @AfterTest(alwaysRun = true)
206 public void cleanUpSiftsClient()
211 @Test(groups = { "Functional" })
212 public void getSIFTsFileTest() throws SiftsException
217 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
218 FileAssert.assertFile(siftsFile);
219 // test for SIFTs file caching
220 SiftsSettings.setCacheThresholdInDays("0");
221 siftsFile = SiftsClient.getSiftsFile(testPDBId);
222 FileAssert.assertFile(siftsFile);
223 SiftsSettings.setCacheThresholdInDays("2");
224 } catch (IOException e)
230 @Test(groups = { "Functional" })
231 public void downloadSiftsFileTest() throws SiftsException
233 // Assert that file isn't yet downloaded - if already downloaded, assert it
235 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
239 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
240 FileAssert.assertFile(siftsFile);
241 SiftsClient.downloadSiftsFile(testPDBId);
242 } catch (IOException e)
248 @Test(groups = { "Functional" })
249 public void getAllMappingAccessionTest()
251 Assert.assertNotNull(siftsClient);
252 Assert.assertNotNull(siftsClient.getAllMappingAccession());
253 Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
256 @Test(groups = { "Functional" })
257 public void getGreedyMappingTest()
259 Assert.assertNotNull(siftsClient);
260 Assert.assertNotNull(testSeq);
261 Assert.assertNotNull(expectedMapping);
263 // TODO delete when auto-fetching of DBRefEntry is implemented
264 DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
265 testSeq.addDBRef(dbRef);
266 // testSeq.setSourceDBRef(dbRef);
270 HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
272 Assert.assertEquals(testSeq.getStart(), 1);
273 Assert.assertEquals(testSeq.getEnd(), 147);
274 Assert.assertEquals(actualMapping, expectedMapping);
275 } catch (Exception e)
278 Assert.fail("Exception thrown while generating mapping...");
282 @Test(groups = { "Functional" })
283 private void getAtomIndexTest()
285 ArrayList<Atom> atoms = new ArrayList<Atom>();
286 Atom atom = new Atom(u, u, u);
290 int actualAtomIndex = siftsClient.getAtomIndex(1, atoms);
291 Assert.assertEquals(actualAtomIndex, -1);
292 actualAtomIndex = siftsClient.getAtomIndex(43, atoms);
293 Assert.assertEquals(actualAtomIndex, 7);
297 groups = { "Functional" },
298 expectedExceptions = IllegalArgumentException.class)
299 private void getAtomIndexNullTest()
301 siftsClient.getAtomIndex(1, null);
304 @Test(groups = { "Functional" })
305 private void padWithGapsTest()
311 groups = { "Functional" },
312 expectedExceptions = SiftsException.class)
313 private void populateAtomPositionsNullTest1()
314 throws IllegalArgumentException, SiftsException
316 siftsClient.populateAtomPositions(null, null);
320 groups = { "Functional" },
321 expectedExceptions = SiftsException.class)
322 private void populateAtomPositionsNullTest2()
323 throws IllegalArgumentException, SiftsException
325 siftsClient.populateAtomPositions("A", null);
328 @Test(groups = { "Functional" })
329 public void getValidSourceDBRefTest()
333 DBRefEntryI actualValidSrcDBRef = siftsClient
334 .getValidSourceDBRef(testSeq);
335 DBRefEntryI expectedDBRef = new DBRefEntry();
336 expectedDBRef.setSource(DBRefSource.UNIPROT);
337 expectedDBRef.setAccessionId("P00221");
338 expectedDBRef.setVersion("");
339 Assert.assertEquals(actualValidSrcDBRef, expectedDBRef);
340 } catch (Exception e)
346 groups = { "Functional" },
347 expectedExceptions = SiftsException.class)
348 public void getValidSourceDBRefExceptionTest() throws SiftsException
350 SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
353 siftsClient.getValidSourceDBRef(invalidTestSeq);
354 } catch (SiftsException e)
356 throw new SiftsException(e.getMessage());
361 groups = { "Functional" },
362 expectedExceptions = SiftsException.class)
363 public void getValidSourceDBRefExceptionXTest() throws SiftsException
365 SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
366 DBRefEntry invalidDBRef = new DBRefEntry();
367 invalidDBRef.setAccessionId("BLAR");
368 invalidTestSeq.addDBRef(invalidDBRef);
371 siftsClient.getValidSourceDBRef(invalidTestSeq);
372 } catch (SiftsException e)
374 throw new SiftsException(e.getMessage());
379 @Test(groups = { "Functional" })
380 public void isValidDBRefEntryTest()
382 DBRefEntryI validDBRef = new DBRefEntry();
383 validDBRef.setSource(DBRefSource.UNIPROT);
384 validDBRef.setAccessionId("P00221");
385 validDBRef.setVersion("");
386 Assert.assertTrue(siftsClient.isValidDBRefEntry(validDBRef));
389 @Test(groups = { "Functional" })
390 public void getSiftsStructureMappingTest()
394 Assert.assertTrue(SiftsSettings.isMapWithSifts());
395 StructureMapping strucMapping = siftsClient.getSiftsStructureMapping(
396 testSeq, testPDBId, "A");
397 String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
398 + "Method: SIFTS\n\n"
399 + "P00221 : 51 - 147 Maps to \n"
400 + "1A70|A : 1 - 97\n\n"
401 + "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
402 + " |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
403 + "1A70|A AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n\n"
405 + "P00221 DDQIDEGWVLTCAAYPVSDVTIETHKEEELTA\n"
406 + " |||||||||||||||||||||||||| |||||\n"
407 + "1A70|A DDQIDEGWVLTCAAYPVSDVTIETHKKEELTA\n\n" +
409 "Length of alignment = 97\n" + "Percentage ID = 98.97\n";
411 Assert.assertEquals(strucMapping.getMappingDetailsOutput(),
412 expectedMappingOutput);
413 Assert.assertEquals(strucMapping.getMapping(), expectedMapping);
414 } catch (SiftsException e)
420 @Test(groups = { "Functional" })
421 public void getEntityCountTest()
423 int actualEntityCount = siftsClient.getEntityCount();
424 System.out.println("actual entity count : " + actualEntityCount);
425 Assert.assertEquals(actualEntityCount, 1);
428 @Test(groups = { "Functional" })
429 public void getDbAccessionIdTest()
431 String actualDbAccId = siftsClient.getDbAccessionId();
432 System.out.println("Actual Db Accession Id: " + actualDbAccId);
433 Assert.assertEquals(actualDbAccId, "1a70");
436 @Test(groups = { "Functional" })
437 public void getDbCoordSysTest()
439 String actualDbCoordSys = siftsClient.getDbCoordSys();
440 System.out.println("Actual DbCoordSys: " + actualDbCoordSys);
441 Assert.assertEquals(actualDbCoordSys, "PDBe");
444 @Test(groups = { "Functional" })
445 public void getDbSourceTest()
447 String actualDbSource = siftsClient.getDbSource();
448 System.out.println("Actual DbSource: " + actualDbSource);
449 Assert.assertEquals(actualDbSource, "PDBe");
452 @Test(groups = { "Functional" })
453 public void getDbVersionTest()
455 String actualDbVersion = siftsClient.getDbVersion();
456 System.out.println("Actual DbVersion: " + actualDbVersion);
457 Assert.assertEquals(actualDbVersion, "2.0");
460 @Test(groups = { "Functional" })
461 public void getEntityByMostOptimalMatchedIdTest1()
463 SiftsClient siftsClientX = null;
467 pdbFile = new PDBfile(false, false, false, "test/jalview/io/2nq2"
468 + ".pdb", DataSourceType.FILE);
469 siftsClientX = new SiftsClient(pdbFile);
470 } catch (Exception e)
474 Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("A");
475 Assert.assertEquals(entityA.getEntityId(), "A");
476 Entity entityB = siftsClientX.getEntityByMostOptimalMatchedId("B");
477 Assert.assertEquals(entityB.getEntityId(), "C");
478 Entity entityC = siftsClientX.getEntityByMostOptimalMatchedId("C");
479 Assert.assertEquals(entityC.getEntityId(), "B");
480 Entity entityD = siftsClientX.getEntityByMostOptimalMatchedId("D");
481 Assert.assertEquals(entityD.getEntityId(), "D");
485 @Test(groups = { "Functional" })
486 public void getEntityByMostOptimalMatchedIdTest2()
488 // This test is for a SIFTS file in which entity A should map to chain P for
489 // the given PDB Id. All the other chains shouldn't be mapped as there are
490 // no SIFTS entity records for them.
491 SiftsClient siftsClientX = null;
495 pdbFile = new PDBfile(false, false, false,
496 "test/jalview/io/3ucu.cif", DataSourceType.FILE);
497 siftsClientX = new SiftsClient(pdbFile);
498 } catch (Exception e)
502 Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("P");
503 Entity entityP = siftsClientX.getEntityByMostOptimalMatchedId("A");
504 Entity entityR = siftsClientX.getEntityByMostOptimalMatchedId("R");
505 Assert.assertEquals(entityA.getEntityId(), "A");
506 Assert.assertNotEquals(entityR, "A");
507 Assert.assertNotEquals(entityP, "A");
508 Assert.assertNotEquals(entityR, "R");
509 Assert.assertNotEquals(entityP, "P");
510 Assert.assertNull(entityR);
511 Assert.assertNull(entityP);