--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.io;
+
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.PrintStream;
+
+import org.testng.Assert;
+import org.testng.FileAssert;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class SiftsClientTest
+{
+ private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+
+ private String testPDBId = "1a70";
+
+ private SiftsClient siftsClient = null;
+
+ SequenceI testSeq = new Sequence(
+ "P00221",
+ "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
+ + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
+ + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
+
+ int[][] expectedMapping = { { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 },
+ { 0, 4 }, { 0, 5 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 },
+ { 0, 10 }, { 0, 11 }, { 0, 12 }, { 0, 13 }, { 0, 14 }, { 0, 15 },
+ { 0, 16 }, { 0, 17 }, { 0, 18 }, { 0, 19 }, { 0, 20 }, { 0, 21 },
+ { 0, 22 }, { 0, 23 }, { 0, 24 }, { 0, 25 }, { 0, 26 }, { 0, 27 },
+ { 0, 28 }, { 0, 29 }, { 0, 30 }, { 0, 31 }, { 0, 32 }, { 0, 33 },
+ { 0, 34 }, { 0, 35 }, { 0, 36 }, { 0, 37 }, { 0, 38 }, { 0, 39 },
+ { 0, 40 }, { 0, 41 }, { 0, 42 }, { 0, 43 }, { 0, 44 }, { 0, 45 },
+ { 0, 46 }, { 0, 47 }, { 0, 48 }, { 0, 49 }, { 0, 50 }, { 1, 51 },
+ { 2, 52 }, { 3, 53 }, { 4, 54 }, { 5, 55 }, { 6, 56 }, { 7, 57 },
+ { 8, 58 }, { 9, 59 }, { 10, 60 }, { 11, 61 }, { 12, 62 }, { 13, 63 },
+ { 14, 64 }, { 15, 65 }, { 16, 66 }, { 17, 67 }, { 18, 68 },
+ { 19, 69 }, { 20, 70 }, { 21, 71 }, { 22, 72 }, { 23, 73 },
+ { 24, 74 }, { 25, 75 }, { 26, 76 }, { 27, 77 }, { 28, 78 },
+ { 29, 79 }, { 30, 80 }, { 31, 81 }, { 32, 82 }, { 33, 83 },
+ { 34, 84 }, { 35, 85 }, { 36, 86 }, { 37, 87 }, { 38, 88 },
+ { 39, 89 }, { 40, 90 }, { 41, 91 }, { 42, 92 }, { 43, 93 },
+ { 44, 94 }, { 45, 95 }, { 46, 96 }, { 47, 97 }, { 48, 98 },
+ { 49, 99 }, { 50, 100 }, { 51, 101 }, { 52, 102 }, { 53, 103 },
+ { 54, 104 }, { 55, 105 }, { 56, 106 }, { 57, 107 }, { 58, 108 },
+ { 59, 109 }, { 60, 110 }, { 61, 111 }, { 62, 112 }, { 63, 113 },
+ { 64, 114 }, { 65, 115 }, { 66, 116 }, { 67, 117 }, { 68, 118 },
+ { 69, 119 }, { 70, 120 }, { 71, 121 }, { 72, 122 }, { 73, 123 },
+ { 74, 124 }, { 75, 125 }, { 76, 126 }, { 77, 127 }, { 78, 128 },
+ { 79, 129 }, { 80, 130 }, { 81, 131 }, { 82, 132 }, { 83, 133 },
+ { 84, 134 }, { 85, 135 }, { 86, 136 }, { 87, 137 }, { 88, 138 },
+ { 89, 139 }, { 90, 140 }, { 91, 141 }, { 92, 142 }, { 93, 143 },
+ { 94, 144 }, { 95, 145 }, { 96, 146 } };
+
+ @BeforeTest(alwaysRun = true)
+ public void setUpSiftsClient()
+ {
+ // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
+ // test reproducibility
+ File testSiftsFile = new File("test/jalview/io/" + testPDBId
+ + ".xml.gz");
+ siftsClient = new SiftsClient(testPDBId, testSiftsFile);
+ }
+
+ @AfterTest(alwaysRun = true)
+ public void cleanUpSiftsClient()
+ {
+ siftsClient = null;
+ }
+
+ @BeforeTest(alwaysRun = true)
+ public void setUpStreams()
+ {
+ System.setOut(new PrintStream(outContent));
+ }
+
+ @AfterTest(alwaysRun = true)
+ public void cleanUpStreams()
+ {
+ System.setOut(null);
+ }
+
+ @Test(groups = { "Functional" })
+ public void getSIFTsFileTest()
+ {
+ Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
+ SiftsClient.getSiftsFile(testPDBId);
+ Assert.assertFalse(outContent.toString().contains(
+ ">>> SIFTS File already downloaded for " + testPDBId));
+
+ // test for SIFTs file caching
+ SiftsClient.getSiftsFile(testPDBId);
+ Assert.assertTrue(outContent.toString().contains(
+ ">>> SIFTS File already downloaded for " + testPDBId));
+ }
+
+ @Test(groups = { "Functional" })
+ public void downloadSiftsFileTest()
+ {
+ // Assert that file isn't yet downloaded - if already downloaded, assert it
+ // is deleted
+ Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
+ File siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ SiftsClient.downloadSiftsFile(testPDBId);
+ }
+
+ @Test(groups = { "Functional" })
+ public void getAllMappingAccessionTest()
+ {
+ Assert.assertNotNull(siftsClient);
+ Assert.assertNotNull(siftsClient.getAllMappingAccession());
+ Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
+ }
+
+ @Test(groups = { "Functional" })
+ public void getGreedyMappingTest()
+ {
+ Assert.assertNotNull(siftsClient);
+ Assert.assertNotNull(testSeq);
+ Assert.assertNotNull(expectedMapping);
+
+ // TODO delete when auto-fetching of DBRefEntry is implemented
+ DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221");
+ dbRef.setStartRes(1);
+ dbRef.setEndRes(147);
+ testSeq.addDBRef(dbRef);
+ // testSeq.setSourceDBRef(dbRef);
+
+ try
+ {
+ int[][] actualMapping = siftsClient.getGreedyMapping("A", testSeq,
+ null);
+ Assert.assertEquals(actualMapping, expectedMapping);
+ Assert.assertEquals(testSeq.getStart(), 1);
+ Assert.assertEquals(testSeq.getEnd(), 147);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Exception thrown while generating mapping...");
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void getValidSourceDBRefTest()
+ {
+
+ }
+
+ @Test(groups = { "Functional" })
+ public void isValidDBRefEntryTest()
+ {
+
+ }
+}