X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPreferences.java;h=c8fef96f847e03f8ece4b6f51141f5ec211f3b20;hb=46406ae21c62b964714ce136c9d692985c17211d;hp=b5fa4e8f258396414b6148f3325b3d0238975ffe;hpb=bb7c8e1f39eca07ec0bc544df298ee58f109b011;p=jalview.git diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index b5fa4e8..c8fef96 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -22,8 +22,14 @@ package jalview.gui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenMarkovModel; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; +import jalview.hmmer.HMMBuildThread; import jalview.io.FileFormatI; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; @@ -52,6 +58,7 @@ import java.awt.event.MouseEvent; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Scanner; import javax.help.HelpSetException; import javax.swing.JColorChooser; @@ -201,6 +208,34 @@ public class Preferences extends GPreferences frame.setMinimumSize(new Dimension(width, height)); /* + * Set HMMER tab defaults + */ + trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false)); + isHMMERInstalled + .setSelected(Cache.getDefault("HMMER_INSTALLED", false)); + if (Cache.getDefault("USE_UNIPROT", false)) + { + uniprot.setSelected(true); + } + else + { + alignment.setSelected(true); + } + numberOfSequencesToKeepField + .setText(Cache.getProperty("SEQUENCES_TO_KEEP")); + installationLocation.setEnabled(isHMMERInstalled.isSelected()); + hmmerPath.setEnabled(isHMMERInstalled.isSelected()); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); + hmmerPath.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + validateHMMERPath(); + } + }); + + /* * Set Visual tab defaults */ seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true)); @@ -640,6 +675,44 @@ public class Preferences extends GPreferences maxColour.getBackground()); /* + * Save HMMER settings + */ + Cache.applicationProperties.setProperty("TRIM_TERMINI", + Boolean.toString(trimTermini.isSelected())); + Cache.applicationProperties.setProperty("USE_UNIPROT", + Boolean.toString(uniprot.isSelected())); + Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP", + numberOfSequencesToKeepField.getText()); + Cache.applicationProperties.setProperty(HMMER_PATH, + hmmerPath.getText()); + boolean hmmerInstalled = isHMMERInstalled.isSelected(); + Cache.applicationProperties.setProperty("HMMER_INSTALLED", + Boolean.toString(hmmerInstalled)); + boolean hmmerFunctioning = validateHMMERPath(false); + Cache.applicationProperties.setProperty("HMMER_FUNCTIONING", + Boolean.toString(hmmerFunctioning)); + AlignFrame[] frames = Desktop.getAlignFrames(); + boolean hmmerStatus = hmmerFunctioning && hmmerInstalled ? true : false; + for (AlignFrame frame : frames) + { + frame.updateHMMERStatus(hmmerStatus); + } + + + trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false)); + if (Cache.getDefault("USE_UNIPROT", false)) + { + uniprot.setSelected(true); + } + else + { + alignment.setSelected(true); + } + numberOfSequencesToKeepField + .setText(Cache.getProperty("SEQUENCES_TO_KEEP")); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); + + /* * Save Structure settings */ Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN, @@ -796,6 +869,14 @@ public class Preferences extends GPreferences structureTab.requestFocusInWindow(); return false; } + if (isHMMERInstalled.isSelected()) + { + if (!validateHMMER()) + { + hmmerTab.requestFocusInWindow(); + return false; + } + } return true; } @@ -806,6 +887,13 @@ public class Preferences extends GPreferences } + @Override + protected boolean validateHMMER() + { + return validateHMMERPath(); + + } + /** * DOCUMENT ME! */ @@ -1098,27 +1186,170 @@ public class Preferences extends GPreferences } /** - * Returns true if hmmer path contains the necessary valid executables, else show an error - * dialog. + * Returns true if hmmer path contains the necessary valid executables, else + * show an error dialog (if showing dialog). */ - private boolean validateHMMERPath() + private boolean validateHMMERPath(boolean showDialog) { - String path = Cache.getProperty("HMMERPATH"); - if (path.length() > 0) + int missing = 0; + String message = ""; + String folder = hmmerPath.getText().trim(); + if (folder.length() > 0) { - File f = new File(path); - if (!f.canExecute()) + File f = new File(folder); + if (!f.exists()) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.invalid_hmmer_folder"), - MessageManager.getString("Invalid folder"), + if (showDialog) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.folder_not_exists"), + MessageManager.getString("label.invalid_folder"), JvOptionPane.ERROR_MESSAGE); + } return false; } + AlignmentI alignment = new Alignment( + new SequenceI[] + { new Sequence("test", "WLWL", 0, 3) }); + if (canExecute(folder + "/hmmbuild")) + { + validateHMMBuild(alignment); + } + else + { + message += MessageManager.getString("label.hmmbuild_not_found") + + "\n"; + missing++; + } + + + if (canExecute(folder + "/hmmalign")) + { + + } + else + { + message += MessageManager.getString("label.hmmalign_not_found") + + "\n"; + missing++; + } + + + if (canExecute(folder + "/hmmsearch")) + { + + } + else + { + message += MessageManager.getString("label.hmmsearch_not_found") + + "\n"; + missing++; + } + } + + if (missing > 0) + { + if (missing < 3) + { + if (showDialog) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, message, + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + } + return false; + } + else + { + if (showDialog) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.no_binaries"), + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + } + + return false; + } + } + + return true; + } + + /** + * Checks if a file can be executed + * + * @param path + * the path to the file + * @return + */ + public boolean canExecute(String path) + { + File file = new File(path); + if (!file.canExecute()) + { + file = new File(path + ".exe"); + { + if (!file.canExecute()) + { + return false; + } + } + } + return true; + } + + /** + * Runs hmmbuild to check if it is working. While doing this it parses the + * version of HMMER. + * + * @param frame + * @return + */ + public boolean validateHMMBuild(AlignmentI alignment) + { + HMMBuildThread hmmbuild = new HMMBuildThread(alignment); + hmmbuild.hmmbuildWaitTillComplete(); + SequenceI hmmSeq = alignment.getSequenceAt(1); + HiddenMarkovModel hmm; + if (hmmSeq.isHMMConsensusSequence() && hmmSeq.getHMM() != null) + { + hmm = hmmSeq.getHMM(); + + if (hmm.getNumberOfSymbols() < 1) + { + return false; + } + } + else + { + return false; + } + + String header = hmm.getFileHeader(); + if (header == null) + { + return false; + } + else + { + Scanner scanner = new Scanner(header); + scanner.next(); + String string = scanner.next(); + String version = string.substring(1); + Cache.setProperty("HMMER_VERSION", version); + scanner.close(); + } return true; } + + private boolean validateHMMERPath() + { + return validateHMMERPath(true); + } + /** * If Chimera is selected, check it can be found on default or user-specified * path, if not show a warning/help dialog.