JAL-1479 updated SIFTS FTP download URL, added improvement to ensure that new SIFTS...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 10 Jun 2016 14:56:39 +0000 (15:56 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 10 Jun 2016 14:56:39 +0000 (15:56 +0100)
src/jalview/io/StructureFile.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/ws/sifts/SiftsClient.java
test/jalview/ws/sifts/SiftsClientTest.java

index af5a1fa..6a236fd 100644 (file)
@@ -297,6 +297,7 @@ public abstract class StructureFile extends AlignFile
     } catch (ClassNotFoundException q)
     {
     }
+    StructureViewSettings.setShowSeqFeatures(true);
   }
 
   public PDBChain findChain(String id) throws Exception
index 4dff04d..33c566d 100644 (file)
@@ -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<StructureMapping> foundSiftsMappings = new ArrayList<StructureMapping>();
+          for (PDBChain chain : pdb.getChains())
           {
-            ArrayList<StructureMapping> tempMapping = new ArrayList<StructureMapping>();
-            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);
           }
         }
       }
index 3c2e703..6c11dd2 100644 (file)
@@ -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);
   }
 
index a1c2c9a..28113d6 100644 (file)
@@ -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" })