2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.GeneticCodeI;
28 import jalview.analysis.ParseProperties;
29 import jalview.analysis.SequenceIdMatcher;
30 import jalview.api.AlignExportSettingI;
31 import jalview.api.AlignViewControllerGuiI;
32 import jalview.api.AlignViewControllerI;
33 import jalview.api.AlignViewportI;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.api.FeatureSettingsControllerI;
36 import jalview.api.FeatureSettingsModelI;
37 import jalview.api.SplitContainerI;
38 import jalview.api.ViewStyleI;
39 import jalview.api.analysis.SimilarityParamsI;
40 import jalview.bin.Cache;
41 import jalview.bin.Jalview;
42 import jalview.commands.CommandI;
43 import jalview.commands.EditCommand;
44 import jalview.commands.EditCommand.Action;
45 import jalview.commands.OrderCommand;
46 import jalview.commands.RemoveGapColCommand;
47 import jalview.commands.RemoveGapsCommand;
48 import jalview.commands.SlideSequencesCommand;
49 import jalview.commands.TrimRegionCommand;
50 import jalview.datamodel.AlignedCodonFrame;
51 import jalview.datamodel.Alignment;
52 import jalview.datamodel.AlignmentAnnotation;
53 import jalview.datamodel.AlignmentExportData;
54 import jalview.datamodel.AlignmentI;
55 import jalview.datamodel.AlignmentOrder;
56 import jalview.datamodel.AlignmentView;
57 import jalview.datamodel.ColumnSelection;
58 import jalview.datamodel.HiddenColumns;
59 import jalview.datamodel.HiddenSequences;
60 import jalview.datamodel.PDBEntry;
61 import jalview.datamodel.SeqCigar;
62 import jalview.datamodel.Sequence;
63 import jalview.datamodel.SequenceGroup;
64 import jalview.datamodel.SequenceI;
65 import jalview.gui.ColourMenuHelper.ColourChangeListener;
66 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
67 import jalview.hmmer.HMMAlign;
68 import jalview.hmmer.HMMBuild;
69 import jalview.hmmer.HMMERParamStore;
70 import jalview.hmmer.HMMERPreset;
71 import jalview.hmmer.HMMSearch;
72 import jalview.hmmer.HmmerCommand;
73 import jalview.hmmer.JackHMMER;
74 import jalview.io.AlignmentProperties;
75 import jalview.io.AnnotationFile;
76 import jalview.io.BackupFiles;
77 import jalview.io.BioJsHTMLOutput;
78 import jalview.io.DataSourceType;
79 import jalview.io.FileFormat;
80 import jalview.io.FileFormatI;
81 import jalview.io.FileFormats;
82 import jalview.io.FileLoader;
83 import jalview.io.FileParse;
84 import jalview.io.FormatAdapter;
85 import jalview.io.HtmlSvgOutput;
86 import jalview.io.IdentifyFile;
87 import jalview.io.JPredFile;
88 import jalview.io.JalviewFileChooser;
89 import jalview.io.JalviewFileView;
90 import jalview.io.JnetAnnotationMaker;
91 import jalview.io.NewickFile;
92 import jalview.io.ScoreMatrixFile;
93 import jalview.io.TCoffeeScoreFile;
94 import jalview.io.vcf.VCFLoader;
95 import jalview.jbgui.GAlignFrame;
96 import jalview.schemes.ColourSchemeI;
97 import jalview.schemes.ColourSchemes;
98 import jalview.schemes.ResidueColourScheme;
99 import jalview.schemes.TCoffeeColourScheme;
100 import jalview.util.MessageManager;
101 import jalview.viewmodel.AlignmentViewport;
102 import jalview.viewmodel.ViewportRanges;
103 import jalview.ws.DBRefFetcher;
104 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
105 import jalview.ws.api.ServiceWithParameters;
106 import jalview.ws.jws1.Discoverer;
107 import jalview.ws.jws2.Jws2Discoverer;
108 import jalview.ws.params.ArgumentI;
109 import jalview.ws.params.ParamDatastoreI;
110 import jalview.ws.params.WsParamSetI;
111 import jalview.ws.seqfetcher.DbSourceProxy;
112 import jalview.ws.slivkaws.SlivkaWSDiscoverer;
114 import java.awt.BorderLayout;
115 import java.awt.Component;
116 import java.awt.Rectangle;
117 import java.awt.Toolkit;
118 import java.awt.datatransfer.Clipboard;
119 import java.awt.datatransfer.DataFlavor;
120 import java.awt.datatransfer.StringSelection;
121 import java.awt.datatransfer.Transferable;
122 import java.awt.dnd.DnDConstants;
123 import java.awt.dnd.DropTargetDragEvent;
124 import java.awt.dnd.DropTargetDropEvent;
125 import java.awt.dnd.DropTargetEvent;
126 import java.awt.dnd.DropTargetListener;
127 import java.awt.event.ActionEvent;
128 import java.awt.event.ActionListener;
129 import java.awt.event.FocusAdapter;
130 import java.awt.event.FocusEvent;
131 import java.awt.event.ItemEvent;
132 import java.awt.event.ItemListener;
133 import java.awt.event.KeyAdapter;
134 import java.awt.event.KeyEvent;
135 import java.awt.event.MouseEvent;
136 import java.awt.print.PageFormat;
137 import java.awt.print.PrinterJob;
138 import java.beans.PropertyChangeEvent;
140 import java.io.FileWriter;
141 import java.io.IOException;
142 import java.io.PrintWriter;
144 import java.util.ArrayList;
145 import java.util.Arrays;
146 import java.util.Deque;
147 import java.util.HashSet;
148 import java.util.List;
149 import java.util.Set;
150 import java.util.Vector;
152 import javax.swing.ButtonGroup;
153 import javax.swing.JCheckBoxMenuItem;
154 import javax.swing.JEditorPane;
155 import javax.swing.JFileChooser;
156 import javax.swing.JInternalFrame;
157 import javax.swing.JLayeredPane;
158 import javax.swing.JMenu;
159 import javax.swing.JMenuItem;
160 import javax.swing.JOptionPane;
161 import javax.swing.JScrollPane;
162 import javax.swing.SwingUtilities;
168 * @version $Revision$
170 public class AlignFrame extends GAlignFrame implements DropTargetListener,
171 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
173 public static final int DEFAULT_WIDTH = 700;
175 public static final int DEFAULT_HEIGHT = 500;
178 * The currently displayed panel (selected tabbed view if more than one)
180 public AlignmentPanel alignPanel;
182 AlignViewport viewport;
184 public AlignViewControllerI avc;
186 List<AlignmentPanel> alignPanels = new ArrayList<>();
189 * Last format used to load or save alignments in this window
191 FileFormatI currentFileFormat = null;
194 * Current filename for this alignment
196 String fileName = null;
200 * Creates a new AlignFrame object with specific width and height.
206 public AlignFrame(AlignmentI al, int width, int height)
208 this(al, null, width, height);
212 * Creates a new AlignFrame object with specific width, height and
218 * @param sequenceSetId
220 public AlignFrame(AlignmentI al, int width, int height,
221 String sequenceSetId)
223 this(al, null, width, height, sequenceSetId);
227 * Creates a new AlignFrame object with specific width, height and
233 * @param sequenceSetId
236 public AlignFrame(AlignmentI al, int width, int height,
237 String sequenceSetId, String viewId)
239 this(al, null, width, height, sequenceSetId, viewId);
243 * new alignment window with hidden columns
247 * @param hiddenColumns
248 * ColumnSelection or null
250 * Width of alignment frame
254 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
257 this(al, hiddenColumns, width, height, null);
261 * Create alignment frame for al with hiddenColumns, a specific width and
262 * height, and specific sequenceId
265 * @param hiddenColumns
268 * @param sequenceSetId
271 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
272 int height, String sequenceSetId)
274 this(al, hiddenColumns, width, height, sequenceSetId, null);
278 * Create alignment frame for al with hiddenColumns, a specific width and
279 * height, and specific sequenceId
282 * @param hiddenColumns
285 * @param sequenceSetId
290 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
291 int height, String sequenceSetId, String viewId)
293 setSize(width, height);
295 if (al.getDataset() == null)
300 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
302 alignPanel = new AlignmentPanel(this, viewport);
304 addAlignmentPanel(alignPanel, true);
308 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
309 HiddenColumns hiddenColumns, int width, int height)
311 setSize(width, height);
313 if (al.getDataset() == null)
318 viewport = new AlignViewport(al, hiddenColumns);
320 if (hiddenSeqs != null && hiddenSeqs.length > 0)
322 viewport.hideSequence(hiddenSeqs);
324 alignPanel = new AlignmentPanel(this, viewport);
325 addAlignmentPanel(alignPanel, true);
330 * Make a new AlignFrame from existing alignmentPanels
337 public AlignFrame(AlignmentPanel ap)
341 addAlignmentPanel(ap, false);
346 * initalise the alignframe from the underlying viewport data and the
351 if (!Jalview.isHeadlessMode())
353 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
356 avc = new jalview.controller.AlignViewController(this, viewport,
358 if (viewport.getAlignmentConservationAnnotation() == null)
360 // BLOSUM62Colour.setEnabled(false);
361 conservationMenuItem.setEnabled(false);
362 modifyConservation.setEnabled(false);
363 // PIDColour.setEnabled(false);
364 // abovePIDThreshold.setEnabled(false);
365 // modifyPID.setEnabled(false);
368 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
371 if (sortby.equals("Id"))
373 sortIDMenuItem_actionPerformed(null);
375 else if (sortby.equals("Pairwise Identity"))
377 sortPairwiseMenuItem_actionPerformed(null);
381 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
383 setMenusFromViewport(viewport);
384 buildSortByAnnotationScoresMenu();
385 calculateTree.addActionListener(new ActionListener()
389 public void actionPerformed(ActionEvent e)
396 if (Desktop.desktop != null)
398 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
399 addServiceListeners();
403 if (viewport.getWrapAlignment())
405 wrapMenuItem_actionPerformed(null);
408 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
410 this.overviewMenuItem_actionPerformed(null);
415 final List<AlignmentPanel> selviews = new ArrayList<>();
416 final List<AlignmentPanel> origview = new ArrayList<>();
417 final String menuLabel = MessageManager
418 .getString("label.copy_format_from");
419 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
420 new ViewSetProvider()
424 public AlignmentPanel[] getAllAlignmentPanels()
427 origview.add(alignPanel);
428 // make an array of all alignment panels except for this one
429 List<AlignmentPanel> aps = new ArrayList<>(
430 Arrays.asList(Desktop.getAlignmentPanels(null)));
431 aps.remove(AlignFrame.this.alignPanel);
432 return aps.toArray(new AlignmentPanel[aps.size()]);
434 }, selviews, new ItemListener()
438 public void itemStateChanged(ItemEvent e)
440 if (origview.size() > 0)
442 final AlignmentPanel ap = origview.get(0);
445 * Copy the ViewStyle of the selected panel to 'this one'.
446 * Don't change value of 'scaleProteinAsCdna' unless copying
449 ViewStyleI vs = selviews.get(0).getAlignViewport()
451 boolean fromSplitFrame = selviews.get(0)
452 .getAlignViewport().getCodingComplement() != null;
455 vs.setScaleProteinAsCdna(ap.getAlignViewport()
456 .getViewStyle().isScaleProteinAsCdna());
458 ap.getAlignViewport().setViewStyle(vs);
461 * Also rescale ViewStyle of SplitFrame complement if there is
462 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
463 * the whole ViewStyle (allow cDNA protein to have different
466 AlignViewportI complement = ap.getAlignViewport()
467 .getCodingComplement();
468 if (complement != null && vs.isScaleProteinAsCdna())
470 AlignFrame af = Desktop.getAlignFrameFor(complement);
471 ((SplitFrame) af.getSplitViewContainer())
473 af.setMenusForViewport();
477 ap.setSelected(true);
478 ap.alignFrame.setMenusForViewport();
483 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
484 .indexOf("devel") > -1
485 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
486 .indexOf("test") > -1)
488 formatMenu.add(vsel);
490 addFocusListener(new FocusAdapter()
493 public void focusGained(FocusEvent e)
495 Jalview.setCurrentAlignFrame(AlignFrame.this);
502 * Change the filename and format for the alignment, and enable the 'reload'
503 * button functionality.
510 public void setFileName(String file, FileFormatI format)
513 setFileFormat(format);
514 reload.setEnabled(true);
518 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
521 void addKeyListener()
523 addKeyListener(new KeyAdapter()
526 public void keyPressed(KeyEvent evt)
528 if (viewport.cursorMode
529 && ((evt.getKeyCode() >= KeyEvent.VK_0
530 && evt.getKeyCode() <= KeyEvent.VK_9)
531 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
532 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
533 && Character.isDigit(evt.getKeyChar()))
535 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
538 switch (evt.getKeyCode())
541 case 27: // escape key
542 deselectAllSequenceMenuItem_actionPerformed(null);
546 case KeyEvent.VK_DOWN:
547 if (evt.isAltDown() || !viewport.cursorMode)
549 moveSelectedSequences(false);
551 if (viewport.cursorMode)
553 alignPanel.getSeqPanel().moveCursor(0, 1);
558 if (evt.isAltDown() || !viewport.cursorMode)
560 moveSelectedSequences(true);
562 if (viewport.cursorMode)
564 alignPanel.getSeqPanel().moveCursor(0, -1);
569 case KeyEvent.VK_LEFT:
570 if (evt.isAltDown() || !viewport.cursorMode)
572 slideSequences(false,
573 alignPanel.getSeqPanel().getKeyboardNo1());
577 alignPanel.getSeqPanel().moveCursor(-1, 0);
582 case KeyEvent.VK_RIGHT:
583 if (evt.isAltDown() || !viewport.cursorMode)
585 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
589 alignPanel.getSeqPanel().moveCursor(1, 0);
593 case KeyEvent.VK_SPACE:
594 if (viewport.cursorMode)
596 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
597 || evt.isShiftDown() || evt.isAltDown());
601 // case KeyEvent.VK_A:
602 // if (viewport.cursorMode)
604 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
605 // //System.out.println("A");
609 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
610 * System.out.println("closing bracket"); } break;
612 case KeyEvent.VK_DELETE:
613 case KeyEvent.VK_BACK_SPACE:
614 if (!viewport.cursorMode)
616 cut_actionPerformed(null);
620 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
621 || evt.isShiftDown() || evt.isAltDown());
627 if (viewport.cursorMode)
629 alignPanel.getSeqPanel().setCursorRow();
633 if (viewport.cursorMode && !evt.isControlDown())
635 alignPanel.getSeqPanel().setCursorColumn();
639 if (viewport.cursorMode)
641 alignPanel.getSeqPanel().setCursorPosition();
645 case KeyEvent.VK_ENTER:
646 case KeyEvent.VK_COMMA:
647 if (viewport.cursorMode)
649 alignPanel.getSeqPanel().setCursorRowAndColumn();
654 if (viewport.cursorMode)
656 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
660 if (viewport.cursorMode)
662 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
667 viewport.cursorMode = !viewport.cursorMode;
668 statusBar.setText(MessageManager
669 .formatMessage("label.keyboard_editing_mode", new String[]
670 { (viewport.cursorMode ? "on" : "off") }));
671 if (viewport.cursorMode)
673 ViewportRanges ranges = viewport.getRanges();
674 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
676 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
679 alignPanel.getSeqPanel().seqCanvas.repaint();
685 Help.showHelpWindow();
686 } catch (Exception ex)
688 ex.printStackTrace();
693 boolean toggleSeqs = !evt.isControlDown();
694 boolean toggleCols = !evt.isShiftDown();
695 toggleHiddenRegions(toggleSeqs, toggleCols);
700 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
701 boolean modifyExisting = true; // always modify, don't clear
702 // evt.isShiftDown();
703 boolean invertHighlighted = evt.isAltDown();
704 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
708 case KeyEvent.VK_PAGE_UP:
709 viewport.getRanges().pageUp();
711 case KeyEvent.VK_PAGE_DOWN:
712 viewport.getRanges().pageDown();
718 public void keyReleased(KeyEvent evt)
720 switch (evt.getKeyCode())
722 case KeyEvent.VK_LEFT:
723 if (evt.isAltDown() || !viewport.cursorMode)
725 viewport.firePropertyChange("alignment", null,
726 viewport.getAlignment().getSequences());
730 case KeyEvent.VK_RIGHT:
731 if (evt.isAltDown() || !viewport.cursorMode)
733 viewport.firePropertyChange("alignment", null,
734 viewport.getAlignment().getSequences());
742 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
744 ap.alignFrame = this;
745 avc = new jalview.controller.AlignViewController(this, viewport,
750 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
752 int aSize = alignPanels.size();
754 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
756 if (aSize == 1 && ap.av.getViewName() == null)
758 this.getContentPane().add(ap, BorderLayout.CENTER);
764 setInitialTabVisible();
767 expandViews.setEnabled(true);
768 gatherViews.setEnabled(true);
769 tabbedPane.addTab(ap.av.getViewName(), ap);
771 ap.setVisible(false);
776 if (ap.av.isPadGaps())
778 ap.av.getAlignment().padGaps();
780 ap.av.updateConservation(ap);
781 ap.av.updateConsensus(ap);
782 ap.av.updateStrucConsensus(ap);
783 ap.av.initInformationWorker(ap);
787 public void setInitialTabVisible()
789 expandViews.setEnabled(true);
790 gatherViews.setEnabled(true);
791 tabbedPane.setVisible(true);
792 AlignmentPanel first = alignPanels.get(0);
793 tabbedPane.addTab(first.av.getViewName(), first);
794 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
797 public AlignViewport getViewport()
802 /* Set up intrinsic listeners for dynamically generated GUI bits. */
803 private void addServiceListeners()
805 final java.beans.PropertyChangeListener thisListener;
806 Desktop.instance.addJalviewPropertyChangeListener("services",
807 thisListener = new java.beans.PropertyChangeListener()
810 public void propertyChange(PropertyChangeEvent evt)
812 // // System.out.println("Discoverer property change.");
813 // if (evt.getPropertyName().equals("services"))
815 SwingUtilities.invokeLater(new Runnable()
822 "Rebuild WS Menu for service change");
823 BuildWebServiceMenu();
830 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
833 public void internalFrameClosed(
834 javax.swing.event.InternalFrameEvent evt)
836 // System.out.println("deregistering discoverer listener");
837 Desktop.instance.removeJalviewPropertyChangeListener("services",
839 closeMenuItem_actionPerformed(true);
842 // Finally, build the menu once to get current service state
843 new Thread(new Runnable()
848 BuildWebServiceMenu();
854 * Configure menu items that vary according to whether the alignment is
855 * nucleotide or protein
857 public void setGUINucleotide()
859 AlignmentI al = getViewport().getAlignment();
860 boolean nucleotide = al.isNucleotide();
862 loadVcf.setVisible(nucleotide);
863 showTranslation.setVisible(nucleotide);
864 showReverse.setVisible(nucleotide);
865 showReverseComplement.setVisible(nucleotide);
866 conservationMenuItem.setEnabled(!nucleotide);
868 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
869 showGroupConservation.setEnabled(!nucleotide);
871 showComplementMenuItem
872 .setText(nucleotide ? MessageManager.getString("label.protein")
873 : MessageManager.getString("label.nucleotide"));
877 * set up menus for the current viewport. This may be called after any
878 * operation that affects the data in the current view (selection changed,
879 * etc) to update the menus to reflect the new state.
882 public void setMenusForViewport()
884 setMenusFromViewport(viewport);
888 * Need to call this method when tabs are selected for multiple views, or when
889 * loading from Jalview2XML.java
894 public void setMenusFromViewport(AlignViewport av)
896 padGapsMenuitem.setSelected(av.isPadGaps());
897 colourTextMenuItem.setSelected(av.isShowColourText());
898 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
899 modifyPID.setEnabled(abovePIDThreshold.isSelected());
900 conservationMenuItem.setSelected(av.getConservationSelected());
901 modifyConservation.setEnabled(conservationMenuItem.isSelected());
902 seqLimits.setSelected(av.getShowJVSuffix());
903 idRightAlign.setSelected(av.isRightAlignIds());
904 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
905 renderGapsMenuItem.setSelected(av.isRenderGaps());
906 wrapMenuItem.setSelected(av.getWrapAlignment());
907 scaleAbove.setVisible(av.getWrapAlignment());
908 scaleLeft.setVisible(av.getWrapAlignment());
909 scaleRight.setVisible(av.getWrapAlignment());
910 annotationPanelMenuItem.setState(av.isShowAnnotation());
912 * Show/hide annotations only enabled if annotation panel is shown
914 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
915 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
916 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
917 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
918 viewBoxesMenuItem.setSelected(av.getShowBoxes());
919 viewTextMenuItem.setSelected(av.getShowText());
920 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
921 showGroupConsensus.setSelected(av.isShowGroupConsensus());
922 showGroupConservation.setSelected(av.isShowGroupConservation());
923 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
924 showSequenceLogo.setSelected(av.isShowSequenceLogo());
925 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
926 showInformationHistogram.setSelected(av.isShowInformationHistogram());
927 showHMMSequenceLogo.setSelected(av.isShowHMMSequenceLogo());
928 normaliseHMMSequenceLogo.setSelected(av.isNormaliseHMMSequenceLogo());
930 ColourMenuHelper.setColourSelected(colourMenu,
931 av.getGlobalColourScheme());
933 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
934 hiddenMarkers.setState(av.getShowHiddenMarkers());
935 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
936 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
937 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
938 autoCalculate.setSelected(av.autoCalculateConsensus);
939 sortByTree.setSelected(av.sortByTree);
940 listenToViewSelections.setSelected(av.followSelection);
942 showProducts.setEnabled(canShowProducts());
943 setGroovyEnabled(Desktop.getGroovyConsole() != null);
949 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
953 public void setGroovyEnabled(boolean b)
955 runGroovy.setEnabled(b);
958 private IProgressIndicator progressBar;
963 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
966 public void setProgressBar(String message, long id)
968 progressBar.setProgressBar(message, id);
972 public void registerHandler(final long id,
973 final IProgressIndicatorHandler handler)
975 progressBar.registerHandler(id, handler);
980 * @return true if any progress bars are still active
983 public boolean operationInProgress()
985 return progressBar.operationInProgress();
989 * Sets the text of the status bar. Note that setting a null or empty value
990 * will cause the status bar to be hidden, with possibly undesirable flicker
991 * of the screen layout.
994 public void setStatus(String text)
996 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1000 * Added so Castor Mapping file can obtain Jalview Version
1002 public String getVersion()
1004 return jalview.bin.Cache.getProperty("VERSION");
1007 public FeatureRenderer getFeatureRenderer()
1009 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1013 public void fetchSequence_actionPerformed(ActionEvent e)
1015 new jalview.gui.SequenceFetcher(this);
1019 public void addFromFile_actionPerformed(ActionEvent e)
1021 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1025 public void hmmBuild_actionPerformed(boolean withDefaults)
1027 if (!alignmentIsSufficient(1))
1033 * get default parameters, and optionally show a dialog
1034 * to allow them to be modified
1036 ParamDatastoreI store = HMMERParamStore.forBuild(viewport);
1037 List<ArgumentI> args = store.getServiceParameters();
1041 WsParamSetI set = new HMMERPreset();
1042 WsJobParameters params = new WsJobParameters(store, set, args);
1043 if (params.showRunDialog())
1045 args = params.getJobParams();
1049 return; // user cancelled
1052 new Thread(new HMMBuild(this, args)).start();
1056 public void hmmAlign_actionPerformed(boolean withDefaults)
1058 if (!(checkForHMM() && alignmentIsSufficient(2)))
1064 * get default parameters, and optionally show a dialog
1065 * to allow them to be modified
1067 ParamDatastoreI store = HMMERParamStore.forAlign(viewport);
1068 List<ArgumentI> args = store.getServiceParameters();
1072 WsParamSetI set = new HMMERPreset();
1073 WsJobParameters params = new WsJobParameters(store, set, args);
1074 if (params.showRunDialog())
1076 args = params.getJobParams();
1080 return; // user cancelled
1083 new Thread(new HMMAlign(this, args)).start();
1087 public void hmmSearch_actionPerformed(boolean withDefaults)
1095 * get default parameters, and (if requested) show
1096 * dialog to allow modification
1098 ParamDatastoreI store = HMMERParamStore.forSearch(viewport);
1099 List<ArgumentI> args = store.getServiceParameters();
1103 WsParamSetI set = new HMMERPreset();
1104 WsJobParameters params = new WsJobParameters(store, set, args);
1105 if (params.showRunDialog())
1107 args = params.getJobParams();
1111 return; // user cancelled
1114 new Thread(new HMMSearch(this, args)).start();
1115 alignPanel.repaint();
1119 public void jackhmmer_actionPerformed(boolean withDefaults)
1123 * get default parameters, and (if requested) show
1124 * dialog to allow modification
1127 ParamDatastoreI store = HMMERParamStore.forJackhmmer(viewport);
1128 List<ArgumentI> args = store.getServiceParameters();
1132 WsParamSetI set = new HMMERPreset();
1133 WsJobParameters params = new WsJobParameters(store, set, args);
1134 if (params.showRunDialog())
1136 args = params.getJobParams();
1140 return; // user cancelled
1143 new Thread(new JackHMMER(this, args)).start();
1144 alignPanel.repaint();
1149 * Checks if the alignment has at least one hidden Markov model, if not shows
1150 * a dialog advising to run hmmbuild or load an HMM profile
1154 private boolean checkForHMM()
1156 if (viewport.getAlignment().getHmmSequences().isEmpty())
1158 JOptionPane.showMessageDialog(this,
1159 MessageManager.getString("warn.no_hmm"));
1166 protected void filterByEValue_actionPerformed()
1168 viewport.filterByEvalue(inputDouble("Enter E-Value Cutoff"));
1172 protected void filterByScore_actionPerformed()
1174 viewport.filterByScore(inputDouble("Enter Bit Score Threshold"));
1177 private double inputDouble(String message)
1181 while(d == null || d <= 0)
1183 str = JOptionPane.showInputDialog(this.alignPanel, message);
1186 d = Double.valueOf(str);
1188 catch (NumberFormatException e)
1196 * Checks if the alignment contains the required number of sequences.
1201 public boolean alignmentIsSufficient(int required)
1203 if (getViewport().getSequenceSelection().length < required)
1205 JOptionPane.showMessageDialog(this,
1206 MessageManager.getString("label.not_enough_sequences"));
1213 * Opens a file browser and adds the selected file, if in Fasta, Stockholm or
1214 * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a
1215 * comma-separated list)
1218 public void addDatabase_actionPerformed() throws IOException
1220 if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null)
1222 Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
1225 String path = openFileChooser(false);
1226 if (path != null && new File(path).exists())
1228 IdentifyFile identifier = new IdentifyFile();
1229 FileFormatI format = identifier.identify(path, DataSourceType.FILE);
1230 if (format == FileFormat.Fasta || format == FileFormat.Stockholm
1231 || format == FileFormat.Pfam)
1233 String currentDbPaths = Cache
1234 .getProperty(Preferences.HMMSEARCH_DBS);
1235 currentDbPaths += Preferences.COMMA + path;
1236 Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
1240 JOptionPane.showMessageDialog(this,
1241 MessageManager.getString("warn.invalid_format"));
1247 * Opens a file chooser, optionally restricted to selecting folders
1248 * (directories) only. Answers the path to the selected file or folder, or
1249 * null if none is chosen.
1254 protected String openFileChooser(boolean forFolder)
1256 // TODO duplicates GPreferences method - relocate to JalviewFileChooser?
1257 String choice = null;
1258 JFileChooser chooser = new JFileChooser();
1261 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1263 chooser.setDialogTitle(
1264 MessageManager.getString("label.open_local_file"));
1265 chooser.setToolTipText(MessageManager.getString("action.open"));
1267 int value = chooser.showOpenDialog(this);
1269 if (value == JFileChooser.APPROVE_OPTION)
1271 choice = chooser.getSelectedFile().getPath();
1277 public void reload_actionPerformed(ActionEvent e)
1279 if (fileName != null)
1281 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1282 // originating file's format
1283 // TODO: work out how to recover feature settings for correct view(s) when
1284 // file is reloaded.
1285 if (FileFormat.Jalview.equals(currentFileFormat))
1287 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1288 for (int i = 0; i < frames.length; i++)
1290 if (frames[i] instanceof AlignFrame && frames[i] != this
1291 && ((AlignFrame) frames[i]).fileName != null
1292 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1296 frames[i].setSelected(true);
1297 Desktop.instance.closeAssociatedWindows();
1298 } catch (java.beans.PropertyVetoException ex)
1304 Desktop.instance.closeAssociatedWindows();
1306 FileLoader loader = new FileLoader();
1307 DataSourceType protocol = fileName.startsWith("http:")
1308 ? DataSourceType.URL
1309 : DataSourceType.FILE;
1310 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1314 Rectangle bounds = this.getBounds();
1316 FileLoader loader = new FileLoader();
1317 DataSourceType protocol = fileName.startsWith("http:")
1318 ? DataSourceType.URL
1319 : DataSourceType.FILE;
1320 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1321 protocol, currentFileFormat);
1323 newframe.setBounds(bounds);
1324 if (featureSettings != null && featureSettings.isShowing())
1326 final Rectangle fspos = featureSettings.frame.getBounds();
1327 // TODO: need a 'show feature settings' function that takes bounds -
1328 // need to refactor Desktop.addFrame
1329 newframe.featureSettings_actionPerformed(null);
1330 final FeatureSettings nfs = newframe.featureSettings;
1331 SwingUtilities.invokeLater(new Runnable()
1336 nfs.frame.setBounds(fspos);
1339 this.featureSettings.close();
1340 this.featureSettings = null;
1342 this.closeMenuItem_actionPerformed(true);
1348 public void addFromText_actionPerformed(ActionEvent e)
1351 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1355 public void addFromURL_actionPerformed(ActionEvent e)
1357 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1361 public void save_actionPerformed(ActionEvent e)
1363 if (fileName == null || (currentFileFormat == null)
1364 || fileName.startsWith("http"))
1366 saveAs_actionPerformed(null);
1370 saveAlignment(fileName, currentFileFormat);
1381 public void saveAs_actionPerformed(ActionEvent e)
1383 String format = currentFileFormat == null ? null
1384 : currentFileFormat.getName();
1385 JalviewFileChooser chooser = JalviewFileChooser
1386 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1388 chooser.setFileView(new JalviewFileView());
1389 chooser.setDialogTitle(
1390 MessageManager.getString("label.save_alignment_to_file"));
1391 chooser.setToolTipText(MessageManager.getString("action.save"));
1393 int value = chooser.showSaveDialog(this);
1395 if (value == JalviewFileChooser.APPROVE_OPTION)
1397 currentFileFormat = chooser.getSelectedFormat();
1398 while (currentFileFormat == null)
1400 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1401 MessageManager.getString(
1402 "label.select_file_format_before_saving"),
1403 MessageManager.getString("label.file_format_not_specified"),
1404 JvOptionPane.WARNING_MESSAGE);
1405 currentFileFormat = chooser.getSelectedFormat();
1406 value = chooser.showSaveDialog(this);
1407 if (value != JalviewFileChooser.APPROVE_OPTION)
1413 fileName = chooser.getSelectedFile().getPath();
1415 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1417 Cache.setProperty("LAST_DIRECTORY", fileName);
1418 saveAlignment(fileName, currentFileFormat);
1422 public boolean saveAlignment(String file, FileFormatI format)
1424 boolean success = true;
1426 if (FileFormat.Jalview.equals(format))
1428 String shortName = title;
1430 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1432 shortName = shortName.substring(
1433 shortName.lastIndexOf(java.io.File.separatorChar) + 1);
1436 success = new jalview.project.Jalview2XML().saveAlignment(this, file,
1439 statusBar.setText(MessageManager.formatMessage(
1440 "label.successfully_saved_to_file_in_format", new Object[]
1441 { fileName, format }));
1446 AlignmentExportData exportData = getAlignmentForExport(format,
1448 if (exportData.getSettings().isCancelled())
1452 FormatAdapter f = new FormatAdapter(alignPanel,
1453 exportData.getSettings());
1454 String output = f.formatSequences(format, exportData.getAlignment(), // class
1458 // occur in the distant future
1459 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1460 f.getCacheSuffixDefault(format),
1461 viewport.getAlignment().getHiddenColumns());
1469 // create backupfiles object and get new temp filename destination
1470 BackupFiles backupfiles = new BackupFiles(file);
1474 PrintWriter out = new PrintWriter(
1475 new FileWriter(backupfiles.getTempFilePath()));
1479 this.setTitle(file);
1480 statusBar.setText(MessageManager.formatMessage(
1481 "label.successfully_saved_to_file_in_format", new Object[]
1482 { fileName, format.getName() }));
1483 } catch (Exception ex)
1486 ex.printStackTrace();
1489 backupfiles.setWriteSuccess(success);
1490 // do the backup file roll and rename the temp file to actual file
1491 success = backupfiles.rollBackupsAndRenameTempFile();
1498 JvOptionPane.showInternalMessageDialog(this, MessageManager
1499 .formatMessage("label.couldnt_save_file", new Object[]
1501 MessageManager.getString("label.error_saving_file"),
1502 JvOptionPane.WARNING_MESSAGE);
1508 private void warningMessage(String warning, String title)
1510 if (new jalview.util.Platform().isHeadless())
1512 System.err.println("Warning: " + title + "\nWarning: " + warning);
1517 JvOptionPane.showInternalMessageDialog(this, warning, title,
1518 JvOptionPane.WARNING_MESSAGE);
1530 protected void outputText_actionPerformed(ActionEvent e)
1532 FileFormatI fileFormat = FileFormats.getInstance()
1533 .forName(e.getActionCommand());
1534 AlignmentExportData exportData = getAlignmentForExport(fileFormat,
1536 if (exportData.getSettings().isCancelled())
1540 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1541 cap.setForInput(null);
1544 FileFormatI format = fileFormat;
1545 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1546 .formatSequences(format, exportData.getAlignment(),
1547 exportData.getOmitHidden(),
1548 exportData.getStartEndPostions(),
1549 viewport.getAlignment().getHiddenColumns()));
1550 Desktop.addInternalFrame(cap, MessageManager
1551 .formatMessage("label.alignment_output_command", new Object[]
1552 { e.getActionCommand() }), 600, 500);
1553 } catch (OutOfMemoryError oom)
1555 new OOMWarning("Outputting alignment as " + e.getActionCommand(),
1562 public static AlignmentExportData getAlignmentForExport(
1563 FileFormatI format, AlignViewportI viewport,
1564 AlignExportSettingI exportSettings)
1566 AlignmentI alignmentToExport = null;
1567 AlignExportSettingI settings = exportSettings;
1568 String[] omitHidden = null;
1570 HiddenSequences hiddenSeqs = viewport.getAlignment()
1571 .getHiddenSequences();
1573 alignmentToExport = viewport.getAlignment();
1575 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1576 if (settings == null)
1578 settings = new AlignExportSettings(hasHiddenSeqs,
1579 viewport.hasHiddenColumns(), format);
1581 // settings.isExportAnnotations();
1583 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1585 omitHidden = viewport.getViewAsString(false,
1586 settings.isExportHiddenSequences());
1589 int[] alignmentStartEnd = new int[2];
1590 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1592 alignmentToExport = hiddenSeqs.getFullAlignment();
1596 alignmentToExport = viewport.getAlignment();
1598 alignmentStartEnd = viewport.getAlignment().getHiddenColumns()
1599 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
1600 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1601 omitHidden, alignmentStartEnd, settings);
1612 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1614 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1615 htmlSVG.exportHTML(null);
1619 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1621 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1622 bjs.exportHTML(null);
1625 public void createImageMap(File file, String image)
1627 alignPanel.makePNGImageMap(file, image);
1637 public void createPNG(File f)
1639 alignPanel.makePNG(f);
1649 public void createEPS(File f)
1651 alignPanel.makeEPS(f);
1655 public void createSVG(File f)
1657 alignPanel.makeSVG(f);
1661 public void pageSetup_actionPerformed(ActionEvent e)
1663 PrinterJob printJob = PrinterJob.getPrinterJob();
1664 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1674 public void printMenuItem_actionPerformed(ActionEvent e)
1676 // Putting in a thread avoids Swing painting problems
1677 PrintThread thread = new PrintThread(alignPanel);
1682 public void exportFeatures_actionPerformed(ActionEvent e)
1684 new AnnotationExporter(alignPanel).exportFeatures();
1688 public void exportAnnotations_actionPerformed(ActionEvent e)
1690 new AnnotationExporter(alignPanel).exportAnnotations();
1694 public void associatedData_actionPerformed(ActionEvent e)
1695 throws IOException, InterruptedException
1697 // Pick the tree file
1698 JalviewFileChooser chooser = new JalviewFileChooser(
1699 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1700 chooser.setFileView(new JalviewFileView());
1701 chooser.setDialogTitle(
1702 MessageManager.getString("label.load_jalview_annotations"));
1703 chooser.setToolTipText(
1704 MessageManager.getString("label.load_jalview_annotations"));
1706 int value = chooser.showOpenDialog(null);
1708 if (value == JalviewFileChooser.APPROVE_OPTION)
1710 String choice = chooser.getSelectedFile().getPath();
1711 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1712 loadJalviewDataFile(choice, null, null, null);
1718 * Close the current view or all views in the alignment frame. If the frame
1719 * only contains one view then the alignment will be removed from memory.
1721 * @param closeAllTabs
1724 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1726 if (alignPanels != null && alignPanels.size() < 2)
1728 closeAllTabs = true;
1733 if (alignPanels != null)
1737 if (this.isClosed())
1739 // really close all the windows - otherwise wait till
1740 // setClosed(true) is called
1741 for (int i = 0; i < alignPanels.size(); i++)
1743 AlignmentPanel ap = alignPanels.get(i);
1750 closeView(alignPanel);
1755 if (featureSettings != null && featureSettings.isOpen())
1757 featureSettings.close();
1758 featureSettings = null;
1761 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1762 * be called recursively, with the frame now in 'closed' state
1764 this.setClosed(true);
1766 } catch (Exception ex)
1768 ex.printStackTrace();
1773 * Close the specified panel and close up tabs appropriately.
1775 * @param panelToClose
1777 public void closeView(AlignmentPanel panelToClose)
1779 int index = tabbedPane.getSelectedIndex();
1780 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1781 alignPanels.remove(panelToClose);
1782 panelToClose.closePanel();
1783 panelToClose = null;
1785 tabbedPane.removeTabAt(closedindex);
1786 tabbedPane.validate();
1788 if (index > closedindex || index == tabbedPane.getTabCount())
1790 // modify currently selected tab index if necessary.
1794 this.tabSelectionChanged(index);
1800 void updateEditMenuBar()
1803 if (viewport.getHistoryList().size() > 0)
1805 undoMenuItem.setEnabled(true);
1806 CommandI command = viewport.getHistoryList().peek();
1807 undoMenuItem.setText(MessageManager
1808 .formatMessage("label.undo_command", new Object[]
1809 { command.getDescription() }));
1813 undoMenuItem.setEnabled(false);
1814 undoMenuItem.setText(MessageManager.getString("action.undo"));
1817 if (viewport.getRedoList().size() > 0)
1819 redoMenuItem.setEnabled(true);
1821 CommandI command = viewport.getRedoList().peek();
1822 redoMenuItem.setText(MessageManager
1823 .formatMessage("label.redo_command", new Object[]
1824 { command.getDescription() }));
1828 redoMenuItem.setEnabled(false);
1829 redoMenuItem.setText(MessageManager.getString("action.redo"));
1834 public void addHistoryItem(CommandI command)
1836 if (command.getSize() > 0)
1838 viewport.addToHistoryList(command);
1839 viewport.clearRedoList();
1840 updateEditMenuBar();
1841 viewport.updateHiddenColumns();
1842 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1843 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1844 // viewport.getColumnSelection()
1845 // .getHiddenColumns().size() > 0);
1851 * @return alignment objects for all views
1853 AlignmentI[] getViewAlignments()
1855 if (alignPanels != null)
1857 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1859 for (AlignmentPanel ap : alignPanels)
1861 als[i++] = ap.av.getAlignment();
1865 if (viewport != null)
1867 return new AlignmentI[] { viewport.getAlignment() };
1879 protected void undoMenuItem_actionPerformed(ActionEvent e)
1881 if (viewport.getHistoryList().isEmpty())
1885 CommandI command = viewport.getHistoryList().pop();
1886 viewport.addToRedoList(command);
1887 command.undoCommand(getViewAlignments());
1889 AlignmentViewport originalSource = getOriginatingSource(command);
1890 updateEditMenuBar();
1892 if (originalSource != null)
1894 if (originalSource != viewport)
1897 "Implementation worry: mismatch of viewport origin for undo");
1899 originalSource.updateHiddenColumns();
1900 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1902 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1903 // viewport.getColumnSelection()
1904 // .getHiddenColumns().size() > 0);
1905 originalSource.firePropertyChange("alignment", null,
1906 originalSource.getAlignment().getSequences());
1917 protected void redoMenuItem_actionPerformed(ActionEvent e)
1919 if (viewport.getRedoList().size() < 1)
1924 CommandI command = viewport.getRedoList().pop();
1925 viewport.addToHistoryList(command);
1926 command.doCommand(getViewAlignments());
1928 AlignmentViewport originalSource = getOriginatingSource(command);
1929 updateEditMenuBar();
1931 if (originalSource != null)
1934 if (originalSource != viewport)
1937 "Implementation worry: mismatch of viewport origin for redo");
1939 originalSource.updateHiddenColumns();
1940 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1942 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1943 // viewport.getColumnSelection()
1944 // .getHiddenColumns().size() > 0);
1945 originalSource.firePropertyChange("alignment", null,
1946 originalSource.getAlignment().getSequences());
1950 AlignmentViewport getOriginatingSource(CommandI command)
1952 AlignmentViewport originalSource = null;
1953 // For sequence removal and addition, we need to fire
1954 // the property change event FROM the viewport where the
1955 // original alignment was altered
1956 AlignmentI al = null;
1957 if (command instanceof EditCommand)
1959 EditCommand editCommand = (EditCommand) command;
1960 al = editCommand.getAlignment();
1961 List<Component> comps = PaintRefresher.components
1962 .get(viewport.getSequenceSetId());
1964 for (Component comp : comps)
1966 if (comp instanceof AlignmentPanel)
1968 if (al == ((AlignmentPanel) comp).av.getAlignment())
1970 originalSource = ((AlignmentPanel) comp).av;
1977 if (originalSource == null)
1979 // The original view is closed, we must validate
1980 // the current view against the closed view first
1983 PaintRefresher.validateSequences(al, viewport.getAlignment());
1986 originalSource = viewport;
1989 return originalSource;
1998 public void moveSelectedSequences(boolean up)
2000 SequenceGroup sg = viewport.getSelectionGroup();
2006 viewport.getAlignment().moveSelectedSequencesByOne(sg,
2007 viewport.getHiddenRepSequences(), up);
2008 alignPanel.paintAlignment(true, false);
2011 synchronized void slideSequences(boolean right, int size)
2013 List<SequenceI> sg = new ArrayList<>();
2014 if (viewport.cursorMode)
2016 sg.add(viewport.getAlignment()
2017 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
2019 else if (viewport.getSelectionGroup() != null
2020 && viewport.getSelectionGroup().getSize() != viewport
2021 .getAlignment().getHeight())
2023 sg = viewport.getSelectionGroup()
2024 .getSequences(viewport.getHiddenRepSequences());
2032 List<SequenceI> invertGroup = new ArrayList<>();
2034 for (SequenceI seq : viewport.getAlignment().getSequences())
2036 if (!sg.contains(seq))
2038 invertGroup.add(seq);
2042 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
2044 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
2045 for (int i = 0; i < invertGroup.size(); i++)
2047 seqs2[i] = invertGroup.get(i);
2050 SlideSequencesCommand ssc;
2053 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
2054 viewport.getGapCharacter());
2058 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
2059 viewport.getGapCharacter());
2062 int groupAdjustment = 0;
2063 if (ssc.getGapsInsertedBegin() && right)
2065 if (viewport.cursorMode)
2067 alignPanel.getSeqPanel().moveCursor(size, 0);
2071 groupAdjustment = size;
2074 else if (!ssc.getGapsInsertedBegin() && !right)
2076 if (viewport.cursorMode)
2078 alignPanel.getSeqPanel().moveCursor(-size, 0);
2082 groupAdjustment = -size;
2086 if (groupAdjustment != 0)
2088 viewport.getSelectionGroup().setStartRes(
2089 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
2090 viewport.getSelectionGroup().setEndRes(
2091 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
2095 * just extend the last slide command if compatible; but not if in
2096 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
2098 boolean appendHistoryItem = false;
2099 Deque<CommandI> historyList = viewport.getHistoryList();
2100 boolean inSplitFrame = getSplitViewContainer() != null;
2101 if (!inSplitFrame && historyList != null && historyList.size() > 0
2102 && historyList.peek() instanceof SlideSequencesCommand)
2104 appendHistoryItem = ssc.appendSlideCommand(
2105 (SlideSequencesCommand) historyList.peek());
2108 if (!appendHistoryItem)
2110 addHistoryItem(ssc);
2123 protected void copy_actionPerformed(ActionEvent e)
2125 if (viewport.getSelectionGroup() == null)
2129 // TODO: preserve the ordering of displayed alignment annotation in any
2130 // internal paste (particularly sequence associated annotation)
2131 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
2132 String[] omitHidden = null;
2134 if (viewport.hasHiddenColumns())
2136 omitHidden = viewport.getViewAsString(true);
2139 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
2140 seqs, omitHidden, null);
2142 StringSelection ss = new StringSelection(output);
2146 jalview.gui.Desktop.internalCopy = true;
2147 // Its really worth setting the clipboard contents
2148 // to empty before setting the large StringSelection!!
2149 Toolkit.getDefaultToolkit().getSystemClipboard()
2150 .setContents(new StringSelection(""), null);
2152 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
2154 } catch (OutOfMemoryError er)
2156 new OOMWarning("copying region", er);
2160 HiddenColumns hiddenColumns = null;
2161 if (viewport.hasHiddenColumns())
2163 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
2164 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
2166 // create new HiddenColumns object with copy of hidden regions
2167 // between startRes and endRes, offset by startRes
2168 hiddenColumns = new HiddenColumns(
2169 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2170 hiddenCutoff, hiddenOffset);
2173 Desktop.jalviewClipboard = new Object[] { seqs,
2174 viewport.getAlignment().getDataset(), hiddenColumns };
2175 statusBar.setText(MessageManager.formatMessage(
2176 "label.copied_sequences_to_clipboard", new Object[]
2177 { Integer.valueOf(seqs.length).toString() }));
2185 * @throws InterruptedException
2186 * @throws IOException
2189 protected void pasteNew_actionPerformed(ActionEvent e)
2190 throws IOException, InterruptedException
2200 * @throws InterruptedException
2201 * @throws IOException
2204 protected void pasteThis_actionPerformed(ActionEvent e)
2205 throws IOException, InterruptedException
2211 * Paste contents of Jalview clipboard
2213 * @param newAlignment
2214 * true to paste to a new alignment, otherwise add to this.
2215 * @throws InterruptedException
2216 * @throws IOException
2218 void paste(boolean newAlignment) throws IOException, InterruptedException
2220 boolean externalPaste = true;
2223 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2224 Transferable contents = c.getContents(this);
2226 if (contents == null)
2235 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2236 if (str.length() < 1)
2241 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2243 } catch (OutOfMemoryError er)
2245 new OOMWarning("Out of memory pasting sequences!!", er);
2249 SequenceI[] sequences;
2250 boolean annotationAdded = false;
2251 AlignmentI alignment = null;
2253 if (Desktop.jalviewClipboard != null)
2255 // The clipboard was filled from within Jalview, we must use the
2257 // And dataset from the copied alignment
2258 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2259 // be doubly sure that we create *new* sequence objects.
2260 sequences = new SequenceI[newseq.length];
2261 for (int i = 0; i < newseq.length; i++)
2263 sequences[i] = new Sequence(newseq[i]);
2265 alignment = new Alignment(sequences);
2266 externalPaste = false;
2270 // parse the clipboard as an alignment.
2271 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2273 sequences = alignment.getSequencesArray();
2277 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2283 if (Desktop.jalviewClipboard != null)
2285 // dataset is inherited
2286 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2290 // new dataset is constructed
2291 alignment.setDataset(null);
2293 alwidth = alignment.getWidth() + 1;
2297 AlignmentI pastedal = alignment; // preserve pasted alignment object
2298 // Add pasted sequences and dataset into existing alignment.
2299 alignment = viewport.getAlignment();
2300 alwidth = alignment.getWidth() + 1;
2301 // decide if we need to import sequences from an existing dataset
2302 boolean importDs = Desktop.jalviewClipboard != null
2303 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2304 // importDs==true instructs us to copy over new dataset sequences from
2305 // an existing alignment
2306 Vector newDs = (importDs) ? new Vector() : null; // used to create
2307 // minimum dataset set
2309 for (int i = 0; i < sequences.length; i++)
2313 newDs.addElement(null);
2315 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2317 if (importDs && ds != null)
2319 if (!newDs.contains(ds))
2321 newDs.setElementAt(ds, i);
2322 ds = new Sequence(ds);
2323 // update with new dataset sequence
2324 sequences[i].setDatasetSequence(ds);
2328 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2333 // copy and derive new dataset sequence
2334 sequences[i] = sequences[i].deriveSequence();
2335 alignment.getDataset()
2336 .addSequence(sequences[i].getDatasetSequence());
2337 // TODO: avoid creation of duplicate dataset sequences with a
2338 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2340 alignment.addSequence(sequences[i]); // merges dataset
2344 newDs.clear(); // tidy up
2346 if (alignment.getAlignmentAnnotation() != null)
2348 for (AlignmentAnnotation alan : alignment
2349 .getAlignmentAnnotation())
2351 if (alan.graphGroup > fgroup)
2353 fgroup = alan.graphGroup;
2357 if (pastedal.getAlignmentAnnotation() != null)
2359 // Add any annotation attached to alignment.
2360 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2361 for (int i = 0; i < alann.length; i++)
2363 annotationAdded = true;
2364 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2366 AlignmentAnnotation newann = new AlignmentAnnotation(
2368 if (newann.graphGroup > -1)
2370 if (newGraphGroups.size() <= newann.graphGroup
2371 || newGraphGroups.get(newann.graphGroup) == null)
2373 for (int q = newGraphGroups
2374 .size(); q <= newann.graphGroup; q++)
2376 newGraphGroups.add(q, null);
2378 newGraphGroups.set(newann.graphGroup,
2379 Integer.valueOf(++fgroup));
2381 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2385 newann.padAnnotation(alwidth);
2386 alignment.addAnnotation(newann);
2396 addHistoryItem(new EditCommand(
2397 MessageManager.getString("label.add_sequences"),
2398 Action.PASTE, sequences, 0, alignment.getWidth(),
2401 // Add any annotations attached to sequences
2402 for (int i = 0; i < sequences.length; i++)
2404 if (sequences[i].getAnnotation() != null)
2406 AlignmentAnnotation newann;
2407 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2409 annotationAdded = true;
2410 newann = sequences[i].getAnnotation()[a];
2411 newann.adjustForAlignment();
2412 newann.padAnnotation(alwidth);
2413 if (newann.graphGroup > -1)
2415 if (newann.graphGroup > -1)
2417 if (newGraphGroups.size() <= newann.graphGroup
2418 || newGraphGroups.get(newann.graphGroup) == null)
2420 for (int q = newGraphGroups
2421 .size(); q <= newann.graphGroup; q++)
2423 newGraphGroups.add(q, null);
2425 newGraphGroups.set(newann.graphGroup,
2426 Integer.valueOf(++fgroup));
2428 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2432 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2436 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2444 // propagate alignment changed.
2445 viewport.getRanges().setEndSeq(alignment.getHeight());
2446 if (annotationAdded)
2448 // Duplicate sequence annotation in all views.
2449 AlignmentI[] alview = this.getViewAlignments();
2450 for (int i = 0; i < sequences.length; i++)
2452 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2457 for (int avnum = 0; avnum < alview.length; avnum++)
2459 if (alview[avnum] != alignment)
2461 // duplicate in a view other than the one with input focus
2462 int avwidth = alview[avnum].getWidth() + 1;
2463 // this relies on sann being preserved after we
2464 // modify the sequence's annotation array for each duplication
2465 for (int a = 0; a < sann.length; a++)
2467 AlignmentAnnotation newann = new AlignmentAnnotation(
2469 sequences[i].addAlignmentAnnotation(newann);
2470 newann.padAnnotation(avwidth);
2471 alview[avnum].addAnnotation(newann); // annotation was
2472 // duplicated earlier
2473 // TODO JAL-1145 graphGroups are not updated for sequence
2474 // annotation added to several views. This may cause
2476 alview[avnum].setAnnotationIndex(newann, a);
2481 buildSortByAnnotationScoresMenu();
2483 viewport.firePropertyChange("alignment", null,
2484 alignment.getSequences());
2485 if (alignPanels != null)
2487 for (AlignmentPanel ap : alignPanels)
2489 ap.validateAnnotationDimensions(false);
2494 alignPanel.validateAnnotationDimensions(false);
2500 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2502 String newtitle = new String("Copied sequences");
2504 if (Desktop.jalviewClipboard != null
2505 && Desktop.jalviewClipboard[2] != null)
2507 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2508 af.viewport.setHiddenColumns(hc);
2511 // >>>This is a fix for the moment, until a better solution is
2513 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2514 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2515 .getFeatureRenderer());
2517 // TODO: maintain provenance of an alignment, rather than just make the
2518 // title a concatenation of operations.
2521 if (title.startsWith("Copied sequences"))
2527 newtitle = newtitle.concat("- from " + title);
2532 newtitle = new String("Pasted sequences");
2535 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2540 } catch (Exception ex)
2542 ex.printStackTrace();
2543 System.out.println("Exception whilst pasting: " + ex);
2544 // could be anything being pasted in here
2549 protected void expand_newalign(ActionEvent e)
2553 AlignmentI alignment = AlignmentUtils
2554 .expandContext(getViewport().getAlignment(), -1);
2555 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2557 String newtitle = new String("Flanking alignment");
2559 if (Desktop.jalviewClipboard != null
2560 && Desktop.jalviewClipboard[2] != null)
2562 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2563 af.viewport.setHiddenColumns(hc);
2566 // >>>This is a fix for the moment, until a better solution is
2568 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2569 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2570 .getFeatureRenderer());
2572 // TODO: maintain provenance of an alignment, rather than just make the
2573 // title a concatenation of operations.
2575 if (title.startsWith("Copied sequences"))
2581 newtitle = newtitle.concat("- from " + title);
2585 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2587 } catch (Exception ex)
2589 ex.printStackTrace();
2590 System.out.println("Exception whilst pasting: " + ex);
2591 // could be anything being pasted in here
2592 } catch (OutOfMemoryError oom)
2594 new OOMWarning("Viewing flanking region of alignment", oom);
2605 protected void cut_actionPerformed(ActionEvent e)
2607 copy_actionPerformed(null);
2608 delete_actionPerformed(null);
2618 protected void delete_actionPerformed(ActionEvent evt)
2621 SequenceGroup sg = viewport.getSelectionGroup();
2628 * If the cut affects all sequences, warn, remove highlighted columns
2630 if (sg.getSize() == viewport.getAlignment().getHeight())
2632 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
2633 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2634 if (isEntireAlignWidth)
2636 int confirm = JvOptionPane.showConfirmDialog(this,
2637 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2638 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2639 JvOptionPane.OK_CANCEL_OPTION);
2641 if (confirm == JvOptionPane.CANCEL_OPTION
2642 || confirm == JvOptionPane.CLOSED_OPTION)
2647 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2648 sg.getEndRes() + 1);
2650 SequenceI[] cut = sg.getSequences()
2651 .toArray(new SequenceI[sg.getSize()]);
2653 addHistoryItem(new EditCommand(
2654 MessageManager.getString("label.cut_sequences"), Action.CUT,
2655 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2656 viewport.getAlignment()));
2658 viewport.setSelectionGroup(null);
2659 viewport.sendSelection();
2660 viewport.getAlignment().deleteGroup(sg);
2662 viewport.firePropertyChange("alignment", null,
2663 viewport.getAlignment().getSequences());
2664 if (viewport.getAlignment().getHeight() < 1)
2668 this.setClosed(true);
2669 } catch (Exception ex)
2682 protected void deleteGroups_actionPerformed(ActionEvent e)
2684 if (avc.deleteGroups())
2686 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2687 alignPanel.updateAnnotation();
2688 alignPanel.paintAlignment(true, true);
2699 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2701 SequenceGroup sg = new SequenceGroup(
2702 viewport.getAlignment().getSequences());
2704 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2705 viewport.setSelectionGroup(sg);
2706 viewport.isSelectionGroupChanged(true);
2707 viewport.sendSelection();
2708 // JAL-2034 - should delegate to
2709 // alignPanel to decide if overview needs
2711 alignPanel.paintAlignment(false, false);
2712 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2722 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2724 if (viewport.cursorMode)
2726 alignPanel.getSeqPanel().keyboardNo1 = null;
2727 alignPanel.getSeqPanel().keyboardNo2 = null;
2729 viewport.setSelectionGroup(null);
2730 viewport.getColumnSelection().clear();
2731 viewport.setSelectionGroup(null);
2732 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2733 // JAL-2034 - should delegate to
2734 // alignPanel to decide if overview needs
2736 alignPanel.paintAlignment(false, false);
2737 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2738 viewport.sendSelection();
2748 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2750 SequenceGroup sg = viewport.getSelectionGroup();
2754 selectAllSequenceMenuItem_actionPerformed(null);
2759 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2761 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2763 // JAL-2034 - should delegate to
2764 // alignPanel to decide if overview needs
2767 alignPanel.paintAlignment(true, false);
2768 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2769 viewport.sendSelection();
2773 public void invertColSel_actionPerformed(ActionEvent e)
2775 viewport.invertColumnSelection();
2776 alignPanel.paintAlignment(true, false);
2777 viewport.sendSelection();
2787 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2789 trimAlignment(true);
2799 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2801 trimAlignment(false);
2804 void trimAlignment(boolean trimLeft)
2806 ColumnSelection colSel = viewport.getColumnSelection();
2809 if (!colSel.isEmpty())
2813 column = colSel.getMin();
2817 column = colSel.getMax();
2821 if (viewport.getSelectionGroup() != null)
2823 seqs = viewport.getSelectionGroup()
2824 .getSequencesAsArray(viewport.getHiddenRepSequences());
2828 seqs = viewport.getAlignment().getSequencesArray();
2831 TrimRegionCommand trimRegion;
2834 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2835 column, viewport.getAlignment());
2836 viewport.getRanges().setStartRes(0);
2840 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2841 column, viewport.getAlignment());
2844 statusBar.setText(MessageManager
2845 .formatMessage("label.removed_columns", new String[]
2846 { Integer.valueOf(trimRegion.getSize()).toString() }));
2848 addHistoryItem(trimRegion);
2850 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2852 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2853 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2855 viewport.getAlignment().deleteGroup(sg);
2859 viewport.firePropertyChange("alignment", null,
2860 viewport.getAlignment().getSequences());
2871 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2873 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2876 if (viewport.getSelectionGroup() != null)
2878 seqs = viewport.getSelectionGroup()
2879 .getSequencesAsArray(viewport.getHiddenRepSequences());
2880 start = viewport.getSelectionGroup().getStartRes();
2881 end = viewport.getSelectionGroup().getEndRes();
2885 seqs = viewport.getAlignment().getSequencesArray();
2888 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2889 "Remove Gapped Columns", seqs, start, end,
2890 viewport.getAlignment());
2892 addHistoryItem(removeGapCols);
2894 statusBar.setText(MessageManager
2895 .formatMessage("label.removed_empty_columns", new Object[]
2896 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2898 // This is to maintain viewport position on first residue
2899 // of first sequence
2900 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2901 ViewportRanges ranges = viewport.getRanges();
2902 int startRes = seq.findPosition(ranges.getStartRes());
2903 // ShiftList shifts;
2904 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2905 // edit.alColumnChanges=shifts.getInverse();
2906 // if (viewport.hasHiddenColumns)
2907 // viewport.getColumnSelection().compensateForEdits(shifts);
2908 ranges.setStartRes(seq.findIndex(startRes) - 1);
2909 viewport.firePropertyChange("alignment", null,
2910 viewport.getAlignment().getSequences());
2921 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2923 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2926 if (viewport.getSelectionGroup() != null)
2928 seqs = viewport.getSelectionGroup()
2929 .getSequencesAsArray(viewport.getHiddenRepSequences());
2930 start = viewport.getSelectionGroup().getStartRes();
2931 end = viewport.getSelectionGroup().getEndRes();
2935 seqs = viewport.getAlignment().getSequencesArray();
2938 // This is to maintain viewport position on first residue
2939 // of first sequence
2940 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2941 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2943 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2944 viewport.getAlignment()));
2946 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2948 viewport.firePropertyChange("alignment", null,
2949 viewport.getAlignment().getSequences());
2960 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2962 viewport.setPadGaps(padGapsMenuitem.isSelected());
2963 viewport.firePropertyChange("alignment", null,
2964 viewport.getAlignment().getSequences());
2974 public void findMenuItem_actionPerformed(ActionEvent e)
2980 * Create a new view of the current alignment.
2983 public void newView_actionPerformed(ActionEvent e)
2985 newView(null, true);
2989 * Creates and shows a new view of the current alignment.
2992 * title of newly created view; if null, one will be generated
2993 * @param copyAnnotation
2994 * if true then duplicate all annnotation, groups and settings
2995 * @return new alignment panel, already displayed.
2997 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
3000 * Create a new AlignmentPanel (with its own, new Viewport)
3002 AlignmentPanel newap = new jalview.project.Jalview2XML()
3003 .copyAlignPanel(alignPanel);
3004 if (!copyAnnotation)
3007 * remove all groups and annotation except for the automatic stuff
3009 newap.av.getAlignment().deleteAllGroups();
3010 newap.av.getAlignment().deleteAllAnnotations(false);
3013 newap.av.setGatherViewsHere(false);
3015 if (viewport.getViewName() == null)
3017 viewport.setViewName(MessageManager
3018 .getString("label.view_name_original"));
3022 * Views share the same edits undo and redo stacks
3024 newap.av.setHistoryList(viewport.getHistoryList());
3025 newap.av.setRedoList(viewport.getRedoList());
3028 * copy any visualisation settings that are not saved in the project
3030 newap.av.setColourAppliesToAllGroups(
3031 viewport.getColourAppliesToAllGroups());
3034 * Views share the same mappings; need to deregister any new mappings
3035 * created by copyAlignPanel, and register the new reference to the shared
3038 newap.av.replaceMappings(viewport.getAlignment());
3041 * start up cDNA consensus (if applicable) now mappings are in place
3043 if (newap.av.initComplementConsensus())
3045 newap.refresh(true); // adjust layout of annotations
3048 newap.av.setViewName(getNewViewName(viewTitle));
3050 addAlignmentPanel(newap, true);
3051 newap.alignmentChanged();
3053 if (alignPanels.size() == 2)
3055 viewport.setGatherViewsHere(true);
3057 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
3062 * Make a new name for the view, ensuring it is unique within the current
3063 * sequenceSetId. (This used to be essential for Jalview Project archives, but
3064 * these now use viewId. Unique view names are still desirable for usability.)
3069 protected String getNewViewName(String viewTitle)
3071 int index = Desktop.getViewCount(viewport.getSequenceSetId());
3072 boolean addFirstIndex = false;
3073 if (viewTitle == null || viewTitle.trim().length() == 0)
3075 viewTitle = MessageManager.getString("action.view");
3076 addFirstIndex = true;
3080 index = 1;// we count from 1 if given a specific name
3082 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
3084 List<Component> comps = PaintRefresher.components
3085 .get(viewport.getSequenceSetId());
3087 List<String> existingNames = getExistingViewNames(comps);
3089 while (existingNames.contains(newViewName))
3091 newViewName = viewTitle + " " + (++index);
3097 * Returns a list of distinct view names found in the given list of
3098 * components. View names are held on the viewport of an AlignmentPanel.
3103 protected List<String> getExistingViewNames(List<Component> comps)
3105 List<String> existingNames = new ArrayList<>();
3106 for (Component comp : comps)
3108 if (comp instanceof AlignmentPanel)
3110 AlignmentPanel ap = (AlignmentPanel) comp;
3111 if (!existingNames.contains(ap.av.getViewName()))
3113 existingNames.add(ap.av.getViewName());
3117 return existingNames;
3121 * Explode tabbed views into separate windows.
3124 public void expandViews_actionPerformed(ActionEvent e)
3126 Desktop.explodeViews(this);
3130 * Gather views in separate windows back into a tabbed presentation.
3133 public void gatherViews_actionPerformed(ActionEvent e)
3135 Desktop.instance.gatherViews(this);
3145 public void font_actionPerformed(ActionEvent e)
3147 new FontChooser(alignPanel);
3157 protected void seqLimit_actionPerformed(ActionEvent e)
3159 viewport.setShowJVSuffix(seqLimits.isSelected());
3161 alignPanel.getIdPanel().getIdCanvas()
3162 .setPreferredSize(alignPanel.calculateIdWidth());
3163 alignPanel.paintAlignment(true, false);
3167 public void idRightAlign_actionPerformed(ActionEvent e)
3169 viewport.setRightAlignIds(idRightAlign.isSelected());
3170 alignPanel.paintAlignment(false, false);
3174 public void centreColumnLabels_actionPerformed(ActionEvent e)
3176 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3177 alignPanel.paintAlignment(false, false);
3183 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3186 protected void followHighlight_actionPerformed()
3189 * Set the 'follow' flag on the Viewport (and scroll to position if now
3192 final boolean state = this.followHighlightMenuItem.getState();
3193 viewport.setFollowHighlight(state);
3196 alignPanel.scrollToPosition(viewport.getSearchResults());
3207 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3209 viewport.setColourText(colourTextMenuItem.isSelected());
3210 alignPanel.paintAlignment(false, false);
3220 public void wrapMenuItem_actionPerformed(ActionEvent e)
3222 scaleAbove.setVisible(wrapMenuItem.isSelected());
3223 scaleLeft.setVisible(wrapMenuItem.isSelected());
3224 scaleRight.setVisible(wrapMenuItem.isSelected());
3225 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3226 alignPanel.updateLayout();
3230 public void showAllSeqs_actionPerformed(ActionEvent e)
3232 viewport.showAllHiddenSeqs();
3236 public void showAllColumns_actionPerformed(ActionEvent e)
3238 viewport.showAllHiddenColumns();
3239 alignPanel.paintAlignment(true, true);
3240 viewport.sendSelection();
3244 public void hideSelSequences_actionPerformed(ActionEvent e)
3246 viewport.hideAllSelectedSeqs();
3250 * called by key handler and the hide all/show all menu items
3255 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3258 boolean hide = false;
3259 SequenceGroup sg = viewport.getSelectionGroup();
3260 if (!toggleSeqs && !toggleCols)
3262 // Hide everything by the current selection - this is a hack - we do the
3263 // invert and then hide
3264 // first check that there will be visible columns after the invert.
3265 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3266 && sg.getStartRes() <= sg.getEndRes()))
3268 // now invert the sequence set, if required - empty selection implies
3269 // that no hiding is required.
3272 invertSequenceMenuItem_actionPerformed(null);
3273 sg = viewport.getSelectionGroup();
3277 viewport.expandColSelection(sg, true);
3278 // finally invert the column selection and get the new sequence
3280 invertColSel_actionPerformed(null);
3287 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3289 hideSelSequences_actionPerformed(null);
3292 else if (!(toggleCols && viewport.hasSelectedColumns()))
3294 showAllSeqs_actionPerformed(null);
3300 if (viewport.hasSelectedColumns())
3302 hideSelColumns_actionPerformed(null);
3305 viewport.setSelectionGroup(sg);
3310 showAllColumns_actionPerformed(null);
3319 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3320 * event.ActionEvent)
3323 public void hideAllButSelection_actionPerformed(ActionEvent e)
3325 toggleHiddenRegions(false, false);
3326 viewport.sendSelection();
3333 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3337 public void hideAllSelection_actionPerformed(ActionEvent e)
3339 SequenceGroup sg = viewport.getSelectionGroup();
3340 viewport.expandColSelection(sg, false);
3341 viewport.hideAllSelectedSeqs();
3342 viewport.hideSelectedColumns();
3343 alignPanel.updateLayout();
3344 alignPanel.paintAlignment(true, true);
3345 viewport.sendSelection();
3352 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3356 public void showAllhidden_actionPerformed(ActionEvent e)
3358 viewport.showAllHiddenColumns();
3359 viewport.showAllHiddenSeqs();
3360 alignPanel.paintAlignment(true, true);
3361 viewport.sendSelection();
3365 public void hideSelColumns_actionPerformed(ActionEvent e)
3367 viewport.hideSelectedColumns();
3368 alignPanel.updateLayout();
3369 alignPanel.paintAlignment(true, true);
3370 viewport.sendSelection();
3374 public void hiddenMarkers_actionPerformed(ActionEvent e)
3376 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3387 protected void scaleAbove_actionPerformed(ActionEvent e)
3389 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3390 alignPanel.updateLayout();
3391 alignPanel.paintAlignment(true, false);
3401 protected void scaleLeft_actionPerformed(ActionEvent e)
3403 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3404 alignPanel.updateLayout();
3405 alignPanel.paintAlignment(true, false);
3415 protected void scaleRight_actionPerformed(ActionEvent e)
3417 viewport.setScaleRightWrapped(scaleRight.isSelected());
3418 alignPanel.updateLayout();
3419 alignPanel.paintAlignment(true, false);
3429 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3431 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3432 alignPanel.paintAlignment(false, false);
3442 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3444 viewport.setShowText(viewTextMenuItem.isSelected());
3445 alignPanel.paintAlignment(false, false);
3455 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3457 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3458 alignPanel.paintAlignment(false, false);
3461 public FeatureSettings featureSettings;
3464 public FeatureSettingsControllerI getFeatureSettingsUI()
3466 return featureSettings;
3470 public void featureSettings_actionPerformed(ActionEvent e)
3472 showFeatureSettingsUI();
3476 public FeatureSettingsControllerI showFeatureSettingsUI()
3478 if (featureSettings != null)
3480 featureSettings.closeOldSettings();
3481 featureSettings = null;
3483 if (!showSeqFeatures.isSelected())
3485 // make sure features are actually displayed
3486 showSeqFeatures.setSelected(true);
3487 showSeqFeatures_actionPerformed(null);
3489 featureSettings = new FeatureSettings(this);
3490 return featureSettings;
3494 * Set or clear 'Show Sequence Features'
3500 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3502 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3503 alignPanel.paintAlignment(true, true);
3507 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3508 * the annotations panel as a whole.
3510 * The options to show/hide all annotations should be enabled when the panel
3511 * is shown, and disabled when the panel is hidden.
3516 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3518 final boolean setVisible = annotationPanelMenuItem.isSelected();
3519 viewport.setShowAnnotation(setVisible);
3520 this.showAllSeqAnnotations.setEnabled(setVisible);
3521 this.hideAllSeqAnnotations.setEnabled(setVisible);
3522 this.showAllAlAnnotations.setEnabled(setVisible);
3523 this.hideAllAlAnnotations.setEnabled(setVisible);
3524 alignPanel.updateLayout();
3528 public void alignmentProperties()
3530 JEditorPane editPane = new JEditorPane("text/html", "");
3531 editPane.setEditable(false);
3532 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3535 MessageManager.formatMessage("label.html_content", new Object[]
3536 { contents.toString() }));
3537 JInternalFrame frame = new JInternalFrame();
3538 frame.getContentPane().add(new JScrollPane(editPane));
3540 Desktop.addInternalFrame(frame, MessageManager
3541 .formatMessage("label.alignment_properties", new Object[]
3542 { getTitle() }), 500, 400);
3552 public void overviewMenuItem_actionPerformed(ActionEvent e)
3554 if (alignPanel.overviewPanel != null)
3559 JInternalFrame frame = new JInternalFrame();
3560 final OverviewPanel overview = new OverviewPanel(alignPanel);
3561 frame.setContentPane(overview);
3562 Desktop.addInternalFrame(frame, MessageManager
3563 .formatMessage("label.overview_params", new Object[]
3564 { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
3567 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3568 frame.addInternalFrameListener(
3569 new javax.swing.event.InternalFrameAdapter()
3572 public void internalFrameClosed(
3573 javax.swing.event.InternalFrameEvent evt)
3576 alignPanel.setOverviewPanel(null);
3579 if (getKeyListeners().length > 0)
3581 frame.addKeyListener(getKeyListeners()[0]);
3584 alignPanel.setOverviewPanel(overview);
3588 public void textColour_actionPerformed()
3590 new TextColourChooser().chooseColour(alignPanel, null);
3594 * public void covariationColour_actionPerformed() {
3596 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3600 public void annotationColour_actionPerformed()
3602 new AnnotationColourChooser(viewport, alignPanel);
3606 public void annotationColumn_actionPerformed(ActionEvent e)
3608 new AnnotationColumnChooser(viewport, alignPanel);
3612 * Action on the user checking or unchecking the option to apply the selected
3613 * colour scheme to all groups. If unchecked, groups may have their own
3614 * independent colour schemes.
3619 public void applyToAllGroups_actionPerformed(boolean selected)
3621 viewport.setColourAppliesToAllGroups(selected);
3625 * Action on user selecting a colour from the colour menu
3628 * the name (not the menu item label!) of the colour scheme
3631 public void changeColour_actionPerformed(String name)
3634 * 'User Defined' opens a panel to configure or load a
3635 * user-defined colour scheme
3637 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3639 new UserDefinedColours(alignPanel);
3644 * otherwise set the chosen colour scheme (or null for 'None')
3646 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3648 viewport.getAlignment(), viewport.getHiddenRepSequences());
3653 * Actions on setting or changing the alignment colour scheme
3658 public void changeColour(ColourSchemeI cs)
3660 // TODO: pull up to controller method
3661 ColourMenuHelper.setColourSelected(colourMenu, cs);
3663 viewport.setGlobalColourScheme(cs);
3665 alignPanel.paintAlignment(true, true);
3669 * Show the PID threshold slider panel
3672 protected void modifyPID_actionPerformed()
3674 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3675 alignPanel.getViewName());
3676 SliderPanel.showPIDSlider();
3680 * Show the Conservation slider panel
3683 protected void modifyConservation_actionPerformed()
3685 SliderPanel.setConservationSlider(alignPanel,
3686 viewport.getResidueShading(), alignPanel.getViewName());
3687 SliderPanel.showConservationSlider();
3691 * Action on selecting or deselecting (Colour) By Conservation
3694 public void conservationMenuItem_actionPerformed(boolean selected)
3696 modifyConservation.setEnabled(selected);
3697 viewport.setConservationSelected(selected);
3698 viewport.getResidueShading().setConservationApplied(selected);
3700 changeColour(viewport.getGlobalColourScheme());
3703 modifyConservation_actionPerformed();
3707 SliderPanel.hideConservationSlider();
3712 * Action on selecting or deselecting (Colour) Above PID Threshold
3715 public void abovePIDThreshold_actionPerformed(boolean selected)
3717 modifyPID.setEnabled(selected);
3718 viewport.setAbovePIDThreshold(selected);
3721 viewport.getResidueShading().setThreshold(0,
3722 viewport.isIgnoreGapsConsensus());
3725 changeColour(viewport.getGlobalColourScheme());
3728 modifyPID_actionPerformed();
3732 SliderPanel.hidePIDSlider();
3743 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3745 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3746 AlignmentSorter.sortByPID(viewport.getAlignment(),
3747 viewport.getAlignment().getSequenceAt(0));
3748 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3749 viewport.getAlignment()));
3750 alignPanel.paintAlignment(true, false);
3760 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3762 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3763 AlignmentSorter.sortByID(viewport.getAlignment());
3765 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3766 alignPanel.paintAlignment(true, false);
3776 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3778 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3779 AlignmentSorter.sortByLength(viewport.getAlignment());
3780 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3781 viewport.getAlignment()));
3782 alignPanel.paintAlignment(true, false);
3792 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3794 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3795 AlignmentSorter.sortByGroup(viewport.getAlignment());
3796 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3797 viewport.getAlignment()));
3799 alignPanel.paintAlignment(true, false);
3803 public void sortEValueMenuItem_actionPerformed(ActionEvent e)
3805 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3806 AlignmentSorter.sortByEValue(viewport.getAlignment());
3807 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3808 viewport.getAlignment()));
3809 alignPanel.paintAlignment(true, false);
3814 public void sortBitScoreMenuItem_actionPerformed(ActionEvent e)
3816 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3817 AlignmentSorter.sortByBitScore(viewport.getAlignment());
3818 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3819 viewport.getAlignment()));
3820 alignPanel.paintAlignment(true, false);
3831 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3833 new RedundancyPanel(alignPanel, this);
3843 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3845 if ((viewport.getSelectionGroup() == null)
3846 || (viewport.getSelectionGroup().getSize() < 2))
3848 JvOptionPane.showInternalMessageDialog(this,
3849 MessageManager.getString(
3850 "label.you_must_select_least_two_sequences"),
3851 MessageManager.getString("label.invalid_selection"),
3852 JvOptionPane.WARNING_MESSAGE);
3856 JInternalFrame frame = new JInternalFrame();
3857 frame.setContentPane(new PairwiseAlignPanel(viewport));
3858 Desktop.addInternalFrame(frame,
3859 MessageManager.getString("action.pairwise_alignment"), 600,
3865 public void autoCalculate_actionPerformed(ActionEvent e)
3867 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3868 if (viewport.autoCalculateConsensus)
3870 viewport.firePropertyChange("alignment", null,
3871 viewport.getAlignment().getSequences());
3876 public void sortByTreeOption_actionPerformed(ActionEvent e)
3878 viewport.sortByTree = sortByTree.isSelected();
3882 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3884 viewport.followSelection = listenToViewSelections.isSelected();
3888 * Constructs a tree panel and adds it to the desktop
3891 * tree type (NJ or AV)
3893 * name of score model used to compute the tree
3895 * parameters for the distance or similarity calculation
3897 void newTreePanel(String type, String modelName,
3898 SimilarityParamsI options)
3900 String frameTitle = "";
3903 boolean onSelection = false;
3904 if (viewport.getSelectionGroup() != null
3905 && viewport.getSelectionGroup().getSize() > 0)
3907 SequenceGroup sg = viewport.getSelectionGroup();
3909 /* Decide if the selection is a column region */
3910 for (SequenceI _s : sg.getSequences())
3912 if (_s.getLength() < sg.getEndRes())
3914 JvOptionPane.showMessageDialog(Desktop.desktop,
3915 MessageManager.getString(
3916 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3917 MessageManager.getString(
3918 "label.sequences_selection_not_aligned"),
3919 JvOptionPane.WARNING_MESSAGE);
3928 if (viewport.getAlignment().getHeight() < 2)
3934 tp = new TreePanel(alignPanel, type, modelName, options);
3935 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3937 frameTitle += " from ";
3939 if (viewport.getViewName() != null)
3941 frameTitle += viewport.getViewName() + " of ";
3944 frameTitle += this.title;
3946 Desktop.addInternalFrame(tp, frameTitle, 600, 500);
3957 public void addSortByOrderMenuItem(String title,
3958 final AlignmentOrder order)
3960 final JMenuItem item = new JMenuItem(MessageManager
3961 .formatMessage("action.by_title_param", new Object[]
3964 item.addActionListener(new java.awt.event.ActionListener()
3967 public void actionPerformed(ActionEvent e)
3969 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3971 // TODO: JBPNote - have to map order entries to curent SequenceI
3973 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3975 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3976 viewport.getAlignment()));
3978 alignPanel.paintAlignment(true, false);
3984 * Add a new sort by annotation score menu item
3987 * the menu to add the option to
3989 * the label used to retrieve scores for each sequence on the
3992 public void addSortByAnnotScoreMenuItem(JMenu sort,
3993 final String scoreLabel)
3995 final JMenuItem item = new JMenuItem(scoreLabel);
3997 item.addActionListener(new java.awt.event.ActionListener()
4000 public void actionPerformed(ActionEvent e)
4002 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4003 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4004 viewport.getAlignment());// ,viewport.getSelectionGroup());
4005 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4006 viewport.getAlignment()));
4007 alignPanel.paintAlignment(true, false);
4013 * last hash for alignment's annotation array - used to minimise cost of
4016 protected int _annotationScoreVectorHash;
4019 * search the alignment and rebuild the sort by annotation score submenu the
4020 * last alignment annotation vector hash is stored to minimize cost of
4021 * rebuilding in subsequence calls.
4025 public void buildSortByAnnotationScoresMenu()
4027 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4032 if (viewport.getAlignment().getAlignmentAnnotation()
4033 .hashCode() == _annotationScoreVectorHash)
4038 sortByAnnotScore.removeAll();
4039 Set<String> scoreSorts = new HashSet<>();
4040 for (SequenceI sqa : viewport.getAlignment().getSequences())
4042 AlignmentAnnotation[] anns = sqa.getAnnotation();
4043 for (int i = 0; anns != null && i < anns.length; i++)
4045 AlignmentAnnotation aa = anns[i];
4046 if (aa != null && aa.hasScore() && aa.sequenceRef != null)
4048 scoreSorts.add(aa.label);
4052 for (String label : scoreSorts)
4054 addSortByAnnotScoreMenuItem(sortByAnnotScore, label);
4056 sortByAnnotScore.setVisible(!scoreSorts.isEmpty());
4058 _annotationScoreVectorHash = viewport.getAlignment()
4059 .getAlignmentAnnotation().hashCode();
4063 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4064 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4065 * call. Listeners are added to remove the menu item when the treePanel is
4066 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4070 public void buildTreeSortMenu()
4072 sortByTreeMenu.removeAll();
4074 List<Component> comps = PaintRefresher.components
4075 .get(viewport.getSequenceSetId());
4076 List<TreePanel> treePanels = new ArrayList<>();
4077 for (Component comp : comps)
4079 if (comp instanceof TreePanel)
4081 treePanels.add((TreePanel) comp);
4085 if (treePanels.size() < 1)
4087 sortByTreeMenu.setVisible(false);
4091 sortByTreeMenu.setVisible(true);
4093 for (final TreePanel tp : treePanels)
4095 final JMenuItem item = new JMenuItem(tp.getTitle());
4096 item.addActionListener(new java.awt.event.ActionListener()
4099 public void actionPerformed(ActionEvent e)
4101 tp.sortByTree_actionPerformed();
4102 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4107 sortByTreeMenu.add(item);
4111 public boolean sortBy(AlignmentOrder alorder, String undoname)
4113 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4114 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4115 if (undoname != null)
4117 addHistoryItem(new OrderCommand(undoname, oldOrder,
4118 viewport.getAlignment()));
4120 alignPanel.paintAlignment(true, false);
4125 * Work out whether the whole set of sequences or just the selected set will
4126 * be submitted for multiple alignment.
4129 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4131 // Now, check we have enough sequences
4132 AlignmentView msa = null;
4134 if ((viewport.getSelectionGroup() != null)
4135 && (viewport.getSelectionGroup().getSize() > 1))
4137 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4138 // some common interface!
4140 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4141 * SequenceI[sz = seqs.getSize(false)];
4143 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4144 * seqs.getSequenceAt(i); }
4146 msa = viewport.getAlignmentView(true);
4148 else if (viewport.getSelectionGroup() != null
4149 && viewport.getSelectionGroup().getSize() == 1)
4151 int option = JvOptionPane.showConfirmDialog(this,
4152 MessageManager.getString("warn.oneseq_msainput_selection"),
4153 MessageManager.getString("label.invalid_selection"),
4154 JvOptionPane.OK_CANCEL_OPTION);
4155 if (option == JvOptionPane.OK_OPTION)
4157 msa = viewport.getAlignmentView(false);
4162 msa = viewport.getAlignmentView(false);
4168 * Decides what is submitted to a secondary structure prediction service: the
4169 * first sequence in the alignment, or in the current selection, or, if the
4170 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4171 * region or the whole alignment. (where the first sequence in the set is the
4172 * one that the prediction will be for).
4174 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4176 AlignmentView seqs = null;
4178 if ((viewport.getSelectionGroup() != null)
4179 && (viewport.getSelectionGroup().getSize() > 0))
4181 seqs = viewport.getAlignmentView(true);
4185 seqs = viewport.getAlignmentView(false);
4187 // limit sequences - JBPNote in future - could spawn multiple prediction
4189 // TODO: viewport.getAlignment().isAligned is a global state - the local
4190 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4191 if (!viewport.getAlignment().isAligned(false))
4193 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4194 // TODO: if seqs.getSequences().length>1 then should really have warned
4208 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4210 // Pick the tree file
4211 JalviewFileChooser chooser = new JalviewFileChooser(
4212 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4213 chooser.setFileView(new JalviewFileView());
4214 chooser.setDialogTitle(
4215 MessageManager.getString("label.select_newick_like_tree_file"));
4216 chooser.setToolTipText(
4217 MessageManager.getString("label.load_tree_file"));
4219 int value = chooser.showOpenDialog(null);
4221 if (value == JalviewFileChooser.APPROVE_OPTION)
4223 String filePath = chooser.getSelectedFile().getPath();
4224 Cache.setProperty("LAST_DIRECTORY", filePath);
4225 NewickFile fin = null;
4228 fin = new NewickFile(filePath, DataSourceType.FILE);
4229 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4230 } catch (Exception ex)
4232 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4233 MessageManager.getString("label.problem_reading_tree_file"),
4234 JvOptionPane.WARNING_MESSAGE);
4235 ex.printStackTrace();
4237 if (fin != null && fin.hasWarningMessage())
4239 JvOptionPane.showMessageDialog(Desktop.desktop,
4240 fin.getWarningMessage(),
4242 .getString("label.possible_problem_with_tree_file"),
4243 JvOptionPane.WARNING_MESSAGE);
4248 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4250 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4253 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4254 int h, int x, int y)
4256 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4260 * Add a treeviewer for the tree extracted from a Newick file object to the
4261 * current alignment view
4268 * Associated alignment input data (or null)
4277 * @return TreePanel handle
4279 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4280 AlignmentView input, int w, int h, int x, int y)
4282 TreePanel tp = null;
4288 if (nf.getTree() != null)
4290 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4296 tp.setLocation(x, y);
4299 Desktop.addInternalFrame(tp, treeTitle, w, h);
4301 } catch (Exception ex)
4303 ex.printStackTrace();
4309 private boolean buildingMenu = false;
4312 * Generates menu items and listener event actions for web service clients
4315 public void BuildWebServiceMenu()
4317 while (buildingMenu)
4321 System.err.println("Waiting for building menu to finish.");
4323 } catch (Exception e)
4327 final AlignFrame me = this;
4328 buildingMenu = true;
4329 new Thread(new Runnable()
4334 final List<JMenuItem> legacyItems = new ArrayList<>();
4337 // System.err.println("Building ws menu again "
4338 // + Thread.currentThread());
4339 // TODO: add support for context dependent disabling of services based
4341 // alignment and current selection
4342 // TODO: add additional serviceHandle parameter to specify abstract
4344 // class independently of AbstractName
4345 // TODO: add in rediscovery GUI function to restart discoverer
4346 // TODO: group services by location as well as function and/or
4348 // object broker mechanism.
4349 final Vector<JMenu> wsmenu = new Vector<>();
4350 final IProgressIndicator af = me;
4353 * do not i18n these strings - they are hard-coded in class
4354 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4355 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4357 final JMenu msawsmenu = new JMenu("Alignment");
4358 final JMenu secstrmenu = new JMenu(
4359 "Secondary Structure Prediction");
4360 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4361 final JMenu analymenu = new JMenu("Analysis");
4362 final JMenu dismenu = new JMenu("Protein Disorder");
4363 // JAL-940 - only show secondary structure prediction services from
4364 // the legacy server
4365 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4367 Discoverer.services != null && (Discoverer.services.size() > 0))
4369 // TODO: refactor to allow list of AbstractName/Handler bindings to
4371 // stored or retrieved from elsewhere
4372 // No MSAWS used any more:
4373 // Vector msaws = null; // (Vector)
4374 // Discoverer.services.get("MsaWS");
4375 Vector secstrpr = (Vector) Discoverer.services
4377 if (secstrpr != null)
4379 // Add any secondary structure prediction services
4380 for (int i = 0, j = secstrpr.size(); i < j; i++)
4382 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4384 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4385 .getServiceClient(sh);
4386 int p = secstrmenu.getItemCount();
4387 impl.attachWSMenuEntry(secstrmenu, me);
4388 int q = secstrmenu.getItemCount();
4389 for (int litm = p; litm < q; litm++)
4391 legacyItems.add(secstrmenu.getItem(litm));
4397 // Add all submenus in the order they should appear on the web
4399 wsmenu.add(msawsmenu);
4400 wsmenu.add(secstrmenu);
4401 wsmenu.add(dismenu);
4402 wsmenu.add(analymenu);
4403 // No search services yet
4404 // wsmenu.add(seqsrchmenu);
4406 javax.swing.SwingUtilities.invokeLater(new Runnable()
4413 webService.removeAll();
4414 // first, add discovered services onto the webservices menu
4415 if (wsmenu.size() > 0)
4417 for (int i = 0, j = wsmenu.size(); i < j; i++)
4419 webService.add(wsmenu.get(i));
4424 webService.add(me.webServiceNoServices);
4426 // TODO: move into separate menu builder class.
4427 boolean new_sspred = false;
4428 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4430 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4431 if (jws2servs != null)
4433 if (jws2servs.hasServices())
4435 jws2servs.attachWSMenuEntry(webService, me);
4436 for (ServiceWithParameters sv : jws2servs.getServices())
4438 if (sv.getName().toLowerCase().contains("jpred"))
4440 for (JMenuItem jmi : legacyItems)
4442 jmi.setVisible(false);
4448 if (jws2servs.isRunning())
4450 JMenuItem tm = new JMenuItem(
4451 "Still discovering JABA Services");
4452 tm.setEnabled(false);
4457 build_urlServiceMenu(me.webService);
4460 // TODO Mateusz - follow pattern for adding web service
4461 // JMenuItems for slivka-based services
4463 SlivkaWSDiscoverer slivkaDiscoverer = SlivkaWSDiscoverer.getInstance();
4464 if (slivkaDiscoverer.hasServices())
4466 slivkaDiscoverer.attachWSMenuEntry(webService, me);
4468 if (slivkaDiscoverer.isRunning())
4471 JMenuItem tm = new JMenuItem(
4472 "Still discovering Slivka Services");
4473 tm.setEnabled(false);
4481 build_fetchdbmenu(webService);
4482 for (JMenu item : wsmenu)
4484 if (item.getItemCount() == 0)
4486 item.setEnabled(false);
4490 item.setEnabled(true);
4493 } catch (Exception e)
4496 "Exception during web service menu building process.",
4501 } catch (Exception e)
4504 buildingMenu = false;
4511 * construct any groupURL type service menu entries.
4515 private void build_urlServiceMenu(JMenu webService)
4517 // TODO: remove this code when 2.7 is released
4518 // DEBUG - alignmentView
4520 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4521 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4523 * @Override public void actionPerformed(ActionEvent e) {
4524 * jalview.datamodel.AlignmentView
4525 * .testSelectionViews(af.viewport.getAlignment(),
4526 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4528 * }); webService.add(testAlView);
4530 // TODO: refactor to RestClient discoverer and merge menu entries for
4531 // rest-style services with other types of analysis/calculation service
4532 // SHmmr test client - still being implemented.
4533 // DEBUG - alignmentView
4535 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4538 client.attachWSMenuEntry(
4539 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4545 * Searches the alignment sequences for xRefs and builds the Show
4546 * Cross-References menu (formerly called Show Products), with database
4547 * sources for which cross-references are found (protein sources for a
4548 * nucleotide alignment and vice versa)
4550 * @return true if Show Cross-references menu should be enabled
4552 public boolean canShowProducts()
4554 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4555 AlignmentI dataset = viewport.getAlignment().getDataset();
4557 showProducts.removeAll();
4558 final boolean dna = viewport.getAlignment().isNucleotide();
4560 if (seqs == null || seqs.length == 0)
4562 // nothing to see here.
4566 boolean showp = false;
4569 List<String> ptypes = new CrossRef(seqs, dataset)
4570 .findXrefSourcesForSequences(dna);
4572 for (final String source : ptypes)
4575 final AlignFrame af = this;
4576 JMenuItem xtype = new JMenuItem(source);
4577 xtype.addActionListener(new ActionListener()
4580 public void actionPerformed(ActionEvent e)
4582 showProductsFor(af.viewport.getSequenceSelection(), dna,
4586 showProducts.add(xtype);
4588 showProducts.setVisible(showp);
4589 showProducts.setEnabled(showp);
4590 } catch (Exception e)
4593 "canShowProducts threw an exception - please report to help@jalview.org",
4601 * Finds and displays cross-references for the selected sequences (protein
4602 * products for nucleotide sequences, dna coding sequences for peptides).
4605 * the sequences to show cross-references for
4607 * true if from a nucleotide alignment (so showing proteins)
4609 * the database to show cross-references for
4611 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4612 final String source)
4614 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4619 * Construct and display a new frame containing the translation of this
4620 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4623 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4625 AlignmentI al = null;
4628 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4630 al = dna.translateCdna(codeTable);
4631 } catch (Exception ex)
4633 jalview.bin.Cache.log.error(
4634 "Exception during translation. Please report this !", ex);
4635 final String msg = MessageManager.getString(
4636 "label.error_when_translating_sequences_submit_bug_report");
4637 final String errorTitle = MessageManager
4638 .getString("label.implementation_error")
4639 + MessageManager.getString("label.translation_failed");
4640 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4641 JvOptionPane.ERROR_MESSAGE);
4644 if (al == null || al.getHeight() == 0)
4646 final String msg = MessageManager.getString(
4647 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4648 final String errorTitle = MessageManager
4649 .getString("label.translation_failed");
4650 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4651 JvOptionPane.WARNING_MESSAGE);
4655 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4656 af.setFileFormat(this.currentFileFormat);
4657 final String newTitle = MessageManager
4658 .formatMessage("label.translation_of_params", new Object[]
4659 { this.getTitle(), codeTable.getId() });
4660 af.setTitle(newTitle);
4661 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4663 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4664 viewport.openSplitFrame(af, new Alignment(seqs));
4668 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4675 * Set the file format
4679 public void setFileFormat(FileFormatI format)
4681 this.currentFileFormat = format;
4685 * Try to load a features file onto the alignment.
4688 * contents or path to retrieve file
4690 * access mode of file (see jalview.io.AlignFile)
4691 * @return true if features file was parsed correctly.
4693 public boolean parseFeaturesFile(String file, DataSourceType sourceType)
4695 return avc.parseFeaturesFile(file, sourceType,
4696 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4701 public void refreshFeatureUI(boolean enableIfNecessary)
4703 // note - currently this is only still here rather than in the controller
4704 // because of the featureSettings hard reference that is yet to be
4706 if (enableIfNecessary)
4708 viewport.setShowSequenceFeatures(true);
4709 showSeqFeatures.setSelected(true);
4715 public void dragEnter(DropTargetDragEvent evt)
4720 public void dragExit(DropTargetEvent evt)
4725 public void dragOver(DropTargetDragEvent evt)
4730 public void dropActionChanged(DropTargetDragEvent evt)
4735 public void drop(DropTargetDropEvent evt)
4737 // JAL-1552 - acceptDrop required before getTransferable call for
4738 // Java's Transferable for native dnd
4739 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4740 Transferable t = evt.getTransferable();
4741 final AlignFrame thisaf = this;
4742 final List<String> files = new ArrayList<>();
4743 List<DataSourceType> protocols = new ArrayList<>();
4747 Desktop.transferFromDropTarget(files, protocols, evt, t);
4748 } catch (Exception e)
4750 e.printStackTrace();
4754 new Thread(new Runnable()
4761 // check to see if any of these files have names matching sequences
4764 SequenceIdMatcher idm = new SequenceIdMatcher(
4765 viewport.getAlignment().getSequencesArray());
4767 * Object[] { String,SequenceI}
4769 ArrayList<Object[]> filesmatched = new ArrayList<>();
4770 ArrayList<String> filesnotmatched = new ArrayList<>();
4771 for (int i = 0; i < files.size(); i++)
4773 String file = files.get(i).toString();
4775 DataSourceType protocol = FormatAdapter.checkProtocol(file);
4776 if (protocol == DataSourceType.FILE)
4778 File fl = new File(file);
4779 pdbfn = fl.getName();
4781 else if (protocol == DataSourceType.URL)
4783 URL url = new URL(file);
4784 pdbfn = url.getFile();
4786 if (pdbfn.length() > 0)
4788 // attempt to find a match in the alignment
4789 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4790 int l = 0, c = pdbfn.indexOf(".");
4791 while (mtch == null && c != -1)
4796 } while ((c = pdbfn.indexOf(".", l)) > l);
4799 pdbfn = pdbfn.substring(0, l);
4801 mtch = idm.findAllIdMatches(pdbfn);
4805 FileFormatI type = null;
4808 type = new IdentifyFile().identify(file, protocol);
4809 } catch (Exception ex)
4813 if (type != null && type.isStructureFile())
4815 filesmatched.add(new Object[] { file, protocol, mtch });
4819 // File wasn't named like one of the sequences or wasn't a PDB
4821 filesnotmatched.add(file);
4825 if (filesmatched.size() > 0)
4827 boolean autoAssociate = Cache
4828 .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
4831 String msg = MessageManager.formatMessage(
4832 "label.automatically_associate_structure_files_with_sequences_same_name",
4834 { Integer.valueOf(filesmatched.size())
4836 String ttl = MessageManager.getString(
4837 "label.automatically_associate_structure_files_by_name");
4838 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4839 ttl, JvOptionPane.YES_NO_OPTION);
4840 autoAssociate = choice == JvOptionPane.YES_OPTION;
4844 for (Object[] fm : filesmatched)
4846 // try and associate
4847 // TODO: may want to set a standard ID naming formalism for
4848 // associating PDB files which have no IDs.
4849 for (SequenceI toassoc : (SequenceI[]) fm[2])
4851 PDBEntry pe = new AssociatePdbFileWithSeq()
4852 .associatePdbWithSeq((String) fm[0],
4853 (DataSourceType) fm[1], toassoc, false,
4857 System.err.println("Associated file : "
4858 + ((String) fm[0]) + " with "
4859 + toassoc.getDisplayId(true));
4863 // TODO: do we need to update overview ? only if features are
4865 alignPanel.paintAlignment(true, false);
4871 * add declined structures as sequences
4873 for (Object[] o : filesmatched)
4875 filesnotmatched.add((String) o[0]);
4879 if (filesnotmatched.size() > 0)
4881 if (assocfiles > 0 && (Cache.getDefault(
4882 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4883 || JvOptionPane.showConfirmDialog(thisaf,
4884 "<html>" + MessageManager.formatMessage(
4885 "label.ignore_unmatched_dropped_files_info",
4888 filesnotmatched.size())
4891 MessageManager.getString(
4892 "label.ignore_unmatched_dropped_files"),
4893 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4897 for (String fn : filesnotmatched)
4899 loadJalviewDataFile(fn, null, null, null);
4903 } catch (Exception ex)
4905 ex.printStackTrace();
4913 * Attempt to load a "dropped" file or URL string, by testing in turn for
4915 * <li>an Annotation file</li>
4916 * <li>a JNet file</li>
4917 * <li>a features file</li>
4918 * <li>else try to interpret as an alignment file</li>
4922 * either a filename or a URL string.
4923 * @throws InterruptedException
4924 * @throws IOException
4926 public void loadJalviewDataFile(String file, DataSourceType sourceType,
4927 FileFormatI format, SequenceI assocSeq)
4931 if (sourceType == null)
4933 sourceType = FormatAdapter.checkProtocol(file);
4935 // if the file isn't identified, or not positively identified as some
4936 // other filetype (PFAM is default unidentified alignment file type) then
4937 // try to parse as annotation.
4938 boolean isAnnotation = (format == null
4939 || FileFormat.Pfam.equals(format))
4940 ? new AnnotationFile().annotateAlignmentView(viewport,
4946 // first see if its a T-COFFEE score file
4947 TCoffeeScoreFile tcf = null;
4950 tcf = new TCoffeeScoreFile(file, sourceType);
4953 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4957 new TCoffeeColourScheme(viewport.getAlignment()));
4958 isAnnotation = true;
4959 statusBar.setText(MessageManager.getString(
4960 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4964 // some problem - if no warning its probable that the ID matching
4965 // process didn't work
4966 JvOptionPane.showMessageDialog(Desktop.desktop,
4967 tcf.getWarningMessage() == null
4968 ? MessageManager.getString(
4969 "label.check_file_matches_sequence_ids_alignment")
4970 : tcf.getWarningMessage(),
4971 MessageManager.getString(
4972 "label.problem_reading_tcoffee_score_file"),
4973 JvOptionPane.WARNING_MESSAGE);
4980 } catch (Exception x)
4983 "Exception when processing data source as T-COFFEE score file",
4989 // try to see if its a JNet 'concise' style annotation file *before*
4991 // try to parse it as a features file
4994 format = new IdentifyFile().identify(file, sourceType);
4996 if (FileFormat.ScoreMatrix == format)
4998 ScoreMatrixFile sm = new ScoreMatrixFile(
4999 new FileParse(file, sourceType));
5001 // todo: i18n this message
5002 statusBar.setText(MessageManager.formatMessage(
5003 "label.successfully_loaded_matrix",
5004 sm.getMatrixName()));
5006 else if (FileFormat.Jnet.equals(format))
5008 JPredFile predictions = new JPredFile(file, sourceType);
5009 new JnetAnnotationMaker();
5010 JnetAnnotationMaker.add_annotation(predictions,
5011 viewport.getAlignment(), 0, false);
5012 viewport.getAlignment().setupJPredAlignment();
5013 isAnnotation = true;
5015 // else if (IdentifyFile.FeaturesFile.equals(format))
5016 else if (FileFormat.Features.equals(format))
5018 if (parseFeaturesFile(file, sourceType))
5020 SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
5021 if (splitFrame != null)
5023 splitFrame.repaint();
5027 alignPanel.paintAlignment(true, true);
5033 new FileLoader().LoadFile(viewport, file, sourceType, format);
5039 alignPanel.adjustAnnotationHeight();
5040 viewport.updateSequenceIdColours();
5041 buildSortByAnnotationScoresMenu();
5042 alignPanel.paintAlignment(true, true);
5044 } catch (Exception ex)
5046 ex.printStackTrace();
5047 } catch (OutOfMemoryError oom)
5052 } catch (Exception x)
5057 + (sourceType != null
5058 ? (sourceType == DataSourceType.PASTE
5060 : "using " + sourceType + " from "
5064 ? "(parsing as '" + format + "' file)"
5066 oom, Desktop.desktop);
5071 * Method invoked by the ChangeListener on the tabbed pane, in other words
5072 * when a different tabbed pane is selected by the user or programmatically.
5075 public void tabSelectionChanged(int index)
5079 alignPanel = alignPanels.get(index);
5080 viewport = alignPanel.av;
5081 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5082 setMenusFromViewport(viewport);
5083 if (featureSettings != null && featureSettings.isOpen()
5084 && featureSettings.fr.getViewport() != viewport)
5086 if (viewport.isShowSequenceFeatures())
5088 // refresh the featureSettings to reflect UI change
5089 showFeatureSettingsUI();
5093 // close feature settings for this view.
5094 featureSettings.close();
5101 * 'focus' any colour slider that is open to the selected viewport
5103 if (viewport.getConservationSelected())
5105 SliderPanel.setConservationSlider(alignPanel,
5106 viewport.getResidueShading(), alignPanel.getViewName());
5110 SliderPanel.hideConservationSlider();
5112 if (viewport.getAbovePIDThreshold())
5114 SliderPanel.setPIDSliderSource(alignPanel,
5115 viewport.getResidueShading(), alignPanel.getViewName());
5119 SliderPanel.hidePIDSlider();
5123 * If there is a frame linked to this one in a SplitPane, switch it to the
5124 * same view tab index. No infinite recursion of calls should happen, since
5125 * tabSelectionChanged() should not get invoked on setting the selected
5126 * index to an unchanged value. Guard against setting an invalid index
5127 * before the new view peer tab has been created.
5129 final AlignViewportI peer = viewport.getCodingComplement();
5132 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5133 .getAlignPanel().alignFrame;
5134 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5136 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5142 * On right mouse click on view tab, prompt for and set new view name.
5145 public void tabbedPane_mousePressed(MouseEvent e)
5147 if (e.isPopupTrigger())
5149 String msg = MessageManager.getString("label.enter_view_name");
5150 String reply = JvOptionPane.showInternalInputDialog(this, msg, msg,
5151 JvOptionPane.QUESTION_MESSAGE);
5155 viewport.setViewName(reply);
5156 // TODO warn if reply is in getExistingViewNames()?
5157 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5162 public AlignViewport getCurrentView()
5168 * Open the dialog for regex description parsing.
5171 protected void extractScores_actionPerformed(ActionEvent e)
5173 ParseProperties pp = new jalview.analysis.ParseProperties(
5174 viewport.getAlignment());
5175 // TODO: verify regex and introduce GUI dialog for version 2.5
5176 // if (pp.getScoresFromDescription("col", "score column ",
5177 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5179 if (pp.getScoresFromDescription("description column",
5180 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5182 buildSortByAnnotationScoresMenu();
5190 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5194 protected void showDbRefs_actionPerformed(ActionEvent e)
5196 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5202 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5206 protected void showNpFeats_actionPerformed(ActionEvent e)
5208 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5212 * find the viewport amongst the tabs in this alignment frame and close that
5217 public boolean closeView(AlignViewportI av)
5221 this.closeMenuItem_actionPerformed(false);
5224 Component[] comp = tabbedPane.getComponents();
5225 for (int i = 0; comp != null && i < comp.length; i++)
5227 if (comp[i] instanceof AlignmentPanel)
5229 if (((AlignmentPanel) comp[i]).av == av)
5232 closeView((AlignmentPanel) comp[i]);
5240 protected void build_fetchdbmenu(JMenu webService)
5242 // Temporary hack - DBRef Fetcher always top level ws entry.
5243 // TODO We probably want to store a sequence database checklist in
5244 // preferences and have checkboxes.. rather than individual sources selected
5246 final JMenu rfetch = new JMenu(
5247 MessageManager.getString("action.fetch_db_references"));
5248 rfetch.setToolTipText(MessageManager.getString(
5249 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5250 webService.add(rfetch);
5252 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5253 MessageManager.getString("option.trim_retrieved_seqs"));
5254 trimrs.setToolTipText(
5255 MessageManager.getString("label.trim_retrieved_sequences"));
5257 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5258 trimrs.addActionListener(new ActionListener()
5261 public void actionPerformed(ActionEvent e)
5263 trimrs.setSelected(trimrs.isSelected());
5264 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5265 Boolean.valueOf(trimrs.isSelected()).toString());
5269 JMenuItem fetchr = new JMenuItem(
5270 MessageManager.getString("label.standard_databases"));
5271 fetchr.setToolTipText(
5272 MessageManager.getString("label.fetch_embl_uniprot"));
5273 fetchr.addActionListener(new ActionListener()
5277 public void actionPerformed(ActionEvent e)
5279 new Thread(new Runnable()
5284 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5285 .getAlignment().isNucleotide();
5286 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5287 alignPanel.av.getSequenceSelection(),
5288 alignPanel.alignFrame, null,
5289 alignPanel.alignFrame.featureSettings, isNucleotide);
5290 dbRefFetcher.addListener(new FetchFinishedListenerI()
5293 public void finished()
5296 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5297 .getFeatureSettingsModels())
5300 alignPanel.av.mergeFeaturesStyle(srcSettings);
5302 AlignFrame.this.setMenusForViewport();
5305 dbRefFetcher.fetchDBRefs(false);
5313 final AlignFrame me = this;
5314 new Thread(new Runnable()
5319 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5320 .getSequenceFetcherSingleton(me);
5321 javax.swing.SwingUtilities.invokeLater(new Runnable()
5326 String[] dbclasses = sf.getOrderedSupportedSources();
5327 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5328 // jalview.util.QuickSort.sort(otherdb, otherdb);
5329 List<DbSourceProxy> otherdb;
5330 JMenu dfetch = new JMenu();
5331 JMenu ifetch = new JMenu();
5332 JMenuItem fetchr = null;
5333 int comp = 0, icomp = 0, mcomp = 15;
5334 String mname = null;
5336 for (String dbclass : dbclasses)
5338 otherdb = sf.getSourceProxy(dbclass);
5339 // add a single entry for this class, or submenu allowing 'fetch
5341 if (otherdb == null || otherdb.size() < 1)
5345 // List<DbSourceProxy> dbs=otherdb;
5346 // otherdb=new ArrayList<DbSourceProxy>();
5347 // for (DbSourceProxy db:dbs)
5349 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5353 mname = "From " + dbclass;
5355 if (otherdb.size() == 1)
5357 final DbSourceProxy[] dassource = otherdb
5358 .toArray(new DbSourceProxy[0]);
5359 DbSourceProxy src = otherdb.get(0);
5360 fetchr = new JMenuItem(src.getDbSource());
5361 fetchr.addActionListener(new ActionListener()
5365 public void actionPerformed(ActionEvent e)
5367 new Thread(new Runnable()
5373 boolean isNucleotide = alignPanel.alignFrame
5374 .getViewport().getAlignment()
5376 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5377 alignPanel.av.getSequenceSelection(),
5378 alignPanel.alignFrame, dassource,
5379 alignPanel.alignFrame.featureSettings,
5382 .addListener(new FetchFinishedListenerI()
5385 public void finished()
5387 FeatureSettingsModelI srcSettings = dassource[0]
5388 .getFeatureColourScheme();
5389 alignPanel.av.mergeFeaturesStyle(
5391 AlignFrame.this.setMenusForViewport();
5394 dbRefFetcher.fetchDBRefs(false);
5400 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5401 MessageManager.formatMessage(
5402 "label.fetch_retrieve_from", new Object[]
5403 { src.getDbName() })));
5409 final DbSourceProxy[] dassource = otherdb
5410 .toArray(new DbSourceProxy[0]);
5412 DbSourceProxy src = otherdb.get(0);
5413 fetchr = new JMenuItem(MessageManager
5414 .formatMessage("label.fetch_all_param", new Object[]
5415 { src.getDbSource() }));
5416 fetchr.addActionListener(new ActionListener()
5419 public void actionPerformed(ActionEvent e)
5421 new Thread(new Runnable()
5427 boolean isNucleotide = alignPanel.alignFrame
5428 .getViewport().getAlignment()
5430 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5431 alignPanel.av.getSequenceSelection(),
5432 alignPanel.alignFrame, dassource,
5433 alignPanel.alignFrame.featureSettings,
5436 .addListener(new FetchFinishedListenerI()
5439 public void finished()
5441 AlignFrame.this.setMenusForViewport();
5444 dbRefFetcher.fetchDBRefs(false);
5450 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5451 MessageManager.formatMessage(
5452 "label.fetch_retrieve_from_all_sources",
5454 { Integer.valueOf(otherdb.size())
5456 src.getDbSource(), src.getDbName() })));
5459 // and then build the rest of the individual menus
5460 ifetch = new JMenu(MessageManager.formatMessage(
5461 "label.source_from_db_source", new Object[]
5462 { src.getDbSource() }));
5464 String imname = null;
5466 for (DbSourceProxy sproxy : otherdb)
5468 String dbname = sproxy.getDbName();
5469 String sname = dbname.length() > 5
5470 ? dbname.substring(0, 5) + "..."
5472 String msname = dbname.length() > 10
5473 ? dbname.substring(0, 10) + "..."
5477 imname = MessageManager
5478 .formatMessage("label.from_msname", new Object[]
5481 fetchr = new JMenuItem(msname);
5482 final DbSourceProxy[] dassrc = { sproxy };
5483 fetchr.addActionListener(new ActionListener()
5487 public void actionPerformed(ActionEvent e)
5489 new Thread(new Runnable()
5495 boolean isNucleotide = alignPanel.alignFrame
5496 .getViewport().getAlignment()
5498 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5499 alignPanel.av.getSequenceSelection(),
5500 alignPanel.alignFrame, dassrc,
5501 alignPanel.alignFrame.featureSettings,
5504 .addListener(new FetchFinishedListenerI()
5507 public void finished()
5509 AlignFrame.this.setMenusForViewport();
5512 dbRefFetcher.fetchDBRefs(false);
5518 fetchr.setToolTipText(
5519 "<html>" + MessageManager.formatMessage(
5520 "label.fetch_retrieve_from", new Object[]
5524 if (++icomp >= mcomp || i == (otherdb.size()))
5526 ifetch.setText(MessageManager.formatMessage(
5527 "label.source_to_target", imname, sname));
5529 ifetch = new JMenu();
5537 if (comp >= mcomp || dbi >= (dbclasses.length))
5539 dfetch.setText(MessageManager.formatMessage(
5540 "label.source_to_target", mname, dbclass));
5542 dfetch = new JMenu();
5555 * Left justify the whole alignment.
5558 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5560 AlignmentI al = viewport.getAlignment();
5562 viewport.firePropertyChange("alignment", null, al);
5566 * Right justify the whole alignment.
5569 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5571 AlignmentI al = viewport.getAlignment();
5573 viewport.firePropertyChange("alignment", null, al);
5577 public void setShowSeqFeatures(boolean b)
5579 showSeqFeatures.setSelected(b);
5580 viewport.setShowSequenceFeatures(b);
5587 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5588 * awt.event.ActionEvent)
5591 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5593 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5594 alignPanel.paintAlignment(false, false);
5601 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5605 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5607 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5608 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5616 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5617 * .event.ActionEvent)
5620 protected void showGroupConservation_actionPerformed(ActionEvent e)
5622 viewport.setShowGroupConservation(showGroupConservation.getState());
5623 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5630 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5631 * .event.ActionEvent)
5634 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5636 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5637 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5644 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5645 * .event.ActionEvent)
5648 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5650 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5651 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5655 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5657 showSequenceLogo.setState(true);
5658 viewport.setShowSequenceLogo(true);
5659 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5660 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5664 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5666 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5673 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5674 * .event.ActionEvent)
5677 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5679 if (avc.makeGroupsFromSelection())
5681 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5682 alignPanel.updateAnnotation();
5683 alignPanel.paintAlignment(true,
5684 viewport.needToUpdateStructureViews());
5688 public void clearAlignmentSeqRep()
5690 // TODO refactor alignmentseqrep to controller
5691 if (viewport.getAlignment().hasSeqrep())
5693 viewport.getAlignment().setSeqrep(null);
5694 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5695 alignPanel.updateAnnotation();
5696 alignPanel.paintAlignment(true, true);
5701 protected void createGroup_actionPerformed(ActionEvent e)
5703 if (avc.createGroup())
5705 if (applyAutoAnnotationSettings.isSelected())
5707 alignPanel.updateAnnotation(true, false);
5709 alignPanel.alignmentChanged();
5714 protected void unGroup_actionPerformed(ActionEvent e)
5718 alignPanel.alignmentChanged();
5723 * make the given alignmentPanel the currently selected tab
5725 * @param alignmentPanel
5727 public void setDisplayedView(AlignmentPanel alignmentPanel)
5729 if (!viewport.getSequenceSetId()
5730 .equals(alignmentPanel.av.getSequenceSetId()))
5732 throw new Error(MessageManager.getString(
5733 "error.implementation_error_cannot_show_view_alignment_frame"));
5735 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5736 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5738 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5743 * Action on selection of menu options to Show or Hide annotations.
5746 * @param forSequences
5747 * update sequence-related annotations
5748 * @param forAlignment
5749 * update non-sequence-related annotations
5752 protected void setAnnotationsVisibility(boolean visible,
5753 boolean forSequences, boolean forAlignment)
5755 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5756 .getAlignmentAnnotation();
5761 for (AlignmentAnnotation aa : anns)
5764 * don't display non-positional annotations on an alignment
5766 if (aa.annotations == null)
5770 boolean apply = (aa.sequenceRef == null && forAlignment)
5771 || (aa.sequenceRef != null && forSequences);
5774 aa.visible = visible;
5777 alignPanel.validateAnnotationDimensions(true);
5778 alignPanel.alignmentChanged();
5782 * Store selected annotation sort order for the view and repaint.
5785 protected void sortAnnotations_actionPerformed()
5787 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5789 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5790 alignPanel.paintAlignment(false, false);
5795 * @return alignment panels in this alignment frame
5797 public List<? extends AlignmentViewPanel> getAlignPanels()
5799 // alignPanels is never null
5800 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5805 * Open a new alignment window, with the cDNA associated with this (protein)
5806 * alignment, aligned as is the protein.
5808 protected void viewAsCdna_actionPerformed()
5810 // TODO no longer a menu action - refactor as required
5811 final AlignmentI alignment = getViewport().getAlignment();
5812 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5813 if (mappings == null)
5817 List<SequenceI> cdnaSeqs = new ArrayList<>();
5818 for (SequenceI aaSeq : alignment.getSequences())
5820 for (AlignedCodonFrame acf : mappings)
5822 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5826 * There is a cDNA mapping for this protein sequence - add to new
5827 * alignment. It will share the same dataset sequence as other mapped
5828 * cDNA (no new mappings need to be created).
5830 final Sequence newSeq = new Sequence(dnaSeq);
5831 newSeq.setDatasetSequence(dnaSeq);
5832 cdnaSeqs.add(newSeq);
5836 if (cdnaSeqs.size() == 0)
5838 // show a warning dialog no mapped cDNA
5841 AlignmentI cdna = new Alignment(
5842 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5843 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5844 AlignFrame.DEFAULT_HEIGHT);
5845 cdna.alignAs(alignment);
5846 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5848 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5849 AlignFrame.DEFAULT_HEIGHT);
5853 * Set visibility of dna/protein complement view (available when shown in a
5859 protected void showComplement_actionPerformed(boolean show)
5861 SplitContainerI sf = getSplitViewContainer();
5864 sf.setComplementVisible(this, show);
5869 * Generate the reverse (optionally complemented) of the selected sequences,
5870 * and add them to the alignment
5873 protected void showReverse_actionPerformed(boolean complement)
5875 AlignmentI al = null;
5878 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5879 al = dna.reverseCdna(complement);
5880 viewport.addAlignment(al, "");
5881 addHistoryItem(new EditCommand(
5882 MessageManager.getString("label.add_sequences"), Action.PASTE,
5883 al.getSequencesArray(), 0, al.getWidth(),
5884 viewport.getAlignment()));
5885 } catch (Exception ex)
5887 System.err.println(ex.getMessage());
5893 * Try to run a script in the Groovy console, having first ensured that this
5894 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5895 * be targeted at this alignment.
5898 protected void runGroovy_actionPerformed()
5900 Jalview.setCurrentAlignFrame(this);
5901 groovy.ui.Console console = Desktop.getGroovyConsole();
5902 if (console != null)
5906 console.runScript();
5907 } catch (Exception ex)
5909 System.err.println((ex.toString()));
5910 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
5911 MessageManager.getString("label.couldnt_run_groovy_script"),
5912 MessageManager.getString("label.groovy_support_failed"),
5913 JvOptionPane.ERROR_MESSAGE);
5918 System.err.println("Can't run Groovy script as console not found");
5923 * Hides columns containing (or not containing) a specified feature, provided
5924 * that would not leave all columns hidden
5926 * @param featureType
5927 * @param columnsContaining
5930 public boolean hideFeatureColumns(String featureType,
5931 boolean columnsContaining)
5933 boolean notForHiding = avc.markColumnsContainingFeatures(
5934 columnsContaining, false, false, featureType);
5937 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5938 false, featureType))
5940 getViewport().hideSelectedColumns();
5948 protected void selectHighlightedColumns_actionPerformed(
5949 ActionEvent actionEvent)
5951 // include key modifier check in case user selects from menu
5952 avc.markHighlightedColumns(
5953 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5954 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5955 | ActionEvent.CTRL_MASK)) != 0);
5959 * Rebuilds the Colour menu, including any user-defined colours which have
5960 * been loaded either on startup or during the session
5962 public void buildColourMenu()
5964 colourMenu.removeAll();
5966 colourMenu.add(applyToAllGroups);
5967 colourMenu.add(textColour);
5968 colourMenu.addSeparator();
5970 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
5971 viewport.getAlignment(), false);
5973 colourMenu.add(annotationColour);
5974 bg.add(annotationColour);
5975 colourMenu.addSeparator();
5976 colourMenu.add(conservationMenuItem);
5977 colourMenu.add(modifyConservation);
5978 colourMenu.add(abovePIDThreshold);
5979 colourMenu.add(modifyPID);
5981 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5982 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5986 * Open a dialog (if not already open) that allows the user to select and
5987 * calculate PCA or Tree analysis
5989 protected void openTreePcaDialog()
5991 if (alignPanel.getCalculationDialog() == null)
5993 new CalculationChooser(AlignFrame.this);
5998 * Sets the status of the HMMER menu
6000 public void updateHMMERStatus()
6002 hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
6006 protected void loadVcf_actionPerformed()
6008 JalviewFileChooser chooser = new JalviewFileChooser(
6009 Cache.getProperty("LAST_DIRECTORY"));
6010 chooser.setFileView(new JalviewFileView());
6011 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
6012 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
6014 int value = chooser.showOpenDialog(null);
6016 if (value == JalviewFileChooser.APPROVE_OPTION)
6018 String choice = chooser.getSelectedFile().getPath();
6019 Cache.setProperty("LAST_DIRECTORY", choice);
6020 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
6021 new VCFLoader(choice).loadVCF(seqs, this);
6026 private Rectangle lastFeatureSettingsBounds = null;
6028 public void setFeatureSettingsGeometry(Rectangle bounds)
6030 lastFeatureSettingsBounds = bounds;
6034 public Rectangle getFeatureSettingsGeometry()
6036 return lastFeatureSettingsBounds;
6040 class PrintThread extends Thread
6044 public PrintThread(AlignmentPanel ap)
6049 static PageFormat pf;
6054 PrinterJob printJob = PrinterJob.getPrinterJob();
6058 printJob.setPrintable(ap, pf);
6062 printJob.setPrintable(ap);
6065 if (printJob.printDialog())
6070 } catch (Exception PrintException)
6072 PrintException.printStackTrace();