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 java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Rectangle;
27 import java.awt.Toolkit;
28 import java.awt.datatransfer.Clipboard;
29 import java.awt.datatransfer.DataFlavor;
30 import java.awt.datatransfer.StringSelection;
31 import java.awt.datatransfer.Transferable;
32 import java.awt.dnd.DnDConstants;
33 import java.awt.dnd.DropTargetDragEvent;
34 import java.awt.dnd.DropTargetDropEvent;
35 import java.awt.dnd.DropTargetEvent;
36 import java.awt.dnd.DropTargetListener;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.awt.event.FocusAdapter;
40 import java.awt.event.FocusEvent;
41 import java.awt.event.ItemEvent;
42 import java.awt.event.ItemListener;
43 import java.awt.event.KeyAdapter;
44 import java.awt.event.KeyEvent;
45 import java.awt.event.MouseEvent;
46 import java.awt.print.PageFormat;
47 import java.awt.print.PrinterJob;
48 import java.beans.PropertyChangeListener;
50 import java.io.FileWriter;
51 import java.io.PrintWriter;
53 import java.util.ArrayList;
54 import java.util.Arrays;
55 import java.util.Collection;
56 import java.util.Deque;
57 import java.util.List;
58 import java.util.Vector;
60 import javax.swing.ButtonGroup;
61 import javax.swing.JCheckBoxMenuItem;
62 import javax.swing.JComponent;
63 import javax.swing.JEditorPane;
64 import javax.swing.JInternalFrame;
65 import javax.swing.JLabel;
66 import javax.swing.JLayeredPane;
67 import javax.swing.JMenu;
68 import javax.swing.JMenuItem;
69 import javax.swing.JPanel;
70 import javax.swing.JScrollPane;
71 import javax.swing.SwingUtilities;
72 import javax.swing.event.InternalFrameAdapter;
73 import javax.swing.event.InternalFrameEvent;
75 import jalview.analysis.AlignmentSorter;
76 import jalview.analysis.AlignmentUtils;
77 import jalview.analysis.CrossRef;
78 import jalview.analysis.Dna;
79 import jalview.analysis.GeneticCodeI;
80 import jalview.analysis.ParseProperties;
81 import jalview.analysis.SequenceIdMatcher;
82 import jalview.api.AlignExportSettingsI;
83 import jalview.api.AlignViewControllerGuiI;
84 import jalview.api.AlignViewControllerI;
85 import jalview.api.AlignViewportI;
86 import jalview.api.AlignmentViewPanel;
87 import jalview.api.FeatureSettingsControllerI;
88 import jalview.api.FeatureSettingsModelI;
89 import jalview.api.SplitContainerI;
90 import jalview.api.ViewStyleI;
91 import jalview.api.analysis.SimilarityParamsI;
92 import jalview.bin.Cache;
93 import jalview.bin.Jalview;
94 import jalview.commands.CommandI;
95 import jalview.commands.EditCommand;
96 import jalview.commands.EditCommand.Action;
97 import jalview.commands.OrderCommand;
98 import jalview.commands.RemoveGapColCommand;
99 import jalview.commands.RemoveGapsCommand;
100 import jalview.commands.SlideSequencesCommand;
101 import jalview.commands.TrimRegionCommand;
102 import jalview.datamodel.AlignExportSettingsAdapter;
103 import jalview.datamodel.AlignedCodonFrame;
104 import jalview.datamodel.Alignment;
105 import jalview.datamodel.AlignmentAnnotation;
106 import jalview.datamodel.AlignmentExportData;
107 import jalview.datamodel.AlignmentI;
108 import jalview.datamodel.AlignmentOrder;
109 import jalview.datamodel.AlignmentView;
110 import jalview.datamodel.ColumnSelection;
111 import jalview.datamodel.HiddenColumns;
112 import jalview.datamodel.PDBEntry;
113 import jalview.datamodel.SeqCigar;
114 import jalview.datamodel.Sequence;
115 import jalview.datamodel.SequenceGroup;
116 import jalview.datamodel.SequenceI;
117 import jalview.gui.ColourMenuHelper.ColourChangeListener;
118 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
119 import jalview.hmmer.HMMAlign;
120 import jalview.hmmer.HMMBuild;
121 import jalview.hmmer.HMMERParamStore;
122 import jalview.hmmer.HMMERPreset;
123 import jalview.hmmer.HMMSearch;
124 import jalview.hmmer.HmmerCommand;
125 import jalview.hmmer.JackHMMER;
126 import jalview.io.AlignmentProperties;
127 import jalview.io.AnnotationFile;
128 import jalview.io.BackupFiles;
129 import jalview.io.BioJsHTMLOutput;
130 import jalview.io.DataSourceType;
131 import jalview.io.FileFormat;
132 import jalview.io.FileFormatI;
133 import jalview.io.FileFormats;
134 import jalview.io.FileLoader;
135 import jalview.io.FileParse;
136 import jalview.io.FormatAdapter;
137 import jalview.io.HtmlSvgOutput;
138 import jalview.io.IdentifyFile;
139 import jalview.io.JPredFile;
140 import jalview.io.JalviewFileChooser;
141 import jalview.io.JalviewFileView;
142 import jalview.io.JnetAnnotationMaker;
143 import jalview.io.NewickFile;
144 import jalview.io.ScoreMatrixFile;
145 import jalview.io.TCoffeeScoreFile;
146 import jalview.io.vcf.VCFLoader;
147 import jalview.jbgui.GAlignFrame;
148 import jalview.project.Jalview2XML;
149 import jalview.schemes.ColourSchemeI;
150 import jalview.schemes.ColourSchemes;
151 import jalview.schemes.ResidueColourScheme;
152 import jalview.schemes.TCoffeeColourScheme;
153 import jalview.util.ImageMaker.TYPE;
154 import jalview.util.MessageManager;
155 import jalview.util.Platform;
156 import jalview.viewmodel.AlignmentViewport;
157 import jalview.viewmodel.ViewportRanges;
158 import jalview.ws.DBRefFetcher;
159 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
160 import jalview.ws.ServiceChangeListener;
161 import jalview.ws.WSDiscovererI;
162 import jalview.ws.api.ServiceWithParameters;
163 import jalview.ws.jws1.Discoverer;
164 import jalview.ws.jws2.Jws2Discoverer;
165 import jalview.ws.jws2.PreferredServiceRegistry;
166 import jalview.ws.params.ArgumentI;
167 import jalview.ws.params.ParamDatastoreI;
168 import jalview.ws.params.WsParamSetI;
169 import jalview.ws.seqfetcher.DbSourceProxy;
170 import jalview.ws.slivkaws.SlivkaWSDiscoverer;
171 import java.io.IOException;
172 import java.util.HashSet;
173 import java.util.Set;
175 import javax.swing.JFileChooser;
176 import javax.swing.JOptionPane;
182 * @version $Revision$
184 @SuppressWarnings("serial")
185 public class AlignFrame extends GAlignFrame
186 implements DropTargetListener, IProgressIndicator,
187 AlignViewControllerGuiI, ColourChangeListener, ServiceChangeListener
189 public static final int DEFAULT_WIDTH = 700;
191 public static final int DEFAULT_HEIGHT = 500;
194 * The currently displayed panel (selected tabbed view if more than one)
196 public AlignmentPanel alignPanel;
198 AlignViewport viewport;
200 public AlignViewControllerI avc;
202 List<AlignmentPanel> alignPanels = new ArrayList<>();
205 * Last format used to load or save alignments in this window
207 FileFormatI currentFileFormat = null;
210 * Current filename for this alignment
212 String fileName = null;
215 * TODO: remove reference to 'FileObject' in AlignFrame - not correct mapping
220 * Creates a new AlignFrame object with specific width and height.
226 public AlignFrame(AlignmentI al, int width, int height)
228 this(al, null, width, height);
232 * Creates a new AlignFrame object with specific width, height and
238 * @param sequenceSetId
240 public AlignFrame(AlignmentI al, int width, int height,
241 String sequenceSetId)
243 this(al, null, width, height, sequenceSetId);
247 * Creates a new AlignFrame object with specific width, height and
253 * @param sequenceSetId
256 public AlignFrame(AlignmentI al, int width, int height,
257 String sequenceSetId, String viewId)
259 this(al, null, width, height, sequenceSetId, viewId);
263 * new alignment window with hidden columns
267 * @param hiddenColumns
268 * ColumnSelection or null
270 * Width of alignment frame
274 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
277 this(al, hiddenColumns, width, height, null);
281 * Create alignment frame for al with hiddenColumns, a specific width and
282 * height, and specific sequenceId
285 * @param hiddenColumns
288 * @param sequenceSetId
291 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
292 int height, String sequenceSetId)
294 this(al, hiddenColumns, width, height, sequenceSetId, null);
298 * Create alignment frame for al with hiddenColumns, a specific width and
299 * height, and specific sequenceId
302 * @param hiddenColumns
305 * @param sequenceSetId
310 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
311 int height, String sequenceSetId, String viewId)
313 setSize(width, height);
315 if (al.getDataset() == null)
320 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
322 alignPanel = new AlignmentPanel(this, viewport);
324 addAlignmentPanel(alignPanel, true);
328 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
329 HiddenColumns hiddenColumns, int width, int height)
331 setSize(width, height);
333 if (al.getDataset() == null)
338 viewport = new AlignViewport(al, hiddenColumns);
340 if (hiddenSeqs != null && hiddenSeqs.length > 0)
342 viewport.hideSequence(hiddenSeqs);
344 alignPanel = new AlignmentPanel(this, viewport);
345 addAlignmentPanel(alignPanel, true);
350 * Make a new AlignFrame from existing alignmentPanels
357 public AlignFrame(AlignmentPanel ap)
361 addAlignmentPanel(ap, false);
366 * initalise the alignframe from the underlying viewport data and the
371 // setBackground(Color.white); // BH 2019
373 if (!Jalview.isHeadlessMode())
375 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
378 avc = new jalview.controller.AlignViewController(this, viewport,
380 if (viewport.getAlignmentConservationAnnotation() == null)
382 // BLOSUM62Colour.setEnabled(false);
383 conservationMenuItem.setEnabled(false);
384 modifyConservation.setEnabled(false);
385 // PIDColour.setEnabled(false);
386 // abovePIDThreshold.setEnabled(false);
387 // modifyPID.setEnabled(false);
390 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
393 if (sortby.equals("Id"))
395 sortIDMenuItem_actionPerformed(null);
397 else if (sortby.equals("Pairwise Identity"))
399 sortPairwiseMenuItem_actionPerformed(null);
403 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
405 setMenusFromViewport(viewport);
406 buildSortByAnnotationScoresMenu();
407 calculateTree.addActionListener(new ActionListener()
411 public void actionPerformed(ActionEvent e)
418 if (Desktop.desktop != null)
420 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
421 if (!Platform.isJS())
423 addServiceListeners();
428 if (viewport.getWrapAlignment())
430 wrapMenuItem_actionPerformed(null);
433 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
435 this.overviewMenuItem_actionPerformed(null);
440 final List<AlignmentPanel> selviews = new ArrayList<>();
441 final List<AlignmentPanel> origview = new ArrayList<>();
442 final String menuLabel = MessageManager
443 .getString("label.copy_format_from");
444 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
445 new ViewSetProvider()
449 public AlignmentPanel[] getAllAlignmentPanels()
452 origview.add(alignPanel);
453 // make an array of all alignment panels except for this one
454 List<AlignmentPanel> aps = new ArrayList<>(
455 Arrays.asList(Desktop.getAlignmentPanels(null)));
456 aps.remove(AlignFrame.this.alignPanel);
457 return aps.toArray(new AlignmentPanel[aps.size()]);
459 }, selviews, new ItemListener()
463 public void itemStateChanged(ItemEvent e)
465 if (origview.size() > 0)
467 final AlignmentPanel ap = origview.get(0);
470 * Copy the ViewStyle of the selected panel to 'this one'.
471 * Don't change value of 'scaleProteinAsCdna' unless copying
474 ViewStyleI vs = selviews.get(0).getAlignViewport()
476 boolean fromSplitFrame = selviews.get(0)
477 .getAlignViewport().getCodingComplement() != null;
480 vs.setScaleProteinAsCdna(ap.getAlignViewport()
481 .getViewStyle().isScaleProteinAsCdna());
483 ap.getAlignViewport().setViewStyle(vs);
486 * Also rescale ViewStyle of SplitFrame complement if there is
487 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
488 * the whole ViewStyle (allow cDNA protein to have different
491 AlignViewportI complement = ap.getAlignViewport()
492 .getCodingComplement();
493 if (complement != null && vs.isScaleProteinAsCdna())
495 AlignFrame af = Desktop.getAlignFrameFor(complement);
496 ((SplitFrame) af.getSplitViewContainer())
498 af.setMenusForViewport();
502 ap.setSelected(true);
503 ap.alignFrame.setMenusForViewport();
508 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
509 .indexOf("devel") > -1
510 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
511 .indexOf("test") > -1)
513 formatMenu.add(vsel);
515 addFocusListener(new FocusAdapter()
518 public void focusGained(FocusEvent e)
520 Jalview.setCurrentAlignFrame(AlignFrame.this);
527 * Change the filename and format for the alignment, and enable the 'reload'
528 * button functionality.
535 public void setFileName(String file, FileFormatI format)
538 setFileFormat(format);
539 reload.setEnabled(true);
543 * JavaScript will have this, maybe others. More dependable than a file name
544 * and maintains a reference to the actual bytes loaded.
548 public void setFileObject(File file)
550 this.fileObject = file;
554 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
557 void addKeyListener()
559 addKeyListener(new KeyAdapter()
562 public void keyPressed(KeyEvent evt)
564 if (viewport.cursorMode
565 && ((evt.getKeyCode() >= KeyEvent.VK_0
566 && evt.getKeyCode() <= KeyEvent.VK_9)
567 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
568 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
569 && Character.isDigit(evt.getKeyChar()))
571 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
574 switch (evt.getKeyCode())
577 case 27: // escape key
578 deselectAllSequenceMenuItem_actionPerformed(null);
582 case KeyEvent.VK_DOWN:
583 if (evt.isAltDown() || !viewport.cursorMode)
585 moveSelectedSequences(false);
587 if (viewport.cursorMode)
589 alignPanel.getSeqPanel().moveCursor(0, 1);
594 if (evt.isAltDown() || !viewport.cursorMode)
596 moveSelectedSequences(true);
598 if (viewport.cursorMode)
600 alignPanel.getSeqPanel().moveCursor(0, -1);
605 case KeyEvent.VK_LEFT:
606 if (evt.isAltDown() || !viewport.cursorMode)
608 slideSequences(false,
609 alignPanel.getSeqPanel().getKeyboardNo1());
613 alignPanel.getSeqPanel().moveCursor(-1, 0);
618 case KeyEvent.VK_RIGHT:
619 if (evt.isAltDown() || !viewport.cursorMode)
621 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
625 alignPanel.getSeqPanel().moveCursor(1, 0);
629 case KeyEvent.VK_SPACE:
630 if (viewport.cursorMode)
632 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
633 || evt.isShiftDown() || evt.isAltDown());
637 // case KeyEvent.VK_A:
638 // if (viewport.cursorMode)
640 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
641 // //System.out.println("A");
645 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
646 * System.out.println("closing bracket"); } break;
648 case KeyEvent.VK_DELETE:
649 case KeyEvent.VK_BACK_SPACE:
650 if (!viewport.cursorMode)
652 cut_actionPerformed();
656 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
657 || evt.isShiftDown() || evt.isAltDown());
663 if (viewport.cursorMode)
665 alignPanel.getSeqPanel().setCursorRow();
669 if (viewport.cursorMode && !evt.isControlDown())
671 alignPanel.getSeqPanel().setCursorColumn();
675 if (viewport.cursorMode)
677 alignPanel.getSeqPanel().setCursorPosition();
681 case KeyEvent.VK_ENTER:
682 case KeyEvent.VK_COMMA:
683 if (viewport.cursorMode)
685 alignPanel.getSeqPanel().setCursorRowAndColumn();
690 if (viewport.cursorMode)
692 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
696 if (viewport.cursorMode)
698 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
703 viewport.cursorMode = !viewport.cursorMode;
704 setStatus(MessageManager
705 .formatMessage("label.keyboard_editing_mode", new String[]
706 { (viewport.cursorMode ? "on" : "off") }));
707 if (viewport.cursorMode)
709 ViewportRanges ranges = viewport.getRanges();
710 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
712 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
715 alignPanel.getSeqPanel().seqCanvas.repaint();
721 Help.showHelpWindow();
722 } catch (Exception ex)
724 ex.printStackTrace();
729 boolean toggleSeqs = !evt.isControlDown();
730 boolean toggleCols = !evt.isShiftDown();
731 toggleHiddenRegions(toggleSeqs, toggleCols);
736 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
737 boolean modifyExisting = true; // always modify, don't clear
738 // evt.isShiftDown();
739 boolean invertHighlighted = evt.isAltDown();
740 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
744 case KeyEvent.VK_PAGE_UP:
745 viewport.getRanges().pageUp();
747 case KeyEvent.VK_PAGE_DOWN:
748 viewport.getRanges().pageDown();
754 public void keyReleased(KeyEvent evt)
756 switch (evt.getKeyCode())
758 case KeyEvent.VK_LEFT:
759 if (evt.isAltDown() || !viewport.cursorMode)
761 viewport.firePropertyChange("alignment", null,
762 viewport.getAlignment().getSequences());
766 case KeyEvent.VK_RIGHT:
767 if (evt.isAltDown() || !viewport.cursorMode)
769 viewport.firePropertyChange("alignment", null,
770 viewport.getAlignment().getSequences());
778 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
780 ap.alignFrame = this;
781 avc = new jalview.controller.AlignViewController(this, viewport,
786 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
788 int aSize = alignPanels.size();
790 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
792 if (aSize == 1 && ap.av.getViewName() == null)
794 this.getContentPane().add(ap, BorderLayout.CENTER);
800 setInitialTabVisible();
803 expandViews.setEnabled(true);
804 gatherViews.setEnabled(true);
805 tabbedPane.addTab(ap.av.getViewName(), ap);
807 ap.setVisible(false);
812 if (ap.av.isPadGaps())
814 ap.av.getAlignment().padGaps();
816 ap.av.updateConservation(ap);
817 ap.av.updateConsensus(ap);
818 ap.av.updateStrucConsensus(ap);
819 ap.av.initInformationWorker(ap);
823 public void setInitialTabVisible()
825 expandViews.setEnabled(true);
826 gatherViews.setEnabled(true);
827 tabbedPane.setVisible(true);
828 AlignmentPanel first = alignPanels.get(0);
829 tabbedPane.addTab(first.av.getViewName(), first);
830 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
833 public AlignViewport getViewport()
839 public void servicesChanged(WSDiscovererI discoverer,
840 Collection<? extends ServiceWithParameters> services)
842 buildWebServicesMenu();
845 /* Set up intrinsic listeners for dynamically generated GUI bits. */
846 private void addServiceListeners()
848 if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
850 WSDiscovererI discoverer = SlivkaWSDiscoverer.getInstance();
851 discoverer.addServiceChangeListener(this);
853 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
855 WSDiscovererI discoverer = Jws2Discoverer.getDiscoverer();
856 discoverer.addServiceChangeListener(this);
858 // legacy event listener for compatibility with jws1
859 PropertyChangeListener legacyListener = (changeEvent) -> {
860 buildWebServicesMenu();
862 Desktop.instance.addJalviewPropertyChangeListener("services",legacyListener);
864 addInternalFrameListener(new InternalFrameAdapter() {
866 public void internalFrameClosed(InternalFrameEvent e) {
867 System.out.println("deregistering discoverer listener");
868 SlivkaWSDiscoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
869 Jws2Discoverer.getDiscoverer().removeServiceChangeListener(AlignFrame.this);
870 Desktop.instance.removeJalviewPropertyChangeListener("services", legacyListener);
871 closeMenuItem_actionPerformed(true);
874 buildWebServicesMenu();
878 * Configure menu items that vary according to whether the alignment is
879 * nucleotide or protein
881 public void setGUINucleotide()
883 AlignmentI al = getViewport().getAlignment();
884 boolean nucleotide = al.isNucleotide();
886 loadVcf.setVisible(nucleotide);
887 showTranslation.setVisible(nucleotide);
888 showReverse.setVisible(nucleotide);
889 showReverseComplement.setVisible(nucleotide);
890 conservationMenuItem.setEnabled(!nucleotide);
892 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
893 showGroupConservation.setEnabled(!nucleotide);
895 showComplementMenuItem
896 .setText(nucleotide ? MessageManager.getString("label.protein")
897 : MessageManager.getString("label.nucleotide"));
901 * set up menus for the current viewport. This may be called after any
902 * operation that affects the data in the current view (selection changed,
903 * etc) to update the menus to reflect the new state.
906 public void setMenusForViewport()
908 setMenusFromViewport(viewport);
912 * Need to call this method when tabs are selected for multiple views, or when
913 * loading from Jalview2XML.java
918 public void setMenusFromViewport(AlignViewport av)
920 padGapsMenuitem.setSelected(av.isPadGaps());
921 colourTextMenuItem.setSelected(av.isShowColourText());
922 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
923 modifyPID.setEnabled(abovePIDThreshold.isSelected());
924 conservationMenuItem.setSelected(av.getConservationSelected());
925 modifyConservation.setEnabled(conservationMenuItem.isSelected());
926 seqLimits.setSelected(av.getShowJVSuffix());
927 idRightAlign.setSelected(av.isRightAlignIds());
928 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
929 renderGapsMenuItem.setSelected(av.isRenderGaps());
930 wrapMenuItem.setSelected(av.getWrapAlignment());
931 scaleAbove.setVisible(av.getWrapAlignment());
932 scaleLeft.setVisible(av.getWrapAlignment());
933 scaleRight.setVisible(av.getWrapAlignment());
934 annotationPanelMenuItem.setState(av.isShowAnnotation());
936 * Show/hide annotations only enabled if annotation panel is shown
938 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
939 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
940 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
941 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
942 viewBoxesMenuItem.setSelected(av.getShowBoxes());
943 viewTextMenuItem.setSelected(av.getShowText());
944 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
945 showGroupConsensus.setSelected(av.isShowGroupConsensus());
946 showGroupConservation.setSelected(av.isShowGroupConservation());
947 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
948 showSequenceLogo.setSelected(av.isShowSequenceLogo());
949 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
950 showInformationHistogram.setSelected(av.isShowInformationHistogram());
951 showHMMSequenceLogo.setSelected(av.isShowHMMSequenceLogo());
952 normaliseHMMSequenceLogo.setSelected(av.isNormaliseHMMSequenceLogo());
954 ColourMenuHelper.setColourSelected(colourMenu,
955 av.getGlobalColourScheme());
957 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
958 hiddenMarkers.setState(av.getShowHiddenMarkers());
959 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
960 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
961 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
962 autoCalculate.setSelected(av.autoCalculateConsensus);
963 sortByTree.setSelected(av.sortByTree);
964 listenToViewSelections.setSelected(av.followSelection);
966 showProducts.setEnabled(canShowProducts());
967 setGroovyEnabled(Desktop.getGroovyConsole() != null);
973 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
977 public void setGroovyEnabled(boolean b)
979 runGroovy.setEnabled(b);
982 private IProgressIndicator progressBar;
987 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
990 public void setProgressBar(String message, long id)
992 progressBar.setProgressBar(message, id);
996 public void registerHandler(final long id,
997 final IProgressIndicatorHandler handler)
999 progressBar.registerHandler(id, handler);
1004 * @return true if any progress bars are still active
1007 public boolean operationInProgress()
1009 return progressBar.operationInProgress();
1013 * Sets the text of the status bar. Note that setting a null or empty value
1014 * will cause the status bar to be hidden, with possibly undesirable flicker
1015 * of the screen layout.
1018 public void setStatus(String text)
1020 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1024 * Added so Castor Mapping file can obtain Jalview Version
1026 public String getVersion()
1028 return jalview.bin.Cache.getProperty("VERSION");
1031 public FeatureRenderer getFeatureRenderer()
1033 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1037 public void fetchSequence_actionPerformed()
1039 new SequenceFetcher(this);
1043 public void addFromFile_actionPerformed(ActionEvent e)
1045 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1049 public void hmmBuild_actionPerformed(boolean withDefaults)
1051 if (!alignmentIsSufficient(1))
1057 * get default parameters, and optionally show a dialog
1058 * to allow them to be modified
1060 ParamDatastoreI store = HMMERParamStore.forBuild(viewport);
1061 List<ArgumentI> args = store.getServiceParameters();
1065 WsParamSetI set = new HMMERPreset();
1066 WsJobParameters params = new WsJobParameters(store, set, args);
1067 if (params.showRunDialog())
1069 args = params.getJobParams();
1073 return; // user cancelled
1076 new Thread(new HMMBuild(this, args)).start();
1080 public void hmmAlign_actionPerformed(boolean withDefaults)
1082 if (!(checkForHMM() && alignmentIsSufficient(2)))
1088 * get default parameters, and optionally show a dialog
1089 * to allow them to be modified
1091 ParamDatastoreI store = HMMERParamStore.forAlign(viewport);
1092 List<ArgumentI> args = store.getServiceParameters();
1096 WsParamSetI set = new HMMERPreset();
1097 WsJobParameters params = new WsJobParameters(store, set, args);
1098 if (params.showRunDialog())
1100 args = params.getJobParams();
1104 return; // user cancelled
1107 new Thread(new HMMAlign(this, args)).start();
1111 public void hmmSearch_actionPerformed(boolean withDefaults)
1119 * get default parameters, and (if requested) show
1120 * dialog to allow modification
1122 ParamDatastoreI store = HMMERParamStore.forSearch(viewport);
1123 List<ArgumentI> args = store.getServiceParameters();
1127 WsParamSetI set = new HMMERPreset();
1128 WsJobParameters params = new WsJobParameters(store, set, args);
1129 if (params.showRunDialog())
1131 args = params.getJobParams();
1135 return; // user cancelled
1138 new Thread(new HMMSearch(this, args)).start();
1139 alignPanel.repaint();
1143 public void jackhmmer_actionPerformed(boolean withDefaults)
1147 * get default parameters, and (if requested) show
1148 * dialog to allow modification
1151 ParamDatastoreI store = HMMERParamStore.forJackhmmer(viewport);
1152 List<ArgumentI> args = store.getServiceParameters();
1156 WsParamSetI set = new HMMERPreset();
1157 WsJobParameters params = new WsJobParameters(store, set, args);
1158 if (params.showRunDialog())
1160 args = params.getJobParams();
1164 return; // user cancelled
1167 new Thread(new JackHMMER(this, args)).start();
1168 alignPanel.repaint();
1173 * Checks if the alignment has at least one hidden Markov model, if not shows
1174 * a dialog advising to run hmmbuild or load an HMM profile
1178 private boolean checkForHMM()
1180 if (viewport.getAlignment().getHmmSequences().isEmpty())
1182 JOptionPane.showMessageDialog(this,
1183 MessageManager.getString("warn.no_hmm"));
1190 protected void filterByEValue_actionPerformed()
1192 viewport.filterByEvalue(inputDouble("Enter E-Value Cutoff"));
1196 protected void filterByScore_actionPerformed()
1198 viewport.filterByScore(inputDouble("Enter Bit Score Threshold"));
1201 private double inputDouble(String message)
1205 while (d == null || d <= 0)
1207 str = JOptionPane.showInputDialog(this.alignPanel, message);
1210 d = Double.valueOf(str);
1211 } catch (NumberFormatException e)
1219 * Checks if the alignment contains the required number of sequences.
1224 public boolean alignmentIsSufficient(int required)
1226 if (getViewport().getSequenceSelection().length < required)
1228 JOptionPane.showMessageDialog(this,
1229 MessageManager.getString("label.not_enough_sequences"));
1236 * Opens a file browser and adds the selected file, if in Fasta, Stockholm or
1237 * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a
1238 * comma-separated list)
1241 public void addDatabase_actionPerformed() throws IOException
1243 if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null)
1245 Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
1248 String path = openFileChooser(false);
1249 if (path != null && new File(path).exists())
1251 IdentifyFile identifier = new IdentifyFile();
1252 FileFormatI format = identifier.identify(path, DataSourceType.FILE);
1253 if (format == FileFormat.Fasta || format == FileFormat.Stockholm
1254 || format == FileFormat.Pfam)
1256 String currentDbPaths = Cache
1257 .getProperty(Preferences.HMMSEARCH_DBS);
1258 currentDbPaths += Preferences.COMMA + path;
1259 Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
1263 JOptionPane.showMessageDialog(this,
1264 MessageManager.getString("warn.invalid_format"));
1270 * Opens a file chooser, optionally restricted to selecting folders
1271 * (directories) only. Answers the path to the selected file or folder, or
1272 * null if none is chosen.
1277 protected String openFileChooser(boolean forFolder)
1279 // TODO duplicates GPreferences method - relocate to JalviewFileChooser?
1280 String choice = null;
1281 JFileChooser chooser = new JFileChooser();
1284 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1286 chooser.setDialogTitle(
1287 MessageManager.getString("label.open_local_file"));
1288 chooser.setToolTipText(MessageManager.getString("action.open"));
1290 int value = chooser.showOpenDialog(this);
1292 if (value == JFileChooser.APPROVE_OPTION)
1294 choice = chooser.getSelectedFile().getPath();
1300 public void reload_actionPerformed(ActionEvent e)
1302 if (fileName != null)
1304 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1305 // originating file's format
1306 // TODO: work out how to recover feature settings for correct view(s) when
1307 // file is reloaded.
1308 if (FileFormat.Jalview.equals(currentFileFormat))
1310 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1311 for (int i = 0; i < frames.length; i++)
1313 if (frames[i] instanceof AlignFrame && frames[i] != this
1314 && ((AlignFrame) frames[i]).fileName != null
1315 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1319 frames[i].setSelected(true);
1320 Desktop.instance.closeAssociatedWindows();
1321 } catch (java.beans.PropertyVetoException ex)
1327 Desktop.instance.closeAssociatedWindows();
1329 FileLoader loader = new FileLoader();
1330 DataSourceType protocol = fileName.startsWith("http:")
1331 ? DataSourceType.URL
1332 : DataSourceType.FILE;
1333 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1337 Rectangle bounds = this.getBounds();
1339 FileLoader loader = new FileLoader();
1341 AlignFrame newframe = null;
1343 if (fileObject == null)
1346 DataSourceType protocol = (fileName.startsWith("http:")
1347 ? DataSourceType.URL
1348 : DataSourceType.FILE);
1349 newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
1354 newframe = loader.LoadFileWaitTillLoaded(fileObject,
1355 DataSourceType.FILE, currentFileFormat);
1358 newframe.setBounds(bounds);
1359 if (featureSettings != null && featureSettings.isShowing())
1361 final Rectangle fspos = featureSettings.frame.getBounds();
1362 // TODO: need a 'show feature settings' function that takes bounds -
1363 // need to refactor Desktop.addFrame
1364 newframe.featureSettings_actionPerformed(null);
1365 final FeatureSettings nfs = newframe.featureSettings;
1366 SwingUtilities.invokeLater(new Runnable()
1371 nfs.frame.setBounds(fspos);
1374 this.featureSettings.close();
1375 this.featureSettings = null;
1377 this.closeMenuItem_actionPerformed(true);
1383 public void addFromText_actionPerformed(ActionEvent e)
1386 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1390 public void addFromURL_actionPerformed(ActionEvent e)
1392 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1396 public void save_actionPerformed(ActionEvent e)
1398 if (fileName == null || (currentFileFormat == null)
1399 || fileName.startsWith("http"))
1401 saveAs_actionPerformed();
1405 saveAlignment(fileName, currentFileFormat);
1410 * Saves the alignment to a file with a name chosen by the user, if necessary
1411 * warning if a file would be overwritten
1414 public void saveAs_actionPerformed()
1416 String format = currentFileFormat == null ? null
1417 : currentFileFormat.getName();
1418 JalviewFileChooser chooser = JalviewFileChooser
1419 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1421 chooser.setFileView(new JalviewFileView());
1422 chooser.setDialogTitle(
1423 MessageManager.getString("label.save_alignment_to_file"));
1424 chooser.setToolTipText(MessageManager.getString("action.save"));
1426 int value = chooser.showSaveDialog(this);
1428 if (value != JalviewFileChooser.APPROVE_OPTION)
1432 currentFileFormat = chooser.getSelectedFormat();
1433 // todo is this (2005) test now obsolete - value is never null?
1434 while (currentFileFormat == null)
1436 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1438 .getString("label.select_file_format_before_saving"),
1439 MessageManager.getString("label.file_format_not_specified"),
1440 JvOptionPane.WARNING_MESSAGE);
1441 currentFileFormat = chooser.getSelectedFormat();
1442 value = chooser.showSaveDialog(this);
1443 if (value != JalviewFileChooser.APPROVE_OPTION)
1449 fileName = chooser.getSelectedFile().getPath();
1451 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1452 Cache.setProperty("LAST_DIRECTORY", fileName);
1453 saveAlignment(fileName, currentFileFormat);
1456 boolean lastSaveSuccessful = false;
1458 FileFormatI lastFormatSaved;
1460 String lastFilenameSaved;
1463 * Raise a dialog or status message for the last call to saveAlignment.
1465 * @return true if last call to saveAlignment(file, format) was successful.
1467 public boolean isSaveAlignmentSuccessful()
1470 if (!lastSaveSuccessful)
1472 JvOptionPane.showInternalMessageDialog(this, MessageManager
1473 .formatMessage("label.couldnt_save_file", new Object[]
1474 { lastFilenameSaved }),
1475 MessageManager.getString("label.error_saving_file"),
1476 JvOptionPane.WARNING_MESSAGE);
1481 setStatus(MessageManager.formatMessage(
1482 "label.successfully_saved_to_file_in_format", new Object[]
1483 { lastFilenameSaved, lastFormatSaved }));
1486 return lastSaveSuccessful;
1490 * Saves the alignment to the specified file path, in the specified format,
1491 * which may be an alignment format, or Jalview project format. If the
1492 * alignment has hidden regions, or the format is one capable of including
1493 * non-sequence data (features, annotations, groups), then the user may be
1494 * prompted to specify what to include in the output.
1499 public void saveAlignment(String file, FileFormatI format)
1501 lastSaveSuccessful = true;
1502 lastFilenameSaved = file;
1503 lastFormatSaved = format;
1505 if (FileFormat.Jalview.equals(format))
1507 String shortName = title;
1508 if (shortName.indexOf(File.separatorChar) > -1)
1510 shortName = shortName
1511 .substring(shortName.lastIndexOf(File.separatorChar) + 1);
1513 lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
1516 statusBar.setText(MessageManager.formatMessage(
1517 "label.successfully_saved_to_file_in_format", new Object[]
1518 { fileName, format }));
1523 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1524 Runnable cancelAction = new Runnable()
1529 lastSaveSuccessful = false;
1532 Runnable outputAction = new Runnable()
1537 // todo defer this to inside formatSequences (or later)
1538 AlignmentExportData exportData = viewport
1539 .getAlignExportData(options);
1540 String output = new FormatAdapter(alignPanel, options)
1541 .formatSequences(format, exportData.getAlignment(),
1542 exportData.getOmitHidden(),
1543 exportData.getStartEndPostions(),
1544 viewport.getAlignment().getHiddenColumns());
1547 lastSaveSuccessful = false;
1551 // create backupfiles object and get new temp filename destination
1552 boolean doBackup = BackupFiles.getEnabled();
1553 BackupFiles backupfiles = doBackup ? new BackupFiles(file) : null;
1556 String tempFilePath = doBackup ? backupfiles.getTempFilePath()
1558 PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
1562 AlignFrame.this.setTitle(file);
1563 statusBar.setText(MessageManager.formatMessage(
1564 "label.successfully_saved_to_file_in_format",
1566 { fileName, format.getName() }));
1567 lastSaveSuccessful = true;
1568 } catch (Exception ex)
1570 lastSaveSuccessful = false;
1571 ex.printStackTrace();
1576 backupfiles.setWriteSuccess(lastSaveSuccessful);
1577 // do the backup file roll and rename the temp file to actual file
1578 lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
1585 * show dialog with export options if applicable; else just do it
1587 if (AlignExportOptions.isNeeded(viewport, format))
1589 AlignExportOptions choices = new AlignExportOptions(
1590 alignPanel.getAlignViewport(), format, options);
1591 choices.setResponseAction(0, outputAction);
1592 choices.setResponseAction(1, cancelAction);
1593 choices.showDialog();
1602 * Outputs the alignment to textbox in the requested format, if necessary
1603 * first prompting the user for whether to include hidden regions or
1606 * @param fileFormatName
1609 protected void outputText_actionPerformed(String fileFormatName)
1611 FileFormatI fileFormat = FileFormats.getInstance()
1612 .forName(fileFormatName);
1613 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1614 Runnable outputAction = new Runnable()
1619 // todo defer this to inside formatSequences (or later)
1620 AlignmentExportData exportData = viewport
1621 .getAlignExportData(options);
1622 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1623 cap.setForInput(null);
1626 FileFormatI format = fileFormat;
1627 cap.setText(new FormatAdapter(alignPanel, options)
1628 .formatSequences(format, exportData.getAlignment(),
1629 exportData.getOmitHidden(),
1630 exportData.getStartEndPostions(),
1631 viewport.getAlignment().getHiddenColumns()));
1632 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1633 "label.alignment_output_command", new Object[]
1634 { fileFormat.getName() }), 600, 500);
1635 } catch (OutOfMemoryError oom)
1637 new OOMWarning("Outputting alignment as " + fileFormat.getName(),
1645 * show dialog with export options if applicable; else just do it
1647 if (AlignExportOptions.isNeeded(viewport, fileFormat))
1649 AlignExportOptions choices = new AlignExportOptions(
1650 alignPanel.getAlignViewport(), fileFormat, options);
1651 choices.setResponseAction(0, outputAction);
1652 choices.showDialog();
1667 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1669 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1670 htmlSVG.exportHTML(null);
1674 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1676 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1677 bjs.exportHTML(null);
1680 public void createImageMap(File file, String image)
1682 alignPanel.makePNGImageMap(file, image);
1686 * Creates a PNG image of the alignment and writes it to the given file. If
1687 * the file is null, the user is prompted to choose a file.
1692 public void createPNG(File f)
1694 alignPanel.makeAlignmentImage(TYPE.PNG, f);
1698 * Creates an EPS image of the alignment and writes it to the given file. If
1699 * the file is null, the user is prompted to choose a file.
1704 public void createEPS(File f)
1706 alignPanel.makeAlignmentImage(TYPE.EPS, f);
1710 * Creates an SVG image of the alignment and writes it to the given file. If
1711 * the file is null, the user is prompted to choose a file.
1716 public void createSVG(File f)
1718 alignPanel.makeAlignmentImage(TYPE.SVG, f);
1722 public void pageSetup_actionPerformed(ActionEvent e)
1724 PrinterJob printJob = PrinterJob.getPrinterJob();
1725 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1735 public void printMenuItem_actionPerformed(ActionEvent e)
1737 // Putting in a thread avoids Swing painting problems
1738 PrintThread thread = new PrintThread(alignPanel);
1743 public void exportFeatures_actionPerformed(ActionEvent e)
1745 new AnnotationExporter(alignPanel).exportFeatures();
1749 public void exportAnnotations_actionPerformed(ActionEvent e)
1751 new AnnotationExporter(alignPanel).exportAnnotations();
1755 public void associatedData_actionPerformed(ActionEvent e)
1756 throws IOException, InterruptedException
1758 final JalviewFileChooser chooser = new JalviewFileChooser(
1759 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1760 chooser.setFileView(new JalviewFileView());
1761 String tooltip = MessageManager
1762 .getString("label.load_jalview_annotations");
1763 chooser.setDialogTitle(tooltip);
1764 chooser.setToolTipText(tooltip);
1765 chooser.setResponseHandler(0, new Runnable()
1770 String choice = chooser.getSelectedFile().getPath();
1771 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1772 loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
1776 chooser.showOpenDialog(this);
1780 * Close the current view or all views in the alignment frame. If the frame
1781 * only contains one view then the alignment will be removed from memory.
1783 * @param closeAllTabs
1786 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1788 if (alignPanels != null && alignPanels.size() < 2)
1790 closeAllTabs = true;
1795 if (alignPanels != null)
1799 if (this.isClosed())
1801 // really close all the windows - otherwise wait till
1802 // setClosed(true) is called
1803 for (int i = 0; i < alignPanels.size(); i++)
1805 AlignmentPanel ap = alignPanels.get(i);
1812 closeView(alignPanel);
1817 if (featureSettings != null && featureSettings.isOpen())
1819 featureSettings.close();
1820 featureSettings = null;
1823 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1824 * be called recursively, with the frame now in 'closed' state
1826 this.setClosed(true);
1828 } catch (Exception ex)
1830 ex.printStackTrace();
1835 * Close the specified panel and close up tabs appropriately.
1837 * @param panelToClose
1839 public void closeView(AlignmentPanel panelToClose)
1841 int index = tabbedPane.getSelectedIndex();
1842 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1843 alignPanels.remove(panelToClose);
1844 panelToClose.closePanel();
1845 panelToClose = null;
1847 tabbedPane.removeTabAt(closedindex);
1848 tabbedPane.validate();
1850 if (index > closedindex || index == tabbedPane.getTabCount())
1852 // modify currently selected tab index if necessary.
1856 this.tabSelectionChanged(index);
1862 void updateEditMenuBar()
1865 if (viewport.getHistoryList().size() > 0)
1867 undoMenuItem.setEnabled(true);
1868 CommandI command = viewport.getHistoryList().peek();
1869 undoMenuItem.setText(MessageManager
1870 .formatMessage("label.undo_command", new Object[]
1871 { command.getDescription() }));
1875 undoMenuItem.setEnabled(false);
1876 undoMenuItem.setText(MessageManager.getString("action.undo"));
1879 if (viewport.getRedoList().size() > 0)
1881 redoMenuItem.setEnabled(true);
1883 CommandI command = viewport.getRedoList().peek();
1884 redoMenuItem.setText(MessageManager
1885 .formatMessage("label.redo_command", new Object[]
1886 { command.getDescription() }));
1890 redoMenuItem.setEnabled(false);
1891 redoMenuItem.setText(MessageManager.getString("action.redo"));
1896 public void addHistoryItem(CommandI command)
1898 if (command.getSize() > 0)
1900 viewport.addToHistoryList(command);
1901 viewport.clearRedoList();
1902 updateEditMenuBar();
1903 viewport.updateHiddenColumns();
1904 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1905 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1906 // viewport.getColumnSelection()
1907 // .getHiddenColumns().size() > 0);
1913 * @return alignment objects for all views
1915 AlignmentI[] getViewAlignments()
1917 if (alignPanels != null)
1919 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1921 for (AlignmentPanel ap : alignPanels)
1923 als[i++] = ap.av.getAlignment();
1927 if (viewport != null)
1929 return new AlignmentI[] { viewport.getAlignment() };
1941 protected void undoMenuItem_actionPerformed(ActionEvent e)
1943 if (viewport.getHistoryList().isEmpty())
1947 CommandI command = viewport.getHistoryList().pop();
1948 viewport.addToRedoList(command);
1949 command.undoCommand(getViewAlignments());
1951 AlignmentViewport originalSource = getOriginatingSource(command);
1952 updateEditMenuBar();
1954 if (originalSource != null)
1956 if (originalSource != viewport)
1959 "Implementation worry: mismatch of viewport origin for undo");
1961 originalSource.updateHiddenColumns();
1962 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1964 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1965 // viewport.getColumnSelection()
1966 // .getHiddenColumns().size() > 0);
1967 originalSource.firePropertyChange("alignment", null,
1968 originalSource.getAlignment().getSequences());
1979 protected void redoMenuItem_actionPerformed(ActionEvent e)
1981 if (viewport.getRedoList().size() < 1)
1986 CommandI command = viewport.getRedoList().pop();
1987 viewport.addToHistoryList(command);
1988 command.doCommand(getViewAlignments());
1990 AlignmentViewport originalSource = getOriginatingSource(command);
1991 updateEditMenuBar();
1993 if (originalSource != null)
1996 if (originalSource != viewport)
1999 "Implementation worry: mismatch of viewport origin for redo");
2001 originalSource.updateHiddenColumns();
2002 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
2004 // && viewport.getColumnSelection().getHiddenColumns() != null &&
2005 // viewport.getColumnSelection()
2006 // .getHiddenColumns().size() > 0);
2007 originalSource.firePropertyChange("alignment", null,
2008 originalSource.getAlignment().getSequences());
2012 AlignmentViewport getOriginatingSource(CommandI command)
2014 AlignmentViewport originalSource = null;
2015 // For sequence removal and addition, we need to fire
2016 // the property change event FROM the viewport where the
2017 // original alignment was altered
2018 AlignmentI al = null;
2019 if (command instanceof EditCommand)
2021 EditCommand editCommand = (EditCommand) command;
2022 al = editCommand.getAlignment();
2023 List<Component> comps = PaintRefresher.components
2024 .get(viewport.getSequenceSetId());
2026 for (Component comp : comps)
2028 if (comp instanceof AlignmentPanel)
2030 if (al == ((AlignmentPanel) comp).av.getAlignment())
2032 originalSource = ((AlignmentPanel) comp).av;
2039 if (originalSource == null)
2041 // The original view is closed, we must validate
2042 // the current view against the closed view first
2045 PaintRefresher.validateSequences(al, viewport.getAlignment());
2048 originalSource = viewport;
2051 return originalSource;
2060 public void moveSelectedSequences(boolean up)
2062 SequenceGroup sg = viewport.getSelectionGroup();
2068 viewport.getAlignment().moveSelectedSequencesByOne(sg,
2069 viewport.getHiddenRepSequences(), up);
2070 alignPanel.paintAlignment(true, false);
2073 synchronized void slideSequences(boolean right, int size)
2075 List<SequenceI> sg = new ArrayList<>();
2076 if (viewport.cursorMode)
2078 sg.add(viewport.getAlignment()
2079 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
2081 else if (viewport.getSelectionGroup() != null
2082 && viewport.getSelectionGroup().getSize() != viewport
2083 .getAlignment().getHeight())
2085 sg = viewport.getSelectionGroup()
2086 .getSequences(viewport.getHiddenRepSequences());
2094 List<SequenceI> invertGroup = new ArrayList<>();
2096 for (SequenceI seq : viewport.getAlignment().getSequences())
2098 if (!sg.contains(seq))
2100 invertGroup.add(seq);
2104 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
2106 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
2107 for (int i = 0; i < invertGroup.size(); i++)
2109 seqs2[i] = invertGroup.get(i);
2112 SlideSequencesCommand ssc;
2115 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
2116 viewport.getGapCharacter());
2120 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
2121 viewport.getGapCharacter());
2124 int groupAdjustment = 0;
2125 if (ssc.getGapsInsertedBegin() && right)
2127 if (viewport.cursorMode)
2129 alignPanel.getSeqPanel().moveCursor(size, 0);
2133 groupAdjustment = size;
2136 else if (!ssc.getGapsInsertedBegin() && !right)
2138 if (viewport.cursorMode)
2140 alignPanel.getSeqPanel().moveCursor(-size, 0);
2144 groupAdjustment = -size;
2148 if (groupAdjustment != 0)
2150 viewport.getSelectionGroup().setStartRes(
2151 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
2152 viewport.getSelectionGroup().setEndRes(
2153 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
2157 * just extend the last slide command if compatible; but not if in
2158 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
2160 boolean appendHistoryItem = false;
2161 Deque<CommandI> historyList = viewport.getHistoryList();
2162 boolean inSplitFrame = getSplitViewContainer() != null;
2163 if (!inSplitFrame && historyList != null && historyList.size() > 0
2164 && historyList.peek() instanceof SlideSequencesCommand)
2166 appendHistoryItem = ssc.appendSlideCommand(
2167 (SlideSequencesCommand) historyList.peek());
2170 if (!appendHistoryItem)
2172 addHistoryItem(ssc);
2185 protected void copy_actionPerformed()
2187 if (viewport.getSelectionGroup() == null)
2191 // TODO: preserve the ordering of displayed alignment annotation in any
2192 // internal paste (particularly sequence associated annotation)
2193 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
2194 String[] omitHidden = null;
2196 if (viewport.hasHiddenColumns())
2198 omitHidden = viewport.getViewAsString(true);
2201 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
2202 seqs, omitHidden, null);
2204 StringSelection ss = new StringSelection(output);
2208 jalview.gui.Desktop.internalCopy = true;
2209 // Its really worth setting the clipboard contents
2210 // to empty before setting the large StringSelection!!
2211 Toolkit.getDefaultToolkit().getSystemClipboard()
2212 .setContents(new StringSelection(""), null);
2214 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
2216 } catch (OutOfMemoryError er)
2218 new OOMWarning("copying region", er);
2222 HiddenColumns hiddenColumns = null;
2223 if (viewport.hasHiddenColumns())
2225 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
2226 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
2228 // create new HiddenColumns object with copy of hidden regions
2229 // between startRes and endRes, offset by startRes
2230 hiddenColumns = new HiddenColumns(
2231 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2232 hiddenCutoff, hiddenOffset);
2235 Desktop.jalviewClipboard = new Object[] { seqs,
2236 viewport.getAlignment().getDataset(), hiddenColumns };
2237 setStatus(MessageManager.formatMessage(
2238 "label.copied_sequences_to_clipboard", new Object[]
2239 { Integer.valueOf(seqs.length).toString() }));
2247 * @throws InterruptedException
2248 * @throws IOException
2251 protected void pasteNew_actionPerformed(ActionEvent e)
2252 throws IOException, InterruptedException
2262 * @throws InterruptedException
2263 * @throws IOException
2266 protected void pasteThis_actionPerformed(ActionEvent e)
2267 throws IOException, InterruptedException
2273 * Paste contents of Jalview clipboard
2275 * @param newAlignment
2276 * true to paste to a new alignment, otherwise add to this.
2277 * @throws InterruptedException
2278 * @throws IOException
2280 void paste(boolean newAlignment) throws IOException, InterruptedException
2282 boolean externalPaste = true;
2285 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2286 Transferable contents = c.getContents(this);
2288 if (contents == null)
2297 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2298 if (str.length() < 1)
2303 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2305 } catch (OutOfMemoryError er)
2307 new OOMWarning("Out of memory pasting sequences!!", er);
2311 SequenceI[] sequences;
2312 boolean annotationAdded = false;
2313 AlignmentI alignment = null;
2315 if (Desktop.jalviewClipboard != null)
2317 // The clipboard was filled from within Jalview, we must use the
2319 // And dataset from the copied alignment
2320 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2321 // be doubly sure that we create *new* sequence objects.
2322 sequences = new SequenceI[newseq.length];
2323 for (int i = 0; i < newseq.length; i++)
2325 sequences[i] = new Sequence(newseq[i]);
2327 alignment = new Alignment(sequences);
2328 externalPaste = false;
2332 // parse the clipboard as an alignment.
2333 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2335 sequences = alignment.getSequencesArray();
2339 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2345 if (Desktop.jalviewClipboard != null)
2347 // dataset is inherited
2348 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2352 // new dataset is constructed
2353 alignment.setDataset(null);
2355 alwidth = alignment.getWidth() + 1;
2359 AlignmentI pastedal = alignment; // preserve pasted alignment object
2360 // Add pasted sequences and dataset into existing alignment.
2361 alignment = viewport.getAlignment();
2362 alwidth = alignment.getWidth() + 1;
2363 // decide if we need to import sequences from an existing dataset
2364 boolean importDs = Desktop.jalviewClipboard != null
2365 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2366 // importDs==true instructs us to copy over new dataset sequences from
2367 // an existing alignment
2368 Vector<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
2370 // minimum dataset set
2372 for (int i = 0; i < sequences.length; i++)
2376 newDs.addElement(null);
2378 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2380 if (importDs && ds != null)
2382 if (!newDs.contains(ds))
2384 newDs.setElementAt(ds, i);
2385 ds = new Sequence(ds);
2386 // update with new dataset sequence
2387 sequences[i].setDatasetSequence(ds);
2391 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2396 // copy and derive new dataset sequence
2397 sequences[i] = sequences[i].deriveSequence();
2398 alignment.getDataset()
2399 .addSequence(sequences[i].getDatasetSequence());
2400 // TODO: avoid creation of duplicate dataset sequences with a
2401 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2403 alignment.addSequence(sequences[i]); // merges dataset
2407 newDs.clear(); // tidy up
2409 if (alignment.getAlignmentAnnotation() != null)
2411 for (AlignmentAnnotation alan : alignment
2412 .getAlignmentAnnotation())
2414 if (alan.graphGroup > fgroup)
2416 fgroup = alan.graphGroup;
2420 if (pastedal.getAlignmentAnnotation() != null)
2422 // Add any annotation attached to alignment.
2423 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2424 for (int i = 0; i < alann.length; i++)
2426 annotationAdded = true;
2427 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2429 AlignmentAnnotation newann = new AlignmentAnnotation(
2431 if (newann.graphGroup > -1)
2433 if (newGraphGroups.size() <= newann.graphGroup
2434 || newGraphGroups.get(newann.graphGroup) == null)
2436 for (int q = newGraphGroups
2437 .size(); q <= newann.graphGroup; q++)
2439 newGraphGroups.add(q, null);
2441 newGraphGroups.set(newann.graphGroup,
2442 Integer.valueOf(++fgroup));
2444 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2448 newann.padAnnotation(alwidth);
2449 alignment.addAnnotation(newann);
2459 addHistoryItem(new EditCommand(
2460 MessageManager.getString("label.add_sequences"),
2461 Action.PASTE, sequences, 0, alignment.getWidth(),
2464 // Add any annotations attached to sequences
2465 for (int i = 0; i < sequences.length; i++)
2467 if (sequences[i].getAnnotation() != null)
2469 AlignmentAnnotation newann;
2470 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2472 annotationAdded = true;
2473 newann = sequences[i].getAnnotation()[a];
2474 newann.adjustForAlignment();
2475 newann.padAnnotation(alwidth);
2476 if (newann.graphGroup > -1)
2478 if (newann.graphGroup > -1)
2480 if (newGraphGroups.size() <= newann.graphGroup
2481 || newGraphGroups.get(newann.graphGroup) == null)
2483 for (int q = newGraphGroups
2484 .size(); q <= newann.graphGroup; q++)
2486 newGraphGroups.add(q, null);
2488 newGraphGroups.set(newann.graphGroup,
2489 Integer.valueOf(++fgroup));
2491 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2495 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2499 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2507 // propagate alignment changed.
2508 viewport.getRanges().setEndSeq(alignment.getHeight() - 1);
2509 if (annotationAdded)
2511 // Duplicate sequence annotation in all views.
2512 AlignmentI[] alview = this.getViewAlignments();
2513 for (int i = 0; i < sequences.length; i++)
2515 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2520 for (int avnum = 0; avnum < alview.length; avnum++)
2522 if (alview[avnum] != alignment)
2524 // duplicate in a view other than the one with input focus
2525 int avwidth = alview[avnum].getWidth() + 1;
2526 // this relies on sann being preserved after we
2527 // modify the sequence's annotation array for each duplication
2528 for (int a = 0; a < sann.length; a++)
2530 AlignmentAnnotation newann = new AlignmentAnnotation(
2532 sequences[i].addAlignmentAnnotation(newann);
2533 newann.padAnnotation(avwidth);
2534 alview[avnum].addAnnotation(newann); // annotation was
2535 // duplicated earlier
2536 // TODO JAL-1145 graphGroups are not updated for sequence
2537 // annotation added to several views. This may cause
2539 alview[avnum].setAnnotationIndex(newann, a);
2544 buildSortByAnnotationScoresMenu();
2546 viewport.firePropertyChange("alignment", null,
2547 alignment.getSequences());
2548 if (alignPanels != null)
2550 for (AlignmentPanel ap : alignPanels)
2552 ap.validateAnnotationDimensions(false);
2557 alignPanel.validateAnnotationDimensions(false);
2563 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2565 String newtitle = new String("Copied sequences");
2567 if (Desktop.jalviewClipboard != null
2568 && Desktop.jalviewClipboard[2] != null)
2570 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2571 af.viewport.setHiddenColumns(hc);
2574 // >>>This is a fix for the moment, until a better solution is
2576 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2577 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2578 .getFeatureRenderer());
2580 // TODO: maintain provenance of an alignment, rather than just make the
2581 // title a concatenation of operations.
2584 if (title.startsWith("Copied sequences"))
2590 newtitle = newtitle.concat("- from " + title);
2595 newtitle = new String("Pasted sequences");
2598 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2603 } catch (Exception ex)
2605 ex.printStackTrace();
2606 System.out.println("Exception whilst pasting: " + ex);
2607 // could be anything being pasted in here
2612 protected void expand_newalign(ActionEvent e)
2616 AlignmentI alignment = AlignmentUtils
2617 .expandContext(getViewport().getAlignment(), -1);
2618 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2620 String newtitle = new String("Flanking alignment");
2622 if (Desktop.jalviewClipboard != null
2623 && Desktop.jalviewClipboard[2] != null)
2625 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2626 af.viewport.setHiddenColumns(hc);
2629 // >>>This is a fix for the moment, until a better solution is
2631 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2632 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2633 .getFeatureRenderer());
2635 // TODO: maintain provenance of an alignment, rather than just make the
2636 // title a concatenation of operations.
2638 if (title.startsWith("Copied sequences"))
2644 newtitle = newtitle.concat("- from " + title);
2648 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2650 } catch (Exception ex)
2652 ex.printStackTrace();
2653 System.out.println("Exception whilst pasting: " + ex);
2654 // could be anything being pasted in here
2655 } catch (OutOfMemoryError oom)
2657 new OOMWarning("Viewing flanking region of alignment", oom);
2662 * Action Cut (delete and copy) the selected region
2665 protected void cut_actionPerformed()
2667 copy_actionPerformed();
2668 delete_actionPerformed();
2672 * Performs menu option to Delete the currently selected region
2675 protected void delete_actionPerformed()
2678 SequenceGroup sg = viewport.getSelectionGroup();
2684 Runnable okAction = new Runnable()
2689 SequenceI[] cut = sg.getSequences()
2690 .toArray(new SequenceI[sg.getSize()]);
2692 addHistoryItem(new EditCommand(
2693 MessageManager.getString("label.cut_sequences"), Action.CUT,
2694 cut, sg.getStartRes(),
2695 sg.getEndRes() - sg.getStartRes() + 1,
2696 viewport.getAlignment()));
2698 viewport.setSelectionGroup(null);
2699 viewport.sendSelection();
2700 viewport.getAlignment().deleteGroup(sg);
2702 viewport.firePropertyChange("alignment", null,
2703 viewport.getAlignment().getSequences());
2704 if (viewport.getAlignment().getHeight() < 1)
2708 AlignFrame.this.setClosed(true);
2709 } catch (Exception ex)
2717 * If the cut affects all sequences, prompt for confirmation
2719 boolean wholeHeight = sg.getSize() == viewport.getAlignment()
2721 boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
2722 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2723 if (wholeHeight && wholeWidth)
2725 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
2726 dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
2727 Object[] options = new Object[] {
2728 MessageManager.getString("action.ok"),
2729 MessageManager.getString("action.cancel") };
2730 dialog.showDialog(MessageManager.getString("warn.delete_all"),
2731 MessageManager.getString("label.delete_all"),
2732 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
2733 options, options[0]);
2748 protected void deleteGroups_actionPerformed(ActionEvent e)
2750 if (avc.deleteGroups())
2752 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2753 alignPanel.updateAnnotation();
2754 alignPanel.paintAlignment(true, true);
2765 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2767 SequenceGroup sg = new SequenceGroup(
2768 viewport.getAlignment().getSequences());
2770 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2771 viewport.setSelectionGroup(sg);
2772 viewport.isSelectionGroupChanged(true);
2773 viewport.sendSelection();
2774 // JAL-2034 - should delegate to
2775 // alignPanel to decide if overview needs
2777 alignPanel.paintAlignment(false, false);
2778 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2788 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2790 if (viewport.cursorMode)
2792 alignPanel.getSeqPanel().keyboardNo1 = null;
2793 alignPanel.getSeqPanel().keyboardNo2 = null;
2795 viewport.setSelectionGroup(null);
2796 viewport.getColumnSelection().clear();
2797 viewport.setSelectionGroup(null);
2798 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2799 // JAL-2034 - should delegate to
2800 // alignPanel to decide if overview needs
2802 alignPanel.paintAlignment(false, false);
2803 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2804 viewport.sendSelection();
2814 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2816 SequenceGroup sg = viewport.getSelectionGroup();
2820 selectAllSequenceMenuItem_actionPerformed(null);
2825 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2827 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2829 // JAL-2034 - should delegate to
2830 // alignPanel to decide if overview needs
2833 alignPanel.paintAlignment(true, false);
2834 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2835 viewport.sendSelection();
2839 public void invertColSel_actionPerformed(ActionEvent e)
2841 viewport.invertColumnSelection();
2842 alignPanel.paintAlignment(true, false);
2843 viewport.sendSelection();
2853 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2855 trimAlignment(true);
2865 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2867 trimAlignment(false);
2870 void trimAlignment(boolean trimLeft)
2872 ColumnSelection colSel = viewport.getColumnSelection();
2875 if (!colSel.isEmpty())
2879 column = colSel.getMin();
2883 column = colSel.getMax();
2887 if (viewport.getSelectionGroup() != null)
2889 seqs = viewport.getSelectionGroup()
2890 .getSequencesAsArray(viewport.getHiddenRepSequences());
2894 seqs = viewport.getAlignment().getSequencesArray();
2897 TrimRegionCommand trimRegion;
2900 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2901 column, viewport.getAlignment());
2902 viewport.getRanges().setStartRes(0);
2906 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2907 column, viewport.getAlignment());
2910 setStatus(MessageManager
2911 .formatMessage("label.removed_columns", new String[]
2912 { Integer.valueOf(trimRegion.getSize()).toString() }));
2914 addHistoryItem(trimRegion);
2916 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2918 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2919 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2921 viewport.getAlignment().deleteGroup(sg);
2925 viewport.firePropertyChange("alignment", null,
2926 viewport.getAlignment().getSequences());
2937 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2939 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2942 if (viewport.getSelectionGroup() != null)
2944 seqs = viewport.getSelectionGroup()
2945 .getSequencesAsArray(viewport.getHiddenRepSequences());
2946 start = viewport.getSelectionGroup().getStartRes();
2947 end = viewport.getSelectionGroup().getEndRes();
2951 seqs = viewport.getAlignment().getSequencesArray();
2954 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2955 "Remove Gapped Columns", seqs, start, end,
2956 viewport.getAlignment());
2958 addHistoryItem(removeGapCols);
2960 setStatus(MessageManager
2961 .formatMessage("label.removed_empty_columns", new Object[]
2962 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2964 // This is to maintain viewport position on first residue
2965 // of first sequence
2966 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2967 ViewportRanges ranges = viewport.getRanges();
2968 int startRes = seq.findPosition(ranges.getStartRes());
2969 // ShiftList shifts;
2970 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2971 // edit.alColumnChanges=shifts.getInverse();
2972 // if (viewport.hasHiddenColumns)
2973 // viewport.getColumnSelection().compensateForEdits(shifts);
2974 ranges.setStartRes(seq.findIndex(startRes) - 1);
2975 viewport.firePropertyChange("alignment", null,
2976 viewport.getAlignment().getSequences());
2987 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2989 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2992 if (viewport.getSelectionGroup() != null)
2994 seqs = viewport.getSelectionGroup()
2995 .getSequencesAsArray(viewport.getHiddenRepSequences());
2996 start = viewport.getSelectionGroup().getStartRes();
2997 end = viewport.getSelectionGroup().getEndRes();
3001 seqs = viewport.getAlignment().getSequencesArray();
3004 // This is to maintain viewport position on first residue
3005 // of first sequence
3006 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
3007 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
3009 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
3010 viewport.getAlignment()));
3012 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
3014 viewport.firePropertyChange("alignment", null,
3015 viewport.getAlignment().getSequences());
3026 public void padGapsMenuitem_actionPerformed(ActionEvent e)
3028 viewport.setPadGaps(padGapsMenuitem.isSelected());
3029 viewport.firePropertyChange("alignment", null,
3030 viewport.getAlignment().getSequences());
3040 public void findMenuItem_actionPerformed(ActionEvent e)
3046 * Create a new view of the current alignment.
3049 public void newView_actionPerformed(ActionEvent e)
3051 newView(null, true);
3055 * Creates and shows a new view of the current alignment.
3058 * title of newly created view; if null, one will be generated
3059 * @param copyAnnotation
3060 * if true then duplicate all annnotation, groups and settings
3061 * @return new alignment panel, already displayed.
3063 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
3066 * Create a new AlignmentPanel (with its own, new Viewport)
3068 AlignmentPanel newap = new jalview.project.Jalview2XML()
3069 .copyAlignPanel(alignPanel);
3070 if (!copyAnnotation)
3073 * remove all groups and annotation except for the automatic stuff
3075 newap.av.getAlignment().deleteAllGroups();
3076 newap.av.getAlignment().deleteAllAnnotations(false);
3079 newap.av.setGatherViewsHere(false);
3081 if (viewport.getViewName() == null)
3083 viewport.setViewName(MessageManager
3084 .getString("label.view_name_original"));
3088 * Views share the same edits undo and redo stacks
3090 newap.av.setHistoryList(viewport.getHistoryList());
3091 newap.av.setRedoList(viewport.getRedoList());
3094 * copy any visualisation settings that are not saved in the project
3096 newap.av.setColourAppliesToAllGroups(
3097 viewport.getColourAppliesToAllGroups());
3100 * Views share the same mappings; need to deregister any new mappings
3101 * created by copyAlignPanel, and register the new reference to the shared
3104 newap.av.replaceMappings(viewport.getAlignment());
3107 * start up cDNA consensus (if applicable) now mappings are in place
3109 if (newap.av.initComplementConsensus())
3111 newap.refresh(true); // adjust layout of annotations
3114 newap.av.setViewName(getNewViewName(viewTitle));
3116 addAlignmentPanel(newap, true);
3117 newap.alignmentChanged();
3119 if (alignPanels.size() == 2)
3121 viewport.setGatherViewsHere(true);
3123 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
3128 * Make a new name for the view, ensuring it is unique within the current
3129 * sequenceSetId. (This used to be essential for Jalview Project archives, but
3130 * these now use viewId. Unique view names are still desirable for usability.)
3135 protected String getNewViewName(String viewTitle)
3137 int index = Desktop.getViewCount(viewport.getSequenceSetId());
3138 boolean addFirstIndex = false;
3139 if (viewTitle == null || viewTitle.trim().length() == 0)
3141 viewTitle = MessageManager.getString("action.view");
3142 addFirstIndex = true;
3146 index = 1;// we count from 1 if given a specific name
3148 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
3150 List<Component> comps = PaintRefresher.components
3151 .get(viewport.getSequenceSetId());
3153 List<String> existingNames = getExistingViewNames(comps);
3155 while (existingNames.contains(newViewName))
3157 newViewName = viewTitle + " " + (++index);
3163 * Returns a list of distinct view names found in the given list of
3164 * components. View names are held on the viewport of an AlignmentPanel.
3169 protected List<String> getExistingViewNames(List<Component> comps)
3171 List<String> existingNames = new ArrayList<>();
3172 for (Component comp : comps)
3174 if (comp instanceof AlignmentPanel)
3176 AlignmentPanel ap = (AlignmentPanel) comp;
3177 if (!existingNames.contains(ap.av.getViewName()))
3179 existingNames.add(ap.av.getViewName());
3183 return existingNames;
3187 * Explode tabbed views into separate windows.
3190 public void expandViews_actionPerformed(ActionEvent e)
3192 Desktop.explodeViews(this);
3196 * Gather views in separate windows back into a tabbed presentation.
3199 public void gatherViews_actionPerformed(ActionEvent e)
3201 Desktop.instance.gatherViews(this);
3211 public void font_actionPerformed(ActionEvent e)
3213 new FontChooser(alignPanel);
3223 protected void seqLimit_actionPerformed(ActionEvent e)
3225 viewport.setShowJVSuffix(seqLimits.isSelected());
3227 alignPanel.getIdPanel().getIdCanvas()
3228 .setPreferredSize(alignPanel.calculateIdWidth());
3229 alignPanel.paintAlignment(true, false);
3233 public void idRightAlign_actionPerformed(ActionEvent e)
3235 viewport.setRightAlignIds(idRightAlign.isSelected());
3236 alignPanel.paintAlignment(false, false);
3240 public void centreColumnLabels_actionPerformed(ActionEvent e)
3242 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3243 alignPanel.paintAlignment(false, false);
3249 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3252 protected void followHighlight_actionPerformed()
3255 * Set the 'follow' flag on the Viewport (and scroll to position if now
3258 final boolean state = this.followHighlightMenuItem.getState();
3259 viewport.setFollowHighlight(state);
3262 alignPanel.scrollToPosition(viewport.getSearchResults());
3273 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3275 viewport.setColourText(colourTextMenuItem.isSelected());
3276 alignPanel.paintAlignment(false, false);
3286 public void wrapMenuItem_actionPerformed(ActionEvent e)
3288 scaleAbove.setVisible(wrapMenuItem.isSelected());
3289 scaleLeft.setVisible(wrapMenuItem.isSelected());
3290 scaleRight.setVisible(wrapMenuItem.isSelected());
3291 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3292 alignPanel.updateLayout();
3296 public void showAllSeqs_actionPerformed(ActionEvent e)
3298 viewport.showAllHiddenSeqs();
3302 public void showAllColumns_actionPerformed(ActionEvent e)
3304 viewport.showAllHiddenColumns();
3305 alignPanel.paintAlignment(true, true);
3306 viewport.sendSelection();
3310 public void hideSelSequences_actionPerformed(ActionEvent e)
3312 viewport.hideAllSelectedSeqs();
3316 * called by key handler and the hide all/show all menu items
3321 protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3324 boolean hide = false;
3325 SequenceGroup sg = viewport.getSelectionGroup();
3326 if (!toggleSeqs && !toggleCols)
3328 // Hide everything by the current selection - this is a hack - we do the
3329 // invert and then hide
3330 // first check that there will be visible columns after the invert.
3331 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3332 && sg.getStartRes() <= sg.getEndRes()))
3334 // now invert the sequence set, if required - empty selection implies
3335 // that no hiding is required.
3338 invertSequenceMenuItem_actionPerformed(null);
3339 sg = viewport.getSelectionGroup();
3343 viewport.expandColSelection(sg, true);
3344 // finally invert the column selection and get the new sequence
3346 invertColSel_actionPerformed(null);
3353 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3355 hideSelSequences_actionPerformed(null);
3358 else if (!(toggleCols && viewport.hasSelectedColumns()))
3360 showAllSeqs_actionPerformed(null);
3366 if (viewport.hasSelectedColumns())
3368 hideSelColumns_actionPerformed(null);
3371 viewport.setSelectionGroup(sg);
3376 showAllColumns_actionPerformed(null);
3385 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3386 * event.ActionEvent)
3389 public void hideAllButSelection_actionPerformed(ActionEvent e)
3391 toggleHiddenRegions(false, false);
3392 viewport.sendSelection();
3399 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3403 public void hideAllSelection_actionPerformed(ActionEvent e)
3405 SequenceGroup sg = viewport.getSelectionGroup();
3406 viewport.expandColSelection(sg, false);
3407 viewport.hideAllSelectedSeqs();
3408 viewport.hideSelectedColumns();
3409 alignPanel.updateLayout();
3410 alignPanel.paintAlignment(true, true);
3411 viewport.sendSelection();
3418 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3422 public void showAllhidden_actionPerformed(ActionEvent e)
3424 viewport.showAllHiddenColumns();
3425 viewport.showAllHiddenSeqs();
3426 alignPanel.paintAlignment(true, true);
3427 viewport.sendSelection();
3431 public void hideSelColumns_actionPerformed(ActionEvent e)
3433 viewport.hideSelectedColumns();
3434 alignPanel.updateLayout();
3435 alignPanel.paintAlignment(true, true);
3436 viewport.sendSelection();
3440 public void hiddenMarkers_actionPerformed(ActionEvent e)
3442 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3453 protected void scaleAbove_actionPerformed(ActionEvent e)
3455 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3456 alignPanel.updateLayout();
3457 alignPanel.paintAlignment(true, false);
3467 protected void scaleLeft_actionPerformed(ActionEvent e)
3469 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3470 alignPanel.updateLayout();
3471 alignPanel.paintAlignment(true, false);
3481 protected void scaleRight_actionPerformed(ActionEvent e)
3483 viewport.setScaleRightWrapped(scaleRight.isSelected());
3484 alignPanel.updateLayout();
3485 alignPanel.paintAlignment(true, false);
3495 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3497 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3498 alignPanel.paintAlignment(false, false);
3508 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3510 viewport.setShowText(viewTextMenuItem.isSelected());
3511 alignPanel.paintAlignment(false, false);
3521 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3523 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3524 alignPanel.paintAlignment(false, false);
3527 public FeatureSettings featureSettings;
3530 public FeatureSettingsControllerI getFeatureSettingsUI()
3532 return featureSettings;
3536 public void featureSettings_actionPerformed(ActionEvent e)
3538 showFeatureSettingsUI();
3542 public FeatureSettingsControllerI showFeatureSettingsUI()
3544 if (featureSettings != null)
3546 featureSettings.closeOldSettings();
3547 featureSettings = null;
3549 if (!showSeqFeatures.isSelected())
3551 // make sure features are actually displayed
3552 showSeqFeatures.setSelected(true);
3553 showSeqFeatures_actionPerformed(null);
3555 featureSettings = new FeatureSettings(this);
3556 return featureSettings;
3560 * Set or clear 'Show Sequence Features'
3566 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3568 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3569 alignPanel.paintAlignment(true, true);
3573 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3574 * the annotations panel as a whole.
3576 * The options to show/hide all annotations should be enabled when the panel
3577 * is shown, and disabled when the panel is hidden.
3582 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3584 final boolean setVisible = annotationPanelMenuItem.isSelected();
3585 viewport.setShowAnnotation(setVisible);
3586 this.showAllSeqAnnotations.setEnabled(setVisible);
3587 this.hideAllSeqAnnotations.setEnabled(setVisible);
3588 this.showAllAlAnnotations.setEnabled(setVisible);
3589 this.hideAllAlAnnotations.setEnabled(setVisible);
3590 alignPanel.updateLayout();
3594 public void alignmentProperties()
3597 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3600 String content = MessageManager.formatMessage("label.html_content",
3602 { contents.toString() });
3605 if (Platform.isJS())
3607 JLabel textLabel = new JLabel();
3608 textLabel.setText(content);
3609 textLabel.setBackground(Color.WHITE);
3611 pane = new JPanel(new BorderLayout());
3612 ((JPanel) pane).setOpaque(true);
3613 pane.setBackground(Color.WHITE);
3614 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
3623 JEditorPane editPane = new JEditorPane("text/html", "");
3624 editPane.setEditable(false);
3625 editPane.setText(content);
3629 JInternalFrame frame = new JInternalFrame();
3631 frame.getContentPane().add(new JScrollPane(pane));
3633 Desktop.addInternalFrame(frame, MessageManager
3634 .formatMessage("label.alignment_properties", new Object[]
3635 { getTitle() }), 500, 400);
3645 public void overviewMenuItem_actionPerformed(ActionEvent e)
3647 if (alignPanel.overviewPanel != null)
3652 JInternalFrame frame = new JInternalFrame();
3653 final OverviewPanel overview = new OverviewPanel(alignPanel);
3654 frame.setContentPane(overview);
3655 Desktop.addInternalFrame(frame, MessageManager
3656 .formatMessage("label.overview_params", new Object[]
3657 { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
3660 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3661 frame.addInternalFrameListener(
3662 new javax.swing.event.InternalFrameAdapter()
3665 public void internalFrameClosed(
3666 javax.swing.event.InternalFrameEvent evt)
3669 alignPanel.setOverviewPanel(null);
3672 if (getKeyListeners().length > 0)
3674 frame.addKeyListener(getKeyListeners()[0]);
3677 alignPanel.setOverviewPanel(overview);
3681 public void textColour_actionPerformed()
3683 new TextColourChooser().chooseColour(alignPanel, null);
3687 * public void covariationColour_actionPerformed() {
3689 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3693 public void annotationColour_actionPerformed()
3695 new AnnotationColourChooser(viewport, alignPanel);
3699 public void annotationColumn_actionPerformed(ActionEvent e)
3701 new AnnotationColumnChooser(viewport, alignPanel);
3705 * Action on the user checking or unchecking the option to apply the selected
3706 * colour scheme to all groups. If unchecked, groups may have their own
3707 * independent colour schemes.
3712 public void applyToAllGroups_actionPerformed(boolean selected)
3714 viewport.setColourAppliesToAllGroups(selected);
3718 * Action on user selecting a colour from the colour menu
3721 * the name (not the menu item label!) of the colour scheme
3724 public void changeColour_actionPerformed(String name)
3727 * 'User Defined' opens a panel to configure or load a
3728 * user-defined colour scheme
3730 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3732 new UserDefinedColours(alignPanel);
3737 * otherwise set the chosen colour scheme (or null for 'None')
3739 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3740 viewport, viewport.getAlignment(),
3741 viewport.getHiddenRepSequences());
3746 * Actions on setting or changing the alignment colour scheme
3751 public void changeColour(ColourSchemeI cs)
3753 // TODO: pull up to controller method
3754 ColourMenuHelper.setColourSelected(colourMenu, cs);
3756 viewport.setGlobalColourScheme(cs);
3758 alignPanel.paintAlignment(true, true);
3762 * Show the PID threshold slider panel
3765 protected void modifyPID_actionPerformed()
3767 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3768 alignPanel.getViewName());
3769 SliderPanel.showPIDSlider();
3773 * Show the Conservation slider panel
3776 protected void modifyConservation_actionPerformed()
3778 SliderPanel.setConservationSlider(alignPanel,
3779 viewport.getResidueShading(), alignPanel.getViewName());
3780 SliderPanel.showConservationSlider();
3784 * Action on selecting or deselecting (Colour) By Conservation
3787 public void conservationMenuItem_actionPerformed(boolean selected)
3789 modifyConservation.setEnabled(selected);
3790 viewport.setConservationSelected(selected);
3791 viewport.getResidueShading().setConservationApplied(selected);
3793 changeColour(viewport.getGlobalColourScheme());
3796 modifyConservation_actionPerformed();
3800 SliderPanel.hideConservationSlider();
3805 * Action on selecting or deselecting (Colour) Above PID Threshold
3808 public void abovePIDThreshold_actionPerformed(boolean selected)
3810 modifyPID.setEnabled(selected);
3811 viewport.setAbovePIDThreshold(selected);
3814 viewport.getResidueShading().setThreshold(0,
3815 viewport.isIgnoreGapsConsensus());
3818 changeColour(viewport.getGlobalColourScheme());
3821 modifyPID_actionPerformed();
3825 SliderPanel.hidePIDSlider();
3836 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3838 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3839 AlignmentSorter.sortByPID(viewport.getAlignment(),
3840 viewport.getAlignment().getSequenceAt(0));
3841 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3842 viewport.getAlignment()));
3843 alignPanel.paintAlignment(true, false);
3853 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3855 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3856 AlignmentSorter.sortByID(viewport.getAlignment());
3858 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3859 alignPanel.paintAlignment(true, false);
3869 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3871 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3872 AlignmentSorter.sortByLength(viewport.getAlignment());
3873 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3874 viewport.getAlignment()));
3875 alignPanel.paintAlignment(true, false);
3885 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3887 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3888 AlignmentSorter.sortByGroup(viewport.getAlignment());
3889 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3890 viewport.getAlignment()));
3892 alignPanel.paintAlignment(true, false);
3896 public void sortEValueMenuItem_actionPerformed(ActionEvent e)
3898 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3899 AlignmentSorter.sortByEValue(viewport.getAlignment());
3900 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3901 viewport.getAlignment()));
3902 alignPanel.paintAlignment(true, false);
3907 public void sortBitScoreMenuItem_actionPerformed(ActionEvent e)
3909 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3910 AlignmentSorter.sortByBitScore(viewport.getAlignment());
3911 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3912 viewport.getAlignment()));
3913 alignPanel.paintAlignment(true, false);
3924 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3926 new RedundancyPanel(alignPanel, this);
3936 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3938 if ((viewport.getSelectionGroup() == null)
3939 || (viewport.getSelectionGroup().getSize() < 2))
3941 JvOptionPane.showInternalMessageDialog(this,
3942 MessageManager.getString(
3943 "label.you_must_select_least_two_sequences"),
3944 MessageManager.getString("label.invalid_selection"),
3945 JvOptionPane.WARNING_MESSAGE);
3949 JInternalFrame frame = new JInternalFrame();
3950 frame.setContentPane(new PairwiseAlignPanel(viewport));
3951 Desktop.addInternalFrame(frame,
3952 MessageManager.getString("action.pairwise_alignment"), 600,
3958 public void autoCalculate_actionPerformed(ActionEvent e)
3960 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3961 if (viewport.autoCalculateConsensus)
3963 viewport.firePropertyChange("alignment", null,
3964 viewport.getAlignment().getSequences());
3969 public void sortByTreeOption_actionPerformed(ActionEvent e)
3971 viewport.sortByTree = sortByTree.isSelected();
3975 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3977 viewport.followSelection = listenToViewSelections.isSelected();
3981 * Constructs a tree panel and adds it to the desktop
3984 * tree type (NJ or AV)
3986 * name of score model used to compute the tree
3988 * parameters for the distance or similarity calculation
3990 void newTreePanel(String type, String modelName,
3991 SimilarityParamsI options)
3993 String frameTitle = "";
3996 boolean onSelection = false;
3997 if (viewport.getSelectionGroup() != null
3998 && viewport.getSelectionGroup().getSize() > 0)
4000 SequenceGroup sg = viewport.getSelectionGroup();
4002 /* Decide if the selection is a column region */
4003 for (SequenceI _s : sg.getSequences())
4005 if (_s.getLength() < sg.getEndRes())
4007 JvOptionPane.showMessageDialog(Desktop.desktop,
4008 MessageManager.getString(
4009 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4010 MessageManager.getString(
4011 "label.sequences_selection_not_aligned"),
4012 JvOptionPane.WARNING_MESSAGE);
4021 if (viewport.getAlignment().getHeight() < 2)
4027 tp = new TreePanel(alignPanel, type, modelName, options);
4028 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
4030 frameTitle += " from ";
4032 if (viewport.getViewName() != null)
4034 frameTitle += viewport.getViewName() + " of ";
4037 frameTitle += this.title;
4039 Desktop.addInternalFrame(tp, frameTitle, 600, 500);
4050 public void addSortByOrderMenuItem(String title,
4051 final AlignmentOrder order)
4053 final JMenuItem item = new JMenuItem(MessageManager
4054 .formatMessage("action.by_title_param", new Object[]
4057 item.addActionListener(new java.awt.event.ActionListener()
4060 public void actionPerformed(ActionEvent e)
4062 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4064 // TODO: JBPNote - have to map order entries to curent SequenceI
4066 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4068 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
4069 viewport.getAlignment()));
4071 alignPanel.paintAlignment(true, false);
4077 * Add a new sort by annotation score menu item
4080 * the menu to add the option to
4082 * the label used to retrieve scores for each sequence on the
4085 public void addSortByAnnotScoreMenuItem(JMenu sort,
4086 final String scoreLabel)
4088 final JMenuItem item = new JMenuItem(scoreLabel);
4090 item.addActionListener(new java.awt.event.ActionListener()
4093 public void actionPerformed(ActionEvent e)
4095 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4096 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4097 viewport.getAlignment());// ,viewport.getSelectionGroup());
4098 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4099 viewport.getAlignment()));
4100 alignPanel.paintAlignment(true, false);
4106 * last hash for alignment's annotation array - used to minimise cost of
4109 protected int _annotationScoreVectorHash;
4112 * search the alignment and rebuild the sort by annotation score submenu the
4113 * last alignment annotation vector hash is stored to minimize cost of
4114 * rebuilding in subsequence calls.
4118 public void buildSortByAnnotationScoresMenu()
4120 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4125 if (viewport.getAlignment().getAlignmentAnnotation()
4126 .hashCode() == _annotationScoreVectorHash)
4131 sortByAnnotScore.removeAll();
4132 Set<String> scoreSorts = new HashSet<>();
4133 for (SequenceI sqa : viewport.getAlignment().getSequences())
4135 AlignmentAnnotation[] anns = sqa.getAnnotation();
4136 for (int i = 0; anns != null && i < anns.length; i++)
4138 AlignmentAnnotation aa = anns[i];
4139 if (aa != null && aa.hasScore() && aa.sequenceRef != null)
4141 scoreSorts.add(aa.label);
4145 for (String label : scoreSorts)
4147 addSortByAnnotScoreMenuItem(sortByAnnotScore, label);
4149 sortByAnnotScore.setVisible(!scoreSorts.isEmpty());
4151 _annotationScoreVectorHash = viewport.getAlignment()
4152 .getAlignmentAnnotation().hashCode();
4156 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4157 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4158 * call. Listeners are added to remove the menu item when the treePanel is
4159 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4163 public void buildTreeSortMenu()
4165 sortByTreeMenu.removeAll();
4167 List<Component> comps = PaintRefresher.components
4168 .get(viewport.getSequenceSetId());
4169 List<TreePanel> treePanels = new ArrayList<>();
4170 for (Component comp : comps)
4172 if (comp instanceof TreePanel)
4174 treePanels.add((TreePanel) comp);
4178 if (treePanels.size() < 1)
4180 sortByTreeMenu.setVisible(false);
4184 sortByTreeMenu.setVisible(true);
4186 for (final TreePanel tp : treePanels)
4188 final JMenuItem item = new JMenuItem(tp.getTitle());
4189 item.addActionListener(new java.awt.event.ActionListener()
4192 public void actionPerformed(ActionEvent e)
4194 tp.sortByTree_actionPerformed();
4195 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4200 sortByTreeMenu.add(item);
4204 public boolean sortBy(AlignmentOrder alorder, String undoname)
4206 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4207 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4208 if (undoname != null)
4210 addHistoryItem(new OrderCommand(undoname, oldOrder,
4211 viewport.getAlignment()));
4213 alignPanel.paintAlignment(true, false);
4218 * Work out whether the whole set of sequences or just the selected set will
4219 * be submitted for multiple alignment.
4222 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4224 // Now, check we have enough sequences
4225 AlignmentView msa = null;
4227 if ((viewport.getSelectionGroup() != null)
4228 && (viewport.getSelectionGroup().getSize() > 1))
4230 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4231 // some common interface!
4233 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4234 * SequenceI[sz = seqs.getSize(false)];
4236 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4237 * seqs.getSequenceAt(i); }
4239 msa = viewport.getAlignmentView(true);
4241 else if (viewport.getSelectionGroup() != null
4242 && viewport.getSelectionGroup().getSize() == 1)
4244 int option = JvOptionPane.showConfirmDialog(this,
4245 MessageManager.getString("warn.oneseq_msainput_selection"),
4246 MessageManager.getString("label.invalid_selection"),
4247 JvOptionPane.OK_CANCEL_OPTION);
4248 if (option == JvOptionPane.OK_OPTION)
4250 msa = viewport.getAlignmentView(false);
4255 msa = viewport.getAlignmentView(false);
4261 * Decides what is submitted to a secondary structure prediction service: the
4262 * first sequence in the alignment, or in the current selection, or, if the
4263 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4264 * region or the whole alignment. (where the first sequence in the set is the
4265 * one that the prediction will be for).
4267 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4269 AlignmentView seqs = null;
4271 if ((viewport.getSelectionGroup() != null)
4272 && (viewport.getSelectionGroup().getSize() > 0))
4274 seqs = viewport.getAlignmentView(true);
4278 seqs = viewport.getAlignmentView(false);
4280 // limit sequences - JBPNote in future - could spawn multiple prediction
4282 // TODO: viewport.getAlignment().isAligned is a global state - the local
4283 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4284 if (!viewport.getAlignment().isAligned(false))
4286 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4287 // TODO: if seqs.getSequences().length>1 then should really have warned
4301 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4303 // Pick the tree file
4304 JalviewFileChooser chooser = new JalviewFileChooser(
4305 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4306 chooser.setFileView(new JalviewFileView());
4307 chooser.setDialogTitle(
4308 MessageManager.getString("label.select_newick_like_tree_file"));
4309 chooser.setToolTipText(
4310 MessageManager.getString("label.load_tree_file"));
4312 chooser.setResponseHandler(0, new Runnable()
4317 String filePath = chooser.getSelectedFile().getPath();
4318 Cache.setProperty("LAST_DIRECTORY", filePath);
4319 NewickFile fin = null;
4322 fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
4323 DataSourceType.FILE));
4324 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4325 } catch (Exception ex)
4327 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4329 .getString("label.problem_reading_tree_file"),
4330 JvOptionPane.WARNING_MESSAGE);
4331 ex.printStackTrace();
4333 if (fin != null && fin.hasWarningMessage())
4335 JvOptionPane.showMessageDialog(Desktop.desktop,
4336 fin.getWarningMessage(),
4337 MessageManager.getString(
4338 "label.possible_problem_with_tree_file"),
4339 JvOptionPane.WARNING_MESSAGE);
4343 chooser.showOpenDialog(this);
4346 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4348 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4351 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4352 int h, int x, int y)
4354 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4358 * Add a treeviewer for the tree extracted from a Newick file object to the
4359 * current alignment view
4366 * Associated alignment input data (or null)
4375 * @return TreePanel handle
4377 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4378 AlignmentView input, int w, int h, int x, int y)
4380 TreePanel tp = null;
4386 if (nf.getTree() != null)
4388 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4394 tp.setLocation(x, y);
4397 Desktop.addInternalFrame(tp, treeTitle, w, h);
4399 } catch (Exception ex)
4401 ex.printStackTrace();
4408 * Schedule the web services menu rebuild to the event dispatch thread.
4410 public void buildWebServicesMenu()
4412 SwingUtilities.invokeLater(() -> {
4413 Cache.log.info("Rebuiling WS menu");
4414 webService.removeAll();
4415 if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
4417 SlivkaWSDiscoverer discoverer = SlivkaWSDiscoverer.getInstance();
4418 JMenu submenu = new JMenu("Slivka");
4419 buildWebServicesMenu(discoverer, submenu);
4420 webService.add(submenu);
4422 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4424 WSDiscovererI jws2servs = Jws2Discoverer.getDiscoverer();
4425 JMenu submenu = new JMenu("JABAWS");
4426 buildLegacyWebServicesMenu(submenu);
4427 buildWebServicesMenu(jws2servs, submenu);
4428 webService.add(submenu);
4433 private void buildLegacyWebServicesMenu(JMenu menu)
4435 JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
4436 if (Discoverer.services != null && Discoverer.services.size() > 0)
4438 var secstrpred = Discoverer.services.get("SecStrPred");
4439 if (secstrpred != null)
4441 for (ext.vamsas.ServiceHandle sh : secstrpred)
4443 var menuProvider = Discoverer.getServiceClient(sh);
4444 menuProvider.attachWSMenuEntry(secstrmenu, this);
4448 menu.add(secstrmenu);
4452 * Constructs the web services menu for the given discoverer under the
4453 * specified menu. This method must be called on the EDT
4456 * the discoverer used to build the menu
4458 * parent component which the elements will be attached to
4460 private void buildWebServicesMenu(WSDiscovererI discoverer, JMenu menu)
4462 if (discoverer.hasServices())
4464 PreferredServiceRegistry.getRegistry().populateWSMenuEntry(
4465 discoverer.getServices(), sv -> buildWebServicesMenu(), menu,
4468 if (discoverer.isRunning())
4470 JMenuItem item = new JMenuItem("Service discovery in progress.");
4471 item.setEnabled(false);
4474 else if (!discoverer.hasServices())
4476 JMenuItem item = new JMenuItem("No services available.");
4477 item.setEnabled(false);
4483 * construct any groupURL type service menu entries.
4487 protected void build_urlServiceMenu(JMenu webService)
4489 // TODO: remove this code when 2.7 is released
4490 // DEBUG - alignmentView
4492 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4493 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4495 * @Override public void actionPerformed(ActionEvent e) {
4496 * jalview.datamodel.AlignmentView
4497 * .testSelectionViews(af.viewport.getAlignment(),
4498 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4500 * }); webService.add(testAlView);
4502 // TODO: refactor to RestClient discoverer and merge menu entries for
4503 // rest-style services with other types of analysis/calculation service
4504 // SHmmr test client - still being implemented.
4505 // DEBUG - alignmentView
4507 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4510 client.attachWSMenuEntry(
4511 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4517 * Searches the alignment sequences for xRefs and builds the Show
4518 * Cross-References menu (formerly called Show Products), with database
4519 * sources for which cross-references are found (protein sources for a
4520 * nucleotide alignment and vice versa)
4522 * @return true if Show Cross-references menu should be enabled
4524 public boolean canShowProducts()
4526 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4527 AlignmentI dataset = viewport.getAlignment().getDataset();
4529 showProducts.removeAll();
4530 final boolean dna = viewport.getAlignment().isNucleotide();
4532 if (seqs == null || seqs.length == 0)
4534 // nothing to see here.
4538 boolean showp = false;
4541 List<String> ptypes = new CrossRef(seqs, dataset)
4542 .findXrefSourcesForSequences(dna);
4544 for (final String source : ptypes)
4547 final AlignFrame af = this;
4548 JMenuItem xtype = new JMenuItem(source);
4549 xtype.addActionListener(new ActionListener()
4552 public void actionPerformed(ActionEvent e)
4554 showProductsFor(af.viewport.getSequenceSelection(), dna,
4558 showProducts.add(xtype);
4560 showProducts.setVisible(showp);
4561 showProducts.setEnabled(showp);
4562 } catch (Exception e)
4565 "canShowProducts threw an exception - please report to help@jalview.org",
4573 * Finds and displays cross-references for the selected sequences (protein
4574 * products for nucleotide sequences, dna coding sequences for peptides).
4577 * the sequences to show cross-references for
4579 * true if from a nucleotide alignment (so showing proteins)
4581 * the database to show cross-references for
4583 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4584 final String source)
4586 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4591 * Construct and display a new frame containing the translation of this
4592 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4595 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4597 AlignmentI al = null;
4600 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4602 al = dna.translateCdna(codeTable);
4603 } catch (Exception ex)
4605 jalview.bin.Cache.log.error(
4606 "Exception during translation. Please report this !", ex);
4607 final String msg = MessageManager.getString(
4608 "label.error_when_translating_sequences_submit_bug_report");
4609 final String errorTitle = MessageManager
4610 .getString("label.implementation_error")
4611 + MessageManager.getString("label.translation_failed");
4612 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4613 JvOptionPane.ERROR_MESSAGE);
4616 if (al == null || al.getHeight() == 0)
4618 final String msg = MessageManager.getString(
4619 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4620 final String errorTitle = MessageManager
4621 .getString("label.translation_failed");
4622 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4623 JvOptionPane.WARNING_MESSAGE);
4627 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4628 af.setFileFormat(this.currentFileFormat);
4629 final String newTitle = MessageManager
4630 .formatMessage("label.translation_of_params", new Object[]
4631 { this.getTitle(), codeTable.getId() });
4632 af.setTitle(newTitle);
4633 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4635 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4636 viewport.openSplitFrame(af, new Alignment(seqs));
4640 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4647 * Set the file format
4651 public void setFileFormat(FileFormatI format)
4653 this.currentFileFormat = format;
4657 * Try to load a features file onto the alignment.
4660 * contents or path to retrieve file or a File object
4662 * access mode of file (see jalview.io.AlignFile)
4663 * @return true if features file was parsed correctly.
4665 public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
4668 return avc.parseFeaturesFile(file, sourceType,
4669 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4674 public void refreshFeatureUI(boolean enableIfNecessary)
4676 // note - currently this is only still here rather than in the controller
4677 // because of the featureSettings hard reference that is yet to be
4679 if (enableIfNecessary)
4681 viewport.setShowSequenceFeatures(true);
4682 showSeqFeatures.setSelected(true);
4688 public void dragEnter(DropTargetDragEvent evt)
4693 public void dragExit(DropTargetEvent evt)
4698 public void dragOver(DropTargetDragEvent evt)
4703 public void dropActionChanged(DropTargetDragEvent evt)
4708 public void drop(DropTargetDropEvent evt)
4710 // JAL-1552 - acceptDrop required before getTransferable call for
4711 // Java's Transferable for native dnd
4712 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4713 Transferable t = evt.getTransferable();
4715 final AlignFrame thisaf = this;
4716 final List<Object> files = new ArrayList<>();
4717 List<DataSourceType> protocols = new ArrayList<>();
4721 Desktop.transferFromDropTarget(files, protocols, evt, t);
4722 } catch (Exception e)
4724 e.printStackTrace();
4728 new Thread(new Runnable()
4735 // check to see if any of these files have names matching sequences
4738 SequenceIdMatcher idm = new SequenceIdMatcher(
4739 viewport.getAlignment().getSequencesArray());
4741 * Object[] { String,SequenceI}
4743 ArrayList<Object[]> filesmatched = new ArrayList<>();
4744 ArrayList<Object> filesnotmatched = new ArrayList<>();
4745 for (int i = 0; i < files.size(); i++)
4748 Object file = files.get(i);
4749 String fileName = file.toString();
4751 DataSourceType protocol = (file instanceof File
4752 ? DataSourceType.FILE
4753 : FormatAdapter.checkProtocol(fileName));
4754 if (protocol == DataSourceType.FILE)
4757 if (file instanceof File)
4760 Platform.cacheFileData(fl);
4764 fl = new File(fileName);
4766 pdbfn = fl.getName();
4768 else if (protocol == DataSourceType.URL)
4770 URL url = new URL(fileName);
4771 pdbfn = url.getFile();
4773 if (pdbfn.length() > 0)
4775 // attempt to find a match in the alignment
4776 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4777 int l = 0, c = pdbfn.indexOf(".");
4778 while (mtch == null && c != -1)
4783 } while ((c = pdbfn.indexOf(".", l)) > l);
4786 pdbfn = pdbfn.substring(0, l);
4788 mtch = idm.findAllIdMatches(pdbfn);
4795 type = new IdentifyFile().identify(file, protocol);
4796 } catch (Exception ex)
4800 if (type != null && type.isStructureFile())
4802 filesmatched.add(new Object[] { file, protocol, mtch });
4806 // File wasn't named like one of the sequences or wasn't a PDB
4808 filesnotmatched.add(file);
4812 if (filesmatched.size() > 0)
4814 boolean autoAssociate = Cache
4815 .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
4818 String msg = MessageManager.formatMessage(
4819 "label.automatically_associate_structure_files_with_sequences_same_name",
4821 { Integer.valueOf(filesmatched.size())
4823 String ttl = MessageManager.getString(
4824 "label.automatically_associate_structure_files_by_name");
4825 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4826 ttl, JvOptionPane.YES_NO_OPTION);
4827 autoAssociate = choice == JvOptionPane.YES_OPTION;
4831 for (Object[] fm : filesmatched)
4833 // try and associate
4834 // TODO: may want to set a standard ID naming formalism for
4835 // associating PDB files which have no IDs.
4836 for (SequenceI toassoc : (SequenceI[]) fm[2])
4838 PDBEntry pe = new AssociatePdbFileWithSeq()
4839 .associatePdbWithSeq(fm[0].toString(),
4840 (DataSourceType) fm[1], toassoc, false,
4844 System.err.println("Associated file : "
4845 + (fm[0].toString()) + " with "
4846 + toassoc.getDisplayId(true));
4850 // TODO: do we need to update overview ? only if features are
4852 alignPanel.paintAlignment(true, false);
4858 * add declined structures as sequences
4860 for (Object[] o : filesmatched)
4862 filesnotmatched.add(o[0]);
4866 if (filesnotmatched.size() > 0)
4868 if (assocfiles > 0 && (Cache.getDefault(
4869 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4870 || JvOptionPane.showConfirmDialog(thisaf,
4871 "<html>" + MessageManager.formatMessage(
4872 "label.ignore_unmatched_dropped_files_info",
4875 filesnotmatched.size())
4878 MessageManager.getString(
4879 "label.ignore_unmatched_dropped_files"),
4880 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4884 for (Object fn : filesnotmatched)
4886 loadJalviewDataFile(fn, null, null, null);
4890 } catch (Exception ex)
4892 ex.printStackTrace();
4900 * Attempt to load a "dropped" file or URL string, by testing in turn for
4902 * <li>an Annotation file</li>
4903 * <li>a JNet file</li>
4904 * <li>a features file</li>
4905 * <li>else try to interpret as an alignment file</li>
4909 * either a filename or a URL string.
4910 * @throws InterruptedException
4911 * @throws IOException
4913 public void loadJalviewDataFile(Object file, DataSourceType sourceType,
4914 FileFormatI format, SequenceI assocSeq)
4916 // BH 2018 was String file
4919 if (sourceType == null)
4921 sourceType = FormatAdapter.checkProtocol(file);
4923 // if the file isn't identified, or not positively identified as some
4924 // other filetype (PFAM is default unidentified alignment file type) then
4925 // try to parse as annotation.
4926 boolean isAnnotation = (format == null
4927 || FileFormat.Pfam.equals(format))
4928 ? new AnnotationFile().annotateAlignmentView(viewport,
4934 // first see if its a T-COFFEE score file
4935 TCoffeeScoreFile tcf = null;
4938 tcf = new TCoffeeScoreFile(file, sourceType);
4941 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4945 new TCoffeeColourScheme(viewport.getAlignment()));
4946 isAnnotation = true;
4947 setStatus(MessageManager.getString(
4948 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4952 // some problem - if no warning its probable that the ID matching
4953 // process didn't work
4954 JvOptionPane.showMessageDialog(Desktop.desktop,
4955 tcf.getWarningMessage() == null
4956 ? MessageManager.getString(
4957 "label.check_file_matches_sequence_ids_alignment")
4958 : tcf.getWarningMessage(),
4959 MessageManager.getString(
4960 "label.problem_reading_tcoffee_score_file"),
4961 JvOptionPane.WARNING_MESSAGE);
4968 } catch (Exception x)
4971 "Exception when processing data source as T-COFFEE score file",
4977 // try to see if its a JNet 'concise' style annotation file *before*
4979 // try to parse it as a features file
4982 format = new IdentifyFile().identify(file, sourceType);
4984 if (FileFormat.ScoreMatrix == format)
4986 ScoreMatrixFile sm = new ScoreMatrixFile(
4987 new FileParse(file, sourceType));
4989 // todo: i18n this message
4990 setStatus(MessageManager.formatMessage(
4991 "label.successfully_loaded_matrix",
4992 sm.getMatrixName()));
4994 else if (FileFormat.Jnet.equals(format))
4996 JPredFile predictions = new JPredFile(file, sourceType);
4997 new JnetAnnotationMaker();
4998 JnetAnnotationMaker.add_annotation(predictions,
4999 viewport.getAlignment(), 0, false);
5000 viewport.getAlignment().setupJPredAlignment();
5001 isAnnotation = true;
5003 // else if (IdentifyFile.FeaturesFile.equals(format))
5004 else if (FileFormat.Features.equals(format))
5006 if (parseFeaturesFile(file, sourceType))
5008 SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
5009 if (splitFrame != null)
5011 splitFrame.repaint();
5015 alignPanel.paintAlignment(true, true);
5021 new FileLoader().LoadFile(viewport, file, sourceType, format);
5027 alignPanel.adjustAnnotationHeight();
5028 viewport.updateSequenceIdColours();
5029 buildSortByAnnotationScoresMenu();
5030 alignPanel.paintAlignment(true, true);
5032 } catch (Exception ex)
5034 ex.printStackTrace();
5035 } catch (OutOfMemoryError oom)
5040 } catch (Exception x)
5045 + (sourceType != null
5046 ? (sourceType == DataSourceType.PASTE
5048 : "using " + sourceType + " from "
5052 ? "(parsing as '" + format + "' file)"
5054 oom, Desktop.desktop);
5059 * Method invoked by the ChangeListener on the tabbed pane, in other words
5060 * when a different tabbed pane is selected by the user or programmatically.
5063 public void tabSelectionChanged(int index)
5067 alignPanel = alignPanels.get(index);
5068 viewport = alignPanel.av;
5069 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5070 setMenusFromViewport(viewport);
5071 if (featureSettings != null && featureSettings.isOpen()
5072 && featureSettings.fr.getViewport() != viewport)
5074 if (viewport.isShowSequenceFeatures())
5076 // refresh the featureSettings to reflect UI change
5077 showFeatureSettingsUI();
5081 // close feature settings for this view.
5082 featureSettings.close();
5089 * 'focus' any colour slider that is open to the selected viewport
5091 if (viewport.getConservationSelected())
5093 SliderPanel.setConservationSlider(alignPanel,
5094 viewport.getResidueShading(), alignPanel.getViewName());
5098 SliderPanel.hideConservationSlider();
5100 if (viewport.getAbovePIDThreshold())
5102 SliderPanel.setPIDSliderSource(alignPanel,
5103 viewport.getResidueShading(), alignPanel.getViewName());
5107 SliderPanel.hidePIDSlider();
5111 * If there is a frame linked to this one in a SplitPane, switch it to the
5112 * same view tab index. No infinite recursion of calls should happen, since
5113 * tabSelectionChanged() should not get invoked on setting the selected
5114 * index to an unchanged value. Guard against setting an invalid index
5115 * before the new view peer tab has been created.
5117 final AlignViewportI peer = viewport.getCodingComplement();
5120 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5121 .getAlignPanel().alignFrame;
5122 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5124 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5130 * On right mouse click on view tab, prompt for and set new view name.
5133 public void tabbedPane_mousePressed(MouseEvent e)
5135 if (e.isPopupTrigger())
5137 String msg = MessageManager.getString("label.enter_view_name");
5138 String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
5139 String reply = JvOptionPane.showInputDialog(msg, ttl);
5143 viewport.setViewName(reply);
5144 // TODO warn if reply is in getExistingViewNames()?
5145 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5150 public AlignViewport getCurrentView()
5156 * Open the dialog for regex description parsing.
5159 protected void extractScores_actionPerformed(ActionEvent e)
5161 ParseProperties pp = new jalview.analysis.ParseProperties(
5162 viewport.getAlignment());
5163 // TODO: verify regex and introduce GUI dialog for version 2.5
5164 // if (pp.getScoresFromDescription("col", "score column ",
5165 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5167 if (pp.getScoresFromDescription("description column",
5168 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5170 buildSortByAnnotationScoresMenu();
5178 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5182 protected void showDbRefs_actionPerformed(ActionEvent e)
5184 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5190 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5194 protected void showNpFeats_actionPerformed(ActionEvent e)
5196 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5200 * find the viewport amongst the tabs in this alignment frame and close that
5205 public boolean closeView(AlignViewportI av)
5209 this.closeMenuItem_actionPerformed(false);
5212 Component[] comp = tabbedPane.getComponents();
5213 for (int i = 0; comp != null && i < comp.length; i++)
5215 if (comp[i] instanceof AlignmentPanel)
5217 if (((AlignmentPanel) comp[i]).av == av)
5220 closeView((AlignmentPanel) comp[i]);
5228 protected void build_fetchdbmenu(JMenu webService)
5230 // Temporary hack - DBRef Fetcher always top level ws entry.
5231 // TODO We probably want to store a sequence database checklist in
5232 // preferences and have checkboxes.. rather than individual sources selected
5234 final JMenu rfetch = new JMenu(
5235 MessageManager.getString("action.fetch_db_references"));
5236 rfetch.setToolTipText(MessageManager.getString(
5237 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5238 webService.add(rfetch);
5240 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5241 MessageManager.getString("option.trim_retrieved_seqs"));
5242 trimrs.setToolTipText(
5243 MessageManager.getString("label.trim_retrieved_sequences"));
5245 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5246 trimrs.addActionListener(new ActionListener()
5249 public void actionPerformed(ActionEvent e)
5251 trimrs.setSelected(trimrs.isSelected());
5252 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5253 Boolean.valueOf(trimrs.isSelected()).toString());
5257 JMenuItem fetchr = new JMenuItem(
5258 MessageManager.getString("label.standard_databases"));
5259 fetchr.setToolTipText(
5260 MessageManager.getString("label.fetch_embl_uniprot"));
5261 fetchr.addActionListener(new ActionListener()
5265 public void actionPerformed(ActionEvent e)
5267 new Thread(new Runnable()
5272 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5273 .getAlignment().isNucleotide();
5274 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5275 alignPanel.av.getSequenceSelection(),
5276 alignPanel.alignFrame, null,
5277 alignPanel.alignFrame.featureSettings, isNucleotide);
5278 dbRefFetcher.addListener(new FetchFinishedListenerI()
5281 public void finished()
5284 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5285 .getFeatureSettingsModels())
5288 alignPanel.av.mergeFeaturesStyle(srcSettings);
5290 AlignFrame.this.setMenusForViewport();
5293 dbRefFetcher.fetchDBRefs(false);
5301 new Thread(new Runnable()
5306 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5307 .getSequenceFetcherSingleton();
5308 javax.swing.SwingUtilities.invokeLater(new Runnable()
5313 String[] dbclasses = sf.getNonAlignmentSources();
5314 List<DbSourceProxy> otherdb;
5315 JMenu dfetch = new JMenu();
5316 JMenu ifetch = new JMenu();
5317 JMenuItem fetchr = null;
5318 int comp = 0, icomp = 0, mcomp = 15;
5319 String mname = null;
5321 for (String dbclass : dbclasses)
5323 otherdb = sf.getSourceProxy(dbclass);
5324 // add a single entry for this class, or submenu allowing 'fetch
5326 if (otherdb == null || otherdb.size() < 1)
5332 mname = "From " + dbclass;
5334 if (otherdb.size() == 1)
5336 final DbSourceProxy[] dassource = otherdb
5337 .toArray(new DbSourceProxy[0]);
5338 DbSourceProxy src = otherdb.get(0);
5339 fetchr = new JMenuItem(src.getDbSource());
5340 fetchr.addActionListener(new ActionListener()
5344 public void actionPerformed(ActionEvent e)
5346 new Thread(new Runnable()
5352 boolean isNucleotide = alignPanel.alignFrame
5353 .getViewport().getAlignment()
5355 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5356 alignPanel.av.getSequenceSelection(),
5357 alignPanel.alignFrame, dassource,
5358 alignPanel.alignFrame.featureSettings,
5361 .addListener(new FetchFinishedListenerI()
5364 public void finished()
5366 FeatureSettingsModelI srcSettings = dassource[0]
5367 .getFeatureColourScheme();
5368 alignPanel.av.mergeFeaturesStyle(
5370 AlignFrame.this.setMenusForViewport();
5373 dbRefFetcher.fetchDBRefs(false);
5379 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5380 MessageManager.formatMessage(
5381 "label.fetch_retrieve_from", new Object[]
5382 { src.getDbName() })));
5388 final DbSourceProxy[] dassource = otherdb
5389 .toArray(new DbSourceProxy[0]);
5391 DbSourceProxy src = otherdb.get(0);
5392 fetchr = new JMenuItem(MessageManager
5393 .formatMessage("label.fetch_all_param", new Object[]
5394 { src.getDbSource() }));
5395 fetchr.addActionListener(new ActionListener()
5398 public void actionPerformed(ActionEvent e)
5400 new Thread(new Runnable()
5406 boolean isNucleotide = alignPanel.alignFrame
5407 .getViewport().getAlignment()
5409 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5410 alignPanel.av.getSequenceSelection(),
5411 alignPanel.alignFrame, dassource,
5412 alignPanel.alignFrame.featureSettings,
5415 .addListener(new FetchFinishedListenerI()
5418 public void finished()
5420 AlignFrame.this.setMenusForViewport();
5423 dbRefFetcher.fetchDBRefs(false);
5429 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5430 MessageManager.formatMessage(
5431 "label.fetch_retrieve_from_all_sources",
5433 { Integer.valueOf(otherdb.size())
5435 src.getDbSource(), src.getDbName() })));
5438 // and then build the rest of the individual menus
5439 ifetch = new JMenu(MessageManager.formatMessage(
5440 "label.source_from_db_source", new Object[]
5441 { src.getDbSource() }));
5443 String imname = null;
5445 for (DbSourceProxy sproxy : otherdb)
5447 String dbname = sproxy.getDbName();
5448 String sname = dbname.length() > 5
5449 ? dbname.substring(0, 5) + "..."
5451 String msname = dbname.length() > 10
5452 ? dbname.substring(0, 10) + "..."
5456 imname = MessageManager
5457 .formatMessage("label.from_msname", new Object[]
5460 fetchr = new JMenuItem(msname);
5461 final DbSourceProxy[] dassrc = { sproxy };
5462 fetchr.addActionListener(new ActionListener()
5466 public void actionPerformed(ActionEvent e)
5468 new Thread(new Runnable()
5474 boolean isNucleotide = alignPanel.alignFrame
5475 .getViewport().getAlignment()
5477 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5478 alignPanel.av.getSequenceSelection(),
5479 alignPanel.alignFrame, dassrc,
5480 alignPanel.alignFrame.featureSettings,
5483 .addListener(new FetchFinishedListenerI()
5486 public void finished()
5488 AlignFrame.this.setMenusForViewport();
5491 dbRefFetcher.fetchDBRefs(false);
5497 fetchr.setToolTipText(
5498 "<html>" + MessageManager.formatMessage(
5499 "label.fetch_retrieve_from", new Object[]
5503 if (++icomp >= mcomp || i == (otherdb.size()))
5505 ifetch.setText(MessageManager.formatMessage(
5506 "label.source_to_target", imname, sname));
5508 ifetch = new JMenu();
5516 if (comp >= mcomp || dbi >= (dbclasses.length))
5518 dfetch.setText(MessageManager.formatMessage(
5519 "label.source_to_target", mname, dbclass));
5521 dfetch = new JMenu();
5534 * Left justify the whole alignment.
5537 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5539 AlignmentI al = viewport.getAlignment();
5541 viewport.firePropertyChange("alignment", null, al);
5545 * Right justify the whole alignment.
5548 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5550 AlignmentI al = viewport.getAlignment();
5552 viewport.firePropertyChange("alignment", null, al);
5556 public void setShowSeqFeatures(boolean b)
5558 showSeqFeatures.setSelected(b);
5559 viewport.setShowSequenceFeatures(b);
5566 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5567 * awt.event.ActionEvent)
5570 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5572 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5573 alignPanel.paintAlignment(false, false);
5580 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5584 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5586 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5587 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5595 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5596 * .event.ActionEvent)
5599 protected void showGroupConservation_actionPerformed(ActionEvent e)
5601 viewport.setShowGroupConservation(showGroupConservation.getState());
5602 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5609 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5610 * .event.ActionEvent)
5613 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5615 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5616 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5623 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5624 * .event.ActionEvent)
5627 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5629 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5630 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5634 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5636 showSequenceLogo.setState(true);
5637 viewport.setShowSequenceLogo(true);
5638 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5639 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5643 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5645 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5652 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5653 * .event.ActionEvent)
5656 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5658 if (avc.makeGroupsFromSelection())
5660 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5661 alignPanel.updateAnnotation();
5662 alignPanel.paintAlignment(true,
5663 viewport.needToUpdateStructureViews());
5667 public void clearAlignmentSeqRep()
5669 // TODO refactor alignmentseqrep to controller
5670 if (viewport.getAlignment().hasSeqrep())
5672 viewport.getAlignment().setSeqrep(null);
5673 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5674 alignPanel.updateAnnotation();
5675 alignPanel.paintAlignment(true, true);
5680 protected void createGroup_actionPerformed(ActionEvent e)
5682 if (avc.createGroup())
5684 if (applyAutoAnnotationSettings.isSelected())
5686 alignPanel.updateAnnotation(true, false);
5688 alignPanel.alignmentChanged();
5693 protected void unGroup_actionPerformed(ActionEvent e)
5697 alignPanel.alignmentChanged();
5702 * make the given alignmentPanel the currently selected tab
5704 * @param alignmentPanel
5706 public void setDisplayedView(AlignmentPanel alignmentPanel)
5708 if (!viewport.getSequenceSetId()
5709 .equals(alignmentPanel.av.getSequenceSetId()))
5711 throw new Error(MessageManager.getString(
5712 "error.implementation_error_cannot_show_view_alignment_frame"));
5714 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5715 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5717 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5722 * Action on selection of menu options to Show or Hide annotations.
5725 * @param forSequences
5726 * update sequence-related annotations
5727 * @param forAlignment
5728 * update non-sequence-related annotations
5731 protected void setAnnotationsVisibility(boolean visible,
5732 boolean forSequences, boolean forAlignment)
5734 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5735 .getAlignmentAnnotation();
5740 for (AlignmentAnnotation aa : anns)
5743 * don't display non-positional annotations on an alignment
5745 if (aa.annotations == null)
5749 boolean apply = (aa.sequenceRef == null && forAlignment)
5750 || (aa.sequenceRef != null && forSequences);
5753 aa.visible = visible;
5756 alignPanel.validateAnnotationDimensions(true);
5757 alignPanel.alignmentChanged();
5761 * Store selected annotation sort order for the view and repaint.
5764 protected void sortAnnotations_actionPerformed()
5766 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5768 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5769 alignPanel.paintAlignment(false, false);
5774 * @return alignment panels in this alignment frame
5776 public List<? extends AlignmentViewPanel> getAlignPanels()
5778 // alignPanels is never null
5779 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5784 * Open a new alignment window, with the cDNA associated with this (protein)
5785 * alignment, aligned as is the protein.
5787 protected void viewAsCdna_actionPerformed()
5789 // TODO no longer a menu action - refactor as required
5790 final AlignmentI alignment = getViewport().getAlignment();
5791 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5792 if (mappings == null)
5796 List<SequenceI> cdnaSeqs = new ArrayList<>();
5797 for (SequenceI aaSeq : alignment.getSequences())
5799 for (AlignedCodonFrame acf : mappings)
5801 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5805 * There is a cDNA mapping for this protein sequence - add to new
5806 * alignment. It will share the same dataset sequence as other mapped
5807 * cDNA (no new mappings need to be created).
5809 final Sequence newSeq = new Sequence(dnaSeq);
5810 newSeq.setDatasetSequence(dnaSeq);
5811 cdnaSeqs.add(newSeq);
5815 if (cdnaSeqs.size() == 0)
5817 // show a warning dialog no mapped cDNA
5820 AlignmentI cdna = new Alignment(
5821 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5822 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5823 AlignFrame.DEFAULT_HEIGHT);
5824 cdna.alignAs(alignment);
5825 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5827 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5828 AlignFrame.DEFAULT_HEIGHT);
5832 * Set visibility of dna/protein complement view (available when shown in a
5838 protected void showComplement_actionPerformed(boolean show)
5840 SplitContainerI sf = getSplitViewContainer();
5843 sf.setComplementVisible(this, show);
5848 * Generate the reverse (optionally complemented) of the selected sequences,
5849 * and add them to the alignment
5852 protected void showReverse_actionPerformed(boolean complement)
5854 AlignmentI al = null;
5857 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5858 al = dna.reverseCdna(complement);
5859 viewport.addAlignment(al, "");
5860 addHistoryItem(new EditCommand(
5861 MessageManager.getString("label.add_sequences"), Action.PASTE,
5862 al.getSequencesArray(), 0, al.getWidth(),
5863 viewport.getAlignment()));
5864 } catch (Exception ex)
5866 System.err.println(ex.getMessage());
5872 * Try to run a script in the Groovy console, having first ensured that this
5873 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5874 * be targeted at this alignment.
5877 protected void runGroovy_actionPerformed()
5879 Jalview.setCurrentAlignFrame(this);
5880 groovy.ui.Console console = Desktop.getGroovyConsole();
5881 if (console != null)
5885 console.runScript();
5886 } catch (Exception ex)
5888 System.err.println((ex.toString()));
5889 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
5890 MessageManager.getString("label.couldnt_run_groovy_script"),
5891 MessageManager.getString("label.groovy_support_failed"),
5892 JvOptionPane.ERROR_MESSAGE);
5897 System.err.println("Can't run Groovy script as console not found");
5902 * Hides columns containing (or not containing) a specified feature, provided
5903 * that would not leave all columns hidden
5905 * @param featureType
5906 * @param columnsContaining
5909 public boolean hideFeatureColumns(String featureType,
5910 boolean columnsContaining)
5912 boolean notForHiding = avc.markColumnsContainingFeatures(
5913 columnsContaining, false, false, featureType);
5916 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5917 false, featureType))
5919 getViewport().hideSelectedColumns();
5927 protected void selectHighlightedColumns_actionPerformed(
5928 ActionEvent actionEvent)
5930 // include key modifier check in case user selects from menu
5931 avc.markHighlightedColumns(
5932 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5933 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5934 | ActionEvent.CTRL_MASK)) != 0);
5938 * Rebuilds the Colour menu, including any user-defined colours which have
5939 * been loaded either on startup or during the session
5941 public void buildColourMenu()
5943 colourMenu.removeAll();
5945 colourMenu.add(applyToAllGroups);
5946 colourMenu.add(textColour);
5947 colourMenu.addSeparator();
5949 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
5950 viewport.getAlignment(), false);
5952 colourMenu.add(annotationColour);
5953 bg.add(annotationColour);
5954 colourMenu.addSeparator();
5955 colourMenu.add(conservationMenuItem);
5956 colourMenu.add(modifyConservation);
5957 colourMenu.add(abovePIDThreshold);
5958 colourMenu.add(modifyPID);
5960 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5961 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5965 * Open a dialog (if not already open) that allows the user to select and
5966 * calculate PCA or Tree analysis
5968 protected void openTreePcaDialog()
5970 if (alignPanel.getCalculationDialog() == null)
5972 new CalculationChooser(AlignFrame.this);
5977 * Sets the status of the HMMER menu
5979 public void updateHMMERStatus()
5981 hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
5985 protected void loadVcf_actionPerformed()
5987 JalviewFileChooser chooser = new JalviewFileChooser(
5988 Cache.getProperty("LAST_DIRECTORY"));
5989 chooser.setFileView(new JalviewFileView());
5990 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5991 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5992 final AlignFrame us = this;
5993 chooser.setResponseHandler(0, new Runnable()
5998 String choice = chooser.getSelectedFile().getPath();
5999 Cache.setProperty("LAST_DIRECTORY", choice);
6000 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
6001 new VCFLoader(choice).loadVCF(seqs, us);
6004 chooser.showOpenDialog(null);
6008 private Rectangle lastFeatureSettingsBounds = null;
6011 public void setFeatureSettingsGeometry(Rectangle bounds)
6013 lastFeatureSettingsBounds = bounds;
6017 public Rectangle getFeatureSettingsGeometry()
6019 return lastFeatureSettingsBounds;
6023 class PrintThread extends Thread
6027 public PrintThread(AlignmentPanel ap)
6032 static PageFormat pf;
6037 PrinterJob printJob = PrinterJob.getPrinterJob();
6041 printJob.setPrintable(ap, pf);
6045 printJob.setPrintable(ap);
6048 if (printJob.printDialog())
6053 } catch (Exception PrintException)
6055 PrintException.printStackTrace();