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