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;
30 import java.util.HashMap;
32 import org.testng.Assert;
33 import org.testng.FileAssert;
34 import org.testng.annotations.AfterTest;
35 import org.testng.annotations.BeforeTest;
36 import org.testng.annotations.Test;
38 import MCview.PDBfile;
40 public class SiftsClientTest
42 private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
44 private String testPDBId = "1a70";
46 private SiftsClient siftsClient = null;
48 SequenceI testSeq = new Sequence(
50 "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
51 + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
52 + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
54 int u = SiftsClient.UNASSIGNED;
56 HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
58 @BeforeTest(alwaysRun = true)
59 public void populateExpectedMapping() throws SiftsException
61 for (int x = 1; x <= 97; x++)
63 expectedMapping.put(50 + x, new int[] { x, u });
67 @BeforeTest(alwaysRun = true)
68 public void setUpSiftsClient() throws SiftsException
70 // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
71 // test reproducibility
72 File testSiftsFile = new File("test/jalview/io/" + testPDBId
74 PDBfile pdbFile = new PDBfile(false, false, false);
75 siftsClient = new SiftsClient(pdbFile, testSiftsFile);
78 @AfterTest(alwaysRun = true)
79 public void cleanUpSiftsClient()
84 @BeforeTest(alwaysRun = true)
85 public void setUpStreams()
87 System.setOut(new PrintStream(outContent));
90 @AfterTest(alwaysRun = true)
91 public void cleanUpStreams()
96 @Test(groups = { "Functional" })
97 public void getSIFTsFileTest() throws SiftsException
99 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
100 SiftsClient.getSiftsFile(testPDBId);
101 Assert.assertFalse(outContent.toString().contains(
102 ">>> SIFTS File already downloaded for " + testPDBId));
104 // test for SIFTs file caching
105 SiftsClient.getSiftsFile(testPDBId);
106 Assert.assertTrue(outContent.toString().contains(
107 ">>> SIFTS File already downloaded for " + testPDBId));
110 @Test(groups = { "Functional" })
111 public void downloadSiftsFileTest() throws SiftsException
113 // Assert that file isn't yet downloaded - if already downloaded, assert it
115 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
116 File siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
117 FileAssert.assertFile(siftsFile);
118 SiftsClient.downloadSiftsFile(testPDBId);
121 @Test(groups = { "Functional" })
122 public void getAllMappingAccessionTest()
124 Assert.assertNotNull(siftsClient);
125 Assert.assertNotNull(siftsClient.getAllMappingAccession());
126 Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
129 @Test(groups = { "Functional" })
130 public void getGreedyMappingTest()
132 Assert.assertNotNull(siftsClient);
133 Assert.assertNotNull(testSeq);
134 Assert.assertNotNull(expectedMapping);
136 // TODO delete when auto-fetching of DBRefEntry is implemented
137 DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
138 dbRef.setStartRes(1);
139 dbRef.setEndRes(147);
140 testSeq.addDBRef(dbRef);
141 // testSeq.setSourceDBRef(dbRef);
145 HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
148 Assert.assertEquals(actualMapping, expectedMapping);
149 Assert.assertEquals(testSeq.getStart(), 1);
150 Assert.assertEquals(testSeq.getEnd(), 147);
151 } catch (Exception e)
154 Assert.fail("Exception thrown while generating mapping...");
158 @Test(groups = { "Functional" })
159 private void getAtomIndexTest()
161 // siftsClient.getAtomIndex(1, null);
162 // Assert.assertTrue(true);
166 groups = { "Functional" },
167 expectedExceptions = IllegalArgumentException.class)
168 private void getAtomIndexNullTest()
170 siftsClient.getAtomIndex(1, null);
173 @Test(groups = { "Functional" })
174 private void padWithGapsTest()
179 @Test(groups = { "Functional" })
180 private void populateAtomPositionsTest()
185 @Test(groups = { "Functional" })
186 public void getValidSourceDBRefTest()
191 @Test(groups = { "Functional" })
192 public void isValidDBRefEntryTest()