2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.FeatureSettingsModelI;
36 import jalview.api.SplitContainerI;
37 import jalview.api.ViewStyleI;
38 import jalview.api.analysis.ScoreModelI;
39 import jalview.bin.Cache;
40 import jalview.bin.Jalview;
41 import jalview.commands.CommandI;
42 import jalview.commands.EditCommand;
43 import jalview.commands.EditCommand.Action;
44 import jalview.commands.OrderCommand;
45 import jalview.commands.RemoveGapColCommand;
46 import jalview.commands.RemoveGapsCommand;
47 import jalview.commands.SlideSequencesCommand;
48 import jalview.commands.TrimRegionCommand;
49 import jalview.datamodel.AlignedCodonFrame;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentExportData;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.AlignmentOrder;
55 import jalview.datamodel.AlignmentView;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.DBRefSource;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.PDBEntry;
60 import jalview.datamodel.SeqCigar;
61 import jalview.datamodel.Sequence;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
65 import jalview.io.AlignmentProperties;
66 import jalview.io.AnnotationFile;
67 import jalview.io.BioJsHTMLOutput;
68 import jalview.io.FileLoader;
69 import jalview.io.FormatAdapter;
70 import jalview.io.HtmlSvgOutput;
71 import jalview.io.IdentifyFile;
72 import jalview.io.JalviewFileChooser;
73 import jalview.io.JalviewFileView;
74 import jalview.io.JnetAnnotationMaker;
75 import jalview.io.NewickFile;
76 import jalview.io.TCoffeeScoreFile;
77 import jalview.io.gff.SequenceOntologyI;
78 import jalview.jbgui.GAlignFrame;
79 import jalview.schemes.Blosum62ColourScheme;
80 import jalview.schemes.BuriedColourScheme;
81 import jalview.schemes.ClustalxColourScheme;
82 import jalview.schemes.ColourSchemeI;
83 import jalview.schemes.ColourSchemeProperty;
84 import jalview.schemes.HelixColourScheme;
85 import jalview.schemes.HydrophobicColourScheme;
86 import jalview.schemes.NucleotideColourScheme;
87 import jalview.schemes.PIDColourScheme;
88 import jalview.schemes.PurinePyrimidineColourScheme;
89 import jalview.schemes.RNAHelicesColourChooser;
90 import jalview.schemes.ResidueProperties;
91 import jalview.schemes.StrandColourScheme;
92 import jalview.schemes.TCoffeeColourScheme;
93 import jalview.schemes.TaylorColourScheme;
94 import jalview.schemes.TurnColourScheme;
95 import jalview.schemes.UserColourScheme;
96 import jalview.schemes.ZappoColourScheme;
97 import jalview.structure.StructureSelectionManager;
98 import jalview.util.MessageManager;
99 import jalview.viewmodel.AlignmentViewport;
100 import jalview.ws.DBRefFetcher;
101 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
102 import jalview.ws.SequenceFetcher;
103 import jalview.ws.jws1.Discoverer;
104 import jalview.ws.jws2.Jws2Discoverer;
105 import jalview.ws.jws2.jabaws2.Jws2Instance;
106 import jalview.ws.seqfetcher.DbSourceProxy;
108 import java.awt.BorderLayout;
109 import java.awt.Component;
110 import java.awt.Rectangle;
111 import java.awt.Toolkit;
112 import java.awt.datatransfer.Clipboard;
113 import java.awt.datatransfer.DataFlavor;
114 import java.awt.datatransfer.StringSelection;
115 import java.awt.datatransfer.Transferable;
116 import java.awt.dnd.DropTargetDragEvent;
117 import java.awt.dnd.DropTargetDropEvent;
118 import java.awt.dnd.DropTargetEvent;
119 import java.awt.dnd.DropTargetListener;
120 import java.awt.event.ActionEvent;
121 import java.awt.event.ActionListener;
122 import java.awt.event.FocusAdapter;
123 import java.awt.event.FocusEvent;
124 import java.awt.event.ItemEvent;
125 import java.awt.event.ItemListener;
126 import java.awt.event.KeyAdapter;
127 import java.awt.event.KeyEvent;
128 import java.awt.event.MouseAdapter;
129 import java.awt.event.MouseEvent;
130 import java.awt.print.PageFormat;
131 import java.awt.print.PrinterJob;
132 import java.beans.PropertyChangeEvent;
135 import java.util.ArrayList;
136 import java.util.Arrays;
137 import java.util.Deque;
138 import java.util.Enumeration;
139 import java.util.Hashtable;
140 import java.util.List;
141 import java.util.Vector;
143 import javax.swing.JCheckBoxMenuItem;
144 import javax.swing.JEditorPane;
145 import javax.swing.JInternalFrame;
146 import javax.swing.JLayeredPane;
147 import javax.swing.JMenu;
148 import javax.swing.JMenuItem;
149 import javax.swing.JOptionPane;
150 import javax.swing.JRadioButtonMenuItem;
151 import javax.swing.JScrollPane;
152 import javax.swing.SwingUtilities;
158 * @version $Revision$
160 public class AlignFrame extends GAlignFrame implements DropTargetListener,
161 IProgressIndicator, AlignViewControllerGuiI
164 public static final int DEFAULT_WIDTH = 700;
166 public static final int DEFAULT_HEIGHT = 500;
169 * The currently displayed panel (selected tabbed view if more than one)
171 public AlignmentPanel alignPanel;
173 AlignViewport viewport;
175 public AlignViewControllerI avc;
177 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
180 * Last format used to load or save alignments in this window
182 String currentFileFormat = null;
185 * Current filename for this alignment
187 String fileName = null;
190 * Creates a new AlignFrame object with specific width and height.
196 public AlignFrame(AlignmentI al, int width, int height)
198 this(al, null, width, height);
202 * Creates a new AlignFrame object with specific width, height and
208 * @param sequenceSetId
210 public AlignFrame(AlignmentI al, int width, int height,
211 String sequenceSetId)
213 this(al, null, width, height, sequenceSetId);
217 * Creates a new AlignFrame object with specific width, height and
223 * @param sequenceSetId
226 public AlignFrame(AlignmentI al, int width, int height,
227 String sequenceSetId, String viewId)
229 this(al, null, width, height, sequenceSetId, viewId);
233 * new alignment window with hidden columns
237 * @param hiddenColumns
238 * ColumnSelection or null
240 * Width of alignment frame
244 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
245 int width, int height)
247 this(al, hiddenColumns, width, height, null);
251 * Create alignment frame for al with hiddenColumns, a specific width and
252 * height, and specific sequenceId
255 * @param hiddenColumns
258 * @param sequenceSetId
261 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
262 int width, int height, String sequenceSetId)
264 this(al, hiddenColumns, width, height, sequenceSetId, null);
268 * Create alignment frame for al with hiddenColumns, a specific width and
269 * height, and specific sequenceId
272 * @param hiddenColumns
275 * @param sequenceSetId
280 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
281 int width, int height, String sequenceSetId, String viewId)
283 setSize(width, height);
285 if (al.getDataset() == null)
290 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
292 alignPanel = new AlignmentPanel(this, viewport);
294 addAlignmentPanel(alignPanel, true);
298 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
299 ColumnSelection hiddenColumns, int width, int height)
301 setSize(width, height);
303 if (al.getDataset() == null)
308 viewport = new AlignViewport(al, hiddenColumns);
310 if (hiddenSeqs != null && hiddenSeqs.length > 0)
312 viewport.hideSequence(hiddenSeqs);
314 alignPanel = new AlignmentPanel(this, viewport);
315 addAlignmentPanel(alignPanel, true);
320 * Make a new AlignFrame from existing alignmentPanels
327 public AlignFrame(AlignmentPanel ap)
331 addAlignmentPanel(ap, false);
336 * initalise the alignframe from the underlying viewport data and the
341 if (!Jalview.isHeadlessMode())
343 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
346 avc = new jalview.controller.AlignViewController(this, viewport,
348 if (viewport.getAlignmentConservationAnnotation() == null)
350 BLOSUM62Colour.setEnabled(false);
351 conservationMenuItem.setEnabled(false);
352 modifyConservation.setEnabled(false);
353 // PIDColour.setEnabled(false);
354 // abovePIDThreshold.setEnabled(false);
355 // modifyPID.setEnabled(false);
358 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
361 if (sortby.equals("Id"))
363 sortIDMenuItem_actionPerformed(null);
365 else if (sortby.equals("Pairwise Identity"))
367 sortPairwiseMenuItem_actionPerformed(null);
370 if (Desktop.desktop != null)
372 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
373 addServiceListeners();
374 setGUINucleotide(viewport.getAlignment().isNucleotide());
378 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
380 setMenusFromViewport(viewport);
381 buildSortByAnnotationScoresMenu();
384 if (viewport.getWrapAlignment())
386 wrapMenuItem_actionPerformed(null);
389 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
391 this.overviewMenuItem_actionPerformed(null);
396 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
397 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
398 final String menuLabel = MessageManager
399 .getString("label.copy_format_from");
400 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
401 new ViewSetProvider()
405 public AlignmentPanel[] getAllAlignmentPanels()
408 origview.add(alignPanel);
409 // make an array of all alignment panels except for this one
410 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
411 Arrays.asList(Desktop.getAlignmentPanels(null)));
412 aps.remove(AlignFrame.this.alignPanel);
413 return aps.toArray(new AlignmentPanel[aps.size()]);
415 }, selviews, new ItemListener()
419 public void itemStateChanged(ItemEvent e)
421 if (origview.size() > 0)
423 final AlignmentPanel ap = origview.get(0);
426 * Copy the ViewStyle of the selected panel to 'this one'.
427 * Don't change value of 'scaleProteinAsCdna' unless copying
430 ViewStyleI vs = selviews.get(0).getAlignViewport()
432 boolean fromSplitFrame = selviews.get(0)
433 .getAlignViewport().getCodingComplement() != null;
436 vs.setScaleProteinAsCdna(ap.getAlignViewport()
437 .getViewStyle().isScaleProteinAsCdna());
439 ap.getAlignViewport().setViewStyle(vs);
442 * Also rescale ViewStyle of SplitFrame complement if there is
443 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
444 * the whole ViewStyle (allow cDNA protein to have different
447 AlignViewportI complement = ap.getAlignViewport()
448 .getCodingComplement();
449 if (complement != null && vs.isScaleProteinAsCdna())
451 AlignFrame af = Desktop.getAlignFrameFor(complement);
452 ((SplitFrame) af.getSplitViewContainer())
454 af.setMenusForViewport();
458 ap.setSelected(true);
459 ap.alignFrame.setMenusForViewport();
464 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
465 .indexOf("devel") > -1
466 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
467 .indexOf("test") > -1)
469 formatMenu.add(vsel);
471 addFocusListener(new FocusAdapter()
474 public void focusGained(FocusEvent e)
476 Jalview.setCurrentAlignFrame(AlignFrame.this);
483 * Change the filename and format for the alignment, and enable the 'reload'
484 * button functionality.
491 public void setFileName(String file, String format)
494 setFileFormat(format);
495 reload.setEnabled(true);
499 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
502 void addKeyListener()
504 addKeyListener(new KeyAdapter()
507 public void keyPressed(KeyEvent evt)
509 if (viewport.cursorMode
510 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
511 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
512 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
513 && Character.isDigit(evt.getKeyChar()))
515 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
518 switch (evt.getKeyCode())
521 case 27: // escape key
522 deselectAllSequenceMenuItem_actionPerformed(null);
526 case KeyEvent.VK_DOWN:
527 if (evt.isAltDown() || !viewport.cursorMode)
529 moveSelectedSequences(false);
531 if (viewport.cursorMode)
533 alignPanel.getSeqPanel().moveCursor(0, 1);
538 if (evt.isAltDown() || !viewport.cursorMode)
540 moveSelectedSequences(true);
542 if (viewport.cursorMode)
544 alignPanel.getSeqPanel().moveCursor(0, -1);
549 case KeyEvent.VK_LEFT:
550 if (evt.isAltDown() || !viewport.cursorMode)
552 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
556 alignPanel.getSeqPanel().moveCursor(-1, 0);
561 case KeyEvent.VK_RIGHT:
562 if (evt.isAltDown() || !viewport.cursorMode)
564 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
568 alignPanel.getSeqPanel().moveCursor(1, 0);
572 case KeyEvent.VK_SPACE:
573 if (viewport.cursorMode)
575 alignPanel.getSeqPanel().insertGapAtCursor(
576 evt.isControlDown() || evt.isShiftDown()
581 // case KeyEvent.VK_A:
582 // if (viewport.cursorMode)
584 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
585 // //System.out.println("A");
589 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
590 * System.out.println("closing bracket"); } break;
592 case KeyEvent.VK_DELETE:
593 case KeyEvent.VK_BACK_SPACE:
594 if (!viewport.cursorMode)
596 cut_actionPerformed(null);
600 alignPanel.getSeqPanel().deleteGapAtCursor(
601 evt.isControlDown() || evt.isShiftDown()
608 if (viewport.cursorMode)
610 alignPanel.getSeqPanel().setCursorRow();
614 if (viewport.cursorMode && !evt.isControlDown())
616 alignPanel.getSeqPanel().setCursorColumn();
620 if (viewport.cursorMode)
622 alignPanel.getSeqPanel().setCursorPosition();
626 case KeyEvent.VK_ENTER:
627 case KeyEvent.VK_COMMA:
628 if (viewport.cursorMode)
630 alignPanel.getSeqPanel().setCursorRowAndColumn();
635 if (viewport.cursorMode)
637 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
641 if (viewport.cursorMode)
643 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
648 viewport.cursorMode = !viewport.cursorMode;
649 statusBar.setText(MessageManager.formatMessage(
650 "label.keyboard_editing_mode",
651 new String[] { (viewport.cursorMode ? "on" : "off") }));
652 if (viewport.cursorMode)
654 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
655 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
657 alignPanel.getSeqPanel().seqCanvas.repaint();
663 Help.showHelpWindow();
664 } catch (Exception ex)
666 ex.printStackTrace();
671 boolean toggleSeqs = !evt.isControlDown();
672 boolean toggleCols = !evt.isShiftDown();
673 toggleHiddenRegions(toggleSeqs, toggleCols);
676 case KeyEvent.VK_PAGE_UP:
677 if (viewport.getWrapAlignment())
679 alignPanel.scrollUp(true);
683 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
684 - viewport.endSeq + viewport.startSeq);
687 case KeyEvent.VK_PAGE_DOWN:
688 if (viewport.getWrapAlignment())
690 alignPanel.scrollUp(false);
694 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
695 + viewport.endSeq - viewport.startSeq);
702 public void keyReleased(KeyEvent evt)
704 switch (evt.getKeyCode())
706 case KeyEvent.VK_LEFT:
707 if (evt.isAltDown() || !viewport.cursorMode)
709 viewport.firePropertyChange("alignment", null, viewport
710 .getAlignment().getSequences());
714 case KeyEvent.VK_RIGHT:
715 if (evt.isAltDown() || !viewport.cursorMode)
717 viewport.firePropertyChange("alignment", null, viewport
718 .getAlignment().getSequences());
726 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
728 ap.alignFrame = this;
729 avc = new jalview.controller.AlignViewController(this, viewport,
734 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
736 int aSize = alignPanels.size();
738 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
740 if (aSize == 1 && ap.av.viewName == null)
742 this.getContentPane().add(ap, BorderLayout.CENTER);
748 setInitialTabVisible();
751 expandViews.setEnabled(true);
752 gatherViews.setEnabled(true);
753 tabbedPane.addTab(ap.av.viewName, ap);
755 ap.setVisible(false);
760 if (ap.av.isPadGaps())
762 ap.av.getAlignment().padGaps();
764 ap.av.updateConservation(ap);
765 ap.av.updateConsensus(ap);
766 ap.av.updateStrucConsensus(ap);
770 public void setInitialTabVisible()
772 expandViews.setEnabled(true);
773 gatherViews.setEnabled(true);
774 tabbedPane.setVisible(true);
775 AlignmentPanel first = alignPanels.get(0);
776 tabbedPane.addTab(first.av.viewName, first);
777 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
780 public AlignViewport getViewport()
785 /* Set up intrinsic listeners for dynamically generated GUI bits. */
786 private void addServiceListeners()
788 final java.beans.PropertyChangeListener thisListener;
789 Desktop.instance.addJalviewPropertyChangeListener("services",
790 thisListener = new java.beans.PropertyChangeListener()
793 public void propertyChange(PropertyChangeEvent evt)
795 // // System.out.println("Discoverer property change.");
796 // if (evt.getPropertyName().equals("services"))
798 SwingUtilities.invokeLater(new Runnable()
805 .println("Rebuild WS Menu for service change");
806 BuildWebServiceMenu();
813 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
816 public void internalFrameClosed(
817 javax.swing.event.InternalFrameEvent evt)
819 // System.out.println("deregistering discoverer listener");
820 Desktop.instance.removeJalviewPropertyChangeListener("services",
822 closeMenuItem_actionPerformed(true);
825 // Finally, build the menu once to get current service state
826 new Thread(new Runnable()
831 BuildWebServiceMenu();
837 * Configure menu items that vary according to whether the alignment is
838 * nucleotide or protein
842 public void setGUINucleotide(boolean nucleotide)
844 showTranslation.setVisible(nucleotide);
845 showReverse.setVisible(nucleotide);
846 showReverseComplement.setVisible(nucleotide);
847 conservationMenuItem.setEnabled(!nucleotide);
848 modifyConservation.setEnabled(!nucleotide);
849 showGroupConservation.setEnabled(!nucleotide);
850 rnahelicesColour.setEnabled(nucleotide);
851 purinePyrimidineColour.setEnabled(nucleotide);
852 showComplementMenuItem.setText(nucleotide ? MessageManager
853 .getString("label.protein") : MessageManager
854 .getString("label.nucleotide"));
855 setColourSelected(jalview.bin.Cache.getDefault(
856 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
857 : Preferences.DEFAULT_COLOUR_PROT, "None"));
861 * set up menus for the current viewport. This may be called after any
862 * operation that affects the data in the current view (selection changed,
863 * etc) to update the menus to reflect the new state.
866 public void setMenusForViewport()
868 setMenusFromViewport(viewport);
872 * Need to call this method when tabs are selected for multiple views, or when
873 * loading from Jalview2XML.java
878 void setMenusFromViewport(AlignViewport av)
880 padGapsMenuitem.setSelected(av.isPadGaps());
881 colourTextMenuItem.setSelected(av.isShowColourText());
882 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
883 conservationMenuItem.setSelected(av.getConservationSelected());
884 seqLimits.setSelected(av.getShowJVSuffix());
885 idRightAlign.setSelected(av.isRightAlignIds());
886 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
887 renderGapsMenuItem.setSelected(av.isRenderGaps());
888 wrapMenuItem.setSelected(av.getWrapAlignment());
889 scaleAbove.setVisible(av.getWrapAlignment());
890 scaleLeft.setVisible(av.getWrapAlignment());
891 scaleRight.setVisible(av.getWrapAlignment());
892 annotationPanelMenuItem.setState(av.isShowAnnotation());
894 * Show/hide annotations only enabled if annotation panel is shown
896 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
897 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
898 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
899 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
900 viewBoxesMenuItem.setSelected(av.getShowBoxes());
901 viewTextMenuItem.setSelected(av.getShowText());
902 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
903 showGroupConsensus.setSelected(av.isShowGroupConsensus());
904 showGroupConservation.setSelected(av.isShowGroupConservation());
905 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
906 showSequenceLogo.setSelected(av.isShowSequenceLogo());
907 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
909 setColourSelected(ColourSchemeProperty.getColourName(av
910 .getGlobalColourScheme()));
912 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
913 hiddenMarkers.setState(av.getShowHiddenMarkers());
914 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
915 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
916 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
917 autoCalculate.setSelected(av.autoCalculateConsensus);
918 sortByTree.setSelected(av.sortByTree);
919 listenToViewSelections.setSelected(av.followSelection);
920 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
922 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
924 showProducts.setEnabled(canShowProducts());
925 setGroovyEnabled(Desktop.getGroovyConsole() != null);
931 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
935 public void setGroovyEnabled(boolean b)
937 runGroovy.setEnabled(b);
940 private IProgressIndicator progressBar;
945 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
948 public void setProgressBar(String message, long id)
950 progressBar.setProgressBar(message, id);
954 public void registerHandler(final long id,
955 final IProgressIndicatorHandler handler)
957 progressBar.registerHandler(id, handler);
962 * @return true if any progress bars are still active
965 public boolean operationInProgress()
967 return progressBar.operationInProgress();
971 public void setStatus(String text)
973 statusBar.setText(text);
977 * Added so Castor Mapping file can obtain Jalview Version
979 public String getVersion()
981 return jalview.bin.Cache.getProperty("VERSION");
984 public FeatureRenderer getFeatureRenderer()
986 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
990 public void fetchSequence_actionPerformed(ActionEvent e)
992 new jalview.gui.SequenceFetcher(this);
996 public void addFromFile_actionPerformed(ActionEvent e)
998 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1002 public void reload_actionPerformed(ActionEvent e)
1004 if (fileName != null)
1006 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1007 // originating file's format
1008 // TODO: work out how to recover feature settings for correct view(s) when
1009 // file is reloaded.
1010 if (currentFileFormat.equals("Jalview"))
1012 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1013 for (int i = 0; i < frames.length; i++)
1015 if (frames[i] instanceof AlignFrame && frames[i] != this
1016 && ((AlignFrame) frames[i]).fileName != null
1017 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1021 frames[i].setSelected(true);
1022 Desktop.instance.closeAssociatedWindows();
1023 } catch (java.beans.PropertyVetoException ex)
1029 Desktop.instance.closeAssociatedWindows();
1031 FileLoader loader = new FileLoader();
1032 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1033 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1037 Rectangle bounds = this.getBounds();
1039 FileLoader loader = new FileLoader();
1040 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1041 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1042 protocol, currentFileFormat);
1044 newframe.setBounds(bounds);
1045 if (featureSettings != null && featureSettings.isShowing())
1047 final Rectangle fspos = featureSettings.frame.getBounds();
1048 // TODO: need a 'show feature settings' function that takes bounds -
1049 // need to refactor Desktop.addFrame
1050 newframe.featureSettings_actionPerformed(null);
1051 final FeatureSettings nfs = newframe.featureSettings;
1052 SwingUtilities.invokeLater(new Runnable()
1057 nfs.frame.setBounds(fspos);
1060 this.featureSettings.close();
1061 this.featureSettings = null;
1063 this.closeMenuItem_actionPerformed(true);
1069 public void addFromText_actionPerformed(ActionEvent e)
1071 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1076 public void addFromURL_actionPerformed(ActionEvent e)
1078 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1082 public void save_actionPerformed(ActionEvent e)
1084 if (fileName == null
1085 || (currentFileFormat == null || !jalview.io.FormatAdapter
1086 .isValidIOFormat(currentFileFormat, true))
1087 || fileName.startsWith("http"))
1089 saveAs_actionPerformed(null);
1093 saveAlignment(fileName, currentFileFormat);
1104 public void saveAs_actionPerformed(ActionEvent e)
1106 JalviewFileChooser chooser = new JalviewFileChooser(
1107 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1108 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1109 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1110 currentFileFormat, false);
1112 chooser.setFileView(new JalviewFileView());
1113 chooser.setDialogTitle(MessageManager
1114 .getString("label.save_alignment_to_file"));
1115 chooser.setToolTipText(MessageManager.getString("action.save"));
1117 int value = chooser.showSaveDialog(this);
1119 if (value == JalviewFileChooser.APPROVE_OPTION)
1121 currentFileFormat = chooser.getSelectedFormat();
1122 while (currentFileFormat == null)
1125 .showInternalMessageDialog(
1128 .getString("label.select_file_format_before_saving"),
1130 .getString("label.file_format_not_specified"),
1131 JOptionPane.WARNING_MESSAGE);
1132 currentFileFormat = chooser.getSelectedFormat();
1133 value = chooser.showSaveDialog(this);
1134 if (value != JalviewFileChooser.APPROVE_OPTION)
1140 fileName = chooser.getSelectedFile().getPath();
1142 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1145 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1146 if (currentFileFormat.indexOf(" ") > -1)
1148 currentFileFormat = currentFileFormat.substring(0,
1149 currentFileFormat.indexOf(" "));
1151 saveAlignment(fileName, currentFileFormat);
1155 public boolean saveAlignment(String file, String format)
1157 boolean success = true;
1159 if (format.equalsIgnoreCase("Jalview"))
1161 String shortName = title;
1163 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1165 shortName = shortName.substring(shortName
1166 .lastIndexOf(java.io.File.separatorChar) + 1);
1169 success = new Jalview2XML().saveAlignment(this, file, shortName);
1171 statusBar.setText(MessageManager.formatMessage(
1172 "label.successfully_saved_to_file_in_format", new Object[] {
1173 fileName, format }));
1178 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1180 warningMessage("Cannot save file " + fileName + " using format "
1181 + format, "Alignment output format not supported");
1182 if (!Jalview.isHeadlessMode())
1184 saveAs_actionPerformed(null);
1189 AlignmentExportData exportData = getAlignmentForExport(format,
1191 if (exportData.getSettings().isCancelled())
1195 FormatAdapter f = new FormatAdapter(alignPanel,
1196 exportData.getSettings());
1197 String output = f.formatSequences(
1199 exportData.getAlignment(), // class cast exceptions will
1200 // occur in the distant future
1201 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1202 f.getCacheSuffixDefault(format),
1203 viewport.getColumnSelection());
1213 java.io.PrintWriter out = new java.io.PrintWriter(
1214 new java.io.FileWriter(file));
1218 this.setTitle(file);
1219 statusBar.setText(MessageManager.formatMessage(
1220 "label.successfully_saved_to_file_in_format",
1221 new Object[] { fileName, format }));
1222 } catch (Exception ex)
1225 ex.printStackTrace();
1232 JOptionPane.showInternalMessageDialog(this, MessageManager
1233 .formatMessage("label.couldnt_save_file",
1234 new Object[] { fileName }), MessageManager
1235 .getString("label.error_saving_file"),
1236 JOptionPane.WARNING_MESSAGE);
1242 private void warningMessage(String warning, String title)
1244 if (new jalview.util.Platform().isHeadless())
1246 System.err.println("Warning: " + title + "\nWarning: " + warning);
1251 JOptionPane.showInternalMessageDialog(this, warning, title,
1252 JOptionPane.WARNING_MESSAGE);
1264 protected void outputText_actionPerformed(ActionEvent e)
1267 AlignmentExportData exportData = getAlignmentForExport(
1268 e.getActionCommand(), viewport, null);
1269 if (exportData.getSettings().isCancelled())
1273 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1274 cap.setForInput(null);
1277 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1278 .formatSequences(e.getActionCommand(),
1279 exportData.getAlignment(),
1280 exportData.getOmitHidden(),
1281 exportData.getStartEndPostions(),
1282 viewport.getColumnSelection()));
1283 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1284 "label.alignment_output_command",
1285 new Object[] { e.getActionCommand() }), 600, 500);
1286 } catch (OutOfMemoryError oom)
1288 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1294 public static AlignmentExportData getAlignmentForExport(
1295 String exportFormat, AlignViewportI viewport,
1296 AlignExportSettingI exportSettings)
1298 AlignmentI alignmentToExport = null;
1299 AlignExportSettingI settings = exportSettings;
1300 String[] omitHidden = null;
1302 HiddenSequences hiddenSeqs = viewport.getAlignment()
1303 .getHiddenSequences();
1305 alignmentToExport = viewport.getAlignment();
1307 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1308 if (settings == null)
1310 settings = new AlignExportSettings(hasHiddenSeqs,
1311 viewport.hasHiddenColumns(), exportFormat);
1313 // settings.isExportAnnotations();
1315 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1317 omitHidden = viewport.getViewAsString(false,
1318 settings.isExportHiddenSequences());
1321 int[] alignmentStartEnd = new int[2];
1322 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1324 alignmentToExport = hiddenSeqs.getFullAlignment();
1328 alignmentToExport = viewport.getAlignment();
1330 alignmentStartEnd = alignmentToExport
1331 .getVisibleStartAndEndIndex(viewport.getColumnSelection()
1332 .getHiddenColumns());
1333 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1334 omitHidden, alignmentStartEnd, settings);
1345 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1347 new HtmlSvgOutput(null, alignPanel);
1351 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1353 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
1354 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1357 public void createImageMap(File file, String image)
1359 alignPanel.makePNGImageMap(file, image);
1369 public void createPNG(File f)
1371 alignPanel.makePNG(f);
1381 public void createEPS(File f)
1383 alignPanel.makeEPS(f);
1387 public void createSVG(File f)
1389 alignPanel.makeSVG(f);
1393 public void pageSetup_actionPerformed(ActionEvent e)
1395 PrinterJob printJob = PrinterJob.getPrinterJob();
1396 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1406 public void printMenuItem_actionPerformed(ActionEvent e)
1408 // Putting in a thread avoids Swing painting problems
1409 PrintThread thread = new PrintThread(alignPanel);
1414 public void exportFeatures_actionPerformed(ActionEvent e)
1416 new AnnotationExporter().exportFeatures(alignPanel);
1420 public void exportAnnotations_actionPerformed(ActionEvent e)
1422 new AnnotationExporter().exportAnnotations(alignPanel);
1426 public void associatedData_actionPerformed(ActionEvent e)
1428 // Pick the tree file
1429 JalviewFileChooser chooser = new JalviewFileChooser(
1430 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1431 chooser.setFileView(new JalviewFileView());
1432 chooser.setDialogTitle(MessageManager
1433 .getString("label.load_jalview_annotations"));
1434 chooser.setToolTipText(MessageManager
1435 .getString("label.load_jalview_annotations"));
1437 int value = chooser.showOpenDialog(null);
1439 if (value == JalviewFileChooser.APPROVE_OPTION)
1441 String choice = chooser.getSelectedFile().getPath();
1442 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1443 loadJalviewDataFile(choice, null, null, null);
1449 * Close the current view or all views in the alignment frame. If the frame
1450 * only contains one view then the alignment will be removed from memory.
1452 * @param closeAllTabs
1455 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1457 if (alignPanels != null && alignPanels.size() < 2)
1459 closeAllTabs = true;
1464 if (alignPanels != null)
1468 if (this.isClosed())
1470 // really close all the windows - otherwise wait till
1471 // setClosed(true) is called
1472 for (int i = 0; i < alignPanels.size(); i++)
1474 AlignmentPanel ap = alignPanels.get(i);
1481 closeView(alignPanel);
1488 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1489 * be called recursively, with the frame now in 'closed' state
1491 this.setClosed(true);
1493 } catch (Exception ex)
1495 ex.printStackTrace();
1500 * Close the specified panel and close up tabs appropriately.
1502 * @param panelToClose
1504 public void closeView(AlignmentPanel panelToClose)
1506 int index = tabbedPane.getSelectedIndex();
1507 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1508 alignPanels.remove(panelToClose);
1509 panelToClose.closePanel();
1510 panelToClose = null;
1512 tabbedPane.removeTabAt(closedindex);
1513 tabbedPane.validate();
1515 if (index > closedindex || index == tabbedPane.getTabCount())
1517 // modify currently selected tab index if necessary.
1521 this.tabSelectionChanged(index);
1527 void updateEditMenuBar()
1530 if (viewport.getHistoryList().size() > 0)
1532 undoMenuItem.setEnabled(true);
1533 CommandI command = viewport.getHistoryList().peek();
1534 undoMenuItem.setText(MessageManager.formatMessage(
1535 "label.undo_command",
1536 new Object[] { command.getDescription() }));
1540 undoMenuItem.setEnabled(false);
1541 undoMenuItem.setText(MessageManager.getString("action.undo"));
1544 if (viewport.getRedoList().size() > 0)
1546 redoMenuItem.setEnabled(true);
1548 CommandI command = viewport.getRedoList().peek();
1549 redoMenuItem.setText(MessageManager.formatMessage(
1550 "label.redo_command",
1551 new Object[] { command.getDescription() }));
1555 redoMenuItem.setEnabled(false);
1556 redoMenuItem.setText(MessageManager.getString("action.redo"));
1561 public void addHistoryItem(CommandI command)
1563 if (command.getSize() > 0)
1565 viewport.addToHistoryList(command);
1566 viewport.clearRedoList();
1567 updateEditMenuBar();
1568 viewport.updateHiddenColumns();
1569 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1570 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1571 // viewport.getColumnSelection()
1572 // .getHiddenColumns().size() > 0);
1578 * @return alignment objects for all views
1580 AlignmentI[] getViewAlignments()
1582 if (alignPanels != null)
1584 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1586 for (AlignmentPanel ap : alignPanels)
1588 als[i++] = ap.av.getAlignment();
1592 if (viewport != null)
1594 return new AlignmentI[] { viewport.getAlignment() };
1606 protected void undoMenuItem_actionPerformed(ActionEvent e)
1608 if (viewport.getHistoryList().isEmpty())
1612 CommandI command = viewport.getHistoryList().pop();
1613 viewport.addToRedoList(command);
1614 command.undoCommand(getViewAlignments());
1616 AlignmentViewport originalSource = getOriginatingSource(command);
1617 updateEditMenuBar();
1619 if (originalSource != null)
1621 if (originalSource != viewport)
1624 .warn("Implementation worry: mismatch of viewport origin for undo");
1626 originalSource.updateHiddenColumns();
1627 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1629 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1630 // viewport.getColumnSelection()
1631 // .getHiddenColumns().size() > 0);
1632 originalSource.firePropertyChange("alignment", null, originalSource
1633 .getAlignment().getSequences());
1644 protected void redoMenuItem_actionPerformed(ActionEvent e)
1646 if (viewport.getRedoList().size() < 1)
1651 CommandI command = viewport.getRedoList().pop();
1652 viewport.addToHistoryList(command);
1653 command.doCommand(getViewAlignments());
1655 AlignmentViewport originalSource = getOriginatingSource(command);
1656 updateEditMenuBar();
1658 if (originalSource != null)
1661 if (originalSource != viewport)
1664 .warn("Implementation worry: mismatch of viewport origin for redo");
1666 originalSource.updateHiddenColumns();
1667 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1669 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1670 // viewport.getColumnSelection()
1671 // .getHiddenColumns().size() > 0);
1672 originalSource.firePropertyChange("alignment", null, originalSource
1673 .getAlignment().getSequences());
1677 AlignmentViewport getOriginatingSource(CommandI command)
1679 AlignmentViewport originalSource = null;
1680 // For sequence removal and addition, we need to fire
1681 // the property change event FROM the viewport where the
1682 // original alignment was altered
1683 AlignmentI al = null;
1684 if (command instanceof EditCommand)
1686 EditCommand editCommand = (EditCommand) command;
1687 al = editCommand.getAlignment();
1688 List<Component> comps = PaintRefresher.components.get(viewport
1689 .getSequenceSetId());
1691 for (Component comp : comps)
1693 if (comp instanceof AlignmentPanel)
1695 if (al == ((AlignmentPanel) comp).av.getAlignment())
1697 originalSource = ((AlignmentPanel) comp).av;
1704 if (originalSource == null)
1706 // The original view is closed, we must validate
1707 // the current view against the closed view first
1710 PaintRefresher.validateSequences(al, viewport.getAlignment());
1713 originalSource = viewport;
1716 return originalSource;
1725 public void moveSelectedSequences(boolean up)
1727 SequenceGroup sg = viewport.getSelectionGroup();
1733 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1734 viewport.getHiddenRepSequences(), up);
1735 alignPanel.paintAlignment(true);
1738 synchronized void slideSequences(boolean right, int size)
1740 List<SequenceI> sg = new ArrayList<SequenceI>();
1741 if (viewport.cursorMode)
1743 sg.add(viewport.getAlignment().getSequenceAt(
1744 alignPanel.getSeqPanel().seqCanvas.cursorY));
1746 else if (viewport.getSelectionGroup() != null
1747 && viewport.getSelectionGroup().getSize() != viewport
1748 .getAlignment().getHeight())
1750 sg = viewport.getSelectionGroup().getSequences(
1751 viewport.getHiddenRepSequences());
1759 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1761 for (SequenceI seq : viewport.getAlignment().getSequences())
1763 if (!sg.contains(seq))
1765 invertGroup.add(seq);
1769 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1771 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1772 for (int i = 0; i < invertGroup.size(); i++)
1774 seqs2[i] = invertGroup.get(i);
1777 SlideSequencesCommand ssc;
1780 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1781 size, viewport.getGapCharacter());
1785 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1786 size, viewport.getGapCharacter());
1789 int groupAdjustment = 0;
1790 if (ssc.getGapsInsertedBegin() && right)
1792 if (viewport.cursorMode)
1794 alignPanel.getSeqPanel().moveCursor(size, 0);
1798 groupAdjustment = size;
1801 else if (!ssc.getGapsInsertedBegin() && !right)
1803 if (viewport.cursorMode)
1805 alignPanel.getSeqPanel().moveCursor(-size, 0);
1809 groupAdjustment = -size;
1813 if (groupAdjustment != 0)
1815 viewport.getSelectionGroup().setStartRes(
1816 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1817 viewport.getSelectionGroup().setEndRes(
1818 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1822 * just extend the last slide command if compatible; but not if in
1823 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1825 boolean appendHistoryItem = false;
1826 Deque<CommandI> historyList = viewport.getHistoryList();
1827 boolean inSplitFrame = getSplitViewContainer() != null;
1828 if (!inSplitFrame && historyList != null && historyList.size() > 0
1829 && historyList.peek() instanceof SlideSequencesCommand)
1831 appendHistoryItem = ssc
1832 .appendSlideCommand((SlideSequencesCommand) historyList
1836 if (!appendHistoryItem)
1838 addHistoryItem(ssc);
1851 protected void copy_actionPerformed(ActionEvent e)
1854 if (viewport.getSelectionGroup() == null)
1858 // TODO: preserve the ordering of displayed alignment annotation in any
1859 // internal paste (particularly sequence associated annotation)
1860 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1861 String[] omitHidden = null;
1863 if (viewport.hasHiddenColumns())
1865 omitHidden = viewport.getViewAsString(true);
1868 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1871 StringSelection ss = new StringSelection(output);
1875 jalview.gui.Desktop.internalCopy = true;
1876 // Its really worth setting the clipboard contents
1877 // to empty before setting the large StringSelection!!
1878 Toolkit.getDefaultToolkit().getSystemClipboard()
1879 .setContents(new StringSelection(""), null);
1881 Toolkit.getDefaultToolkit().getSystemClipboard()
1882 .setContents(ss, Desktop.instance);
1883 } catch (OutOfMemoryError er)
1885 new OOMWarning("copying region", er);
1889 ArrayList<int[]> hiddenColumns = null;
1890 if (viewport.hasHiddenColumns())
1892 hiddenColumns = new ArrayList<int[]>();
1893 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1894 .getSelectionGroup().getEndRes();
1895 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1897 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1899 hiddenColumns.add(new int[] { region[0] - hiddenOffset,
1900 region[1] - hiddenOffset });
1905 Desktop.jalviewClipboard = new Object[] { seqs,
1906 viewport.getAlignment().getDataset(), hiddenColumns };
1907 statusBar.setText(MessageManager.formatMessage(
1908 "label.copied_sequences_to_clipboard", new Object[] { Integer
1909 .valueOf(seqs.length).toString() }));
1919 protected void pasteNew_actionPerformed(ActionEvent e)
1931 protected void pasteThis_actionPerformed(ActionEvent e)
1937 * Paste contents of Jalview clipboard
1939 * @param newAlignment
1940 * true to paste to a new alignment, otherwise add to this.
1942 void paste(boolean newAlignment)
1944 boolean externalPaste = true;
1947 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1948 Transferable contents = c.getContents(this);
1950 if (contents == null)
1958 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1959 if (str.length() < 1)
1964 format = new IdentifyFile().identify(str, "Paste");
1966 } catch (OutOfMemoryError er)
1968 new OOMWarning("Out of memory pasting sequences!!", er);
1972 SequenceI[] sequences;
1973 boolean annotationAdded = false;
1974 AlignmentI alignment = null;
1976 if (Desktop.jalviewClipboard != null)
1978 // The clipboard was filled from within Jalview, we must use the
1980 // And dataset from the copied alignment
1981 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1982 // be doubly sure that we create *new* sequence objects.
1983 sequences = new SequenceI[newseq.length];
1984 for (int i = 0; i < newseq.length; i++)
1986 sequences[i] = new Sequence(newseq[i]);
1988 alignment = new Alignment(sequences);
1989 externalPaste = false;
1993 // parse the clipboard as an alignment.
1994 alignment = new FormatAdapter().readFile(str, "Paste", format);
1995 sequences = alignment.getSequencesArray();
1999 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2005 if (Desktop.jalviewClipboard != null)
2007 // dataset is inherited
2008 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2012 // new dataset is constructed
2013 alignment.setDataset(null);
2015 alwidth = alignment.getWidth() + 1;
2019 AlignmentI pastedal = alignment; // preserve pasted alignment object
2020 // Add pasted sequences and dataset into existing alignment.
2021 alignment = viewport.getAlignment();
2022 alwidth = alignment.getWidth() + 1;
2023 // decide if we need to import sequences from an existing dataset
2024 boolean importDs = Desktop.jalviewClipboard != null
2025 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2026 // importDs==true instructs us to copy over new dataset sequences from
2027 // an existing alignment
2028 Vector newDs = (importDs) ? new Vector() : null; // used to create
2029 // minimum dataset set
2031 for (int i = 0; i < sequences.length; i++)
2035 newDs.addElement(null);
2037 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2039 if (importDs && ds != null)
2041 if (!newDs.contains(ds))
2043 newDs.setElementAt(ds, i);
2044 ds = new Sequence(ds);
2045 // update with new dataset sequence
2046 sequences[i].setDatasetSequence(ds);
2050 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2055 // copy and derive new dataset sequence
2056 sequences[i] = sequences[i].deriveSequence();
2057 alignment.getDataset().addSequence(
2058 sequences[i].getDatasetSequence());
2059 // TODO: avoid creation of duplicate dataset sequences with a
2060 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2062 alignment.addSequence(sequences[i]); // merges dataset
2066 newDs.clear(); // tidy up
2068 if (alignment.getAlignmentAnnotation() != null)
2070 for (AlignmentAnnotation alan : alignment
2071 .getAlignmentAnnotation())
2073 if (alan.graphGroup > fgroup)
2075 fgroup = alan.graphGroup;
2079 if (pastedal.getAlignmentAnnotation() != null)
2081 // Add any annotation attached to alignment.
2082 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2083 for (int i = 0; i < alann.length; i++)
2085 annotationAdded = true;
2086 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2088 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2089 if (newann.graphGroup > -1)
2091 if (newGraphGroups.size() <= newann.graphGroup
2092 || newGraphGroups.get(newann.graphGroup) == null)
2094 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2096 newGraphGroups.add(q, null);
2098 newGraphGroups.set(newann.graphGroup, new Integer(
2101 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2105 newann.padAnnotation(alwidth);
2106 alignment.addAnnotation(newann);
2116 addHistoryItem(new EditCommand(
2117 MessageManager.getString("label.add_sequences"),
2118 Action.PASTE, sequences, 0, alignment.getWidth(), alignment));
2120 // Add any annotations attached to sequences
2121 for (int i = 0; i < sequences.length; i++)
2123 if (sequences[i].getAnnotation() != null)
2125 AlignmentAnnotation newann;
2126 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2128 annotationAdded = true;
2129 newann = sequences[i].getAnnotation()[a];
2130 newann.adjustForAlignment();
2131 newann.padAnnotation(alwidth);
2132 if (newann.graphGroup > -1)
2134 if (newann.graphGroup > -1)
2136 if (newGraphGroups.size() <= newann.graphGroup
2137 || newGraphGroups.get(newann.graphGroup) == null)
2139 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2141 newGraphGroups.add(q, null);
2143 newGraphGroups.set(newann.graphGroup, new Integer(
2146 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2150 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2155 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2162 // propagate alignment changed.
2163 viewport.setEndSeq(alignment.getHeight());
2164 if (annotationAdded)
2166 // Duplicate sequence annotation in all views.
2167 AlignmentI[] alview = this.getViewAlignments();
2168 for (int i = 0; i < sequences.length; i++)
2170 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2175 for (int avnum = 0; avnum < alview.length; avnum++)
2177 if (alview[avnum] != alignment)
2179 // duplicate in a view other than the one with input focus
2180 int avwidth = alview[avnum].getWidth() + 1;
2181 // this relies on sann being preserved after we
2182 // modify the sequence's annotation array for each duplication
2183 for (int a = 0; a < sann.length; a++)
2185 AlignmentAnnotation newann = new AlignmentAnnotation(
2187 sequences[i].addAlignmentAnnotation(newann);
2188 newann.padAnnotation(avwidth);
2189 alview[avnum].addAnnotation(newann); // annotation was
2190 // duplicated earlier
2191 // TODO JAL-1145 graphGroups are not updated for sequence
2192 // annotation added to several views. This may cause
2194 alview[avnum].setAnnotationIndex(newann, a);
2199 buildSortByAnnotationScoresMenu();
2201 viewport.firePropertyChange("alignment", null,
2202 alignment.getSequences());
2203 if (alignPanels != null)
2205 for (AlignmentPanel ap : alignPanels)
2207 ap.validateAnnotationDimensions(false);
2212 alignPanel.validateAnnotationDimensions(false);
2218 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2220 String newtitle = new String("Copied sequences");
2222 if (Desktop.jalviewClipboard != null
2223 && Desktop.jalviewClipboard[2] != null)
2225 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2226 for (int[] region : hc)
2228 af.viewport.hideColumns(region[0], region[1]);
2232 // >>>This is a fix for the moment, until a better solution is
2234 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2236 alignPanel.getSeqPanel().seqCanvas
2237 .getFeatureRenderer());
2239 // TODO: maintain provenance of an alignment, rather than just make the
2240 // title a concatenation of operations.
2243 if (title.startsWith("Copied sequences"))
2249 newtitle = newtitle.concat("- from " + title);
2254 newtitle = new String("Pasted sequences");
2257 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2262 } catch (Exception ex)
2264 ex.printStackTrace();
2265 System.out.println("Exception whilst pasting: " + ex);
2266 // could be anything being pasted in here
2272 protected void expand_newalign(ActionEvent e)
2276 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2277 .getAlignment(), -1);
2278 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2280 String newtitle = new String("Flanking alignment");
2282 if (Desktop.jalviewClipboard != null
2283 && Desktop.jalviewClipboard[2] != null)
2285 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2286 for (int region[] : hc)
2288 af.viewport.hideColumns(region[0], region[1]);
2292 // >>>This is a fix for the moment, until a better solution is
2294 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2296 alignPanel.getSeqPanel().seqCanvas
2297 .getFeatureRenderer());
2299 // TODO: maintain provenance of an alignment, rather than just make the
2300 // title a concatenation of operations.
2302 if (title.startsWith("Copied sequences"))
2308 newtitle = newtitle.concat("- from " + title);
2312 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2314 } catch (Exception ex)
2316 ex.printStackTrace();
2317 System.out.println("Exception whilst pasting: " + ex);
2318 // could be anything being pasted in here
2319 } catch (OutOfMemoryError oom)
2321 new OOMWarning("Viewing flanking region of alignment", oom);
2332 protected void cut_actionPerformed(ActionEvent e)
2334 copy_actionPerformed(null);
2335 delete_actionPerformed(null);
2345 protected void delete_actionPerformed(ActionEvent evt)
2348 SequenceGroup sg = viewport.getSelectionGroup();
2355 * If the cut affects all sequences, warn, remove highlighted columns
2357 if (sg.getSize() == viewport.getAlignment().getHeight())
2359 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2360 .getAlignment().getWidth()) ? true : false;
2361 if (isEntireAlignWidth)
2363 int confirm = JOptionPane.showConfirmDialog(this,
2364 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2365 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2366 JOptionPane.OK_CANCEL_OPTION);
2368 if (confirm == JOptionPane.CANCEL_OPTION
2369 || confirm == JOptionPane.CLOSED_OPTION)
2374 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2375 sg.getEndRes() + 1);
2377 SequenceI[] cut = sg.getSequences()
2378 .toArray(new SequenceI[sg.getSize()]);
2380 addHistoryItem(new EditCommand(
2381 MessageManager.getString("label.cut_sequences"), Action.CUT,
2382 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2383 viewport.getAlignment()));
2385 viewport.setSelectionGroup(null);
2386 viewport.sendSelection();
2387 viewport.getAlignment().deleteGroup(sg);
2389 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2391 if (viewport.getAlignment().getHeight() < 1)
2395 this.setClosed(true);
2396 } catch (Exception ex)
2409 protected void deleteGroups_actionPerformed(ActionEvent e)
2411 if (avc.deleteGroups())
2413 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2414 alignPanel.updateAnnotation();
2415 alignPanel.paintAlignment(true);
2426 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2428 SequenceGroup sg = new SequenceGroup();
2430 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2432 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2435 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2436 viewport.setSelectionGroup(sg);
2437 viewport.sendSelection();
2438 // JAL-2034 - should delegate to
2439 // alignPanel to decide if overview needs
2441 alignPanel.paintAlignment(false);
2442 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2452 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2454 if (viewport.cursorMode)
2456 alignPanel.getSeqPanel().keyboardNo1 = null;
2457 alignPanel.getSeqPanel().keyboardNo2 = null;
2459 viewport.setSelectionGroup(null);
2460 viewport.getColumnSelection().clear();
2461 viewport.setSelectionGroup(null);
2462 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2463 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2464 // JAL-2034 - should delegate to
2465 // alignPanel to decide if overview needs
2467 alignPanel.paintAlignment(false);
2468 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2469 viewport.sendSelection();
2479 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2481 SequenceGroup sg = viewport.getSelectionGroup();
2485 selectAllSequenceMenuItem_actionPerformed(null);
2490 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2492 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2494 // JAL-2034 - should delegate to
2495 // alignPanel to decide if overview needs
2498 alignPanel.paintAlignment(true);
2499 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2500 viewport.sendSelection();
2504 public void invertColSel_actionPerformed(ActionEvent e)
2506 viewport.invertColumnSelection();
2507 alignPanel.paintAlignment(true);
2508 viewport.sendSelection();
2518 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2520 trimAlignment(true);
2530 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2532 trimAlignment(false);
2535 void trimAlignment(boolean trimLeft)
2537 ColumnSelection colSel = viewport.getColumnSelection();
2540 if (!colSel.isEmpty())
2544 column = colSel.getMin();
2548 column = colSel.getMax();
2552 if (viewport.getSelectionGroup() != null)
2554 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2555 viewport.getHiddenRepSequences());
2559 seqs = viewport.getAlignment().getSequencesArray();
2562 TrimRegionCommand trimRegion;
2565 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2566 column, viewport.getAlignment());
2567 viewport.setStartRes(0);
2571 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2572 column, viewport.getAlignment());
2575 statusBar.setText(MessageManager.formatMessage(
2576 "label.removed_columns",
2577 new String[] { Integer.valueOf(trimRegion.getSize())
2580 addHistoryItem(trimRegion);
2582 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2584 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2585 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2587 viewport.getAlignment().deleteGroup(sg);
2591 viewport.firePropertyChange("alignment", null, viewport
2592 .getAlignment().getSequences());
2603 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2605 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2608 if (viewport.getSelectionGroup() != null)
2610 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2611 viewport.getHiddenRepSequences());
2612 start = viewport.getSelectionGroup().getStartRes();
2613 end = viewport.getSelectionGroup().getEndRes();
2617 seqs = viewport.getAlignment().getSequencesArray();
2620 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2621 "Remove Gapped Columns", seqs, start, end,
2622 viewport.getAlignment());
2624 addHistoryItem(removeGapCols);
2626 statusBar.setText(MessageManager.formatMessage(
2627 "label.removed_empty_columns",
2628 new Object[] { Integer.valueOf(removeGapCols.getSize())
2631 // This is to maintain viewport position on first residue
2632 // of first sequence
2633 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2634 int startRes = seq.findPosition(viewport.startRes);
2635 // ShiftList shifts;
2636 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2637 // edit.alColumnChanges=shifts.getInverse();
2638 // if (viewport.hasHiddenColumns)
2639 // viewport.getColumnSelection().compensateForEdits(shifts);
2640 viewport.setStartRes(seq.findIndex(startRes) - 1);
2641 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2653 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2655 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2658 if (viewport.getSelectionGroup() != null)
2660 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2661 viewport.getHiddenRepSequences());
2662 start = viewport.getSelectionGroup().getStartRes();
2663 end = viewport.getSelectionGroup().getEndRes();
2667 seqs = viewport.getAlignment().getSequencesArray();
2670 // This is to maintain viewport position on first residue
2671 // of first sequence
2672 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2673 int startRes = seq.findPosition(viewport.startRes);
2675 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2676 viewport.getAlignment()));
2678 viewport.setStartRes(seq.findIndex(startRes) - 1);
2680 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2692 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2694 viewport.setPadGaps(padGapsMenuitem.isSelected());
2695 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2706 public void findMenuItem_actionPerformed(ActionEvent e)
2712 * Create a new view of the current alignment.
2715 public void newView_actionPerformed(ActionEvent e)
2717 newView(null, true);
2721 * Creates and shows a new view of the current alignment.
2724 * title of newly created view; if null, one will be generated
2725 * @param copyAnnotation
2726 * if true then duplicate all annnotation, groups and settings
2727 * @return new alignment panel, already displayed.
2729 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2732 * Create a new AlignmentPanel (with its own, new Viewport)
2734 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2736 if (!copyAnnotation)
2739 * remove all groups and annotation except for the automatic stuff
2741 newap.av.getAlignment().deleteAllGroups();
2742 newap.av.getAlignment().deleteAllAnnotations(false);
2745 newap.av.setGatherViewsHere(false);
2747 if (viewport.viewName == null)
2749 viewport.viewName = MessageManager
2750 .getString("label.view_name_original");
2754 * Views share the same edits undo and redo stacks
2756 newap.av.setHistoryList(viewport.getHistoryList());
2757 newap.av.setRedoList(viewport.getRedoList());
2760 * Views share the same mappings; need to deregister any new mappings
2761 * created by copyAlignPanel, and register the new reference to the shared
2764 newap.av.replaceMappings(viewport.getAlignment());
2766 newap.av.viewName = getNewViewName(viewTitle);
2768 addAlignmentPanel(newap, true);
2769 newap.alignmentChanged();
2771 if (alignPanels.size() == 2)
2773 viewport.setGatherViewsHere(true);
2775 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2780 * Make a new name for the view, ensuring it is unique within the current
2781 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2782 * these now use viewId. Unique view names are still desirable for usability.)
2787 protected String getNewViewName(String viewTitle)
2789 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2790 boolean addFirstIndex = false;
2791 if (viewTitle == null || viewTitle.trim().length() == 0)
2793 viewTitle = MessageManager.getString("action.view");
2794 addFirstIndex = true;
2798 index = 1;// we count from 1 if given a specific name
2800 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2802 List<Component> comps = PaintRefresher.components.get(viewport
2803 .getSequenceSetId());
2805 List<String> existingNames = getExistingViewNames(comps);
2807 while (existingNames.contains(newViewName))
2809 newViewName = viewTitle + " " + (++index);
2815 * Returns a list of distinct view names found in the given list of
2816 * components. View names are held on the viewport of an AlignmentPanel.
2821 protected List<String> getExistingViewNames(List<Component> comps)
2823 List<String> existingNames = new ArrayList<String>();
2824 for (Component comp : comps)
2826 if (comp instanceof AlignmentPanel)
2828 AlignmentPanel ap = (AlignmentPanel) comp;
2829 if (!existingNames.contains(ap.av.viewName))
2831 existingNames.add(ap.av.viewName);
2835 return existingNames;
2839 * Explode tabbed views into separate windows.
2842 public void expandViews_actionPerformed(ActionEvent e)
2844 Desktop.explodeViews(this);
2848 * Gather views in separate windows back into a tabbed presentation.
2851 public void gatherViews_actionPerformed(ActionEvent e)
2853 Desktop.instance.gatherViews(this);
2863 public void font_actionPerformed(ActionEvent e)
2865 new FontChooser(alignPanel);
2875 protected void seqLimit_actionPerformed(ActionEvent e)
2877 viewport.setShowJVSuffix(seqLimits.isSelected());
2879 alignPanel.getIdPanel().getIdCanvas()
2880 .setPreferredSize(alignPanel.calculateIdWidth());
2881 alignPanel.paintAlignment(true);
2885 public void idRightAlign_actionPerformed(ActionEvent e)
2887 viewport.setRightAlignIds(idRightAlign.isSelected());
2888 alignPanel.paintAlignment(true);
2892 public void centreColumnLabels_actionPerformed(ActionEvent e)
2894 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2895 alignPanel.paintAlignment(true);
2901 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2904 protected void followHighlight_actionPerformed()
2907 * Set the 'follow' flag on the Viewport (and scroll to position if now
2910 final boolean state = this.followHighlightMenuItem.getState();
2911 viewport.setFollowHighlight(state);
2914 alignPanel.scrollToPosition(
2915 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2926 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2928 viewport.setColourText(colourTextMenuItem.isSelected());
2929 alignPanel.paintAlignment(true);
2939 public void wrapMenuItem_actionPerformed(ActionEvent e)
2941 scaleAbove.setVisible(wrapMenuItem.isSelected());
2942 scaleLeft.setVisible(wrapMenuItem.isSelected());
2943 scaleRight.setVisible(wrapMenuItem.isSelected());
2944 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2945 alignPanel.updateLayout();
2949 public void showAllSeqs_actionPerformed(ActionEvent e)
2951 viewport.showAllHiddenSeqs();
2955 public void showAllColumns_actionPerformed(ActionEvent e)
2957 viewport.showAllHiddenColumns();
2959 viewport.sendSelection();
2963 public void hideSelSequences_actionPerformed(ActionEvent e)
2965 viewport.hideAllSelectedSeqs();
2966 // alignPanel.paintAlignment(true);
2970 * called by key handler and the hide all/show all menu items
2975 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2978 boolean hide = false;
2979 SequenceGroup sg = viewport.getSelectionGroup();
2980 if (!toggleSeqs && !toggleCols)
2982 // Hide everything by the current selection - this is a hack - we do the
2983 // invert and then hide
2984 // first check that there will be visible columns after the invert.
2985 if ((viewport.getColumnSelection() != null
2986 && viewport.getColumnSelection().getSelected() != null && viewport
2987 .getColumnSelection().getSelected().size() > 0)
2988 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2991 // now invert the sequence set, if required - empty selection implies
2992 // that no hiding is required.
2995 invertSequenceMenuItem_actionPerformed(null);
2996 sg = viewport.getSelectionGroup();
3000 viewport.expandColSelection(sg, true);
3001 // finally invert the column selection and get the new sequence
3003 invertColSel_actionPerformed(null);
3010 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3012 hideSelSequences_actionPerformed(null);
3015 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3018 showAllSeqs_actionPerformed(null);
3024 if (viewport.getColumnSelection().getSelected().size() > 0)
3026 hideSelColumns_actionPerformed(null);
3029 viewport.setSelectionGroup(sg);
3034 showAllColumns_actionPerformed(null);
3043 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3044 * event.ActionEvent)
3047 public void hideAllButSelection_actionPerformed(ActionEvent e)
3049 toggleHiddenRegions(false, false);
3050 viewport.sendSelection();
3057 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3061 public void hideAllSelection_actionPerformed(ActionEvent e)
3063 SequenceGroup sg = viewport.getSelectionGroup();
3064 viewport.expandColSelection(sg, false);
3065 viewport.hideAllSelectedSeqs();
3066 viewport.hideSelectedColumns();
3067 alignPanel.paintAlignment(true);
3068 viewport.sendSelection();
3075 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3079 public void showAllhidden_actionPerformed(ActionEvent e)
3081 viewport.showAllHiddenColumns();
3082 viewport.showAllHiddenSeqs();
3083 alignPanel.paintAlignment(true);
3084 viewport.sendSelection();
3088 public void hideSelColumns_actionPerformed(ActionEvent e)
3090 viewport.hideSelectedColumns();
3091 alignPanel.paintAlignment(true);
3092 viewport.sendSelection();
3096 public void hiddenMarkers_actionPerformed(ActionEvent e)
3098 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3109 protected void scaleAbove_actionPerformed(ActionEvent e)
3111 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3112 alignPanel.paintAlignment(true);
3122 protected void scaleLeft_actionPerformed(ActionEvent e)
3124 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3125 alignPanel.paintAlignment(true);
3135 protected void scaleRight_actionPerformed(ActionEvent e)
3137 viewport.setScaleRightWrapped(scaleRight.isSelected());
3138 alignPanel.paintAlignment(true);
3148 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3150 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3151 alignPanel.paintAlignment(true);
3161 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3163 viewport.setShowText(viewTextMenuItem.isSelected());
3164 alignPanel.paintAlignment(true);
3174 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3176 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3177 alignPanel.paintAlignment(true);
3180 public FeatureSettings featureSettings;
3183 public FeatureSettingsControllerI getFeatureSettingsUI()
3185 return featureSettings;
3189 public void featureSettings_actionPerformed(ActionEvent e)
3191 if (featureSettings != null)
3193 featureSettings.close();
3194 featureSettings = null;
3196 if (!showSeqFeatures.isSelected())
3198 // make sure features are actually displayed
3199 showSeqFeatures.setSelected(true);
3200 showSeqFeatures_actionPerformed(null);
3202 featureSettings = new FeatureSettings(this);
3206 * Set or clear 'Show Sequence Features'
3212 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3214 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3215 alignPanel.paintAlignment(true);
3216 if (alignPanel.getOverviewPanel() != null)
3218 alignPanel.getOverviewPanel().updateOverviewImage();
3223 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3224 * the annotations panel as a whole.
3226 * The options to show/hide all annotations should be enabled when the panel
3227 * is shown, and disabled when the panel is hidden.
3232 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3234 final boolean setVisible = annotationPanelMenuItem.isSelected();
3235 viewport.setShowAnnotation(setVisible);
3236 this.showAllSeqAnnotations.setEnabled(setVisible);
3237 this.hideAllSeqAnnotations.setEnabled(setVisible);
3238 this.showAllAlAnnotations.setEnabled(setVisible);
3239 this.hideAllAlAnnotations.setEnabled(setVisible);
3240 alignPanel.updateLayout();
3244 public void alignmentProperties()
3246 JEditorPane editPane = new JEditorPane("text/html", "");
3247 editPane.setEditable(false);
3248 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3250 editPane.setText(MessageManager.formatMessage("label.html_content",
3251 new Object[] { contents.toString() }));
3252 JInternalFrame frame = new JInternalFrame();
3253 frame.getContentPane().add(new JScrollPane(editPane));
3255 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3256 "label.alignment_properties", new Object[] { getTitle() }),
3267 public void overviewMenuItem_actionPerformed(ActionEvent e)
3269 if (alignPanel.overviewPanel != null)
3274 JInternalFrame frame = new JInternalFrame();
3275 OverviewPanel overview = new OverviewPanel(alignPanel);
3276 frame.setContentPane(overview);
3277 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3278 "label.overview_params", new Object[] { this.getTitle() }),
3279 frame.getWidth(), frame.getHeight());
3281 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3282 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3285 public void internalFrameClosed(
3286 javax.swing.event.InternalFrameEvent evt)
3288 alignPanel.setOverviewPanel(null);
3292 alignPanel.setOverviewPanel(overview);
3296 public void textColour_actionPerformed(ActionEvent e)
3298 new TextColourChooser().chooseColour(alignPanel, null);
3308 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3320 public void clustalColour_actionPerformed(ActionEvent e)
3322 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3323 viewport.getHiddenRepSequences()));
3333 public void zappoColour_actionPerformed(ActionEvent e)
3335 changeColour(new ZappoColourScheme());
3345 public void taylorColour_actionPerformed(ActionEvent e)
3347 changeColour(new TaylorColourScheme());
3357 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3359 changeColour(new HydrophobicColourScheme());
3369 public void helixColour_actionPerformed(ActionEvent e)
3371 changeColour(new HelixColourScheme());
3381 public void strandColour_actionPerformed(ActionEvent e)
3383 changeColour(new StrandColourScheme());
3393 public void turnColour_actionPerformed(ActionEvent e)
3395 changeColour(new TurnColourScheme());
3405 public void buriedColour_actionPerformed(ActionEvent e)
3407 changeColour(new BuriedColourScheme());
3417 public void nucleotideColour_actionPerformed(ActionEvent e)
3419 changeColour(new NucleotideColourScheme());
3423 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3425 changeColour(new PurinePyrimidineColourScheme());
3429 * public void covariationColour_actionPerformed(ActionEvent e) {
3431 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3435 public void annotationColour_actionPerformed(ActionEvent e)
3437 new AnnotationColourChooser(viewport, alignPanel);
3441 public void annotationColumn_actionPerformed(ActionEvent e)
3443 new AnnotationColumnChooser(viewport, alignPanel);
3447 public void rnahelicesColour_actionPerformed(ActionEvent e)
3449 new RNAHelicesColourChooser(viewport, alignPanel);
3459 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3461 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3471 public void changeColour(ColourSchemeI cs)
3473 // TODO: pull up to controller method
3477 // Make sure viewport is up to date w.r.t. any sliders
3478 if (viewport.getAbovePIDThreshold())
3480 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3482 viewport.setThreshold(threshold);
3485 if (viewport.getConservationSelected())
3487 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3490 if (cs instanceof TCoffeeColourScheme)
3492 tcoffeeColour.setEnabled(true);
3493 tcoffeeColour.setSelected(true);
3497 viewport.setGlobalColourScheme(cs);
3499 alignPanel.paintAlignment(true);
3509 protected void modifyPID_actionPerformed(ActionEvent e)
3511 if (viewport.getAbovePIDThreshold()
3512 && viewport.getGlobalColourScheme() != null)
3514 SliderPanel.setPIDSliderSource(alignPanel,
3515 viewport.getGlobalColourScheme(), "Background");
3516 SliderPanel.showPIDSlider();
3527 protected void modifyConservation_actionPerformed(ActionEvent e)
3529 if (viewport.getConservationSelected()
3530 && viewport.getGlobalColourScheme() != null)
3532 SliderPanel.setConservationSlider(alignPanel,
3533 viewport.getGlobalColourScheme(), "Background");
3534 SliderPanel.showConservationSlider();
3545 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3547 viewport.setConservationSelected(conservationMenuItem.isSelected());
3549 viewport.setAbovePIDThreshold(false);
3550 abovePIDThreshold.setSelected(false);
3552 changeColour(viewport.getGlobalColourScheme());
3554 modifyConservation_actionPerformed(null);
3564 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3566 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3568 conservationMenuItem.setSelected(false);
3569 viewport.setConservationSelected(false);
3571 changeColour(viewport.getGlobalColourScheme());
3573 modifyPID_actionPerformed(null);
3583 public void userDefinedColour_actionPerformed(ActionEvent e)
3585 if (e.getActionCommand().equals(
3586 MessageManager.getString("action.user_defined")))
3588 new UserDefinedColours(alignPanel, null);
3592 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3593 .getUserColourSchemes().get(e.getActionCommand());
3599 public void updateUserColourMenu()
3602 Component[] menuItems = colourMenu.getMenuComponents();
3603 int iSize = menuItems.length;
3604 for (int i = 0; i < iSize; i++)
3606 if (menuItems[i].getName() != null
3607 && menuItems[i].getName().equals("USER_DEFINED"))
3609 colourMenu.remove(menuItems[i]);
3613 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3615 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3616 .getUserColourSchemes().keys();
3618 while (userColours.hasMoreElements())
3620 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3621 userColours.nextElement().toString());
3622 radioItem.setName("USER_DEFINED");
3623 radioItem.addMouseListener(new MouseAdapter()
3626 public void mousePressed(MouseEvent evt)
3628 if (evt.isPopupTrigger())
3630 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3632 int option = JOptionPane.showInternalConfirmDialog(
3633 jalview.gui.Desktop.desktop,
3635 .getString("label.remove_from_default_list"),
3637 .getString("label.remove_user_defined_colour"),
3638 JOptionPane.YES_NO_OPTION);
3639 if (option == JOptionPane.YES_OPTION)
3641 jalview.gui.UserDefinedColours
3642 .removeColourFromDefaults(radioItem.getText());
3643 colourMenu.remove(radioItem);
3647 radioItem.addActionListener(new ActionListener()
3650 public void actionPerformed(ActionEvent evt)
3652 userDefinedColour_actionPerformed(evt);
3659 radioItem.addActionListener(new ActionListener()
3662 public void actionPerformed(ActionEvent evt)
3664 userDefinedColour_actionPerformed(evt);
3668 colourMenu.insert(radioItem, 15);
3669 colours.add(radioItem);
3681 public void PIDColour_actionPerformed(ActionEvent e)
3683 changeColour(new PIDColourScheme());
3693 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3695 changeColour(new Blosum62ColourScheme());
3705 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3707 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3708 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3709 .getAlignment().getSequenceAt(0), null);
3710 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3711 viewport.getAlignment()));
3712 alignPanel.paintAlignment(true);
3722 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3724 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3725 AlignmentSorter.sortByID(viewport.getAlignment());
3726 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3727 viewport.getAlignment()));
3728 alignPanel.paintAlignment(true);
3738 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3740 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3741 AlignmentSorter.sortByLength(viewport.getAlignment());
3742 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3743 viewport.getAlignment()));
3744 alignPanel.paintAlignment(true);
3754 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3756 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3757 AlignmentSorter.sortByGroup(viewport.getAlignment());
3758 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3759 viewport.getAlignment()));
3761 alignPanel.paintAlignment(true);
3771 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3773 new RedundancyPanel(alignPanel, this);
3783 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3785 if ((viewport.getSelectionGroup() == null)
3786 || (viewport.getSelectionGroup().getSize() < 2))
3788 JOptionPane.showInternalMessageDialog(this, MessageManager
3789 .getString("label.you_must_select_least_two_sequences"),
3790 MessageManager.getString("label.invalid_selection"),
3791 JOptionPane.WARNING_MESSAGE);
3795 JInternalFrame frame = new JInternalFrame();
3796 frame.setContentPane(new PairwiseAlignPanel(viewport));
3797 Desktop.addInternalFrame(frame,
3798 MessageManager.getString("action.pairwise_alignment"), 600,
3810 public void PCAMenuItem_actionPerformed(ActionEvent e)
3812 if (((viewport.getSelectionGroup() != null)
3813 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3814 .getSelectionGroup().getSize() > 0))
3815 || (viewport.getAlignment().getHeight() < 4))
3818 .showInternalMessageDialog(
3821 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3823 .getString("label.sequence_selection_insufficient"),
3824 JOptionPane.WARNING_MESSAGE);
3829 new PCAPanel(alignPanel);
3833 public void autoCalculate_actionPerformed(ActionEvent e)
3835 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3836 if (viewport.autoCalculateConsensus)
3838 viewport.firePropertyChange("alignment", null, viewport
3839 .getAlignment().getSequences());
3844 public void sortByTreeOption_actionPerformed(ActionEvent e)
3846 viewport.sortByTree = sortByTree.isSelected();
3850 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3852 viewport.followSelection = listenToViewSelections.isSelected();
3862 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3864 newTreePanel("AV", "PID", "Average distance tree using PID");
3874 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3876 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3886 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3888 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3898 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3900 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3913 void newTreePanel(String type, String pwType, String title)
3917 if (viewport.getSelectionGroup() != null
3918 && viewport.getSelectionGroup().getSize() > 0)
3920 if (viewport.getSelectionGroup().getSize() < 3)
3926 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3928 .getString("label.not_enough_sequences"),
3929 JOptionPane.WARNING_MESSAGE);
3933 SequenceGroup sg = viewport.getSelectionGroup();
3935 /* Decide if the selection is a column region */
3936 for (SequenceI _s : sg.getSequences())
3938 if (_s.getLength() < sg.getEndRes())
3944 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3946 .getString("label.sequences_selection_not_aligned"),
3947 JOptionPane.WARNING_MESSAGE);
3953 title = title + " on region";
3954 tp = new TreePanel(alignPanel, type, pwType);
3958 // are the visible sequences aligned?
3959 if (!viewport.getAlignment().isAligned(false))
3965 .getString("label.sequences_must_be_aligned_before_creating_tree"),
3967 .getString("label.sequences_not_aligned"),
3968 JOptionPane.WARNING_MESSAGE);
3973 if (viewport.getAlignment().getHeight() < 2)
3978 tp = new TreePanel(alignPanel, type, pwType);
3983 if (viewport.viewName != null)
3985 title += viewport.viewName + " of ";
3988 title += this.title;
3990 Desktop.addInternalFrame(tp, title, 600, 500);
4001 public void addSortByOrderMenuItem(String title,
4002 final AlignmentOrder order)
4004 final JMenuItem item = new JMenuItem(MessageManager.formatMessage(
4005 "action.by_title_param", new Object[] { title }));
4007 item.addActionListener(new java.awt.event.ActionListener()
4010 public void actionPerformed(ActionEvent e)
4012 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4014 // TODO: JBPNote - have to map order entries to curent SequenceI
4016 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4018 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4021 alignPanel.paintAlignment(true);
4027 * Add a new sort by annotation score menu item
4030 * the menu to add the option to
4032 * the label used to retrieve scores for each sequence on the
4035 public void addSortByAnnotScoreMenuItem(JMenu sort,
4036 final String scoreLabel)
4038 final JMenuItem item = new JMenuItem(scoreLabel);
4040 item.addActionListener(new java.awt.event.ActionListener()
4043 public void actionPerformed(ActionEvent e)
4045 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4046 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4047 viewport.getAlignment());// ,viewport.getSelectionGroup());
4048 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4049 viewport.getAlignment()));
4050 alignPanel.paintAlignment(true);
4056 * last hash for alignment's annotation array - used to minimise cost of
4059 protected int _annotationScoreVectorHash;
4062 * search the alignment and rebuild the sort by annotation score submenu the
4063 * last alignment annotation vector hash is stored to minimize cost of
4064 * rebuilding in subsequence calls.
4068 public void buildSortByAnnotationScoresMenu()
4070 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4075 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4077 sortByAnnotScore.removeAll();
4078 // almost certainly a quicker way to do this - but we keep it simple
4079 Hashtable scoreSorts = new Hashtable();
4080 AlignmentAnnotation aann[];
4081 for (SequenceI sqa : viewport.getAlignment().getSequences())
4083 aann = sqa.getAnnotation();
4084 for (int i = 0; aann != null && i < aann.length; i++)
4086 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4088 scoreSorts.put(aann[i].label, aann[i].label);
4092 Enumeration labels = scoreSorts.keys();
4093 while (labels.hasMoreElements())
4095 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4096 (String) labels.nextElement());
4098 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4101 _annotationScoreVectorHash = viewport.getAlignment()
4102 .getAlignmentAnnotation().hashCode();
4107 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4108 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4109 * call. Listeners are added to remove the menu item when the treePanel is
4110 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4114 * Displayed tree window.
4116 * SortBy menu item title.
4119 public void buildTreeMenu()
4121 calculateTree.removeAll();
4122 // build the calculate menu
4124 for (final String type : new String[] { "NJ", "AV" })
4126 String treecalcnm = MessageManager.getString("label.tree_calc_"
4127 + type.toLowerCase());
4128 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4130 JMenuItem tm = new JMenuItem();
4131 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4132 if (sm.isDNA() == viewport.getAlignment().isNucleotide()
4133 || sm.isProtein() == !viewport.getAlignment()
4136 String smn = MessageManager.getStringOrReturn(
4137 "label.score_model_", sm.getName());
4138 final String title = MessageManager.formatMessage(
4139 "label.treecalc_title", treecalcnm, smn);
4140 tm.setText(title);//
4141 tm.addActionListener(new java.awt.event.ActionListener()
4144 public void actionPerformed(ActionEvent e)
4146 newTreePanel(type, pwtype, title);
4149 calculateTree.add(tm);
4154 sortByTreeMenu.removeAll();
4156 List<Component> comps = PaintRefresher.components.get(viewport
4157 .getSequenceSetId());
4158 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4159 for (Component comp : comps)
4161 if (comp instanceof TreePanel)
4163 treePanels.add((TreePanel) comp);
4167 if (treePanels.size() < 1)
4169 sortByTreeMenu.setVisible(false);
4173 sortByTreeMenu.setVisible(true);
4175 for (final TreePanel tp : treePanels)
4177 final JMenuItem item = new JMenuItem(tp.getTitle());
4178 item.addActionListener(new java.awt.event.ActionListener()
4181 public void actionPerformed(ActionEvent e)
4183 tp.sortByTree_actionPerformed();
4184 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4189 sortByTreeMenu.add(item);
4193 public boolean sortBy(AlignmentOrder alorder, String undoname)
4195 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4196 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4197 if (undoname != null)
4199 addHistoryItem(new OrderCommand(undoname, oldOrder,
4200 viewport.getAlignment()));
4202 alignPanel.paintAlignment(true);
4207 * Work out whether the whole set of sequences or just the selected set will
4208 * be submitted for multiple alignment.
4211 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4213 // Now, check we have enough sequences
4214 AlignmentView msa = null;
4216 if ((viewport.getSelectionGroup() != null)
4217 && (viewport.getSelectionGroup().getSize() > 1))
4219 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4220 // some common interface!
4222 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4223 * SequenceI[sz = seqs.getSize(false)];
4225 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4226 * seqs.getSequenceAt(i); }
4228 msa = viewport.getAlignmentView(true);
4230 else if (viewport.getSelectionGroup() != null
4231 && viewport.getSelectionGroup().getSize() == 1)
4233 int option = JOptionPane.showConfirmDialog(this,
4234 MessageManager.getString("warn.oneseq_msainput_selection"),
4235 MessageManager.getString("label.invalid_selection"),
4236 JOptionPane.OK_CANCEL_OPTION);
4237 if (option == JOptionPane.OK_OPTION)
4239 msa = viewport.getAlignmentView(false);
4244 msa = viewport.getAlignmentView(false);
4250 * Decides what is submitted to a secondary structure prediction service: the
4251 * first sequence in the alignment, or in the current selection, or, if the
4252 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4253 * region or the whole alignment. (where the first sequence in the set is the
4254 * one that the prediction will be for).
4256 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4258 AlignmentView seqs = null;
4260 if ((viewport.getSelectionGroup() != null)
4261 && (viewport.getSelectionGroup().getSize() > 0))
4263 seqs = viewport.getAlignmentView(true);
4267 seqs = viewport.getAlignmentView(false);
4269 // limit sequences - JBPNote in future - could spawn multiple prediction
4271 // TODO: viewport.getAlignment().isAligned is a global state - the local
4272 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4273 if (!viewport.getAlignment().isAligned(false))
4275 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4276 // TODO: if seqs.getSequences().length>1 then should really have warned
4290 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4292 // Pick the tree file
4293 JalviewFileChooser chooser = new JalviewFileChooser(
4294 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4295 chooser.setFileView(new JalviewFileView());
4296 chooser.setDialogTitle(MessageManager
4297 .getString("label.select_newick_like_tree_file"));
4298 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4300 int value = chooser.showOpenDialog(null);
4302 if (value == JalviewFileChooser.APPROVE_OPTION)
4304 String choice = chooser.getSelectedFile().getPath();
4305 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4306 jalview.io.NewickFile fin = null;
4309 fin = new jalview.io.NewickFile(choice, "File");
4310 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4311 } catch (Exception ex)
4318 .getString("label.problem_reading_tree_file"),
4319 JOptionPane.WARNING_MESSAGE);
4320 ex.printStackTrace();
4322 if (fin != null && fin.hasWarningMessage())
4324 JOptionPane.showMessageDialog(Desktop.desktop, fin
4325 .getWarningMessage(), MessageManager
4326 .getString("label.possible_problem_with_tree_file"),
4327 JOptionPane.WARNING_MESSAGE);
4333 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4335 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4338 public TreePanel ShowNewickTree(NewickFile nf, String title)
4340 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4343 public TreePanel ShowNewickTree(NewickFile nf, String title,
4344 AlignmentView input)
4346 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4349 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4350 int h, int x, int y)
4352 return ShowNewickTree(nf, title, null, w, h, x, y);
4356 * Add a treeviewer for the tree extracted from a newick file object to the
4357 * current alignment view
4364 * Associated alignment input data (or null)
4373 * @return TreePanel handle
4375 public TreePanel ShowNewickTree(NewickFile nf, String title,
4376 AlignmentView input, int w, int h, int x, int y)
4378 TreePanel tp = null;
4384 if (nf.getTree() != null)
4386 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4392 tp.setLocation(x, y);
4395 Desktop.addInternalFrame(tp, title, w, h);
4397 } catch (Exception ex)
4399 ex.printStackTrace();
4405 private boolean buildingMenu = false;
4408 * Generates menu items and listener event actions for web service clients
4411 public void BuildWebServiceMenu()
4413 while (buildingMenu)
4417 System.err.println("Waiting for building menu to finish.");
4419 } catch (Exception e)
4423 final AlignFrame me = this;
4424 buildingMenu = true;
4425 new Thread(new Runnable()
4430 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4433 // System.err.println("Building ws menu again "
4434 // + Thread.currentThread());
4435 // TODO: add support for context dependent disabling of services based
4437 // alignment and current selection
4438 // TODO: add additional serviceHandle parameter to specify abstract
4440 // class independently of AbstractName
4441 // TODO: add in rediscovery GUI function to restart discoverer
4442 // TODO: group services by location as well as function and/or
4444 // object broker mechanism.
4445 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4446 final IProgressIndicator af = me;
4449 * do not i18n these strings - they are hard-coded in class
4450 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4451 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4453 final JMenu msawsmenu = new JMenu("Alignment");
4454 final JMenu secstrmenu = new JMenu(
4455 "Secondary Structure Prediction");
4456 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4457 final JMenu analymenu = new JMenu("Analysis");
4458 final JMenu dismenu = new JMenu("Protein Disorder");
4459 // JAL-940 - only show secondary structure prediction services from
4460 // the legacy server
4461 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4463 Discoverer.services != null && (Discoverer.services.size() > 0))
4465 // TODO: refactor to allow list of AbstractName/Handler bindings to
4467 // stored or retrieved from elsewhere
4468 // No MSAWS used any more:
4469 // Vector msaws = null; // (Vector)
4470 // Discoverer.services.get("MsaWS");
4471 Vector secstrpr = (Vector) Discoverer.services
4473 if (secstrpr != null)
4475 // Add any secondary structure prediction services
4476 for (int i = 0, j = secstrpr.size(); i < j; i++)
4478 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4480 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4481 .getServiceClient(sh);
4482 int p = secstrmenu.getItemCount();
4483 impl.attachWSMenuEntry(secstrmenu, me);
4484 int q = secstrmenu.getItemCount();
4485 for (int litm = p; litm < q; litm++)
4487 legacyItems.add(secstrmenu.getItem(litm));
4493 // Add all submenus in the order they should appear on the web
4495 wsmenu.add(msawsmenu);
4496 wsmenu.add(secstrmenu);
4497 wsmenu.add(dismenu);
4498 wsmenu.add(analymenu);
4499 // No search services yet
4500 // wsmenu.add(seqsrchmenu);
4502 javax.swing.SwingUtilities.invokeLater(new Runnable()
4509 webService.removeAll();
4510 // first, add discovered services onto the webservices menu
4511 if (wsmenu.size() > 0)
4513 for (int i = 0, j = wsmenu.size(); i < j; i++)
4515 webService.add(wsmenu.get(i));
4520 webService.add(me.webServiceNoServices);
4522 // TODO: move into separate menu builder class.
4523 boolean new_sspred = false;
4524 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4526 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4527 if (jws2servs != null)
4529 if (jws2servs.hasServices())
4531 jws2servs.attachWSMenuEntry(webService, me);
4532 for (Jws2Instance sv : jws2servs.getServices())
4534 if (sv.description.toLowerCase().contains("jpred"))
4536 for (JMenuItem jmi : legacyItems)
4538 jmi.setVisible(false);
4544 if (jws2servs.isRunning())
4546 JMenuItem tm = new JMenuItem(
4547 "Still discovering JABA Services");
4548 tm.setEnabled(false);
4553 build_urlServiceMenu(me.webService);
4554 build_fetchdbmenu(webService);
4555 for (JMenu item : wsmenu)
4557 if (item.getItemCount() == 0)
4559 item.setEnabled(false);
4563 item.setEnabled(true);
4566 } catch (Exception e)
4569 .debug("Exception during web service menu building process.",
4574 } catch (Exception e)
4577 buildingMenu = false;
4584 * construct any groupURL type service menu entries.
4588 private void build_urlServiceMenu(JMenu webService)
4590 // TODO: remove this code when 2.7 is released
4591 // DEBUG - alignmentView
4593 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4594 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4596 * @Override public void actionPerformed(ActionEvent e) {
4597 * jalview.datamodel.AlignmentView
4598 * .testSelectionViews(af.viewport.getAlignment(),
4599 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4601 * }); webService.add(testAlView);
4603 // TODO: refactor to RestClient discoverer and merge menu entries for
4604 // rest-style services with other types of analysis/calculation service
4605 // SHmmr test client - still being implemented.
4606 // DEBUG - alignmentView
4608 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4611 client.attachWSMenuEntry(
4612 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4618 * Searches the alignment sequences for xRefs and builds the Show
4619 * Cross-References menu (formerly called Show Products), with database
4620 * sources for which cross-references are found (protein sources for a
4621 * nucleotide alignment and vice versa)
4623 * @return true if Show Cross-references menu should be enabled
4625 public boolean canShowProducts()
4627 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4628 AlignmentI dataset = viewport.getAlignment().getDataset();
4629 boolean showp = false;
4632 showProducts.removeAll();
4633 final boolean dna = viewport.getAlignment().isNucleotide();
4634 List<String> ptypes = (seqs == null || seqs.length == 0) ? null
4635 : new CrossRef(seqs, dataset)
4636 .findXrefSourcesForSequences(dna);
4638 for (final String source : ptypes)
4641 final AlignFrame af = this;
4642 JMenuItem xtype = new JMenuItem(source);
4643 xtype.addActionListener(new ActionListener()
4646 public void actionPerformed(ActionEvent e)
4648 showProductsFor(af.viewport.getSequenceSelection(), dna, source);
4651 showProducts.add(xtype);
4653 showProducts.setVisible(showp);
4654 showProducts.setEnabled(showp);
4655 } catch (Exception e)
4658 .warn("canShowProducts threw an exception - please report to help@jalview.org",
4666 * Finds and displays cross-references for the selected sequences (protein
4667 * products for nucleotide sequences, dna coding sequences for peptides).
4670 * the sequences to show cross-references for
4672 * true if from a nucleotide alignment (so showing proteins)
4674 * the database to show cross-references for
4676 protected void showProductsFor(final SequenceI[] sel,
4677 final boolean _odna, final String source)
4679 Runnable foo = new Runnable()
4685 final long sttime = System.currentTimeMillis();
4686 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4687 "status.searching_for_sequences_from",
4688 new Object[] { source }), sttime);
4691 AlignmentI alignment = AlignFrame.this.getViewport()
4693 AlignmentI dataset = alignment.getDataset() == null ? alignment
4694 : alignment.getDataset();
4695 boolean dna = alignment.isNucleotide();
4699 .println("Conflict: showProducts for alignment originally "
4701 + (_odna ? "DNA" : "Protein")
4702 + " now searching for "
4703 + (dna ? "DNA" : "Protein") + " Context.");
4705 AlignmentI xrefs = new CrossRef(sel, dataset).findXrefSequences(
4712 * get display scheme (if any) to apply to features
4714 FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
4715 .getFeatureColourScheme(source);
4717 AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset,
4721 xrefsAlignment = AlignmentUtils.makeCdsAlignment(
4722 xrefsAlignment.getSequencesArray(), dataset, sel);
4723 xrefsAlignment.alignAs(alignment);
4727 * If we are opening a splitframe, make a copy of this alignment (sharing the same dataset
4728 * sequences). If we are DNA, drop introns and update mappings
4730 AlignmentI copyAlignment = null;
4732 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4734 boolean copyAlignmentIsAligned = false;
4737 copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset,
4738 xrefsAlignment.getSequencesArray());
4739 if (copyAlignment.getHeight() == 0)
4741 JOptionPane.showMessageDialog(AlignFrame.this,
4742 MessageManager.getString("label.cant_map_cds"),
4743 MessageManager.getString("label.operation_failed"),
4744 JOptionPane.OK_OPTION);
4745 System.err.println("Failed to make CDS alignment");
4749 * pending getting Embl transcripts to 'align',
4750 * we are only doing this for Ensembl
4752 // TODO proper criteria for 'can align as cdna'
4753 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
4754 || AlignmentUtils.looksLikeEnsembl(alignment))
4756 copyAlignment.alignAs(alignment);
4757 copyAlignmentIsAligned = true;
4762 copyAlignment = AlignmentUtils.makeCopyAlignment(sel,
4763 xrefs.getSequencesArray(), dataset);
4765 copyAlignment.setGapCharacter(AlignFrame.this.viewport
4766 .getGapCharacter());
4768 StructureSelectionManager ssm = StructureSelectionManager
4769 .getStructureSelectionManager(Desktop.instance);
4772 * register any new mappings for sequence mouseover etc
4773 * (will not duplicate any previously registered mappings)
4775 ssm.registerMappings(dataset.getCodonFrames());
4777 if (copyAlignment.getHeight() <= 0)
4779 System.err.println("No Sequences generated for xRef type "
4784 * align protein to dna
4786 if (dna && copyAlignmentIsAligned)
4788 xrefsAlignment.alignAs(copyAlignment);
4793 * align cdna to protein - currently only if
4794 * fetching and aligning Ensembl transcripts!
4796 // TODO: generalise for other sources of locus/transcript/cds data
4797 if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source))
4799 copyAlignment.alignAs(xrefsAlignment);
4804 * build AlignFrame(s) according to available alignment data
4806 AlignFrame newFrame = new AlignFrame(xrefsAlignment,
4807 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4808 if (Cache.getDefault("HIDE_INTRONS", true))
4810 newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
4812 String newtitle = String.format("%s %s %s",
4813 dna ? MessageManager.getString("label.proteins")
4814 : MessageManager.getString("label.nucleotides"),
4815 MessageManager.getString("label.for"), getTitle());
4816 newFrame.setTitle(newtitle);
4818 if (copyAlignment == null)
4821 * split frame display is turned off in preferences file
4823 Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
4825 return; // via finally clause
4827 AlignFrame copyThis = new AlignFrame(copyAlignment,
4828 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4829 copyThis.setTitle(AlignFrame.this.getTitle());
4831 boolean showSequenceFeatures = viewport.isShowSequenceFeatures();
4832 newFrame.setShowSeqFeatures(showSequenceFeatures);
4833 copyThis.setShowSeqFeatures(showSequenceFeatures);
4834 FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
4835 .getFeatureRenderer();
4838 * copy feature rendering settings to split frame
4840 newFrame.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
4841 .transferSettings(myFeatureStyling);
4842 copyThis.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
4843 .transferSettings(myFeatureStyling);
4846 * apply 'database source' feature configuration
4849 // TODO is this the feature colouring for the original
4850 // alignment or the fetched xrefs? either could be Ensembl
4851 newFrame.getViewport().applyFeaturesStyle(featureColourScheme);
4852 copyThis.getViewport().applyFeaturesStyle(featureColourScheme);
4854 SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
4855 dna ? newFrame : copyThis);
4856 newFrame.setVisible(true);
4857 copyThis.setVisible(true);
4858 String linkedTitle = MessageManager
4859 .getString("label.linked_view_title");
4860 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4862 } catch (OutOfMemoryError e)
4864 new OOMWarning("whilst fetching crossreferences", e);
4865 } catch (Throwable e)
4867 Cache.log.error("Error when finding crossreferences", e);
4870 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4871 "status.finished_searching_for_sequences_from",
4872 new Object[] { source }), sttime);
4877 * Makes an alignment containing the given sequences, and adds them to the
4878 * given dataset, which is also set as the dataset for the new alignment
4880 * TODO: refactor to DatasetI method
4886 protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
4889 SequenceI[] sprods = new SequenceI[seqs.getHeight()];
4890 for (int s = 0; s < sprods.length; s++)
4892 sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
4893 if (dataset.getSequences() == null
4894 || !dataset.getSequences().contains(
4895 sprods[s].getDatasetSequence()))
4897 dataset.addSequence(sprods[s].getDatasetSequence());
4899 sprods[s].updatePDBIds();
4901 Alignment al = new Alignment(sprods);
4902 al.setDataset(dataset);
4907 Thread frunner = new Thread(foo);
4912 * Construct and display a new frame containing the translation of this
4913 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4916 public void showTranslation_actionPerformed(ActionEvent e)
4918 AlignmentI al = null;
4921 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4923 al = dna.translateCdna();
4924 } catch (Exception ex)
4926 jalview.bin.Cache.log.error(
4927 "Exception during translation. Please report this !", ex);
4928 final String msg = MessageManager
4929 .getString("label.error_when_translating_sequences_submit_bug_report");
4930 final String errorTitle = MessageManager
4931 .getString("label.implementation_error")
4932 + MessageManager.getString("label.translation_failed");
4933 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4934 JOptionPane.ERROR_MESSAGE);
4937 if (al == null || al.getHeight() == 0)
4939 final String msg = MessageManager
4940 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4941 final String errorTitle = MessageManager
4942 .getString("label.translation_failed");
4943 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4944 JOptionPane.WARNING_MESSAGE);
4948 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4949 af.setFileFormat(this.currentFileFormat);
4950 final String newTitle = MessageManager.formatMessage(
4951 "label.translation_of_params",
4952 new Object[] { this.getTitle() });
4953 af.setTitle(newTitle);
4954 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4956 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4957 viewport.openSplitFrame(af, new Alignment(seqs));
4961 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4968 * Set the file format
4972 public void setFileFormat(String fileFormat)
4974 this.currentFileFormat = fileFormat;
4978 * Try to load a features file onto the alignment.
4981 * contents or path to retrieve file
4983 * access mode of file (see jalview.io.AlignFile)
4984 * @return true if features file was parsed correctly.
4986 public boolean parseFeaturesFile(String file, String type)
4988 return avc.parseFeaturesFile(file, type,
4989 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4994 public void refreshFeatureUI(boolean enableIfNecessary)
4996 // note - currently this is only still here rather than in the controller
4997 // because of the featureSettings hard reference that is yet to be
4999 if (enableIfNecessary)
5001 viewport.setShowSequenceFeatures(true);
5002 showSeqFeatures.setSelected(true);
5008 public void dragEnter(DropTargetDragEvent evt)
5013 public void dragExit(DropTargetEvent evt)
5018 public void dragOver(DropTargetDragEvent evt)
5023 public void dropActionChanged(DropTargetDragEvent evt)
5028 public void drop(DropTargetDropEvent evt)
5030 Transferable t = evt.getTransferable();
5031 java.util.List<String> files = new ArrayList<String>(), protocols = new ArrayList<String>();
5035 Desktop.transferFromDropTarget(files, protocols, evt, t);
5036 } catch (Exception e)
5038 e.printStackTrace();
5044 // check to see if any of these files have names matching sequences in
5046 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5047 .getAlignment().getSequencesArray());
5049 * Object[] { String,SequenceI}
5051 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5052 ArrayList<String> filesnotmatched = new ArrayList<String>();
5053 for (int i = 0; i < files.size(); i++)
5055 String file = files.get(i).toString();
5057 String protocol = FormatAdapter.checkProtocol(file);
5058 if (protocol == jalview.io.FormatAdapter.FILE)
5060 File fl = new File(file);
5061 pdbfn = fl.getName();
5063 else if (protocol == jalview.io.FormatAdapter.URL)
5065 URL url = new URL(file);
5066 pdbfn = url.getFile();
5068 if (pdbfn.length() > 0)
5070 // attempt to find a match in the alignment
5071 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5072 int l = 0, c = pdbfn.indexOf(".");
5073 while (mtch == null && c != -1)
5078 } while ((c = pdbfn.indexOf(".", l)) > l);
5081 pdbfn = pdbfn.substring(0, l);
5083 mtch = idm.findAllIdMatches(pdbfn);
5090 type = new IdentifyFile().identify(file, protocol);
5091 } catch (Exception ex)
5097 if (type.equalsIgnoreCase("PDB"))
5099 filesmatched.add(new Object[] { file, protocol, mtch });
5104 // File wasn't named like one of the sequences or wasn't a PDB file.
5105 filesnotmatched.add(file);
5109 if (filesmatched.size() > 0)
5111 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5117 "label.automatically_associate_pdb_files_with_sequences_same_name",
5118 new Object[] { Integer
5124 .getString("label.automatically_associate_pdb_files_by_name"),
5125 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5128 for (Object[] fm : filesmatched)
5130 // try and associate
5131 // TODO: may want to set a standard ID naming formalism for
5132 // associating PDB files which have no IDs.
5133 for (SequenceI toassoc : (SequenceI[]) fm[2])
5135 PDBEntry pe = new AssociatePdbFileWithSeq()
5136 .associatePdbWithSeq((String) fm[0],
5137 (String) fm[1], toassoc, false,
5141 System.err.println("Associated file : "
5142 + ((String) fm[0]) + " with "
5143 + toassoc.getDisplayId(true));
5147 alignPanel.paintAlignment(true);
5151 if (filesnotmatched.size() > 0)
5154 && (Cache.getDefault(
5155 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5161 "label.ignore_unmatched_dropped_files_info",
5162 new Object[] { Integer
5169 .getString("label.ignore_unmatched_dropped_files"),
5170 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5174 for (String fn : filesnotmatched)
5176 loadJalviewDataFile(fn, null, null, null);
5180 } catch (Exception ex)
5182 ex.printStackTrace();
5188 * Attempt to load a "dropped" file or URL string: First by testing whether
5189 * it's an Annotation file, then a JNet file, and finally a features file. If
5190 * all are false then the user may have dropped an alignment file onto this
5194 * either a filename or a URL string.
5196 public void loadJalviewDataFile(String file, String protocol,
5197 String format, SequenceI assocSeq)
5201 if (protocol == null)
5203 protocol = FormatAdapter.checkProtocol(file);
5205 // if the file isn't identified, or not positively identified as some
5206 // other filetype (PFAM is default unidentified alignment file type) then
5207 // try to parse as annotation.
5208 boolean isAnnotation = (format == null || format
5209 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5210 .annotateAlignmentView(viewport, file, protocol) : false;
5214 // first see if its a T-COFFEE score file
5215 TCoffeeScoreFile tcf = null;
5218 tcf = new TCoffeeScoreFile(file, protocol);
5221 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5223 tcoffeeColour.setEnabled(true);
5224 tcoffeeColour.setSelected(true);
5225 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5226 isAnnotation = true;
5228 .setText(MessageManager
5229 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5233 // some problem - if no warning its probable that the ID matching
5234 // process didn't work
5238 tcf.getWarningMessage() == null ? MessageManager
5239 .getString("label.check_file_matches_sequence_ids_alignment")
5240 : tcf.getWarningMessage(),
5242 .getString("label.problem_reading_tcoffee_score_file"),
5243 JOptionPane.WARNING_MESSAGE);
5250 } catch (Exception x)
5253 .debug("Exception when processing data source as T-COFFEE score file",
5259 // try to see if its a JNet 'concise' style annotation file *before*
5261 // try to parse it as a features file
5264 format = new IdentifyFile().identify(file, protocol);
5266 if (format.equalsIgnoreCase("JnetFile"))
5268 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5270 new JnetAnnotationMaker();
5271 JnetAnnotationMaker.add_annotation(predictions,
5272 viewport.getAlignment(), 0, false);
5273 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5274 viewport.getAlignment().setSeqrep(repseq);
5275 ColumnSelection cs = new ColumnSelection();
5276 cs.hideInsertionsFor(repseq);
5277 viewport.setColumnSelection(cs);
5278 isAnnotation = true;
5280 else if (IdentifyFile.FeaturesFile.equals(format))
5282 if (parseFeaturesFile(file, protocol))
5284 alignPanel.paintAlignment(true);
5289 new FileLoader().LoadFile(viewport, file, protocol, format);
5296 alignPanel.adjustAnnotationHeight();
5297 viewport.updateSequenceIdColours();
5298 buildSortByAnnotationScoresMenu();
5299 alignPanel.paintAlignment(true);
5301 } catch (Exception ex)
5303 ex.printStackTrace();
5304 } catch (OutOfMemoryError oom)
5309 } catch (Exception x)
5314 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5315 : "using " + protocol + " from " + file)
5317 + (format != null ? "(parsing as '" + format
5318 + "' file)" : ""), oom, Desktop.desktop);
5323 * Method invoked by the ChangeListener on the tabbed pane, in other words
5324 * when a different tabbed pane is selected by the user or programmatically.
5327 public void tabSelectionChanged(int index)
5331 alignPanel = alignPanels.get(index);
5332 viewport = alignPanel.av;
5333 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5334 setMenusFromViewport(viewport);
5338 * If there is a frame linked to this one in a SplitPane, switch it to the
5339 * same view tab index. No infinite recursion of calls should happen, since
5340 * tabSelectionChanged() should not get invoked on setting the selected
5341 * index to an unchanged value. Guard against setting an invalid index
5342 * before the new view peer tab has been created.
5344 final AlignViewportI peer = viewport.getCodingComplement();
5347 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5348 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5350 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5356 * On right mouse click on view tab, prompt for and set new view name.
5359 public void tabbedPane_mousePressed(MouseEvent e)
5361 if (e.isPopupTrigger())
5363 String msg = MessageManager.getString("label.enter_view_name");
5364 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5365 JOptionPane.QUESTION_MESSAGE);
5369 viewport.viewName = reply;
5370 // TODO warn if reply is in getExistingViewNames()?
5371 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5376 public AlignViewport getCurrentView()
5382 * Open the dialog for regex description parsing.
5385 protected void extractScores_actionPerformed(ActionEvent e)
5387 ParseProperties pp = new jalview.analysis.ParseProperties(
5388 viewport.getAlignment());
5389 // TODO: verify regex and introduce GUI dialog for version 2.5
5390 // if (pp.getScoresFromDescription("col", "score column ",
5391 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5393 if (pp.getScoresFromDescription("description column",
5394 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5396 buildSortByAnnotationScoresMenu();
5404 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5408 protected void showDbRefs_actionPerformed(ActionEvent e)
5410 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5416 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5420 protected void showNpFeats_actionPerformed(ActionEvent e)
5422 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5426 * find the viewport amongst the tabs in this alignment frame and close that
5431 public boolean closeView(AlignViewportI av)
5435 this.closeMenuItem_actionPerformed(false);
5438 Component[] comp = tabbedPane.getComponents();
5439 for (int i = 0; comp != null && i < comp.length; i++)
5441 if (comp[i] instanceof AlignmentPanel)
5443 if (((AlignmentPanel) comp[i]).av == av)
5446 closeView((AlignmentPanel) comp[i]);
5454 protected void build_fetchdbmenu(JMenu webService)
5456 // Temporary hack - DBRef Fetcher always top level ws entry.
5457 // TODO We probably want to store a sequence database checklist in
5458 // preferences and have checkboxes.. rather than individual sources selected
5460 final JMenu rfetch = new JMenu(
5461 MessageManager.getString("action.fetch_db_references"));
5462 rfetch.setToolTipText(MessageManager
5463 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5464 webService.add(rfetch);
5466 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5467 MessageManager.getString("option.trim_retrieved_seqs"));
5468 trimrs.setToolTipText(MessageManager
5469 .getString("label.trim_retrieved_sequences"));
5470 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5471 trimrs.addActionListener(new ActionListener()
5474 public void actionPerformed(ActionEvent e)
5476 trimrs.setSelected(trimrs.isSelected());
5477 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5478 Boolean.valueOf(trimrs.isSelected()).toString());
5482 JMenuItem fetchr = new JMenuItem(
5483 MessageManager.getString("label.standard_databases"));
5484 fetchr.setToolTipText(MessageManager
5485 .getString("label.fetch_embl_uniprot"));
5486 fetchr.addActionListener(new ActionListener()
5490 public void actionPerformed(ActionEvent e)
5492 new Thread(new Runnable()
5497 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5498 .getAlignment().isNucleotide();
5499 DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
5500 .getSequenceSelection(), alignPanel.alignFrame, null,
5501 alignPanel.alignFrame.featureSettings, isNucleotide);
5502 dbRefFetcher.addListener(new FetchFinishedListenerI()
5505 public void finished()
5507 AlignFrame.this.setMenusForViewport();
5510 dbRefFetcher.fetchDBRefs(false);
5518 final AlignFrame me = this;
5519 new Thread(new Runnable()
5524 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5525 .getSequenceFetcherSingleton(me);
5526 javax.swing.SwingUtilities.invokeLater(new Runnable()
5531 String[] dbclasses = sf.getOrderedSupportedSources();
5532 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5533 // jalview.util.QuickSort.sort(otherdb, otherdb);
5534 List<DbSourceProxy> otherdb;
5535 JMenu dfetch = new JMenu();
5536 JMenu ifetch = new JMenu();
5537 JMenuItem fetchr = null;
5538 int comp = 0, icomp = 0, mcomp = 15;
5539 String mname = null;
5541 for (String dbclass : dbclasses)
5543 otherdb = sf.getSourceProxy(dbclass);
5544 // add a single entry for this class, or submenu allowing 'fetch
5546 if (otherdb == null || otherdb.size() < 1)
5550 // List<DbSourceProxy> dbs=otherdb;
5551 // otherdb=new ArrayList<DbSourceProxy>();
5552 // for (DbSourceProxy db:dbs)
5554 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5558 mname = "From " + dbclass;
5560 if (otherdb.size() == 1)
5562 final DbSourceProxy[] dassource = otherdb
5563 .toArray(new DbSourceProxy[0]);
5564 DbSourceProxy src = otherdb.get(0);
5565 fetchr = new JMenuItem(src.getDbSource());
5566 fetchr.addActionListener(new ActionListener()
5570 public void actionPerformed(ActionEvent e)
5572 new Thread(new Runnable()
5578 boolean isNucleotide = alignPanel.alignFrame
5579 .getViewport().getAlignment()
5581 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5582 alignPanel.av.getSequenceSelection(),
5583 alignPanel.alignFrame, dassource,
5584 alignPanel.alignFrame.featureSettings,
5587 .addListener(new FetchFinishedListenerI()
5590 public void finished()
5592 AlignFrame.this.setMenusForViewport();
5595 dbRefFetcher.fetchDBRefs(false);
5601 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5602 MessageManager.formatMessage(
5603 "label.fetch_retrieve_from",
5604 new Object[] { src.getDbName() })));
5610 final DbSourceProxy[] dassource = otherdb
5611 .toArray(new DbSourceProxy[0]);
5613 DbSourceProxy src = otherdb.get(0);
5614 fetchr = new JMenuItem(MessageManager.formatMessage(
5615 "label.fetch_all_param",
5616 new Object[] { src.getDbSource() }));
5617 fetchr.addActionListener(new ActionListener()
5620 public void actionPerformed(ActionEvent e)
5622 new Thread(new Runnable()
5628 boolean isNucleotide = alignPanel.alignFrame
5629 .getViewport().getAlignment()
5631 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5632 alignPanel.av.getSequenceSelection(),
5633 alignPanel.alignFrame, dassource,
5634 alignPanel.alignFrame.featureSettings,
5637 .addListener(new FetchFinishedListenerI()
5640 public void finished()
5642 AlignFrame.this.setMenusForViewport();
5645 dbRefFetcher.fetchDBRefs(false);
5651 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5652 MessageManager.formatMessage(
5653 "label.fetch_retrieve_from_all_sources",
5655 Integer.valueOf(otherdb.size())
5656 .toString(), src.getDbSource(),
5657 src.getDbName() })));
5660 // and then build the rest of the individual menus
5661 ifetch = new JMenu(MessageManager.formatMessage(
5662 "label.source_from_db_source",
5663 new Object[] { src.getDbSource() }));
5665 String imname = null;
5667 for (DbSourceProxy sproxy : otherdb)
5669 String dbname = sproxy.getDbName();
5670 String sname = dbname.length() > 5 ? dbname.substring(0,
5671 5) + "..." : dbname;
5672 String msname = dbname.length() > 10 ? dbname.substring(
5673 0, 10) + "..." : dbname;
5676 imname = MessageManager.formatMessage(
5677 "label.from_msname", new Object[] { sname });
5679 fetchr = new JMenuItem(msname);
5680 final DbSourceProxy[] dassrc = { sproxy };
5681 fetchr.addActionListener(new ActionListener()
5685 public void actionPerformed(ActionEvent e)
5687 new Thread(new Runnable()
5693 boolean isNucleotide = alignPanel.alignFrame
5694 .getViewport().getAlignment()
5696 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5697 alignPanel.av.getSequenceSelection(),
5698 alignPanel.alignFrame, dassrc,
5699 alignPanel.alignFrame.featureSettings,
5702 .addListener(new FetchFinishedListenerI()
5705 public void finished()
5707 AlignFrame.this.setMenusForViewport();
5710 dbRefFetcher.fetchDBRefs(false);
5716 fetchr.setToolTipText("<html>"
5717 + MessageManager.formatMessage(
5718 "label.fetch_retrieve_from", new Object[]
5722 if (++icomp >= mcomp || i == (otherdb.size()))
5724 ifetch.setText(MessageManager.formatMessage(
5725 "label.source_to_target", imname, sname));
5727 ifetch = new JMenu();
5735 if (comp >= mcomp || dbi >= (dbclasses.length))
5737 dfetch.setText(MessageManager.formatMessage(
5738 "label.source_to_target", mname, dbclass));
5740 dfetch = new JMenu();
5753 * Left justify the whole alignment.
5756 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5758 AlignmentI al = viewport.getAlignment();
5760 viewport.firePropertyChange("alignment", null, al);
5764 * Right justify the whole alignment.
5767 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5769 AlignmentI al = viewport.getAlignment();
5771 viewport.firePropertyChange("alignment", null, al);
5775 public void setShowSeqFeatures(boolean b)
5777 showSeqFeatures.setSelected(b);
5778 viewport.setShowSequenceFeatures(b);
5785 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5786 * awt.event.ActionEvent)
5789 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5791 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5792 alignPanel.paintAlignment(true);
5799 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5803 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5805 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5806 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5814 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5815 * .event.ActionEvent)
5818 protected void showGroupConservation_actionPerformed(ActionEvent e)
5820 viewport.setShowGroupConservation(showGroupConservation.getState());
5821 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5828 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5829 * .event.ActionEvent)
5832 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5834 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5835 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5842 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5843 * .event.ActionEvent)
5846 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5848 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5849 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5853 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5855 showSequenceLogo.setState(true);
5856 viewport.setShowSequenceLogo(true);
5857 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5858 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5862 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5864 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5871 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5872 * .event.ActionEvent)
5875 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5877 if (avc.makeGroupsFromSelection())
5879 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5880 alignPanel.updateAnnotation();
5881 alignPanel.paintAlignment(true);
5885 public void clearAlignmentSeqRep()
5887 // TODO refactor alignmentseqrep to controller
5888 if (viewport.getAlignment().hasSeqrep())
5890 viewport.getAlignment().setSeqrep(null);
5891 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5892 alignPanel.updateAnnotation();
5893 alignPanel.paintAlignment(true);
5898 protected void createGroup_actionPerformed(ActionEvent e)
5900 if (avc.createGroup())
5902 alignPanel.alignmentChanged();
5907 protected void unGroup_actionPerformed(ActionEvent e)
5911 alignPanel.alignmentChanged();
5916 * make the given alignmentPanel the currently selected tab
5918 * @param alignmentPanel
5920 public void setDisplayedView(AlignmentPanel alignmentPanel)
5922 if (!viewport.getSequenceSetId().equals(
5923 alignmentPanel.av.getSequenceSetId()))
5927 .getString("error.implementation_error_cannot_show_view_alignment_frame"));
5929 if (tabbedPane != null
5930 && tabbedPane.getTabCount() > 0
5931 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5932 .getSelectedIndex())
5934 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5939 * Action on selection of menu options to Show or Hide annotations.
5942 * @param forSequences
5943 * update sequence-related annotations
5944 * @param forAlignment
5945 * update non-sequence-related annotations
5948 protected void setAnnotationsVisibility(boolean visible,
5949 boolean forSequences, boolean forAlignment)
5951 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5952 .getAlignmentAnnotation();
5957 for (AlignmentAnnotation aa : anns)
5960 * don't display non-positional annotations on an alignment
5962 if (aa.annotations == null)
5966 boolean apply = (aa.sequenceRef == null && forAlignment)
5967 || (aa.sequenceRef != null && forSequences);
5970 aa.visible = visible;
5973 alignPanel.validateAnnotationDimensions(true);
5974 alignPanel.alignmentChanged();
5978 * Store selected annotation sort order for the view and repaint.
5981 protected void sortAnnotations_actionPerformed()
5983 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5985 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5986 alignPanel.paintAlignment(true);
5991 * @return alignment panels in this alignment frame
5993 public List<? extends AlignmentViewPanel> getAlignPanels()
5995 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5999 * Open a new alignment window, with the cDNA associated with this (protein)
6000 * alignment, aligned as is the protein.
6002 protected void viewAsCdna_actionPerformed()
6004 // TODO no longer a menu action - refactor as required
6005 final AlignmentI alignment = getViewport().getAlignment();
6006 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6007 if (mappings == null)
6011 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6012 for (SequenceI aaSeq : alignment.getSequences())
6014 for (AlignedCodonFrame acf : mappings)
6016 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6020 * There is a cDNA mapping for this protein sequence - add to new
6021 * alignment. It will share the same dataset sequence as other mapped
6022 * cDNA (no new mappings need to be created).
6024 final Sequence newSeq = new Sequence(dnaSeq);
6025 newSeq.setDatasetSequence(dnaSeq);
6026 cdnaSeqs.add(newSeq);
6030 if (cdnaSeqs.size() == 0)
6032 // show a warning dialog no mapped cDNA
6035 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6037 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6038 AlignFrame.DEFAULT_HEIGHT);
6039 cdna.alignAs(alignment);
6040 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6042 Desktop.addInternalFrame(alignFrame, newtitle,
6043 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
6047 * Set visibility of dna/protein complement view (available when shown in a
6053 protected void showComplement_actionPerformed(boolean show)
6055 SplitContainerI sf = getSplitViewContainer();
6058 sf.setComplementVisible(this, show);
6063 * Generate the reverse (optionally complemented) of the selected sequences,
6064 * and add them to the alignment
6067 protected void showReverse_actionPerformed(boolean complement)
6069 AlignmentI al = null;
6072 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
6073 al = dna.reverseCdna(complement);
6074 viewport.addAlignment(al, "");
6075 addHistoryItem(new EditCommand(
6076 MessageManager.getString("label.add_sequences"),
6077 Action.PASTE, al.getSequencesArray(), 0, al.getWidth(),
6078 viewport.getAlignment()));
6079 } catch (Exception ex)
6081 System.err.println(ex.getMessage());
6087 * Try to run a script in the Groovy console, having first ensured that this
6088 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
6089 * be targeted at this alignment.
6092 protected void runGroovy_actionPerformed()
6094 Jalview.setCurrentAlignFrame(this);
6095 groovy.ui.Console console = Desktop.getGroovyConsole();
6096 if (console != null)
6100 console.runScript();
6101 } catch (Exception ex)
6103 System.err.println((ex.toString()));
6105 .showInternalMessageDialog(Desktop.desktop, MessageManager
6106 .getString("label.couldnt_run_groovy_script"),
6108 .getString("label.groovy_support_failed"),
6109 JOptionPane.ERROR_MESSAGE);
6114 System.err.println("Can't run Groovy script as console not found");
6119 * Hides columns containing (or not containing) a specified feature, provided
6120 * that would not leave all columns hidden
6122 * @param featureType
6123 * @param columnsContaining
6126 public boolean hideFeatureColumns(String featureType,
6127 boolean columnsContaining)
6129 boolean notForHiding = avc.markColumnsContainingFeatures(
6130 columnsContaining, false, false, featureType);
6133 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
6134 false, featureType))
6136 getViewport().hideSelectedColumns();
6144 class PrintThread extends Thread
6148 public PrintThread(AlignmentPanel ap)
6153 static PageFormat pf;
6158 PrinterJob printJob = PrinterJob.getPrinterJob();
6162 printJob.setPrintable(ap, pf);
6166 printJob.setPrintable(ap);
6169 if (printJob.printDialog())
6174 } catch (Exception PrintException)
6176 PrintException.printStackTrace();