From 2651fb17a01a99d8d4b4b241ff5dff1d6edd6ec0 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Thu, 24 Aug 2017 12:24:46 +0100 Subject: [PATCH] JAL-2629 add ability to add and select a DB for hmmsearch --- resources/lang/Messages.properties | 6 ++- src/jalview/gui/AlignFrame.java | 78 ++++++++++++++++++++++++++++++-- src/jalview/gui/Preferences.java | 4 ++ src/jalview/hmmer/HMMERParamStore.java | 33 ++++++++++++++ src/jalview/jbgui/GAlignFrame.java | 29 ++++++++++++ 5 files changed, 146 insertions(+), 4 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 0749a23..a7623f7 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1360,4 +1360,8 @@ label.seq_e_value_desc = The E-value cutoff for returned sequences. label.seq_score_desc = The score threshold for returned sequences. label.dom_e_value_desc = The E-value cutoff for returned domains. label.dom_score_desc = The score threshold for returned domains. -label.not_enough_sequences = There are not enough sequences to run {0} \ No newline at end of file +label.not_enough_sequences = There are not enough sequences to run {0} +label.add_database = Add Database +warn.file_not_exists = File does not exist +warn.invalid_format = This is not a valid database file format. The current supported formats are Fasta, Stockholm and Pfam. +label.database_for_hmmsearch = The database hmmsearch will search through. \ No newline at end of file diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 85e3db5..d1d8a61 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -93,6 +93,7 @@ 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,10 +144,12 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.Scanner; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; import javax.swing.JEditorPane; +import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; @@ -172,9 +175,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public static final int DEFAULT_HEIGHT = 500; - boolean autoAlignNewSequences; - - /* * The currently displayed panel (selected tabbed view if more than one) */ @@ -1163,6 +1163,78 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } @Override + public void addDatabase_actionPerformed(ActionEvent e) throws IOException + { + if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null) + { + Cache.setProperty(Preferences.HMMSEARCH_DBS, ""); + Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, ""); + } + + String path = openFileChooser(false); + if (new File(path).exists()) + { + IdentifyFile identifier = new IdentifyFile(); + FileFormatI format = identifier.identify(path, DataSourceType.FILE); + 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, new String("/")); + 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); + Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths); + } + else + { + JOptionPane.showMessageDialog(this, + MessageManager.getString("warn.invalid_format")); + } + } + else + { + JOptionPane.showMessageDialog(this, + MessageManager.getString("warn.not_enough_sequences")); + } + } + + /** + * Opens a file chooser + * + * @param forFolder + * @return + */ + protected String openFileChooser(boolean forFolder) + { + String choice = null; + JFileChooser chooser = new JFileChooser(); + if (forFolder) + { + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + chooser.setDialogTitle( + MessageManager.getString("label.open_local_file")); + chooser.setToolTipText(MessageManager.getString("action.open")); + + int value = chooser.showOpenDialog(this); + + if (value == JFileChooser.APPROVE_OPTION) + { + choice = chooser.getSelectedFile().getPath(); + } + return choice; + } + + @Override public void reload_actionPerformed(ActionEvent e) { if (fileName != null) diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 7af3abc..bb226a0 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -112,6 +112,10 @@ public class Preferences extends GPreferences public static final String HMMER_PATH = "HMMER_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"; public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE"; diff --git a/src/jalview/hmmer/HMMERParamStore.java b/src/jalview/hmmer/HMMERParamStore.java index 1bfc72f..3dad581 100644 --- a/src/jalview/hmmer/HMMERParamStore.java +++ b/src/jalview/hmmer/HMMERParamStore.java @@ -1,6 +1,8 @@ package jalview.hmmer; +import jalview.bin.Cache; +import jalview.gui.Preferences; import jalview.util.MessageManager; import jalview.ws.params.ArgumentI; import jalview.ws.params.ParamDatastoreI; @@ -8,10 +10,13 @@ import jalview.ws.params.WsParamSetI; import jalview.ws.params.simple.BooleanOption; import jalview.ws.params.simple.IntegerParameter; import jalview.ws.params.simple.LogarithmicParameter; +import jalview.ws.params.simple.Option; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Scanner; public class HMMERParamStore implements ParamDatastoreI @@ -51,6 +56,34 @@ public class HMMERParamStore implements ParamDatastoreI MessageManager .getString("label.number_of_results_desc"), true, 100, 0, 100000)); + String names = Cache.getProperty(Preferences.HMMSEARCH_DBS); + if (names != null && !names.isEmpty()) + { + Collection databases = new ArrayList<>(); + databases.add("This Alignment"); + Scanner nameScanner = new Scanner(names); + + if (nameScanner.hasNext()) + { + while (nameScanner.hasNext()) + { + String next = nameScanner.next(); + if (next == "null") + { + Cache.setProperty(Preferences.HMMSEARCH_DBS, ""); + Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, ""); + } + else + { + databases.add(next); + } + } + } + nameScanner.close(); + args.add(new Option(MessageManager.getString("label.database"), + MessageManager.getString("label.database_for_hmmsearch"), + true, "This Alignment", "This Alignment", databases, null)); + } args.add(new BooleanOption( MessageManager.getString("label.auto_align_seqs"), MessageManager.getString("label.auto_align_seqs_desc"), diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index cf6c487..c2d19d7 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -25,6 +25,7 @@ import jalview.api.SplitContainerI; import jalview.bin.Cache; import jalview.gui.JvSwingUtils; import jalview.gui.Preferences; +import jalview.io.FileFormatException; import jalview.io.FileFormats; import jalview.util.MessageManager; import jalview.util.Platform; @@ -82,6 +83,8 @@ public class GAlignFrame extends JInternalFrame protected JMenuItem hmmSearchSettings = new JMenuItem(); + protected JMenuItem addDatabase = new JMenuItem(); + protected JMenu hmmBuild = new JMenu(); protected JMenuItem hmmBuildRun = new JMenuItem(); @@ -1833,6 +1836,24 @@ public class GAlignFrame extends JInternalFrame } }); + addDatabase.setText(MessageManager.getString("label.add_database")); + addDatabase.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + try + { + addDatabase_actionPerformed(e); + } catch (IOException e1) + { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + + }); hmmSearchSettings.setText( MessageManager.getString("label.edit_settings_and_run")); hmmSearchSettings.addActionListener(new ActionListener() @@ -2055,8 +2076,11 @@ public class GAlignFrame extends JInternalFrame MessageManager.getString("label.edit_settings_and_run")); hmmSearchRun = new JMenuItem(MessageManager.formatMessage( "label.action_with_default_settings", "hmmsearch")); + addDatabase = new JMenuItem( + MessageManager.getString("label.add_database")); hmmSearch.add(hmmSearchSettings); hmmSearch.add(hmmSearchRun); + hmmSearch.add(addDatabase); } /** @@ -2552,6 +2576,11 @@ public class GAlignFrame extends JInternalFrame { } + protected void addDatabase_actionPerformed(ActionEvent e) + throws FileFormatException, IOException + { + } + protected void hmmAlignRun_actionPerformed(ActionEvent e) throws IOException, InterruptedException { -- 1.7.10.2