From: TZVanaalten Date: Mon, 14 Aug 2017 10:43:21 +0000 (+0100) Subject: JAL-2629 add validation for HMMER path X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e72204b6418eec97b08ed43019e5e7ea8cc6fb82;p=jalview.git JAL-2629 add validation for HMMER path --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 2499e79..807f88f 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1315,7 +1315,6 @@ 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.auto_align_seqs = Automatically Align New Sequences label.hmmalign = Align Sequences to HMM label.hmmbuild = Build HMM from Alignment label.hmmbuild_group = Build HMM from Selected Group @@ -1325,7 +1324,7 @@ label.change_hmmer_location = 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.enter_location = Please enter the path of your HMMER folder. label.invalid_hmmer_folder = The folder that you selected does not contain the necessary HMMER binaries. warn.no_selected_hmm = Please select a hidden Markov model sequence. label.select_hmm = Select HMM @@ -1337,3 +1336,10 @@ label.freq_alignment = Use Alignment Background Frequencies label.freq_uniprot = Use Uniprot Background Frequencies label.hmmalign_label = hmmalign Options label.hmmsearch_label = hmmsearch Options +label.hmmbuild_not_found = The hmmbuild binary was not found. +label.hmmalign_not_found = The hmmalign binary was not found. +label.hmmsearch_not_found = The hmmsearch binary was not found. +warn.hmmbuild_failed = hmmbuild was not found. +warn.align_failed = hmmalign was not found. +label.invalid_folder = Invalid Folder +label.folder_not_exists = HMMER not found. \n Please enter the path to HMMER (if installed). \ No newline at end of file diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index c25fc2f..e11bdec 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -214,7 +214,15 @@ public class Preferences extends GPreferences } numberOfSequencesToKeepField .setText(Cache.getProperty("SEQUENCES_TO_KEEP")); - installationLocationField.setText(Cache.getProperty(HMMER_PATH)); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); + hmmerPath.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + validateHMMERPath(); + } + }); /* * Set Visual tab defaults @@ -665,7 +673,7 @@ public class Preferences extends GPreferences Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP", numberOfSequencesToKeepField.getText()); Cache.applicationProperties.setProperty(HMMER_PATH, - installationLocationField.getText()); + hmmerPath.getText()); trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false)); if (Cache.getDefault("USE_UNIPROT", false)) { @@ -677,7 +685,7 @@ public class Preferences extends GPreferences } numberOfSequencesToKeepField .setText(Cache.getProperty("SEQUENCES_TO_KEEP")); - installationLocationField.setText(Cache.getProperty(HMMER_PATH)); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); /* * Save Structure settings @@ -836,6 +844,11 @@ public class Preferences extends GPreferences structureTab.requestFocusInWindow(); return false; } + if (!validateHMMER()) + { + hmmerTab.requestFocusInWindow(); + return false; + } return true; } @@ -846,6 +859,13 @@ public class Preferences extends GPreferences } + @Override + protected boolean validateHMMER() + { + return validateHMMERPath(); + + } + /** * DOCUMENT ME! */ @@ -1143,18 +1163,74 @@ public class Preferences extends GPreferences */ private boolean validateHMMERPath() { - String path = Cache.getProperty("HMMERPATH"); - if (path.length() > 0) + int missing = 0; + String message = ""; + String path = hmmerPath.getText(); + if (path.length() < 1) + { + return false; + } + else { File f = new File(path); - if (!f.canExecute()) + if (!f.exists()) { JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.invalid_hmmer_folder"), - MessageManager.getString("Invalid folder"), + MessageManager.getString("label.folder_not_exists"), + MessageManager.getString("label.invalid_folder"), JvOptionPane.ERROR_MESSAGE); return false; } + + File hmmbuild = new File(path + "/binaries/hmmbuild.exe"); + { + if (!hmmbuild.canExecute()) + { + message += MessageManager.getString("label.hmmbuild_not_found") + + "\n"; + missing++; + } + } + + File hmmalign = new File(path + "/binaries/hmmalign.exe"); + { + if (!hmmalign.canExecute()) + { + message += MessageManager.getString("label.hmmalign_not_found") + + "\n"; + missing++; + } + } + + File hmmsearch = new File(path + "/binaries/hmmsearch.exe"); + { + if (!hmmsearch.canExecute()) + { + message += MessageManager.getString("label.hmmsearch_not_found") + + "\n"; + missing++; + } + } + + if (missing > 0) + { + if (missing < 3) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, message, + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + return false; + } + else + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.no_binaries"), + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + return false; + } + } + } return true; } diff --git a/src/jalview/hmmer/HMMAlignThread.java b/src/jalview/hmmer/HMMAlignThread.java index c424cf0..4f4e46c 100644 --- a/src/jalview/hmmer/HMMAlignThread.java +++ b/src/jalview/hmmer/HMMAlignThread.java @@ -10,6 +10,7 @@ import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.Desktop; +import jalview.gui.JvOptionPane; import jalview.gui.Preferences; import jalview.gui.SplitFrame; import jalview.io.DataSourceType; @@ -123,7 +124,13 @@ public class HMMAlignThread implements Runnable } try { - runCommand(); + boolean ran = runCommand(); + if (!ran) + { + JvOptionPane.showInternalMessageDialog(af, + MessageManager.getString("warn.hmmalign_failed")); + return; + } } catch (IOException | InterruptedException e) { e.printStackTrace(); @@ -156,8 +163,13 @@ public class HMMAlignThread implements Runnable inputTemp.deleteOnExit(); } - private void runCommand() throws IOException, InterruptedException + private boolean runCommand() throws IOException, InterruptedException { + File file = new File(cmds.HMMERFOLDER + "/binaries/hmmalign.exe"); + if (!file.canExecute()) + { + return false; + } String command = cmds.HMMERFOLDER + cmds.HMMALIGN; if (!hmm.getFileHeader().contains("HMMER3/f")) { @@ -176,7 +188,7 @@ public class HMMAlignThread implements Runnable command += " -o" + inputTemp.getAbsolutePath() + cmds.SPACE + hmmTemp.getAbsolutePath() + cmds.SPACE + outTemp.getAbsolutePath(); - cmds.runCommand(command); + return cmds.runCommand(command); } private void importData(int index) diff --git a/src/jalview/hmmer/HMMBuildThread.java b/src/jalview/hmmer/HMMBuildThread.java index e9f691b..d1039f9 100644 --- a/src/jalview/hmmer/HMMBuildThread.java +++ b/src/jalview/hmmer/HMMBuildThread.java @@ -5,6 +5,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.JvOptionPane; import jalview.gui.Preferences; import jalview.io.DataSourceType; import jalview.io.FileFormat; @@ -98,7 +99,13 @@ public class HMMBuildThread implements Runnable } try { - runCommand(); + boolean ran = runCommand(); + if (!ran) + { + JvOptionPane.showInternalMessageDialog(af, + MessageManager.getString("warn.hmmbuild_failed")); + return; + } } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block @@ -126,8 +133,13 @@ public class HMMBuildThread implements Runnable - private void runCommand() throws IOException, InterruptedException + private boolean runCommand() throws IOException, InterruptedException { + File file = new File(cmds.HMMERFOLDER + "/binaries/hmmbuild.exe"); + if (!file.canExecute()) + { + return false; + } String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME + af.getName() + cmds.SPACE; if (!alignment.isNucleotide()) @@ -141,7 +153,7 @@ public class HMMBuildThread implements Runnable command += hmmTemp.getAbsolutePath() + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE; - cmds.runCommand(command); + return cmds.runCommand(command); } private void importData() throws IOException, InterruptedException diff --git a/src/jalview/hmmer/HMMERCommands.java b/src/jalview/hmmer/HMMERCommands.java index bcd0662..136ad5c 100644 --- a/src/jalview/hmmer/HMMERCommands.java +++ b/src/jalview/hmmer/HMMERCommands.java @@ -24,11 +24,11 @@ public class HMMERCommands public String JALVIEWDIRECTORY = System.getProperty("user.dir") + "/"; - public final String HMMALIGN = "/hmmalign "; + public final String HMMALIGN = "/binaries/hmmalign "; - public final String HMMBUILD = "/hmmbuild "; + public final String HMMBUILD = "/binaries/hmmbuild "; - public final String HMMSEARCH = "/hmmsearch "; + public final String HMMSEARCH = "/binaries/hmmsearch "; public String HMMBUFFER; @@ -73,7 +73,7 @@ public class HMMERCommands * @throws IOException * @throws InterruptedException */ - public void runCommand(String command) + public boolean runCommand(String command) throws IOException, InterruptedException { try @@ -106,7 +106,9 @@ public class HMMERCommands } catch (Exception e) { e.printStackTrace(); + return false; } + return true; } /** diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 40f8616..25742b4 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -276,7 +276,7 @@ public class GPreferences extends JPanel protected JLabel installationLocation = new JLabel(); - protected JTextField installationLocationField = new JTextField(); + protected JTextField hmmerPath = new JTextField(); protected JLabel hmmsearch = new JLabel(); @@ -376,6 +376,15 @@ public class GPreferences extends JPanel return; } } + else if (lastTab == hmmerTab + && tabbedPane.getSelectedComponent() != hmmerTab) + { + if (!validateHMMER()) + { + tabbedPane.setSelectedComponent(hmmerTab); + } + return; + } lastTab = tabbedPane.getSelectedComponent(); } @@ -443,8 +452,8 @@ public class GPreferences extends JPanel installationLocation.setText( MessageManager.getString("label.change_hmmer_location")); installationLocation.setBounds(new Rectangle(22, 200, 200, 23)); - installationLocationField.setBounds(new Rectangle(22, 220, 200, 23)); - installationLocationField.addMouseListener(new MouseAdapter() + hmmerPath.setBounds(new Rectangle(22, 220, 200, 23)); + hmmerPath.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) @@ -454,7 +463,7 @@ public class GPreferences extends JPanel String chosen = openFileChooser(); if (chosen != null) { - installationLocationField.setText(chosen); + hmmerPath.setText(chosen); } } } @@ -477,7 +486,7 @@ public class GPreferences extends JPanel hmmerTab.add(hmmalign); hmmerTab.add(hmmsearch); hmmerTab.add(installationLocation); - hmmerTab.add(installationLocationField); + hmmerTab.add(hmmerPath); hmmerTab.add(trimTermini); hmmerTab.add(sequencesToKeep); hmmerTab.add(sequencesToKeep); @@ -1247,11 +1256,31 @@ public class GPreferences extends JPanel return true; } + /** + * Validate the hmmer tab preferences; if invalid, set focus on this tab. + * + * @param e + */ + protected boolean validateHMMER(FocusEvent e) + { + if (!validateHMMER()) + { + e.getComponent().requestFocusInWindow(); + return false; + } + return true; + } + protected boolean validateStructure() { return false; } + protected boolean validateHMMER() + { + return false; + } + /** * Initialises the Visual tabbed panel. * @@ -1741,4 +1770,9 @@ public class GPreferences extends JPanel } } + + public void hmmerPath_actionPerformed(ActionEvent e) + { + + } }