2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingsI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.SplitContainerI;
36 import jalview.api.ViewStyleI;
37 import jalview.api.analysis.SimilarityParamsI;
38 import jalview.bin.Cache;
39 import jalview.bin.Jalview;
40 import jalview.commands.CommandI;
41 import jalview.commands.EditCommand;
42 import jalview.commands.EditCommand.Action;
43 import jalview.commands.OrderCommand;
44 import jalview.commands.RemoveGapColCommand;
45 import jalview.commands.RemoveGapsCommand;
46 import jalview.commands.SlideSequencesCommand;
47 import jalview.commands.TrimRegionCommand;
48 import jalview.datamodel.AlignExportSettingsAdapter;
49 import jalview.datamodel.AlignedCodonFrame;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentExportData;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.AlignmentOrder;
55 import jalview.datamodel.AlignmentView;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.HiddenColumns;
58 import jalview.datamodel.PDBEntry;
59 import jalview.datamodel.SeqCigar;
60 import jalview.datamodel.Sequence;
61 import jalview.datamodel.SequenceGroup;
62 import jalview.datamodel.SequenceI;
63 import jalview.gui.ColourMenuHelper.ColourChangeListener;
64 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
65 import jalview.io.AlignmentProperties;
66 import jalview.io.AnnotationFile;
67 import jalview.io.BioJsHTMLOutput;
68 import jalview.io.DataSourceType;
69 import jalview.io.FileFormat;
70 import jalview.io.FileFormatI;
71 import jalview.io.FileFormats;
72 import jalview.io.FileLoader;
73 import jalview.io.FileParse;
74 import jalview.io.FormatAdapter;
75 import jalview.io.HtmlSvgOutput;
76 import jalview.io.IdentifyFile;
77 import jalview.io.JPredFile;
78 import jalview.io.JalviewFileChooser;
79 import jalview.io.JalviewFileView;
80 import jalview.io.JnetAnnotationMaker;
81 import jalview.io.NewickFile;
82 import jalview.io.ScoreMatrixFile;
83 import jalview.io.TCoffeeScoreFile;
84 import jalview.io.vcf.VCFLoader;
85 import jalview.jbgui.GAlignFrame;
86 import jalview.schemes.ColourSchemeI;
87 import jalview.schemes.ColourSchemes;
88 import jalview.schemes.ResidueColourScheme;
89 import jalview.schemes.TCoffeeColourScheme;
90 import jalview.util.ImageMaker.TYPE;
91 import jalview.util.MessageManager;
92 import jalview.util.dialogrunner.RunResponse;
93 import jalview.viewmodel.AlignmentViewport;
94 import jalview.viewmodel.ViewportRanges;
95 import jalview.ws.DBRefFetcher;
96 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
97 import jalview.ws.jws1.Discoverer;
98 import jalview.ws.jws2.Jws2Discoverer;
99 import jalview.ws.jws2.jabaws2.Jws2Instance;
100 import jalview.ws.seqfetcher.DbSourceProxy;
102 import java.awt.BorderLayout;
103 import java.awt.Color;
104 import java.awt.Component;
105 import java.awt.Rectangle;
106 import java.awt.Toolkit;
107 import java.awt.datatransfer.Clipboard;
108 import java.awt.datatransfer.DataFlavor;
109 import java.awt.datatransfer.StringSelection;
110 import java.awt.datatransfer.Transferable;
111 import java.awt.dnd.DnDConstants;
112 import java.awt.dnd.DropTargetDragEvent;
113 import java.awt.dnd.DropTargetDropEvent;
114 import java.awt.dnd.DropTargetEvent;
115 import java.awt.dnd.DropTargetListener;
116 import java.awt.event.ActionEvent;
117 import java.awt.event.ActionListener;
118 import java.awt.event.FocusAdapter;
119 import java.awt.event.FocusEvent;
120 import java.awt.event.ItemEvent;
121 import java.awt.event.ItemListener;
122 import java.awt.event.KeyAdapter;
123 import java.awt.event.KeyEvent;
124 import java.awt.event.MouseEvent;
125 import java.awt.print.PageFormat;
126 import java.awt.print.PrinterJob;
127 import java.beans.PropertyChangeEvent;
128 import java.beans.PropertyChangeListener;
130 import java.io.FileWriter;
131 import java.io.PrintWriter;
133 import java.util.ArrayList;
134 import java.util.Arrays;
135 import java.util.Deque;
136 import java.util.Enumeration;
137 import java.util.Hashtable;
138 import java.util.List;
139 import java.util.Vector;
141 import javax.swing.JCheckBoxMenuItem;
142 import javax.swing.JComponent;
143 import javax.swing.JEditorPane;
144 import javax.swing.JInternalFrame;
145 import javax.swing.JLabel;
146 import javax.swing.JLayeredPane;
147 import javax.swing.JMenu;
148 import javax.swing.JMenuItem;
149 import javax.swing.JPanel;
150 import javax.swing.JScrollPane;
151 import javax.swing.SwingUtilities;
157 * @version $Revision$
159 public class AlignFrame extends GAlignFrame implements DropTargetListener,
160 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener,
161 PropertyChangeListener
164 public static final int DEFAULT_WIDTH = 700;
166 public static final int DEFAULT_HEIGHT = 500;
169 * The currently displayed panel (selected tabbed view if more than one)
171 public AlignmentPanel alignPanel;
173 AlignViewport viewport;
175 public AlignViewControllerI avc;
177 List<AlignmentPanel> alignPanels = new ArrayList<>();
180 * Last format used to load or save alignments in this window
182 FileFormatI currentFileFormat = null;
185 * Current filename for this alignment
187 String fileName = null;
192 * Creates a new AlignFrame object with specific width and height.
198 public AlignFrame(AlignmentI al, int width, int height)
200 this(al, null, width, height);
204 * Creates a new AlignFrame object with specific width, height and
210 * @param sequenceSetId
212 public AlignFrame(AlignmentI al, int width, int height,
213 String sequenceSetId)
215 this(al, null, width, height, sequenceSetId);
219 * Creates a new AlignFrame object with specific width, height and
225 * @param sequenceSetId
228 public AlignFrame(AlignmentI al, int width, int height,
229 String sequenceSetId, String viewId)
231 this(al, null, width, height, sequenceSetId, viewId);
235 * new alignment window with hidden columns
239 * @param hiddenColumns
240 * ColumnSelection or null
242 * Width of alignment frame
246 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
249 this(al, hiddenColumns, width, height, null);
253 * Create alignment frame for al with hiddenColumns, a specific width and
254 * height, and specific sequenceId
257 * @param hiddenColumns
260 * @param sequenceSetId
263 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
264 int height, String sequenceSetId)
266 this(al, hiddenColumns, width, height, sequenceSetId, null);
270 * Create alignment frame for al with hiddenColumns, a specific width and
271 * height, and specific sequenceId
274 * @param hiddenColumns
277 * @param sequenceSetId
282 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
283 int height, String sequenceSetId, String viewId)
285 setSize(width, height);
287 if (al.getDataset() == null)
292 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
294 alignPanel = new AlignmentPanel(this, viewport);
296 addAlignmentPanel(alignPanel, true);
300 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
301 HiddenColumns hiddenColumns, int width, int height)
303 setSize(width, height);
305 if (al.getDataset() == null)
310 viewport = new AlignViewport(al, hiddenColumns);
312 if (hiddenSeqs != null && hiddenSeqs.length > 0)
314 viewport.hideSequence(hiddenSeqs);
316 alignPanel = new AlignmentPanel(this, viewport);
317 addAlignmentPanel(alignPanel, true);
322 * Make a new AlignFrame from existing alignmentPanels
329 public AlignFrame(AlignmentPanel ap)
333 addAlignmentPanel(ap, false);
338 public void propertyChange(PropertyChangeEvent evt)
340 Desktop.getDesktop().propertyChange(evt);
346 * @return true if we have any features
349 protected boolean haveAlignmentFeatures()
351 AlignmentI alignment = getViewport().getAlignment();
353 for (int i = 0; i < alignment.getHeight(); i++)
355 SequenceI seq = alignment.getSequenceAt(i);
356 for (String group : seq.getFeatures().getFeatureGroups(true))
366 * initalise the alignframe from the underlying viewport data and the
371 if (!Jalview.isHeadlessMode())
373 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
376 avc = new jalview.controller.AlignViewController(this, viewport,
378 if (viewport.getAlignmentConservationAnnotation() == null)
380 // BLOSUM62Colour.setEnabled(false);
381 conservationMenuItem.setEnabled(false);
382 modifyConservation.setEnabled(false);
383 // PIDColour.setEnabled(false);
384 // abovePIDThreshold.setEnabled(false);
385 // modifyPID.setEnabled(false);
388 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
391 if (sortby.equals("Id"))
393 sortIDMenuItem_actionPerformed(null);
395 else if (sortby.equals("Pairwise Identity"))
397 sortPairwiseMenuItem_actionPerformed(null);
401 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
403 setMenusFromViewport(viewport);
404 buildSortByAnnotationScoresMenu();
405 calculateTree.addActionListener(new ActionListener()
409 public void actionPerformed(ActionEvent e)
416 if (Desktop.desktop != null)
418 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
420 * BH 2018 ignore service listeners
426 addServiceListeners();
431 if (viewport.getWrapAlignment())
433 wrapMenuItem_actionPerformed(null);
436 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
438 this.overviewMenuItem_actionPerformed(null);
443 final List<AlignmentPanel> selviews = new ArrayList<>();
444 final List<AlignmentPanel> origview = new ArrayList<>();
445 final String menuLabel = MessageManager
446 .getString("label.copy_format_from");
447 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
448 new ViewSetProvider()
452 public AlignmentPanel[] getAllAlignmentPanels()
455 origview.add(alignPanel);
456 // make an array of all alignment panels except for this one
457 List<AlignmentPanel> aps = new ArrayList<>(
458 Arrays.asList(Desktop.getAlignmentPanels(null)));
459 aps.remove(AlignFrame.this.alignPanel);
460 return aps.toArray(new AlignmentPanel[aps.size()]);
462 }, selviews, new ItemListener()
466 public void itemStateChanged(ItemEvent e)
468 if (origview.size() > 0)
470 final AlignmentPanel ap = origview.get(0);
473 * Copy the ViewStyle of the selected panel to 'this one'.
474 * Don't change value of 'scaleProteinAsCdna' unless copying
477 ViewStyleI vs = selviews.get(0).getAlignViewport()
479 boolean fromSplitFrame = selviews.get(0)
480 .getAlignViewport().getCodingComplement() != null;
483 vs.setScaleProteinAsCdna(ap.getAlignViewport()
484 .getViewStyle().isScaleProteinAsCdna());
486 ap.getAlignViewport().setViewStyle(vs);
489 * Also rescale ViewStyle of SplitFrame complement if there is
490 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
491 * the whole ViewStyle (allow cDNA protein to have different
494 AlignViewportI complement = ap.getAlignViewport()
495 .getCodingComplement();
496 if (complement != null && vs.isScaleProteinAsCdna())
498 AlignFrame af = Desktop.getAlignFrameFor(complement);
499 ((SplitFrame) af.getSplitViewContainer())
501 af.setMenusForViewport();
505 ap.setSelected(true);
506 ap.alignFrame.setMenusForViewport();
511 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
512 .indexOf("devel") > -1
513 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
514 .indexOf("test") > -1)
516 formatMenu.add(vsel);
518 addFocusListener(new FocusAdapter()
521 public void focusGained(FocusEvent e)
523 Jalview.setCurrentAlignFrame(AlignFrame.this);
530 * Change the filename and format for the alignment, and enable the 'reload'
531 * button functionality.
538 public void setFileName(String file, FileFormatI format)
541 setFileFormat(format);
542 reload.setEnabled(true);
546 * JavaScript will have this, maybe others. More dependable than a file name
547 * and maintains a reference to the actual bytes loaded.
551 public void setFileObject(File file)
553 this.fileObject = file;
557 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
560 void addKeyListener()
562 addKeyListener(new KeyAdapter()
565 public void keyPressed(KeyEvent evt)
567 if (viewport.cursorMode
568 && ((evt.getKeyCode() >= KeyEvent.VK_0
569 && evt.getKeyCode() <= KeyEvent.VK_9)
570 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
571 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
572 && Character.isDigit(evt.getKeyChar()))
574 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
577 switch (evt.getKeyCode())
580 case 27: // escape key
581 deselectAllSequenceMenuItem_actionPerformed(null);
585 case KeyEvent.VK_DOWN:
586 if (evt.isAltDown() || !viewport.cursorMode)
588 moveSelectedSequences(false);
590 if (viewport.cursorMode)
592 alignPanel.getSeqPanel().moveCursor(0, 1);
597 if (evt.isAltDown() || !viewport.cursorMode)
599 moveSelectedSequences(true);
601 if (viewport.cursorMode)
603 alignPanel.getSeqPanel().moveCursor(0, -1);
608 case KeyEvent.VK_LEFT:
609 if (evt.isAltDown() || !viewport.cursorMode)
611 slideSequences(false,
612 alignPanel.getSeqPanel().getKeyboardNo1());
616 alignPanel.getSeqPanel().moveCursor(-1, 0);
621 case KeyEvent.VK_RIGHT:
622 if (evt.isAltDown() || !viewport.cursorMode)
624 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
628 alignPanel.getSeqPanel().moveCursor(1, 0);
632 case KeyEvent.VK_SPACE:
633 if (viewport.cursorMode)
635 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
636 || evt.isShiftDown() || evt.isAltDown());
640 // case KeyEvent.VK_A:
641 // if (viewport.cursorMode)
643 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
644 // //System.out.println("A");
648 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
649 * System.out.println("closing bracket"); } break;
651 case KeyEvent.VK_DELETE:
652 case KeyEvent.VK_BACK_SPACE:
653 if (!viewport.cursorMode)
655 cut_actionPerformed(null);
659 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
660 || evt.isShiftDown() || evt.isAltDown());
666 if (viewport.cursorMode)
668 alignPanel.getSeqPanel().setCursorRow();
672 if (viewport.cursorMode && !evt.isControlDown())
674 alignPanel.getSeqPanel().setCursorColumn();
678 if (viewport.cursorMode)
680 alignPanel.getSeqPanel().setCursorPosition();
684 case KeyEvent.VK_ENTER:
685 case KeyEvent.VK_COMMA:
686 if (viewport.cursorMode)
688 alignPanel.getSeqPanel().setCursorRowAndColumn();
693 if (viewport.cursorMode)
695 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
699 if (viewport.cursorMode)
701 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
706 viewport.cursorMode = !viewport.cursorMode;
707 statusBar.setText(MessageManager
708 .formatMessage("label.keyboard_editing_mode", new String[]
709 { (viewport.cursorMode ? "on" : "off") }));
710 if (viewport.cursorMode)
712 ViewportRanges ranges = viewport.getRanges();
713 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
715 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
718 alignPanel.getSeqPanel().seqCanvas.repaint();
724 Help.showHelpWindow();
725 } catch (Exception ex)
727 ex.printStackTrace();
732 boolean toggleSeqs = !evt.isControlDown();
733 boolean toggleCols = !evt.isShiftDown();
734 toggleHiddenRegions(toggleSeqs, toggleCols);
739 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
740 boolean modifyExisting = true; // always modify, don't clear
741 // evt.isShiftDown();
742 boolean invertHighlighted = evt.isAltDown();
743 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
747 case KeyEvent.VK_PAGE_UP:
748 viewport.getRanges().pageUp();
750 case KeyEvent.VK_PAGE_DOWN:
751 viewport.getRanges().pageDown();
757 public void keyReleased(KeyEvent evt)
759 switch (evt.getKeyCode())
761 case KeyEvent.VK_LEFT:
762 if (evt.isAltDown() || !viewport.cursorMode)
764 viewport.firePropertyChange("alignment", null,
765 viewport.getAlignment().getSequences());
769 case KeyEvent.VK_RIGHT:
770 if (evt.isAltDown() || !viewport.cursorMode)
772 viewport.firePropertyChange("alignment", null,
773 viewport.getAlignment().getSequences());
781 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
783 ap.alignFrame = this;
784 avc = new jalview.controller.AlignViewController(this, viewport,
789 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
791 int aSize = alignPanels.size();
793 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
795 if (aSize == 1 && ap.av.viewName == null)
797 this.getContentPane().add(ap, BorderLayout.CENTER);
803 setInitialTabVisible();
806 expandViews.setEnabled(true);
807 gatherViews.setEnabled(true);
808 tabbedPane.addTab(ap.av.viewName, ap);
810 ap.setVisible(false);
815 if (ap.av.isPadGaps())
817 ap.av.getAlignment().padGaps();
819 ap.av.updateConservation(ap);
820 ap.av.updateConsensus(ap);
821 ap.av.updateStrucConsensus(ap);
825 public void setInitialTabVisible()
827 expandViews.setEnabled(true);
828 gatherViews.setEnabled(true);
829 tabbedPane.setVisible(true);
830 AlignmentPanel first = alignPanels.get(0);
831 tabbedPane.addTab(first.av.viewName, first);
832 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
835 public AlignViewport getViewport()
840 /* Set up intrinsic listeners for dynamically generated GUI bits. */
841 private void addServiceListeners()
843 final java.beans.PropertyChangeListener thisListener;
844 Desktop.instance.addJalviewPropertyChangeListener("services",
845 thisListener = new java.beans.PropertyChangeListener()
848 public void propertyChange(PropertyChangeEvent evt)
850 // // System.out.println("Discoverer property change.");
851 // if (evt.getPropertyName().equals("services"))
853 SwingUtilities.invokeLater(new Runnable()
860 "Rebuild WS Menu for service change");
861 BuildWebServiceMenu();
868 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
871 public void internalFrameClosed(
872 javax.swing.event.InternalFrameEvent evt)
874 // System.out.println("deregistering discoverer listener");
875 Desktop.instance.removeJalviewPropertyChangeListener("services",
877 closeMenuItem_actionPerformed(true);
880 // Finally, build the menu once to get current service state
881 new Thread(new Runnable()
886 BuildWebServiceMenu();
892 * Configure menu items that vary according to whether the alignment is
893 * nucleotide or protein
895 public void setGUINucleotide()
897 AlignmentI al = getViewport().getAlignment();
898 boolean nucleotide = al.isNucleotide();
900 loadVcf.setVisible(nucleotide);
901 showTranslation.setVisible(nucleotide);
902 showReverse.setVisible(nucleotide);
903 showReverseComplement.setVisible(nucleotide);
904 conservationMenuItem.setEnabled(!nucleotide);
906 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
907 showGroupConservation.setEnabled(!nucleotide);
909 showComplementMenuItem
910 .setText(nucleotide ? MessageManager.getString("label.protein")
911 : MessageManager.getString("label.nucleotide"));
915 * set up menus for the current viewport. This may be called after any
916 * operation that affects the data in the current view (selection changed,
917 * etc) to update the menus to reflect the new state.
920 public void setMenusForViewport()
922 setMenusFromViewport(viewport);
926 * Need to call this method when tabs are selected for multiple views, or when
927 * loading from Jalview2XML.java
932 void setMenusFromViewport(AlignViewport av)
934 padGapsMenuitem.setSelected(av.isPadGaps());
935 colourTextMenuItem.setSelected(av.isShowColourText());
936 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
937 modifyPID.setEnabled(abovePIDThreshold.isSelected());
938 conservationMenuItem.setSelected(av.getConservationSelected());
939 modifyConservation.setEnabled(conservationMenuItem.isSelected());
940 seqLimits.setSelected(av.getShowJVSuffix());
941 idRightAlign.setSelected(av.isRightAlignIds());
942 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
943 renderGapsMenuItem.setSelected(av.isRenderGaps());
944 wrapMenuItem.setSelected(av.getWrapAlignment());
945 scaleAbove.setVisible(av.getWrapAlignment());
946 scaleLeft.setVisible(av.getWrapAlignment());
947 scaleRight.setVisible(av.getWrapAlignment());
948 annotationPanelMenuItem.setState(av.isShowAnnotation());
950 * Show/hide annotations only enabled if annotation panel is shown
952 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
953 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
954 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
955 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
956 viewBoxesMenuItem.setSelected(av.getShowBoxes());
957 viewTextMenuItem.setSelected(av.getShowText());
958 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
959 showGroupConsensus.setSelected(av.isShowGroupConsensus());
960 showGroupConservation.setSelected(av.isShowGroupConservation());
961 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
962 showSequenceLogo.setSelected(av.isShowSequenceLogo());
963 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
965 ColourMenuHelper.setColourSelected(colourMenu,
966 av.getGlobalColourScheme());
968 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
969 hiddenMarkers.setState(av.getShowHiddenMarkers());
970 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
971 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
972 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
973 autoCalculate.setSelected(av.autoCalculateConsensus);
974 sortByTree.setSelected(av.sortByTree);
975 listenToViewSelections.setSelected(av.followSelection);
977 showProducts.setEnabled(canShowProducts());
978 setGroovyEnabled(Desktop.getGroovyConsole() != null);
984 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
988 public void setGroovyEnabled(boolean b)
990 runGroovy.setEnabled(b);
993 private IProgressIndicator progressBar;
998 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1001 public void setProgressBar(String message, long id)
1003 progressBar.setProgressBar(message, id);
1007 public void registerHandler(final long id,
1008 final IProgressIndicatorHandler handler)
1010 progressBar.registerHandler(id, handler);
1015 * @return true if any progress bars are still active
1018 public boolean operationInProgress()
1020 return progressBar.operationInProgress();
1024 public void setStatus(String text)
1026 statusBar.setText(text);
1030 * Added so Castor Mapping file can obtain Jalview Version
1032 public String getVersion()
1034 return jalview.bin.Cache.getProperty("VERSION");
1037 public FeatureRenderer getFeatureRenderer()
1039 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1043 public void fetchSequence_actionPerformed(ActionEvent e)
1045 new jalview.gui.SequenceFetcher(this);
1049 public void addFromFile_actionPerformed(ActionEvent e)
1051 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1055 public void reload_actionPerformed(ActionEvent e)
1057 if (fileName != null)
1059 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1060 // originating file's format
1061 // TODO: work out how to recover feature settings for correct view(s) when
1062 // file is reloaded.
1063 if (FileFormat.Jalview.equals(currentFileFormat))
1065 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1066 for (int i = 0; i < frames.length; i++)
1068 if (frames[i] instanceof AlignFrame && frames[i] != this
1069 && ((AlignFrame) frames[i]).fileName != null
1070 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1074 frames[i].setSelected(true);
1075 Desktop.instance.closeAssociatedWindows();
1076 } catch (java.beans.PropertyVetoException ex)
1082 Desktop.instance.closeAssociatedWindows();
1084 FileLoader loader = new FileLoader();
1085 DataSourceType protocol = fileName.startsWith("http:")
1086 ? DataSourceType.URL
1087 : DataSourceType.FILE;
1088 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1092 Rectangle bounds = this.getBounds();
1094 FileLoader loader = new FileLoader();
1096 AlignFrame newframe = null;
1098 if (fileObject == null)
1101 DataSourceType protocol = (fileName.startsWith("http:")
1102 ? DataSourceType.URL
1103 : DataSourceType.FILE);
1104 newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
1109 newframe = loader.LoadFileWaitTillLoaded(fileObject,
1110 DataSourceType.FILE, currentFileFormat);
1113 newframe.setBounds(bounds);
1114 if (featureSettings != null && featureSettings.isShowing())
1116 final Rectangle fspos = featureSettings.frame.getBounds();
1117 // TODO: need a 'show feature settings' function that takes bounds -
1118 // need to refactor Desktop.addFrame
1119 newframe.featureSettings_actionPerformed(null);
1120 final FeatureSettings nfs = newframe.featureSettings;
1121 SwingUtilities.invokeLater(new Runnable()
1126 nfs.frame.setBounds(fspos);
1129 this.featureSettings.close();
1130 this.featureSettings = null;
1132 this.closeMenuItem_actionPerformed(true);
1138 public void addFromText_actionPerformed(ActionEvent e)
1141 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1145 public void addFromURL_actionPerformed(ActionEvent e)
1147 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1151 public void save_actionPerformed(ActionEvent e)
1153 if (fileName == null || (currentFileFormat == null)
1154 || fileName.startsWith("http"))
1156 saveAs_actionPerformed();
1160 saveAlignment(fileName, currentFileFormat);
1165 * Saves the alignment to a file with a name chosen by the user, if necessary
1166 * warning if a file would be overwritten
1169 public void saveAs_actionPerformed()
1171 String format = currentFileFormat == null ? null
1172 : currentFileFormat.getName();
1173 JalviewFileChooser chooser = JalviewFileChooser
1174 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1176 chooser.setFileView(new JalviewFileView());
1177 chooser.setDialogTitle(
1178 MessageManager.getString("label.save_alignment_to_file"));
1179 chooser.setToolTipText(MessageManager.getString("action.save"));
1181 int value = chooser.showSaveDialog(this);
1183 if (value != JalviewFileChooser.APPROVE_OPTION)
1187 currentFileFormat = chooser.getSelectedFormat();
1188 // todo is this (2005) test now obsolete - value is never null?
1189 while (currentFileFormat == null)
1191 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1193 .getString("label.select_file_format_before_saving"),
1194 MessageManager.getString("label.file_format_not_specified"),
1195 JvOptionPane.WARNING_MESSAGE);
1196 currentFileFormat = chooser.getSelectedFormat();
1197 value = chooser.showSaveDialog(this);
1198 if (value != JalviewFileChooser.APPROVE_OPTION)
1204 fileName = chooser.getSelectedFile().getPath();
1206 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1207 Cache.setProperty("LAST_DIRECTORY", fileName);
1208 saveAlignment(fileName, currentFileFormat);
1211 boolean lastSaveSuccessful = false;
1213 FileFormatI lastFormatSaved;
1215 String lastFilenameSaved;
1218 * Raise a dialog or status message for the last call to saveAlignment.
1220 * @return true if last call to saveAlignment(file, format) was successful.
1222 public boolean isSaveAlignmentSuccessful()
1225 if (!lastSaveSuccessful)
1227 JvOptionPane.showInternalMessageDialog(this, MessageManager
1228 .formatMessage("label.couldnt_save_file", new Object[]
1229 { lastFilenameSaved }),
1230 MessageManager.getString("label.error_saving_file"),
1231 JvOptionPane.WARNING_MESSAGE);
1236 statusBar.setText(MessageManager.formatMessage(
1237 "label.successfully_saved_to_file_in_format", new Object[]
1238 { lastFilenameSaved, lastFormatSaved }));
1241 return lastSaveSuccessful;
1245 * Saves the alignment to the specified file path, in the specified format,
1246 * which may be an alignment format, or Jalview project format. If the
1247 * alignment has hidden regions, or the format is one capable of including
1248 * non-sequence data (features, annotations, groups), then the user may be
1249 * prompted to specify what to include in the output.
1254 public void saveAlignment(String file, FileFormatI format)
1256 lastSaveSuccessful = false;
1257 lastFilenameSaved = file;
1258 lastFormatSaved = format;
1260 if (FileFormat.Jalview.equals(format))
1262 String shortName = title;
1263 if (shortName.indexOf(File.separatorChar) > -1)
1265 shortName = shortName.substring(
1266 shortName.lastIndexOf(File.separatorChar) + 1);
1268 lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
1273 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1274 RunResponse cancelAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
1279 lastSaveSuccessful = false;
1282 RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
1287 // todo defer this to inside formatSequences (or later)
1288 AlignmentExportData exportData = viewport
1289 .getAlignExportData(options);
1290 String output = new FormatAdapter(alignPanel, options)
1291 .formatSequences(format, exportData.getAlignment(),
1292 exportData.getOmitHidden(),
1293 exportData.getStartEndPostions(),
1294 viewport.getAlignment().getHiddenColumns());
1297 lastSaveSuccessful = false;
1303 PrintWriter out = new PrintWriter(new FileWriter(file));
1306 AlignFrame.this.setTitle(file);
1307 statusBar.setText(MessageManager.formatMessage(
1308 "label.successfully_saved_to_file_in_format",
1310 { fileName, format.getName() }));
1311 } catch (Exception ex)
1313 lastSaveSuccessful = false;
1314 ex.printStackTrace();
1321 * show dialog with export options if applicable; else just do it
1323 if (AlignExportOptions.isNeeded(viewport, format))
1325 AlignExportOptions choices = new AlignExportOptions(
1326 alignPanel.getAlignViewport(), format, options);
1327 choices.setResponseAction(outputAction);
1328 choices.setResponseAction(cancelAction);
1329 choices.showDialog();
1338 * Outputs the alignment to textbox in the requested format, if necessary
1339 * first prompting the user for whether to include hidden regions or
1342 * @param fileFormatName
1345 protected void outputText_actionPerformed(String fileFormatName)
1347 FileFormatI fileFormat = FileFormats.getInstance()
1348 .forName(fileFormatName);
1349 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1350 RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
1355 // todo defer this to inside formatSequences (or later)
1356 AlignmentExportData exportData = viewport
1357 .getAlignExportData(options);
1358 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1359 cap.setForInput(null);
1362 FileFormatI format = fileFormat;
1363 cap.setText(new FormatAdapter(alignPanel, options)
1364 .formatSequences(format, exportData.getAlignment(),
1365 exportData.getOmitHidden(),
1366 exportData.getStartEndPostions(),
1367 viewport.getAlignment().getHiddenColumns()));
1368 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1369 "label.alignment_output_command", new Object[]
1370 { fileFormat.getName() }), 600, 500);
1371 } catch (OutOfMemoryError oom)
1373 new OOMWarning("Outputting alignment as " + fileFormat.getName(),
1381 * show dialog with export options if applicable; else just do it
1383 if (AlignExportOptions.isNeeded(viewport, fileFormat))
1385 AlignExportOptions choices = new AlignExportOptions(
1386 alignPanel.getAlignViewport(), fileFormat, options);
1387 choices.setResponseAction(outputAction);
1388 choices.showDialog();
1403 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1405 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1406 htmlSVG.exportHTML(null);
1410 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1412 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1413 bjs.exportHTML(null);
1416 public void createImageMap(File file, String image)
1418 alignPanel.makePNGImageMap(file, image);
1422 * Creates a PNG image of the alignment and writes it to the given file. If
1423 * the file is null, the user is prompted to choose a file.
1428 public void createPNG(File f)
1430 alignPanel.makeAlignmentImage(TYPE.PNG, f);
1434 * Creates an EPS image of the alignment and writes it to the given file. If
1435 * the file is null, the user is prompted to choose a file.
1440 public void createEPS(File f)
1442 alignPanel.makeAlignmentImage(TYPE.EPS, f);
1446 * Creates an SVG image of the alignment and writes it to the given file. If
1447 * the file is null, the user is prompted to choose a file.
1452 public void createSVG(File f)
1454 alignPanel.makeAlignmentImage(TYPE.SVG, f);
1458 public void pageSetup_actionPerformed(ActionEvent e)
1460 PrinterJob printJob = PrinterJob.getPrinterJob();
1461 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1471 public void printMenuItem_actionPerformed(ActionEvent e)
1473 // Putting in a thread avoids Swing painting problems
1474 PrintThread thread = new PrintThread(alignPanel);
1479 public void exportFeatures_actionPerformed(ActionEvent e)
1481 new AnnotationExporter(alignPanel).exportFeatures();
1485 public void exportAnnotations_actionPerformed(ActionEvent e)
1487 new AnnotationExporter(alignPanel).exportAnnotations();
1491 public void associatedData_actionPerformed(ActionEvent e)
1493 final JalviewFileChooser chooser = new JalviewFileChooser(
1494 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1495 chooser.setFileView(new JalviewFileView());
1496 chooser.setDialogTitle(
1497 MessageManager.getString("label.load_jalview_annotations"));
1498 chooser.setToolTipText(
1499 MessageManager.getString("label.load_jalview_annotations"));
1500 chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
1506 String choice = chooser.getSelectedFile().getPath();
1507 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1508 loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
1513 chooser.openDialog(this);
1517 * Close the current view or all views in the alignment frame. If the frame
1518 * only contains one view then the alignment will be removed from memory.
1520 * @param closeAllTabs
1523 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1525 if (alignPanels != null && alignPanels.size() < 2)
1527 closeAllTabs = true;
1532 if (alignPanels != null)
1536 if (this.isClosed())
1538 // really close all the windows - otherwise wait till
1539 // setClosed(true) is called
1540 for (int i = 0; i < alignPanels.size(); i++)
1542 AlignmentPanel ap = alignPanels.get(i);
1549 closeView(alignPanel);
1556 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1557 * be called recursively, with the frame now in 'closed' state
1559 this.setClosed(true);
1561 } catch (Exception ex)
1563 ex.printStackTrace();
1568 * Close the specified panel and close up tabs appropriately.
1570 * @param panelToClose
1572 public void closeView(AlignmentPanel panelToClose)
1574 int index = tabbedPane.getSelectedIndex();
1575 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1576 alignPanels.remove(panelToClose);
1577 panelToClose.closePanel();
1578 panelToClose = null;
1580 tabbedPane.removeTabAt(closedindex);
1581 tabbedPane.validate();
1583 if (index > closedindex || index == tabbedPane.getTabCount())
1585 // modify currently selected tab index if necessary.
1589 this.tabSelectionChanged(index);
1595 void updateEditMenuBar()
1598 if (viewport.getHistoryList().size() > 0)
1600 undoMenuItem.setEnabled(true);
1601 CommandI command = viewport.getHistoryList().peek();
1602 undoMenuItem.setText(MessageManager
1603 .formatMessage("label.undo_command", new Object[]
1604 { command.getDescription() }));
1608 undoMenuItem.setEnabled(false);
1609 undoMenuItem.setText(MessageManager.getString("action.undo"));
1612 if (viewport.getRedoList().size() > 0)
1614 redoMenuItem.setEnabled(true);
1616 CommandI command = viewport.getRedoList().peek();
1617 redoMenuItem.setText(MessageManager
1618 .formatMessage("label.redo_command", new Object[]
1619 { command.getDescription() }));
1623 redoMenuItem.setEnabled(false);
1624 redoMenuItem.setText(MessageManager.getString("action.redo"));
1629 public void addHistoryItem(CommandI command)
1631 if (command.getSize() > 0)
1633 viewport.addToHistoryList(command);
1634 viewport.clearRedoList();
1635 updateEditMenuBar();
1636 viewport.updateHiddenColumns();
1637 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1638 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1639 // viewport.getColumnSelection()
1640 // .getHiddenColumns().size() > 0);
1646 * @return alignment objects for all views
1648 AlignmentI[] getViewAlignments()
1650 if (alignPanels != null)
1652 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1654 for (AlignmentPanel ap : alignPanels)
1656 als[i++] = ap.av.getAlignment();
1660 if (viewport != null)
1662 return new AlignmentI[] { viewport.getAlignment() };
1674 protected void undoMenuItem_actionPerformed(ActionEvent e)
1676 if (viewport.getHistoryList().isEmpty())
1680 CommandI command = viewport.getHistoryList().pop();
1681 viewport.addToRedoList(command);
1682 command.undoCommand(getViewAlignments());
1684 AlignmentViewport originalSource = getOriginatingSource(command);
1685 updateEditMenuBar();
1687 if (originalSource != null)
1689 if (originalSource != viewport)
1692 "Implementation worry: mismatch of viewport origin for undo");
1694 originalSource.updateHiddenColumns();
1695 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1697 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1698 // viewport.getColumnSelection()
1699 // .getHiddenColumns().size() > 0);
1700 originalSource.firePropertyChange("alignment", null,
1701 originalSource.getAlignment().getSequences());
1712 protected void redoMenuItem_actionPerformed(ActionEvent e)
1714 if (viewport.getRedoList().size() < 1)
1719 CommandI command = viewport.getRedoList().pop();
1720 viewport.addToHistoryList(command);
1721 command.doCommand(getViewAlignments());
1723 AlignmentViewport originalSource = getOriginatingSource(command);
1724 updateEditMenuBar();
1726 if (originalSource != null)
1729 if (originalSource != viewport)
1732 "Implementation worry: mismatch of viewport origin for redo");
1734 originalSource.updateHiddenColumns();
1735 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1737 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1738 // viewport.getColumnSelection()
1739 // .getHiddenColumns().size() > 0);
1740 originalSource.firePropertyChange("alignment", null,
1741 originalSource.getAlignment().getSequences());
1745 AlignmentViewport getOriginatingSource(CommandI command)
1747 AlignmentViewport originalSource = null;
1748 // For sequence removal and addition, we need to fire
1749 // the property change event FROM the viewport where the
1750 // original alignment was altered
1751 AlignmentI al = null;
1752 if (command instanceof EditCommand)
1754 EditCommand editCommand = (EditCommand) command;
1755 al = editCommand.getAlignment();
1756 List<Component> comps = PaintRefresher.components
1757 .get(viewport.getSequenceSetId());
1759 for (Component comp : comps)
1761 if (comp instanceof AlignmentPanel)
1763 if (al == ((AlignmentPanel) comp).av.getAlignment())
1765 originalSource = ((AlignmentPanel) comp).av;
1772 if (originalSource == null)
1774 // The original view is closed, we must validate
1775 // the current view against the closed view first
1778 PaintRefresher.validateSequences(al, viewport.getAlignment());
1781 originalSource = viewport;
1784 return originalSource;
1793 public void moveSelectedSequences(boolean up)
1795 SequenceGroup sg = viewport.getSelectionGroup();
1801 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1802 viewport.getHiddenRepSequences(), up);
1803 alignPanel.paintAlignment(true, false);
1806 synchronized void slideSequences(boolean right, int size)
1808 List<SequenceI> sg = new ArrayList<>();
1809 if (viewport.cursorMode)
1811 sg.add(viewport.getAlignment()
1812 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
1814 else if (viewport.getSelectionGroup() != null
1815 && viewport.getSelectionGroup().getSize() != viewport
1816 .getAlignment().getHeight())
1818 sg = viewport.getSelectionGroup()
1819 .getSequences(viewport.getHiddenRepSequences());
1827 List<SequenceI> invertGroup = new ArrayList<>();
1829 for (SequenceI seq : viewport.getAlignment().getSequences())
1831 if (!sg.contains(seq))
1833 invertGroup.add(seq);
1837 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1839 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1840 for (int i = 0; i < invertGroup.size(); i++)
1842 seqs2[i] = invertGroup.get(i);
1845 SlideSequencesCommand ssc;
1848 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1849 viewport.getGapCharacter());
1853 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1854 viewport.getGapCharacter());
1857 int groupAdjustment = 0;
1858 if (ssc.getGapsInsertedBegin() && right)
1860 if (viewport.cursorMode)
1862 alignPanel.getSeqPanel().moveCursor(size, 0);
1866 groupAdjustment = size;
1869 else if (!ssc.getGapsInsertedBegin() && !right)
1871 if (viewport.cursorMode)
1873 alignPanel.getSeqPanel().moveCursor(-size, 0);
1877 groupAdjustment = -size;
1881 if (groupAdjustment != 0)
1883 viewport.getSelectionGroup().setStartRes(
1884 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1885 viewport.getSelectionGroup().setEndRes(
1886 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1890 * just extend the last slide command if compatible; but not if in
1891 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1893 boolean appendHistoryItem = false;
1894 Deque<CommandI> historyList = viewport.getHistoryList();
1895 boolean inSplitFrame = getSplitViewContainer() != null;
1896 if (!inSplitFrame && historyList != null && historyList.size() > 0
1897 && historyList.peek() instanceof SlideSequencesCommand)
1899 appendHistoryItem = ssc.appendSlideCommand(
1900 (SlideSequencesCommand) historyList.peek());
1903 if (!appendHistoryItem)
1905 addHistoryItem(ssc);
1918 protected void copy_actionPerformed(ActionEvent e)
1920 if (viewport.getSelectionGroup() == null)
1924 // TODO: preserve the ordering of displayed alignment annotation in any
1925 // internal paste (particularly sequence associated annotation)
1926 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1927 String[] omitHidden = null;
1929 if (viewport.hasHiddenColumns())
1931 omitHidden = viewport.getViewAsString(true);
1934 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1935 seqs, omitHidden, null);
1937 StringSelection ss = new StringSelection(output);
1941 jalview.gui.Desktop.internalCopy = true;
1942 // Its really worth setting the clipboard contents
1943 // to empty before setting the large StringSelection!!
1944 Toolkit.getDefaultToolkit().getSystemClipboard()
1945 .setContents(new StringSelection(""), null);
1947 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
1949 } catch (OutOfMemoryError er)
1951 new OOMWarning("copying region", er);
1955 HiddenColumns hiddenColumns = null;
1956 if (viewport.hasHiddenColumns())
1958 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1959 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
1961 // create new HiddenColumns object with copy of hidden regions
1962 // between startRes and endRes, offset by startRes
1963 hiddenColumns = new HiddenColumns(
1964 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
1965 hiddenCutoff, hiddenOffset);
1968 Desktop.jalviewClipboard = new Object[] { seqs,
1969 viewport.getAlignment().getDataset(), hiddenColumns };
1970 statusBar.setText(MessageManager.formatMessage(
1971 "label.copied_sequences_to_clipboard", new Object[]
1972 { Integer.valueOf(seqs.length).toString() }));
1982 protected void pasteNew_actionPerformed(ActionEvent e)
1994 protected void pasteThis_actionPerformed(ActionEvent e)
2000 * Paste contents of Jalview clipboard
2002 * @param newAlignment
2003 * true to paste to a new alignment, otherwise add to this.
2005 void paste(boolean newAlignment)
2007 boolean externalPaste = true;
2010 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2011 Transferable contents = c.getContents(this);
2013 if (contents == null)
2022 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2023 if (str.length() < 1)
2028 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2030 } catch (OutOfMemoryError er)
2032 new OOMWarning("Out of memory pasting sequences!!", er);
2036 SequenceI[] sequences;
2037 boolean annotationAdded = false;
2038 AlignmentI alignment = null;
2040 if (Desktop.jalviewClipboard != null)
2042 // The clipboard was filled from within Jalview, we must use the
2044 // And dataset from the copied alignment
2045 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2046 // be doubly sure that we create *new* sequence objects.
2047 sequences = new SequenceI[newseq.length];
2048 for (int i = 0; i < newseq.length; i++)
2050 sequences[i] = new Sequence(newseq[i]);
2052 alignment = new Alignment(sequences);
2053 externalPaste = false;
2057 // parse the clipboard as an alignment.
2058 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2060 sequences = alignment.getSequencesArray();
2064 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2070 if (Desktop.jalviewClipboard != null)
2072 // dataset is inherited
2073 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2077 // new dataset is constructed
2078 alignment.setDataset(null);
2080 alwidth = alignment.getWidth() + 1;
2084 AlignmentI pastedal = alignment; // preserve pasted alignment object
2085 // Add pasted sequences and dataset into existing alignment.
2086 alignment = viewport.getAlignment();
2087 alwidth = alignment.getWidth() + 1;
2088 // decide if we need to import sequences from an existing dataset
2089 boolean importDs = Desktop.jalviewClipboard != null
2090 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2091 // importDs==true instructs us to copy over new dataset sequences from
2092 // an existing alignment
2093 Vector newDs = (importDs) ? new Vector() : null; // used to create
2094 // minimum dataset set
2096 for (int i = 0; i < sequences.length; i++)
2100 newDs.addElement(null);
2102 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2104 if (importDs && ds != null)
2106 if (!newDs.contains(ds))
2108 newDs.setElementAt(ds, i);
2109 ds = new Sequence(ds);
2110 // update with new dataset sequence
2111 sequences[i].setDatasetSequence(ds);
2115 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2120 // copy and derive new dataset sequence
2121 sequences[i] = sequences[i].deriveSequence();
2122 alignment.getDataset()
2123 .addSequence(sequences[i].getDatasetSequence());
2124 // TODO: avoid creation of duplicate dataset sequences with a
2125 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2127 alignment.addSequence(sequences[i]); // merges dataset
2131 newDs.clear(); // tidy up
2133 if (alignment.getAlignmentAnnotation() != null)
2135 for (AlignmentAnnotation alan : alignment
2136 .getAlignmentAnnotation())
2138 if (alan.graphGroup > fgroup)
2140 fgroup = alan.graphGroup;
2144 if (pastedal.getAlignmentAnnotation() != null)
2146 // Add any annotation attached to alignment.
2147 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2148 for (int i = 0; i < alann.length; i++)
2150 annotationAdded = true;
2151 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2153 AlignmentAnnotation newann = new AlignmentAnnotation(
2155 if (newann.graphGroup > -1)
2157 if (newGraphGroups.size() <= newann.graphGroup
2158 || newGraphGroups.get(newann.graphGroup) == null)
2160 for (int q = newGraphGroups
2161 .size(); q <= newann.graphGroup; q++)
2163 newGraphGroups.add(q, null);
2165 newGraphGroups.set(newann.graphGroup,
2166 new Integer(++fgroup));
2168 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2172 newann.padAnnotation(alwidth);
2173 alignment.addAnnotation(newann);
2183 addHistoryItem(new EditCommand(
2184 MessageManager.getString("label.add_sequences"),
2185 Action.PASTE, sequences, 0, alignment.getWidth(),
2188 // Add any annotations attached to sequences
2189 for (int i = 0; i < sequences.length; i++)
2191 if (sequences[i].getAnnotation() != null)
2193 AlignmentAnnotation newann;
2194 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2196 annotationAdded = true;
2197 newann = sequences[i].getAnnotation()[a];
2198 newann.adjustForAlignment();
2199 newann.padAnnotation(alwidth);
2200 if (newann.graphGroup > -1)
2202 if (newann.graphGroup > -1)
2204 if (newGraphGroups.size() <= newann.graphGroup
2205 || newGraphGroups.get(newann.graphGroup) == null)
2207 for (int q = newGraphGroups
2208 .size(); q <= newann.graphGroup; q++)
2210 newGraphGroups.add(q, null);
2212 newGraphGroups.set(newann.graphGroup,
2213 new Integer(++fgroup));
2215 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2219 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2223 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2231 // propagate alignment changed.
2232 viewport.getRanges().setEndSeq(alignment.getHeight());
2233 if (annotationAdded)
2235 // Duplicate sequence annotation in all views.
2236 AlignmentI[] alview = this.getViewAlignments();
2237 for (int i = 0; i < sequences.length; i++)
2239 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2244 for (int avnum = 0; avnum < alview.length; avnum++)
2246 if (alview[avnum] != alignment)
2248 // duplicate in a view other than the one with input focus
2249 int avwidth = alview[avnum].getWidth() + 1;
2250 // this relies on sann being preserved after we
2251 // modify the sequence's annotation array for each duplication
2252 for (int a = 0; a < sann.length; a++)
2254 AlignmentAnnotation newann = new AlignmentAnnotation(
2256 sequences[i].addAlignmentAnnotation(newann);
2257 newann.padAnnotation(avwidth);
2258 alview[avnum].addAnnotation(newann); // annotation was
2259 // duplicated earlier
2260 // TODO JAL-1145 graphGroups are not updated for sequence
2261 // annotation added to several views. This may cause
2263 alview[avnum].setAnnotationIndex(newann, a);
2268 buildSortByAnnotationScoresMenu();
2270 viewport.firePropertyChange("alignment", null,
2271 alignment.getSequences());
2272 if (alignPanels != null)
2274 for (AlignmentPanel ap : alignPanels)
2276 ap.validateAnnotationDimensions(false);
2281 alignPanel.validateAnnotationDimensions(false);
2287 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2289 String newtitle = new String("Copied sequences");
2291 if (Desktop.jalviewClipboard != null
2292 && Desktop.jalviewClipboard[2] != null)
2294 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2295 af.viewport.setHiddenColumns(hc);
2298 // >>>This is a fix for the moment, until a better solution is
2300 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2301 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2302 .getFeatureRenderer());
2304 // TODO: maintain provenance of an alignment, rather than just make the
2305 // title a concatenation of operations.
2308 if (title.startsWith("Copied sequences"))
2314 newtitle = newtitle.concat("- from " + title);
2319 newtitle = new String("Pasted sequences");
2322 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2327 } catch (Exception ex)
2329 ex.printStackTrace();
2330 System.out.println("Exception whilst pasting: " + ex);
2331 // could be anything being pasted in here
2337 protected void expand_newalign(ActionEvent e)
2341 AlignmentI alignment = AlignmentUtils
2342 .expandContext(getViewport().getAlignment(), -1);
2343 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2345 String newtitle = new String("Flanking alignment");
2347 if (Desktop.jalviewClipboard != null
2348 && Desktop.jalviewClipboard[2] != null)
2350 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2351 af.viewport.setHiddenColumns(hc);
2354 // >>>This is a fix for the moment, until a better solution is
2356 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2357 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2358 .getFeatureRenderer());
2360 // TODO: maintain provenance of an alignment, rather than just make the
2361 // title a concatenation of operations.
2363 if (title.startsWith("Copied sequences"))
2369 newtitle = newtitle.concat("- from " + title);
2373 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2375 } catch (Exception ex)
2377 ex.printStackTrace();
2378 System.out.println("Exception whilst pasting: " + ex);
2379 // could be anything being pasted in here
2380 } catch (OutOfMemoryError oom)
2382 new OOMWarning("Viewing flanking region of alignment", oom);
2393 protected void cut_actionPerformed(ActionEvent e)
2395 copy_actionPerformed(null);
2396 delete_actionPerformed(null);
2406 protected void delete_actionPerformed(ActionEvent evt)
2409 SequenceGroup sg = viewport.getSelectionGroup();
2416 * If the cut affects all sequences, warn, remove highlighted columns
2418 if (sg.getSize() == viewport.getAlignment().getHeight())
2420 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
2421 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2422 if (isEntireAlignWidth)
2424 int confirm = JvOptionPane.showConfirmDialog(this,
2425 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2426 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2427 JvOptionPane.OK_CANCEL_OPTION);
2429 if (confirm == JvOptionPane.CANCEL_OPTION
2430 || confirm == JvOptionPane.CLOSED_OPTION)
2435 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2436 sg.getEndRes() + 1);
2438 SequenceI[] cut = sg.getSequences()
2439 .toArray(new SequenceI[sg.getSize()]);
2441 addHistoryItem(new EditCommand(
2442 MessageManager.getString("label.cut_sequences"), Action.CUT,
2443 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2444 viewport.getAlignment()));
2446 viewport.setSelectionGroup(null);
2447 viewport.sendSelection();
2448 viewport.getAlignment().deleteGroup(sg);
2450 viewport.firePropertyChange("alignment", null,
2451 viewport.getAlignment().getSequences());
2452 if (viewport.getAlignment().getHeight() < 1)
2456 this.setClosed(true);
2457 } catch (Exception ex)
2470 protected void deleteGroups_actionPerformed(ActionEvent e)
2472 if (avc.deleteGroups())
2474 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2475 alignPanel.updateAnnotation();
2476 alignPanel.paintAlignment(true, true);
2487 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2489 SequenceGroup sg = new SequenceGroup();
2491 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2493 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2496 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2497 viewport.setSelectionGroup(sg);
2498 viewport.sendSelection();
2499 // JAL-2034 - should delegate to
2500 // alignPanel to decide if overview needs
2502 alignPanel.paintAlignment(false, false);
2503 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2513 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2515 if (viewport.cursorMode)
2517 alignPanel.getSeqPanel().keyboardNo1 = null;
2518 alignPanel.getSeqPanel().keyboardNo2 = null;
2520 viewport.setSelectionGroup(null);
2521 viewport.getColumnSelection().clear();
2522 viewport.setSelectionGroup(null);
2523 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2524 // JAL-2034 - should delegate to
2525 // alignPanel to decide if overview needs
2527 alignPanel.paintAlignment(false, false);
2528 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2529 viewport.sendSelection();
2539 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2541 SequenceGroup sg = viewport.getSelectionGroup();
2545 selectAllSequenceMenuItem_actionPerformed(null);
2550 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2552 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2554 // JAL-2034 - should delegate to
2555 // alignPanel to decide if overview needs
2558 alignPanel.paintAlignment(true, false);
2559 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2560 viewport.sendSelection();
2564 public void invertColSel_actionPerformed(ActionEvent e)
2566 viewport.invertColumnSelection();
2567 alignPanel.paintAlignment(true, false);
2568 viewport.sendSelection();
2578 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2580 trimAlignment(true);
2590 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2592 trimAlignment(false);
2595 void trimAlignment(boolean trimLeft)
2597 ColumnSelection colSel = viewport.getColumnSelection();
2600 if (!colSel.isEmpty())
2604 column = colSel.getMin();
2608 column = colSel.getMax();
2612 if (viewport.getSelectionGroup() != null)
2614 seqs = viewport.getSelectionGroup()
2615 .getSequencesAsArray(viewport.getHiddenRepSequences());
2619 seqs = viewport.getAlignment().getSequencesArray();
2622 TrimRegionCommand trimRegion;
2625 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2626 column, viewport.getAlignment());
2627 viewport.getRanges().setStartRes(0);
2631 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2632 column, viewport.getAlignment());
2635 statusBar.setText(MessageManager
2636 .formatMessage("label.removed_columns", new String[]
2637 { Integer.valueOf(trimRegion.getSize()).toString() }));
2639 addHistoryItem(trimRegion);
2641 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2643 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2644 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2646 viewport.getAlignment().deleteGroup(sg);
2650 viewport.firePropertyChange("alignment", null,
2651 viewport.getAlignment().getSequences());
2662 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2664 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2667 if (viewport.getSelectionGroup() != null)
2669 seqs = viewport.getSelectionGroup()
2670 .getSequencesAsArray(viewport.getHiddenRepSequences());
2671 start = viewport.getSelectionGroup().getStartRes();
2672 end = viewport.getSelectionGroup().getEndRes();
2676 seqs = viewport.getAlignment().getSequencesArray();
2679 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2680 "Remove Gapped Columns", seqs, start, end,
2681 viewport.getAlignment());
2683 addHistoryItem(removeGapCols);
2685 statusBar.setText(MessageManager
2686 .formatMessage("label.removed_empty_columns", new Object[]
2687 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2689 // This is to maintain viewport position on first residue
2690 // of first sequence
2691 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2692 ViewportRanges ranges = viewport.getRanges();
2693 int startRes = seq.findPosition(ranges.getStartRes());
2694 // ShiftList shifts;
2695 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2696 // edit.alColumnChanges=shifts.getInverse();
2697 // if (viewport.hasHiddenColumns)
2698 // viewport.getColumnSelection().compensateForEdits(shifts);
2699 ranges.setStartRes(seq.findIndex(startRes) - 1);
2700 viewport.firePropertyChange("alignment", null,
2701 viewport.getAlignment().getSequences());
2712 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2714 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2717 if (viewport.getSelectionGroup() != null)
2719 seqs = viewport.getSelectionGroup()
2720 .getSequencesAsArray(viewport.getHiddenRepSequences());
2721 start = viewport.getSelectionGroup().getStartRes();
2722 end = viewport.getSelectionGroup().getEndRes();
2726 seqs = viewport.getAlignment().getSequencesArray();
2729 // This is to maintain viewport position on first residue
2730 // of first sequence
2731 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2732 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2734 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2735 viewport.getAlignment()));
2737 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2739 viewport.firePropertyChange("alignment", null,
2740 viewport.getAlignment().getSequences());
2751 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2753 viewport.setPadGaps(padGapsMenuitem.isSelected());
2754 viewport.firePropertyChange("alignment", null,
2755 viewport.getAlignment().getSequences());
2765 public void findMenuItem_actionPerformed(ActionEvent e)
2771 * Create a new view of the current alignment.
2774 public void newView_actionPerformed(ActionEvent e)
2776 newView(null, true);
2780 * Creates and shows a new view of the current alignment.
2783 * title of newly created view; if null, one will be generated
2784 * @param copyAnnotation
2785 * if true then duplicate all annnotation, groups and settings
2786 * @return new alignment panel, already displayed.
2788 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2791 * Create a new AlignmentPanel (with its own, new Viewport)
2793 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel);
2794 if (!copyAnnotation)
2797 * remove all groups and annotation except for the automatic stuff
2799 newap.av.getAlignment().deleteAllGroups();
2800 newap.av.getAlignment().deleteAllAnnotations(false);
2803 newap.av.setGatherViewsHere(false);
2805 if (viewport.viewName == null)
2807 viewport.viewName = MessageManager
2808 .getString("label.view_name_original");
2812 * Views share the same edits undo and redo stacks
2814 newap.av.setHistoryList(viewport.getHistoryList());
2815 newap.av.setRedoList(viewport.getRedoList());
2818 * Views share the same mappings; need to deregister any new mappings
2819 * created by copyAlignPanel, and register the new reference to the shared
2822 newap.av.replaceMappings(viewport.getAlignment());
2825 * start up cDNA consensus (if applicable) now mappings are in place
2827 if (newap.av.initComplementConsensus())
2829 newap.refresh(true); // adjust layout of annotations
2832 newap.av.viewName = getNewViewName(viewTitle);
2834 addAlignmentPanel(newap, true);
2835 newap.alignmentChanged();
2837 if (alignPanels.size() == 2)
2839 viewport.setGatherViewsHere(true);
2841 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2846 * Make a new name for the view, ensuring it is unique within the current
2847 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2848 * these now use viewId. Unique view names are still desirable for usability.)
2853 protected String getNewViewName(String viewTitle)
2855 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2856 boolean addFirstIndex = false;
2857 if (viewTitle == null || viewTitle.trim().length() == 0)
2859 viewTitle = MessageManager.getString("action.view");
2860 addFirstIndex = true;
2864 index = 1;// we count from 1 if given a specific name
2866 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2868 List<Component> comps = PaintRefresher.components
2869 .get(viewport.getSequenceSetId());
2871 List<String> existingNames = getExistingViewNames(comps);
2873 while (existingNames.contains(newViewName))
2875 newViewName = viewTitle + " " + (++index);
2881 * Returns a list of distinct view names found in the given list of
2882 * components. View names are held on the viewport of an AlignmentPanel.
2887 protected List<String> getExistingViewNames(List<Component> comps)
2889 List<String> existingNames = new ArrayList<>();
2890 for (Component comp : comps)
2892 if (comp instanceof AlignmentPanel)
2894 AlignmentPanel ap = (AlignmentPanel) comp;
2895 if (!existingNames.contains(ap.av.viewName))
2897 existingNames.add(ap.av.viewName);
2901 return existingNames;
2905 * Explode tabbed views into separate windows.
2908 public void expandViews_actionPerformed(ActionEvent e)
2910 Desktop.explodeViews(this);
2914 * Gather views in separate windows back into a tabbed presentation.
2917 public void gatherViews_actionPerformed(ActionEvent e)
2919 Desktop.instance.gatherViews(this);
2929 public void font_actionPerformed(ActionEvent e)
2931 new FontChooser(alignPanel);
2941 protected void seqLimit_actionPerformed(ActionEvent e)
2943 viewport.setShowJVSuffix(seqLimits.isSelected());
2945 alignPanel.getIdPanel().getIdCanvas()
2946 .setPreferredSize(alignPanel.calculateIdWidth());
2947 alignPanel.paintAlignment(true, false);
2951 public void idRightAlign_actionPerformed(ActionEvent e)
2953 viewport.setRightAlignIds(idRightAlign.isSelected());
2954 alignPanel.paintAlignment(false, false);
2958 public void centreColumnLabels_actionPerformed(ActionEvent e)
2960 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2961 alignPanel.paintAlignment(false, false);
2967 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2970 protected void followHighlight_actionPerformed()
2973 * Set the 'follow' flag on the Viewport (and scroll to position if now
2976 final boolean state = this.followHighlightMenuItem.getState();
2977 viewport.setFollowHighlight(state);
2980 alignPanel.scrollToPosition(viewport.getSearchResults(), false);
2991 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2993 viewport.setColourText(colourTextMenuItem.isSelected());
2994 alignPanel.paintAlignment(false, false);
3004 public void wrapMenuItem_actionPerformed(ActionEvent e)
3006 scaleAbove.setVisible(wrapMenuItem.isSelected());
3007 scaleLeft.setVisible(wrapMenuItem.isSelected());
3008 scaleRight.setVisible(wrapMenuItem.isSelected());
3009 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3010 alignPanel.updateLayout();
3014 public void showAllSeqs_actionPerformed(ActionEvent e)
3016 viewport.showAllHiddenSeqs();
3020 public void showAllColumns_actionPerformed(ActionEvent e)
3022 viewport.showAllHiddenColumns();
3023 alignPanel.paintAlignment(true, true);
3024 viewport.sendSelection();
3028 public void hideSelSequences_actionPerformed(ActionEvent e)
3030 viewport.hideAllSelectedSeqs();
3034 * called by key handler and the hide all/show all menu items
3039 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3042 boolean hide = false;
3043 SequenceGroup sg = viewport.getSelectionGroup();
3044 if (!toggleSeqs && !toggleCols)
3046 // Hide everything by the current selection - this is a hack - we do the
3047 // invert and then hide
3048 // first check that there will be visible columns after the invert.
3049 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3050 && sg.getStartRes() <= sg.getEndRes()))
3052 // now invert the sequence set, if required - empty selection implies
3053 // that no hiding is required.
3056 invertSequenceMenuItem_actionPerformed(null);
3057 sg = viewport.getSelectionGroup();
3061 viewport.expandColSelection(sg, true);
3062 // finally invert the column selection and get the new sequence
3064 invertColSel_actionPerformed(null);
3071 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3073 hideSelSequences_actionPerformed(null);
3076 else if (!(toggleCols && viewport.hasSelectedColumns()))
3078 showAllSeqs_actionPerformed(null);
3084 if (viewport.hasSelectedColumns())
3086 hideSelColumns_actionPerformed(null);
3089 viewport.setSelectionGroup(sg);
3094 showAllColumns_actionPerformed(null);
3103 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3104 * event.ActionEvent)
3107 public void hideAllButSelection_actionPerformed(ActionEvent e)
3109 toggleHiddenRegions(false, false);
3110 viewport.sendSelection();
3117 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3121 public void hideAllSelection_actionPerformed(ActionEvent e)
3123 SequenceGroup sg = viewport.getSelectionGroup();
3124 viewport.expandColSelection(sg, false);
3125 viewport.hideAllSelectedSeqs();
3126 viewport.hideSelectedColumns();
3127 alignPanel.paintAlignment(true, true);
3128 viewport.sendSelection();
3135 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3139 public void showAllhidden_actionPerformed(ActionEvent e)
3141 viewport.showAllHiddenColumns();
3142 viewport.showAllHiddenSeqs();
3143 alignPanel.paintAlignment(true, true);
3144 viewport.sendSelection();
3148 public void hideSelColumns_actionPerformed(ActionEvent e)
3150 viewport.hideSelectedColumns();
3151 alignPanel.paintAlignment(true, true);
3152 viewport.sendSelection();
3156 public void hiddenMarkers_actionPerformed(ActionEvent e)
3158 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3169 protected void scaleAbove_actionPerformed(ActionEvent e)
3171 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3172 // TODO: do we actually need to update overview for scale above change ?
3173 alignPanel.paintAlignment(true, false);
3183 protected void scaleLeft_actionPerformed(ActionEvent e)
3185 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3186 alignPanel.paintAlignment(true, false);
3196 protected void scaleRight_actionPerformed(ActionEvent e)
3198 viewport.setScaleRightWrapped(scaleRight.isSelected());
3199 alignPanel.paintAlignment(true, false);
3209 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3211 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3212 alignPanel.paintAlignment(false, false);
3222 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3224 viewport.setShowText(viewTextMenuItem.isSelected());
3225 alignPanel.paintAlignment(false, false);
3235 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3237 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3238 alignPanel.paintAlignment(false, false);
3241 public FeatureSettings featureSettings;
3244 public FeatureSettingsControllerI getFeatureSettingsUI()
3246 return featureSettings;
3250 public void featureSettings_actionPerformed(ActionEvent e)
3252 if (featureSettings != null)
3254 featureSettings.close();
3255 featureSettings = null;
3257 if (!showSeqFeatures.isSelected())
3259 // make sure features are actually displayed
3260 showSeqFeatures.setSelected(true);
3261 showSeqFeatures_actionPerformed(null);
3263 featureSettings = new FeatureSettings(this);
3267 * Set or clear 'Show Sequence Features'
3273 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3275 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3276 alignPanel.paintAlignment(true, true);
3280 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3281 * the annotations panel as a whole.
3283 * The options to show/hide all annotations should be enabled when the panel
3284 * is shown, and disabled when the panel is hidden.
3289 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3291 final boolean setVisible = annotationPanelMenuItem.isSelected();
3292 viewport.setShowAnnotation(setVisible);
3293 this.showAllSeqAnnotations.setEnabled(setVisible);
3294 this.hideAllSeqAnnotations.setEnabled(setVisible);
3295 this.showAllAlAnnotations.setEnabled(setVisible);
3296 this.hideAllAlAnnotations.setEnabled(setVisible);
3297 alignPanel.updateLayout();
3301 public void alignmentProperties()
3304 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3307 String content = MessageManager.formatMessage("label.html_content",
3309 { contents.toString() });
3312 if (/** @j2sNative true || */
3315 JLabel textLabel = new JLabel();
3316 textLabel.setText(content);
3317 textLabel.setBackground(Color.WHITE);
3319 pane = new JPanel(new BorderLayout());
3320 ((JPanel) pane).setOpaque(true);
3321 ((JPanel) pane).add(textLabel, BorderLayout.CENTER);
3325 JEditorPane editPane = new JEditorPane("text/html", "");
3326 editPane.setEditable(false);
3327 editPane.setText(content);
3331 JInternalFrame frame = new JInternalFrame();
3333 frame.getContentPane().add(new JScrollPane(pane));
3335 Desktop.addInternalFrame(frame, MessageManager
3336 .formatMessage("label.alignment_properties", new Object[]
3337 { getTitle() }), 500, 400);
3347 public void overviewMenuItem_actionPerformed(ActionEvent e)
3349 if (alignPanel.overviewPanel != null)
3354 JInternalFrame frame = new JInternalFrame();
3355 final OverviewPanel overview = new OverviewPanel(alignPanel);
3356 frame.setContentPane(overview);
3357 Desktop.addInternalFrame(frame, MessageManager
3358 .formatMessage("label.overview_params", new Object[]
3359 { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
3362 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3363 frame.addInternalFrameListener(
3364 new javax.swing.event.InternalFrameAdapter()
3367 public void internalFrameClosed(
3368 javax.swing.event.InternalFrameEvent evt)
3371 alignPanel.setOverviewPanel(null);
3374 if (getKeyListeners().length > 0)
3376 frame.addKeyListener(getKeyListeners()[0]);
3379 alignPanel.setOverviewPanel(overview);
3383 public void textColour_actionPerformed()
3385 new TextColourChooser().chooseColour(alignPanel, null);
3389 * public void covariationColour_actionPerformed() {
3391 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3395 public void annotationColour_actionPerformed()
3397 new AnnotationColourChooser(viewport, alignPanel);
3401 public void annotationColumn_actionPerformed(ActionEvent e)
3403 new AnnotationColumnChooser(viewport, alignPanel);
3407 * Action on the user checking or unchecking the option to apply the selected
3408 * colour scheme to all groups. If unchecked, groups may have their own
3409 * independent colour schemes.
3414 public void applyToAllGroups_actionPerformed(boolean selected)
3416 viewport.setColourAppliesToAllGroups(selected);
3420 * Action on user selecting a colour from the colour menu
3423 * the name (not the menu item label!) of the colour scheme
3426 public void changeColour_actionPerformed(String name)
3429 * 'User Defined' opens a panel to configure or load a
3430 * user-defined colour scheme
3432 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3434 new UserDefinedColours(alignPanel);
3439 * otherwise set the chosen colour scheme (or null for 'None')
3441 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3442 viewport.getAlignment(), viewport.getHiddenRepSequences());
3447 * Actions on setting or changing the alignment colour scheme
3452 public void changeColour(ColourSchemeI cs)
3454 // TODO: pull up to controller method
3455 ColourMenuHelper.setColourSelected(colourMenu, cs);
3457 viewport.setGlobalColourScheme(cs);
3459 alignPanel.paintAlignment(true, true);
3463 * Show the PID threshold slider panel
3466 protected void modifyPID_actionPerformed()
3468 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3469 alignPanel.getViewName());
3470 SliderPanel.showPIDSlider();
3474 * Show the Conservation slider panel
3477 protected void modifyConservation_actionPerformed()
3479 SliderPanel.setConservationSlider(alignPanel,
3480 viewport.getResidueShading(), alignPanel.getViewName());
3481 SliderPanel.showConservationSlider();
3485 * Action on selecting or deselecting (Colour) By Conservation
3488 public void conservationMenuItem_actionPerformed(boolean selected)
3490 modifyConservation.setEnabled(selected);
3491 viewport.setConservationSelected(selected);
3492 viewport.getResidueShading().setConservationApplied(selected);
3494 changeColour(viewport.getGlobalColourScheme());
3497 modifyConservation_actionPerformed();
3501 SliderPanel.hideConservationSlider();
3506 * Action on selecting or deselecting (Colour) Above PID Threshold
3509 public void abovePIDThreshold_actionPerformed(boolean selected)
3511 modifyPID.setEnabled(selected);
3512 viewport.setAbovePIDThreshold(selected);
3515 viewport.getResidueShading().setThreshold(0,
3516 viewport.isIgnoreGapsConsensus());
3519 changeColour(viewport.getGlobalColourScheme());
3522 modifyPID_actionPerformed();
3526 SliderPanel.hidePIDSlider();
3537 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3539 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3540 AlignmentSorter.sortByPID(viewport.getAlignment(),
3541 viewport.getAlignment().getSequenceAt(0));
3542 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3543 viewport.getAlignment()));
3544 alignPanel.paintAlignment(true, false);
3554 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3556 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3557 AlignmentSorter.sortByID(viewport.getAlignment());
3559 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3560 alignPanel.paintAlignment(true, false);
3570 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3572 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3573 AlignmentSorter.sortByLength(viewport.getAlignment());
3574 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3575 viewport.getAlignment()));
3576 alignPanel.paintAlignment(true, false);
3586 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3588 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3589 AlignmentSorter.sortByGroup(viewport.getAlignment());
3590 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3591 viewport.getAlignment()));
3593 alignPanel.paintAlignment(true, false);
3603 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3605 new RedundancyPanel(alignPanel, this);
3615 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3617 if ((viewport.getSelectionGroup() == null)
3618 || (viewport.getSelectionGroup().getSize() < 2))
3620 JvOptionPane.showInternalMessageDialog(this,
3621 MessageManager.getString(
3622 "label.you_must_select_least_two_sequences"),
3623 MessageManager.getString("label.invalid_selection"),
3624 JvOptionPane.WARNING_MESSAGE);
3628 JInternalFrame frame = new JInternalFrame();
3629 frame.setContentPane(new PairwiseAlignPanel(viewport));
3630 Desktop.addInternalFrame(frame,
3631 MessageManager.getString("action.pairwise_alignment"), 600,
3637 public void autoCalculate_actionPerformed(ActionEvent e)
3639 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3640 if (viewport.autoCalculateConsensus)
3642 viewport.firePropertyChange("alignment", null,
3643 viewport.getAlignment().getSequences());
3648 public void sortByTreeOption_actionPerformed(ActionEvent e)
3650 viewport.sortByTree = sortByTree.isSelected();
3654 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3656 viewport.followSelection = listenToViewSelections.isSelected();
3660 * Constructs a tree panel and adds it to the desktop
3663 * tree type (NJ or AV)
3665 * name of score model used to compute the tree
3667 * parameters for the distance or similarity calculation
3669 void newTreePanel(String type, String modelName,
3670 SimilarityParamsI options)
3672 String frameTitle = "";
3675 boolean onSelection = false;
3676 if (viewport.getSelectionGroup() != null
3677 && viewport.getSelectionGroup().getSize() > 0)
3679 SequenceGroup sg = viewport.getSelectionGroup();
3681 /* Decide if the selection is a column region */
3682 for (SequenceI _s : sg.getSequences())
3684 if (_s.getLength() < sg.getEndRes())
3686 JvOptionPane.showMessageDialog(Desktop.desktop,
3687 MessageManager.getString(
3688 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3689 MessageManager.getString(
3690 "label.sequences_selection_not_aligned"),
3691 JvOptionPane.WARNING_MESSAGE);
3700 if (viewport.getAlignment().getHeight() < 2)
3706 tp = new TreePanel(alignPanel, type, modelName, options);
3707 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3709 frameTitle += " from ";
3711 if (viewport.viewName != null)
3713 frameTitle += viewport.viewName + " of ";
3716 frameTitle += this.title;
3718 Desktop.addInternalFrame(tp, frameTitle, 600, 500);
3729 public void addSortByOrderMenuItem(String title,
3730 final AlignmentOrder order)
3732 final JMenuItem item = new JMenuItem(MessageManager
3733 .formatMessage("action.by_title_param", new Object[]
3736 item.addActionListener(new java.awt.event.ActionListener()
3739 public void actionPerformed(ActionEvent e)
3741 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3743 // TODO: JBPNote - have to map order entries to curent SequenceI
3745 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3747 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3748 viewport.getAlignment()));
3750 alignPanel.paintAlignment(true, false);
3756 * Add a new sort by annotation score menu item
3759 * the menu to add the option to
3761 * the label used to retrieve scores for each sequence on the
3764 public void addSortByAnnotScoreMenuItem(JMenu sort,
3765 final String scoreLabel)
3767 final JMenuItem item = new JMenuItem(scoreLabel);
3769 item.addActionListener(new java.awt.event.ActionListener()
3772 public void actionPerformed(ActionEvent e)
3774 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3775 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3776 viewport.getAlignment());// ,viewport.getSelectionGroup());
3777 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3778 viewport.getAlignment()));
3779 alignPanel.paintAlignment(true, false);
3785 * last hash for alignment's annotation array - used to minimise cost of
3788 protected int _annotationScoreVectorHash;
3791 * search the alignment and rebuild the sort by annotation score submenu the
3792 * last alignment annotation vector hash is stored to minimize cost of
3793 * rebuilding in subsequence calls.
3797 public void buildSortByAnnotationScoresMenu()
3799 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3804 if (viewport.getAlignment().getAlignmentAnnotation()
3805 .hashCode() != _annotationScoreVectorHash)
3807 sortByAnnotScore.removeAll();
3808 // almost certainly a quicker way to do this - but we keep it simple
3809 Hashtable scoreSorts = new Hashtable();
3810 AlignmentAnnotation aann[];
3811 for (SequenceI sqa : viewport.getAlignment().getSequences())
3813 aann = sqa.getAnnotation();
3814 for (int i = 0; aann != null && i < aann.length; i++)
3816 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3818 scoreSorts.put(aann[i].label, aann[i].label);
3822 Enumeration labels = scoreSorts.keys();
3823 while (labels.hasMoreElements())
3825 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3826 (String) labels.nextElement());
3828 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3831 _annotationScoreVectorHash = viewport.getAlignment()
3832 .getAlignmentAnnotation().hashCode();
3837 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3838 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3839 * call. Listeners are added to remove the menu item when the treePanel is
3840 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3844 public void buildTreeSortMenu()
3846 sortByTreeMenu.removeAll();
3848 List<Component> comps = PaintRefresher.components
3849 .get(viewport.getSequenceSetId());
3850 List<TreePanel> treePanels = new ArrayList<>();
3851 for (Component comp : comps)
3853 if (comp instanceof TreePanel)
3855 treePanels.add((TreePanel) comp);
3859 if (treePanels.size() < 1)
3861 sortByTreeMenu.setVisible(false);
3865 sortByTreeMenu.setVisible(true);
3867 for (final TreePanel tp : treePanels)
3869 final JMenuItem item = new JMenuItem(tp.getTitle());
3870 item.addActionListener(new java.awt.event.ActionListener()
3873 public void actionPerformed(ActionEvent e)
3875 tp.sortByTree_actionPerformed();
3876 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3881 sortByTreeMenu.add(item);
3885 public boolean sortBy(AlignmentOrder alorder, String undoname)
3887 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3888 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3889 if (undoname != null)
3891 addHistoryItem(new OrderCommand(undoname, oldOrder,
3892 viewport.getAlignment()));
3894 alignPanel.paintAlignment(true, false);
3899 * Work out whether the whole set of sequences or just the selected set will
3900 * be submitted for multiple alignment.
3903 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3905 // Now, check we have enough sequences
3906 AlignmentView msa = null;
3908 if ((viewport.getSelectionGroup() != null)
3909 && (viewport.getSelectionGroup().getSize() > 1))
3911 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3912 // some common interface!
3914 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3915 * SequenceI[sz = seqs.getSize(false)];
3917 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3918 * seqs.getSequenceAt(i); }
3920 msa = viewport.getAlignmentView(true);
3922 else if (viewport.getSelectionGroup() != null
3923 && viewport.getSelectionGroup().getSize() == 1)
3925 int option = JvOptionPane.showConfirmDialog(this,
3926 MessageManager.getString("warn.oneseq_msainput_selection"),
3927 MessageManager.getString("label.invalid_selection"),
3928 JvOptionPane.OK_CANCEL_OPTION);
3929 if (option == JvOptionPane.OK_OPTION)
3931 msa = viewport.getAlignmentView(false);
3936 msa = viewport.getAlignmentView(false);
3942 * Decides what is submitted to a secondary structure prediction service: the
3943 * first sequence in the alignment, or in the current selection, or, if the
3944 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3945 * region or the whole alignment. (where the first sequence in the set is the
3946 * one that the prediction will be for).
3948 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3950 AlignmentView seqs = null;
3952 if ((viewport.getSelectionGroup() != null)
3953 && (viewport.getSelectionGroup().getSize() > 0))
3955 seqs = viewport.getAlignmentView(true);
3959 seqs = viewport.getAlignmentView(false);
3961 // limit sequences - JBPNote in future - could spawn multiple prediction
3963 // TODO: viewport.getAlignment().isAligned is a global state - the local
3964 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3965 if (!viewport.getAlignment().isAligned(false))
3967 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
3968 // TODO: if seqs.getSequences().length>1 then should really have warned
3982 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
3984 // Pick the tree file
3985 JalviewFileChooser chooser = new JalviewFileChooser(
3986 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3987 chooser.setFileView(new JalviewFileView());
3988 chooser.setDialogTitle(
3989 MessageManager.getString("label.select_newick_like_tree_file"));
3990 chooser.setToolTipText(
3991 MessageManager.getString("label.load_tree_file"));
3993 chooser.response(new jalview.util.dialogrunner.RunResponse(
3994 JalviewFileChooser.APPROVE_OPTION)
3999 String filePath = chooser.getSelectedFile().getPath();
4000 Cache.setProperty("LAST_DIRECTORY", filePath);
4001 NewickFile fin = null;
4004 fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
4005 DataSourceType.FILE));
4006 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4007 } catch (Exception ex)
4009 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4011 .getString("label.problem_reading_tree_file"),
4012 JvOptionPane.WARNING_MESSAGE);
4013 ex.printStackTrace();
4015 if (fin != null && fin.hasWarningMessage())
4017 JvOptionPane.showMessageDialog(Desktop.desktop,
4018 fin.getWarningMessage(),
4019 MessageManager.getString(
4020 "label.possible_problem_with_tree_file"),
4021 JvOptionPane.WARNING_MESSAGE);
4024 }).openDialog(this);
4027 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4029 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4032 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4033 int h, int x, int y)
4035 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4039 * Add a treeviewer for the tree extracted from a Newick file object to the
4040 * current alignment view
4047 * Associated alignment input data (or null)
4056 * @return TreePanel handle
4058 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4059 AlignmentView input, int w, int h, int x, int y)
4061 TreePanel tp = null;
4067 if (nf.getTree() != null)
4069 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4075 tp.setLocation(x, y);
4078 Desktop.addInternalFrame(tp, treeTitle, w, h);
4080 } catch (Exception ex)
4082 ex.printStackTrace();
4088 private boolean buildingMenu = false;
4091 * Generates menu items and listener event actions for web service clients
4094 public void BuildWebServiceMenu()
4096 while (buildingMenu)
4100 System.err.println("Waiting for building menu to finish.");
4102 } catch (Exception e)
4106 final AlignFrame me = this;
4107 buildingMenu = true;
4108 new Thread(new Runnable()
4113 final List<JMenuItem> legacyItems = new ArrayList<>();
4116 // System.err.println("Building ws menu again "
4117 // + Thread.currentThread());
4118 // TODO: add support for context dependent disabling of services based
4120 // alignment and current selection
4121 // TODO: add additional serviceHandle parameter to specify abstract
4123 // class independently of AbstractName
4124 // TODO: add in rediscovery GUI function to restart discoverer
4125 // TODO: group services by location as well as function and/or
4127 // object broker mechanism.
4128 final Vector<JMenu> wsmenu = new Vector<>();
4129 final IProgressIndicator af = me;
4132 * do not i18n these strings - they are hard-coded in class
4133 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4134 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4136 final JMenu msawsmenu = new JMenu("Alignment");
4137 final JMenu secstrmenu = new JMenu(
4138 "Secondary Structure Prediction");
4139 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4140 final JMenu analymenu = new JMenu("Analysis");
4141 final JMenu dismenu = new JMenu("Protein Disorder");
4142 // JAL-940 - only show secondary structure prediction services from
4143 // the legacy server
4144 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4146 Discoverer.services != null && (Discoverer.services.size() > 0))
4148 // TODO: refactor to allow list of AbstractName/Handler bindings to
4150 // stored or retrieved from elsewhere
4151 // No MSAWS used any more:
4152 // Vector msaws = null; // (Vector)
4153 // Discoverer.services.get("MsaWS");
4154 Vector secstrpr = (Vector) Discoverer.services
4156 if (secstrpr != null)
4158 // Add any secondary structure prediction services
4159 for (int i = 0, j = secstrpr.size(); i < j; i++)
4161 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4163 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4164 .getServiceClient(sh);
4165 int p = secstrmenu.getItemCount();
4166 impl.attachWSMenuEntry(secstrmenu, me);
4167 int q = secstrmenu.getItemCount();
4168 for (int litm = p; litm < q; litm++)
4170 legacyItems.add(secstrmenu.getItem(litm));
4176 // Add all submenus in the order they should appear on the web
4178 wsmenu.add(msawsmenu);
4179 wsmenu.add(secstrmenu);
4180 wsmenu.add(dismenu);
4181 wsmenu.add(analymenu);
4182 // No search services yet
4183 // wsmenu.add(seqsrchmenu);
4185 javax.swing.SwingUtilities.invokeLater(new Runnable()
4192 webService.removeAll();
4193 // first, add discovered services onto the webservices menu
4194 if (wsmenu.size() > 0)
4196 for (int i = 0, j = wsmenu.size(); i < j; i++)
4198 webService.add(wsmenu.get(i));
4203 webService.add(me.webServiceNoServices);
4205 // TODO: move into separate menu builder class.
4206 boolean new_sspred = false;
4207 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4209 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4210 if (jws2servs != null)
4212 if (jws2servs.hasServices())
4214 jws2servs.attachWSMenuEntry(webService, me);
4215 for (Jws2Instance sv : jws2servs.getServices())
4217 if (sv.description.toLowerCase().contains("jpred"))
4219 for (JMenuItem jmi : legacyItems)
4221 jmi.setVisible(false);
4227 if (jws2servs.isRunning())
4229 JMenuItem tm = new JMenuItem(
4230 "Still discovering JABA Services");
4231 tm.setEnabled(false);
4236 build_urlServiceMenu(me.webService);
4237 build_fetchdbmenu(webService);
4238 for (JMenu item : wsmenu)
4240 if (item.getItemCount() == 0)
4242 item.setEnabled(false);
4246 item.setEnabled(true);
4249 } catch (Exception e)
4252 "Exception during web service menu building process.",
4257 } catch (Exception e)
4260 buildingMenu = false;
4267 * construct any groupURL type service menu entries.
4271 private void build_urlServiceMenu(JMenu webService)
4273 // TODO: remove this code when 2.7 is released
4274 // DEBUG - alignmentView
4276 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4277 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4279 * @Override public void actionPerformed(ActionEvent e) {
4280 * jalview.datamodel.AlignmentView
4281 * .testSelectionViews(af.viewport.getAlignment(),
4282 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4284 * }); webService.add(testAlView);
4286 // TODO: refactor to RestClient discoverer and merge menu entries for
4287 // rest-style services with other types of analysis/calculation service
4288 // SHmmr test client - still being implemented.
4289 // DEBUG - alignmentView
4291 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4294 client.attachWSMenuEntry(
4295 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4301 * Searches the alignment sequences for xRefs and builds the Show
4302 * Cross-References menu (formerly called Show Products), with database
4303 * sources for which cross-references are found (protein sources for a
4304 * nucleotide alignment and vice versa)
4306 * @return true if Show Cross-references menu should be enabled
4308 public boolean canShowProducts()
4310 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4311 AlignmentI dataset = viewport.getAlignment().getDataset();
4313 showProducts.removeAll();
4314 final boolean dna = viewport.getAlignment().isNucleotide();
4316 if (seqs == null || seqs.length == 0)
4318 // nothing to see here.
4322 boolean showp = false;
4325 List<String> ptypes = new CrossRef(seqs, dataset)
4326 .findXrefSourcesForSequences(dna);
4328 for (final String source : ptypes)
4331 final AlignFrame af = this;
4332 JMenuItem xtype = new JMenuItem(source);
4333 xtype.addActionListener(new ActionListener()
4336 public void actionPerformed(ActionEvent e)
4338 showProductsFor(af.viewport.getSequenceSelection(), dna,
4342 showProducts.add(xtype);
4344 showProducts.setVisible(showp);
4345 showProducts.setEnabled(showp);
4346 } catch (Exception e)
4349 "canShowProducts threw an exception - please report to help@jalview.org",
4357 * Finds and displays cross-references for the selected sequences (protein
4358 * products for nucleotide sequences, dna coding sequences for peptides).
4361 * the sequences to show cross-references for
4363 * true if from a nucleotide alignment (so showing proteins)
4365 * the database to show cross-references for
4367 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4368 final String source)
4370 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4375 * Construct and display a new frame containing the translation of this
4376 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4379 public void showTranslation_actionPerformed(ActionEvent e)
4381 AlignmentI al = null;
4384 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4386 al = dna.translateCdna();
4387 } catch (Exception ex)
4389 jalview.bin.Cache.log.error(
4390 "Exception during translation. Please report this !", ex);
4391 final String msg = MessageManager.getString(
4392 "label.error_when_translating_sequences_submit_bug_report");
4393 final String errorTitle = MessageManager
4394 .getString("label.implementation_error")
4395 + MessageManager.getString("label.translation_failed");
4396 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4397 JvOptionPane.ERROR_MESSAGE);
4400 if (al == null || al.getHeight() == 0)
4402 final String msg = MessageManager.getString(
4403 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4404 final String errorTitle = MessageManager
4405 .getString("label.translation_failed");
4406 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4407 JvOptionPane.WARNING_MESSAGE);
4411 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4412 af.setFileFormat(this.currentFileFormat);
4413 final String newTitle = MessageManager
4414 .formatMessage("label.translation_of_params", new Object[]
4415 { this.getTitle() });
4416 af.setTitle(newTitle);
4417 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4419 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4420 viewport.openSplitFrame(af, new Alignment(seqs));
4424 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4431 * Set the file format
4435 public void setFileFormat(FileFormatI format)
4437 this.currentFileFormat = format;
4441 * Try to load a features file onto the alignment.
4444 * contents or path to retrieve file or a File object
4446 * access mode of file (see jalview.io.AlignFile)
4447 * @return true if features file was parsed correctly.
4449 public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
4452 return avc.parseFeaturesFile(file, sourceType,
4453 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4458 public void refreshFeatureUI(boolean enableIfNecessary)
4460 // note - currently this is only still here rather than in the controller
4461 // because of the featureSettings hard reference that is yet to be
4463 if (enableIfNecessary)
4465 viewport.setShowSequenceFeatures(true);
4466 showSeqFeatures.setSelected(true);
4472 public void dragEnter(DropTargetDragEvent evt)
4477 public void dragExit(DropTargetEvent evt)
4482 public void dragOver(DropTargetDragEvent evt)
4487 public void dropActionChanged(DropTargetDragEvent evt)
4492 public void drop(DropTargetDropEvent evt)
4494 // JAL-1552 - acceptDrop required before getTransferable call for
4495 // Java's Transferable for native dnd
4496 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4497 Transferable t = evt.getTransferable();
4499 final AlignFrame thisaf = this;
4500 final List<Object> files = new ArrayList<>();
4501 List<DataSourceType> protocols = new ArrayList<>();
4505 Desktop.transferFromDropTarget(files, protocols, evt, t);
4506 } catch (Exception e)
4508 e.printStackTrace();
4512 new Thread(new Runnable()
4519 // check to see if any of these files have names matching sequences
4522 SequenceIdMatcher idm = new SequenceIdMatcher(
4523 viewport.getAlignment().getSequencesArray());
4525 * Object[] { String,SequenceI}
4527 ArrayList<Object[]> filesmatched = new ArrayList<>();
4528 ArrayList<Object> filesnotmatched = new ArrayList<>();
4529 for (int i = 0; i < files.size(); i++)
4532 Object file = files.get(i);
4533 String fileName = file.toString();
4535 DataSourceType protocol = (file instanceof File
4536 ? DataSourceType.FILE
4537 : FormatAdapter.checkProtocol(fileName));
4538 if (protocol == DataSourceType.FILE)
4540 File fl = (file instanceof File ? (File) file
4541 : new File(fileName));
4542 pdbfn = fl.getName();
4544 else if (protocol == DataSourceType.URL)
4546 URL url = new URL(fileName);
4547 pdbfn = url.getFile();
4549 if (pdbfn.length() > 0)
4551 // attempt to find a match in the alignment
4552 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4553 int l = 0, c = pdbfn.indexOf(".");
4554 while (mtch == null && c != -1)
4559 } while ((c = pdbfn.indexOf(".", l)) > l);
4562 pdbfn = pdbfn.substring(0, l);
4564 mtch = idm.findAllIdMatches(pdbfn);
4571 type = new IdentifyFile().identify(file, protocol);
4572 } catch (Exception ex)
4576 if (type != null && type.isStructureFile())
4578 filesmatched.add(new Object[] { file, protocol, mtch });
4582 // File wasn't named like one of the sequences or wasn't a PDB
4584 filesnotmatched.add(file);
4588 if (filesmatched.size() > 0)
4590 boolean autoAssociate = Cache
4591 .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
4594 String msg = MessageManager.formatMessage(
4595 "label.automatically_associate_structure_files_with_sequences_same_name",
4597 { Integer.valueOf(filesmatched.size())
4599 String ttl = MessageManager.getString(
4600 "label.automatically_associate_structure_files_by_name");
4601 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4602 ttl, JvOptionPane.YES_NO_OPTION);
4603 autoAssociate = choice == JvOptionPane.YES_OPTION;
4607 for (Object[] fm : filesmatched)
4609 // try and associate
4610 // TODO: may want to set a standard ID naming formalism for
4611 // associating PDB files which have no IDs.
4612 for (SequenceI toassoc : (SequenceI[]) fm[2])
4614 PDBEntry pe = new AssociatePdbFileWithSeq()
4615 .associatePdbWithSeq((String) fm[0],
4616 (DataSourceType) fm[1], toassoc, false,
4620 System.err.println("Associated file : "
4621 + ((String) fm[0]) + " with "
4622 + toassoc.getDisplayId(true));
4626 // TODO: do we need to update overview ? only if features are
4628 alignPanel.paintAlignment(true, false);
4634 * add declined structures as sequences
4636 for (Object[] o : filesmatched)
4638 filesnotmatched.add(o[0]);
4642 if (filesnotmatched.size() > 0)
4644 if (assocfiles > 0 && (Cache.getDefault(
4645 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4646 || JvOptionPane.showConfirmDialog(thisaf,
4647 "<html>" + MessageManager.formatMessage(
4648 "label.ignore_unmatched_dropped_files_info",
4651 filesnotmatched.size())
4654 MessageManager.getString(
4655 "label.ignore_unmatched_dropped_files"),
4656 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4660 for (Object fn : filesnotmatched)
4662 loadJalviewDataFile(fn, null, null, null);
4666 } catch (Exception ex)
4668 ex.printStackTrace();
4676 * Attempt to load a "dropped" file or URL string, by testing in turn for
4678 * <li>an Annotation file</li>
4679 * <li>a JNet file</li>
4680 * <li>a features file</li>
4681 * <li>else try to interpret as an alignment file</li>
4685 * either a filename or a URL string.
4687 public void loadJalviewDataFile(Object file, DataSourceType sourceType,
4688 FileFormatI format, SequenceI assocSeq)
4690 // BH 2018 was String file
4693 if (sourceType == null)
4695 sourceType = FormatAdapter.checkProtocol(file);
4697 // if the file isn't identified, or not positively identified as some
4698 // other filetype (PFAM is default unidentified alignment file type) then
4699 // try to parse as annotation.
4700 boolean isAnnotation = (format == null
4701 || FileFormat.Pfam.equals(format))
4702 ? new AnnotationFile().annotateAlignmentView(viewport,
4708 // first see if its a T-COFFEE score file
4709 TCoffeeScoreFile tcf = null;
4712 tcf = new TCoffeeScoreFile(file, sourceType);
4715 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4719 new TCoffeeColourScheme(viewport.getAlignment()));
4720 isAnnotation = true;
4721 statusBar.setText(MessageManager.getString(
4722 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4726 // some problem - if no warning its probable that the ID matching
4727 // process didn't work
4728 JvOptionPane.showMessageDialog(Desktop.desktop,
4729 tcf.getWarningMessage() == null
4730 ? MessageManager.getString(
4731 "label.check_file_matches_sequence_ids_alignment")
4732 : tcf.getWarningMessage(),
4733 MessageManager.getString(
4734 "label.problem_reading_tcoffee_score_file"),
4735 JvOptionPane.WARNING_MESSAGE);
4742 } catch (Exception x)
4745 "Exception when processing data source as T-COFFEE score file",
4751 // try to see if its a JNet 'concise' style annotation file *before*
4753 // try to parse it as a features file
4756 format = new IdentifyFile().identify(file, sourceType);
4758 if (FileFormat.ScoreMatrix == format)
4760 ScoreMatrixFile sm = new ScoreMatrixFile(
4761 new FileParse(file, sourceType));
4763 // todo: i18n this message
4764 statusBar.setText(MessageManager.formatMessage(
4765 "label.successfully_loaded_matrix",
4766 sm.getMatrixName()));
4768 else if (FileFormat.Jnet.equals(format))
4770 JPredFile predictions = new JPredFile(file, sourceType);
4771 new JnetAnnotationMaker();
4772 JnetAnnotationMaker.add_annotation(predictions,
4773 viewport.getAlignment(), 0, false);
4774 viewport.getAlignment().setupJPredAlignment();
4775 isAnnotation = true;
4777 // else if (IdentifyFile.FeaturesFile.equals(format))
4778 else if (FileFormat.Features.equals(format))
4780 if (parseFeaturesFile(file, sourceType))
4782 alignPanel.paintAlignment(true, true);
4787 new FileLoader().LoadFile(viewport, file, sourceType, format);
4794 alignPanel.adjustAnnotationHeight();
4795 viewport.updateSequenceIdColours();
4796 buildSortByAnnotationScoresMenu();
4797 alignPanel.paintAlignment(true, true);
4799 } catch (Exception ex)
4801 ex.printStackTrace();
4802 } catch (OutOfMemoryError oom)
4807 } catch (Exception x)
4812 + (sourceType != null
4813 ? (sourceType == DataSourceType.PASTE
4815 : "using " + sourceType + " from "
4819 ? "(parsing as '" + format + "' file)"
4821 oom, Desktop.desktop);
4826 * Method invoked by the ChangeListener on the tabbed pane, in other words
4827 * when a different tabbed pane is selected by the user or programmatically.
4830 public void tabSelectionChanged(int index)
4834 alignPanel = alignPanels.get(index);
4835 viewport = alignPanel.av;
4836 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
4837 setMenusFromViewport(viewport);
4841 * 'focus' any colour slider that is open to the selected viewport
4843 if (viewport.getConservationSelected())
4845 SliderPanel.setConservationSlider(alignPanel,
4846 viewport.getResidueShading(), alignPanel.getViewName());
4850 SliderPanel.hideConservationSlider();
4852 if (viewport.getAbovePIDThreshold())
4854 SliderPanel.setPIDSliderSource(alignPanel,
4855 viewport.getResidueShading(), alignPanel.getViewName());
4859 SliderPanel.hidePIDSlider();
4863 * If there is a frame linked to this one in a SplitPane, switch it to the
4864 * same view tab index. No infinite recursion of calls should happen, since
4865 * tabSelectionChanged() should not get invoked on setting the selected
4866 * index to an unchanged value. Guard against setting an invalid index
4867 * before the new view peer tab has been created.
4869 final AlignViewportI peer = viewport.getCodingComplement();
4872 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
4873 .getAlignPanel().alignFrame;
4874 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
4876 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
4882 * On right mouse click on view tab, prompt for and set new view name.
4885 public void tabbedPane_mousePressed(MouseEvent e)
4887 if (e.isPopupTrigger())
4889 String msg = MessageManager.getString("label.enter_view_name");
4890 String reply = JvOptionPane.showInternalInputDialog(this, msg, msg,
4891 JvOptionPane.QUESTION_MESSAGE);
4895 viewport.viewName = reply;
4896 // TODO warn if reply is in getExistingViewNames()?
4897 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4902 public AlignViewport getCurrentView()
4908 * Open the dialog for regex description parsing.
4911 protected void extractScores_actionPerformed(ActionEvent e)
4913 ParseProperties pp = new jalview.analysis.ParseProperties(
4914 viewport.getAlignment());
4915 // TODO: verify regex and introduce GUI dialog for version 2.5
4916 // if (pp.getScoresFromDescription("col", "score column ",
4917 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4919 if (pp.getScoresFromDescription("description column",
4920 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4922 buildSortByAnnotationScoresMenu();
4930 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4934 protected void showDbRefs_actionPerformed(ActionEvent e)
4936 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
4942 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4946 protected void showNpFeats_actionPerformed(ActionEvent e)
4948 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
4952 * find the viewport amongst the tabs in this alignment frame and close that
4957 public boolean closeView(AlignViewportI av)
4961 this.closeMenuItem_actionPerformed(false);
4964 Component[] comp = tabbedPane.getComponents();
4965 for (int i = 0; comp != null && i < comp.length; i++)
4967 if (comp[i] instanceof AlignmentPanel)
4969 if (((AlignmentPanel) comp[i]).av == av)
4972 closeView((AlignmentPanel) comp[i]);
4980 protected void build_fetchdbmenu(JMenu webService)
4982 // Temporary hack - DBRef Fetcher always top level ws entry.
4983 // TODO We probably want to store a sequence database checklist in
4984 // preferences and have checkboxes.. rather than individual sources selected
4986 final JMenu rfetch = new JMenu(
4987 MessageManager.getString("action.fetch_db_references"));
4988 rfetch.setToolTipText(MessageManager.getString(
4989 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
4990 webService.add(rfetch);
4992 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
4993 MessageManager.getString("option.trim_retrieved_seqs"));
4994 trimrs.setToolTipText(
4995 MessageManager.getString("label.trim_retrieved_sequences"));
4997 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
4998 trimrs.addActionListener(new ActionListener()
5001 public void actionPerformed(ActionEvent e)
5003 trimrs.setSelected(trimrs.isSelected());
5004 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5005 Boolean.valueOf(trimrs.isSelected()).toString());
5009 JMenuItem fetchr = new JMenuItem(
5010 MessageManager.getString("label.standard_databases"));
5011 fetchr.setToolTipText(
5012 MessageManager.getString("label.fetch_embl_uniprot"));
5013 fetchr.addActionListener(new ActionListener()
5017 public void actionPerformed(ActionEvent e)
5019 new Thread(new Runnable()
5024 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5025 .getAlignment().isNucleotide();
5026 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5027 alignPanel.av.getSequenceSelection(),
5028 alignPanel.alignFrame, null,
5029 alignPanel.alignFrame.featureSettings, isNucleotide);
5030 dbRefFetcher.addListener(new FetchFinishedListenerI()
5033 public void finished()
5035 AlignFrame.this.setMenusForViewport();
5038 dbRefFetcher.fetchDBRefs(false);
5046 final AlignFrame me = this;
5047 new Thread(new Runnable()
5052 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5053 .getSequenceFetcherSingleton(me);
5054 javax.swing.SwingUtilities.invokeLater(new Runnable()
5059 String[] dbclasses = sf.getOrderedSupportedSources();
5060 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5061 // jalview.util.QuickSort.sort(otherdb, otherdb);
5062 List<DbSourceProxy> otherdb;
5063 JMenu dfetch = new JMenu();
5064 JMenu ifetch = new JMenu();
5065 JMenuItem fetchr = null;
5066 int comp = 0, icomp = 0, mcomp = 15;
5067 String mname = null;
5069 for (String dbclass : dbclasses)
5071 otherdb = sf.getSourceProxy(dbclass);
5072 // add a single entry for this class, or submenu allowing 'fetch
5074 if (otherdb == null || otherdb.size() < 1)
5078 // List<DbSourceProxy> dbs=otherdb;
5079 // otherdb=new ArrayList<DbSourceProxy>();
5080 // for (DbSourceProxy db:dbs)
5082 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5086 mname = "From " + dbclass;
5088 if (otherdb.size() == 1)
5090 final DbSourceProxy[] dassource = otherdb
5091 .toArray(new DbSourceProxy[0]);
5092 DbSourceProxy src = otherdb.get(0);
5093 fetchr = new JMenuItem(src.getDbSource());
5094 fetchr.addActionListener(new ActionListener()
5098 public void actionPerformed(ActionEvent e)
5100 new Thread(new Runnable()
5106 boolean isNucleotide = alignPanel.alignFrame
5107 .getViewport().getAlignment()
5109 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5110 alignPanel.av.getSequenceSelection(),
5111 alignPanel.alignFrame, dassource,
5112 alignPanel.alignFrame.featureSettings,
5115 .addListener(new FetchFinishedListenerI()
5118 public void finished()
5120 AlignFrame.this.setMenusForViewport();
5123 dbRefFetcher.fetchDBRefs(false);
5129 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5130 MessageManager.formatMessage(
5131 "label.fetch_retrieve_from", new Object[]
5132 { src.getDbName() })));
5138 final DbSourceProxy[] dassource = otherdb
5139 .toArray(new DbSourceProxy[0]);
5141 DbSourceProxy src = otherdb.get(0);
5142 fetchr = new JMenuItem(MessageManager
5143 .formatMessage("label.fetch_all_param", new Object[]
5144 { src.getDbSource() }));
5145 fetchr.addActionListener(new ActionListener()
5148 public void actionPerformed(ActionEvent e)
5150 new Thread(new Runnable()
5156 boolean isNucleotide = alignPanel.alignFrame
5157 .getViewport().getAlignment()
5159 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5160 alignPanel.av.getSequenceSelection(),
5161 alignPanel.alignFrame, dassource,
5162 alignPanel.alignFrame.featureSettings,
5165 .addListener(new FetchFinishedListenerI()
5168 public void finished()
5170 AlignFrame.this.setMenusForViewport();
5173 dbRefFetcher.fetchDBRefs(false);
5179 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5180 MessageManager.formatMessage(
5181 "label.fetch_retrieve_from_all_sources",
5183 { Integer.valueOf(otherdb.size())
5185 src.getDbSource(), src.getDbName() })));
5188 // and then build the rest of the individual menus
5189 ifetch = new JMenu(MessageManager.formatMessage(
5190 "label.source_from_db_source", new Object[]
5191 { src.getDbSource() }));
5193 String imname = null;
5195 for (DbSourceProxy sproxy : otherdb)
5197 String dbname = sproxy.getDbName();
5198 String sname = dbname.length() > 5
5199 ? dbname.substring(0, 5) + "..."
5201 String msname = dbname.length() > 10
5202 ? dbname.substring(0, 10) + "..."
5206 imname = MessageManager
5207 .formatMessage("label.from_msname", new Object[]
5210 fetchr = new JMenuItem(msname);
5211 final DbSourceProxy[] dassrc = { sproxy };
5212 fetchr.addActionListener(new ActionListener()
5216 public void actionPerformed(ActionEvent e)
5218 new Thread(new Runnable()
5224 boolean isNucleotide = alignPanel.alignFrame
5225 .getViewport().getAlignment()
5227 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5228 alignPanel.av.getSequenceSelection(),
5229 alignPanel.alignFrame, dassrc,
5230 alignPanel.alignFrame.featureSettings,
5233 .addListener(new FetchFinishedListenerI()
5236 public void finished()
5238 AlignFrame.this.setMenusForViewport();
5241 dbRefFetcher.fetchDBRefs(false);
5247 fetchr.setToolTipText(
5248 "<html>" + MessageManager.formatMessage(
5249 "label.fetch_retrieve_from", new Object[]
5253 if (++icomp >= mcomp || i == (otherdb.size()))
5255 ifetch.setText(MessageManager.formatMessage(
5256 "label.source_to_target", imname, sname));
5258 ifetch = new JMenu();
5266 if (comp >= mcomp || dbi >= (dbclasses.length))
5268 dfetch.setText(MessageManager.formatMessage(
5269 "label.source_to_target", mname, dbclass));
5271 dfetch = new JMenu();
5284 * Left justify the whole alignment.
5287 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5289 AlignmentI al = viewport.getAlignment();
5291 viewport.firePropertyChange("alignment", null, al);
5295 * Right justify the whole alignment.
5298 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5300 AlignmentI al = viewport.getAlignment();
5302 viewport.firePropertyChange("alignment", null, al);
5306 public void setShowSeqFeatures(boolean b)
5308 showSeqFeatures.setSelected(b);
5309 viewport.setShowSequenceFeatures(b);
5316 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5317 * awt.event.ActionEvent)
5320 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5322 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5323 alignPanel.paintAlignment(false, false);
5330 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5334 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5336 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5337 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5345 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5346 * .event.ActionEvent)
5349 protected void showGroupConservation_actionPerformed(ActionEvent e)
5351 viewport.setShowGroupConservation(showGroupConservation.getState());
5352 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5359 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5360 * .event.ActionEvent)
5363 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5365 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5366 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5373 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5374 * .event.ActionEvent)
5377 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5379 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5380 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5384 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5386 showSequenceLogo.setState(true);
5387 viewport.setShowSequenceLogo(true);
5388 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5389 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5393 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5395 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5402 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5403 * .event.ActionEvent)
5406 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5408 if (avc.makeGroupsFromSelection())
5410 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5411 alignPanel.updateAnnotation();
5412 alignPanel.paintAlignment(true, true);
5416 public void clearAlignmentSeqRep()
5418 // TODO refactor alignmentseqrep to controller
5419 if (viewport.getAlignment().hasSeqrep())
5421 viewport.getAlignment().setSeqrep(null);
5422 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5423 alignPanel.updateAnnotation();
5424 alignPanel.paintAlignment(true, true);
5429 protected void createGroup_actionPerformed(ActionEvent e)
5431 if (avc.createGroup())
5433 alignPanel.alignmentChanged();
5438 protected void unGroup_actionPerformed(ActionEvent e)
5442 alignPanel.alignmentChanged();
5447 * make the given alignmentPanel the currently selected tab
5449 * @param alignmentPanel
5451 public void setDisplayedView(AlignmentPanel alignmentPanel)
5453 if (!viewport.getSequenceSetId()
5454 .equals(alignmentPanel.av.getSequenceSetId()))
5456 throw new Error(MessageManager.getString(
5457 "error.implementation_error_cannot_show_view_alignment_frame"));
5459 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5460 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5462 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5467 * Action on selection of menu options to Show or Hide annotations.
5470 * @param forSequences
5471 * update sequence-related annotations
5472 * @param forAlignment
5473 * update non-sequence-related annotations
5476 protected void setAnnotationsVisibility(boolean visible,
5477 boolean forSequences, boolean forAlignment)
5479 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5480 .getAlignmentAnnotation();
5485 for (AlignmentAnnotation aa : anns)
5488 * don't display non-positional annotations on an alignment
5490 if (aa.annotations == null)
5494 boolean apply = (aa.sequenceRef == null && forAlignment)
5495 || (aa.sequenceRef != null && forSequences);
5498 aa.visible = visible;
5501 alignPanel.validateAnnotationDimensions(true);
5502 alignPanel.alignmentChanged();
5506 * Store selected annotation sort order for the view and repaint.
5509 protected void sortAnnotations_actionPerformed()
5511 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5513 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5514 alignPanel.paintAlignment(false, false);
5519 * @return alignment panels in this alignment frame
5521 public List<? extends AlignmentViewPanel> getAlignPanels()
5523 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5527 * Open a new alignment window, with the cDNA associated with this (protein)
5528 * alignment, aligned as is the protein.
5530 protected void viewAsCdna_actionPerformed()
5532 // TODO no longer a menu action - refactor as required
5533 final AlignmentI alignment = getViewport().getAlignment();
5534 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5535 if (mappings == null)
5539 List<SequenceI> cdnaSeqs = new ArrayList<>();
5540 for (SequenceI aaSeq : alignment.getSequences())
5542 for (AlignedCodonFrame acf : mappings)
5544 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5548 * There is a cDNA mapping for this protein sequence - add to new
5549 * alignment. It will share the same dataset sequence as other mapped
5550 * cDNA (no new mappings need to be created).
5552 final Sequence newSeq = new Sequence(dnaSeq);
5553 newSeq.setDatasetSequence(dnaSeq);
5554 cdnaSeqs.add(newSeq);
5558 if (cdnaSeqs.size() == 0)
5560 // show a warning dialog no mapped cDNA
5563 AlignmentI cdna = new Alignment(
5564 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5565 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5566 AlignFrame.DEFAULT_HEIGHT);
5567 cdna.alignAs(alignment);
5568 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5570 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5571 AlignFrame.DEFAULT_HEIGHT);
5575 * Set visibility of dna/protein complement view (available when shown in a
5581 protected void showComplement_actionPerformed(boolean show)
5583 SplitContainerI sf = getSplitViewContainer();
5586 sf.setComplementVisible(this, show);
5591 * Generate the reverse (optionally complemented) of the selected sequences,
5592 * and add them to the alignment
5595 protected void showReverse_actionPerformed(boolean complement)
5597 AlignmentI al = null;
5600 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5601 al = dna.reverseCdna(complement);
5602 viewport.addAlignment(al, "");
5603 addHistoryItem(new EditCommand(
5604 MessageManager.getString("label.add_sequences"), Action.PASTE,
5605 al.getSequencesArray(), 0, al.getWidth(),
5606 viewport.getAlignment()));
5607 } catch (Exception ex)
5609 System.err.println(ex.getMessage());
5615 * Try to run a script in the Groovy console, having first ensured that this
5616 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5617 * be targeted at this alignment.
5620 protected void runGroovy_actionPerformed()
5622 Jalview.setCurrentAlignFrame(this);
5623 groovy.ui.Console console = Desktop.getGroovyConsole();
5624 if (console != null)
5628 console.runScript();
5629 } catch (Exception ex)
5631 System.err.println((ex.toString()));
5632 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
5633 MessageManager.getString("label.couldnt_run_groovy_script"),
5634 MessageManager.getString("label.groovy_support_failed"),
5635 JvOptionPane.ERROR_MESSAGE);
5640 System.err.println("Can't run Groovy script as console not found");
5645 * Hides columns containing (or not containing) a specified feature, provided
5646 * that would not leave all columns hidden
5648 * @param featureType
5649 * @param columnsContaining
5652 public boolean hideFeatureColumns(String featureType,
5653 boolean columnsContaining)
5655 boolean notForHiding = avc.markColumnsContainingFeatures(
5656 columnsContaining, false, false, featureType);
5659 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5660 false, featureType))
5662 getViewport().hideSelectedColumns();
5670 protected void selectHighlightedColumns_actionPerformed(
5671 ActionEvent actionEvent)
5673 // include key modifier check in case user selects from menu
5674 avc.markHighlightedColumns(
5675 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5676 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5677 | ActionEvent.CTRL_MASK)) != 0);
5681 * Rebuilds the Colour menu, including any user-defined colours which have
5682 * been loaded either on startup or during the session
5684 public void buildColourMenu()
5686 colourMenu.removeAll();
5688 colourMenu.add(applyToAllGroups);
5689 colourMenu.add(textColour);
5690 colourMenu.addSeparator();
5692 ColourMenuHelper.addMenuItems(colourMenu, this, viewport.getAlignment(),
5695 colourMenu.addSeparator();
5696 colourMenu.add(conservationMenuItem);
5697 colourMenu.add(modifyConservation);
5698 colourMenu.add(abovePIDThreshold);
5699 colourMenu.add(modifyPID);
5700 colourMenu.add(annotationColour);
5702 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5703 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5707 * Open a dialog (if not already open) that allows the user to select and
5708 * calculate PCA or Tree analysis
5710 protected void openTreePcaDialog()
5712 if (alignPanel.getCalculationDialog() == null)
5714 new CalculationChooser(AlignFrame.this);
5719 protected void loadVcf_actionPerformed()
5721 JalviewFileChooser chooser = new JalviewFileChooser(
5722 Cache.getProperty("LAST_DIRECTORY"));
5723 chooser.setFileView(new JalviewFileView());
5724 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5725 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5726 final AlignFrame us = this;
5727 chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
5734 String choice = chooser.getSelectedFile().getPath();
5735 Cache.setProperty("LAST_DIRECTORY", choice);
5736 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
5737 new VCFLoader(choice).loadVCF(seqs, us);
5741 }).openDialog(null);
5747 class PrintThread extends Thread
5751 public PrintThread(AlignmentPanel ap)
5756 static PageFormat pf;
5761 PrinterJob printJob = PrinterJob.getPrinterJob();
5765 printJob.setPrintable(ap, pf);
5769 printJob.setPrintable(ap);
5772 if (printJob.printDialog())
5777 } catch (Exception PrintException)
5779 PrintException.printStackTrace();