From: TZVanaalten Date: Tue, 8 Aug 2017 16:55:12 +0000 (+0100) Subject: JAL-2629 add ability to select hmmer binaries folder X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=bb7c8e1f39eca07ec0bc544df298ee58f109b011;p=jalview.git JAL-2629 add ability to select hmmer binaries folder --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 5291493..339a764 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1315,11 +1315,13 @@ label.occupancy_descr = Number of aligned positions label.show_experimental = Enable experimental features label.show_experimental_tip = Enable any new and currently 'experimental' features (see Latest Release Notes for details) label.warning_hidden = Warning: {0} {1} is currently hidden -label.change_hmmer_directory = Change HMMER suite location label.auto_align_seqs = Automatically Align New Sequences label.hmmalign = Align Sequences to HMM label.hmmbuild = Build HMM from Alignment label.hmmsearch = Search for Related Sequences +label.change_hmmer_location = Set HMMER Installation Location warn.null_hmm = Please ensure the alignment contains a hidden Markov model. label.ignore_below_background_frequency = Ignore Below Background Frequency label.information_description = Information content, measured in bits +label.enter_location = Please enter the path of your HMMER binaries folder. +label.invalid_hmmer_folder = The folder that you selected does not contain the necessary HMMER binaries. diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index da3cb92..4b890cc 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -260,6 +260,8 @@ public class Cache private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER .toString(); + private static String HMMER_PATH; + /* * a date formatter using a fixed (rather than the user's) locale; * this ensures that date properties can be written and re-read successfully @@ -281,7 +283,7 @@ public class Cache @Override public synchronized Enumeration keys() { - return Collections.enumeration(new TreeSet(super.keySet())); + return Collections.enumeration(new TreeSet<>(super.keySet())); } }; diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index dba6717..9b5681b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -146,6 +146,7 @@ import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; @@ -339,6 +340,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, init(); } + public void setIsRecurring(boolean status) + { + recurring = status; + } + /** * initalise the alignframe from the underlying viewport data and the * configurations @@ -501,6 +507,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { hmmerMenu.removeAll(); + hmmerMenu.add(changeHMMERLocation); + hmmerMenu.addSeparator(); + hmmerMenu.add(autoAlignSeqs); hmmerMenu.addSeparator(); @@ -1053,13 +1062,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void hmmAlign_actionPerformed(ActionEvent e) throws IOException, InterruptedException { - SequenceI seq = getViewport().getAlignment() - .getHMMConsensusSequences(false).get(0); new Thread(new HMMAlignThread(this, true)).start(); alignPanel.repaint(); } @Override + public void changeHMMERLocation_actionPerformed(ActionEvent e) + { + String location = JOptionPane.showInputDialog( + MessageManager.getString("label.enter_location")); + Cache.setProperty(Preferences.HMMER_PATH, location); + } + + @Override public void autoAlignSeqs_actionPerformed(boolean autoAlignSeqs) { autoAlignNewSequences = autoAlignSeqs; @@ -4759,6 +4774,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, else { new FileLoader().LoadFile(viewport, file, sourceType, format); + if (autoAlignNewSequences && !recurring) + { + new Thread(new HMMAlignThread(this, false)).start(); + } } } } @@ -4788,14 +4807,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, + (format != null ? "(parsing as '" + format + "' file)" : ""), oom, Desktop.desktop); } - if (autoAlignNewSequences && !recurring) - { - recurring = true; - HiddenMarkovModel hmm = getViewport().getAlignment() - .getHMMConsensusSequences(false).get(0).getHMM(); - new Thread(new HMMAlignThread(this, false)).start(); - } - recurring = false; } /** @@ -5752,4 +5763,5 @@ class PrintThread extends Thread } } + } diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 8b4f85f..b5fa4e8 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -102,6 +102,8 @@ public class Preferences extends GPreferences public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY"; public static final String CHIMERA_PATH = "CHIMERA_PATH"; + + public static final String HMMER_PATH = "HMMER_PATH"; public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS"; @@ -1094,6 +1096,28 @@ public class Preferences extends GPreferences } return true; } + + /** + * Returns true if hmmer path contains the necessary valid executables, else show an error + * dialog. + */ + private boolean validateHMMERPath() + { + String path = Cache.getProperty("HMMERPATH"); + if (path.length() > 0) + { + File f = new File(path); + if (!f.canExecute()) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.invalid_hmmer_folder"), + MessageManager.getString("Invalid folder"), + JvOptionPane.ERROR_MESSAGE); + return false; + } + } + return true; + } /** * If Chimera is selected, check it can be found on default or user-specified diff --git a/src/jalview/hmmer/HMMAlignThread.java b/src/jalview/hmmer/HMMAlignThread.java index 8cd4270..3879a87 100644 --- a/src/jalview/hmmer/HMMAlignThread.java +++ b/src/jalview/hmmer/HMMAlignThread.java @@ -1,9 +1,12 @@ package jalview.hmmer; +import jalview.bin.Cache; import jalview.datamodel.AlignmentI; +import jalview.datamodel.AlignmentOrder; import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.Preferences; import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.io.FileLoader; @@ -11,6 +14,7 @@ import jalview.util.MessageManager; import java.io.FileNotFoundException; import java.io.IOException; +import java.util.HashMap; import java.util.Map; public class HMMAlignThread implements Runnable @@ -42,7 +46,7 @@ public class HMMAlignThread implements Runnable barID = System.currentTimeMillis(); af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), barID); - + HMMERCommands.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); try { try @@ -73,7 +77,7 @@ public class HMMAlignThread implements Runnable } } catch (Exception e) { - + e.printStackTrace(); } finally { af.setProgressBar(MessageManager.getString("status.running_hmmalign"), @@ -83,7 +87,7 @@ public class HMMAlignThread implements Runnable private void runCommand() throws IOException, InterruptedException { - String command = HMMERCommands.HMMALIGN; + String command = HMMERCommands.HMMERFOLDER + HMMERCommands.HMMALIGN; if (!hmm.getFileHeader().contains("HMMER3/f")) { command += HMMERCommands.ALLCOL; @@ -100,22 +104,31 @@ public class HMMAlignThread implements Runnable if (newFrame) { FileLoader loader = new FileLoader(); + AlignmentOrder order = new AlignmentOrder(alignment); AlignFrame newAFrame = loader.LoadFileWaitTillLoaded( HMMERCommands.ALIGNMENTINPUT, DataSourceType.FILE); - addSeqs(newAFrame); + Map copy = new HashMap<>( + hmmSeqs); + addSeqs(newAFrame, copy); + SequenceI seq = newAFrame.getViewport().getAlignment() + .getSequenceAt(0); + hmm.mapToReferenceAnnotation(newAFrame, seq); + addSeqs(af, hmmSeqs); } else { af.getViewport().getAlignment().getSequences().clear(); + af.setIsRecurring(true); af.loadJalviewDataFile(HMMERCommands.ALIGNMENTBUFFER, DataSourceType.FILE, FileFormat.Stockholm, null); - addSeqs(af); + af.setIsRecurring(false); + addSeqs(af, hmmSeqs); } } - private void addSeqs(AlignFrame alignFrame) + private void addSeqs(AlignFrame alignFrame, Map map) { - for (Map.Entry entry : hmmSeqs.entrySet()) + for (Map.Entry entry : map.entrySet()) { SequenceI seq = entry.getValue(); Integer pos = entry.getKey(); diff --git a/src/jalview/hmmer/HMMBuildThread.java b/src/jalview/hmmer/HMMBuildThread.java index c66e53d..e48dce3 100644 --- a/src/jalview/hmmer/HMMBuildThread.java +++ b/src/jalview/hmmer/HMMBuildThread.java @@ -1,9 +1,11 @@ package jalview.hmmer; +import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.Preferences; import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.util.MessageManager; @@ -34,6 +36,7 @@ public class HMMBuildThread implements Runnable barID = System.currentTimeMillis(); af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), barID); + HMMERCommands.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); try { @@ -79,7 +82,8 @@ public class HMMBuildThread implements Runnable private void runCommand() throws IOException, InterruptedException { - final String command = HMMERCommands.HMMBUILD + HMMERCommands.NAME + final String command = HMMERCommands.HMMERFOLDER + + HMMERCommands.HMMBUILD + HMMERCommands.NAME + af.getName() + HMMERCommands.SPACE + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.HMMBUFFER + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.ALIGNMENTBUFFER; diff --git a/src/jalview/hmmer/HMMERCommands.java b/src/jalview/hmmer/HMMERCommands.java index 56f7e3a..54516b5 100644 --- a/src/jalview/hmmer/HMMERCommands.java +++ b/src/jalview/hmmer/HMMERCommands.java @@ -17,15 +17,16 @@ import java.util.List; public class HMMERCommands { // Path of hmmer binaries directory - static final String HMMERFOLDER = "H:/Documents/"; + static String HMMERFOLDER = "/Documents/"; - static final String HMMALIGN = HMMERFOLDER + "hmmalign "; + static final String JALVIEWDIRECTORY = System.getProperty("user.dir") + + "/"; - static final String HMMBUILD = HMMERFOLDER + "hmmbuild "; + static String HMMALIGN = "/hmmalign "; - static final String HMMSEARCH = HMMERFOLDER + "hmmsearch "; + static String HMMBUILD = "/hmmbuild "; - static final String JALVIEWDIRECTORY = "C:/Users/TZVanaalten/git/jalview/"; + static String HMMSEARCH = "/hmmsearch "; static final String HMMBUFFER = "src/jalview/hmmer/hmm_buffer.hmm "; diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 0dc82cc..6e3c517 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -72,6 +72,8 @@ public class GAlignFrame extends JInternalFrame protected JCheckBoxMenuItem autoAlignSeqs = new JCheckBoxMenuItem(); + protected JMenuItem changeHMMERLocation = new JCheckBoxMenuItem(); + protected JMenuItem hmmAlign = new JMenuItem(); protected JMenuItem hmmSearch = new JMenuItem(); @@ -1756,6 +1758,18 @@ public class GAlignFrame extends JInternalFrame } }); + changeHMMERLocation.setText( + MessageManager.getString("label.change_hmmer_location")); + changeHMMERLocation.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + changeHMMERLocation_actionPerformed(e); + } + + }); selectHighlighted.addActionListener(al); JMenu tooltipSettingsMenu = new JMenu( MessageManager.getString("label.sequence_id_tooltip")); @@ -2449,6 +2463,10 @@ public class GAlignFrame extends JInternalFrame { } + protected void changeHMMERLocation_actionPerformed(ActionEvent e) + { + } + protected void hmmBuild_actionPerformed(ActionEvent e) throws IOException, InterruptedException {