--- /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.ws.sifts;
+
+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;
+
+import MCview.PDBfile;
+
+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 u = SiftsClient.UNASSIGNED;
+
+ int[][] expectedMapping = { { u, u }, { u, u }, { u, u }, { u, u },
+ { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
+ { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
+ { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
+ { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
+ { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
+ { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { u, u },
+ { u, u }, { u, u }, { u, u }, { u, u }, { u, u }, { 1, u }, { 2, u },
+ { 3, u }, { 4, u }, { 5, u }, { 6, u }, { 7, u }, { 8, u }, { 9, u },
+ { 10, u }, { 11, u }, { 12, u }, { 13, u }, { 14, u }, { 15, u },
+ { 16, u }, { 17, u }, { 18, u }, { 19, u }, { 20, u }, { 21, u },
+ { 22, u }, { 23, u }, { 24, u }, { 25, u }, { 26, u }, { 27, u },
+ { 28, u }, { 29, u }, { 30, u }, { 31, u }, { 32, u }, { 33, u },
+ { 34, u }, { 35, u }, { 36, u }, { 37, u }, { 38, u }, { 39, u },
+ { 40, u }, { 41, u }, { 42, u }, { 43, u }, { 44, u }, { 45, u },
+ { 46, u }, { 47, u }, { 48, u }, { 49, u }, { 50, u }, { 51, u },
+ { 52, u }, { 53, u }, { 54, u }, { 55, u }, { 56, u }, { 57, u },
+ { 58, u }, { 59, u }, { 60, u }, { 61, u }, { 62, u }, { 63, u },
+ { 64, u }, { 65, u }, { 66, u }, { 67, u }, { 68, u }, { 69, u },
+ { 70, u }, { 71, u }, { 72, u }, { 73, u }, { 74, u }, { 75, u },
+ { 76, u }, { 77, u }, { 78, u }, { 79, u }, { 80, u }, { 81, u },
+ { 82, u }, { 83, u }, { 84, u }, { 85, u }, { 86, u }, { 87, u },
+ { 88, u }, { 89, u }, { 90, u }, { 91, u }, { 92, u }, { 93, u },
+ { 94, u }, { 95, u }, { 96, u }, { 97, u } };
+
+ @BeforeTest(alwaysRun = true)
+ public void setUpSiftsClient() throws SiftsException
+ {
+ // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
+ // test reproducibility
+ File testSiftsFile = new File("test/jalview/io/" + testPDBId
+ + ".xml.gz");
+ PDBfile pdbFile = new PDBfile(false, false, false);
+ siftsClient = new SiftsClient(pdbFile, 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" })
+ private void getAtomIndexTest()
+ {
+ // siftsClient.getAtomIndex(1, null);
+ // Assert.assertTrue(true);
+ }
+
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = IllegalArgumentException.class)
+ private void getAtomIndexNullTest()
+ {
+ siftsClient.getAtomIndex(1, null);
+ }
+
+ @Test(groups = { "Functional" })
+ private void padWithGapsTest()
+ {
+
+ }
+
+ @Test(groups = { "Functional" })
+ private void populateAtomPositionsTest()
+ {
+
+ }
+
+ @Test(groups = { "Functional" })
+ public void getValidSourceDBRefTest()
+ {
+
+ }
+
+ @Test(groups = { "Functional" })
+ public void isValidDBRefEntryTest()
+ {
+
+ }
+}