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.datamodel.DBRefEntry;
24 import jalview.datamodel.Sequence;
25 import jalview.datamodel.SequenceI;
27 import java.io.ByteArrayOutputStream;
29 import java.io.PrintStream;
31 import org.testng.Assert;
32 import org.testng.FileAssert;
33 import org.testng.annotations.AfterTest;
34 import org.testng.annotations.BeforeTest;
35 import org.testng.annotations.Test;
37 import MCview.PDBfile;
39 public class SiftsClientTest
41 private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
43 private String testPDBId = "1a70";
45 private SiftsClient siftsClient = null;
47 SequenceI testSeq = new Sequence(
49 "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
50 + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
51 + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
53 int u = SiftsClient.UNASSIGNED;
55 int[][] expectedMapping = { { u, u }, { u, u }, { u, u }, { u, u },
56 { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
57 { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
58 { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
59 { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
60 { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
61 { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
62 { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { 1, u }, { 2, u },
63 { 3, u }, { 4, u }, { 5, u }, { 6, u }, { 7, u }, { 8, u }, { 9, u },
64 { 10, u }, { 11, u }, { 12, u }, { 13, u }, { 14, u }, { 15, u },
65 { 16, u }, { 17, u }, { 18, u }, { 19, u }, { 20, u }, { 21, u },
66 { 22, u }, { 23, u }, { 24, u }, { 25, u }, { 26, u }, { 27, u },
67 { 28, u }, { 29, u }, { 30, u }, { 31, u }, { 32, u }, { 33, u },
68 { 34, u }, { 35, u }, { 36, u }, { 37, u }, { 38, u }, { 39, u },
69 { 40, u }, { 41, u }, { 42, u }, { 43, u }, { 44, u }, { 45, u },
70 { 46, u }, { 47, u }, { 48, u }, { 49, u }, { 50, u }, { 51, u },
71 { 52, u }, { 53, u }, { 54, u }, { 55, u }, { 56, u }, { 57, u },
72 { 58, u }, { 59, u }, { 60, u }, { 61, u }, { 62, u }, { 63, u },
73 { 64, u }, { 65, u }, { 66, u }, { 67, u }, { 68, u }, { 69, u },
74 { 70, u }, { 71, u }, { 72, u }, { 73, u }, { 74, u }, { 75, u },
75 { 76, u }, { 77, u }, { 78, u }, { 79, u }, { 80, u }, { 81, u },
76 { 82, u }, { 83, u }, { 84, u }, { 85, u }, { 86, u }, { 87, u },
77 { 88, u }, { 89, u }, { 90, u }, { 91, u }, { 92, u }, { 93, u },
78 { 94, u }, { 95, u }, { 96, u }, { 97, u } };
80 @BeforeTest(alwaysRun = true)
81 public void setUpSiftsClient()
83 // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
84 // test reproducibility
85 File testSiftsFile = new File("test/jalview/io/" + testPDBId
87 PDBfile pdbFile = new PDBfile(false, false, false);
88 siftsClient = new SiftsClient(pdbFile, testSiftsFile);
91 @AfterTest(alwaysRun = true)
92 public void cleanUpSiftsClient()
97 @BeforeTest(alwaysRun = true)
98 public void setUpStreams()
100 System.setOut(new PrintStream(outContent));
103 @AfterTest(alwaysRun = true)
104 public void cleanUpStreams()
109 @Test(groups = { "Functional" })
110 public void getSIFTsFileTest()
112 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
113 SiftsClient.getSiftsFile(testPDBId);
114 Assert.assertFalse(outContent.toString().contains(
115 ">>> SIFTS File already downloaded for " + testPDBId));
117 // test for SIFTs file caching
118 SiftsClient.getSiftsFile(testPDBId);
119 Assert.assertTrue(outContent.toString().contains(
120 ">>> SIFTS File already downloaded for " + testPDBId));
123 @Test(groups = { "Functional" })
124 public void downloadSiftsFileTest()
126 // Assert that file isn't yet downloaded - if already downloaded, assert it
128 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
129 File siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
130 FileAssert.assertFile(siftsFile);
131 SiftsClient.downloadSiftsFile(testPDBId);
134 @Test(groups = { "Functional" })
135 public void getAllMappingAccessionTest()
137 Assert.assertNotNull(siftsClient);
138 Assert.assertNotNull(siftsClient.getAllMappingAccession());
139 Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
142 @Test(groups = { "Functional" })
143 public void getGreedyMappingTest()
145 Assert.assertNotNull(siftsClient);
146 Assert.assertNotNull(testSeq);
147 Assert.assertNotNull(expectedMapping);
149 // TODO delete when auto-fetching of DBRefEntry is implemented
150 DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
151 dbRef.setStartRes(1);
152 dbRef.setEndRes(147);
153 testSeq.addDBRef(dbRef);
154 // testSeq.setSourceDBRef(dbRef);
158 int[][] actualMapping = siftsClient.getGreedyMapping("A", testSeq,
160 Assert.assertEquals(actualMapping, expectedMapping);
161 Assert.assertEquals(testSeq.getStart(), 1);
162 Assert.assertEquals(testSeq.getEnd(), 147);
163 } catch (Exception e)
166 Assert.fail("Exception thrown while generating mapping...");
170 @Test(groups = { "Functional" })
171 private void getAtomIndexTest()
173 // siftsClient.getAtomIndex(1, null);
174 // Assert.assertTrue(true);
178 groups = { "Functional" },
179 expectedExceptions = IllegalArgumentException.class)
180 private void getAtomIndexNullTest()
182 siftsClient.getAtomIndex(1, null);
185 @Test(groups = { "Functional" })
186 private void padWithGapsTest()
191 @Test(groups = { "Functional" })
192 private void populateAtomPositionsTest()
197 @Test(groups = { "Functional" })
198 public void getValidSourceDBRefTest()
203 @Test(groups = { "Functional" })
204 public void isValidDBRefEntryTest()