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.IOException;
30 import java.io.PrintStream;
31 import java.util.HashMap;
33 import org.testng.Assert;
34 import org.testng.FileAssert;
35 import org.testng.annotations.AfterTest;
36 import org.testng.annotations.BeforeTest;
37 import org.testng.annotations.Test;
39 import MCview.PDBfile;
41 public class SiftsClientTest
43 private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
45 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
46 .getProperty("user.home")
48 + ".sifts_downloads" + File.separatorChar;
50 private String testPDBId = "1a70";
52 private SiftsClient siftsClient = null;
54 SequenceI testSeq = new Sequence(
56 "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
57 + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
58 + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
60 int u = SiftsClient.UNASSIGNED;
62 HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
64 @BeforeTest(alwaysRun = true)
65 public void populateExpectedMapping() throws SiftsException
67 for (int x = 1; x <= 97; x++)
69 expectedMapping.put(50 + x, new int[] { x, u });
73 @BeforeTest(alwaysRun = true)
74 public void setUpSiftsClient() throws SiftsException
76 // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
77 // test reproducibility
78 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
79 "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
81 File testSiftsFile = new File("test/jalview/io/" + testPDBId
83 PDBfile pdbFile = new PDBfile(false, false, false);
84 pdbFile.setId(testPDBId);
85 siftsClient = new SiftsClient(pdbFile, testSiftsFile);
88 @AfterTest(alwaysRun = true)
89 public void cleanUpSiftsClient()
94 @BeforeTest(alwaysRun = true)
95 public void setUpStreams()
97 System.setOut(new PrintStream(outContent));
100 @AfterTest(alwaysRun = true)
101 public void cleanUpStreams()
106 @Test(groups = { "Functional" })
107 public void getSIFTsFileTest() throws SiftsException
109 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
110 SiftsClient.getSiftsFile(testPDBId);
111 Assert.assertFalse(outContent.toString().contains(
112 ">>> SIFTS File already downloaded for " + testPDBId));
114 // test for SIFTs file caching
115 SiftsClient.getSiftsFile(testPDBId);
116 Assert.assertTrue(outContent.toString().contains(
117 ">>> SIFTS File already downloaded for " + testPDBId));
120 @Test(groups = { "Functional" })
121 public void downloadSiftsFileTest() throws SiftsException
123 // Assert that file isn't yet downloaded - if already downloaded, assert it
125 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
129 siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
130 FileAssert.assertFile(siftsFile);
131 SiftsClient.downloadSiftsFile(testPDBId);
132 } catch (IOException e)
138 @Test(groups = { "Functional" })
139 public void getAllMappingAccessionTest()
141 Assert.assertNotNull(siftsClient);
142 Assert.assertNotNull(siftsClient.getAllMappingAccession());
143 Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
146 @Test(groups = { "Functional" })
147 public void getGreedyMappingTest()
149 Assert.assertNotNull(siftsClient);
150 Assert.assertNotNull(testSeq);
151 Assert.assertNotNull(expectedMapping);
153 // TODO delete when auto-fetching of DBRefEntry is implemented
154 DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
155 dbRef.setStartRes(1);
156 dbRef.setEndRes(147);
157 testSeq.addDBRef(dbRef);
158 // testSeq.setSourceDBRef(dbRef);
162 HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
165 Assert.assertEquals(actualMapping, expectedMapping);
166 Assert.assertEquals(testSeq.getStart(), 1);
167 Assert.assertEquals(testSeq.getEnd(), 147);
168 } catch (Exception e)
171 Assert.fail("Exception thrown while generating mapping...");
175 @Test(groups = { "Functional" })
176 private void getAtomIndexTest()
178 // siftsClient.getAtomIndex(1, null);
179 // Assert.assertTrue(true);
183 groups = { "Functional" },
184 expectedExceptions = IllegalArgumentException.class)
185 private void getAtomIndexNullTest()
187 siftsClient.getAtomIndex(1, null);
190 @Test(groups = { "Functional" })
191 private void padWithGapsTest()
196 @Test(groups = { "Functional" })
197 private void populateAtomPositionsTest()
202 @Test(groups = { "Functional" })
203 public void getValidSourceDBRefTest()
208 @Test(groups = { "Functional" })
209 public void isValidDBRefEntryTest()