X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPreferences.java;h=c8fef96f847e03f8ece4b6f51141f5ec211f3b20;hb=46406ae21c62b964714ce136c9d692985c17211d;hp=fbf31ffcb61f72bc42b96179c5f113a18d80a47f;hpb=40f8e76e5d28e2c2fe5fddab72fe797a696bed8a;p=jalview.git diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index fbf31ff..c8fef96 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -22,14 +22,22 @@ 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; import jalview.jbgui.GPreferences; import jalview.jbgui.GSequenceLink; -import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ColourSchemes; +import jalview.schemes.ResidueColourScheme; import jalview.urls.UrlLinkTableModel; import jalview.urls.api.UrlProviderFactoryI; import jalview.urls.api.UrlProviderI; @@ -50,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; @@ -100,11 +109,15 @@ 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"; public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE"; + public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY"; + private static final int MIN_FONT_SIZE = 1; private static final int MAX_FONT_SIZE = 30; @@ -151,7 +164,7 @@ public class Preferences extends GPreferences * .properties file as '|' separated strings */ - groupURLLinks = new ArrayList(); + groupURLLinks = new ArrayList<>(); } JInternalFrame frame; @@ -195,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)); @@ -208,6 +249,7 @@ public class Preferences extends GPreferences openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false)); showUnconserved .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false)); + showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false)); showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false)); showGroupConservation.setSelected(Cache.getDefault( @@ -216,6 +258,9 @@ public class Preferences extends GPreferences "SHOW_CONSENSUS_HISTOGRAM", true)); showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false)); + showInformationHistogram.setSelected( + Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true)); + showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false)); showNpTooltip.setSelected(Cache .getDefault("SHOW_NPFEATS_TOOLTIP", true)); showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", @@ -284,12 +329,16 @@ public class Preferences extends GPreferences /* * Set Colours tab defaults */ - for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++) + protColour.addItem(ResidueColourScheme.NONE); + nucColour.addItem(ResidueColourScheme.NONE); + for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes()) { - protColour.addItem(ColourSchemeProperty.getColourName(i)); - nucColour.addItem(ColourSchemeProperty.getColourName(i)); + String name = cs.getSchemeName(); + protColour.addItem(name); + nucColour.addItem(name); } - String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None"); + String oldProp = Cache.getDefault(DEFAULT_COLOUR, + ResidueColourScheme.NONE); String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null); protColour.setSelectedItem(newProp != null ? newProp : oldProp); newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null); @@ -459,8 +508,6 @@ public class Preferences extends GPreferences useProxy.setSelected(Cache.getDefault("USE_PROXY", false)); useProxy_actionPerformed(); // make sure useProxy is correctly initialised - proxyServerTB.setEnabled(useProxy.isSelected()); - proxyPortTB.setEnabled(useProxy.isSelected()); proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", "")); proxyPortTB.setText(Cache.getDefault("PROXY_PORT", "")); @@ -568,6 +615,8 @@ public class Preferences extends GPreferences Boolean.toString(idItalics.isSelected())); Cache.applicationProperties.setProperty("SHOW_UNCONSERVED", Boolean.toString(showUnconserved.isSelected())); + Cache.applicationProperties.setProperty(SHOW_OCCUPANCY, + Boolean.toString(showOccupancy.isSelected())); Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS", Boolean.toString(showGroupConsensus.isSelected())); Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION", @@ -576,6 +625,10 @@ public class Preferences extends GPreferences Boolean.toString(showConsensHistogram.isSelected())); Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO", Boolean.toString(showConsensLogo.isSelected())); + Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM", + Boolean.toString(showConsensHistogram.isSelected())); + Cache.applicationProperties.setProperty("SHOW_HMM_LOGO", + Boolean.toString(showHMMLogo.isSelected())); Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected())); Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA, @@ -622,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, @@ -778,6 +869,14 @@ public class Preferences extends GPreferences structureTab.requestFocusInWindow(); return false; } + if (isHMMERInstalled.isSelected()) + { + if (!validateHMMER()) + { + hmmerTab.requestFocusInWindow(); + return false; + } + } return true; } @@ -788,6 +887,13 @@ public class Preferences extends GPreferences } + @Override + protected boolean validateHMMER() + { + return validateHMMERPath(); + + } + /** * DOCUMENT ME! */ @@ -809,7 +915,7 @@ public class Preferences extends GPreferences if (format != null) { Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT", - format.toString()); + format.getName()); } startupFileTextfield.setText(chooser.getSelectedFile() .getAbsolutePath()); @@ -847,12 +953,15 @@ public class Preferences extends GPreferences conservation.setEnabled(annotations.isSelected()); quality.setEnabled(annotations.isSelected()); identity.setEnabled(annotations.isSelected()); + showOccupancy.setEnabled(annotations.isSelected()); showGroupConsensus.setEnabled(annotations.isSelected()); showGroupConservation.setEnabled(annotations.isSelected()); showConsensHistogram.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected())); showConsensLogo.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected())); + showInformationHistogram.setEnabled(annotations.isSelected()); + showHMMLogo.setEnabled(annotations.isSelected()); } @Override @@ -1075,6 +1184,171 @@ public class Preferences extends GPreferences } return true; } + + /** + * Returns true if hmmer path contains the necessary valid executables, else + * show an error dialog (if showing dialog). + */ + private boolean validateHMMERPath(boolean showDialog) + { + int missing = 0; + String message = ""; + String folder = hmmerPath.getText().trim(); + if (folder.length() > 0) + { + File f = new File(folder); + if (!f.exists()) + { + 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