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 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
45 .getProperty("user.home")
47 + ".sifts_downloads" + File.separatorChar;
49 private String testPDBId = "1a70";
51 private SiftsClient siftsClient = null;
53 SequenceI testSeq = new Sequence(
55 "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
56 + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
57 + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
59 int u = SiftsClient.UNASSIGNED;
61 HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
63 @BeforeTest(alwaysRun = true)
64 public void populateExpectedMapping() throws SiftsException
66 for (int x = 1; x <= 97; x++)
68 expectedMapping.put(50 + x, new int[] { x, u });
72 @BeforeTest(alwaysRun = true)
73 public void setUpSiftsClient() throws SiftsException
75 // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
76 // test reproducibility
77 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
78 "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
80 File testSiftsFile = new File("test/jalview/io/" + testPDBId
82 PDBfile pdbFile = new PDBfile(false, false, false);
83 pdbFile.setId(testPDBId);
84 siftsClient = new SiftsClient(pdbFile, testSiftsFile);
87 @AfterTest(alwaysRun = true)
88 public void cleanUpSiftsClient()
93 @BeforeTest(alwaysRun = true)
94 public void setUpStreams()
96 System.setOut(new PrintStream(outContent));
99 @AfterTest(alwaysRun = true)
100 public void cleanUpStreams()
105 @Test(groups = { "Functional" })
106 public void getSIFTsFileTest() throws SiftsException
108 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
109 SiftsClient.getSiftsFile(testPDBId);
110 Assert.assertFalse(outContent.toString().contains(
111 ">>> SIFTS File already downloaded for " + testPDBId));
113 // test for SIFTs file caching
114 SiftsClient.getSiftsFile(testPDBId);
115 Assert.assertTrue(outContent.toString().contains(
116 ">>> SIFTS File already downloaded for " + testPDBId));
119 @Test(groups = { "Functional" })
120 public void downloadSiftsFileTest() throws SiftsException
122 // Assert that file isn't yet downloaded - if already downloaded, assert it
124 Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
125 File siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
126 FileAssert.assertFile(siftsFile);
127 SiftsClient.downloadSiftsFile(testPDBId);
130 @Test(groups = { "Functional" })
131 public void getAllMappingAccessionTest()
133 Assert.assertNotNull(siftsClient);
134 Assert.assertNotNull(siftsClient.getAllMappingAccession());
135 Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
138 @Test(groups = { "Functional" })
139 public void getGreedyMappingTest()
141 Assert.assertNotNull(siftsClient);
142 Assert.assertNotNull(testSeq);
143 Assert.assertNotNull(expectedMapping);
145 // TODO delete when auto-fetching of DBRefEntry is implemented
146 DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
147 dbRef.setStartRes(1);
148 dbRef.setEndRes(147);
149 testSeq.addDBRef(dbRef);
150 // testSeq.setSourceDBRef(dbRef);
154 HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
157 Assert.assertEquals(actualMapping, expectedMapping);
158 Assert.assertEquals(testSeq.getStart(), 1);
159 Assert.assertEquals(testSeq.getEnd(), 147);
160 } catch (Exception e)
163 Assert.fail("Exception thrown while generating mapping...");
167 @Test(groups = { "Functional" })
168 private void getAtomIndexTest()
170 // siftsClient.getAtomIndex(1, null);
171 // Assert.assertTrue(true);
175 groups = { "Functional" },
176 expectedExceptions = IllegalArgumentException.class)
177 private void getAtomIndexNullTest()
179 siftsClient.getAtomIndex(1, null);
182 @Test(groups = { "Functional" })
183 private void padWithGapsTest()
188 @Test(groups = { "Functional" })
189 private void populateAtomPositionsTest()
194 @Test(groups = { "Functional" })
195 public void getValidSourceDBRefTest()
200 @Test(groups = { "Functional" })
201 public void isValidDBRefEntryTest()