JAL-2711 show short file names in search database combo box
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 14 May 2018 11:17:51 +0000 (12:17 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 14 May 2018 11:17:51 +0000 (12:17 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Preferences.java
src/jalview/hmmer/HMMERParamStore.java

index d52aa97..89066cb 100644 (file)
@@ -94,7 +94,6 @@ import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
 import jalview.util.MessageManager;
-import jalview.util.StringUtils;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 import jalview.ws.DBRefFetcher;
@@ -143,7 +142,6 @@ import java.util.Deque;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Scanner;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
@@ -1140,13 +1138,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     return true;
   }
 
+  /**
+   * Opens a file browser and adds the selected file, if in Fasta, Stockholm or
+   * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a
+   * comma-separated list)
+   */
   @Override
   public void addDatabase_actionPerformed() throws IOException
   {
-    if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null)
+    if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null)
     {
       Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
-      Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
     }
 
     String path = openFileChooser(false);
@@ -1157,19 +1159,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (format == FileFormat.Fasta || format == FileFormat.Stockholm
               || format == FileFormat.Pfam)
       {
-        String currentDbs = Cache.getProperty(Preferences.HMMSEARCH_DBS);
         String currentDbPaths = Cache
-                .getProperty(Preferences.HMMSEARCH_DB_PATHS);
-        currentDbPaths += " " + path;
-
-        String fileName = StringUtils.getLastToken(path, File.separator);
-        Scanner scanner = new Scanner(fileName).useDelimiter(".");
-        String name = scanner.next();
-        scanner.close();
-        currentDbs += " " + path; // TODO remove path from file name
-        scanner.close();
-
-        Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, currentDbPaths);
+                .getProperty(Preferences.HMMSEARCH_DBS);
+        currentDbPaths += Preferences.COMMA + path;
         Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
       }
       else
index 5382f8d..3259909 100755 (executable)
@@ -86,6 +86,9 @@ import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
  */
 public class Preferences extends GPreferences
 {
+  // suggested list delimiter character
+  public static final String COMMA = ",";
+
   public static final String HMMSEARCH_SEQCOUNT = "HMMSEARCH_SEQCOUNT";
 
   public static final String HMMINFO_GLOBAL_BACKGROUND = "HMMINFO_GLOBAL_BACKGROUND";
@@ -118,8 +121,6 @@ public class Preferences extends GPreferences
 
   public static final String CYGWIN_PATH = "CYGWIN_PATH";
 
-  public static final String HMMSEARCH_DB_PATHS = "HMMSEARCH_DB_PATHS";
-
   public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
 
   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
index fbab7a9..00cae85 100644 (file)
@@ -15,10 +15,10 @@ import jalview.ws.params.simple.LogarithmicParameter;
 import jalview.ws.params.simple.Option;
 import jalview.ws.params.simple.StringParameter;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.List;
 import java.util.Scanner;
 
@@ -101,39 +101,6 @@ public final class HMMERParamStore implements ParamDatastoreI
     /*
      * 'Options'
      */
-    addChoiceOfHmm(args);
-
-    String names = Cache.getProperty(Preferences.HMMSEARCH_DBS);
-    if (names != null && !names.isEmpty())
-    {
-      List<String> databases = new ArrayList<>();
-      databases.add(MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY));
-      Scanner nameScanner = new Scanner(names);
-
-      if (nameScanner.hasNext())
-      {
-        while (nameScanner.hasNext())
-        {
-          String next = nameScanner.next();
-          if ("null".equals(next))
-          {
-            Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
-            Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
-          }
-          else
-          {
-            databases.add(next);
-          }
-        }
-      }
-      nameScanner.close();
-      args.add(new StringParameter(
-              MessageManager.getString(HMMSearch.DATABASE_KEY),
-              MessageManager.getString("label.database_for_hmmsearch"),
-              true, MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY),
-              MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY),
-              databases));
-    }
     args.add(new BooleanOption(
             MessageManager.getString(HMMSearch.AUTO_ALIGN_SEQS_KEY),
             MessageManager.getString("label.auto_align_seqs_desc"), false,
@@ -150,6 +117,10 @@ public final class HMMERParamStore implements ParamDatastoreI
     /*
      * 'Parameters'
      */
+    addChoiceOfHmm(args);
+
+    addChoiceOfDatabase(args);
+
     args.add(new IntegerParameter(
             MessageManager.getString(HMMSearch.NUMBER_OF_RESULTS_KEY),
             MessageManager.getString("label.number_of_results_desc"), true,
@@ -158,7 +129,8 @@ public final class HMMERParamStore implements ParamDatastoreI
             MessageManager.getString(HMMSearch.REPORTING_CUTOFF_KEY), null,
             true, HMMSearch.CUTOFF_NONE, HMMSearch.CUTOFF_NONE,
             Arrays.asList(HMMSearch.CUTOFF_NONE, HMMSearch.CUTOFF_EVALUE,
-                    HMMSearch.CUTOFF_SCORE)));
+                    HMMSearch.CUTOFF_SCORE),
+            null));
     args.add(new LogarithmicParameter(
             MessageManager.getString(HMMSearch.SEQ_EVALUE_KEY),
             MessageManager.getString("label.seq_e_value_desc"), false, 1D,
@@ -180,6 +152,56 @@ public final class HMMERParamStore implements ParamDatastoreI
   }
 
   /**
+   * Constructs a choice parameter for database to search; always includes 'this
+   * alignment', and also includes any databases held under user preferences key
+   * "HMMSEARCH_DBS" as a comma-delimited list
+   * 
+   * @param args
+   */
+  protected void addChoiceOfDatabase(List<ArgumentI> args)
+  {
+    String names = Cache.getProperty(Preferences.HMMSEARCH_DBS);
+    if (names == null || names.isEmpty())
+    {
+      return;
+    }
+
+    List<String> filePaths = new ArrayList<>();
+    List<String> fileNames = new ArrayList<>();
+
+    String thisAlignment = MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY);
+    filePaths.add(thisAlignment);
+    fileNames.add(thisAlignment);
+
+    Scanner nameScanner = new Scanner(names);
+    nameScanner.useDelimiter(Preferences.COMMA);
+
+    while (nameScanner.hasNext())
+    {
+      String next = nameScanner.next();
+      if ("null".equals(next))
+      {
+        Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
+      }
+      else
+      {
+        filePaths.add(next);
+        int pos = next.lastIndexOf(File.separator);
+        String fileName = next.substring(pos + 1);
+        fileNames.add(fileName);
+      }
+    }
+    nameScanner.close();
+    ArgumentI databasesOption = new StringParameter(
+            MessageManager.getString(HMMSearch.DATABASE_KEY),
+            MessageManager.getString("label.database_for_hmmsearch"), true,
+            thisAlignment,
+            thisAlignment,
+            filePaths, fileNames);
+    args.add(databasesOption);
+  }
+
+  /**
    * Answers default parameters for hmmalign, taking into account any configured
    * as user preferences
    * 
@@ -216,7 +238,7 @@ public final class HMMERParamStore implements ParamDatastoreI
       String defseq = options.get(0);
       ArgumentI arg = new StringParameter(
               MessageManager.getString("label.use_hmm"), null, true, defseq,
-              defseq, options);
+              defseq, options, null);
       args.add(arg);
     }
   }
@@ -256,7 +278,7 @@ public final class HMMERParamStore implements ParamDatastoreI
      */
     if (!viewport.getAlignment().getGroups().isEmpty())
     {
-      Collection<String> options = new ArrayList<>();
+      List<String> options = new ArrayList<>();
       options.add(MessageManager.getString("label.alignment"));
       options.add(MessageManager.getString("label.groups_and_alignment"));
       options.add(MessageManager.getString("label.groups"));