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.WSDiscovererI;
106 import jalview.ws.api.ServiceWithParameters;
107 import jalview.ws.jws1.Discoverer;
108 import jalview.ws.jws2.Jws2Discoverer;
109 import jalview.ws.params.ArgumentI;
110 import jalview.ws.params.ParamDatastoreI;
111 import jalview.ws.params.WsParamSetI;
112 import jalview.ws.seqfetcher.DbSourceProxy;
113 import jalview.ws.slivkaws.SlivkaWSDiscoverer;
115 import java.awt.BorderLayout;
116 import java.awt.Component;
117 import java.awt.Rectangle;
118 import java.awt.Toolkit;
119 import java.awt.datatransfer.Clipboard;
120 import java.awt.datatransfer.DataFlavor;
121 import java.awt.datatransfer.StringSelection;
122 import java.awt.datatransfer.Transferable;
123 import java.awt.dnd.DnDConstants;
124 import java.awt.dnd.DropTargetDragEvent;
125 import java.awt.dnd.DropTargetDropEvent;
126 import java.awt.dnd.DropTargetEvent;
127 import java.awt.dnd.DropTargetListener;
128 import java.awt.event.ActionEvent;
129 import java.awt.event.ActionListener;
130 import java.awt.event.FocusAdapter;
131 import java.awt.event.FocusEvent;
132 import java.awt.event.ItemEvent;
133 import java.awt.event.ItemListener;
134 import java.awt.event.KeyAdapter;
135 import java.awt.event.KeyEvent;
136 import java.awt.event.MouseEvent;
137 import java.awt.print.PageFormat;
138 import java.awt.print.PrinterJob;
139 import java.beans.PropertyChangeEvent;
141 import java.io.FileWriter;
142 import java.io.IOException;
143 import java.io.PrintWriter;
145 import java.util.ArrayList;
146 import java.util.Arrays;
147 import java.util.Deque;
148 import java.util.HashSet;
149 import java.util.List;
150 import java.util.Set;
151 import java.util.Vector;
153 import javax.swing.ButtonGroup;
154 import javax.swing.JCheckBoxMenuItem;
155 import javax.swing.JEditorPane;
156 import javax.swing.JFileChooser;
157 import javax.swing.JInternalFrame;
158 import javax.swing.JLayeredPane;
159 import javax.swing.JMenu;
160 import javax.swing.JMenuItem;
161 import javax.swing.JOptionPane;
162 import javax.swing.JScrollPane;
163 import javax.swing.SwingUtilities;
169 * @version $Revision$
171 public class AlignFrame extends GAlignFrame implements DropTargetListener,
172 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
174 public static final int DEFAULT_WIDTH = 700;
176 public static final int DEFAULT_HEIGHT = 500;
179 * The currently displayed panel (selected tabbed view if more than one)
181 public AlignmentPanel alignPanel;
183 AlignViewport viewport;
185 public AlignViewControllerI avc;
187 List<AlignmentPanel> alignPanels = new ArrayList<>();
190 * Last format used to load or save alignments in this window
192 FileFormatI currentFileFormat = null;
195 * Current filename for this alignment
197 String fileName = null;
201 * Creates a new AlignFrame object with specific width and height.
207 public AlignFrame(AlignmentI al, int width, int height)
209 this(al, null, width, height);
213 * Creates a new AlignFrame object with specific width, height and
219 * @param sequenceSetId
221 public AlignFrame(AlignmentI al, int width, int height,
222 String sequenceSetId)
224 this(al, null, width, height, sequenceSetId);
228 * Creates a new AlignFrame object with specific width, height and
234 * @param sequenceSetId
237 public AlignFrame(AlignmentI al, int width, int height,
238 String sequenceSetId, String viewId)
240 this(al, null, width, height, sequenceSetId, viewId);
244 * new alignment window with hidden columns
248 * @param hiddenColumns
249 * ColumnSelection or null
251 * Width of alignment frame
255 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
258 this(al, hiddenColumns, width, height, null);
262 * Create alignment frame for al with hiddenColumns, a specific width and
263 * height, and specific sequenceId
266 * @param hiddenColumns
269 * @param sequenceSetId
272 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
273 int height, String sequenceSetId)
275 this(al, hiddenColumns, width, height, sequenceSetId, null);
279 * Create alignment frame for al with hiddenColumns, a specific width and
280 * height, and specific sequenceId
283 * @param hiddenColumns
286 * @param sequenceSetId
291 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
292 int height, String sequenceSetId, String viewId)
294 setSize(width, height);
296 if (al.getDataset() == null)
301 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
303 alignPanel = new AlignmentPanel(this, viewport);
305 addAlignmentPanel(alignPanel, true);
309 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
310 HiddenColumns hiddenColumns, int width, int height)
312 setSize(width, height);
314 if (al.getDataset() == null)
319 viewport = new AlignViewport(al, hiddenColumns);
321 if (hiddenSeqs != null && hiddenSeqs.length > 0)
323 viewport.hideSequence(hiddenSeqs);
325 alignPanel = new AlignmentPanel(this, viewport);
326 addAlignmentPanel(alignPanel, true);
331 * Make a new AlignFrame from existing alignmentPanels
338 public AlignFrame(AlignmentPanel ap)
342 addAlignmentPanel(ap, false);
347 * initalise the alignframe from the underlying viewport data and the
352 if (!Jalview.isHeadlessMode())
354 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
357 avc = new jalview.controller.AlignViewController(this, viewport,
359 if (viewport.getAlignmentConservationAnnotation() == null)
361 // BLOSUM62Colour.setEnabled(false);
362 conservationMenuItem.setEnabled(false);
363 modifyConservation.setEnabled(false);
364 // PIDColour.setEnabled(false);
365 // abovePIDThreshold.setEnabled(false);
366 // modifyPID.setEnabled(false);
369 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
372 if (sortby.equals("Id"))
374 sortIDMenuItem_actionPerformed(null);
376 else if (sortby.equals("Pairwise Identity"))
378 sortPairwiseMenuItem_actionPerformed(null);
382 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
384 setMenusFromViewport(viewport);
385 buildSortByAnnotationScoresMenu();
386 calculateTree.addActionListener(new ActionListener()
390 public void actionPerformed(ActionEvent e)
397 if (Desktop.desktop != null)
399 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
400 addServiceListeners();
404 if (viewport.getWrapAlignment())
406 wrapMenuItem_actionPerformed(null);
409 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
411 this.overviewMenuItem_actionPerformed(null);
416 final List<AlignmentPanel> selviews = new ArrayList<>();
417 final List<AlignmentPanel> origview = new ArrayList<>();
418 final String menuLabel = MessageManager
419 .getString("label.copy_format_from");
420 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
421 new ViewSetProvider()
425 public AlignmentPanel[] getAllAlignmentPanels()
428 origview.add(alignPanel);
429 // make an array of all alignment panels except for this one
430 List<AlignmentPanel> aps = new ArrayList<>(
431 Arrays.asList(Desktop.getAlignmentPanels(null)));
432 aps.remove(AlignFrame.this.alignPanel);
433 return aps.toArray(new AlignmentPanel[aps.size()]);
435 }, selviews, new ItemListener()
439 public void itemStateChanged(ItemEvent e)
441 if (origview.size() > 0)
443 final AlignmentPanel ap = origview.get(0);
446 * Copy the ViewStyle of the selected panel to 'this one'.
447 * Don't change value of 'scaleProteinAsCdna' unless copying
450 ViewStyleI vs = selviews.get(0).getAlignViewport()
452 boolean fromSplitFrame = selviews.get(0)
453 .getAlignViewport().getCodingComplement() != null;
456 vs.setScaleProteinAsCdna(ap.getAlignViewport()
457 .getViewStyle().isScaleProteinAsCdna());
459 ap.getAlignViewport().setViewStyle(vs);
462 * Also rescale ViewStyle of SplitFrame complement if there is
463 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
464 * the whole ViewStyle (allow cDNA protein to have different
467 AlignViewportI complement = ap.getAlignViewport()
468 .getCodingComplement();
469 if (complement != null && vs.isScaleProteinAsCdna())
471 AlignFrame af = Desktop.getAlignFrameFor(complement);
472 ((SplitFrame) af.getSplitViewContainer())
474 af.setMenusForViewport();
478 ap.setSelected(true);
479 ap.alignFrame.setMenusForViewport();
484 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
485 .indexOf("devel") > -1
486 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
487 .indexOf("test") > -1)
489 formatMenu.add(vsel);
491 addFocusListener(new FocusAdapter()
494 public void focusGained(FocusEvent e)
496 Jalview.setCurrentAlignFrame(AlignFrame.this);
503 * Change the filename and format for the alignment, and enable the 'reload'
504 * button functionality.
511 public void setFileName(String file, FileFormatI format)
514 setFileFormat(format);
515 reload.setEnabled(true);
519 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
522 void addKeyListener()
524 addKeyListener(new KeyAdapter()
527 public void keyPressed(KeyEvent evt)
529 if (viewport.cursorMode
530 && ((evt.getKeyCode() >= KeyEvent.VK_0
531 && evt.getKeyCode() <= KeyEvent.VK_9)
532 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
533 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
534 && Character.isDigit(evt.getKeyChar()))
536 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
539 switch (evt.getKeyCode())
542 case 27: // escape key
543 deselectAllSequenceMenuItem_actionPerformed(null);
547 case KeyEvent.VK_DOWN:
548 if (evt.isAltDown() || !viewport.cursorMode)
550 moveSelectedSequences(false);
552 if (viewport.cursorMode)
554 alignPanel.getSeqPanel().moveCursor(0, 1);
559 if (evt.isAltDown() || !viewport.cursorMode)
561 moveSelectedSequences(true);
563 if (viewport.cursorMode)
565 alignPanel.getSeqPanel().moveCursor(0, -1);
570 case KeyEvent.VK_LEFT:
571 if (evt.isAltDown() || !viewport.cursorMode)
573 slideSequences(false,
574 alignPanel.getSeqPanel().getKeyboardNo1());
578 alignPanel.getSeqPanel().moveCursor(-1, 0);
583 case KeyEvent.VK_RIGHT:
584 if (evt.isAltDown() || !viewport.cursorMode)
586 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
590 alignPanel.getSeqPanel().moveCursor(1, 0);
594 case KeyEvent.VK_SPACE:
595 if (viewport.cursorMode)
597 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
598 || evt.isShiftDown() || evt.isAltDown());
602 // case KeyEvent.VK_A:
603 // if (viewport.cursorMode)
605 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
606 // //System.out.println("A");
610 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
611 * System.out.println("closing bracket"); } break;
613 case KeyEvent.VK_DELETE:
614 case KeyEvent.VK_BACK_SPACE:
615 if (!viewport.cursorMode)
617 cut_actionPerformed(null);
621 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
622 || evt.isShiftDown() || evt.isAltDown());
628 if (viewport.cursorMode)
630 alignPanel.getSeqPanel().setCursorRow();
634 if (viewport.cursorMode && !evt.isControlDown())
636 alignPanel.getSeqPanel().setCursorColumn();
640 if (viewport.cursorMode)
642 alignPanel.getSeqPanel().setCursorPosition();
646 case KeyEvent.VK_ENTER:
647 case KeyEvent.VK_COMMA:
648 if (viewport.cursorMode)
650 alignPanel.getSeqPanel().setCursorRowAndColumn();
655 if (viewport.cursorMode)
657 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
661 if (viewport.cursorMode)
663 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
668 viewport.cursorMode = !viewport.cursorMode;
669 statusBar.setText(MessageManager
670 .formatMessage("label.keyboard_editing_mode", new String[]
671 { (viewport.cursorMode ? "on" : "off") }));
672 if (viewport.cursorMode)
674 ViewportRanges ranges = viewport.getRanges();
675 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
677 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
680 alignPanel.getSeqPanel().seqCanvas.repaint();
686 Help.showHelpWindow();
687 } catch (Exception ex)
689 ex.printStackTrace();
694 boolean toggleSeqs = !evt.isControlDown();
695 boolean toggleCols = !evt.isShiftDown();
696 toggleHiddenRegions(toggleSeqs, toggleCols);
701 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
702 boolean modifyExisting = true; // always modify, don't clear
703 // evt.isShiftDown();
704 boolean invertHighlighted = evt.isAltDown();
705 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
709 case KeyEvent.VK_PAGE_UP:
710 viewport.getRanges().pageUp();
712 case KeyEvent.VK_PAGE_DOWN:
713 viewport.getRanges().pageDown();
719 public void keyReleased(KeyEvent evt)
721 switch (evt.getKeyCode())
723 case KeyEvent.VK_LEFT:
724 if (evt.isAltDown() || !viewport.cursorMode)
726 viewport.firePropertyChange("alignment", null,
727 viewport.getAlignment().getSequences());
731 case KeyEvent.VK_RIGHT:
732 if (evt.isAltDown() || !viewport.cursorMode)
734 viewport.firePropertyChange("alignment", null,
735 viewport.getAlignment().getSequences());
743 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
745 ap.alignFrame = this;
746 avc = new jalview.controller.AlignViewController(this, viewport,
751 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
753 int aSize = alignPanels.size();
755 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
757 if (aSize == 1 && ap.av.getViewName() == null)
759 this.getContentPane().add(ap, BorderLayout.CENTER);
765 setInitialTabVisible();
768 expandViews.setEnabled(true);
769 gatherViews.setEnabled(true);
770 tabbedPane.addTab(ap.av.getViewName(), ap);
772 ap.setVisible(false);
777 if (ap.av.isPadGaps())
779 ap.av.getAlignment().padGaps();
781 ap.av.updateConservation(ap);
782 ap.av.updateConsensus(ap);
783 ap.av.updateStrucConsensus(ap);
784 ap.av.initInformationWorker(ap);
788 public void setInitialTabVisible()
790 expandViews.setEnabled(true);
791 gatherViews.setEnabled(true);
792 tabbedPane.setVisible(true);
793 AlignmentPanel first = alignPanels.get(0);
794 tabbedPane.addTab(first.av.getViewName(), first);
795 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
798 public AlignViewport getViewport()
803 /* Set up intrinsic listeners for dynamically generated GUI bits. */
804 private void addServiceListeners()
806 final java.beans.PropertyChangeListener thisListener;
807 Desktop.instance.addJalviewPropertyChangeListener("services",
808 thisListener = new java.beans.PropertyChangeListener()
811 public void propertyChange(PropertyChangeEvent evt)
813 // // System.out.println("Discoverer property change.");
814 // if (evt.getPropertyName().equals("services"))
816 SwingUtilities.invokeLater(new Runnable()
823 "Rebuild WS Menu for service change");
824 BuildWebServiceMenu();
831 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
834 public void internalFrameClosed(
835 javax.swing.event.InternalFrameEvent evt)
837 // System.out.println("deregistering discoverer listener");
838 Desktop.instance.removeJalviewPropertyChangeListener("services",
840 closeMenuItem_actionPerformed(true);
843 // Finally, build the menu once to get current service state
844 new Thread(new Runnable()
849 BuildWebServiceMenu();
855 * Configure menu items that vary according to whether the alignment is
856 * nucleotide or protein
858 public void setGUINucleotide()
860 AlignmentI al = getViewport().getAlignment();
861 boolean nucleotide = al.isNucleotide();
863 loadVcf.setVisible(nucleotide);
864 showTranslation.setVisible(nucleotide);
865 showReverse.setVisible(nucleotide);
866 showReverseComplement.setVisible(nucleotide);
867 conservationMenuItem.setEnabled(!nucleotide);
869 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
870 showGroupConservation.setEnabled(!nucleotide);
872 showComplementMenuItem
873 .setText(nucleotide ? MessageManager.getString("label.protein")
874 : MessageManager.getString("label.nucleotide"));
878 * set up menus for the current viewport. This may be called after any
879 * operation that affects the data in the current view (selection changed,
880 * etc) to update the menus to reflect the new state.
883 public void setMenusForViewport()
885 setMenusFromViewport(viewport);
889 * Need to call this method when tabs are selected for multiple views, or when
890 * loading from Jalview2XML.java
895 public void setMenusFromViewport(AlignViewport av)
897 padGapsMenuitem.setSelected(av.isPadGaps());
898 colourTextMenuItem.setSelected(av.isShowColourText());
899 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
900 modifyPID.setEnabled(abovePIDThreshold.isSelected());
901 conservationMenuItem.setSelected(av.getConservationSelected());
902 modifyConservation.setEnabled(conservationMenuItem.isSelected());
903 seqLimits.setSelected(av.getShowJVSuffix());
904 idRightAlign.setSelected(av.isRightAlignIds());
905 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
906 renderGapsMenuItem.setSelected(av.isRenderGaps());
907 wrapMenuItem.setSelected(av.getWrapAlignment());
908 scaleAbove.setVisible(av.getWrapAlignment());
909 scaleLeft.setVisible(av.getWrapAlignment());
910 scaleRight.setVisible(av.getWrapAlignment());
911 annotationPanelMenuItem.setState(av.isShowAnnotation());
913 * Show/hide annotations only enabled if annotation panel is shown
915 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
916 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
917 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
918 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
919 viewBoxesMenuItem.setSelected(av.getShowBoxes());
920 viewTextMenuItem.setSelected(av.getShowText());
921 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
922 showGroupConsensus.setSelected(av.isShowGroupConsensus());
923 showGroupConservation.setSelected(av.isShowGroupConservation());
924 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
925 showSequenceLogo.setSelected(av.isShowSequenceLogo());
926 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
927 showInformationHistogram.setSelected(av.isShowInformationHistogram());
928 showHMMSequenceLogo.setSelected(av.isShowHMMSequenceLogo());
929 normaliseHMMSequenceLogo.setSelected(av.isNormaliseHMMSequenceLogo());
931 ColourMenuHelper.setColourSelected(colourMenu,
932 av.getGlobalColourScheme());
934 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
935 hiddenMarkers.setState(av.getShowHiddenMarkers());
936 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
937 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
938 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
939 autoCalculate.setSelected(av.autoCalculateConsensus);
940 sortByTree.setSelected(av.sortByTree);
941 listenToViewSelections.setSelected(av.followSelection);
943 showProducts.setEnabled(canShowProducts());
944 setGroovyEnabled(Desktop.getGroovyConsole() != null);
950 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
954 public void setGroovyEnabled(boolean b)
956 runGroovy.setEnabled(b);
959 private IProgressIndicator progressBar;
964 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
967 public void setProgressBar(String message, long id)
969 progressBar.setProgressBar(message, id);
973 public void registerHandler(final long id,
974 final IProgressIndicatorHandler handler)
976 progressBar.registerHandler(id, handler);
981 * @return true if any progress bars are still active
984 public boolean operationInProgress()
986 return progressBar.operationInProgress();
990 * Sets the text of the status bar. Note that setting a null or empty value
991 * will cause the status bar to be hidden, with possibly undesirable flicker
992 * of the screen layout.
995 public void setStatus(String text)
997 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1001 * Added so Castor Mapping file can obtain Jalview Version
1003 public String getVersion()
1005 return jalview.bin.Cache.getProperty("VERSION");
1008 public FeatureRenderer getFeatureRenderer()
1010 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1014 public void fetchSequence_actionPerformed(ActionEvent e)
1016 new jalview.gui.SequenceFetcher(this);
1020 public void addFromFile_actionPerformed(ActionEvent e)
1022 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1026 public void hmmBuild_actionPerformed(boolean withDefaults)
1028 if (!alignmentIsSufficient(1))
1034 * get default parameters, and optionally show a dialog
1035 * to allow them to be modified
1037 ParamDatastoreI store = HMMERParamStore.forBuild(viewport);
1038 List<ArgumentI> args = store.getServiceParameters();
1042 WsParamSetI set = new HMMERPreset();
1043 WsJobParameters params = new WsJobParameters(store, set, args);
1044 if (params.showRunDialog())
1046 args = params.getJobParams();
1050 return; // user cancelled
1053 new Thread(new HMMBuild(this, args)).start();
1057 public void hmmAlign_actionPerformed(boolean withDefaults)
1059 if (!(checkForHMM() && alignmentIsSufficient(2)))
1065 * get default parameters, and optionally show a dialog
1066 * to allow them to be modified
1068 ParamDatastoreI store = HMMERParamStore.forAlign(viewport);
1069 List<ArgumentI> args = store.getServiceParameters();
1073 WsParamSetI set = new HMMERPreset();
1074 WsJobParameters params = new WsJobParameters(store, set, args);
1075 if (params.showRunDialog())
1077 args = params.getJobParams();
1081 return; // user cancelled
1084 new Thread(new HMMAlign(this, args)).start();
1088 public void hmmSearch_actionPerformed(boolean withDefaults)
1096 * get default parameters, and (if requested) show
1097 * dialog to allow modification
1099 ParamDatastoreI store = HMMERParamStore.forSearch(viewport);
1100 List<ArgumentI> args = store.getServiceParameters();
1104 WsParamSetI set = new HMMERPreset();
1105 WsJobParameters params = new WsJobParameters(store, set, args);
1106 if (params.showRunDialog())
1108 args = params.getJobParams();
1112 return; // user cancelled
1115 new Thread(new HMMSearch(this, args)).start();
1116 alignPanel.repaint();
1120 public void jackhmmer_actionPerformed(boolean withDefaults)
1124 * get default parameters, and (if requested) show
1125 * dialog to allow modification
1128 ParamDatastoreI store = HMMERParamStore.forJackhmmer(viewport);
1129 List<ArgumentI> args = store.getServiceParameters();
1133 WsParamSetI set = new HMMERPreset();
1134 WsJobParameters params = new WsJobParameters(store, set, args);
1135 if (params.showRunDialog())
1137 args = params.getJobParams();
1141 return; // user cancelled
1144 new Thread(new JackHMMER(this, args)).start();
1145 alignPanel.repaint();
1150 * Checks if the alignment has at least one hidden Markov model, if not shows
1151 * a dialog advising to run hmmbuild or load an HMM profile
1155 private boolean checkForHMM()
1157 if (viewport.getAlignment().getHmmSequences().isEmpty())
1159 JOptionPane.showMessageDialog(this,
1160 MessageManager.getString("warn.no_hmm"));
1167 protected void filterByEValue_actionPerformed()
1169 viewport.filterByEvalue(inputDouble("Enter E-Value Cutoff"));
1173 protected void filterByScore_actionPerformed()
1175 viewport.filterByScore(inputDouble("Enter Bit Score Threshold"));
1178 private double inputDouble(String message)
1182 while(d == null || d <= 0)
1184 str = JOptionPane.showInputDialog(this.alignPanel, message);
1187 d = Double.valueOf(str);
1189 catch (NumberFormatException e)
1197 * Checks if the alignment contains the required number of sequences.
1202 public boolean alignmentIsSufficient(int required)
1204 if (getViewport().getSequenceSelection().length < required)
1206 JOptionPane.showMessageDialog(this,
1207 MessageManager.getString("label.not_enough_sequences"));
1214 * Opens a file browser and adds the selected file, if in Fasta, Stockholm or
1215 * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a
1216 * comma-separated list)
1219 public void addDatabase_actionPerformed() throws IOException
1221 if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null)
1223 Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
1226 String path = openFileChooser(false);
1227 if (path != null && new File(path).exists())
1229 IdentifyFile identifier = new IdentifyFile();
1230 FileFormatI format = identifier.identify(path, DataSourceType.FILE);
1231 if (format == FileFormat.Fasta || format == FileFormat.Stockholm
1232 || format == FileFormat.Pfam)
1234 String currentDbPaths = Cache
1235 .getProperty(Preferences.HMMSEARCH_DBS);
1236 currentDbPaths += Preferences.COMMA + path;
1237 Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
1241 JOptionPane.showMessageDialog(this,
1242 MessageManager.getString("warn.invalid_format"));
1248 * Opens a file chooser, optionally restricted to selecting folders
1249 * (directories) only. Answers the path to the selected file or folder, or
1250 * null if none is chosen.
1255 protected String openFileChooser(boolean forFolder)
1257 // TODO duplicates GPreferences method - relocate to JalviewFileChooser?
1258 String choice = null;
1259 JFileChooser chooser = new JFileChooser();
1262 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1264 chooser.setDialogTitle(
1265 MessageManager.getString("label.open_local_file"));
1266 chooser.setToolTipText(MessageManager.getString("action.open"));
1268 int value = chooser.showOpenDialog(this);
1270 if (value == JFileChooser.APPROVE_OPTION)
1272 choice = chooser.getSelectedFile().getPath();
1278 public void reload_actionPerformed(ActionEvent e)
1280 if (fileName != null)
1282 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1283 // originating file's format
1284 // TODO: work out how to recover feature settings for correct view(s) when
1285 // file is reloaded.
1286 if (FileFormat.Jalview.equals(currentFileFormat))
1288 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1289 for (int i = 0; i < frames.length; i++)
1291 if (frames[i] instanceof AlignFrame && frames[i] != this
1292 && ((AlignFrame) frames[i]).fileName != null
1293 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1297 frames[i].setSelected(true);
1298 Desktop.instance.closeAssociatedWindows();
1299 } catch (java.beans.PropertyVetoException ex)
1305 Desktop.instance.closeAssociatedWindows();
1307 FileLoader loader = new FileLoader();
1308 DataSourceType protocol = fileName.startsWith("http:")
1309 ? DataSourceType.URL
1310 : DataSourceType.FILE;
1311 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1315 Rectangle bounds = this.getBounds();
1317 FileLoader loader = new FileLoader();
1318 DataSourceType protocol = fileName.startsWith("http:")
1319 ? DataSourceType.URL
1320 : DataSourceType.FILE;
1321 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1322 protocol, currentFileFormat);
1324 newframe.setBounds(bounds);
1325 if (featureSettings != null && featureSettings.isShowing())
1327 final Rectangle fspos = featureSettings.frame.getBounds();
1328 // TODO: need a 'show feature settings' function that takes bounds -
1329 // need to refactor Desktop.addFrame
1330 newframe.featureSettings_actionPerformed(null);
1331 final FeatureSettings nfs = newframe.featureSettings;
1332 SwingUtilities.invokeLater(new Runnable()
1337 nfs.frame.setBounds(fspos);
1340 this.featureSettings.close();
1341 this.featureSettings = null;
1343 this.closeMenuItem_actionPerformed(true);
1349 public void addFromText_actionPerformed(ActionEvent e)
1352 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1356 public void addFromURL_actionPerformed(ActionEvent e)
1358 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1362 public void save_actionPerformed(ActionEvent e)
1364 if (fileName == null || (currentFileFormat == null)
1365 || fileName.startsWith("http"))
1367 saveAs_actionPerformed(null);
1371 saveAlignment(fileName, currentFileFormat);
1382 public void saveAs_actionPerformed(ActionEvent e)
1384 String format = currentFileFormat == null ? null
1385 : currentFileFormat.getName();
1386 JalviewFileChooser chooser = JalviewFileChooser
1387 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1389 chooser.setFileView(new JalviewFileView());
1390 chooser.setDialogTitle(
1391 MessageManager.getString("label.save_alignment_to_file"));
1392 chooser.setToolTipText(MessageManager.getString("action.save"));
1394 int value = chooser.showSaveDialog(this);
1396 if (value == JalviewFileChooser.APPROVE_OPTION)
1398 currentFileFormat = chooser.getSelectedFormat();
1399 while (currentFileFormat == null)
1401 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1402 MessageManager.getString(
1403 "label.select_file_format_before_saving"),
1404 MessageManager.getString("label.file_format_not_specified"),
1405 JvOptionPane.WARNING_MESSAGE);
1406 currentFileFormat = chooser.getSelectedFormat();
1407 value = chooser.showSaveDialog(this);
1408 if (value != JalviewFileChooser.APPROVE_OPTION)
1414 fileName = chooser.getSelectedFile().getPath();
1416 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1418 Cache.setProperty("LAST_DIRECTORY", fileName);
1419 saveAlignment(fileName, currentFileFormat);
1423 public boolean saveAlignment(String file, FileFormatI format)
1425 boolean success = true;
1427 if (FileFormat.Jalview.equals(format))
1429 String shortName = title;
1431 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1433 shortName = shortName.substring(
1434 shortName.lastIndexOf(java.io.File.separatorChar) + 1);
1437 success = new jalview.project.Jalview2XML().saveAlignment(this, file,
1440 statusBar.setText(MessageManager.formatMessage(
1441 "label.successfully_saved_to_file_in_format", new Object[]
1442 { fileName, format }));
1447 AlignmentExportData exportData = getAlignmentForExport(format,
1449 if (exportData.getSettings().isCancelled())
1453 FormatAdapter f = new FormatAdapter(alignPanel,
1454 exportData.getSettings());
1455 String output = f.formatSequences(format, exportData.getAlignment(), // class
1459 // occur in the distant future
1460 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1461 f.getCacheSuffixDefault(format),
1462 viewport.getAlignment().getHiddenColumns());
1470 // create backupfiles object and get new temp filename destination
1471 BackupFiles backupfiles = new BackupFiles(file);
1475 PrintWriter out = new PrintWriter(
1476 new FileWriter(backupfiles.getTempFilePath()));
1480 this.setTitle(file);
1481 statusBar.setText(MessageManager.formatMessage(
1482 "label.successfully_saved_to_file_in_format", new Object[]
1483 { fileName, format.getName() }));
1484 } catch (Exception ex)
1487 ex.printStackTrace();
1490 backupfiles.setWriteSuccess(success);
1491 // do the backup file roll and rename the temp file to actual file
1492 success = backupfiles.rollBackupsAndRenameTempFile();
1499 JvOptionPane.showInternalMessageDialog(this, MessageManager
1500 .formatMessage("label.couldnt_save_file", new Object[]
1502 MessageManager.getString("label.error_saving_file"),
1503 JvOptionPane.WARNING_MESSAGE);
1509 private void warningMessage(String warning, String title)
1511 if (new jalview.util.Platform().isHeadless())
1513 System.err.println("Warning: " + title + "\nWarning: " + warning);
1518 JvOptionPane.showInternalMessageDialog(this, warning, title,
1519 JvOptionPane.WARNING_MESSAGE);
1531 protected void outputText_actionPerformed(ActionEvent e)
1533 FileFormatI fileFormat = FileFormats.getInstance()
1534 .forName(e.getActionCommand());
1535 AlignmentExportData exportData = getAlignmentForExport(fileFormat,
1537 if (exportData.getSettings().isCancelled())
1541 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1542 cap.setForInput(null);
1545 FileFormatI format = fileFormat;
1546 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1547 .formatSequences(format, exportData.getAlignment(),
1548 exportData.getOmitHidden(),
1549 exportData.getStartEndPostions(),
1550 viewport.getAlignment().getHiddenColumns()));
1551 Desktop.addInternalFrame(cap, MessageManager
1552 .formatMessage("label.alignment_output_command", new Object[]
1553 { e.getActionCommand() }), 600, 500);
1554 } catch (OutOfMemoryError oom)
1556 new OOMWarning("Outputting alignment as " + e.getActionCommand(),
1563 public static AlignmentExportData getAlignmentForExport(
1564 FileFormatI format, AlignViewportI viewport,
1565 AlignExportSettingI exportSettings)
1567 AlignmentI alignmentToExport = null;
1568 AlignExportSettingI settings = exportSettings;
1569 String[] omitHidden = null;
1571 HiddenSequences hiddenSeqs = viewport.getAlignment()
1572 .getHiddenSequences();
1574 alignmentToExport = viewport.getAlignment();
1576 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1577 if (settings == null)
1579 settings = new AlignExportSettings(hasHiddenSeqs,
1580 viewport.hasHiddenColumns(), format);
1582 // settings.isExportAnnotations();
1584 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1586 omitHidden = viewport.getViewAsString(false,
1587 settings.isExportHiddenSequences());
1590 int[] alignmentStartEnd = new int[2];
1591 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1593 alignmentToExport = hiddenSeqs.getFullAlignment();
1597 alignmentToExport = viewport.getAlignment();
1599 alignmentStartEnd = viewport.getAlignment().getHiddenColumns()
1600 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
1601 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1602 omitHidden, alignmentStartEnd, settings);
1613 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1615 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1616 htmlSVG.exportHTML(null);
1620 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1622 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1623 bjs.exportHTML(null);
1626 public void createImageMap(File file, String image)
1628 alignPanel.makePNGImageMap(file, image);
1638 public void createPNG(File f)
1640 alignPanel.makePNG(f);
1650 public void createEPS(File f)
1652 alignPanel.makeEPS(f);
1656 public void createSVG(File f)
1658 alignPanel.makeSVG(f);
1662 public void pageSetup_actionPerformed(ActionEvent e)
1664 PrinterJob printJob = PrinterJob.getPrinterJob();
1665 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1675 public void printMenuItem_actionPerformed(ActionEvent e)
1677 // Putting in a thread avoids Swing painting problems
1678 PrintThread thread = new PrintThread(alignPanel);
1683 public void exportFeatures_actionPerformed(ActionEvent e)
1685 new AnnotationExporter(alignPanel).exportFeatures();
1689 public void exportAnnotations_actionPerformed(ActionEvent e)
1691 new AnnotationExporter(alignPanel).exportAnnotations();
1695 public void associatedData_actionPerformed(ActionEvent e)
1696 throws IOException, InterruptedException
1698 // Pick the tree file
1699 JalviewFileChooser chooser = new JalviewFileChooser(
1700 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1701 chooser.setFileView(new JalviewFileView());
1702 chooser.setDialogTitle(
1703 MessageManager.getString("label.load_jalview_annotations"));
1704 chooser.setToolTipText(
1705 MessageManager.getString("label.load_jalview_annotations"));
1707 int value = chooser.showOpenDialog(null);
1709 if (value == JalviewFileChooser.APPROVE_OPTION)
1711 String choice = chooser.getSelectedFile().getPath();
1712 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1713 loadJalviewDataFile(choice, null, null, null);
1719 * Close the current view or all views in the alignment frame. If the frame
1720 * only contains one view then the alignment will be removed from memory.
1722 * @param closeAllTabs
1725 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1727 if (alignPanels != null && alignPanels.size() < 2)
1729 closeAllTabs = true;
1734 if (alignPanels != null)
1738 if (this.isClosed())
1740 // really close all the windows - otherwise wait till
1741 // setClosed(true) is called
1742 for (int i = 0; i < alignPanels.size(); i++)
1744 AlignmentPanel ap = alignPanels.get(i);
1751 closeView(alignPanel);
1758 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1759 * be called recursively, with the frame now in 'closed' state
1761 this.setClosed(true);
1763 } catch (Exception ex)
1765 ex.printStackTrace();
1770 * Close the specified panel and close up tabs appropriately.
1772 * @param panelToClose
1774 public void closeView(AlignmentPanel panelToClose)
1776 int index = tabbedPane.getSelectedIndex();
1777 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1778 alignPanels.remove(panelToClose);
1779 panelToClose.closePanel();
1780 panelToClose = null;
1782 tabbedPane.removeTabAt(closedindex);
1783 tabbedPane.validate();
1785 if (index > closedindex || index == tabbedPane.getTabCount())
1787 // modify currently selected tab index if necessary.
1791 this.tabSelectionChanged(index);
1797 void updateEditMenuBar()
1800 if (viewport.getHistoryList().size() > 0)
1802 undoMenuItem.setEnabled(true);
1803 CommandI command = viewport.getHistoryList().peek();
1804 undoMenuItem.setText(MessageManager
1805 .formatMessage("label.undo_command", new Object[]
1806 { command.getDescription() }));
1810 undoMenuItem.setEnabled(false);
1811 undoMenuItem.setText(MessageManager.getString("action.undo"));
1814 if (viewport.getRedoList().size() > 0)
1816 redoMenuItem.setEnabled(true);
1818 CommandI command = viewport.getRedoList().peek();
1819 redoMenuItem.setText(MessageManager
1820 .formatMessage("label.redo_command", new Object[]
1821 { command.getDescription() }));
1825 redoMenuItem.setEnabled(false);
1826 redoMenuItem.setText(MessageManager.getString("action.redo"));
1831 public void addHistoryItem(CommandI command)
1833 if (command.getSize() > 0)
1835 viewport.addToHistoryList(command);
1836 viewport.clearRedoList();
1837 updateEditMenuBar();
1838 viewport.updateHiddenColumns();
1839 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1840 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1841 // viewport.getColumnSelection()
1842 // .getHiddenColumns().size() > 0);
1848 * @return alignment objects for all views
1850 AlignmentI[] getViewAlignments()
1852 if (alignPanels != null)
1854 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1856 for (AlignmentPanel ap : alignPanels)
1858 als[i++] = ap.av.getAlignment();
1862 if (viewport != null)
1864 return new AlignmentI[] { viewport.getAlignment() };
1876 protected void undoMenuItem_actionPerformed(ActionEvent e)
1878 if (viewport.getHistoryList().isEmpty())
1882 CommandI command = viewport.getHistoryList().pop();
1883 viewport.addToRedoList(command);
1884 command.undoCommand(getViewAlignments());
1886 AlignmentViewport originalSource = getOriginatingSource(command);
1887 updateEditMenuBar();
1889 if (originalSource != null)
1891 if (originalSource != viewport)
1894 "Implementation worry: mismatch of viewport origin for undo");
1896 originalSource.updateHiddenColumns();
1897 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1899 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1900 // viewport.getColumnSelection()
1901 // .getHiddenColumns().size() > 0);
1902 originalSource.firePropertyChange("alignment", null,
1903 originalSource.getAlignment().getSequences());
1914 protected void redoMenuItem_actionPerformed(ActionEvent e)
1916 if (viewport.getRedoList().size() < 1)
1921 CommandI command = viewport.getRedoList().pop();
1922 viewport.addToHistoryList(command);
1923 command.doCommand(getViewAlignments());
1925 AlignmentViewport originalSource = getOriginatingSource(command);
1926 updateEditMenuBar();
1928 if (originalSource != null)
1931 if (originalSource != viewport)
1934 "Implementation worry: mismatch of viewport origin for redo");
1936 originalSource.updateHiddenColumns();
1937 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1939 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1940 // viewport.getColumnSelection()
1941 // .getHiddenColumns().size() > 0);
1942 originalSource.firePropertyChange("alignment", null,
1943 originalSource.getAlignment().getSequences());
1947 AlignmentViewport getOriginatingSource(CommandI command)
1949 AlignmentViewport originalSource = null;
1950 // For sequence removal and addition, we need to fire
1951 // the property change event FROM the viewport where the
1952 // original alignment was altered
1953 AlignmentI al = null;
1954 if (command instanceof EditCommand)
1956 EditCommand editCommand = (EditCommand) command;
1957 al = editCommand.getAlignment();
1958 List<Component> comps = PaintRefresher.components
1959 .get(viewport.getSequenceSetId());
1961 for (Component comp : comps)
1963 if (comp instanceof AlignmentPanel)
1965 if (al == ((AlignmentPanel) comp).av.getAlignment())
1967 originalSource = ((AlignmentPanel) comp).av;
1974 if (originalSource == null)
1976 // The original view is closed, we must validate
1977 // the current view against the closed view first
1980 PaintRefresher.validateSequences(al, viewport.getAlignment());
1983 originalSource = viewport;
1986 return originalSource;
1995 public void moveSelectedSequences(boolean up)
1997 SequenceGroup sg = viewport.getSelectionGroup();
2003 viewport.getAlignment().moveSelectedSequencesByOne(sg,
2004 viewport.getHiddenRepSequences(), up);
2005 alignPanel.paintAlignment(true, false);
2008 synchronized void slideSequences(boolean right, int size)
2010 List<SequenceI> sg = new ArrayList<>();
2011 if (viewport.cursorMode)
2013 sg.add(viewport.getAlignment()
2014 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
2016 else if (viewport.getSelectionGroup() != null
2017 && viewport.getSelectionGroup().getSize() != viewport
2018 .getAlignment().getHeight())
2020 sg = viewport.getSelectionGroup()
2021 .getSequences(viewport.getHiddenRepSequences());
2029 List<SequenceI> invertGroup = new ArrayList<>();
2031 for (SequenceI seq : viewport.getAlignment().getSequences())
2033 if (!sg.contains(seq))
2035 invertGroup.add(seq);
2039 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
2041 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
2042 for (int i = 0; i < invertGroup.size(); i++)
2044 seqs2[i] = invertGroup.get(i);
2047 SlideSequencesCommand ssc;
2050 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
2051 viewport.getGapCharacter());
2055 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
2056 viewport.getGapCharacter());
2059 int groupAdjustment = 0;
2060 if (ssc.getGapsInsertedBegin() && right)
2062 if (viewport.cursorMode)
2064 alignPanel.getSeqPanel().moveCursor(size, 0);
2068 groupAdjustment = size;
2071 else if (!ssc.getGapsInsertedBegin() && !right)
2073 if (viewport.cursorMode)
2075 alignPanel.getSeqPanel().moveCursor(-size, 0);
2079 groupAdjustment = -size;
2083 if (groupAdjustment != 0)
2085 viewport.getSelectionGroup().setStartRes(
2086 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
2087 viewport.getSelectionGroup().setEndRes(
2088 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
2092 * just extend the last slide command if compatible; but not if in
2093 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
2095 boolean appendHistoryItem = false;
2096 Deque<CommandI> historyList = viewport.getHistoryList();
2097 boolean inSplitFrame = getSplitViewContainer() != null;
2098 if (!inSplitFrame && historyList != null && historyList.size() > 0
2099 && historyList.peek() instanceof SlideSequencesCommand)
2101 appendHistoryItem = ssc.appendSlideCommand(
2102 (SlideSequencesCommand) historyList.peek());
2105 if (!appendHistoryItem)
2107 addHistoryItem(ssc);
2120 protected void copy_actionPerformed(ActionEvent e)
2122 if (viewport.getSelectionGroup() == null)
2126 // TODO: preserve the ordering of displayed alignment annotation in any
2127 // internal paste (particularly sequence associated annotation)
2128 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
2129 String[] omitHidden = null;
2131 if (viewport.hasHiddenColumns())
2133 omitHidden = viewport.getViewAsString(true);
2136 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
2137 seqs, omitHidden, null);
2139 StringSelection ss = new StringSelection(output);
2143 jalview.gui.Desktop.internalCopy = true;
2144 // Its really worth setting the clipboard contents
2145 // to empty before setting the large StringSelection!!
2146 Toolkit.getDefaultToolkit().getSystemClipboard()
2147 .setContents(new StringSelection(""), null);
2149 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
2151 } catch (OutOfMemoryError er)
2153 new OOMWarning("copying region", er);
2157 HiddenColumns hiddenColumns = null;
2158 if (viewport.hasHiddenColumns())
2160 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
2161 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
2163 // create new HiddenColumns object with copy of hidden regions
2164 // between startRes and endRes, offset by startRes
2165 hiddenColumns = new HiddenColumns(
2166 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2167 hiddenCutoff, hiddenOffset);
2170 Desktop.jalviewClipboard = new Object[] { seqs,
2171 viewport.getAlignment().getDataset(), hiddenColumns };
2172 statusBar.setText(MessageManager.formatMessage(
2173 "label.copied_sequences_to_clipboard", new Object[]
2174 { Integer.valueOf(seqs.length).toString() }));
2182 * @throws InterruptedException
2183 * @throws IOException
2186 protected void pasteNew_actionPerformed(ActionEvent e)
2187 throws IOException, InterruptedException
2197 * @throws InterruptedException
2198 * @throws IOException
2201 protected void pasteThis_actionPerformed(ActionEvent e)
2202 throws IOException, InterruptedException
2208 * Paste contents of Jalview clipboard
2210 * @param newAlignment
2211 * true to paste to a new alignment, otherwise add to this.
2212 * @throws InterruptedException
2213 * @throws IOException
2215 void paste(boolean newAlignment) throws IOException, InterruptedException
2217 boolean externalPaste = true;
2220 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2221 Transferable contents = c.getContents(this);
2223 if (contents == null)
2232 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2233 if (str.length() < 1)
2238 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2240 } catch (OutOfMemoryError er)
2242 new OOMWarning("Out of memory pasting sequences!!", er);
2246 SequenceI[] sequences;
2247 boolean annotationAdded = false;
2248 AlignmentI alignment = null;
2250 if (Desktop.jalviewClipboard != null)
2252 // The clipboard was filled from within Jalview, we must use the
2254 // And dataset from the copied alignment
2255 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2256 // be doubly sure that we create *new* sequence objects.
2257 sequences = new SequenceI[newseq.length];
2258 for (int i = 0; i < newseq.length; i++)
2260 sequences[i] = new Sequence(newseq[i]);
2262 alignment = new Alignment(sequences);
2263 externalPaste = false;
2267 // parse the clipboard as an alignment.
2268 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2270 sequences = alignment.getSequencesArray();
2274 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2280 if (Desktop.jalviewClipboard != null)
2282 // dataset is inherited
2283 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2287 // new dataset is constructed
2288 alignment.setDataset(null);
2290 alwidth = alignment.getWidth() + 1;
2294 AlignmentI pastedal = alignment; // preserve pasted alignment object
2295 // Add pasted sequences and dataset into existing alignment.
2296 alignment = viewport.getAlignment();
2297 alwidth = alignment.getWidth() + 1;
2298 // decide if we need to import sequences from an existing dataset
2299 boolean importDs = Desktop.jalviewClipboard != null
2300 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2301 // importDs==true instructs us to copy over new dataset sequences from
2302 // an existing alignment
2303 Vector newDs = (importDs) ? new Vector() : null; // used to create
2304 // minimum dataset set
2306 for (int i = 0; i < sequences.length; i++)
2310 newDs.addElement(null);
2312 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2314 if (importDs && ds != null)
2316 if (!newDs.contains(ds))
2318 newDs.setElementAt(ds, i);
2319 ds = new Sequence(ds);
2320 // update with new dataset sequence
2321 sequences[i].setDatasetSequence(ds);
2325 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2330 // copy and derive new dataset sequence
2331 sequences[i] = sequences[i].deriveSequence();
2332 alignment.getDataset()
2333 .addSequence(sequences[i].getDatasetSequence());
2334 // TODO: avoid creation of duplicate dataset sequences with a
2335 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2337 alignment.addSequence(sequences[i]); // merges dataset
2341 newDs.clear(); // tidy up
2343 if (alignment.getAlignmentAnnotation() != null)
2345 for (AlignmentAnnotation alan : alignment
2346 .getAlignmentAnnotation())
2348 if (alan.graphGroup > fgroup)
2350 fgroup = alan.graphGroup;
2354 if (pastedal.getAlignmentAnnotation() != null)
2356 // Add any annotation attached to alignment.
2357 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2358 for (int i = 0; i < alann.length; i++)
2360 annotationAdded = true;
2361 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2363 AlignmentAnnotation newann = new AlignmentAnnotation(
2365 if (newann.graphGroup > -1)
2367 if (newGraphGroups.size() <= newann.graphGroup
2368 || newGraphGroups.get(newann.graphGroup) == null)
2370 for (int q = newGraphGroups
2371 .size(); q <= newann.graphGroup; q++)
2373 newGraphGroups.add(q, null);
2375 newGraphGroups.set(newann.graphGroup,
2376 Integer.valueOf(++fgroup));
2378 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2382 newann.padAnnotation(alwidth);
2383 alignment.addAnnotation(newann);
2393 addHistoryItem(new EditCommand(
2394 MessageManager.getString("label.add_sequences"),
2395 Action.PASTE, sequences, 0, alignment.getWidth(),
2398 // Add any annotations attached to sequences
2399 for (int i = 0; i < sequences.length; i++)
2401 if (sequences[i].getAnnotation() != null)
2403 AlignmentAnnotation newann;
2404 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2406 annotationAdded = true;
2407 newann = sequences[i].getAnnotation()[a];
2408 newann.adjustForAlignment();
2409 newann.padAnnotation(alwidth);
2410 if (newann.graphGroup > -1)
2412 if (newann.graphGroup > -1)
2414 if (newGraphGroups.size() <= newann.graphGroup
2415 || newGraphGroups.get(newann.graphGroup) == null)
2417 for (int q = newGraphGroups
2418 .size(); q <= newann.graphGroup; q++)
2420 newGraphGroups.add(q, null);
2422 newGraphGroups.set(newann.graphGroup,
2423 Integer.valueOf(++fgroup));
2425 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2429 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2433 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2441 // propagate alignment changed.
2442 viewport.getRanges().setEndSeq(alignment.getHeight());
2443 if (annotationAdded)
2445 // Duplicate sequence annotation in all views.
2446 AlignmentI[] alview = this.getViewAlignments();
2447 for (int i = 0; i < sequences.length; i++)
2449 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2454 for (int avnum = 0; avnum < alview.length; avnum++)
2456 if (alview[avnum] != alignment)
2458 // duplicate in a view other than the one with input focus
2459 int avwidth = alview[avnum].getWidth() + 1;
2460 // this relies on sann being preserved after we
2461 // modify the sequence's annotation array for each duplication
2462 for (int a = 0; a < sann.length; a++)
2464 AlignmentAnnotation newann = new AlignmentAnnotation(
2466 sequences[i].addAlignmentAnnotation(newann);
2467 newann.padAnnotation(avwidth);
2468 alview[avnum].addAnnotation(newann); // annotation was
2469 // duplicated earlier
2470 // TODO JAL-1145 graphGroups are not updated for sequence
2471 // annotation added to several views. This may cause
2473 alview[avnum].setAnnotationIndex(newann, a);
2478 buildSortByAnnotationScoresMenu();
2480 viewport.firePropertyChange("alignment", null,
2481 alignment.getSequences());
2482 if (alignPanels != null)
2484 for (AlignmentPanel ap : alignPanels)
2486 ap.validateAnnotationDimensions(false);
2491 alignPanel.validateAnnotationDimensions(false);
2497 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2499 String newtitle = new String("Copied sequences");
2501 if (Desktop.jalviewClipboard != null
2502 && Desktop.jalviewClipboard[2] != null)
2504 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2505 af.viewport.setHiddenColumns(hc);
2508 // >>>This is a fix for the moment, until a better solution is
2510 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2511 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2512 .getFeatureRenderer());
2514 // TODO: maintain provenance of an alignment, rather than just make the
2515 // title a concatenation of operations.
2518 if (title.startsWith("Copied sequences"))
2524 newtitle = newtitle.concat("- from " + title);
2529 newtitle = new String("Pasted sequences");
2532 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2537 } catch (Exception ex)
2539 ex.printStackTrace();
2540 System.out.println("Exception whilst pasting: " + ex);
2541 // could be anything being pasted in here
2546 protected void expand_newalign(ActionEvent e)
2550 AlignmentI alignment = AlignmentUtils
2551 .expandContext(getViewport().getAlignment(), -1);
2552 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2554 String newtitle = new String("Flanking alignment");
2556 if (Desktop.jalviewClipboard != null
2557 && Desktop.jalviewClipboard[2] != null)
2559 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2560 af.viewport.setHiddenColumns(hc);
2563 // >>>This is a fix for the moment, until a better solution is
2565 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2566 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2567 .getFeatureRenderer());
2569 // TODO: maintain provenance of an alignment, rather than just make the
2570 // title a concatenation of operations.
2572 if (title.startsWith("Copied sequences"))
2578 newtitle = newtitle.concat("- from " + title);
2582 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2584 } catch (Exception ex)
2586 ex.printStackTrace();
2587 System.out.println("Exception whilst pasting: " + ex);
2588 // could be anything being pasted in here
2589 } catch (OutOfMemoryError oom)
2591 new OOMWarning("Viewing flanking region of alignment", oom);
2602 protected void cut_actionPerformed(ActionEvent e)
2604 copy_actionPerformed(null);
2605 delete_actionPerformed(null);
2615 protected void delete_actionPerformed(ActionEvent evt)
2618 SequenceGroup sg = viewport.getSelectionGroup();
2625 * If the cut affects all sequences, warn, remove highlighted columns
2627 if (sg.getSize() == viewport.getAlignment().getHeight())
2629 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
2630 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2631 if (isEntireAlignWidth)
2633 int confirm = JvOptionPane.showConfirmDialog(this,
2634 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2635 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2636 JvOptionPane.OK_CANCEL_OPTION);
2638 if (confirm == JvOptionPane.CANCEL_OPTION
2639 || confirm == JvOptionPane.CLOSED_OPTION)
2644 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2645 sg.getEndRes() + 1);
2647 SequenceI[] cut = sg.getSequences()
2648 .toArray(new SequenceI[sg.getSize()]);
2650 addHistoryItem(new EditCommand(
2651 MessageManager.getString("label.cut_sequences"), Action.CUT,
2652 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2653 viewport.getAlignment()));
2655 viewport.setSelectionGroup(null);
2656 viewport.sendSelection();
2657 viewport.getAlignment().deleteGroup(sg);
2659 viewport.firePropertyChange("alignment", null,
2660 viewport.getAlignment().getSequences());
2661 if (viewport.getAlignment().getHeight() < 1)
2665 this.setClosed(true);
2666 } catch (Exception ex)
2679 protected void deleteGroups_actionPerformed(ActionEvent e)
2681 if (avc.deleteGroups())
2683 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2684 alignPanel.updateAnnotation();
2685 alignPanel.paintAlignment(true, true);
2696 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2698 SequenceGroup sg = new SequenceGroup(
2699 viewport.getAlignment().getSequences());
2701 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2702 viewport.setSelectionGroup(sg);
2703 viewport.isSelectionGroupChanged(true);
2704 viewport.sendSelection();
2705 // JAL-2034 - should delegate to
2706 // alignPanel to decide if overview needs
2708 alignPanel.paintAlignment(false, false);
2709 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2719 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2721 if (viewport.cursorMode)
2723 alignPanel.getSeqPanel().keyboardNo1 = null;
2724 alignPanel.getSeqPanel().keyboardNo2 = null;
2726 viewport.setSelectionGroup(null);
2727 viewport.getColumnSelection().clear();
2728 viewport.setSelectionGroup(null);
2729 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2730 // JAL-2034 - should delegate to
2731 // alignPanel to decide if overview needs
2733 alignPanel.paintAlignment(false, false);
2734 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2735 viewport.sendSelection();
2745 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2747 SequenceGroup sg = viewport.getSelectionGroup();
2751 selectAllSequenceMenuItem_actionPerformed(null);
2756 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2758 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2760 // JAL-2034 - should delegate to
2761 // alignPanel to decide if overview needs
2764 alignPanel.paintAlignment(true, false);
2765 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2766 viewport.sendSelection();
2770 public void invertColSel_actionPerformed(ActionEvent e)
2772 viewport.invertColumnSelection();
2773 alignPanel.paintAlignment(true, false);
2774 viewport.sendSelection();
2784 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2786 trimAlignment(true);
2796 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2798 trimAlignment(false);
2801 void trimAlignment(boolean trimLeft)
2803 ColumnSelection colSel = viewport.getColumnSelection();
2806 if (!colSel.isEmpty())
2810 column = colSel.getMin();
2814 column = colSel.getMax();
2818 if (viewport.getSelectionGroup() != null)
2820 seqs = viewport.getSelectionGroup()
2821 .getSequencesAsArray(viewport.getHiddenRepSequences());
2825 seqs = viewport.getAlignment().getSequencesArray();
2828 TrimRegionCommand trimRegion;
2831 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2832 column, viewport.getAlignment());
2833 viewport.getRanges().setStartRes(0);
2837 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2838 column, viewport.getAlignment());
2841 statusBar.setText(MessageManager
2842 .formatMessage("label.removed_columns", new String[]
2843 { Integer.valueOf(trimRegion.getSize()).toString() }));
2845 addHistoryItem(trimRegion);
2847 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2849 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2850 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2852 viewport.getAlignment().deleteGroup(sg);
2856 viewport.firePropertyChange("alignment", null,
2857 viewport.getAlignment().getSequences());
2868 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2870 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2873 if (viewport.getSelectionGroup() != null)
2875 seqs = viewport.getSelectionGroup()
2876 .getSequencesAsArray(viewport.getHiddenRepSequences());
2877 start = viewport.getSelectionGroup().getStartRes();
2878 end = viewport.getSelectionGroup().getEndRes();
2882 seqs = viewport.getAlignment().getSequencesArray();
2885 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2886 "Remove Gapped Columns", seqs, start, end,
2887 viewport.getAlignment());
2889 addHistoryItem(removeGapCols);
2891 statusBar.setText(MessageManager
2892 .formatMessage("label.removed_empty_columns", new Object[]
2893 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2895 // This is to maintain viewport position on first residue
2896 // of first sequence
2897 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2898 ViewportRanges ranges = viewport.getRanges();
2899 int startRes = seq.findPosition(ranges.getStartRes());
2900 // ShiftList shifts;
2901 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2902 // edit.alColumnChanges=shifts.getInverse();
2903 // if (viewport.hasHiddenColumns)
2904 // viewport.getColumnSelection().compensateForEdits(shifts);
2905 ranges.setStartRes(seq.findIndex(startRes) - 1);
2906 viewport.firePropertyChange("alignment", null,
2907 viewport.getAlignment().getSequences());
2918 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2920 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2923 if (viewport.getSelectionGroup() != null)
2925 seqs = viewport.getSelectionGroup()
2926 .getSequencesAsArray(viewport.getHiddenRepSequences());
2927 start = viewport.getSelectionGroup().getStartRes();
2928 end = viewport.getSelectionGroup().getEndRes();
2932 seqs = viewport.getAlignment().getSequencesArray();
2935 // This is to maintain viewport position on first residue
2936 // of first sequence
2937 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2938 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2940 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2941 viewport.getAlignment()));
2943 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2945 viewport.firePropertyChange("alignment", null,
2946 viewport.getAlignment().getSequences());
2957 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2959 viewport.setPadGaps(padGapsMenuitem.isSelected());
2960 viewport.firePropertyChange("alignment", null,
2961 viewport.getAlignment().getSequences());
2971 public void findMenuItem_actionPerformed(ActionEvent e)
2977 * Create a new view of the current alignment.
2980 public void newView_actionPerformed(ActionEvent e)
2982 newView(null, true);
2986 * Creates and shows a new view of the current alignment.
2989 * title of newly created view; if null, one will be generated
2990 * @param copyAnnotation
2991 * if true then duplicate all annnotation, groups and settings
2992 * @return new alignment panel, already displayed.
2994 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2997 * Create a new AlignmentPanel (with its own, new Viewport)
2999 AlignmentPanel newap = new jalview.project.Jalview2XML()
3000 .copyAlignPanel(alignPanel);
3001 if (!copyAnnotation)
3004 * remove all groups and annotation except for the automatic stuff
3006 newap.av.getAlignment().deleteAllGroups();
3007 newap.av.getAlignment().deleteAllAnnotations(false);
3010 newap.av.setGatherViewsHere(false);
3012 if (viewport.getViewName() == null)
3014 viewport.setViewName(MessageManager
3015 .getString("label.view_name_original"));
3019 * Views share the same edits undo and redo stacks
3021 newap.av.setHistoryList(viewport.getHistoryList());
3022 newap.av.setRedoList(viewport.getRedoList());
3025 * copy any visualisation settings that are not saved in the project
3027 newap.av.setColourAppliesToAllGroups(
3028 viewport.getColourAppliesToAllGroups());
3031 * Views share the same mappings; need to deregister any new mappings
3032 * created by copyAlignPanel, and register the new reference to the shared
3035 newap.av.replaceMappings(viewport.getAlignment());
3038 * start up cDNA consensus (if applicable) now mappings are in place
3040 if (newap.av.initComplementConsensus())
3042 newap.refresh(true); // adjust layout of annotations
3045 newap.av.setViewName(getNewViewName(viewTitle));
3047 addAlignmentPanel(newap, true);
3048 newap.alignmentChanged();
3050 if (alignPanels.size() == 2)
3052 viewport.setGatherViewsHere(true);
3054 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
3059 * Make a new name for the view, ensuring it is unique within the current
3060 * sequenceSetId. (This used to be essential for Jalview Project archives, but
3061 * these now use viewId. Unique view names are still desirable for usability.)
3066 protected String getNewViewName(String viewTitle)
3068 int index = Desktop.getViewCount(viewport.getSequenceSetId());
3069 boolean addFirstIndex = false;
3070 if (viewTitle == null || viewTitle.trim().length() == 0)
3072 viewTitle = MessageManager.getString("action.view");
3073 addFirstIndex = true;
3077 index = 1;// we count from 1 if given a specific name
3079 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
3081 List<Component> comps = PaintRefresher.components
3082 .get(viewport.getSequenceSetId());
3084 List<String> existingNames = getExistingViewNames(comps);
3086 while (existingNames.contains(newViewName))
3088 newViewName = viewTitle + " " + (++index);
3094 * Returns a list of distinct view names found in the given list of
3095 * components. View names are held on the viewport of an AlignmentPanel.
3100 protected List<String> getExistingViewNames(List<Component> comps)
3102 List<String> existingNames = new ArrayList<>();
3103 for (Component comp : comps)
3105 if (comp instanceof AlignmentPanel)
3107 AlignmentPanel ap = (AlignmentPanel) comp;
3108 if (!existingNames.contains(ap.av.getViewName()))
3110 existingNames.add(ap.av.getViewName());
3114 return existingNames;
3118 * Explode tabbed views into separate windows.
3121 public void expandViews_actionPerformed(ActionEvent e)
3123 Desktop.explodeViews(this);
3127 * Gather views in separate windows back into a tabbed presentation.
3130 public void gatherViews_actionPerformed(ActionEvent e)
3132 Desktop.instance.gatherViews(this);
3142 public void font_actionPerformed(ActionEvent e)
3144 new FontChooser(alignPanel);
3154 protected void seqLimit_actionPerformed(ActionEvent e)
3156 viewport.setShowJVSuffix(seqLimits.isSelected());
3158 alignPanel.getIdPanel().getIdCanvas()
3159 .setPreferredSize(alignPanel.calculateIdWidth());
3160 alignPanel.paintAlignment(true, false);
3164 public void idRightAlign_actionPerformed(ActionEvent e)
3166 viewport.setRightAlignIds(idRightAlign.isSelected());
3167 alignPanel.paintAlignment(false, false);
3171 public void centreColumnLabels_actionPerformed(ActionEvent e)
3173 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3174 alignPanel.paintAlignment(false, false);
3180 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3183 protected void followHighlight_actionPerformed()
3186 * Set the 'follow' flag on the Viewport (and scroll to position if now
3189 final boolean state = this.followHighlightMenuItem.getState();
3190 viewport.setFollowHighlight(state);
3193 alignPanel.scrollToPosition(viewport.getSearchResults());
3204 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3206 viewport.setColourText(colourTextMenuItem.isSelected());
3207 alignPanel.paintAlignment(false, false);
3217 public void wrapMenuItem_actionPerformed(ActionEvent e)
3219 scaleAbove.setVisible(wrapMenuItem.isSelected());
3220 scaleLeft.setVisible(wrapMenuItem.isSelected());
3221 scaleRight.setVisible(wrapMenuItem.isSelected());
3222 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3223 alignPanel.updateLayout();
3227 public void showAllSeqs_actionPerformed(ActionEvent e)
3229 viewport.showAllHiddenSeqs();
3233 public void showAllColumns_actionPerformed(ActionEvent e)
3235 viewport.showAllHiddenColumns();
3236 alignPanel.paintAlignment(true, true);
3237 viewport.sendSelection();
3241 public void hideSelSequences_actionPerformed(ActionEvent e)
3243 viewport.hideAllSelectedSeqs();
3247 * called by key handler and the hide all/show all menu items
3252 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3255 boolean hide = false;
3256 SequenceGroup sg = viewport.getSelectionGroup();
3257 if (!toggleSeqs && !toggleCols)
3259 // Hide everything by the current selection - this is a hack - we do the
3260 // invert and then hide
3261 // first check that there will be visible columns after the invert.
3262 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3263 && sg.getStartRes() <= sg.getEndRes()))
3265 // now invert the sequence set, if required - empty selection implies
3266 // that no hiding is required.
3269 invertSequenceMenuItem_actionPerformed(null);
3270 sg = viewport.getSelectionGroup();
3274 viewport.expandColSelection(sg, true);
3275 // finally invert the column selection and get the new sequence
3277 invertColSel_actionPerformed(null);
3284 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3286 hideSelSequences_actionPerformed(null);
3289 else if (!(toggleCols && viewport.hasSelectedColumns()))
3291 showAllSeqs_actionPerformed(null);
3297 if (viewport.hasSelectedColumns())
3299 hideSelColumns_actionPerformed(null);
3302 viewport.setSelectionGroup(sg);
3307 showAllColumns_actionPerformed(null);
3316 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3317 * event.ActionEvent)
3320 public void hideAllButSelection_actionPerformed(ActionEvent e)
3322 toggleHiddenRegions(false, false);
3323 viewport.sendSelection();
3330 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3334 public void hideAllSelection_actionPerformed(ActionEvent e)
3336 SequenceGroup sg = viewport.getSelectionGroup();
3337 viewport.expandColSelection(sg, false);
3338 viewport.hideAllSelectedSeqs();
3339 viewport.hideSelectedColumns();
3340 alignPanel.updateLayout();
3341 alignPanel.paintAlignment(true, true);
3342 viewport.sendSelection();
3349 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3353 public void showAllhidden_actionPerformed(ActionEvent e)
3355 viewport.showAllHiddenColumns();
3356 viewport.showAllHiddenSeqs();
3357 alignPanel.paintAlignment(true, true);
3358 viewport.sendSelection();
3362 public void hideSelColumns_actionPerformed(ActionEvent e)
3364 viewport.hideSelectedColumns();
3365 alignPanel.updateLayout();
3366 alignPanel.paintAlignment(true, true);
3367 viewport.sendSelection();
3371 public void hiddenMarkers_actionPerformed(ActionEvent e)
3373 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3384 protected void scaleAbove_actionPerformed(ActionEvent e)
3386 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3387 alignPanel.updateLayout();
3388 alignPanel.paintAlignment(true, false);
3398 protected void scaleLeft_actionPerformed(ActionEvent e)
3400 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3401 alignPanel.updateLayout();
3402 alignPanel.paintAlignment(true, false);
3412 protected void scaleRight_actionPerformed(ActionEvent e)
3414 viewport.setScaleRightWrapped(scaleRight.isSelected());
3415 alignPanel.updateLayout();
3416 alignPanel.paintAlignment(true, false);
3426 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3428 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3429 alignPanel.paintAlignment(false, false);
3439 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3441 viewport.setShowText(viewTextMenuItem.isSelected());
3442 alignPanel.paintAlignment(false, false);
3452 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3454 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3455 alignPanel.paintAlignment(false, false);
3458 public FeatureSettings featureSettings;
3461 public FeatureSettingsControllerI getFeatureSettingsUI()
3463 return featureSettings;
3467 public void featureSettings_actionPerformed(ActionEvent e)
3469 if (featureSettings != null)
3471 featureSettings.close();
3472 featureSettings = null;
3474 if (!showSeqFeatures.isSelected())
3476 // make sure features are actually displayed
3477 showSeqFeatures.setSelected(true);
3478 showSeqFeatures_actionPerformed(null);
3480 featureSettings = new FeatureSettings(this);
3484 * Set or clear 'Show Sequence Features'
3490 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3492 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3493 alignPanel.paintAlignment(true, true);
3497 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3498 * the annotations panel as a whole.
3500 * The options to show/hide all annotations should be enabled when the panel
3501 * is shown, and disabled when the panel is hidden.
3506 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3508 final boolean setVisible = annotationPanelMenuItem.isSelected();
3509 viewport.setShowAnnotation(setVisible);
3510 this.showAllSeqAnnotations.setEnabled(setVisible);
3511 this.hideAllSeqAnnotations.setEnabled(setVisible);
3512 this.showAllAlAnnotations.setEnabled(setVisible);
3513 this.hideAllAlAnnotations.setEnabled(setVisible);
3514 alignPanel.updateLayout();
3518 public void alignmentProperties()
3520 JEditorPane editPane = new JEditorPane("text/html", "");
3521 editPane.setEditable(false);
3522 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3525 MessageManager.formatMessage("label.html_content", new Object[]
3526 { contents.toString() }));
3527 JInternalFrame frame = new JInternalFrame();
3528 frame.getContentPane().add(new JScrollPane(editPane));
3530 Desktop.addInternalFrame(frame, MessageManager
3531 .formatMessage("label.alignment_properties", new Object[]
3532 { getTitle() }), 500, 400);
3542 public void overviewMenuItem_actionPerformed(ActionEvent e)
3544 if (alignPanel.overviewPanel != null)
3549 JInternalFrame frame = new JInternalFrame();
3550 final OverviewPanel overview = new OverviewPanel(alignPanel);
3551 frame.setContentPane(overview);
3552 Desktop.addInternalFrame(frame, MessageManager
3553 .formatMessage("label.overview_params", new Object[]
3554 { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
3557 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3558 frame.addInternalFrameListener(
3559 new javax.swing.event.InternalFrameAdapter()
3562 public void internalFrameClosed(
3563 javax.swing.event.InternalFrameEvent evt)
3566 alignPanel.setOverviewPanel(null);
3569 if (getKeyListeners().length > 0)
3571 frame.addKeyListener(getKeyListeners()[0]);
3574 alignPanel.setOverviewPanel(overview);
3578 public void textColour_actionPerformed()
3580 new TextColourChooser().chooseColour(alignPanel, null);
3584 * public void covariationColour_actionPerformed() {
3586 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3590 public void annotationColour_actionPerformed()
3592 new AnnotationColourChooser(viewport, alignPanel);
3596 public void annotationColumn_actionPerformed(ActionEvent e)
3598 new AnnotationColumnChooser(viewport, alignPanel);
3602 * Action on the user checking or unchecking the option to apply the selected
3603 * colour scheme to all groups. If unchecked, groups may have their own
3604 * independent colour schemes.
3609 public void applyToAllGroups_actionPerformed(boolean selected)
3611 viewport.setColourAppliesToAllGroups(selected);
3615 * Action on user selecting a colour from the colour menu
3618 * the name (not the menu item label!) of the colour scheme
3621 public void changeColour_actionPerformed(String name)
3624 * 'User Defined' opens a panel to configure or load a
3625 * user-defined colour scheme
3627 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3629 new UserDefinedColours(alignPanel);
3634 * otherwise set the chosen colour scheme (or null for 'None')
3636 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3638 viewport.getAlignment(), viewport.getHiddenRepSequences());
3643 * Actions on setting or changing the alignment colour scheme
3648 public void changeColour(ColourSchemeI cs)
3650 // TODO: pull up to controller method
3651 ColourMenuHelper.setColourSelected(colourMenu, cs);
3653 viewport.setGlobalColourScheme(cs);
3655 alignPanel.paintAlignment(true, true);
3659 * Show the PID threshold slider panel
3662 protected void modifyPID_actionPerformed()
3664 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3665 alignPanel.getViewName());
3666 SliderPanel.showPIDSlider();
3670 * Show the Conservation slider panel
3673 protected void modifyConservation_actionPerformed()
3675 SliderPanel.setConservationSlider(alignPanel,
3676 viewport.getResidueShading(), alignPanel.getViewName());
3677 SliderPanel.showConservationSlider();
3681 * Action on selecting or deselecting (Colour) By Conservation
3684 public void conservationMenuItem_actionPerformed(boolean selected)
3686 modifyConservation.setEnabled(selected);
3687 viewport.setConservationSelected(selected);
3688 viewport.getResidueShading().setConservationApplied(selected);
3690 changeColour(viewport.getGlobalColourScheme());
3693 modifyConservation_actionPerformed();
3697 SliderPanel.hideConservationSlider();
3702 * Action on selecting or deselecting (Colour) Above PID Threshold
3705 public void abovePIDThreshold_actionPerformed(boolean selected)
3707 modifyPID.setEnabled(selected);
3708 viewport.setAbovePIDThreshold(selected);
3711 viewport.getResidueShading().setThreshold(0,
3712 viewport.isIgnoreGapsConsensus());
3715 changeColour(viewport.getGlobalColourScheme());
3718 modifyPID_actionPerformed();
3722 SliderPanel.hidePIDSlider();
3733 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3735 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3736 AlignmentSorter.sortByPID(viewport.getAlignment(),
3737 viewport.getAlignment().getSequenceAt(0));
3738 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3739 viewport.getAlignment()));
3740 alignPanel.paintAlignment(true, false);
3750 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3752 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3753 AlignmentSorter.sortByID(viewport.getAlignment());
3755 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3756 alignPanel.paintAlignment(true, false);
3766 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3768 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3769 AlignmentSorter.sortByLength(viewport.getAlignment());
3770 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3771 viewport.getAlignment()));
3772 alignPanel.paintAlignment(true, false);
3782 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3784 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3785 AlignmentSorter.sortByGroup(viewport.getAlignment());
3786 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3787 viewport.getAlignment()));
3789 alignPanel.paintAlignment(true, false);
3793 public void sortEValueMenuItem_actionPerformed(ActionEvent e)
3795 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3796 AlignmentSorter.sortByEValue(viewport.getAlignment());
3797 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3798 viewport.getAlignment()));
3799 alignPanel.paintAlignment(true, false);
3804 public void sortBitScoreMenuItem_actionPerformed(ActionEvent e)
3806 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3807 AlignmentSorter.sortByBitScore(viewport.getAlignment());
3808 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3809 viewport.getAlignment()));
3810 alignPanel.paintAlignment(true, false);
3821 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3823 new RedundancyPanel(alignPanel, this);
3833 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3835 if ((viewport.getSelectionGroup() == null)
3836 || (viewport.getSelectionGroup().getSize() < 2))
3838 JvOptionPane.showInternalMessageDialog(this,
3839 MessageManager.getString(
3840 "label.you_must_select_least_two_sequences"),
3841 MessageManager.getString("label.invalid_selection"),
3842 JvOptionPane.WARNING_MESSAGE);
3846 JInternalFrame frame = new JInternalFrame();
3847 frame.setContentPane(new PairwiseAlignPanel(viewport));
3848 Desktop.addInternalFrame(frame,
3849 MessageManager.getString("action.pairwise_alignment"), 600,
3855 public void autoCalculate_actionPerformed(ActionEvent e)
3857 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3858 if (viewport.autoCalculateConsensus)
3860 viewport.firePropertyChange("alignment", null,
3861 viewport.getAlignment().getSequences());
3866 public void sortByTreeOption_actionPerformed(ActionEvent e)
3868 viewport.sortByTree = sortByTree.isSelected();
3872 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3874 viewport.followSelection = listenToViewSelections.isSelected();
3878 * Constructs a tree panel and adds it to the desktop
3881 * tree type (NJ or AV)
3883 * name of score model used to compute the tree
3885 * parameters for the distance or similarity calculation
3887 void newTreePanel(String type, String modelName,
3888 SimilarityParamsI options)
3890 String frameTitle = "";
3893 boolean onSelection = false;
3894 if (viewport.getSelectionGroup() != null
3895 && viewport.getSelectionGroup().getSize() > 0)
3897 SequenceGroup sg = viewport.getSelectionGroup();
3899 /* Decide if the selection is a column region */
3900 for (SequenceI _s : sg.getSequences())
3902 if (_s.getLength() < sg.getEndRes())
3904 JvOptionPane.showMessageDialog(Desktop.desktop,
3905 MessageManager.getString(
3906 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3907 MessageManager.getString(
3908 "label.sequences_selection_not_aligned"),
3909 JvOptionPane.WARNING_MESSAGE);
3918 if (viewport.getAlignment().getHeight() < 2)
3924 tp = new TreePanel(alignPanel, type, modelName, options);
3925 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3927 frameTitle += " from ";
3929 if (viewport.getViewName() != null)
3931 frameTitle += viewport.getViewName() + " of ";
3934 frameTitle += this.title;
3936 Desktop.addInternalFrame(tp, frameTitle, 600, 500);
3947 public void addSortByOrderMenuItem(String title,
3948 final AlignmentOrder order)
3950 final JMenuItem item = new JMenuItem(MessageManager
3951 .formatMessage("action.by_title_param", new Object[]
3954 item.addActionListener(new java.awt.event.ActionListener()
3957 public void actionPerformed(ActionEvent e)
3959 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3961 // TODO: JBPNote - have to map order entries to curent SequenceI
3963 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3965 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3966 viewport.getAlignment()));
3968 alignPanel.paintAlignment(true, false);
3974 * Add a new sort by annotation score menu item
3977 * the menu to add the option to
3979 * the label used to retrieve scores for each sequence on the
3982 public void addSortByAnnotScoreMenuItem(JMenu sort,
3983 final String scoreLabel)
3985 final JMenuItem item = new JMenuItem(scoreLabel);
3987 item.addActionListener(new java.awt.event.ActionListener()
3990 public void actionPerformed(ActionEvent e)
3992 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3993 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3994 viewport.getAlignment());// ,viewport.getSelectionGroup());
3995 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3996 viewport.getAlignment()));
3997 alignPanel.paintAlignment(true, false);
4003 * last hash for alignment's annotation array - used to minimise cost of
4006 protected int _annotationScoreVectorHash;
4009 * search the alignment and rebuild the sort by annotation score submenu the
4010 * last alignment annotation vector hash is stored to minimize cost of
4011 * rebuilding in subsequence calls.
4015 public void buildSortByAnnotationScoresMenu()
4017 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4022 if (viewport.getAlignment().getAlignmentAnnotation()
4023 .hashCode() == _annotationScoreVectorHash)
4028 sortByAnnotScore.removeAll();
4029 Set<String> scoreSorts = new HashSet<>();
4030 for (SequenceI sqa : viewport.getAlignment().getSequences())
4032 AlignmentAnnotation[] anns = sqa.getAnnotation();
4033 for (int i = 0; anns != null && i < anns.length; i++)
4035 AlignmentAnnotation aa = anns[i];
4036 if (aa != null && aa.hasScore() && aa.sequenceRef != null)
4038 scoreSorts.add(aa.label);
4042 for (String label : scoreSorts)
4044 addSortByAnnotScoreMenuItem(sortByAnnotScore, label);
4046 sortByAnnotScore.setVisible(!scoreSorts.isEmpty());
4048 _annotationScoreVectorHash = viewport.getAlignment()
4049 .getAlignmentAnnotation().hashCode();
4053 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4054 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4055 * call. Listeners are added to remove the menu item when the treePanel is
4056 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4060 public void buildTreeSortMenu()
4062 sortByTreeMenu.removeAll();
4064 List<Component> comps = PaintRefresher.components
4065 .get(viewport.getSequenceSetId());
4066 List<TreePanel> treePanels = new ArrayList<>();
4067 for (Component comp : comps)
4069 if (comp instanceof TreePanel)
4071 treePanels.add((TreePanel) comp);
4075 if (treePanels.size() < 1)
4077 sortByTreeMenu.setVisible(false);
4081 sortByTreeMenu.setVisible(true);
4083 for (final TreePanel tp : treePanels)
4085 final JMenuItem item = new JMenuItem(tp.getTitle());
4086 item.addActionListener(new java.awt.event.ActionListener()
4089 public void actionPerformed(ActionEvent e)
4091 tp.sortByTree_actionPerformed();
4092 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4097 sortByTreeMenu.add(item);
4101 public boolean sortBy(AlignmentOrder alorder, String undoname)
4103 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4104 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4105 if (undoname != null)
4107 addHistoryItem(new OrderCommand(undoname, oldOrder,
4108 viewport.getAlignment()));
4110 alignPanel.paintAlignment(true, false);
4115 * Work out whether the whole set of sequences or just the selected set will
4116 * be submitted for multiple alignment.
4119 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4121 // Now, check we have enough sequences
4122 AlignmentView msa = null;
4124 if ((viewport.getSelectionGroup() != null)
4125 && (viewport.getSelectionGroup().getSize() > 1))
4127 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4128 // some common interface!
4130 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4131 * SequenceI[sz = seqs.getSize(false)];
4133 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4134 * seqs.getSequenceAt(i); }
4136 msa = viewport.getAlignmentView(true);
4138 else if (viewport.getSelectionGroup() != null
4139 && viewport.getSelectionGroup().getSize() == 1)
4141 int option = JvOptionPane.showConfirmDialog(this,
4142 MessageManager.getString("warn.oneseq_msainput_selection"),
4143 MessageManager.getString("label.invalid_selection"),
4144 JvOptionPane.OK_CANCEL_OPTION);
4145 if (option == JvOptionPane.OK_OPTION)
4147 msa = viewport.getAlignmentView(false);
4152 msa = viewport.getAlignmentView(false);
4158 * Decides what is submitted to a secondary structure prediction service: the
4159 * first sequence in the alignment, or in the current selection, or, if the
4160 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4161 * region or the whole alignment. (where the first sequence in the set is the
4162 * one that the prediction will be for).
4164 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4166 AlignmentView seqs = null;
4168 if ((viewport.getSelectionGroup() != null)
4169 && (viewport.getSelectionGroup().getSize() > 0))
4171 seqs = viewport.getAlignmentView(true);
4175 seqs = viewport.getAlignmentView(false);
4177 // limit sequences - JBPNote in future - could spawn multiple prediction
4179 // TODO: viewport.getAlignment().isAligned is a global state - the local
4180 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4181 if (!viewport.getAlignment().isAligned(false))
4183 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4184 // TODO: if seqs.getSequences().length>1 then should really have warned
4198 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4200 // Pick the tree file
4201 JalviewFileChooser chooser = new JalviewFileChooser(
4202 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4203 chooser.setFileView(new JalviewFileView());
4204 chooser.setDialogTitle(
4205 MessageManager.getString("label.select_newick_like_tree_file"));
4206 chooser.setToolTipText(
4207 MessageManager.getString("label.load_tree_file"));
4209 int value = chooser.showOpenDialog(null);
4211 if (value == JalviewFileChooser.APPROVE_OPTION)
4213 String filePath = chooser.getSelectedFile().getPath();
4214 Cache.setProperty("LAST_DIRECTORY", filePath);
4215 NewickFile fin = null;
4218 fin = new NewickFile(filePath, DataSourceType.FILE);
4219 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4220 } catch (Exception ex)
4222 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4223 MessageManager.getString("label.problem_reading_tree_file"),
4224 JvOptionPane.WARNING_MESSAGE);
4225 ex.printStackTrace();
4227 if (fin != null && fin.hasWarningMessage())
4229 JvOptionPane.showMessageDialog(Desktop.desktop,
4230 fin.getWarningMessage(),
4232 .getString("label.possible_problem_with_tree_file"),
4233 JvOptionPane.WARNING_MESSAGE);
4238 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4240 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4243 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4244 int h, int x, int y)
4246 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4250 * Add a treeviewer for the tree extracted from a Newick file object to the
4251 * current alignment view
4258 * Associated alignment input data (or null)
4267 * @return TreePanel handle
4269 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4270 AlignmentView input, int w, int h, int x, int y)
4272 TreePanel tp = null;
4278 if (nf.getTree() != null)
4280 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4286 tp.setLocation(x, y);
4289 Desktop.addInternalFrame(tp, treeTitle, w, h);
4291 } catch (Exception ex)
4293 ex.printStackTrace();
4299 private boolean buildingMenu = false;
4302 * Generates menu items and listener event actions for web service clients
4305 public void BuildWebServiceMenu()
4307 while (buildingMenu)
4311 System.err.println("Waiting for building menu to finish.");
4313 } catch (Exception e)
4317 final AlignFrame me = this;
4318 buildingMenu = true;
4319 new Thread(new Runnable()
4324 final List<JMenuItem> legacyItems = new ArrayList<>();
4327 // System.err.println("Building ws menu again "
4328 // + Thread.currentThread());
4329 // TODO: add support for context dependent disabling of services based
4331 // alignment and current selection
4332 // TODO: add additional serviceHandle parameter to specify abstract
4334 // class independently of AbstractName
4335 // TODO: add in rediscovery GUI function to restart discoverer
4336 // TODO: group services by location as well as function and/or
4338 // object broker mechanism.
4339 final Vector<JMenu> wsmenu = new Vector<>();
4340 final IProgressIndicator af = me;
4343 * do not i18n these strings - they are hard-coded in class
4344 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4345 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4347 final JMenu msawsmenu = new JMenu("Alignment");
4348 final JMenu secstrmenu = new JMenu(
4349 "Secondary Structure Prediction");
4350 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4351 final JMenu analymenu = new JMenu("Analysis");
4352 final JMenu dismenu = new JMenu("Protein Disorder");
4353 // JAL-940 - only show secondary structure prediction services from
4354 // the legacy server
4355 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4357 Discoverer.services != null && (Discoverer.services.size() > 0))
4359 // TODO: refactor to allow list of AbstractName/Handler bindings to
4361 // stored or retrieved from elsewhere
4362 // No MSAWS used any more:
4363 // Vector msaws = null; // (Vector)
4364 // Discoverer.services.get("MsaWS");
4365 Vector secstrpr = (Vector) Discoverer.services
4367 if (secstrpr != null)
4369 // Add any secondary structure prediction services
4370 for (int i = 0, j = secstrpr.size(); i < j; i++)
4372 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4374 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4375 .getServiceClient(sh);
4376 int p = secstrmenu.getItemCount();
4377 impl.attachWSMenuEntry(secstrmenu, me);
4378 int q = secstrmenu.getItemCount();
4379 for (int litm = p; litm < q; litm++)
4381 legacyItems.add(secstrmenu.getItem(litm));
4387 // Add all submenus in the order they should appear on the web
4389 wsmenu.add(msawsmenu);
4390 wsmenu.add(secstrmenu);
4391 wsmenu.add(dismenu);
4392 wsmenu.add(analymenu);
4393 // No search services yet
4394 // wsmenu.add(seqsrchmenu);
4396 javax.swing.SwingUtilities.invokeLater(new Runnable()
4403 webService.removeAll();
4404 // first, add discovered services onto the webservices menu
4405 if (wsmenu.size() > 0)
4407 for (int i = 0, j = wsmenu.size(); i < j; i++)
4409 webService.add(wsmenu.get(i));
4414 webService.add(me.webServiceNoServices);
4416 // TODO: move into separate menu builder class.
4417 boolean new_sspred = false;
4419 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4421 WSDiscovererI jws2servs = Jws2Discoverer.getDiscoverer();
4422 if (jws2servs != null)
4424 if (jws2servs.hasServices())
4426 jws2servs.attachWSMenuEntry(webService, me);
4427 for (ServiceWithParameters sv : jws2servs.getServices())
4429 if (sv.getName().toLowerCase().contains("jpred"))
4431 for (JMenuItem jmi : legacyItems)
4433 jmi.setVisible(false);
4439 if (jws2servs.isRunning())
4441 JMenuItem tm = new JMenuItem(
4442 "Still discovering JABA Services");
4443 tm.setEnabled(false);
4449 if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
4451 WSDiscovererI discoverer = SlivkaWSDiscoverer
4453 if (discoverer != null)
4455 if (discoverer.hasServices())
4457 discoverer.attachWSMenuEntry(webService, me);
4459 if (discoverer.isRunning())
4461 JMenuItem tm = new JMenuItem(
4462 "Still discovering Slivka Services");
4463 tm.setEnabled(false);
4469 build_urlServiceMenu(me.webService);
4470 build_fetchdbmenu(webService);
4471 for (JMenu item : wsmenu)
4473 if (item.getItemCount() == 0)
4475 item.setEnabled(false);
4479 item.setEnabled(true);
4482 } catch (Exception e)
4485 "Exception during web service menu building process.",
4490 } catch (Exception e)
4493 buildingMenu = false;
4500 * construct any groupURL type service menu entries.
4504 private void build_urlServiceMenu(JMenu webService)
4506 // TODO: remove this code when 2.7 is released
4507 // DEBUG - alignmentView
4509 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4510 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4512 * @Override public void actionPerformed(ActionEvent e) {
4513 * jalview.datamodel.AlignmentView
4514 * .testSelectionViews(af.viewport.getAlignment(),
4515 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4517 * }); webService.add(testAlView);
4519 // TODO: refactor to RestClient discoverer and merge menu entries for
4520 // rest-style services with other types of analysis/calculation service
4521 // SHmmr test client - still being implemented.
4522 // DEBUG - alignmentView
4524 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4527 client.attachWSMenuEntry(
4528 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4534 * Searches the alignment sequences for xRefs and builds the Show
4535 * Cross-References menu (formerly called Show Products), with database
4536 * sources for which cross-references are found (protein sources for a
4537 * nucleotide alignment and vice versa)
4539 * @return true if Show Cross-references menu should be enabled
4541 public boolean canShowProducts()
4543 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4544 AlignmentI dataset = viewport.getAlignment().getDataset();
4546 showProducts.removeAll();
4547 final boolean dna = viewport.getAlignment().isNucleotide();
4549 if (seqs == null || seqs.length == 0)
4551 // nothing to see here.
4555 boolean showp = false;
4558 List<String> ptypes = new CrossRef(seqs, dataset)
4559 .findXrefSourcesForSequences(dna);
4561 for (final String source : ptypes)
4564 final AlignFrame af = this;
4565 JMenuItem xtype = new JMenuItem(source);
4566 xtype.addActionListener(new ActionListener()
4569 public void actionPerformed(ActionEvent e)
4571 showProductsFor(af.viewport.getSequenceSelection(), dna,
4575 showProducts.add(xtype);
4577 showProducts.setVisible(showp);
4578 showProducts.setEnabled(showp);
4579 } catch (Exception e)
4582 "canShowProducts threw an exception - please report to help@jalview.org",
4590 * Finds and displays cross-references for the selected sequences (protein
4591 * products for nucleotide sequences, dna coding sequences for peptides).
4594 * the sequences to show cross-references for
4596 * true if from a nucleotide alignment (so showing proteins)
4598 * the database to show cross-references for
4600 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4601 final String source)
4603 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4608 * Construct and display a new frame containing the translation of this
4609 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4612 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4614 AlignmentI al = null;
4617 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4619 al = dna.translateCdna(codeTable);
4620 } catch (Exception ex)
4622 jalview.bin.Cache.log.error(
4623 "Exception during translation. Please report this !", ex);
4624 final String msg = MessageManager.getString(
4625 "label.error_when_translating_sequences_submit_bug_report");
4626 final String errorTitle = MessageManager
4627 .getString("label.implementation_error")
4628 + MessageManager.getString("label.translation_failed");
4629 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4630 JvOptionPane.ERROR_MESSAGE);
4633 if (al == null || al.getHeight() == 0)
4635 final String msg = MessageManager.getString(
4636 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4637 final String errorTitle = MessageManager
4638 .getString("label.translation_failed");
4639 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4640 JvOptionPane.WARNING_MESSAGE);
4644 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4645 af.setFileFormat(this.currentFileFormat);
4646 final String newTitle = MessageManager
4647 .formatMessage("label.translation_of_params", new Object[]
4648 { this.getTitle(), codeTable.getId() });
4649 af.setTitle(newTitle);
4650 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4652 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4653 viewport.openSplitFrame(af, new Alignment(seqs));
4657 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4664 * Set the file format
4668 public void setFileFormat(FileFormatI format)
4670 this.currentFileFormat = format;
4674 * Try to load a features file onto the alignment.
4677 * contents or path to retrieve file
4679 * access mode of file (see jalview.io.AlignFile)
4680 * @return true if features file was parsed correctly.
4682 public boolean parseFeaturesFile(String file, DataSourceType sourceType)
4684 return avc.parseFeaturesFile(file, sourceType,
4685 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4690 public void refreshFeatureUI(boolean enableIfNecessary)
4692 // note - currently this is only still here rather than in the controller
4693 // because of the featureSettings hard reference that is yet to be
4695 if (enableIfNecessary)
4697 viewport.setShowSequenceFeatures(true);
4698 showSeqFeatures.setSelected(true);
4704 public void dragEnter(DropTargetDragEvent evt)
4709 public void dragExit(DropTargetEvent evt)
4714 public void dragOver(DropTargetDragEvent evt)
4719 public void dropActionChanged(DropTargetDragEvent evt)
4724 public void drop(DropTargetDropEvent evt)
4726 // JAL-1552 - acceptDrop required before getTransferable call for
4727 // Java's Transferable for native dnd
4728 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4729 Transferable t = evt.getTransferable();
4730 final AlignFrame thisaf = this;
4731 final List<String> files = new ArrayList<>();
4732 List<DataSourceType> protocols = new ArrayList<>();
4736 Desktop.transferFromDropTarget(files, protocols, evt, t);
4737 } catch (Exception e)
4739 e.printStackTrace();
4743 new Thread(new Runnable()
4750 // check to see if any of these files have names matching sequences
4753 SequenceIdMatcher idm = new SequenceIdMatcher(
4754 viewport.getAlignment().getSequencesArray());
4756 * Object[] { String,SequenceI}
4758 ArrayList<Object[]> filesmatched = new ArrayList<>();
4759 ArrayList<String> filesnotmatched = new ArrayList<>();
4760 for (int i = 0; i < files.size(); i++)
4762 String file = files.get(i).toString();
4764 DataSourceType protocol = FormatAdapter.checkProtocol(file);
4765 if (protocol == DataSourceType.FILE)
4767 File fl = new File(file);
4768 pdbfn = fl.getName();
4770 else if (protocol == DataSourceType.URL)
4772 URL url = new URL(file);
4773 pdbfn = url.getFile();
4775 if (pdbfn.length() > 0)
4777 // attempt to find a match in the alignment
4778 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4779 int l = 0, c = pdbfn.indexOf(".");
4780 while (mtch == null && c != -1)
4785 } while ((c = pdbfn.indexOf(".", l)) > l);
4788 pdbfn = pdbfn.substring(0, l);
4790 mtch = idm.findAllIdMatches(pdbfn);
4794 FileFormatI type = null;
4797 type = new IdentifyFile().identify(file, protocol);
4798 } catch (Exception ex)
4802 if (type != null && type.isStructureFile())
4804 filesmatched.add(new Object[] { file, protocol, mtch });
4808 // File wasn't named like one of the sequences or wasn't a PDB
4810 filesnotmatched.add(file);
4814 if (filesmatched.size() > 0)
4816 boolean autoAssociate = Cache
4817 .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
4820 String msg = MessageManager.formatMessage(
4821 "label.automatically_associate_structure_files_with_sequences_same_name",
4823 { Integer.valueOf(filesmatched.size())
4825 String ttl = MessageManager.getString(
4826 "label.automatically_associate_structure_files_by_name");
4827 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4828 ttl, JvOptionPane.YES_NO_OPTION);
4829 autoAssociate = choice == JvOptionPane.YES_OPTION;
4833 for (Object[] fm : filesmatched)
4835 // try and associate
4836 // TODO: may want to set a standard ID naming formalism for
4837 // associating PDB files which have no IDs.
4838 for (SequenceI toassoc : (SequenceI[]) fm[2])
4840 PDBEntry pe = new AssociatePdbFileWithSeq()
4841 .associatePdbWithSeq((String) fm[0],
4842 (DataSourceType) fm[1], toassoc, false,
4846 System.err.println("Associated file : "
4847 + ((String) fm[0]) + " with "
4848 + toassoc.getDisplayId(true));
4852 // TODO: do we need to update overview ? only if features are
4854 alignPanel.paintAlignment(true, false);
4860 * add declined structures as sequences
4862 for (Object[] o : filesmatched)
4864 filesnotmatched.add((String) o[0]);
4868 if (filesnotmatched.size() > 0)
4870 if (assocfiles > 0 && (Cache.getDefault(
4871 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4872 || JvOptionPane.showConfirmDialog(thisaf,
4873 "<html>" + MessageManager.formatMessage(
4874 "label.ignore_unmatched_dropped_files_info",
4877 filesnotmatched.size())
4880 MessageManager.getString(
4881 "label.ignore_unmatched_dropped_files"),
4882 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4886 for (String fn : filesnotmatched)
4888 loadJalviewDataFile(fn, null, null, null);
4892 } catch (Exception ex)
4894 ex.printStackTrace();
4902 * Attempt to load a "dropped" file or URL string, by testing in turn for
4904 * <li>an Annotation file</li>
4905 * <li>a JNet file</li>
4906 * <li>a features file</li>
4907 * <li>else try to interpret as an alignment file</li>
4911 * either a filename or a URL string.
4912 * @throws InterruptedException
4913 * @throws IOException
4915 public void loadJalviewDataFile(String file, DataSourceType sourceType,
4916 FileFormatI format, SequenceI assocSeq)
4920 if (sourceType == null)
4922 sourceType = FormatAdapter.checkProtocol(file);
4924 // if the file isn't identified, or not positively identified as some
4925 // other filetype (PFAM is default unidentified alignment file type) then
4926 // try to parse as annotation.
4927 boolean isAnnotation = (format == null
4928 || FileFormat.Pfam.equals(format))
4929 ? new AnnotationFile().annotateAlignmentView(viewport,
4935 // first see if its a T-COFFEE score file
4936 TCoffeeScoreFile tcf = null;
4939 tcf = new TCoffeeScoreFile(file, sourceType);
4942 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4946 new TCoffeeColourScheme(viewport.getAlignment()));
4947 isAnnotation = true;
4948 statusBar.setText(MessageManager.getString(
4949 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4953 // some problem - if no warning its probable that the ID matching
4954 // process didn't work
4955 JvOptionPane.showMessageDialog(Desktop.desktop,
4956 tcf.getWarningMessage() == null
4957 ? MessageManager.getString(
4958 "label.check_file_matches_sequence_ids_alignment")
4959 : tcf.getWarningMessage(),
4960 MessageManager.getString(
4961 "label.problem_reading_tcoffee_score_file"),
4962 JvOptionPane.WARNING_MESSAGE);
4969 } catch (Exception x)
4972 "Exception when processing data source as T-COFFEE score file",
4978 // try to see if its a JNet 'concise' style annotation file *before*
4980 // try to parse it as a features file
4983 format = new IdentifyFile().identify(file, sourceType);
4985 if (FileFormat.ScoreMatrix == format)
4987 ScoreMatrixFile sm = new ScoreMatrixFile(
4988 new FileParse(file, sourceType));
4990 // todo: i18n this message
4991 statusBar.setText(MessageManager.formatMessage(
4992 "label.successfully_loaded_matrix",
4993 sm.getMatrixName()));
4995 else if (FileFormat.Jnet.equals(format))
4997 JPredFile predictions = new JPredFile(file, sourceType);
4998 new JnetAnnotationMaker();
4999 JnetAnnotationMaker.add_annotation(predictions,
5000 viewport.getAlignment(), 0, false);
5001 viewport.getAlignment().setupJPredAlignment();
5002 isAnnotation = true;
5004 // else if (IdentifyFile.FeaturesFile.equals(format))
5005 else if (FileFormat.Features.equals(format))
5007 if (parseFeaturesFile(file, sourceType))
5009 alignPanel.paintAlignment(true, true);
5014 new FileLoader().LoadFile(viewport, file, sourceType, format);
5020 alignPanel.adjustAnnotationHeight();
5021 viewport.updateSequenceIdColours();
5022 buildSortByAnnotationScoresMenu();
5023 alignPanel.paintAlignment(true, true);
5025 } catch (Exception ex)
5027 ex.printStackTrace();
5028 } catch (OutOfMemoryError oom)
5033 } catch (Exception x)
5038 + (sourceType != null
5039 ? (sourceType == DataSourceType.PASTE
5041 : "using " + sourceType + " from "
5045 ? "(parsing as '" + format + "' file)"
5047 oom, Desktop.desktop);
5052 * Method invoked by the ChangeListener on the tabbed pane, in other words
5053 * when a different tabbed pane is selected by the user or programmatically.
5056 public void tabSelectionChanged(int index)
5060 alignPanel = alignPanels.get(index);
5061 viewport = alignPanel.av;
5062 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5063 setMenusFromViewport(viewport);
5067 * 'focus' any colour slider that is open to the selected viewport
5069 if (viewport.getConservationSelected())
5071 SliderPanel.setConservationSlider(alignPanel,
5072 viewport.getResidueShading(), alignPanel.getViewName());
5076 SliderPanel.hideConservationSlider();
5078 if (viewport.getAbovePIDThreshold())
5080 SliderPanel.setPIDSliderSource(alignPanel,
5081 viewport.getResidueShading(), alignPanel.getViewName());
5085 SliderPanel.hidePIDSlider();
5089 * If there is a frame linked to this one in a SplitPane, switch it to the
5090 * same view tab index. No infinite recursion of calls should happen, since
5091 * tabSelectionChanged() should not get invoked on setting the selected
5092 * index to an unchanged value. Guard against setting an invalid index
5093 * before the new view peer tab has been created.
5095 final AlignViewportI peer = viewport.getCodingComplement();
5098 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5099 .getAlignPanel().alignFrame;
5100 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5102 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5108 * On right mouse click on view tab, prompt for and set new view name.
5111 public void tabbedPane_mousePressed(MouseEvent e)
5113 if (e.isPopupTrigger())
5115 String msg = MessageManager.getString("label.enter_view_name");
5116 String reply = JvOptionPane.showInternalInputDialog(this, msg, msg,
5117 JvOptionPane.QUESTION_MESSAGE);
5121 viewport.setViewName(reply);
5122 // TODO warn if reply is in getExistingViewNames()?
5123 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5128 public AlignViewport getCurrentView()
5134 * Open the dialog for regex description parsing.
5137 protected void extractScores_actionPerformed(ActionEvent e)
5139 ParseProperties pp = new jalview.analysis.ParseProperties(
5140 viewport.getAlignment());
5141 // TODO: verify regex and introduce GUI dialog for version 2.5
5142 // if (pp.getScoresFromDescription("col", "score column ",
5143 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5145 if (pp.getScoresFromDescription("description column",
5146 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5148 buildSortByAnnotationScoresMenu();
5156 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5160 protected void showDbRefs_actionPerformed(ActionEvent e)
5162 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5168 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5172 protected void showNpFeats_actionPerformed(ActionEvent e)
5174 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5178 * find the viewport amongst the tabs in this alignment frame and close that
5183 public boolean closeView(AlignViewportI av)
5187 this.closeMenuItem_actionPerformed(false);
5190 Component[] comp = tabbedPane.getComponents();
5191 for (int i = 0; comp != null && i < comp.length; i++)
5193 if (comp[i] instanceof AlignmentPanel)
5195 if (((AlignmentPanel) comp[i]).av == av)
5198 closeView((AlignmentPanel) comp[i]);
5206 protected void build_fetchdbmenu(JMenu webService)
5208 // Temporary hack - DBRef Fetcher always top level ws entry.
5209 // TODO We probably want to store a sequence database checklist in
5210 // preferences and have checkboxes.. rather than individual sources selected
5212 final JMenu rfetch = new JMenu(
5213 MessageManager.getString("action.fetch_db_references"));
5214 rfetch.setToolTipText(MessageManager.getString(
5215 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5216 webService.add(rfetch);
5218 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5219 MessageManager.getString("option.trim_retrieved_seqs"));
5220 trimrs.setToolTipText(
5221 MessageManager.getString("label.trim_retrieved_sequences"));
5223 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5224 trimrs.addActionListener(new ActionListener()
5227 public void actionPerformed(ActionEvent e)
5229 trimrs.setSelected(trimrs.isSelected());
5230 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5231 Boolean.valueOf(trimrs.isSelected()).toString());
5235 JMenuItem fetchr = new JMenuItem(
5236 MessageManager.getString("label.standard_databases"));
5237 fetchr.setToolTipText(
5238 MessageManager.getString("label.fetch_embl_uniprot"));
5239 fetchr.addActionListener(new ActionListener()
5243 public void actionPerformed(ActionEvent e)
5245 new Thread(new Runnable()
5250 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5251 .getAlignment().isNucleotide();
5252 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5253 alignPanel.av.getSequenceSelection(),
5254 alignPanel.alignFrame, null,
5255 alignPanel.alignFrame.featureSettings, isNucleotide);
5256 dbRefFetcher.addListener(new FetchFinishedListenerI()
5259 public void finished()
5262 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5263 .getFeatureSettingsModels())
5266 alignPanel.av.mergeFeaturesStyle(srcSettings);
5268 AlignFrame.this.setMenusForViewport();
5271 dbRefFetcher.fetchDBRefs(false);
5279 final AlignFrame me = this;
5280 new Thread(new Runnable()
5285 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5286 .getSequenceFetcherSingleton(me);
5287 javax.swing.SwingUtilities.invokeLater(new Runnable()
5292 String[] dbclasses = sf.getOrderedSupportedSources();
5293 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5294 // jalview.util.QuickSort.sort(otherdb, otherdb);
5295 List<DbSourceProxy> otherdb;
5296 JMenu dfetch = new JMenu();
5297 JMenu ifetch = new JMenu();
5298 JMenuItem fetchr = null;
5299 int comp = 0, icomp = 0, mcomp = 15;
5300 String mname = null;
5302 for (String dbclass : dbclasses)
5304 otherdb = sf.getSourceProxy(dbclass);
5305 // add a single entry for this class, or submenu allowing 'fetch
5307 if (otherdb == null || otherdb.size() < 1)
5311 // List<DbSourceProxy> dbs=otherdb;
5312 // otherdb=new ArrayList<DbSourceProxy>();
5313 // for (DbSourceProxy db:dbs)
5315 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5319 mname = "From " + dbclass;
5321 if (otherdb.size() == 1)
5323 final DbSourceProxy[] dassource = otherdb
5324 .toArray(new DbSourceProxy[0]);
5325 DbSourceProxy src = otherdb.get(0);
5326 fetchr = new JMenuItem(src.getDbSource());
5327 fetchr.addActionListener(new ActionListener()
5331 public void actionPerformed(ActionEvent e)
5333 new Thread(new Runnable()
5339 boolean isNucleotide = alignPanel.alignFrame
5340 .getViewport().getAlignment()
5342 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5343 alignPanel.av.getSequenceSelection(),
5344 alignPanel.alignFrame, dassource,
5345 alignPanel.alignFrame.featureSettings,
5348 .addListener(new FetchFinishedListenerI()
5351 public void finished()
5353 FeatureSettingsModelI srcSettings = dassource[0]
5354 .getFeatureColourScheme();
5355 alignPanel.av.mergeFeaturesStyle(
5357 AlignFrame.this.setMenusForViewport();
5360 dbRefFetcher.fetchDBRefs(false);
5366 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5367 MessageManager.formatMessage(
5368 "label.fetch_retrieve_from", new Object[]
5369 { src.getDbName() })));
5375 final DbSourceProxy[] dassource = otherdb
5376 .toArray(new DbSourceProxy[0]);
5378 DbSourceProxy src = otherdb.get(0);
5379 fetchr = new JMenuItem(MessageManager
5380 .formatMessage("label.fetch_all_param", new Object[]
5381 { src.getDbSource() }));
5382 fetchr.addActionListener(new ActionListener()
5385 public void actionPerformed(ActionEvent e)
5387 new Thread(new Runnable()
5393 boolean isNucleotide = alignPanel.alignFrame
5394 .getViewport().getAlignment()
5396 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5397 alignPanel.av.getSequenceSelection(),
5398 alignPanel.alignFrame, dassource,
5399 alignPanel.alignFrame.featureSettings,
5402 .addListener(new FetchFinishedListenerI()
5405 public void finished()
5407 AlignFrame.this.setMenusForViewport();
5410 dbRefFetcher.fetchDBRefs(false);
5416 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5417 MessageManager.formatMessage(
5418 "label.fetch_retrieve_from_all_sources",
5420 { Integer.valueOf(otherdb.size())
5422 src.getDbSource(), src.getDbName() })));
5425 // and then build the rest of the individual menus
5426 ifetch = new JMenu(MessageManager.formatMessage(
5427 "label.source_from_db_source", new Object[]
5428 { src.getDbSource() }));
5430 String imname = null;
5432 for (DbSourceProxy sproxy : otherdb)
5434 String dbname = sproxy.getDbName();
5435 String sname = dbname.length() > 5
5436 ? dbname.substring(0, 5) + "..."
5438 String msname = dbname.length() > 10
5439 ? dbname.substring(0, 10) + "..."
5443 imname = MessageManager
5444 .formatMessage("label.from_msname", new Object[]
5447 fetchr = new JMenuItem(msname);
5448 final DbSourceProxy[] dassrc = { sproxy };
5449 fetchr.addActionListener(new ActionListener()
5453 public void actionPerformed(ActionEvent e)
5455 new Thread(new Runnable()
5461 boolean isNucleotide = alignPanel.alignFrame
5462 .getViewport().getAlignment()
5464 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5465 alignPanel.av.getSequenceSelection(),
5466 alignPanel.alignFrame, dassrc,
5467 alignPanel.alignFrame.featureSettings,
5470 .addListener(new FetchFinishedListenerI()
5473 public void finished()
5475 AlignFrame.this.setMenusForViewport();
5478 dbRefFetcher.fetchDBRefs(false);
5484 fetchr.setToolTipText(
5485 "<html>" + MessageManager.formatMessage(
5486 "label.fetch_retrieve_from", new Object[]
5490 if (++icomp >= mcomp || i == (otherdb.size()))
5492 ifetch.setText(MessageManager.formatMessage(
5493 "label.source_to_target", imname, sname));
5495 ifetch = new JMenu();
5503 if (comp >= mcomp || dbi >= (dbclasses.length))
5505 dfetch.setText(MessageManager.formatMessage(
5506 "label.source_to_target", mname, dbclass));
5508 dfetch = new JMenu();
5521 * Left justify the whole alignment.
5524 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5526 AlignmentI al = viewport.getAlignment();
5528 viewport.firePropertyChange("alignment", null, al);
5532 * Right justify the whole alignment.
5535 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5537 AlignmentI al = viewport.getAlignment();
5539 viewport.firePropertyChange("alignment", null, al);
5543 public void setShowSeqFeatures(boolean b)
5545 showSeqFeatures.setSelected(b);
5546 viewport.setShowSequenceFeatures(b);
5553 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5554 * awt.event.ActionEvent)
5557 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5559 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5560 alignPanel.paintAlignment(false, false);
5567 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5571 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5573 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5574 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5582 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5583 * .event.ActionEvent)
5586 protected void showGroupConservation_actionPerformed(ActionEvent e)
5588 viewport.setShowGroupConservation(showGroupConservation.getState());
5589 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5596 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5597 * .event.ActionEvent)
5600 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5602 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5603 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5610 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5611 * .event.ActionEvent)
5614 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5616 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5617 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5621 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5623 showSequenceLogo.setState(true);
5624 viewport.setShowSequenceLogo(true);
5625 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5626 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5630 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5632 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5639 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5640 * .event.ActionEvent)
5643 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5645 if (avc.makeGroupsFromSelection())
5647 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5648 alignPanel.updateAnnotation();
5649 alignPanel.paintAlignment(true,
5650 viewport.needToUpdateStructureViews());
5654 public void clearAlignmentSeqRep()
5656 // TODO refactor alignmentseqrep to controller
5657 if (viewport.getAlignment().hasSeqrep())
5659 viewport.getAlignment().setSeqrep(null);
5660 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5661 alignPanel.updateAnnotation();
5662 alignPanel.paintAlignment(true, true);
5667 protected void createGroup_actionPerformed(ActionEvent e)
5669 if (avc.createGroup())
5671 if (applyAutoAnnotationSettings.isSelected())
5673 alignPanel.updateAnnotation(true, false);
5675 alignPanel.alignmentChanged();
5680 protected void unGroup_actionPerformed(ActionEvent e)
5684 alignPanel.alignmentChanged();
5689 * make the given alignmentPanel the currently selected tab
5691 * @param alignmentPanel
5693 public void setDisplayedView(AlignmentPanel alignmentPanel)
5695 if (!viewport.getSequenceSetId()
5696 .equals(alignmentPanel.av.getSequenceSetId()))
5698 throw new Error(MessageManager.getString(
5699 "error.implementation_error_cannot_show_view_alignment_frame"));
5701 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5702 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5704 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5709 * Action on selection of menu options to Show or Hide annotations.
5712 * @param forSequences
5713 * update sequence-related annotations
5714 * @param forAlignment
5715 * update non-sequence-related annotations
5718 protected void setAnnotationsVisibility(boolean visible,
5719 boolean forSequences, boolean forAlignment)
5721 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5722 .getAlignmentAnnotation();
5727 for (AlignmentAnnotation aa : anns)
5730 * don't display non-positional annotations on an alignment
5732 if (aa.annotations == null)
5736 boolean apply = (aa.sequenceRef == null && forAlignment)
5737 || (aa.sequenceRef != null && forSequences);
5740 aa.visible = visible;
5743 alignPanel.validateAnnotationDimensions(true);
5744 alignPanel.alignmentChanged();
5748 * Store selected annotation sort order for the view and repaint.
5751 protected void sortAnnotations_actionPerformed()
5753 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5755 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5756 alignPanel.paintAlignment(false, false);
5761 * @return alignment panels in this alignment frame
5763 public List<? extends AlignmentViewPanel> getAlignPanels()
5765 // alignPanels is never null
5766 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5771 * Open a new alignment window, with the cDNA associated with this (protein)
5772 * alignment, aligned as is the protein.
5774 protected void viewAsCdna_actionPerformed()
5776 // TODO no longer a menu action - refactor as required
5777 final AlignmentI alignment = getViewport().getAlignment();
5778 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5779 if (mappings == null)
5783 List<SequenceI> cdnaSeqs = new ArrayList<>();
5784 for (SequenceI aaSeq : alignment.getSequences())
5786 for (AlignedCodonFrame acf : mappings)
5788 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5792 * There is a cDNA mapping for this protein sequence - add to new
5793 * alignment. It will share the same dataset sequence as other mapped
5794 * cDNA (no new mappings need to be created).
5796 final Sequence newSeq = new Sequence(dnaSeq);
5797 newSeq.setDatasetSequence(dnaSeq);
5798 cdnaSeqs.add(newSeq);
5802 if (cdnaSeqs.size() == 0)
5804 // show a warning dialog no mapped cDNA
5807 AlignmentI cdna = new Alignment(
5808 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5809 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5810 AlignFrame.DEFAULT_HEIGHT);
5811 cdna.alignAs(alignment);
5812 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5814 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5815 AlignFrame.DEFAULT_HEIGHT);
5819 * Set visibility of dna/protein complement view (available when shown in a
5825 protected void showComplement_actionPerformed(boolean show)
5827 SplitContainerI sf = getSplitViewContainer();
5830 sf.setComplementVisible(this, show);
5835 * Generate the reverse (optionally complemented) of the selected sequences,
5836 * and add them to the alignment
5839 protected void showReverse_actionPerformed(boolean complement)
5841 AlignmentI al = null;
5844 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5845 al = dna.reverseCdna(complement);
5846 viewport.addAlignment(al, "");
5847 addHistoryItem(new EditCommand(
5848 MessageManager.getString("label.add_sequences"), Action.PASTE,
5849 al.getSequencesArray(), 0, al.getWidth(),
5850 viewport.getAlignment()));
5851 } catch (Exception ex)
5853 System.err.println(ex.getMessage());
5859 * Try to run a script in the Groovy console, having first ensured that this
5860 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5861 * be targeted at this alignment.
5864 protected void runGroovy_actionPerformed()
5866 Jalview.setCurrentAlignFrame(this);
5867 groovy.ui.Console console = Desktop.getGroovyConsole();
5868 if (console != null)
5872 console.runScript();
5873 } catch (Exception ex)
5875 System.err.println((ex.toString()));
5876 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
5877 MessageManager.getString("label.couldnt_run_groovy_script"),
5878 MessageManager.getString("label.groovy_support_failed"),
5879 JvOptionPane.ERROR_MESSAGE);
5884 System.err.println("Can't run Groovy script as console not found");
5889 * Hides columns containing (or not containing) a specified feature, provided
5890 * that would not leave all columns hidden
5892 * @param featureType
5893 * @param columnsContaining
5896 public boolean hideFeatureColumns(String featureType,
5897 boolean columnsContaining)
5899 boolean notForHiding = avc.markColumnsContainingFeatures(
5900 columnsContaining, false, false, featureType);
5903 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5904 false, featureType))
5906 getViewport().hideSelectedColumns();
5914 protected void selectHighlightedColumns_actionPerformed(
5915 ActionEvent actionEvent)
5917 // include key modifier check in case user selects from menu
5918 avc.markHighlightedColumns(
5919 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5920 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5921 | ActionEvent.CTRL_MASK)) != 0);
5925 * Rebuilds the Colour menu, including any user-defined colours which have
5926 * been loaded either on startup or during the session
5928 public void buildColourMenu()
5930 colourMenu.removeAll();
5932 colourMenu.add(applyToAllGroups);
5933 colourMenu.add(textColour);
5934 colourMenu.addSeparator();
5936 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
5937 viewport.getAlignment(), false);
5939 colourMenu.add(annotationColour);
5940 bg.add(annotationColour);
5941 colourMenu.addSeparator();
5942 colourMenu.add(conservationMenuItem);
5943 colourMenu.add(modifyConservation);
5944 colourMenu.add(abovePIDThreshold);
5945 colourMenu.add(modifyPID);
5947 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5948 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5952 * Open a dialog (if not already open) that allows the user to select and
5953 * calculate PCA or Tree analysis
5955 protected void openTreePcaDialog()
5957 if (alignPanel.getCalculationDialog() == null)
5959 new CalculationChooser(AlignFrame.this);
5964 * Sets the status of the HMMER menu
5966 public void updateHMMERStatus()
5968 hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
5972 protected void loadVcf_actionPerformed()
5974 JalviewFileChooser chooser = new JalviewFileChooser(
5975 Cache.getProperty("LAST_DIRECTORY"));
5976 chooser.setFileView(new JalviewFileView());
5977 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5978 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5980 int value = chooser.showOpenDialog(null);
5982 if (value == JalviewFileChooser.APPROVE_OPTION)
5984 String choice = chooser.getSelectedFile().getPath();
5985 Cache.setProperty("LAST_DIRECTORY", choice);
5986 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
5987 new VCFLoader(choice).loadVCF(seqs, this);
5993 class PrintThread extends Thread
5997 public PrintThread(AlignmentPanel ap)
6002 static PageFormat pf;
6007 PrinterJob printJob = PrinterJob.getPrinterJob();
6011 printJob.setPrintable(ap, pf);
6015 printJob.setPrintable(ap);
6018 if (printJob.printDialog())
6023 } catch (Exception PrintException)
6025 PrintException.printStackTrace();