JAL-1999 JAL-1479 implemented configurable fail-safe mechanism for SIFTS mapping...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 26 Jan 2016 12:56:22 +0000 (12:56 +0000)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 26 Jan 2016 12:56:22 +0000 (12:56 +0000)
src/jalview/bin/Cache.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/ws/sifts/SiftsClient.java
src/jalview/ws/sifts/SiftsSettings.java

index b492067..f9480ab 100755 (executable)
@@ -221,6 +221,11 @@ public class Cache
           .getProperty("user.home")
           + File.separatorChar
           + ".sifts_downloads" + File.separatorChar;
+
+  private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
+
+  private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
+
   /**
    * Initialises the Jalview Application Log
    */
@@ -406,6 +411,14 @@ public class Cache
     SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
             "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
 
+    SiftsSettings.setFailSafePIDThreshold(jalview.bin.Cache.getDefault(
+            "sifts_fail_safe_pid_threshold",
+            DEFAULT_FAIL_SAFE_PID_THRESHOLD));
+
+    SiftsSettings.setCacheThresholdInDays(jalview.bin.Cache.getDefault(
+            "sifts_cache_threshold_in_days",
+            DEFAULT_CACHE_THRESHOLD_IN_DAYS));
+
     System.out
             .println("Jalview Version: " + codeVersion + codeInstallation);
 
index 2f962b5..b3b5708 100644 (file)
@@ -522,11 +522,11 @@ public class StructureSelectionManager
           }
         } catch (SiftsException e)
         {
-          e.printStackTrace();
+          System.err.println(e.getMessage());
           System.err
-                  .println(">>>>>>> SIFTs mapping could not be obtained... Now mapping with NW alignment");
+                  .println(">>> Now switching mapping with NW alignment...");
           setProgressBar(null);
-          setProgressBar("SIFTs mapping could not be obtained... Now mapping with NW alignment");
+          setProgressBar(">>> Now switching mapping with NW alignment...");
           seqToStrucMapping = getNWMappings(seq, pdbFile, maxChainId,
                   maxChain, pdb, maxAlignseq);
         }
index 5b03ddb..f866127 100644 (file)
@@ -103,7 +103,9 @@ public class SiftsClient implements SiftsClientI
 
   private final static String NEWLINE = System.lineSeparator();
 
-  private final static int THRESHOLD_IN_DAYS = 2;
+  // private final static int CACHE_THRESHOLD_IN_DAYS = 2;
+  //
+  // private final static int FAIL_SAFE_PID_THRESHOLD = 30;
 
   private String curSourceDBRef;
 
@@ -233,7 +235,8 @@ public class SiftsClient implements SiftsClientI
       // The line below is required for unit testing... don't comment it out!!!
       System.out.println(">>> SIFTS File already downloaded for " + pdbId);
 
-      if (isFileOlderThanThreshold(siftsFile, THRESHOLD_IN_DAYS))
+      if (isFileOlderThanThreshold(siftsFile,
+              SiftsSettings.getCacheThresholdInDays()))
       {
         // System.out.println("Downloaded file is out of date, hence re-downloading...");
         siftsFile = downloadSiftsFile(pdbId.toLowerCase());
@@ -578,6 +581,10 @@ public class SiftsClient implements SiftsClientI
 
     Integer[] keys = mapping.keySet().toArray(new Integer[0]);
     Arrays.sort(keys);
+    if (keys.length < 1)
+    {
+      throw new SiftsException(">>> Empty SIFTS mapping generated!!");
+    }
     seqStart = keys[0];
     seqEnd = keys[keys.length - 1];
 
@@ -987,9 +994,10 @@ public class SiftsClient implements SiftsClientI
       output.append(NEWLINE).append(NEWLINE);
     }
     float pid = (float) matchedSeqCount / seqRes.length() * 100;
-    if (pid < 2)
+    if (pid < SiftsSettings.getFailSafePIDThreshold())
     {
-      throw new SiftsException("Low PID detected for SIFTs mapping...");
+      throw new SiftsException(
+">>> Low PID detected for SIFTs mapping...");
     }
     output.append("Length of alignment = " + seqRes.length()).append(
             NEWLINE);
index 5554658..e1e3de8 100644 (file)
@@ -1,11 +1,17 @@
 package jalview.ws.sifts;
 
+import java.util.Objects;
+
 public class SiftsSettings
 {
   private static boolean mapWithSifts = false;
 
   private static String siftDownloadDirectory;
 
+  private static int cacheThresholdInDays;
+
+  private static int failSafePIDThreshold;
+
   public static boolean isMapWithSifts()
   {
     return mapWithSifts;
@@ -25,4 +31,28 @@ public class SiftsSettings
   {
     SiftsSettings.siftDownloadDirectory = siftDownloadDirectory;
   }
+
+  public static int getCacheThresholdInDays()
+  {
+    return cacheThresholdInDays;
+  }
+
+  public static void setCacheThresholdInDays(String cacheThresholdInDays)
+  {
+    Objects.requireNonNull(cacheThresholdInDays);
+    SiftsSettings.cacheThresholdInDays = Integer
+            .valueOf(cacheThresholdInDays);
+  }
+
+  public static int getFailSafePIDThreshold()
+  {
+    return failSafePIDThreshold;
+  }
+
+  public static void setFailSafePIDThreshold(String failSafePIDThreshold)
+  {
+    Objects.requireNonNull(failSafePIDThreshold);
+    SiftsSettings.failSafePIDThreshold = Integer
+            .valueOf(failSafePIDThreshold);
+  }
 }