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.xml.binding.sifts.Entry.Entity;
38 import java.io.IOException;
39 import java.util.ArrayList;
40 import java.util.HashMap;
42 import org.testng.Assert;
43 import org.testng.FileAssert;
44 import org.testng.annotations.AfterTest;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.BeforeTest;
47 import org.testng.annotations.Test;
50 import MCview.PDBfile;
52 public class SiftsClientTest
55 @BeforeClass(alwaysRun = true)
56 public void setUpJvOptionPane()
58 JvOptionPane.setInteractiveMode(false);
59 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
62 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
63 .getProperty("user.home")
65 + ".sifts_downloads" + File.separatorChar;
67 private String testPDBId = "1a70";
69 private SiftsClient siftsClient = null;
71 SequenceI testSeq = new Sequence(
73 "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
74 + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
75 + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
77 int u = SiftsClient.UNASSIGNED;
79 HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
81 @BeforeTest(alwaysRun = true)
82 public void populateExpectedMapping() throws SiftsException
84 expectedMapping.put(51, new int[] { 1, 2 });
85 expectedMapping.put(52, new int[] { 2, 7 });
86 expectedMapping.put(53, new int[] { 3, 12 });
87 expectedMapping.put(54, new int[] { 4, 24 });
88 expectedMapping.put(55, new int[] { 5, 33 });
89 expectedMapping.put(56, new int[] { 6, 40 });
90 expectedMapping.put(57, new int[] { 7, 47 });
91 expectedMapping.put(58, new int[] { 8, 55 });
92 expectedMapping.put(59, new int[] { 9, 62 });
93 expectedMapping.put(60, new int[] { 10, 69 });
94 expectedMapping.put(61, new int[] { 11, 76 });
95 expectedMapping.put(62, new int[] { 12, 83 });
96 expectedMapping.put(63, new int[] { 13, 87 });
97 expectedMapping.put(64, new int[] { 14, 95 });
98 expectedMapping.put(65, new int[] { 15, 102 });
99 expectedMapping.put(66, new int[] { 16, 111 });
100 expectedMapping.put(67, new int[] { 17, 122 });
101 expectedMapping.put(68, new int[] { 18, 131 });
102 expectedMapping.put(69, new int[] { 19, 137 });
103 expectedMapping.put(70, new int[] { 20, 144 });
104 expectedMapping.put(71, new int[] { 21, 152 });
105 expectedMapping.put(72, new int[] { 22, 160 });
106 expectedMapping.put(73, new int[] { 23, 167 });
107 expectedMapping.put(74, new int[] { 24, 179 });
108 expectedMapping.put(75, new int[] { 25, 187 });
109 expectedMapping.put(76, new int[] { 26, 195 });
110 expectedMapping.put(77, new int[] { 27, 203 });
111 expectedMapping.put(78, new int[] { 28, 208 });
112 expectedMapping.put(79, new int[] { 29, 213 });
113 expectedMapping.put(80, new int[] { 30, 222 });
114 expectedMapping.put(81, new int[] { 31, 231 });
115 expectedMapping.put(82, new int[] { 32, 240 });
116 expectedMapping.put(83, new int[] { 33, 244 });
117 expectedMapping.put(84, new int[] { 34, 252 });
118 expectedMapping.put(85, new int[] { 35, 260 });
119 expectedMapping.put(86, new int[] { 36, 268 });
120 expectedMapping.put(87, new int[] { 37, 275 });
121 expectedMapping.put(88, new int[] { 38, 287 });
122 expectedMapping.put(89, new int[] { 39, 293 });
123 expectedMapping.put(90, new int[] { 40, 299 });
124 expectedMapping.put(91, new int[] { 41, 310 });
125 expectedMapping.put(92, new int[] { 42, 315 });
126 expectedMapping.put(93, new int[] { 43, 319 });
127 expectedMapping.put(94, new int[] { 44, 325 });
128 expectedMapping.put(95, new int[] { 45, 331 });
129 expectedMapping.put(96, new int[] { 46, 337 });
130 expectedMapping.put(97, new int[] { 47, 343 });
131 expectedMapping.put(98, new int[] { 48, 349 });
132 expectedMapping.put(99, new int[] { 49, 354 });
133 expectedMapping.put(100, new int[] { 50, 358 });
134 expectedMapping.put(101, new int[] { 51, 367 });
135 expectedMapping.put(102, new int[] { 52, 375 });
136 expectedMapping.put(103, new int[] { 53, 384 });
137 expectedMapping.put(104, new int[] { 54, 391 });
138 expectedMapping.put(105, new int[] { 55, 395 });
139 expectedMapping.put(106, new int[] { 56, 401 });
140 expectedMapping.put(107, new int[] { 57, 409 });
141 expectedMapping.put(108, new int[] { 58, 417 });
142 expectedMapping.put(109, new int[] { 59, 426 });
143 expectedMapping.put(110, new int[] { 60, 434 });
144 expectedMapping.put(111, new int[] { 61, 442 });
145 expectedMapping.put(112, new int[] { 62, 451 });
146 expectedMapping.put(113, new int[] { 63, 457 });
147 expectedMapping.put(114, new int[] { 64, 468 });
148 expectedMapping.put(115, new int[] { 65, 476 });
149 expectedMapping.put(116, new int[] { 66, 484 });
150 expectedMapping.put(117, new int[] { 67, 492 });
151 expectedMapping.put(118, new int[] { 68, 500 });
152 expectedMapping.put(119, new int[] { 69, 509 });
153 expectedMapping.put(120, new int[] { 70, 517 });
154 expectedMapping.put(121, new int[] { 71, 525 });
155 expectedMapping.put(122, new int[] { 72, 534 });
156 expectedMapping.put(123, new int[] { 73, 538 });
157 expectedMapping.put(124, new int[] { 74, 552 });
158 expectedMapping.put(125, new int[] { 75, 559 });
159 expectedMapping.put(126, new int[] { 76, 567 });
160 expectedMapping.put(127, new int[] { 77, 574 });
161 expectedMapping.put(128, new int[] { 78, 580 });
162 expectedMapping.put(129, new int[] { 79, 585 });
163 expectedMapping.put(130, new int[] { 80, 590 });
164 expectedMapping.put(131, new int[] { 81, 602 });
165 expectedMapping.put(132, new int[] { 82, 609 });
166 expectedMapping.put(133, new int[] { 83, 616 });
167 expectedMapping.put(134, new int[] { 84, 622 });
168 expectedMapping.put(135, new int[] { 85, 630 });
169 expectedMapping.put(136, new int[] { 86, 637 });
170 expectedMapping.put(137, new int[] { 87, 644 });
171 expectedMapping.put(138, new int[] { 88, 652 });
172 expectedMapping.put(139, new int[] { 89, 661 });
173 expectedMapping.put(140, new int[] { 90, 668 });
174 expectedMapping.put(141, new int[] { 91, 678 });
175 expectedMapping.put(142, new int[] { 92, 687 });
176 expectedMapping.put(143, new int[] { 93, 696 });
177 expectedMapping.put(144, new int[] { 94, 705 });
178 expectedMapping.put(145, new int[] { 95, 714 });
179 expectedMapping.put(146, new int[] { 96, 722 });
180 expectedMapping.put(147, new int[] { 97, 729 });
183 @BeforeTest(alwaysRun = true)
184 public void setUpSiftsClient() throws SiftsException, IOException
186 // read test props before manipulating config
187 Cache.loadProperties("test/jalview/io/testProps.jvprops");
188 // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
189 // test reproducibility
191 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
192 "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
193 SiftsSettings.setMapWithSifts(true);
194 SiftsSettings.setCacheThresholdInDays("2");
195 SiftsSettings.setFailSafePIDThreshold("70");
197 pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
198 + testPDBId + ".pdb", DataSourceType.FILE);
199 siftsClient = new SiftsClient(pdbFile);
202 @AfterTest(alwaysRun = true)
203 public void cleanUpSiftsClient()
208 @Test(groups = { "Network" })
209 public void getSIFTsFileTest() throws SiftsException, IOException
212 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
213 FileAssert.assertFile(siftsFile);
214 long t1 = siftsFile.lastModified();
216 // re-read file should be returned from cache
217 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
218 FileAssert.assertFile(siftsFile);
219 long t2 = siftsFile.lastModified();
220 assertEquals(t1, t2);
223 * force fetch by having 0 expiry of cache
224 * also wait one second, because file timestamp does not
225 * give millisecond resolution :-(
232 } catch (InterruptedException e)
236 SiftsSettings.setCacheThresholdInDays("0");
237 siftsFile = SiftsClient.getSiftsFile(testPDBId);
238 FileAssert.assertFile(siftsFile);
239 long t3 = siftsFile.lastModified();
240 assertTrue(t3 > t2, "file timestamp unchanged at " + t3);
242 SiftsSettings.setCacheThresholdInDays("2");
245 @Test(groups = { "Network" })
246 public void downloadSiftsFileTest() throws SiftsException, IOException
248 // Assert that file isn't yet downloaded - if already downloaded, assert it
250 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
252 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
253 FileAssert.assertFile(siftsFile);
254 SiftsClient.downloadSiftsFile(testPDBId);
257 @Test(groups = { "Network" })
258 public void getAllMappingAccessionTest()
260 Assert.assertNotNull(siftsClient);
261 Assert.assertNotNull(siftsClient.getAllMappingAccession());
262 Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
265 @Test(groups = { "Network" })
266 public void getGreedyMappingTest()
268 Assert.assertNotNull(siftsClient);
269 Assert.assertNotNull(testSeq);
270 Assert.assertNotNull(expectedMapping);
272 // TODO delete when auto-fetching of DBRefEntry is implemented
273 DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
274 testSeq.addDBRef(dbRef);
275 // testSeq.setSourceDBRef(dbRef);
279 HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
281 Assert.assertEquals(testSeq.getStart(), 1);
282 Assert.assertEquals(testSeq.getEnd(), 147);
283 Assert.assertEquals(actualMapping, expectedMapping);
284 } catch (Exception e)
287 Assert.fail("Exception thrown while generating mapping...");
291 @Test(groups = { "Network" })
292 private void getAtomIndexTest()
294 ArrayList<Atom> atoms = new ArrayList<Atom>();
295 Atom atom = new Atom(u, u, u);
299 int actualAtomIndex = siftsClient.getAtomIndex(1, atoms);
300 Assert.assertEquals(actualAtomIndex, -1);
301 actualAtomIndex = siftsClient.getAtomIndex(43, atoms);
302 Assert.assertEquals(actualAtomIndex, 7);
306 groups = { "Network" },
307 expectedExceptions = IllegalArgumentException.class)
308 private void getAtomIndexNullTest()
310 siftsClient.getAtomIndex(1, null);
313 @Test(groups = { "Network" })
314 private void padWithGapsTest()
320 groups = { "Network" },
321 expectedExceptions = SiftsException.class)
322 private void populateAtomPositionsNullTest1()
323 throws IllegalArgumentException, SiftsException
325 siftsClient.populateAtomPositions(null, null);
329 groups = { "Network" },
330 expectedExceptions = SiftsException.class)
331 private void populateAtomPositionsNullTest2()
332 throws IllegalArgumentException, SiftsException
334 siftsClient.populateAtomPositions("A", null);
337 @Test(groups = { "Network" })
338 public void getValidSourceDBRefTest() throws SiftsException
340 DBRefEntryI actualValidSrcDBRef = siftsClient
341 .getValidSourceDBRef(testSeq);
342 DBRefEntryI expectedDBRef = new DBRefEntry();
343 expectedDBRef.setSource(DBRefSource.UNIPROT);
344 expectedDBRef.setAccessionId("P00221");
345 expectedDBRef.setVersion("");
346 Assert.assertEquals(actualValidSrcDBRef, expectedDBRef);
350 groups = { "Network" },
351 expectedExceptions = SiftsException.class)
352 public void getValidSourceDBRefExceptionTest() throws SiftsException
354 SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
355 siftsClient.getValidSourceDBRef(invalidTestSeq);
359 groups = { "Network" },
360 expectedExceptions = SiftsException.class)
361 public void getValidSourceDBRefExceptionXTest() throws SiftsException
363 SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
364 DBRefEntry invalidDBRef = new DBRefEntry();
365 invalidDBRef.setAccessionId("BLAR");
366 invalidTestSeq.addDBRef(invalidDBRef);
367 siftsClient.getValidSourceDBRef(invalidTestSeq);
370 @Test(groups = { "Network" })
371 public void isValidDBRefEntryTest()
373 DBRefEntryI validDBRef = new DBRefEntry();
374 validDBRef.setSource(DBRefSource.UNIPROT);
375 validDBRef.setAccessionId("P00221");
376 validDBRef.setVersion("");
377 Assert.assertTrue(siftsClient.isValidDBRefEntry(validDBRef));
380 @Test(groups = { "Network" })
381 public void getSiftsStructureMappingTest() throws SiftsException
383 Assert.assertTrue(SiftsSettings.isMapWithSifts());
384 StructureMapping strucMapping = siftsClient.getSiftsStructureMapping(
385 testSeq, testPDBId, "A");
386 String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
387 + "Method: SIFTS\n\n"
388 + "P00221 : 51 - 147 Maps to \n"
389 + "1A70|A : 1 - 97\n\n"
390 + "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
391 + " |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
392 + "1A70|A AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n\n"
394 + "P00221 DDQIDEGWVLTCAAYPVSDVTIETHKEEELTA\n"
395 + " |||||||||||||||||||||||||| |||||\n"
396 + "1A70|A DDQIDEGWVLTCAAYPVSDVTIETHKKEELTA\n\n" +
398 "Length of alignment = 97\n" + "Percentage ID = 98.97\n";
400 Assert.assertEquals(strucMapping.getMappingDetailsOutput(),
401 expectedMappingOutput);
402 Assert.assertEquals(strucMapping.getMapping(), expectedMapping);
405 @Test(groups = { "Network" })
406 public void getEntityCountTest()
408 int actualEntityCount = siftsClient.getEntityCount();
409 System.out.println("actual entity count : " + actualEntityCount);
410 Assert.assertEquals(actualEntityCount, 1);
413 @Test(groups = { "Network" })
414 public void getDbAccessionIdTest()
416 String actualDbAccId = siftsClient.getDbAccessionId();
417 System.out.println("Actual Db Accession Id: " + actualDbAccId);
418 Assert.assertEquals(actualDbAccId, "1a70");
421 @Test(groups = { "Network" })
422 public void getDbCoordSysTest()
424 String actualDbCoordSys = siftsClient.getDbCoordSys();
425 System.out.println("Actual DbCoordSys: " + actualDbCoordSys);
426 Assert.assertEquals(actualDbCoordSys, "PDBe");
429 @Test(groups = { "Network" })
430 public void getDbSourceTest()
432 String actualDbSource = siftsClient.getDbSource();
433 System.out.println("Actual DbSource: " + actualDbSource);
434 Assert.assertEquals(actualDbSource, "PDBe");
437 @Test(groups = { "Network" })
438 public void getDbVersionTest()
440 String actualDbVersion = siftsClient.getDbVersion();
441 System.out.println("Actual DbVersion: " + actualDbVersion);
442 Assert.assertEquals(actualDbVersion, "2.0");
445 @Test(groups = { "Network" })
446 public void getEntityByMostOptimalMatchedIdTest1() throws IOException,
449 SiftsClient siftsClientX = null;
451 pdbFile = new PDBfile(false, false, false, "test/jalview/io/2nq2"
452 + ".pdb", DataSourceType.FILE);
453 siftsClientX = new SiftsClient(pdbFile);
454 Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("A");
455 Assert.assertEquals(entityA.getEntityId(), "A");
456 Entity entityB = siftsClientX.getEntityByMostOptimalMatchedId("B");
457 Assert.assertEquals(entityB.getEntityId(), "C");
458 Entity entityC = siftsClientX.getEntityByMostOptimalMatchedId("C");
459 Assert.assertEquals(entityC.getEntityId(), "B");
460 Entity entityD = siftsClientX.getEntityByMostOptimalMatchedId("D");
461 Assert.assertEquals(entityD.getEntityId(), "D");
465 @Test(groups = { "Network" })
466 public void getEntityByMostOptimalMatchedIdTest2() throws IOException,
469 // This test is for a SIFTS file in which entity A should map to chain P for
470 // the given PDB Id. All the other chains shouldn't be mapped as there are
471 // no SIFTS entity records for them.
472 SiftsClient siftsClientX = null;
474 pdbFile = new PDBfile(false, false, false, "test/jalview/io/3ucu.cif",
475 DataSourceType.FILE);
476 siftsClientX = new SiftsClient(pdbFile);
477 Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("P");
478 Entity entityP = siftsClientX.getEntityByMostOptimalMatchedId("A");
479 Entity entityR = siftsClientX.getEntityByMostOptimalMatchedId("R");
480 Assert.assertEquals(entityA.getEntityId(), "A");
481 Assert.assertNotEquals(entityR, "A");
482 Assert.assertNotEquals(entityP, "A");
483 Assert.assertNotEquals(entityR, "R");
484 Assert.assertNotEquals(entityP, "P");
485 Assert.assertNull(entityR);
486 Assert.assertNull(entityP);