X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=a429eceb3b1b850ea6550c5b5842979413722e56;hb=0d519ae0c45b0b9962b4589e84c262a71bb2f346;hp=f258990c3f641532c04e2be8c52f5c0deff2fefd;hpb=c81c5e6d65f3e3ffe711fe98b95a5d9d4a7656c7;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index f258990..a429ece 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -24,6 +24,7 @@ import jalview.analysis.AlignmentSorter; import jalview.analysis.AlignmentUtils; import jalview.analysis.CrossRef; import jalview.analysis.Dna; +import jalview.analysis.GeneticCodeI; import jalview.analysis.ParseProperties; import jalview.analysis.SequenceIdMatcher; import jalview.api.AlignExportSettingI; @@ -68,8 +69,10 @@ import jalview.hmmer.HMMERParamStore; import jalview.hmmer.HMMERPreset; import jalview.hmmer.HMMSearch; import jalview.hmmer.HmmerCommand; +import jalview.hmmer.JackHMMER; import jalview.io.AlignmentProperties; import jalview.io.AnnotationFile; +import jalview.io.BackupFiles; import jalview.io.BioJsHTMLOutput; import jalview.io.DataSourceType; import jalview.io.FileFormat; @@ -94,7 +97,6 @@ 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; @@ -140,12 +142,12 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; -import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashSet; import java.util.List; -import java.util.Scanner; +import java.util.Set; import java.util.Vector; +import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JEditorPane; import javax.swing.JFileChooser; @@ -747,9 +749,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int aSize = alignPanels.size(); - tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null); + tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null); - if (aSize == 1 && ap.av.viewName == null) + if (aSize == 1 && ap.av.getViewName() == null) { this.getContentPane().add(ap, BorderLayout.CENTER); } @@ -762,7 +764,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, expandViews.setEnabled(true); gatherViews.setEnabled(true); - tabbedPane.addTab(ap.av.viewName, ap); + tabbedPane.addTab(ap.av.getViewName(), ap); ap.setVisible(false); } @@ -786,7 +788,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, gatherViews.setEnabled(true); tabbedPane.setVisible(true); AlignmentPanel first = alignPanels.get(0); - tabbedPane.addTab(first.av.viewName, first); + tabbedPane.addTab(first.av.getViewName(), first); this.getContentPane().add(tabbedPane, BorderLayout.CENTER); } @@ -887,7 +889,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param av * AlignViewport */ - void setMenusFromViewport(AlignViewport av) + public void setMenusFromViewport(AlignViewport av) { padGapsMenuitem.setSelected(av.isPadGaps()); colourTextMenuItem.setSelected(av.isShowColourText()); @@ -981,10 +983,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return progressBar.operationInProgress(); } + /** + * Sets the text of the status bar. Note that setting a null or empty value + * will cause the status bar to be hidden, with possibly undesirable flicker + * of the screen layout. + */ @Override public void setStatus(String text) { - statusBar.setText(text); + statusBar.setText(text == null || text.isEmpty() ? " " : text); } /* @@ -1105,6 +1112,36 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, new Thread(new HMMSearch(this, args)).start(); alignPanel.repaint(); } + + @Override + public void jackhmmer_actionPerformed(boolean withDefaults) + { + + /* + * get default parameters, and (if requested) show + * dialog to allow modification + */ + + ParamDatastoreI store = HMMERParamStore.forJackhmmer(viewport); + List args = store.getServiceParameters(); + + if (!withDefaults) + { + WsParamSetI set = new HMMERPreset(); + WsJobParameters params = new WsJobParameters(store, set, args); + if (params.showRunDialog()) + { + args = params.getJobParams(); + } + else + { + return; // user cancelled + } + } + new Thread(new JackHMMER(this, args)).start(); + alignPanel.repaint(); + + } /** * Checks if the alignment has at least one hidden Markov model, if not shows @@ -1122,6 +1159,36 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } return true; } + + @Override + protected void filterByEValue_actionPerformed() + { + viewport.filterByEvalue(inputDouble("Enter E-Value Cutoff")); + } + + @Override + protected void filterByScore_actionPerformed() + { + viewport.filterByScore(inputDouble("Enter Bit Score Threshold")); + } + + private double inputDouble(String message) + { + String str = null; + Double d = null; + while(d == null || d <= 0) + { + str = JOptionPane.showInputDialog(this.alignPanel, message); + try + { + d = Double.valueOf(str); + } + catch (NumberFormatException e) + { + } + } + return d; + } /** * Checks if the alignment contains the required number of sequences. @@ -1131,45 +1198,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ public boolean alignmentIsSufficient(int required) { - if (getViewport().getAlignment().getSequences().size() < required) - { - JOptionPane.showMessageDialog(this, - MessageManager.getString("label.not_enough_sequences")); - return false; - } - return true; + if (getViewport().getSequenceSelection().length < required) + { + JOptionPane.showMessageDialog(this, + MessageManager.getString("label.not_enough_sequences")); + return false; + } + return true; } + /** + * Opens a file browser and adds the selected file, if in Fasta, Stockholm or + * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a + * comma-separated list) + */ @Override public void addDatabase_actionPerformed() throws IOException { - if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null) + if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null) { Cache.setProperty(Preferences.HMMSEARCH_DBS, ""); - Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, ""); } String path = openFileChooser(false); - if (new File(path).exists()) + if (path != null && 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, File.separator); - 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); + .getProperty(Preferences.HMMSEARCH_DBS); + currentDbPaths += Preferences.COMMA + path; Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths); } else @@ -1178,21 +1239,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, MessageManager.getString("warn.invalid_format")); } } - else - { - JOptionPane.showMessageDialog(this, - MessageManager.getString("label.not_enough_sequences")); - } } /** - * Opens a file chooser + * Opens a file chooser, optionally restricted to selecting folders + * (directories) only. Answers the path to the selected file or folder, or + * null if none is chosen. * - * @param forFolder + * @param * @return */ protected String openFileChooser(boolean forFolder) { + // TODO duplicates GPreferences method - relocate to JalviewFileChooser? String choice = null; JFileChooser chooser = new JFileChooser(); if (forFolder) @@ -1372,7 +1431,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, shortName.lastIndexOf(java.io.File.separatorChar) + 1); } - success = new Jalview2XML().saveAlignment(this, file, shortName); + success = new jalview.project.Jalview2XML().saveAlignment(this, file, + shortName); statusBar.setText(MessageManager.formatMessage( "label.successfully_saved_to_file_in_format", new Object[] @@ -1404,9 +1464,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { + // create backupfiles object and get new temp filename destination + BackupFiles backupfiles = new BackupFiles(file); + try { - PrintWriter out = new PrintWriter(new FileWriter(file)); + PrintWriter out = new PrintWriter( + new FileWriter(backupfiles.getTempFilePath())); out.print(output); out.close(); @@ -1419,6 +1483,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, success = false; ex.printStackTrace(); } + + backupfiles.setWriteSuccess(success); + // do the backup file roll and rename the temp file to actual file + success = backupfiles.rollBackupsAndRenameTempFile(); + } } @@ -2301,7 +2370,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newGraphGroups.add(q, null); } newGraphGroups.set(newann.graphGroup, - new Integer(++fgroup)); + Integer.valueOf(++fgroup)); } newann.graphGroup = newGraphGroups.get(newann.graphGroup) .intValue(); @@ -2348,7 +2417,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newGraphGroups.add(q, null); } newGraphGroups.set(newann.graphGroup, - new Integer(++fgroup)); + Integer.valueOf(++fgroup)); } newann.graphGroup = newGraphGroups.get(newann.graphGroup) .intValue(); @@ -2623,15 +2692,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) { - SequenceGroup sg = new SequenceGroup(); - - for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++) - { - sg.addSequence(viewport.getAlignment().getSequenceAt(i), false); - } + SequenceGroup sg = new SequenceGroup( + viewport.getAlignment().getSequences()); sg.setEndRes(viewport.getAlignment().getWidth() - 1); viewport.setSelectionGroup(sg); + viewport.isSelectionGroupChanged(true); viewport.sendSelection(); // JAL-2034 - should delegate to // alignPanel to decide if overview needs @@ -2927,7 +2993,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /* * Create a new AlignmentPanel (with its own, new Viewport) */ - AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel); + AlignmentPanel newap = new jalview.project.Jalview2XML() + .copyAlignPanel(alignPanel); if (!copyAnnotation) { /* @@ -2939,10 +3006,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newap.av.setGatherViewsHere(false); - if (viewport.viewName == null) + if (viewport.getViewName() == null) { - viewport.viewName = MessageManager - .getString("label.view_name_original"); + viewport.setViewName(MessageManager + .getString("label.view_name_original")); } /* @@ -2952,6 +3019,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newap.av.setRedoList(viewport.getRedoList()); /* + * copy any visualisation settings that are not saved in the project + */ + newap.av.setColourAppliesToAllGroups( + viewport.getColourAppliesToAllGroups()); + + /* * Views share the same mappings; need to deregister any new mappings * created by copyAlignPanel, and register the new reference to the shared * mappings @@ -2966,7 +3039,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newap.refresh(true); // adjust layout of annotations } - newap.av.viewName = getNewViewName(viewTitle); + newap.av.setViewName(getNewViewName(viewTitle)); addAlignmentPanel(newap, true); newap.alignmentChanged(); @@ -3029,9 +3102,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (comp instanceof AlignmentPanel) { AlignmentPanel ap = (AlignmentPanel) comp; - if (!existingNames.contains(ap.av.viewName)) + if (!existingNames.contains(ap.av.getViewName())) { - existingNames.add(ap.av.viewName); + existingNames.add(ap.av.getViewName()); } } } @@ -3114,7 +3187,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.setFollowHighlight(state); if (state) { - alignPanel.scrollToPosition(viewport.getSearchResults(), false); + alignPanel.scrollToPosition(viewport.getSearchResults()); } } @@ -3261,6 +3334,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.expandColSelection(sg, false); viewport.hideAllSelectedSeqs(); viewport.hideSelectedColumns(); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3285,6 +3359,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void hideSelColumns_actionPerformed(ActionEvent e) { viewport.hideSelectedColumns(); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3306,7 +3381,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleAbove_actionPerformed(ActionEvent e) { viewport.setScaleAboveWrapped(scaleAbove.isSelected()); - // TODO: do we actually need to update overview for scale above change ? + alignPanel.updateLayout(); alignPanel.paintAlignment(true, false); } @@ -3320,6 +3395,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleLeft_actionPerformed(ActionEvent e) { viewport.setScaleLeftWrapped(scaleLeft.isSelected()); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, false); } @@ -3333,6 +3409,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleRight_actionPerformed(ActionEvent e) { viewport.setScaleRightWrapped(scaleRight.isSelected()); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, false); } @@ -3486,6 +3563,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.setOverviewPanel(null); }; }); + if (getKeyListeners().length > 0) + { + frame.addKeyListener(getKeyListeners()[0]); + } alignPanel.setOverviewPanel(overview); } @@ -3550,6 +3631,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * otherwise set the chosen colour scheme (or null for 'None') */ ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name, + viewport, viewport.getAlignment(), viewport.getHiddenRepSequences()); changeColour(cs); } @@ -3819,9 +3901,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, frameTitle += " from "; - if (viewport.viewName != null) + if (viewport.getViewName() != null) { - frameTitle += viewport.viewName + " of "; + frameTitle += viewport.getViewName() + " of "; } frameTitle += this.title; @@ -3913,35 +3995,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.getAlignment().getAlignmentAnnotation() - .hashCode() != _annotationScoreVectorHash) + .hashCode() == _annotationScoreVectorHash) + { + return; + } + + sortByAnnotScore.removeAll(); + Set scoreSorts = new HashSet<>(); + for (SequenceI sqa : viewport.getAlignment().getSequences()) { - sortByAnnotScore.removeAll(); - // almost certainly a quicker way to do this - but we keep it simple - Hashtable scoreSorts = new Hashtable(); - AlignmentAnnotation aann[]; - for (SequenceI sqa : viewport.getAlignment().getSequences()) + AlignmentAnnotation[] anns = sqa.getAnnotation(); + for (int i = 0; anns != null && i < anns.length; i++) { - aann = sqa.getAnnotation(); - for (int i = 0; aann != null && i < aann.length; i++) + AlignmentAnnotation aa = anns[i]; + if (aa != null && aa.hasScore() && aa.sequenceRef != null) { - if (aann[i].hasScore() && aann[i].sequenceRef != null) - { - scoreSorts.put(aann[i].label, aann[i].label); - } + scoreSorts.add(aa.label); } } - Enumeration labels = scoreSorts.keys(); - while (labels.hasMoreElements()) - { - addSortByAnnotScoreMenuItem(sortByAnnotScore, - (String) labels.nextElement()); - } - sortByAnnotScore.setVisible(scoreSorts.size() > 0); - scoreSorts.clear(); - - _annotationScoreVectorHash = viewport.getAlignment() - .getAlignmentAnnotation().hashCode(); } + for (String label : scoreSorts) + { + addSortByAnnotScoreMenuItem(sortByAnnotScore, label); + } + sortByAnnotScore.setVisible(!scoreSorts.isEmpty()); + + _annotationScoreVectorHash = viewport.getAlignment() + .getAlignmentAnnotation().hashCode(); } /** @@ -4482,14 +4562,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * frame's DNA sequences to their aligned protein (amino acid) equivalents. */ @Override - public void showTranslation_actionPerformed(ActionEvent e) + public void showTranslation_actionPerformed(GeneticCodeI codeTable) { AlignmentI al = null; try { Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true)); - al = dna.translateCdna(); + al = dna.translateCdna(codeTable); } catch (Exception ex) { jalview.bin.Cache.log.error( @@ -4518,7 +4598,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, af.setFileFormat(this.currentFileFormat); final String newTitle = MessageManager .formatMessage("label.translation_of_params", new Object[] - { this.getTitle() }); + { this.getTitle(), codeTable.getId() }); af.setTitle(newTitle); if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) { @@ -4686,17 +4766,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int assocfiles = 0; if (filesmatched.size() > 0) { - if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false) - || JvOptionPane.showConfirmDialog(thisaf, - MessageManager.formatMessage( - "label.automatically_associate_structure_files_with_sequences_same_name", - new Object[] - { Integer.valueOf(filesmatched.size()) - .toString() }), - MessageManager.getString( - "label.automatically_associate_structure_files_by_name"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) - + boolean autoAssociate = Cache + .getDefault("AUTOASSOCIATE_PDBANDSEQS", false); + if (!autoAssociate) + { + String msg = MessageManager.formatMessage( + "label.automatically_associate_structure_files_with_sequences_same_name", + new Object[] + { Integer.valueOf(filesmatched.size()) + .toString() }); + String ttl = MessageManager.getString( + "label.automatically_associate_structure_files_by_name"); + int choice = JvOptionPane.showConfirmDialog(thisaf, msg, + ttl, JvOptionPane.YES_NO_OPTION); + autoAssociate = choice == JvOptionPane.YES_OPTION; + } + if (autoAssociate) { for (Object[] fm : filesmatched) { @@ -4722,6 +4807,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.paintAlignment(true, false); } } + else + { + /* + * add declined structures as sequences + */ + for (Object[] o : filesmatched) + { + filesnotmatched.add((String) o[0]); + } + } } if (filesnotmatched.size() > 0) { @@ -4976,7 +5071,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (reply != null) { - viewport.viewName = reply; + viewport.setViewName(reply); // TODO warn if reply is in getExistingViewNames()? tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply); } @@ -5493,7 +5588,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true, true); + alignPanel.paintAlignment(true, + viewport.needToUpdateStructureViews()); } } @@ -5514,6 +5610,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (avc.createGroup()) { + if (applyAutoAnnotationSettings.isSelected()) + { + alignPanel.updateAnnotation(true, false); + } alignPanel.alignmentChanged(); } } @@ -5604,7 +5704,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ public List getAlignPanels() { - return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels; + // alignPanels is never null + // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels; + return alignPanels; } /** @@ -5773,15 +5875,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, colourMenu.add(textColour); colourMenu.addSeparator(); - ColourMenuHelper.addMenuItems(colourMenu, this, viewport.getAlignment(), - false); + ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, + viewport.getAlignment(), false); + colourMenu.add(annotationColour); + bg.add(annotationColour); colourMenu.addSeparator(); colourMenu.add(conservationMenuItem); colourMenu.add(modifyConservation); colourMenu.add(abovePIDThreshold); colourMenu.add(modifyPID); - colourMenu.add(annotationColour); ColourSchemeI colourScheme = viewport.getGlobalColourScheme(); ColourMenuHelper.setColourSelected(colourMenu, colourScheme); @@ -5808,22 +5911,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } @Override - public void hmmerMenu_actionPerformed(ActionEvent e) - { - SequenceGroup grp = getViewport().getSelectionGroup(); - if (grp != null) - { - hmmBuild.setText(MessageManager.getString("label.hmmbuild") + " from " - + grp.getName()); - } - else - { - hmmBuild.setText(MessageManager.getString("label.hmmbuild") - + " from Alignment"); - } - } - - @Override protected void loadVcf_actionPerformed() { JalviewFileChooser chooser = new JalviewFileChooser(