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