From 776ce4a23c079b7a4baf9f49c10a2e3776842bf0 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Tue, 26 Jan 2016 12:56:22 +0000 Subject: [PATCH] JAL-1999 JAL-1479 implemented configurable fail-safe mechanism for SIFTS mapping based on a PID threshold. Also added config threshold parameter for auto-computing time-based caching of downloaded SIFTS --- src/jalview/bin/Cache.java | 13 +++++++++ .../structure/StructureSelectionManager.java | 6 ++-- src/jalview/ws/sifts/SiftsClient.java | 16 ++++++++--- src/jalview/ws/sifts/SiftsSettings.java | 30 ++++++++++++++++++++ 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index b492067..f9480ab 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -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); diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 2f962b5..b3b5708 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -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); } diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index 5b03ddb..f866127f 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -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); diff --git a/src/jalview/ws/sifts/SiftsSettings.java b/src/jalview/ws/sifts/SiftsSettings.java index 5554658..e1e3de8 100644 --- a/src/jalview/ws/sifts/SiftsSettings.java +++ b/src/jalview/ws/sifts/SiftsSettings.java @@ -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); + } } -- 1.7.10.2