From cbf0b72e90f4c719dff345e467b5c9b9873247ed Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Fri, 10 Jun 2016 15:56:39 +0100 Subject: [PATCH] JAL-1479 updated SIFTS FTP download URL, added improvement to ensure that new SIFTS file are successfully downloaded before overwriting the outdated cached ones, and added fix for PDB RESNUM transfer via JMol parser --- src/jalview/io/StructureFile.java | 1 + .../structure/StructureSelectionManager.java | 52 ++++++++++++-------- src/jalview/ws/sifts/SiftsClient.java | 43 ++++++++++------ test/jalview/ws/sifts/SiftsClientTest.java | 14 ++++-- 4 files changed, 71 insertions(+), 39 deletions(-) diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java index af5a1fa..6a236fd 100644 --- a/src/jalview/io/StructureFile.java +++ b/src/jalview/io/StructureFile.java @@ -297,6 +297,7 @@ public abstract class StructureFile extends AlignFile } catch (ClassNotFoundException q) { } + StructureViewSettings.setShowSeqFeatures(true); } public PDBChain findChain(String id) throws Exception diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 4dff04d..33c566d 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -506,41 +506,53 @@ public class StructureSelectionManager .getMappingFromS1(false); if (targetChainId != null && !targetChainId.trim().isEmpty()) { - StructureMapping mapping; + StructureMapping siftsMapping; try { - mapping = getStructureMapping(seq, pdbFile, targetChainId, pdb, - maxChain, sqmpping, maxAlignseq); - seqToStrucMapping.add(mapping); + siftsMapping = getStructureMapping(seq, pdbFile, targetChainId, + pdb, maxChain, sqmpping, maxAlignseq); + seqToStrucMapping.add(siftsMapping); + maxChain.makeExactMapping(maxAlignseq, seq); + maxChain.transferRESNUMFeatures(seq, null); + maxChain.transferResidueAnnotation(siftsMapping, sqmpping); } catch (SiftsException e) { - // e.printStackTrace(); // fall back to NW alignment System.err.println(e.getMessage()); - seqToStrucMapping.add(getNWMappings(seq, pdbFile, - targetChainId, - maxChain, pdb, maxAlignseq)); + StructureMapping nwMapping = getNWMappings(seq, pdbFile, + targetChainId, maxChain, pdb, maxAlignseq); + seqToStrucMapping.add(nwMapping); } } else { - try + ArrayList foundSiftsMappings = new ArrayList(); + for (PDBChain chain : pdb.getChains()) { - ArrayList tempMapping = new ArrayList(); - for (PDBChain chain : pdb.getChains()) + try { - StructureMapping mapping = getStructureMapping(seq, pdbFile, + StructureMapping siftsMapping = getStructureMapping(seq, + pdbFile, chain.id, pdb, chain, sqmpping, maxAlignseq); - tempMapping.add(mapping); + foundSiftsMappings.add(siftsMapping); + } catch (SiftsException e) + { + System.err.println(e.getMessage()); } - seqToStrucMapping.addAll(tempMapping); - } catch (SiftsException e) + } + if (!foundSiftsMappings.isEmpty()) { - // e.printStackTrace(); - // fall back to NW alignment - System.err.println(e.getMessage()); - seqToStrucMapping.add(getNWMappings(seq, pdbFile, maxChainId, - maxChain, pdb, maxAlignseq)); + seqToStrucMapping.addAll(foundSiftsMappings); + maxChain.makeExactMapping(maxAlignseq, seq); + maxChain.transferRESNUMFeatures(seq, null); + maxChain.transferResidueAnnotation(foundSiftsMappings.get(0), + sqmpping); + } + else + { + StructureMapping nwMapping = getNWMappings(seq, pdbFile, + maxChainId, maxChain, pdb, maxAlignseq); + seqToStrucMapping.add(nwMapping); } } } diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index 3c2e703..6c11dd2 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -96,11 +96,9 @@ public class SiftsClient implements SiftsClientI private static final int PDB_ATOM_POS = 1; - private static final String NOT_FOUND = "Not_Found"; - private static final String NOT_OBSERVED = "Not_Observed"; - private static final String SIFTS_FTP_BASE_URL = "ftp://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/"; + private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/"; private final static String NEWLINE = System.lineSeparator(); @@ -225,8 +223,9 @@ public class SiftsClient implements SiftsClientI */ public static File getSiftsFile(String pdbId) throws SiftsException { - File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory() - + pdbId.toLowerCase() + ".xml.gz"); + String siftsFileName = SiftsSettings.getSiftDownloadDirectory() + + pdbId.toLowerCase() + ".xml.gz"; + File siftsFile = new File(siftsFileName); if (siftsFile.exists()) { // The line below is required for unit testing... don't comment it out!!! @@ -235,12 +234,28 @@ public class SiftsClient implements SiftsClientI if (isFileOlderThanThreshold(siftsFile, SiftsSettings.getCacheThresholdInDays())) { - // System.out.println("Downloaded file is out of date, hence re-downloading..."); - siftsFile = downloadSiftsFile(pdbId.toLowerCase()); + File oldSiftsFile = new File(siftsFileName + "_old"); + siftsFile.renameTo(oldSiftsFile); + try + { + siftsFile = downloadSiftsFile(pdbId.toLowerCase()); + oldSiftsFile.delete(); + return siftsFile; + } catch (IOException e) + { + e.printStackTrace(); + oldSiftsFile.renameTo(siftsFile); + return new File(siftsFileName); + } } - return siftsFile; } - siftsFile = downloadSiftsFile(pdbId.toLowerCase()); + try + { + siftsFile = downloadSiftsFile(pdbId.toLowerCase()); + } catch (IOException e) + { + throw new SiftsException(e.getMessage()); + } return siftsFile; } @@ -278,8 +293,10 @@ public class SiftsClient implements SiftsClientI * @param pdbId * @return downloaded SIFTs XML file * @throws SiftsException + * @throws IOException */ - public static File downloadSiftsFile(String pdbId) throws SiftsException + public static File downloadSiftsFile(String pdbId) throws SiftsException, + IOException { if (pdbId.contains(".cif")) { @@ -295,8 +312,6 @@ public class SiftsClient implements SiftsClientI { siftsDownloadDir.mkdirs(); } - try - { // System.out.println(">> Download ftp url : " + siftsFileFTPURL); URL url = new URL(siftsFileFTPURL); URLConnection conn = url.openConnection(); @@ -312,10 +327,6 @@ public class SiftsClient implements SiftsClientI outputStream.close(); inputStream.close(); // System.out.println(">>> File downloaded : " + downloadedSiftsFile); - } catch (IOException ex) - { - throw new SiftsException(ex.getMessage()); - } return new File(downloadedSiftsFile); } diff --git a/test/jalview/ws/sifts/SiftsClientTest.java b/test/jalview/ws/sifts/SiftsClientTest.java index a1c2c9a..28113d6 100644 --- a/test/jalview/ws/sifts/SiftsClientTest.java +++ b/test/jalview/ws/sifts/SiftsClientTest.java @@ -26,6 +26,7 @@ import jalview.datamodel.SequenceI; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.io.PrintStream; import java.util.HashMap; @@ -122,9 +123,16 @@ public class SiftsClientTest // 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" }) -- 1.7.10.2