*/
package jalview.ws.sifts;
+import jalview.api.DBRefEntryI;
+import jalview.bin.Cache;
import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
+import jalview.io.AppletFormatAdapter;
+import jalview.structure.StructureMapping;
+import jalview.xml.binding.sifts.Entry.Entity;
-import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.PrintStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
import org.testng.Assert;
import org.testng.FileAssert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import MCview.Atom;
import MCview.PDBfile;
public class SiftsClientTest
{
- private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+
+ public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
+ .getProperty("user.home")
+ + File.separatorChar
+ + ".sifts_downloads" + File.separatorChar;
private String testPDBId = "1a70";
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 } };
+ HashMap<Integer, int[]> expectedMapping = new HashMap<Integer, int[]>();
@BeforeTest(alwaysRun = true)
+ public void populateExpectedMapping() throws SiftsException
+ {
+ expectedMapping.put(51, new int[] { 1, 2 });
+ expectedMapping.put(52, new int[] { 2, 7 });
+ expectedMapping.put(53, new int[] { 3, 12 });
+ expectedMapping.put(54, new int[] { 4, 24 });
+ expectedMapping.put(55, new int[] { 5, 33 });
+ expectedMapping.put(56, new int[] { 6, 40 });
+ expectedMapping.put(57, new int[] { 7, 47 });
+ expectedMapping.put(58, new int[] { 8, 55 });
+ expectedMapping.put(59, new int[] { 9, 62 });
+ expectedMapping.put(60, new int[] { 10, 69 });
+ expectedMapping.put(61, new int[] { 11, 76 });
+ expectedMapping.put(62, new int[] { 12, 83 });
+ expectedMapping.put(63, new int[] { 13, 87 });
+ expectedMapping.put(64, new int[] { 14, 95 });
+ expectedMapping.put(65, new int[] { 15, 102 });
+ expectedMapping.put(66, new int[] { 16, 111 });
+ expectedMapping.put(67, new int[] { 17, 122 });
+ expectedMapping.put(68, new int[] { 18, 131 });
+ expectedMapping.put(69, new int[] { 19, 137 });
+ expectedMapping.put(70, new int[] { 20, 144 });
+ expectedMapping.put(71, new int[] { 21, 152 });
+ expectedMapping.put(72, new int[] { 22, 160 });
+ expectedMapping.put(73, new int[] { 23, 167 });
+ expectedMapping.put(74, new int[] { 24, 179 });
+ expectedMapping.put(75, new int[] { 25, 187 });
+ expectedMapping.put(76, new int[] { 26, 195 });
+ expectedMapping.put(77, new int[] { 27, 203 });
+ expectedMapping.put(78, new int[] { 28, 208 });
+ expectedMapping.put(79, new int[] { 29, 213 });
+ expectedMapping.put(80, new int[] { 30, 222 });
+ expectedMapping.put(81, new int[] { 31, 231 });
+ expectedMapping.put(82, new int[] { 32, 240 });
+ expectedMapping.put(83, new int[] { 33, 244 });
+ expectedMapping.put(84, new int[] { 34, 252 });
+ expectedMapping.put(85, new int[] { 35, 260 });
+ expectedMapping.put(86, new int[] { 36, 268 });
+ expectedMapping.put(87, new int[] { 37, 275 });
+ expectedMapping.put(88, new int[] { 38, 287 });
+ expectedMapping.put(89, new int[] { 39, 293 });
+ expectedMapping.put(90, new int[] { 40, 299 });
+ expectedMapping.put(91, new int[] { 41, 310 });
+ expectedMapping.put(92, new int[] { 42, 315 });
+ expectedMapping.put(93, new int[] { 43, 319 });
+ expectedMapping.put(94, new int[] { 44, 325 });
+ expectedMapping.put(95, new int[] { 45, 331 });
+ expectedMapping.put(96, new int[] { 46, 337 });
+ expectedMapping.put(97, new int[] { 47, 343 });
+ expectedMapping.put(98, new int[] { 48, 349 });
+ expectedMapping.put(99, new int[] { 49, 354 });
+ expectedMapping.put(100, new int[] { 50, 358 });
+ expectedMapping.put(101, new int[] { 51, 367 });
+ expectedMapping.put(102, new int[] { 52, 375 });
+ expectedMapping.put(103, new int[] { 53, 384 });
+ expectedMapping.put(104, new int[] { 54, 391 });
+ expectedMapping.put(105, new int[] { 55, 395 });
+ expectedMapping.put(106, new int[] { 56, 401 });
+ expectedMapping.put(107, new int[] { 57, 409 });
+ expectedMapping.put(108, new int[] { 58, 417 });
+ expectedMapping.put(109, new int[] { 59, 426 });
+ expectedMapping.put(110, new int[] { 60, 434 });
+ expectedMapping.put(111, new int[] { 61, 442 });
+ expectedMapping.put(112, new int[] { 62, 451 });
+ expectedMapping.put(113, new int[] { 63, 457 });
+ expectedMapping.put(114, new int[] { 64, 468 });
+ expectedMapping.put(115, new int[] { 65, 476 });
+ expectedMapping.put(116, new int[] { 66, 484 });
+ expectedMapping.put(117, new int[] { 67, 492 });
+ expectedMapping.put(118, new int[] { 68, 500 });
+ expectedMapping.put(119, new int[] { 69, 509 });
+ expectedMapping.put(120, new int[] { 70, 517 });
+ expectedMapping.put(121, new int[] { 71, 525 });
+ expectedMapping.put(122, new int[] { 72, 534 });
+ expectedMapping.put(123, new int[] { 73, 538 });
+ expectedMapping.put(124, new int[] { 74, 552 });
+ expectedMapping.put(125, new int[] { 75, 559 });
+ expectedMapping.put(126, new int[] { 76, 567 });
+ expectedMapping.put(127, new int[] { 77, 574 });
+ expectedMapping.put(128, new int[] { 78, 580 });
+ expectedMapping.put(129, new int[] { 79, 585 });
+ expectedMapping.put(130, new int[] { 80, 590 });
+ expectedMapping.put(131, new int[] { 81, 602 });
+ expectedMapping.put(132, new int[] { 82, 609 });
+ expectedMapping.put(133, new int[] { 83, 616 });
+ expectedMapping.put(134, new int[] { 84, 622 });
+ expectedMapping.put(135, new int[] { 85, 630 });
+ expectedMapping.put(136, new int[] { 86, 637 });
+ expectedMapping.put(137, new int[] { 87, 644 });
+ expectedMapping.put(138, new int[] { 88, 652 });
+ expectedMapping.put(139, new int[] { 89, 661 });
+ expectedMapping.put(140, new int[] { 90, 668 });
+ expectedMapping.put(141, new int[] { 91, 678 });
+ expectedMapping.put(142, new int[] { 92, 687 });
+ expectedMapping.put(143, new int[] { 93, 696 });
+ expectedMapping.put(144, new int[] { 94, 705 });
+ expectedMapping.put(145, new int[] { 95, 714 });
+ expectedMapping.put(146, new int[] { 96, 722 });
+ expectedMapping.put(147, new int[] { 97, 729 });
+ }
+
+ @BeforeTest(alwaysRun = true)
public void setUpSiftsClient() throws SiftsException
{
+ // read test props before manipulating config
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
// 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);
+ new SiftsSettings();
+ SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
+ "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
+ SiftsSettings.setMapWithSifts(true);
+ SiftsSettings.setCacheThresholdInDays("2");
+ SiftsSettings.setFailSafePIDThreshold("70");
+ PDBfile pdbFile;
+ try
+ {
+ pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
+ + testPDBId + ".pdb", AppletFormatAdapter.FILE);
+ siftsClient = new SiftsClient(pdbFile);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
@AfterTest(alwaysRun = true)
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()
+ public void getSIFTsFileTest() throws SiftsException
{
- 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));
+ File siftsFile;
+ try
+ {
+ siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ // test for SIFTs file caching
+ SiftsSettings.setCacheThresholdInDays("0");
+ siftsFile = SiftsClient.getSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ SiftsSettings.setCacheThresholdInDays("2");
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ }
}
@Test(groups = { "Functional" })
- public void downloadSiftsFileTest()
+ public void downloadSiftsFileTest() throws SiftsException
{
// 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);
+ File siftsFile;
+ try
+ {
+ siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ SiftsClient.downloadSiftsFile(testPDBId);
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ }
}
+
@Test(groups = { "Functional" })
public void getAllMappingAccessionTest()
{
// 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,
+ HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
+ "A", testSeq,
null);
- Assert.assertEquals(actualMapping, expectedMapping);
Assert.assertEquals(testSeq.getStart(), 1);
Assert.assertEquals(testSeq.getEnd(), 147);
+ Assert.assertEquals(actualMapping, expectedMapping);
} catch (Exception e)
{
e.printStackTrace();
@Test(groups = { "Functional" })
private void getAtomIndexTest()
{
- // siftsClient.getAtomIndex(1, null);
- // Assert.assertTrue(true);
+ ArrayList<Atom> atoms = new ArrayList<Atom>();
+ Atom atom = new Atom(u, u, u);
+ atom.resNumber = 43;
+ atom.atomIndex = 7;
+ atoms.add(atom);
+ int actualAtomIndex = siftsClient.getAtomIndex(1, atoms);
+ Assert.assertEquals(actualAtomIndex, -1);
+ actualAtomIndex = siftsClient.getAtomIndex(43, atoms);
+ Assert.assertEquals(actualAtomIndex, 7);
}
@Test(
}
- @Test(groups = { "Functional" })
- private void populateAtomPositionsTest()
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = SiftsException.class)
+ private void populateAtomPositionsNullTest1()
+ throws IllegalArgumentException, SiftsException
{
+ siftsClient.populateAtomPositions(null, null);
+ }
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = SiftsException.class)
+ private void populateAtomPositionsNullTest2()
+ throws IllegalArgumentException, SiftsException
+ {
+ siftsClient.populateAtomPositions("A", null);
}
@Test(groups = { "Functional" })
public void getValidSourceDBRefTest()
{
+ try
+ {
+ DBRefEntryI actualValidSrcDBRef = siftsClient
+ .getValidSourceDBRef(testSeq);
+ DBRefEntryI expectedDBRef = new DBRefEntry();
+ expectedDBRef.setSource(DBRefSource.UNIPROT);
+ expectedDBRef.setAccessionId("P00221");
+ expectedDBRef.setVersion("");
+ Assert.assertEquals(actualValidSrcDBRef, expectedDBRef);
+ } catch (Exception e)
+ {
+ }
+ }
+
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = SiftsException.class)
+ public void getValidSourceDBRefExceptionTest() throws SiftsException
+ {
+ SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
+ try
+ {
+ siftsClient.getValidSourceDBRef(invalidTestSeq);
+ } catch (SiftsException e)
+ {
+ throw new SiftsException(e.getMessage());
+ }
+ }
+
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = SiftsException.class)
+ public void getValidSourceDBRefExceptionXTest() throws SiftsException
+ {
+ SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
+ DBRefEntry invalidDBRef = new DBRefEntry();
+ invalidDBRef.setAccessionId("BLAR");
+ invalidTestSeq.addDBRef(invalidDBRef);
+ try
+ {
+ siftsClient.getValidSourceDBRef(invalidTestSeq);
+ } catch (SiftsException e)
+ {
+ throw new SiftsException(e.getMessage());
+ }
}
@Test(groups = { "Functional" })
public void isValidDBRefEntryTest()
{
+ DBRefEntryI validDBRef = new DBRefEntry();
+ validDBRef.setSource(DBRefSource.UNIPROT);
+ validDBRef.setAccessionId("P00221");
+ validDBRef.setVersion("");
+ Assert.assertTrue(siftsClient.isValidDBRefEntry(validDBRef));
+ }
+
+ @Test(groups = { "Functional" })
+ public void getSiftsStructureMappingTest()
+ {
+ try
+ {
+ Assert.assertTrue(SiftsSettings.isMapWithSifts());
+ StructureMapping strucMapping = siftsClient.getSiftsStructureMapping(
+ testSeq, testPDBId, "A");
+ String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
+ + "Method: SIFTS\n\n"
+ + "P00221 : 1 - 97 Maps to \n"
+ + "1A70|A : 51 - 147\n\n"
+ + "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
+ + " |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
+ + "1A70|A AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n\n"
+
+ + "P00221 DDQIDEGWVLTCAAYPVSDVTIETHKEEELTA\n"
+ + " |||||||||||||||||||||||||| |||||\n"
+ + "1A70|A DDQIDEGWVLTCAAYPVSDVTIETHKKEELTA\n\n" +
+
+ "Length of alignment = 97\n" + "Percentage ID = 98.97\n";
+
+ Assert.assertEquals(strucMapping.getMappingDetailsOutput(),
+ expectedMappingOutput);
+ Assert.assertEquals(strucMapping.getMapping(), expectedMapping);
+ } catch (SiftsException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void getEntityCountTest()
+ {
+ int actualEntityCount = siftsClient.getEntityCount();
+ System.out.println("actual entity count : " + actualEntityCount);
+ Assert.assertEquals(actualEntityCount, 1);
+ }
+
+ @Test(groups = { "Functional" })
+ public void getDbAccessionIdTest()
+ {
+ String actualDbAccId = siftsClient.getDbAccessionId();
+ System.out.println("Actual Db Accession Id: " + actualDbAccId);
+ Assert.assertEquals(actualDbAccId, "1a70");
+ }
+
+ @Test(groups = { "Functional" })
+ public void getDbCoordSysTest()
+ {
+ String actualDbCoordSys = siftsClient.getDbCoordSys();
+ System.out.println("Actual DbCoordSys: " + actualDbCoordSys);
+ Assert.assertEquals(actualDbCoordSys, "PDBe");
+ }
+
+ @Test(groups = { "Functional" })
+ public void getDbSourceTest()
+ {
+ String actualDbSource = siftsClient.getDbSource();
+ System.out.println("Actual DbSource: " + actualDbSource);
+ Assert.assertEquals(actualDbSource, "PDBe");
+ }
+
+ @Test(groups = { "Functional" })
+ public void getDbVersionTest()
+ {
+ String actualDbVersion = siftsClient.getDbVersion();
+ System.out.println("Actual DbVersion: " + actualDbVersion);
+ Assert.assertEquals(actualDbVersion, "2.0");
+ }
+
+ @Test(groups = { "Functional" })
+ public void getEntityByMostOptimalMatchedIdTest()
+ {
+ SiftsClient siftsClientX = null;
+ PDBfile pdbFile;
+ try
+ {
+ pdbFile = new PDBfile(false, false, false, "test/jalview/io/2nq2"
+ + ".pdb", AppletFormatAdapter.FILE);
+ siftsClientX = new SiftsClient(pdbFile);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("A");
+ Assert.assertEquals(entityA.getEntityId(), "A");
+ Entity entityB = siftsClientX.getEntityByMostOptimalMatchedId("B");
+ Assert.assertEquals(entityB.getEntityId(), "C");
+ Entity entityC = siftsClientX.getEntityByMostOptimalMatchedId("C");
+ Assert.assertEquals(entityC.getEntityId(), "B");
+ Entity entityD = siftsClientX.getEntityByMostOptimalMatchedId("D");
+ Assert.assertEquals(entityD.getEntityId(), "D");
}
}