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.DataSourceType;
69 import jalview.io.FileFormat;
70 import jalview.io.FileFormatI;
71 import jalview.io.FileLoader;
72 import jalview.io.FormatAdapter;
73 import jalview.io.HtmlSvgOutput;
74 import jalview.io.IdentifyFile;
75 import jalview.io.JPredFile;
76 import jalview.io.JalviewFileChooser;
77 import jalview.io.JalviewFileView;
78 import jalview.io.JnetAnnotationMaker;
79 import jalview.io.NewickFile;
80 import jalview.io.TCoffeeScoreFile;
81 import jalview.io.gff.SequenceOntologyI;
82 import jalview.jbgui.GAlignFrame;
83 import jalview.schemes.Blosum62ColourScheme;
84 import jalview.schemes.BuriedColourScheme;
85 import jalview.schemes.ClustalxColourScheme;
86 import jalview.schemes.ColourSchemeI;
87 import jalview.schemes.ColourSchemeProperty;
88 import jalview.schemes.HelixColourScheme;
89 import jalview.schemes.HydrophobicColourScheme;
90 import jalview.schemes.NucleotideColourScheme;
91 import jalview.schemes.PIDColourScheme;
92 import jalview.schemes.PurinePyrimidineColourScheme;
93 import jalview.schemes.RNAHelicesColourChooser;
94 import jalview.schemes.ResidueProperties;
95 import jalview.schemes.StrandColourScheme;
96 import jalview.schemes.TCoffeeColourScheme;
97 import jalview.schemes.TaylorColourScheme;
98 import jalview.schemes.TurnColourScheme;
99 import jalview.schemes.UserColourScheme;
100 import jalview.schemes.ZappoColourScheme;
101 import jalview.structure.StructureSelectionManager;
102 import jalview.util.MessageManager;
103 import jalview.viewmodel.AlignmentViewport;
104 import jalview.ws.DBRefFetcher;
105 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
106 import jalview.ws.SequenceFetcher;
107 import jalview.ws.jws1.Discoverer;
108 import jalview.ws.jws2.Jws2Discoverer;
109 import jalview.ws.jws2.jabaws2.Jws2Instance;
110 import jalview.ws.seqfetcher.DbSourceProxy;
112 import java.awt.BorderLayout;
113 import java.awt.Component;
114 import java.awt.Rectangle;
115 import java.awt.Toolkit;
116 import java.awt.datatransfer.Clipboard;
117 import java.awt.datatransfer.DataFlavor;
118 import java.awt.datatransfer.StringSelection;
119 import java.awt.datatransfer.Transferable;
120 import java.awt.dnd.DropTargetDragEvent;
121 import java.awt.dnd.DropTargetDropEvent;
122 import java.awt.dnd.DropTargetEvent;
123 import java.awt.dnd.DropTargetListener;
124 import java.awt.event.ActionEvent;
125 import java.awt.event.ActionListener;
126 import java.awt.event.FocusAdapter;
127 import java.awt.event.FocusEvent;
128 import java.awt.event.ItemEvent;
129 import java.awt.event.ItemListener;
130 import java.awt.event.KeyAdapter;
131 import java.awt.event.KeyEvent;
132 import java.awt.event.MouseAdapter;
133 import java.awt.event.MouseEvent;
134 import java.awt.print.PageFormat;
135 import java.awt.print.PrinterJob;
136 import java.beans.PropertyChangeEvent;
139 import java.util.ArrayList;
140 import java.util.Arrays;
141 import java.util.Deque;
142 import java.util.Enumeration;
143 import java.util.Hashtable;
144 import java.util.List;
145 import java.util.Vector;
147 import javax.swing.JCheckBoxMenuItem;
148 import javax.swing.JEditorPane;
149 import javax.swing.JInternalFrame;
150 import javax.swing.JLayeredPane;
151 import javax.swing.JMenu;
152 import javax.swing.JMenuItem;
153 import javax.swing.JOptionPane;
154 import javax.swing.JRadioButtonMenuItem;
155 import javax.swing.JScrollPane;
156 import javax.swing.SwingUtilities;
162 * @version $Revision$
164 public class AlignFrame extends GAlignFrame implements DropTargetListener,
165 IProgressIndicator, AlignViewControllerGuiI
168 public static final int DEFAULT_WIDTH = 700;
170 public static final int DEFAULT_HEIGHT = 500;
173 * The currently displayed panel (selected tabbed view if more than one)
175 public AlignmentPanel alignPanel;
177 AlignViewport viewport;
179 public AlignViewControllerI avc;
181 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
184 * Last format used to load or save alignments in this window
186 FileFormatI currentFileFormat = null;
189 * Current filename for this alignment
191 String fileName = null;
194 * Creates a new AlignFrame object with specific width and height.
200 public AlignFrame(AlignmentI al, int width, int height)
202 this(al, null, width, height);
206 * Creates a new AlignFrame object with specific width, height and
212 * @param sequenceSetId
214 public AlignFrame(AlignmentI al, int width, int height,
215 String sequenceSetId)
217 this(al, null, width, height, sequenceSetId);
221 * Creates a new AlignFrame object with specific width, height and
227 * @param sequenceSetId
230 public AlignFrame(AlignmentI al, int width, int height,
231 String sequenceSetId, String viewId)
233 this(al, null, width, height, sequenceSetId, viewId);
237 * new alignment window with hidden columns
241 * @param hiddenColumns
242 * ColumnSelection or null
244 * Width of alignment frame
248 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
249 int width, int height)
251 this(al, hiddenColumns, width, height, null);
255 * Create alignment frame for al with hiddenColumns, a specific width and
256 * height, and specific sequenceId
259 * @param hiddenColumns
262 * @param sequenceSetId
265 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
266 int width, int height, String sequenceSetId)
268 this(al, hiddenColumns, width, height, sequenceSetId, null);
272 * Create alignment frame for al with hiddenColumns, a specific width and
273 * height, and specific sequenceId
276 * @param hiddenColumns
279 * @param sequenceSetId
284 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
285 int width, int height, String sequenceSetId, String viewId)
287 setSize(width, height);
289 if (al.getDataset() == null)
294 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
296 alignPanel = new AlignmentPanel(this, viewport);
298 addAlignmentPanel(alignPanel, true);
302 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
303 ColumnSelection hiddenColumns, int width, int height)
305 setSize(width, height);
307 if (al.getDataset() == null)
312 viewport = new AlignViewport(al, hiddenColumns);
314 if (hiddenSeqs != null && hiddenSeqs.length > 0)
316 viewport.hideSequence(hiddenSeqs);
318 alignPanel = new AlignmentPanel(this, viewport);
319 addAlignmentPanel(alignPanel, true);
324 * Make a new AlignFrame from existing alignmentPanels
331 public AlignFrame(AlignmentPanel ap)
335 addAlignmentPanel(ap, false);
340 * initalise the alignframe from the underlying viewport data and the
345 if (!Jalview.isHeadlessMode())
347 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
350 avc = new jalview.controller.AlignViewController(this, viewport,
352 if (viewport.getAlignmentConservationAnnotation() == null)
354 BLOSUM62Colour.setEnabled(false);
355 conservationMenuItem.setEnabled(false);
356 modifyConservation.setEnabled(false);
357 // PIDColour.setEnabled(false);
358 // abovePIDThreshold.setEnabled(false);
359 // modifyPID.setEnabled(false);
362 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
365 if (sortby.equals("Id"))
367 sortIDMenuItem_actionPerformed(null);
369 else if (sortby.equals("Pairwise Identity"))
371 sortPairwiseMenuItem_actionPerformed(null);
374 if (Desktop.desktop != null)
376 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
377 addServiceListeners();
378 setGUINucleotide(viewport.getAlignment().isNucleotide());
382 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
384 setMenusFromViewport(viewport);
385 buildSortByAnnotationScoresMenu();
388 if (viewport.getWrapAlignment())
390 wrapMenuItem_actionPerformed(null);
393 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
395 this.overviewMenuItem_actionPerformed(null);
400 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
401 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
402 final String menuLabel = MessageManager
403 .getString("label.copy_format_from");
404 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
405 new ViewSetProvider()
409 public AlignmentPanel[] getAllAlignmentPanels()
412 origview.add(alignPanel);
413 // make an array of all alignment panels except for this one
414 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
415 Arrays.asList(Desktop.getAlignmentPanels(null)));
416 aps.remove(AlignFrame.this.alignPanel);
417 return aps.toArray(new AlignmentPanel[aps.size()]);
419 }, selviews, new ItemListener()
423 public void itemStateChanged(ItemEvent e)
425 if (origview.size() > 0)
427 final AlignmentPanel ap = origview.get(0);
430 * Copy the ViewStyle of the selected panel to 'this one'.
431 * Don't change value of 'scaleProteinAsCdna' unless copying
434 ViewStyleI vs = selviews.get(0).getAlignViewport()
436 boolean fromSplitFrame = selviews.get(0)
437 .getAlignViewport().getCodingComplement() != null;
440 vs.setScaleProteinAsCdna(ap.getAlignViewport()
441 .getViewStyle().isScaleProteinAsCdna());
443 ap.getAlignViewport().setViewStyle(vs);
446 * Also rescale ViewStyle of SplitFrame complement if there is
447 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
448 * the whole ViewStyle (allow cDNA protein to have different
451 AlignViewportI complement = ap.getAlignViewport()
452 .getCodingComplement();
453 if (complement != null && vs.isScaleProteinAsCdna())
455 AlignFrame af = Desktop.getAlignFrameFor(complement);
456 ((SplitFrame) af.getSplitViewContainer())
458 af.setMenusForViewport();
462 ap.setSelected(true);
463 ap.alignFrame.setMenusForViewport();
468 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
469 .indexOf("devel") > -1
470 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
471 .indexOf("test") > -1)
473 formatMenu.add(vsel);
475 addFocusListener(new FocusAdapter()
478 public void focusGained(FocusEvent e)
480 Jalview.setCurrentAlignFrame(AlignFrame.this);
487 * Change the filename and format for the alignment, and enable the 'reload'
488 * button functionality.
495 public void setFileName(String file, FileFormatI format)
498 setFileFormat(format);
499 reload.setEnabled(true);
503 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
506 void addKeyListener()
508 addKeyListener(new KeyAdapter()
511 public void keyPressed(KeyEvent evt)
513 if (viewport.cursorMode
514 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
515 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
516 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
517 && Character.isDigit(evt.getKeyChar()))
519 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
522 switch (evt.getKeyCode())
525 case 27: // escape key
526 deselectAllSequenceMenuItem_actionPerformed(null);
530 case KeyEvent.VK_DOWN:
531 if (evt.isAltDown() || !viewport.cursorMode)
533 moveSelectedSequences(false);
535 if (viewport.cursorMode)
537 alignPanel.getSeqPanel().moveCursor(0, 1);
542 if (evt.isAltDown() || !viewport.cursorMode)
544 moveSelectedSequences(true);
546 if (viewport.cursorMode)
548 alignPanel.getSeqPanel().moveCursor(0, -1);
553 case KeyEvent.VK_LEFT:
554 if (evt.isAltDown() || !viewport.cursorMode)
556 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
560 alignPanel.getSeqPanel().moveCursor(-1, 0);
565 case KeyEvent.VK_RIGHT:
566 if (evt.isAltDown() || !viewport.cursorMode)
568 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
572 alignPanel.getSeqPanel().moveCursor(1, 0);
576 case KeyEvent.VK_SPACE:
577 if (viewport.cursorMode)
579 alignPanel.getSeqPanel().insertGapAtCursor(
580 evt.isControlDown() || evt.isShiftDown()
585 // case KeyEvent.VK_A:
586 // if (viewport.cursorMode)
588 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
589 // //System.out.println("A");
593 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
594 * System.out.println("closing bracket"); } break;
596 case KeyEvent.VK_DELETE:
597 case KeyEvent.VK_BACK_SPACE:
598 if (!viewport.cursorMode)
600 cut_actionPerformed(null);
604 alignPanel.getSeqPanel().deleteGapAtCursor(
605 evt.isControlDown() || evt.isShiftDown()
612 if (viewport.cursorMode)
614 alignPanel.getSeqPanel().setCursorRow();
618 if (viewport.cursorMode && !evt.isControlDown())
620 alignPanel.getSeqPanel().setCursorColumn();
624 if (viewport.cursorMode)
626 alignPanel.getSeqPanel().setCursorPosition();
630 case KeyEvent.VK_ENTER:
631 case KeyEvent.VK_COMMA:
632 if (viewport.cursorMode)
634 alignPanel.getSeqPanel().setCursorRowAndColumn();
639 if (viewport.cursorMode)
641 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
645 if (viewport.cursorMode)
647 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
652 viewport.cursorMode = !viewport.cursorMode;
653 statusBar.setText(MessageManager.formatMessage(
654 "label.keyboard_editing_mode",
655 new String[] { (viewport.cursorMode ? "on" : "off") }));
656 if (viewport.cursorMode)
658 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
659 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
661 alignPanel.getSeqPanel().seqCanvas.repaint();
667 Help.showHelpWindow();
668 } catch (Exception ex)
670 ex.printStackTrace();
675 boolean toggleSeqs = !evt.isControlDown();
676 boolean toggleCols = !evt.isShiftDown();
677 toggleHiddenRegions(toggleSeqs, toggleCols);
680 case KeyEvent.VK_PAGE_UP:
681 if (viewport.getWrapAlignment())
683 alignPanel.scrollUp(true);
687 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
688 - viewport.endSeq + viewport.startSeq);
691 case KeyEvent.VK_PAGE_DOWN:
692 if (viewport.getWrapAlignment())
694 alignPanel.scrollUp(false);
698 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
699 + viewport.endSeq - viewport.startSeq);
706 public void keyReleased(KeyEvent evt)
708 switch (evt.getKeyCode())
710 case KeyEvent.VK_LEFT:
711 if (evt.isAltDown() || !viewport.cursorMode)
713 viewport.firePropertyChange("alignment", null, viewport
714 .getAlignment().getSequences());
718 case KeyEvent.VK_RIGHT:
719 if (evt.isAltDown() || !viewport.cursorMode)
721 viewport.firePropertyChange("alignment", null, viewport
722 .getAlignment().getSequences());
730 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
732 ap.alignFrame = this;
733 avc = new jalview.controller.AlignViewController(this, viewport,
738 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
740 int aSize = alignPanels.size();
742 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
744 if (aSize == 1 && ap.av.viewName == null)
746 this.getContentPane().add(ap, BorderLayout.CENTER);
752 setInitialTabVisible();
755 expandViews.setEnabled(true);
756 gatherViews.setEnabled(true);
757 tabbedPane.addTab(ap.av.viewName, ap);
759 ap.setVisible(false);
764 if (ap.av.isPadGaps())
766 ap.av.getAlignment().padGaps();
768 ap.av.updateConservation(ap);
769 ap.av.updateConsensus(ap);
770 ap.av.updateStrucConsensus(ap);
774 public void setInitialTabVisible()
776 expandViews.setEnabled(true);
777 gatherViews.setEnabled(true);
778 tabbedPane.setVisible(true);
779 AlignmentPanel first = alignPanels.get(0);
780 tabbedPane.addTab(first.av.viewName, first);
781 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
784 public AlignViewport getViewport()
789 /* Set up intrinsic listeners for dynamically generated GUI bits. */
790 private void addServiceListeners()
792 final java.beans.PropertyChangeListener thisListener;
793 Desktop.instance.addJalviewPropertyChangeListener("services",
794 thisListener = new java.beans.PropertyChangeListener()
797 public void propertyChange(PropertyChangeEvent evt)
799 // // System.out.println("Discoverer property change.");
800 // if (evt.getPropertyName().equals("services"))
802 SwingUtilities.invokeLater(new Runnable()
809 .println("Rebuild WS Menu for service change");
810 BuildWebServiceMenu();
817 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
820 public void internalFrameClosed(
821 javax.swing.event.InternalFrameEvent evt)
823 // System.out.println("deregistering discoverer listener");
824 Desktop.instance.removeJalviewPropertyChangeListener("services",
826 closeMenuItem_actionPerformed(true);
829 // Finally, build the menu once to get current service state
830 new Thread(new Runnable()
835 BuildWebServiceMenu();
841 * Configure menu items that vary according to whether the alignment is
842 * nucleotide or protein
846 public void setGUINucleotide(boolean nucleotide)
848 showTranslation.setVisible(nucleotide);
849 showReverse.setVisible(nucleotide);
850 showReverseComplement.setVisible(nucleotide);
851 conservationMenuItem.setEnabled(!nucleotide);
852 modifyConservation.setEnabled(!nucleotide);
853 showGroupConservation.setEnabled(!nucleotide);
854 rnahelicesColour.setEnabled(nucleotide);
855 purinePyrimidineColour.setEnabled(nucleotide);
856 showComplementMenuItem.setText(MessageManager
857 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
858 setColourSelected(jalview.bin.Cache.getDefault(
859 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
860 : Preferences.DEFAULT_COLOUR_PROT, "None"));
864 * set up menus for the current viewport. This may be called after any
865 * operation that affects the data in the current view (selection changed,
866 * etc) to update the menus to reflect the new state.
869 public void setMenusForViewport()
871 setMenusFromViewport(viewport);
875 * Need to call this method when tabs are selected for multiple views, or when
876 * loading from Jalview2XML.java
881 void setMenusFromViewport(AlignViewport av)
883 padGapsMenuitem.setSelected(av.isPadGaps());
884 colourTextMenuItem.setSelected(av.isShowColourText());
885 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
886 conservationMenuItem.setSelected(av.getConservationSelected());
887 seqLimits.setSelected(av.getShowJVSuffix());
888 idRightAlign.setSelected(av.isRightAlignIds());
889 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
890 renderGapsMenuItem.setSelected(av.isRenderGaps());
891 wrapMenuItem.setSelected(av.getWrapAlignment());
892 scaleAbove.setVisible(av.getWrapAlignment());
893 scaleLeft.setVisible(av.getWrapAlignment());
894 scaleRight.setVisible(av.getWrapAlignment());
895 annotationPanelMenuItem.setState(av.isShowAnnotation());
897 * Show/hide annotations only enabled if annotation panel is shown
899 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
900 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
901 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
902 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
903 viewBoxesMenuItem.setSelected(av.getShowBoxes());
904 viewTextMenuItem.setSelected(av.getShowText());
905 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
906 showGroupConsensus.setSelected(av.isShowGroupConsensus());
907 showGroupConservation.setSelected(av.isShowGroupConservation());
908 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
909 showSequenceLogo.setSelected(av.isShowSequenceLogo());
910 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
912 setColourSelected(ColourSchemeProperty.getColourName(av
913 .getGlobalColourScheme()));
915 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
916 hiddenMarkers.setState(av.getShowHiddenMarkers());
917 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
918 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
919 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
920 autoCalculate.setSelected(av.autoCalculateConsensus);
921 sortByTree.setSelected(av.sortByTree);
922 listenToViewSelections.setSelected(av.followSelection);
923 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
925 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
927 showProducts.setEnabled(canShowProducts());
928 setGroovyEnabled(Desktop.getGroovyConsole() != null);
934 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
938 public void setGroovyEnabled(boolean b)
940 runGroovy.setEnabled(b);
943 private IProgressIndicator progressBar;
948 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
951 public void setProgressBar(String message, long id)
953 progressBar.setProgressBar(message, id);
957 public void registerHandler(final long id,
958 final IProgressIndicatorHandler handler)
960 progressBar.registerHandler(id, handler);
965 * @return true if any progress bars are still active
968 public boolean operationInProgress()
970 return progressBar.operationInProgress();
974 public void setStatus(String text)
976 statusBar.setText(text);
980 * Added so Castor Mapping file can obtain Jalview Version
982 public String getVersion()
984 return jalview.bin.Cache.getProperty("VERSION");
987 public FeatureRenderer getFeatureRenderer()
989 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
993 public void fetchSequence_actionPerformed(ActionEvent e)
995 new jalview.gui.SequenceFetcher(this);
999 public void addFromFile_actionPerformed(ActionEvent e)
1001 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1005 public void reload_actionPerformed(ActionEvent e)
1007 if (fileName != null)
1009 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1010 // originating file's format
1011 // TODO: work out how to recover feature settings for correct view(s) when
1012 // file is reloaded.
1013 if (currentFileFormat == FileFormat.Jalview)
1015 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1016 for (int i = 0; i < frames.length; i++)
1018 if (frames[i] instanceof AlignFrame && frames[i] != this
1019 && ((AlignFrame) frames[i]).fileName != null
1020 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1024 frames[i].setSelected(true);
1025 Desktop.instance.closeAssociatedWindows();
1026 } catch (java.beans.PropertyVetoException ex)
1032 Desktop.instance.closeAssociatedWindows();
1034 FileLoader loader = new FileLoader();
1035 DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL
1036 : DataSourceType.FILE;
1037 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1041 Rectangle bounds = this.getBounds();
1043 FileLoader loader = new FileLoader();
1044 DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL
1045 : DataSourceType.FILE;
1046 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1047 protocol, currentFileFormat);
1049 newframe.setBounds(bounds);
1050 if (featureSettings != null && featureSettings.isShowing())
1052 final Rectangle fspos = featureSettings.frame.getBounds();
1053 // TODO: need a 'show feature settings' function that takes bounds -
1054 // need to refactor Desktop.addFrame
1055 newframe.featureSettings_actionPerformed(null);
1056 final FeatureSettings nfs = newframe.featureSettings;
1057 SwingUtilities.invokeLater(new Runnable()
1062 nfs.frame.setBounds(fspos);
1065 this.featureSettings.close();
1066 this.featureSettings = null;
1068 this.closeMenuItem_actionPerformed(true);
1074 public void addFromText_actionPerformed(ActionEvent e)
1076 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1081 public void addFromURL_actionPerformed(ActionEvent e)
1083 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1087 public void save_actionPerformed(ActionEvent e)
1089 if (fileName == null || (currentFileFormat == null)
1090 || fileName.startsWith("http"))
1092 saveAs_actionPerformed(null);
1096 saveAlignment(fileName, currentFileFormat);
1107 public void saveAs_actionPerformed(ActionEvent e)
1109 JalviewFileChooser chooser = new JalviewFileChooser(
1110 Cache.getProperty("LAST_DIRECTORY"),
1111 // AppletFormatAdapter.WRITABLE_EXTENSIONS,
1112 // AppletFormatAdapter.WRITABLE_FNAMES,
1113 currentFileFormat, false);
1115 chooser.setFileView(new JalviewFileView());
1116 chooser.setDialogTitle(MessageManager
1117 .getString("label.save_alignment_to_file"));
1118 chooser.setToolTipText(MessageManager.getString("action.save"));
1120 int value = chooser.showSaveDialog(this);
1122 if (value == JalviewFileChooser.APPROVE_OPTION)
1124 currentFileFormat = chooser.getSelectedFormat();
1125 while (currentFileFormat == null)
1128 .showInternalMessageDialog(
1131 .getString("label.select_file_format_before_saving"),
1133 .getString("label.file_format_not_specified"),
1134 JOptionPane.WARNING_MESSAGE);
1135 currentFileFormat = chooser.getSelectedFormat();
1136 value = chooser.showSaveDialog(this);
1137 if (value != JalviewFileChooser.APPROVE_OPTION)
1143 fileName = chooser.getSelectedFile().getPath();
1145 Cache.setProperty("DEFAULT_FILE_FORMAT",
1146 currentFileFormat.toString());
1148 Cache.setProperty("LAST_DIRECTORY", fileName);
1149 saveAlignment(fileName, currentFileFormat);
1153 public boolean saveAlignment(String file, FileFormatI format)
1155 boolean success = true;
1157 if (format == FileFormat.Jalview)
1159 String shortName = title;
1161 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1163 shortName = shortName.substring(shortName
1164 .lastIndexOf(java.io.File.separatorChar) + 1);
1167 success = new Jalview2XML().saveAlignment(this, file, shortName);
1169 statusBar.setText(MessageManager.formatMessage(
1170 "label.successfully_saved_to_file_in_format", new Object[] {
1171 fileName, format }));
1176 // if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1178 // warningMessage("Cannot save file " + fileName + " using format "
1179 // + format, "Alignment output format not supported");
1180 // if (!Jalview.isHeadlessMode())
1182 // saveAs_actionPerformed(null);
1187 AlignmentExportData exportData = getAlignmentForExport(format,
1189 if (exportData.getSettings().isCancelled())
1193 FormatAdapter f = new FormatAdapter(alignPanel,
1194 exportData.getSettings());
1195 String output = f.formatSequences(
1197 exportData.getAlignment(), // class cast exceptions will
1198 // occur in the distant future
1199 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1200 f.getCacheSuffixDefault(format),
1201 viewport.getColumnSelection());
1211 java.io.PrintWriter out = new java.io.PrintWriter(
1212 new java.io.FileWriter(file));
1216 this.setTitle(file);
1217 statusBar.setText(MessageManager.formatMessage(
1218 "label.successfully_saved_to_file_in_format",
1219 new Object[] { fileName, format }));
1220 } catch (Exception ex)
1223 ex.printStackTrace();
1230 JOptionPane.showInternalMessageDialog(this, MessageManager
1231 .formatMessage("label.couldnt_save_file",
1232 new Object[] { fileName }), MessageManager
1233 .getString("label.error_saving_file"),
1234 JOptionPane.WARNING_MESSAGE);
1240 private void warningMessage(String warning, String title)
1242 if (new jalview.util.Platform().isHeadless())
1244 System.err.println("Warning: " + title + "\nWarning: " + warning);
1249 JOptionPane.showInternalMessageDialog(this, warning, title,
1250 JOptionPane.WARNING_MESSAGE);
1262 protected void outputText_actionPerformed(ActionEvent e)
1265 FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
1266 AlignmentExportData exportData = getAlignmentForExport(
1269 if (exportData.getSettings().isCancelled())
1273 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1274 cap.setForInput(null);
1277 FileFormatI format = fileFormat;
1278 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1279 .formatSequences(format,
1280 exportData.getAlignment(),
1281 exportData.getOmitHidden(),
1282 exportData.getStartEndPostions(),
1283 viewport.getColumnSelection()));
1284 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1285 "label.alignment_output_command",
1286 new Object[] { e.getActionCommand() }), 600, 500);
1287 } catch (OutOfMemoryError oom)
1289 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1295 public static AlignmentExportData getAlignmentForExport(
1296 FileFormatI format, AlignViewportI viewport,
1297 AlignExportSettingI exportSettings)
1299 AlignmentI alignmentToExport = null;
1300 AlignExportSettingI settings = exportSettings;
1301 String[] omitHidden = null;
1303 HiddenSequences hiddenSeqs = viewport.getAlignment()
1304 .getHiddenSequences();
1306 alignmentToExport = viewport.getAlignment();
1308 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1309 if (settings == null)
1311 settings = new AlignExportSettings(hasHiddenSeqs,
1312 viewport.hasHiddenColumns(), format);
1314 // settings.isExportAnnotations();
1316 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1318 omitHidden = viewport.getViewAsString(false,
1319 settings.isExportHiddenSequences());
1322 int[] alignmentStartEnd = new int[2];
1323 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1325 alignmentToExport = hiddenSeqs.getFullAlignment();
1329 alignmentToExport = viewport.getAlignment();
1331 alignmentStartEnd = alignmentToExport
1332 .getVisibleStartAndEndIndex(viewport.getColumnSelection()
1333 .getHiddenColumns());
1334 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1335 omitHidden, alignmentStartEnd, settings);
1346 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1348 new HtmlSvgOutput(null, alignPanel);
1352 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1354 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
1355 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1358 public void createImageMap(File file, String image)
1360 alignPanel.makePNGImageMap(file, image);
1370 public void createPNG(File f)
1372 alignPanel.makePNG(f);
1382 public void createEPS(File f)
1384 alignPanel.makeEPS(f);
1388 public void createSVG(File f)
1390 alignPanel.makeSVG(f);
1394 public void pageSetup_actionPerformed(ActionEvent e)
1396 PrinterJob printJob = PrinterJob.getPrinterJob();
1397 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1407 public void printMenuItem_actionPerformed(ActionEvent e)
1409 // Putting in a thread avoids Swing painting problems
1410 PrintThread thread = new PrintThread(alignPanel);
1415 public void exportFeatures_actionPerformed(ActionEvent e)
1417 new AnnotationExporter().exportFeatures(alignPanel);
1421 public void exportAnnotations_actionPerformed(ActionEvent e)
1423 new AnnotationExporter().exportAnnotations(alignPanel);
1427 public void associatedData_actionPerformed(ActionEvent e)
1429 // Pick the tree file
1430 JalviewFileChooser chooser = new JalviewFileChooser(
1431 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1432 chooser.setFileView(new JalviewFileView());
1433 chooser.setDialogTitle(MessageManager
1434 .getString("label.load_jalview_annotations"));
1435 chooser.setToolTipText(MessageManager
1436 .getString("label.load_jalview_annotations"));
1438 int value = chooser.showOpenDialog(null);
1440 if (value == JalviewFileChooser.APPROVE_OPTION)
1442 String choice = chooser.getSelectedFile().getPath();
1443 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1444 loadJalviewDataFile(choice, null, null, null);
1450 * Close the current view or all views in the alignment frame. If the frame
1451 * only contains one view then the alignment will be removed from memory.
1453 * @param closeAllTabs
1456 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1458 if (alignPanels != null && alignPanels.size() < 2)
1460 closeAllTabs = true;
1465 if (alignPanels != null)
1469 if (this.isClosed())
1471 // really close all the windows - otherwise wait till
1472 // setClosed(true) is called
1473 for (int i = 0; i < alignPanels.size(); i++)
1475 AlignmentPanel ap = alignPanels.get(i);
1482 closeView(alignPanel);
1489 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1490 * be called recursively, with the frame now in 'closed' state
1492 this.setClosed(true);
1494 } catch (Exception ex)
1496 ex.printStackTrace();
1501 * Close the specified panel and close up tabs appropriately.
1503 * @param panelToClose
1505 public void closeView(AlignmentPanel panelToClose)
1507 int index = tabbedPane.getSelectedIndex();
1508 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1509 alignPanels.remove(panelToClose);
1510 panelToClose.closePanel();
1511 panelToClose = null;
1513 tabbedPane.removeTabAt(closedindex);
1514 tabbedPane.validate();
1516 if (index > closedindex || index == tabbedPane.getTabCount())
1518 // modify currently selected tab index if necessary.
1522 this.tabSelectionChanged(index);
1528 void updateEditMenuBar()
1531 if (viewport.getHistoryList().size() > 0)
1533 undoMenuItem.setEnabled(true);
1534 CommandI command = viewport.getHistoryList().peek();
1535 undoMenuItem.setText(MessageManager.formatMessage(
1536 "label.undo_command",
1537 new Object[] { command.getDescription() }));
1541 undoMenuItem.setEnabled(false);
1542 undoMenuItem.setText(MessageManager.getString("action.undo"));
1545 if (viewport.getRedoList().size() > 0)
1547 redoMenuItem.setEnabled(true);
1549 CommandI command = viewport.getRedoList().peek();
1550 redoMenuItem.setText(MessageManager.formatMessage(
1551 "label.redo_command",
1552 new Object[] { command.getDescription() }));
1556 redoMenuItem.setEnabled(false);
1557 redoMenuItem.setText(MessageManager.getString("action.redo"));
1562 public void addHistoryItem(CommandI command)
1564 if (command.getSize() > 0)
1566 viewport.addToHistoryList(command);
1567 viewport.clearRedoList();
1568 updateEditMenuBar();
1569 viewport.updateHiddenColumns();
1570 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1571 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1572 // viewport.getColumnSelection()
1573 // .getHiddenColumns().size() > 0);
1579 * @return alignment objects for all views
1581 AlignmentI[] getViewAlignments()
1583 if (alignPanels != null)
1585 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1587 for (AlignmentPanel ap : alignPanels)
1589 als[i++] = ap.av.getAlignment();
1593 if (viewport != null)
1595 return new AlignmentI[] { viewport.getAlignment() };
1607 protected void undoMenuItem_actionPerformed(ActionEvent e)
1609 if (viewport.getHistoryList().isEmpty())
1613 CommandI command = viewport.getHistoryList().pop();
1614 viewport.addToRedoList(command);
1615 command.undoCommand(getViewAlignments());
1617 AlignmentViewport originalSource = getOriginatingSource(command);
1618 updateEditMenuBar();
1620 if (originalSource != null)
1622 if (originalSource != viewport)
1625 .warn("Implementation worry: mismatch of viewport origin for undo");
1627 originalSource.updateHiddenColumns();
1628 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1630 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1631 // viewport.getColumnSelection()
1632 // .getHiddenColumns().size() > 0);
1633 originalSource.firePropertyChange("alignment", null, originalSource
1634 .getAlignment().getSequences());
1645 protected void redoMenuItem_actionPerformed(ActionEvent e)
1647 if (viewport.getRedoList().size() < 1)
1652 CommandI command = viewport.getRedoList().pop();
1653 viewport.addToHistoryList(command);
1654 command.doCommand(getViewAlignments());
1656 AlignmentViewport originalSource = getOriginatingSource(command);
1657 updateEditMenuBar();
1659 if (originalSource != null)
1662 if (originalSource != viewport)
1665 .warn("Implementation worry: mismatch of viewport origin for redo");
1667 originalSource.updateHiddenColumns();
1668 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1670 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1671 // viewport.getColumnSelection()
1672 // .getHiddenColumns().size() > 0);
1673 originalSource.firePropertyChange("alignment", null, originalSource
1674 .getAlignment().getSequences());
1678 AlignmentViewport getOriginatingSource(CommandI command)
1680 AlignmentViewport originalSource = null;
1681 // For sequence removal and addition, we need to fire
1682 // the property change event FROM the viewport where the
1683 // original alignment was altered
1684 AlignmentI al = null;
1685 if (command instanceof EditCommand)
1687 EditCommand editCommand = (EditCommand) command;
1688 al = editCommand.getAlignment();
1689 List<Component> comps = PaintRefresher.components.get(viewport
1690 .getSequenceSetId());
1692 for (Component comp : comps)
1694 if (comp instanceof AlignmentPanel)
1696 if (al == ((AlignmentPanel) comp).av.getAlignment())
1698 originalSource = ((AlignmentPanel) comp).av;
1705 if (originalSource == null)
1707 // The original view is closed, we must validate
1708 // the current view against the closed view first
1711 PaintRefresher.validateSequences(al, viewport.getAlignment());
1714 originalSource = viewport;
1717 return originalSource;
1726 public void moveSelectedSequences(boolean up)
1728 SequenceGroup sg = viewport.getSelectionGroup();
1734 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1735 viewport.getHiddenRepSequences(), up);
1736 alignPanel.paintAlignment(true);
1739 synchronized void slideSequences(boolean right, int size)
1741 List<SequenceI> sg = new ArrayList<SequenceI>();
1742 if (viewport.cursorMode)
1744 sg.add(viewport.getAlignment().getSequenceAt(
1745 alignPanel.getSeqPanel().seqCanvas.cursorY));
1747 else if (viewport.getSelectionGroup() != null
1748 && viewport.getSelectionGroup().getSize() != viewport
1749 .getAlignment().getHeight())
1751 sg = viewport.getSelectionGroup().getSequences(
1752 viewport.getHiddenRepSequences());
1760 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1762 for (SequenceI seq : viewport.getAlignment().getSequences())
1764 if (!sg.contains(seq))
1766 invertGroup.add(seq);
1770 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1772 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1773 for (int i = 0; i < invertGroup.size(); i++)
1775 seqs2[i] = invertGroup.get(i);
1778 SlideSequencesCommand ssc;
1781 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1782 size, viewport.getGapCharacter());
1786 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1787 size, viewport.getGapCharacter());
1790 int groupAdjustment = 0;
1791 if (ssc.getGapsInsertedBegin() && right)
1793 if (viewport.cursorMode)
1795 alignPanel.getSeqPanel().moveCursor(size, 0);
1799 groupAdjustment = size;
1802 else if (!ssc.getGapsInsertedBegin() && !right)
1804 if (viewport.cursorMode)
1806 alignPanel.getSeqPanel().moveCursor(-size, 0);
1810 groupAdjustment = -size;
1814 if (groupAdjustment != 0)
1816 viewport.getSelectionGroup().setStartRes(
1817 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1818 viewport.getSelectionGroup().setEndRes(
1819 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1823 * just extend the last slide command if compatible; but not if in
1824 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1826 boolean appendHistoryItem = false;
1827 Deque<CommandI> historyList = viewport.getHistoryList();
1828 boolean inSplitFrame = getSplitViewContainer() != null;
1829 if (!inSplitFrame && historyList != null && historyList.size() > 0
1830 && historyList.peek() instanceof SlideSequencesCommand)
1832 appendHistoryItem = ssc
1833 .appendSlideCommand((SlideSequencesCommand) historyList
1837 if (!appendHistoryItem)
1839 addHistoryItem(ssc);
1852 protected void copy_actionPerformed(ActionEvent e)
1855 if (viewport.getSelectionGroup() == null)
1859 // TODO: preserve the ordering of displayed alignment annotation in any
1860 // internal paste (particularly sequence associated annotation)
1861 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1862 String[] omitHidden = null;
1864 if (viewport.hasHiddenColumns())
1866 omitHidden = viewport.getViewAsString(true);
1869 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1872 StringSelection ss = new StringSelection(output);
1876 jalview.gui.Desktop.internalCopy = true;
1877 // Its really worth setting the clipboard contents
1878 // to empty before setting the large StringSelection!!
1879 Toolkit.getDefaultToolkit().getSystemClipboard()
1880 .setContents(new StringSelection(""), null);
1882 Toolkit.getDefaultToolkit().getSystemClipboard()
1883 .setContents(ss, Desktop.instance);
1884 } catch (OutOfMemoryError er)
1886 new OOMWarning("copying region", er);
1890 ArrayList<int[]> hiddenColumns = null;
1891 if (viewport.hasHiddenColumns())
1893 hiddenColumns = new ArrayList<int[]>();
1894 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1895 .getSelectionGroup().getEndRes();
1896 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1898 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1900 hiddenColumns.add(new int[] { region[0] - hiddenOffset,
1901 region[1] - hiddenOffset });
1906 Desktop.jalviewClipboard = new Object[] { seqs,
1907 viewport.getAlignment().getDataset(), hiddenColumns };
1908 statusBar.setText(MessageManager.formatMessage(
1909 "label.copied_sequences_to_clipboard", new Object[] { Integer
1910 .valueOf(seqs.length).toString() }));
1920 protected void pasteNew_actionPerformed(ActionEvent e)
1932 protected void pasteThis_actionPerformed(ActionEvent e)
1938 * Paste contents of Jalview clipboard
1940 * @param newAlignment
1941 * true to paste to a new alignment, otherwise add to this.
1943 void paste(boolean newAlignment)
1945 boolean externalPaste = true;
1948 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1949 Transferable contents = c.getContents(this);
1951 if (contents == null)
1960 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1961 if (str.length() < 1)
1966 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
1968 } catch (OutOfMemoryError er)
1970 new OOMWarning("Out of memory pasting sequences!!", er);
1974 SequenceI[] sequences;
1975 boolean annotationAdded = false;
1976 AlignmentI alignment = null;
1978 if (Desktop.jalviewClipboard != null)
1980 // The clipboard was filled from within Jalview, we must use the
1982 // And dataset from the copied alignment
1983 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1984 // be doubly sure that we create *new* sequence objects.
1985 sequences = new SequenceI[newseq.length];
1986 for (int i = 0; i < newseq.length; i++)
1988 sequences[i] = new Sequence(newseq[i]);
1990 alignment = new Alignment(sequences);
1991 externalPaste = false;
1995 // parse the clipboard as an alignment.
1996 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
1998 sequences = alignment.getSequencesArray();
2002 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2008 if (Desktop.jalviewClipboard != null)
2010 // dataset is inherited
2011 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2015 // new dataset is constructed
2016 alignment.setDataset(null);
2018 alwidth = alignment.getWidth() + 1;
2022 AlignmentI pastedal = alignment; // preserve pasted alignment object
2023 // Add pasted sequences and dataset into existing alignment.
2024 alignment = viewport.getAlignment();
2025 alwidth = alignment.getWidth() + 1;
2026 // decide if we need to import sequences from an existing dataset
2027 boolean importDs = Desktop.jalviewClipboard != null
2028 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2029 // importDs==true instructs us to copy over new dataset sequences from
2030 // an existing alignment
2031 Vector newDs = (importDs) ? new Vector() : null; // used to create
2032 // minimum dataset set
2034 for (int i = 0; i < sequences.length; i++)
2038 newDs.addElement(null);
2040 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2042 if (importDs && ds != null)
2044 if (!newDs.contains(ds))
2046 newDs.setElementAt(ds, i);
2047 ds = new Sequence(ds);
2048 // update with new dataset sequence
2049 sequences[i].setDatasetSequence(ds);
2053 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2058 // copy and derive new dataset sequence
2059 sequences[i] = sequences[i].deriveSequence();
2060 alignment.getDataset().addSequence(
2061 sequences[i].getDatasetSequence());
2062 // TODO: avoid creation of duplicate dataset sequences with a
2063 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2065 alignment.addSequence(sequences[i]); // merges dataset
2069 newDs.clear(); // tidy up
2071 if (alignment.getAlignmentAnnotation() != null)
2073 for (AlignmentAnnotation alan : alignment
2074 .getAlignmentAnnotation())
2076 if (alan.graphGroup > fgroup)
2078 fgroup = alan.graphGroup;
2082 if (pastedal.getAlignmentAnnotation() != null)
2084 // Add any annotation attached to alignment.
2085 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2086 for (int i = 0; i < alann.length; i++)
2088 annotationAdded = true;
2089 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2091 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2092 if (newann.graphGroup > -1)
2094 if (newGraphGroups.size() <= newann.graphGroup
2095 || newGraphGroups.get(newann.graphGroup) == null)
2097 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2099 newGraphGroups.add(q, null);
2101 newGraphGroups.set(newann.graphGroup, new Integer(
2104 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2108 newann.padAnnotation(alwidth);
2109 alignment.addAnnotation(newann);
2119 addHistoryItem(new EditCommand(
2120 MessageManager.getString("label.add_sequences"),
2121 Action.PASTE, sequences, 0, alignment.getWidth(), alignment));
2123 // Add any annotations attached to sequences
2124 for (int i = 0; i < sequences.length; i++)
2126 if (sequences[i].getAnnotation() != null)
2128 AlignmentAnnotation newann;
2129 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2131 annotationAdded = true;
2132 newann = sequences[i].getAnnotation()[a];
2133 newann.adjustForAlignment();
2134 newann.padAnnotation(alwidth);
2135 if (newann.graphGroup > -1)
2137 if (newann.graphGroup > -1)
2139 if (newGraphGroups.size() <= newann.graphGroup
2140 || newGraphGroups.get(newann.graphGroup) == null)
2142 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2144 newGraphGroups.add(q, null);
2146 newGraphGroups.set(newann.graphGroup, new Integer(
2149 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2153 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2158 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2165 // propagate alignment changed.
2166 viewport.setEndSeq(alignment.getHeight());
2167 if (annotationAdded)
2169 // Duplicate sequence annotation in all views.
2170 AlignmentI[] alview = this.getViewAlignments();
2171 for (int i = 0; i < sequences.length; i++)
2173 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2178 for (int avnum = 0; avnum < alview.length; avnum++)
2180 if (alview[avnum] != alignment)
2182 // duplicate in a view other than the one with input focus
2183 int avwidth = alview[avnum].getWidth() + 1;
2184 // this relies on sann being preserved after we
2185 // modify the sequence's annotation array for each duplication
2186 for (int a = 0; a < sann.length; a++)
2188 AlignmentAnnotation newann = new AlignmentAnnotation(
2190 sequences[i].addAlignmentAnnotation(newann);
2191 newann.padAnnotation(avwidth);
2192 alview[avnum].addAnnotation(newann); // annotation was
2193 // duplicated earlier
2194 // TODO JAL-1145 graphGroups are not updated for sequence
2195 // annotation added to several views. This may cause
2197 alview[avnum].setAnnotationIndex(newann, a);
2202 buildSortByAnnotationScoresMenu();
2204 viewport.firePropertyChange("alignment", null,
2205 alignment.getSequences());
2206 if (alignPanels != null)
2208 for (AlignmentPanel ap : alignPanels)
2210 ap.validateAnnotationDimensions(false);
2215 alignPanel.validateAnnotationDimensions(false);
2221 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2223 String newtitle = new String("Copied sequences");
2225 if (Desktop.jalviewClipboard != null
2226 && Desktop.jalviewClipboard[2] != null)
2228 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2229 for (int[] region : hc)
2231 af.viewport.hideColumns(region[0], region[1]);
2235 // >>>This is a fix for the moment, until a better solution is
2237 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2239 alignPanel.getSeqPanel().seqCanvas
2240 .getFeatureRenderer());
2242 // TODO: maintain provenance of an alignment, rather than just make the
2243 // title a concatenation of operations.
2246 if (title.startsWith("Copied sequences"))
2252 newtitle = newtitle.concat("- from " + title);
2257 newtitle = new String("Pasted sequences");
2260 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2265 } catch (Exception ex)
2267 ex.printStackTrace();
2268 System.out.println("Exception whilst pasting: " + ex);
2269 // could be anything being pasted in here
2275 protected void expand_newalign(ActionEvent e)
2279 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2280 .getAlignment(), -1);
2281 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2283 String newtitle = new String("Flanking alignment");
2285 if (Desktop.jalviewClipboard != null
2286 && Desktop.jalviewClipboard[2] != null)
2288 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2289 for (int region[] : hc)
2291 af.viewport.hideColumns(region[0], region[1]);
2295 // >>>This is a fix for the moment, until a better solution is
2297 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2299 alignPanel.getSeqPanel().seqCanvas
2300 .getFeatureRenderer());
2302 // TODO: maintain provenance of an alignment, rather than just make the
2303 // title a concatenation of operations.
2305 if (title.startsWith("Copied sequences"))
2311 newtitle = newtitle.concat("- from " + title);
2315 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2317 } catch (Exception ex)
2319 ex.printStackTrace();
2320 System.out.println("Exception whilst pasting: " + ex);
2321 // could be anything being pasted in here
2322 } catch (OutOfMemoryError oom)
2324 new OOMWarning("Viewing flanking region of alignment", oom);
2335 protected void cut_actionPerformed(ActionEvent e)
2337 copy_actionPerformed(null);
2338 delete_actionPerformed(null);
2348 protected void delete_actionPerformed(ActionEvent evt)
2351 SequenceGroup sg = viewport.getSelectionGroup();
2358 * If the cut affects all sequences, warn, remove highlighted columns
2360 if (sg.getSize() == viewport.getAlignment().getHeight())
2362 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2363 .getAlignment().getWidth()) ? true : false;
2364 if (isEntireAlignWidth)
2366 int confirm = JOptionPane.showConfirmDialog(this,
2367 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2368 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2369 JOptionPane.OK_CANCEL_OPTION);
2371 if (confirm == JOptionPane.CANCEL_OPTION
2372 || confirm == JOptionPane.CLOSED_OPTION)
2377 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2378 sg.getEndRes() + 1);
2380 SequenceI[] cut = sg.getSequences()
2381 .toArray(new SequenceI[sg.getSize()]);
2383 addHistoryItem(new EditCommand(
2384 MessageManager.getString("label.cut_sequences"), Action.CUT,
2385 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2386 viewport.getAlignment()));
2388 viewport.setSelectionGroup(null);
2389 viewport.sendSelection();
2390 viewport.getAlignment().deleteGroup(sg);
2392 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2394 if (viewport.getAlignment().getHeight() < 1)
2398 this.setClosed(true);
2399 } catch (Exception ex)
2412 protected void deleteGroups_actionPerformed(ActionEvent e)
2414 if (avc.deleteGroups())
2416 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2417 alignPanel.updateAnnotation();
2418 alignPanel.paintAlignment(true);
2429 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2431 SequenceGroup sg = new SequenceGroup();
2433 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2435 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2438 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2439 viewport.setSelectionGroup(sg);
2440 viewport.sendSelection();
2441 alignPanel.paintAlignment(true);
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 alignPanel.paintAlignment(true);
2465 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2466 viewport.sendSelection();
2476 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2478 SequenceGroup sg = viewport.getSelectionGroup();
2482 selectAllSequenceMenuItem_actionPerformed(null);
2487 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2489 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2492 alignPanel.paintAlignment(true);
2493 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2494 viewport.sendSelection();
2498 public void invertColSel_actionPerformed(ActionEvent e)
2500 viewport.invertColumnSelection();
2501 alignPanel.paintAlignment(true);
2502 viewport.sendSelection();
2512 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2514 trimAlignment(true);
2524 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2526 trimAlignment(false);
2529 void trimAlignment(boolean trimLeft)
2531 ColumnSelection colSel = viewport.getColumnSelection();
2534 if (!colSel.isEmpty())
2538 column = colSel.getMin();
2542 column = colSel.getMax();
2546 if (viewport.getSelectionGroup() != null)
2548 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2549 viewport.getHiddenRepSequences());
2553 seqs = viewport.getAlignment().getSequencesArray();
2556 TrimRegionCommand trimRegion;
2559 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2560 column, viewport.getAlignment());
2561 viewport.setStartRes(0);
2565 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2566 column, viewport.getAlignment());
2569 statusBar.setText(MessageManager.formatMessage(
2570 "label.removed_columns",
2571 new String[] { Integer.valueOf(trimRegion.getSize())
2574 addHistoryItem(trimRegion);
2576 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2578 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2579 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2581 viewport.getAlignment().deleteGroup(sg);
2585 viewport.firePropertyChange("alignment", null, viewport
2586 .getAlignment().getSequences());
2597 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2599 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2602 if (viewport.getSelectionGroup() != null)
2604 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2605 viewport.getHiddenRepSequences());
2606 start = viewport.getSelectionGroup().getStartRes();
2607 end = viewport.getSelectionGroup().getEndRes();
2611 seqs = viewport.getAlignment().getSequencesArray();
2614 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2615 "Remove Gapped Columns", seqs, start, end,
2616 viewport.getAlignment());
2618 addHistoryItem(removeGapCols);
2620 statusBar.setText(MessageManager.formatMessage(
2621 "label.removed_empty_columns",
2622 new Object[] { Integer.valueOf(removeGapCols.getSize())
2625 // This is to maintain viewport position on first residue
2626 // of first sequence
2627 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2628 int startRes = seq.findPosition(viewport.startRes);
2629 // ShiftList shifts;
2630 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2631 // edit.alColumnChanges=shifts.getInverse();
2632 // if (viewport.hasHiddenColumns)
2633 // viewport.getColumnSelection().compensateForEdits(shifts);
2634 viewport.setStartRes(seq.findIndex(startRes) - 1);
2635 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2647 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2649 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2652 if (viewport.getSelectionGroup() != null)
2654 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2655 viewport.getHiddenRepSequences());
2656 start = viewport.getSelectionGroup().getStartRes();
2657 end = viewport.getSelectionGroup().getEndRes();
2661 seqs = viewport.getAlignment().getSequencesArray();
2664 // This is to maintain viewport position on first residue
2665 // of first sequence
2666 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2667 int startRes = seq.findPosition(viewport.startRes);
2669 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2670 viewport.getAlignment()));
2672 viewport.setStartRes(seq.findIndex(startRes) - 1);
2674 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2686 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2688 viewport.setPadGaps(padGapsMenuitem.isSelected());
2689 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2700 public void findMenuItem_actionPerformed(ActionEvent e)
2706 * Create a new view of the current alignment.
2709 public void newView_actionPerformed(ActionEvent e)
2711 newView(null, true);
2715 * Creates and shows a new view of the current alignment.
2718 * title of newly created view; if null, one will be generated
2719 * @param copyAnnotation
2720 * if true then duplicate all annnotation, groups and settings
2721 * @return new alignment panel, already displayed.
2723 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2726 * Create a new AlignmentPanel (with its own, new Viewport)
2728 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2730 if (!copyAnnotation)
2733 * remove all groups and annotation except for the automatic stuff
2735 newap.av.getAlignment().deleteAllGroups();
2736 newap.av.getAlignment().deleteAllAnnotations(false);
2739 newap.av.setGatherViewsHere(false);
2741 if (viewport.viewName == null)
2743 viewport.viewName = MessageManager
2744 .getString("label.view_name_original");
2748 * Views share the same edits undo and redo stacks
2750 newap.av.setHistoryList(viewport.getHistoryList());
2751 newap.av.setRedoList(viewport.getRedoList());
2754 * Views share the same mappings; need to deregister any new mappings
2755 * created by copyAlignPanel, and register the new reference to the shared
2758 newap.av.replaceMappings(viewport.getAlignment());
2760 newap.av.viewName = getNewViewName(viewTitle);
2762 addAlignmentPanel(newap, true);
2763 newap.alignmentChanged();
2765 if (alignPanels.size() == 2)
2767 viewport.setGatherViewsHere(true);
2769 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2774 * Make a new name for the view, ensuring it is unique within the current
2775 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2776 * these now use viewId. Unique view names are still desirable for usability.)
2781 protected String getNewViewName(String viewTitle)
2783 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2784 boolean addFirstIndex = false;
2785 if (viewTitle == null || viewTitle.trim().length() == 0)
2787 viewTitle = MessageManager.getString("action.view");
2788 addFirstIndex = true;
2792 index = 1;// we count from 1 if given a specific name
2794 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2796 List<Component> comps = PaintRefresher.components.get(viewport
2797 .getSequenceSetId());
2799 List<String> existingNames = getExistingViewNames(comps);
2801 while (existingNames.contains(newViewName))
2803 newViewName = viewTitle + " " + (++index);
2809 * Returns a list of distinct view names found in the given list of
2810 * components. View names are held on the viewport of an AlignmentPanel.
2815 protected List<String> getExistingViewNames(List<Component> comps)
2817 List<String> existingNames = new ArrayList<String>();
2818 for (Component comp : comps)
2820 if (comp instanceof AlignmentPanel)
2822 AlignmentPanel ap = (AlignmentPanel) comp;
2823 if (!existingNames.contains(ap.av.viewName))
2825 existingNames.add(ap.av.viewName);
2829 return existingNames;
2833 * Explode tabbed views into separate windows.
2836 public void expandViews_actionPerformed(ActionEvent e)
2838 Desktop.instance.explodeViews(this);
2842 * Gather views in separate windows back into a tabbed presentation.
2845 public void gatherViews_actionPerformed(ActionEvent e)
2847 Desktop.instance.gatherViews(this);
2857 public void font_actionPerformed(ActionEvent e)
2859 new FontChooser(alignPanel);
2869 protected void seqLimit_actionPerformed(ActionEvent e)
2871 viewport.setShowJVSuffix(seqLimits.isSelected());
2873 alignPanel.getIdPanel().getIdCanvas()
2874 .setPreferredSize(alignPanel.calculateIdWidth());
2875 alignPanel.paintAlignment(true);
2879 public void idRightAlign_actionPerformed(ActionEvent e)
2881 viewport.setRightAlignIds(idRightAlign.isSelected());
2882 alignPanel.paintAlignment(true);
2886 public void centreColumnLabels_actionPerformed(ActionEvent e)
2888 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2889 alignPanel.paintAlignment(true);
2895 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2898 protected void followHighlight_actionPerformed()
2901 * Set the 'follow' flag on the Viewport (and scroll to position if now
2904 final boolean state = this.followHighlightMenuItem.getState();
2905 viewport.setFollowHighlight(state);
2908 alignPanel.scrollToPosition(
2909 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2920 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2922 viewport.setColourText(colourTextMenuItem.isSelected());
2923 alignPanel.paintAlignment(true);
2933 public void wrapMenuItem_actionPerformed(ActionEvent e)
2935 scaleAbove.setVisible(wrapMenuItem.isSelected());
2936 scaleLeft.setVisible(wrapMenuItem.isSelected());
2937 scaleRight.setVisible(wrapMenuItem.isSelected());
2938 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2939 alignPanel.updateLayout();
2943 public void showAllSeqs_actionPerformed(ActionEvent e)
2945 viewport.showAllHiddenSeqs();
2949 public void showAllColumns_actionPerformed(ActionEvent e)
2951 viewport.showAllHiddenColumns();
2953 viewport.sendSelection();
2957 public void hideSelSequences_actionPerformed(ActionEvent e)
2959 viewport.hideAllSelectedSeqs();
2960 // alignPanel.paintAlignment(true);
2964 * called by key handler and the hide all/show all menu items
2969 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2972 boolean hide = false;
2973 SequenceGroup sg = viewport.getSelectionGroup();
2974 if (!toggleSeqs && !toggleCols)
2976 // Hide everything by the current selection - this is a hack - we do the
2977 // invert and then hide
2978 // first check that there will be visible columns after the invert.
2979 if ((viewport.getColumnSelection() != null
2980 && viewport.getColumnSelection().getSelected() != null && viewport
2981 .getColumnSelection().getSelected().size() > 0)
2982 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2985 // now invert the sequence set, if required - empty selection implies
2986 // that no hiding is required.
2989 invertSequenceMenuItem_actionPerformed(null);
2990 sg = viewport.getSelectionGroup();
2994 viewport.expandColSelection(sg, true);
2995 // finally invert the column selection and get the new sequence
2997 invertColSel_actionPerformed(null);
3004 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3006 hideSelSequences_actionPerformed(null);
3009 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3012 showAllSeqs_actionPerformed(null);
3018 if (viewport.getColumnSelection().getSelected().size() > 0)
3020 hideSelColumns_actionPerformed(null);
3023 viewport.setSelectionGroup(sg);
3028 showAllColumns_actionPerformed(null);
3037 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3038 * event.ActionEvent)
3041 public void hideAllButSelection_actionPerformed(ActionEvent e)
3043 toggleHiddenRegions(false, false);
3044 viewport.sendSelection();
3051 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3055 public void hideAllSelection_actionPerformed(ActionEvent e)
3057 SequenceGroup sg = viewport.getSelectionGroup();
3058 viewport.expandColSelection(sg, false);
3059 viewport.hideAllSelectedSeqs();
3060 viewport.hideSelectedColumns();
3061 alignPanel.paintAlignment(true);
3062 viewport.sendSelection();
3069 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3073 public void showAllhidden_actionPerformed(ActionEvent e)
3075 viewport.showAllHiddenColumns();
3076 viewport.showAllHiddenSeqs();
3077 alignPanel.paintAlignment(true);
3078 viewport.sendSelection();
3082 public void hideSelColumns_actionPerformed(ActionEvent e)
3084 viewport.hideSelectedColumns();
3085 alignPanel.paintAlignment(true);
3086 viewport.sendSelection();
3090 public void hiddenMarkers_actionPerformed(ActionEvent e)
3092 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3103 protected void scaleAbove_actionPerformed(ActionEvent e)
3105 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3106 alignPanel.paintAlignment(true);
3116 protected void scaleLeft_actionPerformed(ActionEvent e)
3118 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3119 alignPanel.paintAlignment(true);
3129 protected void scaleRight_actionPerformed(ActionEvent e)
3131 viewport.setScaleRightWrapped(scaleRight.isSelected());
3132 alignPanel.paintAlignment(true);
3142 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3144 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3145 alignPanel.paintAlignment(true);
3155 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3157 viewport.setShowText(viewTextMenuItem.isSelected());
3158 alignPanel.paintAlignment(true);
3168 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3170 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3171 alignPanel.paintAlignment(true);
3174 public FeatureSettings featureSettings;
3177 public FeatureSettingsControllerI getFeatureSettingsUI()
3179 return featureSettings;
3183 public void featureSettings_actionPerformed(ActionEvent e)
3185 if (featureSettings != null)
3187 featureSettings.close();
3188 featureSettings = null;
3190 if (!showSeqFeatures.isSelected())
3192 // make sure features are actually displayed
3193 showSeqFeatures.setSelected(true);
3194 showSeqFeatures_actionPerformed(null);
3196 featureSettings = new FeatureSettings(this);
3200 * Set or clear 'Show Sequence Features'
3206 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3208 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3209 alignPanel.paintAlignment(true);
3210 if (alignPanel.getOverviewPanel() != null)
3212 alignPanel.getOverviewPanel().updateOverviewImage();
3217 * Set or clear 'Show Sequence Features'
3223 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3225 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3227 if (viewport.isShowSequenceFeaturesHeight())
3229 // ensure we're actually displaying features
3230 viewport.setShowSequenceFeatures(true);
3231 showSeqFeatures.setSelected(true);
3233 alignPanel.paintAlignment(true);
3234 if (alignPanel.getOverviewPanel() != null)
3236 alignPanel.getOverviewPanel().updateOverviewImage();
3241 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3242 * the annotations panel as a whole.
3244 * The options to show/hide all annotations should be enabled when the panel
3245 * is shown, and disabled when the panel is hidden.
3250 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3252 final boolean setVisible = annotationPanelMenuItem.isSelected();
3253 viewport.setShowAnnotation(setVisible);
3254 this.showAllSeqAnnotations.setEnabled(setVisible);
3255 this.hideAllSeqAnnotations.setEnabled(setVisible);
3256 this.showAllAlAnnotations.setEnabled(setVisible);
3257 this.hideAllAlAnnotations.setEnabled(setVisible);
3258 alignPanel.updateLayout();
3262 public void alignmentProperties()
3264 JEditorPane editPane = new JEditorPane("text/html", "");
3265 editPane.setEditable(false);
3266 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3268 editPane.setText(MessageManager.formatMessage("label.html_content",
3269 new Object[] { contents.toString() }));
3270 JInternalFrame frame = new JInternalFrame();
3271 frame.getContentPane().add(new JScrollPane(editPane));
3273 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3274 "label.alignment_properties", new Object[] { getTitle() }),
3285 public void overviewMenuItem_actionPerformed(ActionEvent e)
3287 if (alignPanel.overviewPanel != null)
3292 JInternalFrame frame = new JInternalFrame();
3293 OverviewPanel overview = new OverviewPanel(alignPanel);
3294 frame.setContentPane(overview);
3295 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3296 "label.overview_params", new Object[] { this.getTitle() }),
3297 frame.getWidth(), frame.getHeight());
3299 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3300 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3303 public void internalFrameClosed(
3304 javax.swing.event.InternalFrameEvent evt)
3306 alignPanel.setOverviewPanel(null);
3310 alignPanel.setOverviewPanel(overview);
3314 public void textColour_actionPerformed(ActionEvent e)
3316 new TextColourChooser().chooseColour(alignPanel, null);
3326 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3338 public void clustalColour_actionPerformed(ActionEvent e)
3340 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3341 viewport.getHiddenRepSequences()));
3351 public void zappoColour_actionPerformed(ActionEvent e)
3353 changeColour(new ZappoColourScheme());
3363 public void taylorColour_actionPerformed(ActionEvent e)
3365 changeColour(new TaylorColourScheme());
3375 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3377 changeColour(new HydrophobicColourScheme());
3387 public void helixColour_actionPerformed(ActionEvent e)
3389 changeColour(new HelixColourScheme());
3399 public void strandColour_actionPerformed(ActionEvent e)
3401 changeColour(new StrandColourScheme());
3411 public void turnColour_actionPerformed(ActionEvent e)
3413 changeColour(new TurnColourScheme());
3423 public void buriedColour_actionPerformed(ActionEvent e)
3425 changeColour(new BuriedColourScheme());
3435 public void nucleotideColour_actionPerformed(ActionEvent e)
3437 changeColour(new NucleotideColourScheme());
3441 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3443 changeColour(new PurinePyrimidineColourScheme());
3447 * public void covariationColour_actionPerformed(ActionEvent e) {
3449 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3453 public void annotationColour_actionPerformed(ActionEvent e)
3455 new AnnotationColourChooser(viewport, alignPanel);
3459 public void annotationColumn_actionPerformed(ActionEvent e)
3461 new AnnotationColumnChooser(viewport, alignPanel);
3465 public void rnahelicesColour_actionPerformed(ActionEvent e)
3467 new RNAHelicesColourChooser(viewport, alignPanel);
3477 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3479 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3489 public void changeColour(ColourSchemeI cs)
3491 // TODO: pull up to controller method
3495 // Make sure viewport is up to date w.r.t. any sliders
3496 if (viewport.getAbovePIDThreshold())
3498 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3500 viewport.setThreshold(threshold);
3503 if (viewport.getConservationSelected())
3505 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3508 if (cs instanceof TCoffeeColourScheme)
3510 tcoffeeColour.setEnabled(true);
3511 tcoffeeColour.setSelected(true);
3515 viewport.setGlobalColourScheme(cs);
3517 alignPanel.paintAlignment(true);
3527 protected void modifyPID_actionPerformed(ActionEvent e)
3529 if (viewport.getAbovePIDThreshold()
3530 && viewport.getGlobalColourScheme() != null)
3532 SliderPanel.setPIDSliderSource(alignPanel,
3533 viewport.getGlobalColourScheme(), "Background");
3534 SliderPanel.showPIDSlider();
3545 protected void modifyConservation_actionPerformed(ActionEvent e)
3547 if (viewport.getConservationSelected()
3548 && viewport.getGlobalColourScheme() != null)
3550 SliderPanel.setConservationSlider(alignPanel,
3551 viewport.getGlobalColourScheme(), "Background");
3552 SliderPanel.showConservationSlider();
3563 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3565 viewport.setConservationSelected(conservationMenuItem.isSelected());
3567 viewport.setAbovePIDThreshold(false);
3568 abovePIDThreshold.setSelected(false);
3570 changeColour(viewport.getGlobalColourScheme());
3572 modifyConservation_actionPerformed(null);
3582 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3584 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3586 conservationMenuItem.setSelected(false);
3587 viewport.setConservationSelected(false);
3589 changeColour(viewport.getGlobalColourScheme());
3591 modifyPID_actionPerformed(null);
3601 public void userDefinedColour_actionPerformed(ActionEvent e)
3603 if (e.getActionCommand().equals(
3604 MessageManager.getString("action.user_defined")))
3606 new UserDefinedColours(alignPanel, null);
3610 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3611 .getUserColourSchemes().get(e.getActionCommand());
3617 public void updateUserColourMenu()
3620 Component[] menuItems = colourMenu.getMenuComponents();
3621 int iSize = menuItems.length;
3622 for (int i = 0; i < iSize; i++)
3624 if (menuItems[i].getName() != null
3625 && menuItems[i].getName().equals("USER_DEFINED"))
3627 colourMenu.remove(menuItems[i]);
3631 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3633 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3634 .getUserColourSchemes().keys();
3636 while (userColours.hasMoreElements())
3638 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3639 userColours.nextElement().toString());
3640 radioItem.setName("USER_DEFINED");
3641 radioItem.addMouseListener(new MouseAdapter()
3644 public void mousePressed(MouseEvent evt)
3646 if (evt.isPopupTrigger())
3648 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3650 int option = JOptionPane.showInternalConfirmDialog(
3651 jalview.gui.Desktop.desktop,
3653 .getString("label.remove_from_default_list"),
3655 .getString("label.remove_user_defined_colour"),
3656 JOptionPane.YES_NO_OPTION);
3657 if (option == JOptionPane.YES_OPTION)
3659 jalview.gui.UserDefinedColours
3660 .removeColourFromDefaults(radioItem.getText());
3661 colourMenu.remove(radioItem);
3665 radioItem.addActionListener(new ActionListener()
3668 public void actionPerformed(ActionEvent evt)
3670 userDefinedColour_actionPerformed(evt);
3677 radioItem.addActionListener(new ActionListener()
3680 public void actionPerformed(ActionEvent evt)
3682 userDefinedColour_actionPerformed(evt);
3686 colourMenu.insert(radioItem, 15);
3687 colours.add(radioItem);
3699 public void PIDColour_actionPerformed(ActionEvent e)
3701 changeColour(new PIDColourScheme());
3711 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3713 changeColour(new Blosum62ColourScheme());
3723 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3725 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3726 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3727 .getAlignment().getSequenceAt(0), null);
3728 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3729 viewport.getAlignment()));
3730 alignPanel.paintAlignment(true);
3740 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3742 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3743 AlignmentSorter.sortByID(viewport.getAlignment());
3744 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3745 viewport.getAlignment()));
3746 alignPanel.paintAlignment(true);
3756 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3758 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3759 AlignmentSorter.sortByLength(viewport.getAlignment());
3760 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3761 viewport.getAlignment()));
3762 alignPanel.paintAlignment(true);
3772 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3774 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3775 AlignmentSorter.sortByGroup(viewport.getAlignment());
3776 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3777 viewport.getAlignment()));
3779 alignPanel.paintAlignment(true);
3789 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3791 new RedundancyPanel(alignPanel, this);
3801 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3803 if ((viewport.getSelectionGroup() == null)
3804 || (viewport.getSelectionGroup().getSize() < 2))
3806 JOptionPane.showInternalMessageDialog(this, MessageManager
3807 .getString("label.you_must_select_least_two_sequences"),
3808 MessageManager.getString("label.invalid_selection"),
3809 JOptionPane.WARNING_MESSAGE);
3813 JInternalFrame frame = new JInternalFrame();
3814 frame.setContentPane(new PairwiseAlignPanel(viewport));
3815 Desktop.addInternalFrame(frame,
3816 MessageManager.getString("action.pairwise_alignment"), 600,
3828 public void PCAMenuItem_actionPerformed(ActionEvent e)
3830 if (((viewport.getSelectionGroup() != null)
3831 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3832 .getSelectionGroup().getSize() > 0))
3833 || (viewport.getAlignment().getHeight() < 4))
3836 .showInternalMessageDialog(
3839 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3841 .getString("label.sequence_selection_insufficient"),
3842 JOptionPane.WARNING_MESSAGE);
3847 new PCAPanel(alignPanel);
3851 public void autoCalculate_actionPerformed(ActionEvent e)
3853 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3854 if (viewport.autoCalculateConsensus)
3856 viewport.firePropertyChange("alignment", null, viewport
3857 .getAlignment().getSequences());
3862 public void sortByTreeOption_actionPerformed(ActionEvent e)
3864 viewport.sortByTree = sortByTree.isSelected();
3868 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3870 viewport.followSelection = listenToViewSelections.isSelected();
3880 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3882 newTreePanel("AV", "PID", "Average distance tree using PID");
3892 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3894 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3904 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3906 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3916 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3918 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3931 void newTreePanel(String type, String pwType, String title)
3935 if (viewport.getSelectionGroup() != null
3936 && viewport.getSelectionGroup().getSize() > 0)
3938 if (viewport.getSelectionGroup().getSize() < 3)
3944 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3946 .getString("label.not_enough_sequences"),
3947 JOptionPane.WARNING_MESSAGE);
3951 SequenceGroup sg = viewport.getSelectionGroup();
3953 /* Decide if the selection is a column region */
3954 for (SequenceI _s : sg.getSequences())
3956 if (_s.getLength() < sg.getEndRes())
3962 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3964 .getString("label.sequences_selection_not_aligned"),
3965 JOptionPane.WARNING_MESSAGE);
3971 title = title + " on region";
3972 tp = new TreePanel(alignPanel, type, pwType);
3976 // are the visible sequences aligned?
3977 if (!viewport.getAlignment().isAligned(false))
3983 .getString("label.sequences_must_be_aligned_before_creating_tree"),
3985 .getString("label.sequences_not_aligned"),
3986 JOptionPane.WARNING_MESSAGE);
3991 if (viewport.getAlignment().getHeight() < 2)
3996 tp = new TreePanel(alignPanel, type, pwType);
4001 if (viewport.viewName != null)
4003 title += viewport.viewName + " of ";
4006 title += this.title;
4008 Desktop.addInternalFrame(tp, title, 600, 500);
4019 public void addSortByOrderMenuItem(String title,
4020 final AlignmentOrder order)
4022 final JMenuItem item = new JMenuItem(MessageManager.formatMessage(
4023 "action.by_title_param", new Object[] { title }));
4025 item.addActionListener(new java.awt.event.ActionListener()
4028 public void actionPerformed(ActionEvent e)
4030 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4032 // TODO: JBPNote - have to map order entries to curent SequenceI
4034 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4036 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4039 alignPanel.paintAlignment(true);
4045 * Add a new sort by annotation score menu item
4048 * the menu to add the option to
4050 * the label used to retrieve scores for each sequence on the
4053 public void addSortByAnnotScoreMenuItem(JMenu sort,
4054 final String scoreLabel)
4056 final JMenuItem item = new JMenuItem(scoreLabel);
4058 item.addActionListener(new java.awt.event.ActionListener()
4061 public void actionPerformed(ActionEvent e)
4063 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4064 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4065 viewport.getAlignment());// ,viewport.getSelectionGroup());
4066 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4067 viewport.getAlignment()));
4068 alignPanel.paintAlignment(true);
4074 * last hash for alignment's annotation array - used to minimise cost of
4077 protected int _annotationScoreVectorHash;
4080 * search the alignment and rebuild the sort by annotation score submenu the
4081 * last alignment annotation vector hash is stored to minimize cost of
4082 * rebuilding in subsequence calls.
4086 public void buildSortByAnnotationScoresMenu()
4088 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4093 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4095 sortByAnnotScore.removeAll();
4096 // almost certainly a quicker way to do this - but we keep it simple
4097 Hashtable scoreSorts = new Hashtable();
4098 AlignmentAnnotation aann[];
4099 for (SequenceI sqa : viewport.getAlignment().getSequences())
4101 aann = sqa.getAnnotation();
4102 for (int i = 0; aann != null && i < aann.length; i++)
4104 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4106 scoreSorts.put(aann[i].label, aann[i].label);
4110 Enumeration labels = scoreSorts.keys();
4111 while (labels.hasMoreElements())
4113 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4114 (String) labels.nextElement());
4116 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4119 _annotationScoreVectorHash = viewport.getAlignment()
4120 .getAlignmentAnnotation().hashCode();
4125 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4126 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4127 * call. Listeners are added to remove the menu item when the treePanel is
4128 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4132 * Displayed tree window.
4134 * SortBy menu item title.
4137 public void buildTreeMenu()
4139 calculateTree.removeAll();
4140 // build the calculate menu
4142 for (final String type : new String[] { "NJ", "AV" })
4144 String treecalcnm = MessageManager.getString("label.tree_calc_"
4145 + type.toLowerCase());
4146 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4148 JMenuItem tm = new JMenuItem();
4149 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4150 if (sm.isDNA() == viewport.getAlignment().isNucleotide()
4151 || sm.isProtein() == !viewport.getAlignment()
4154 String smn = MessageManager.getStringOrReturn(
4155 "label.score_model_", sm.getName());
4156 final String title = MessageManager.formatMessage(
4157 "label.treecalc_title", treecalcnm, smn);
4158 tm.setText(title);//
4159 tm.addActionListener(new java.awt.event.ActionListener()
4162 public void actionPerformed(ActionEvent e)
4164 newTreePanel(type, pwtype, title);
4167 calculateTree.add(tm);
4172 sortByTreeMenu.removeAll();
4174 List<Component> comps = PaintRefresher.components.get(viewport
4175 .getSequenceSetId());
4176 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4177 for (Component comp : comps)
4179 if (comp instanceof TreePanel)
4181 treePanels.add((TreePanel) comp);
4185 if (treePanels.size() < 1)
4187 sortByTreeMenu.setVisible(false);
4191 sortByTreeMenu.setVisible(true);
4193 for (final TreePanel tp : treePanels)
4195 final JMenuItem item = new JMenuItem(tp.getTitle());
4196 item.addActionListener(new java.awt.event.ActionListener()
4199 public void actionPerformed(ActionEvent e)
4201 tp.sortByTree_actionPerformed();
4202 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4207 sortByTreeMenu.add(item);
4211 public boolean sortBy(AlignmentOrder alorder, String undoname)
4213 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4214 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4215 if (undoname != null)
4217 addHistoryItem(new OrderCommand(undoname, oldOrder,
4218 viewport.getAlignment()));
4220 alignPanel.paintAlignment(true);
4225 * Work out whether the whole set of sequences or just the selected set will
4226 * be submitted for multiple alignment.
4229 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4231 // Now, check we have enough sequences
4232 AlignmentView msa = null;
4234 if ((viewport.getSelectionGroup() != null)
4235 && (viewport.getSelectionGroup().getSize() > 1))
4237 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4238 // some common interface!
4240 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4241 * SequenceI[sz = seqs.getSize(false)];
4243 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4244 * seqs.getSequenceAt(i); }
4246 msa = viewport.getAlignmentView(true);
4248 else if (viewport.getSelectionGroup() != null
4249 && viewport.getSelectionGroup().getSize() == 1)
4251 int option = JOptionPane.showConfirmDialog(this,
4252 MessageManager.getString("warn.oneseq_msainput_selection"),
4253 MessageManager.getString("label.invalid_selection"),
4254 JOptionPane.OK_CANCEL_OPTION);
4255 if (option == JOptionPane.OK_OPTION)
4257 msa = viewport.getAlignmentView(false);
4262 msa = viewport.getAlignmentView(false);
4268 * Decides what is submitted to a secondary structure prediction service: the
4269 * first sequence in the alignment, or in the current selection, or, if the
4270 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4271 * region or the whole alignment. (where the first sequence in the set is the
4272 * one that the prediction will be for).
4274 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4276 AlignmentView seqs = null;
4278 if ((viewport.getSelectionGroup() != null)
4279 && (viewport.getSelectionGroup().getSize() > 0))
4281 seqs = viewport.getAlignmentView(true);
4285 seqs = viewport.getAlignmentView(false);
4287 // limit sequences - JBPNote in future - could spawn multiple prediction
4289 // TODO: viewport.getAlignment().isAligned is a global state - the local
4290 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4291 if (!viewport.getAlignment().isAligned(false))
4293 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4294 // TODO: if seqs.getSequences().length>1 then should really have warned
4308 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4310 // Pick the tree file
4311 JalviewFileChooser chooser = new JalviewFileChooser(
4312 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4313 chooser.setFileView(new JalviewFileView());
4314 chooser.setDialogTitle(MessageManager
4315 .getString("label.select_newick_like_tree_file"));
4316 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4318 int value = chooser.showOpenDialog(null);
4320 if (value == JalviewFileChooser.APPROVE_OPTION)
4322 String choice = chooser.getSelectedFile().getPath();
4323 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4324 jalview.io.NewickFile fin = null;
4327 fin = new NewickFile(choice, DataSourceType.FILE);
4328 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4329 } catch (Exception ex)
4336 .getString("label.problem_reading_tree_file"),
4337 JOptionPane.WARNING_MESSAGE);
4338 ex.printStackTrace();
4340 if (fin != null && fin.hasWarningMessage())
4342 JOptionPane.showMessageDialog(Desktop.desktop, fin
4343 .getWarningMessage(), MessageManager
4344 .getString("label.possible_problem_with_tree_file"),
4345 JOptionPane.WARNING_MESSAGE);
4351 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4353 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4356 public TreePanel ShowNewickTree(NewickFile nf, String title)
4358 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4361 public TreePanel ShowNewickTree(NewickFile nf, String title,
4362 AlignmentView input)
4364 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4367 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4368 int h, int x, int y)
4370 return ShowNewickTree(nf, title, null, w, h, x, y);
4374 * Add a treeviewer for the tree extracted from a newick file object to the
4375 * current alignment view
4382 * Associated alignment input data (or null)
4391 * @return TreePanel handle
4393 public TreePanel ShowNewickTree(NewickFile nf, String title,
4394 AlignmentView input, int w, int h, int x, int y)
4396 TreePanel tp = null;
4402 if (nf.getTree() != null)
4404 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4410 tp.setLocation(x, y);
4413 Desktop.addInternalFrame(tp, title, w, h);
4415 } catch (Exception ex)
4417 ex.printStackTrace();
4423 private boolean buildingMenu = false;
4426 * Generates menu items and listener event actions for web service clients
4429 public void BuildWebServiceMenu()
4431 while (buildingMenu)
4435 System.err.println("Waiting for building menu to finish.");
4437 } catch (Exception e)
4441 final AlignFrame me = this;
4442 buildingMenu = true;
4443 new Thread(new Runnable()
4448 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4451 // System.err.println("Building ws menu again "
4452 // + Thread.currentThread());
4453 // TODO: add support for context dependent disabling of services based
4455 // alignment and current selection
4456 // TODO: add additional serviceHandle parameter to specify abstract
4458 // class independently of AbstractName
4459 // TODO: add in rediscovery GUI function to restart discoverer
4460 // TODO: group services by location as well as function and/or
4462 // object broker mechanism.
4463 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4464 final IProgressIndicator af = me;
4465 final JMenu msawsmenu = new JMenu("Alignment");
4466 final JMenu secstrmenu = new JMenu(
4467 "Secondary Structure Prediction");
4468 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4469 final JMenu analymenu = new JMenu("Analysis");
4470 final JMenu dismenu = new JMenu("Protein Disorder");
4471 // final JMenu msawsmenu = new
4472 // JMenu(MessageManager.getString("label.alignment"));
4473 // final JMenu secstrmenu = new
4474 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4475 // final JMenu seqsrchmenu = new
4476 // JMenu(MessageManager.getString("label.sequence_database_search"));
4477 // final JMenu analymenu = new
4478 // JMenu(MessageManager.getString("label.analysis"));
4479 // final JMenu dismenu = new
4480 // JMenu(MessageManager.getString("label.protein_disorder"));
4481 // JAL-940 - only show secondary structure prediction services from
4482 // the legacy server
4483 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4485 Discoverer.services != null && (Discoverer.services.size() > 0))
4487 // TODO: refactor to allow list of AbstractName/Handler bindings to
4489 // stored or retrieved from elsewhere
4490 // No MSAWS used any more:
4491 // Vector msaws = null; // (Vector)
4492 // Discoverer.services.get("MsaWS");
4493 Vector secstrpr = (Vector) Discoverer.services
4495 if (secstrpr != null)
4497 // Add any secondary structure prediction services
4498 for (int i = 0, j = secstrpr.size(); i < j; i++)
4500 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4502 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4503 .getServiceClient(sh);
4504 int p = secstrmenu.getItemCount();
4505 impl.attachWSMenuEntry(secstrmenu, me);
4506 int q = secstrmenu.getItemCount();
4507 for (int litm = p; litm < q; litm++)
4509 legacyItems.add(secstrmenu.getItem(litm));
4515 // Add all submenus in the order they should appear on the web
4517 wsmenu.add(msawsmenu);
4518 wsmenu.add(secstrmenu);
4519 wsmenu.add(dismenu);
4520 wsmenu.add(analymenu);
4521 // No search services yet
4522 // wsmenu.add(seqsrchmenu);
4524 javax.swing.SwingUtilities.invokeLater(new Runnable()
4531 webService.removeAll();
4532 // first, add discovered services onto the webservices menu
4533 if (wsmenu.size() > 0)
4535 for (int i = 0, j = wsmenu.size(); i < j; i++)
4537 webService.add(wsmenu.get(i));
4542 webService.add(me.webServiceNoServices);
4544 // TODO: move into separate menu builder class.
4545 boolean new_sspred = false;
4546 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4548 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4549 if (jws2servs != null)
4551 if (jws2servs.hasServices())
4553 jws2servs.attachWSMenuEntry(webService, me);
4554 for (Jws2Instance sv : jws2servs.getServices())
4556 if (sv.description.toLowerCase().contains("jpred"))
4558 for (JMenuItem jmi : legacyItems)
4560 jmi.setVisible(false);
4566 if (jws2servs.isRunning())
4568 JMenuItem tm = new JMenuItem(
4569 "Still discovering JABA Services");
4570 tm.setEnabled(false);
4575 build_urlServiceMenu(me.webService);
4576 build_fetchdbmenu(webService);
4577 for (JMenu item : wsmenu)
4579 if (item.getItemCount() == 0)
4581 item.setEnabled(false);
4585 item.setEnabled(true);
4588 } catch (Exception e)
4591 .debug("Exception during web service menu building process.",
4596 } catch (Exception e)
4599 buildingMenu = false;
4606 * construct any groupURL type service menu entries.
4610 private void build_urlServiceMenu(JMenu webService)
4612 // TODO: remove this code when 2.7 is released
4613 // DEBUG - alignmentView
4615 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4616 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4618 * @Override public void actionPerformed(ActionEvent e) {
4619 * jalview.datamodel.AlignmentView
4620 * .testSelectionViews(af.viewport.getAlignment(),
4621 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4623 * }); webService.add(testAlView);
4625 // TODO: refactor to RestClient discoverer and merge menu entries for
4626 // rest-style services with other types of analysis/calculation service
4627 // SHmmr test client - still being implemented.
4628 // DEBUG - alignmentView
4630 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4633 client.attachWSMenuEntry(
4634 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4640 * Searches selected sequences for xRef products and builds the Show
4641 * Cross-References menu (formerly called Show Products)
4643 * @return true if Show Cross-references menu should be enabled.
4645 public boolean canShowProducts()
4647 SequenceI[] selection = viewport.getSequenceSelection();
4648 AlignmentI dataset = viewport.getAlignment().getDataset();
4649 boolean showp = false;
4652 showProducts.removeAll();
4653 final boolean dna = viewport.getAlignment().isNucleotide();
4654 String[] ptypes = (selection == null || selection.length == 0) ? null
4655 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4657 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4660 final AlignFrame af = this;
4661 final String source = ptypes[t];
4662 JMenuItem xtype = new JMenuItem(ptypes[t]);
4663 xtype.addActionListener(new ActionListener()
4667 public void actionPerformed(ActionEvent e)
4669 showProductsFor(af.viewport.getSequenceSelection(), dna, source);
4673 showProducts.add(xtype);
4675 showProducts.setVisible(showp);
4676 showProducts.setEnabled(showp);
4677 } catch (Exception e)
4679 jalview.bin.Cache.log
4680 .warn("canShowProducts threw an exception - please report to help@jalview.org",
4688 * Finds and displays cross-references for the selected sequences (protein
4689 * products for nucleotide sequences, dna coding sequences for peptides).
4692 * the sequences to show cross-references for
4694 * true if from a nucleotide alignment (so showing proteins)
4696 * the database to show cross-references for
4698 protected void showProductsFor(final SequenceI[] sel, final boolean dna,
4699 final String source)
4701 Runnable foo = new Runnable()
4707 final long sttime = System.currentTimeMillis();
4708 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4709 "status.searching_for_sequences_from",
4710 new Object[] { source }), sttime);
4713 AlignmentI alignment = AlignFrame.this.getViewport()
4715 AlignmentI xrefs = CrossRef.findXrefSequences(sel, dna, source,
4720 * get display scheme (if any) to apply to features
4722 FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
4723 .getFeatureColourScheme(source);
4725 AlignmentI al = makeCrossReferencesAlignment(
4726 alignment.getDataset(), xrefs);
4728 AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH,
4730 if (Cache.getDefault("HIDE_INTRONS", true))
4732 newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
4734 String newtitle = String.format("%s %s %s",
4735 MessageManager.getString(dna ? "label.proteins"
4736 : "label.nucleotides"), MessageManager
4737 .getString("label.for"), getTitle());
4738 newFrame.setTitle(newtitle);
4740 if (!Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4743 * split frame display is turned off in preferences file
4745 Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
4747 return; // via finally clause
4751 * Make a copy of this alignment (sharing the same dataset
4752 * sequences). If we are DNA, drop introns and update mappings
4754 AlignmentI copyAlignment = null;
4755 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4756 .getSequenceSelection();
4757 List<AlignedCodonFrame> cf = xrefs.getCodonFrames();
4758 boolean copyAlignmentIsAligned = false;
4761 copyAlignment = AlignmentUtils.makeCdsAlignment(
4762 sequenceSelection, cf, alignment);
4763 if (copyAlignment.getHeight() == 0)
4765 System.err.println("Failed to make CDS alignment");
4767 al.getCodonFrames().clear();
4768 al.addCodonFrames(copyAlignment.getCodonFrames());
4769 al.addCodonFrames(cf);
4772 * pending getting Embl transcripts to 'align',
4773 * we are only doing this for Ensembl
4775 // TODO proper criteria for 'can align as cdna'
4776 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
4777 || AlignmentUtils.looksLikeEnsembl(alignment))
4779 copyAlignment.alignAs(alignment);
4780 copyAlignmentIsAligned = true;
4785 copyAlignment = AlignmentUtils.makeCopyAlignment(
4786 sequenceSelection, xrefs.getSequencesArray());
4787 copyAlignment.addCodonFrames(cf);
4788 al.addCodonFrames(copyAlignment.getCodonFrames());
4789 al.addCodonFrames(cf);
4791 copyAlignment.setGapCharacter(AlignFrame.this.viewport
4792 .getGapCharacter());
4794 StructureSelectionManager ssm = StructureSelectionManager
4795 .getStructureSelectionManager(Desktop.instance);
4796 ssm.registerMappings(cf);
4798 if (copyAlignment.getHeight() <= 0)
4800 System.err.println("No Sequences generated for xRef type "
4805 * align protein to dna
4807 if (dna && copyAlignmentIsAligned)
4809 al.alignAs(copyAlignment);
4814 * align cdna to protein - currently only if
4815 * fetching and aligning Ensembl transcripts!
4817 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source))
4819 copyAlignment.alignAs(al);
4823 AlignFrame copyThis = new AlignFrame(copyAlignment,
4824 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4825 copyThis.setTitle(AlignFrame.this.getTitle());
4827 boolean showSequenceFeatures = viewport
4828 .isShowSequenceFeatures();
4829 newFrame.setShowSeqFeatures(showSequenceFeatures);
4830 copyThis.setShowSeqFeatures(showSequenceFeatures);
4831 FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
4832 .getFeatureRenderer();
4835 * copy feature rendering settings to split frame
4837 newFrame.alignPanel.getSeqPanel().seqCanvas
4838 .getFeatureRenderer()
4839 .transferSettings(myFeatureStyling);
4840 copyThis.alignPanel.getSeqPanel().seqCanvas
4841 .getFeatureRenderer()
4842 .transferSettings(myFeatureStyling);
4845 * apply 'database source' feature configuration
4848 // TODO is this the feature colouring for the original
4849 // alignment or the fetched xrefs? either could be Ensembl
4850 newFrame.getViewport().applyFeaturesStyle(featureColourScheme);
4851 copyThis.getViewport().applyFeaturesStyle(featureColourScheme);
4853 SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
4854 dna ? newFrame : copyThis);
4855 newFrame.setVisible(true);
4856 copyThis.setVisible(true);
4857 String linkedTitle = MessageManager
4858 .getString("label.linked_view_title");
4859 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4862 } catch (Exception e)
4864 Cache.log.error("Exception when finding crossreferences", e);
4865 } catch (OutOfMemoryError e)
4867 new OOMWarning("whilst fetching crossreferences", e);
4868 } catch (Throwable e)
4870 Cache.log.error("Error when finding crossreferences", e);
4873 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4874 "status.finished_searching_for_sequences_from",
4875 new Object[] { source }), sttime);
4880 * Makes an alignment containing the given sequences. If this is of the
4881 * same type as the given dataset (nucleotide/protein), then the new
4882 * alignment shares the same dataset, and its dataset sequences are added
4883 * to it. Otherwise a new dataset sequence is created for the
4890 protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
4893 boolean sameType = dataset.isNucleotide() == seqs.isNucleotide();
4895 SequenceI[] sprods = new SequenceI[seqs.getHeight()];
4896 for (int s = 0; s < sprods.length; s++)
4898 sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
4901 if (dataset.getSequences() == null
4902 || !dataset.getSequences().contains(
4903 sprods[s].getDatasetSequence()))
4905 dataset.addSequence(sprods[s].getDatasetSequence());
4908 sprods[s].updatePDBIds();
4910 Alignment al = new Alignment(sprods);
4913 al.setDataset((Alignment) dataset);
4917 al.createDatasetAlignment();
4923 Thread frunner = new Thread(foo);
4928 * Construct and display a new frame containing the translation of this
4929 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4932 public void showTranslation_actionPerformed(ActionEvent e)
4934 AlignmentI al = null;
4937 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4939 al = dna.translateCdna();
4940 } catch (Exception ex)
4942 jalview.bin.Cache.log.error(
4943 "Exception during translation. Please report this !", ex);
4944 final String msg = MessageManager
4945 .getString("label.error_when_translating_sequences_submit_bug_report");
4946 final String errorTitle = MessageManager
4947 .getString("label.implementation_error")
4948 + MessageManager.getString("label.translation_failed");
4949 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4950 JOptionPane.ERROR_MESSAGE);
4953 if (al == null || al.getHeight() == 0)
4955 final String msg = MessageManager
4956 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4957 final String errorTitle = MessageManager
4958 .getString("label.translation_failed");
4959 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4960 JOptionPane.WARNING_MESSAGE);
4964 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4965 af.setFileFormat(this.currentFileFormat);
4966 final String newTitle = MessageManager.formatMessage(
4967 "label.translation_of_params",
4968 new Object[] { this.getTitle() });
4969 af.setTitle(newTitle);
4970 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4972 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4973 viewport.openSplitFrame(af, new Alignment(seqs));
4977 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4984 * Set the file format
4988 public void setFileFormat(FileFormatI format)
4990 this.currentFileFormat = format;
4994 * Try to load a features file onto the alignment.
4997 * contents or path to retrieve file
4999 * access mode of file (see jalview.io.AlignFile)
5000 * @return true if features file was parsed correctly.
5002 public boolean parseFeaturesFile(String file, DataSourceType sourceType)
5004 return avc.parseFeaturesFile(file, sourceType,
5005 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5010 public void refreshFeatureUI(boolean enableIfNecessary)
5012 // note - currently this is only still here rather than in the controller
5013 // because of the featureSettings hard reference that is yet to be
5015 if (enableIfNecessary)
5017 viewport.setShowSequenceFeatures(true);
5018 showSeqFeatures.setSelected(true);
5024 public void dragEnter(DropTargetDragEvent evt)
5029 public void dragExit(DropTargetEvent evt)
5034 public void dragOver(DropTargetDragEvent evt)
5039 public void dropActionChanged(DropTargetDragEvent evt)
5044 public void drop(DropTargetDropEvent evt)
5046 Transferable t = evt.getTransferable();
5047 List<String> files = new ArrayList<String>();
5048 List<DataSourceType> protocols = new ArrayList<DataSourceType>();
5052 Desktop.transferFromDropTarget(files, protocols, evt, t);
5053 } catch (Exception e)
5055 e.printStackTrace();
5061 // check to see if any of these files have names matching sequences in
5063 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5064 .getAlignment().getSequencesArray());
5066 * Object[] { String,SequenceI}
5068 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5069 ArrayList<String> filesnotmatched = new ArrayList<String>();
5070 for (int i = 0; i < files.size(); i++)
5072 String file = files.get(i).toString();
5074 DataSourceType protocol = FormatAdapter.checkProtocol(file);
5075 if (protocol == DataSourceType.FILE)
5077 File fl = new File(file);
5078 pdbfn = fl.getName();
5080 else if (protocol == DataSourceType.URL)
5082 URL url = new URL(file);
5083 pdbfn = url.getFile();
5085 if (pdbfn.length() > 0)
5087 // attempt to find a match in the alignment
5088 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5089 int l = 0, c = pdbfn.indexOf(".");
5090 while (mtch == null && c != -1)
5095 } while ((c = pdbfn.indexOf(".", l)) > l);
5098 pdbfn = pdbfn.substring(0, l);
5100 mtch = idm.findAllIdMatches(pdbfn);
5104 FileFormatI type = null;
5107 type = new IdentifyFile().identify(file, protocol);
5108 } catch (Exception ex)
5114 if (type == FileFormat.PDB)
5116 filesmatched.add(new Object[] { file, protocol, mtch });
5121 // File wasn't named like one of the sequences or wasn't a PDB file.
5122 filesnotmatched.add(file);
5126 if (filesmatched.size() > 0)
5128 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5134 "label.automatically_associate_pdb_files_with_sequences_same_name",
5135 new Object[] { Integer
5141 .getString("label.automatically_associate_pdb_files_by_name"),
5142 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5145 for (Object[] fm : filesmatched)
5147 // try and associate
5148 // TODO: may want to set a standard ID naming formalism for
5149 // associating PDB files which have no IDs.
5150 for (SequenceI toassoc : (SequenceI[]) fm[2])
5152 PDBEntry pe = new AssociatePdbFileWithSeq()
5153 .associatePdbWithSeq((String) fm[0],
5154 (DataSourceType) fm[1], toassoc, false,
5158 System.err.println("Associated file : "
5159 + ((String) fm[0]) + " with "
5160 + toassoc.getDisplayId(true));
5164 alignPanel.paintAlignment(true);
5168 if (filesnotmatched.size() > 0)
5171 && (Cache.getDefault(
5172 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5178 "label.ignore_unmatched_dropped_files_info",
5179 new Object[] { Integer
5186 .getString("label.ignore_unmatched_dropped_files"),
5187 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5191 for (String fn : filesnotmatched)
5193 loadJalviewDataFile(fn, null, null, null);
5197 } catch (Exception ex)
5199 ex.printStackTrace();
5205 * Attempt to load a "dropped" file or URL string: First by testing whether
5206 * it's an Annotation file, then a JNet file, and finally a features file. If
5207 * all are false then the user may have dropped an alignment file onto this
5211 * either a filename or a URL string.
5213 public void loadJalviewDataFile(String file, DataSourceType sourceType,
5214 FileFormatI format, SequenceI assocSeq)
5218 if (sourceType == null)
5220 sourceType = FormatAdapter.checkProtocol(file);
5222 // if the file isn't identified, or not positively identified as some
5223 // other filetype (PFAM is default unidentified alignment file type) then
5224 // try to parse as annotation.
5225 boolean isAnnotation = (format == null || format == FileFormat.Pfam) ? new AnnotationFile()
5226 .annotateAlignmentView(viewport, file, sourceType) : false;
5230 // first see if its a T-COFFEE score file
5231 TCoffeeScoreFile tcf = null;
5234 tcf = new TCoffeeScoreFile(file, sourceType);
5237 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5239 tcoffeeColour.setEnabled(true);
5240 tcoffeeColour.setSelected(true);
5241 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5242 isAnnotation = true;
5244 .setText(MessageManager
5245 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5249 // some problem - if no warning its probable that the ID matching
5250 // process didn't work
5254 tcf.getWarningMessage() == null ? MessageManager
5255 .getString("label.check_file_matches_sequence_ids_alignment")
5256 : tcf.getWarningMessage(),
5258 .getString("label.problem_reading_tcoffee_score_file"),
5259 JOptionPane.WARNING_MESSAGE);
5266 } catch (Exception x)
5269 .debug("Exception when processing data source as T-COFFEE score file",
5275 // try to see if its a JNet 'concise' style annotation file *before*
5277 // try to parse it as a features file
5280 format = new IdentifyFile().identify(file, sourceType);
5282 if (format == FileFormat.Jnet)
5284 JPredFile predictions = new JPredFile(
5286 new JnetAnnotationMaker();
5287 JnetAnnotationMaker.add_annotation(predictions,
5288 viewport.getAlignment(), 0, false);
5289 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5290 viewport.getAlignment().setSeqrep(repseq);
5291 ColumnSelection cs = new ColumnSelection();
5292 cs.hideInsertionsFor(repseq);
5293 viewport.setColumnSelection(cs);
5294 isAnnotation = true;
5296 else if (IdentifyFile.FeaturesFile.equals(format))
5298 if (parseFeaturesFile(file, sourceType))
5300 alignPanel.paintAlignment(true);
5305 new FileLoader().LoadFile(viewport, file, sourceType, format);
5312 alignPanel.adjustAnnotationHeight();
5313 viewport.updateSequenceIdColours();
5314 buildSortByAnnotationScoresMenu();
5315 alignPanel.paintAlignment(true);
5317 } catch (Exception ex)
5319 ex.printStackTrace();
5320 } catch (OutOfMemoryError oom)
5325 } catch (Exception x)
5330 + (sourceType != null ? (sourceType == DataSourceType.PASTE ? "from clipboard."
5331 : "using " + sourceType + " from " + file)
5333 + (format != null ? "(parsing as '" + format
5334 + "' file)" : ""), oom, Desktop.desktop);
5339 * Method invoked by the ChangeListener on the tabbed pane, in other words
5340 * when a different tabbed pane is selected by the user or programmatically.
5343 public void tabSelectionChanged(int index)
5347 alignPanel = alignPanels.get(index);
5348 viewport = alignPanel.av;
5349 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5350 setMenusFromViewport(viewport);
5354 * If there is a frame linked to this one in a SplitPane, switch it to the
5355 * same view tab index. No infinite recursion of calls should happen, since
5356 * tabSelectionChanged() should not get invoked on setting the selected
5357 * index to an unchanged value. Guard against setting an invalid index
5358 * before the new view peer tab has been created.
5360 final AlignViewportI peer = viewport.getCodingComplement();
5363 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5364 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5366 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5372 * On right mouse click on view tab, prompt for and set new view name.
5375 public void tabbedPane_mousePressed(MouseEvent e)
5377 if (e.isPopupTrigger())
5379 String msg = MessageManager.getString("label.enter_view_name");
5380 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5381 JOptionPane.QUESTION_MESSAGE);
5385 viewport.viewName = reply;
5386 // TODO warn if reply is in getExistingViewNames()?
5387 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5392 public AlignViewport getCurrentView()
5398 * Open the dialog for regex description parsing.
5401 protected void extractScores_actionPerformed(ActionEvent e)
5403 ParseProperties pp = new jalview.analysis.ParseProperties(
5404 viewport.getAlignment());
5405 // TODO: verify regex and introduce GUI dialog for version 2.5
5406 // if (pp.getScoresFromDescription("col", "score column ",
5407 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5409 if (pp.getScoresFromDescription("description column",
5410 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5412 buildSortByAnnotationScoresMenu();
5420 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5424 protected void showDbRefs_actionPerformed(ActionEvent e)
5426 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5432 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5436 protected void showNpFeats_actionPerformed(ActionEvent e)
5438 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5442 * find the viewport amongst the tabs in this alignment frame and close that
5447 public boolean closeView(AlignViewportI av)
5451 this.closeMenuItem_actionPerformed(false);
5454 Component[] comp = tabbedPane.getComponents();
5455 for (int i = 0; comp != null && i < comp.length; i++)
5457 if (comp[i] instanceof AlignmentPanel)
5459 if (((AlignmentPanel) comp[i]).av == av)
5462 closeView((AlignmentPanel) comp[i]);
5470 protected void build_fetchdbmenu(JMenu webService)
5472 // Temporary hack - DBRef Fetcher always top level ws entry.
5473 // TODO We probably want to store a sequence database checklist in
5474 // preferences and have checkboxes.. rather than individual sources selected
5476 final JMenu rfetch = new JMenu(
5477 MessageManager.getString("action.fetch_db_references"));
5478 rfetch.setToolTipText(MessageManager
5479 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5480 webService.add(rfetch);
5482 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5483 MessageManager.getString("option.trim_retrieved_seqs"));
5484 trimrs.setToolTipText(MessageManager
5485 .getString("label.trim_retrieved_sequences"));
5486 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5487 trimrs.addActionListener(new ActionListener()
5490 public void actionPerformed(ActionEvent e)
5492 trimrs.setSelected(trimrs.isSelected());
5493 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5494 Boolean.valueOf(trimrs.isSelected()).toString());
5498 JMenuItem fetchr = new JMenuItem(
5499 MessageManager.getString("label.standard_databases"));
5500 fetchr.setToolTipText(MessageManager
5501 .getString("label.fetch_embl_uniprot"));
5502 fetchr.addActionListener(new ActionListener()
5506 public void actionPerformed(ActionEvent e)
5508 new Thread(new Runnable()
5513 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5514 .getAlignment().isNucleotide();
5515 DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
5516 .getSequenceSelection(), alignPanel.alignFrame, null,
5517 alignPanel.alignFrame.featureSettings, isNucleotide);
5518 dbRefFetcher.addListener(new FetchFinishedListenerI()
5521 public void finished()
5523 AlignFrame.this.setMenusForViewport();
5526 dbRefFetcher.fetchDBRefs(false);
5534 final AlignFrame me = this;
5535 new Thread(new Runnable()
5540 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5541 .getSequenceFetcherSingleton(me);
5542 javax.swing.SwingUtilities.invokeLater(new Runnable()
5547 String[] dbclasses = sf.getOrderedSupportedSources();
5548 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5549 // jalview.util.QuickSort.sort(otherdb, otherdb);
5550 List<DbSourceProxy> otherdb;
5551 JMenu dfetch = new JMenu();
5552 JMenu ifetch = new JMenu();
5553 JMenuItem fetchr = null;
5554 int comp = 0, icomp = 0, mcomp = 15;
5555 String mname = null;
5557 for (String dbclass : dbclasses)
5559 otherdb = sf.getSourceProxy(dbclass);
5560 // add a single entry for this class, or submenu allowing 'fetch
5562 if (otherdb == null || otherdb.size() < 1)
5566 // List<DbSourceProxy> dbs=otherdb;
5567 // otherdb=new ArrayList<DbSourceProxy>();
5568 // for (DbSourceProxy db:dbs)
5570 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5574 mname = "From " + dbclass;
5576 if (otherdb.size() == 1)
5578 final DbSourceProxy[] dassource = otherdb
5579 .toArray(new DbSourceProxy[0]);
5580 DbSourceProxy src = otherdb.get(0);
5581 fetchr = new JMenuItem(src.getDbSource());
5582 fetchr.addActionListener(new ActionListener()
5586 public void actionPerformed(ActionEvent e)
5588 new Thread(new Runnable()
5594 boolean isNucleotide = alignPanel.alignFrame
5595 .getViewport().getAlignment()
5597 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5598 alignPanel.av.getSequenceSelection(),
5599 alignPanel.alignFrame, dassource,
5600 alignPanel.alignFrame.featureSettings,
5603 .addListener(new FetchFinishedListenerI()
5606 public void finished()
5608 AlignFrame.this.setMenusForViewport();
5611 dbRefFetcher.fetchDBRefs(false);
5617 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5618 MessageManager.formatMessage(
5619 "label.fetch_retrieve_from",
5620 new Object[] { src.getDbName() })));
5626 final DbSourceProxy[] dassource = otherdb
5627 .toArray(new DbSourceProxy[0]);
5629 DbSourceProxy src = otherdb.get(0);
5630 fetchr = new JMenuItem(MessageManager.formatMessage(
5631 "label.fetch_all_param",
5632 new Object[] { src.getDbSource() }));
5633 fetchr.addActionListener(new ActionListener()
5636 public void actionPerformed(ActionEvent e)
5638 new Thread(new Runnable()
5644 boolean isNucleotide = alignPanel.alignFrame
5645 .getViewport().getAlignment()
5647 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5648 alignPanel.av.getSequenceSelection(),
5649 alignPanel.alignFrame, dassource,
5650 alignPanel.alignFrame.featureSettings,
5653 .addListener(new FetchFinishedListenerI()
5656 public void finished()
5658 AlignFrame.this.setMenusForViewport();
5661 dbRefFetcher.fetchDBRefs(false);
5667 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5668 MessageManager.formatMessage(
5669 "label.fetch_retrieve_from_all_sources",
5671 Integer.valueOf(otherdb.size())
5672 .toString(), src.getDbSource(),
5673 src.getDbName() })));
5676 // and then build the rest of the individual menus
5677 ifetch = new JMenu(MessageManager.formatMessage(
5678 "label.source_from_db_source",
5679 new Object[] { src.getDbSource() }));
5681 String imname = null;
5683 for (DbSourceProxy sproxy : otherdb)
5685 String dbname = sproxy.getDbName();
5686 String sname = dbname.length() > 5 ? dbname.substring(0,
5687 5) + "..." : dbname;
5688 String msname = dbname.length() > 10 ? dbname.substring(
5689 0, 10) + "..." : dbname;
5692 imname = MessageManager.formatMessage(
5693 "label.from_msname", new Object[] { sname });
5695 fetchr = new JMenuItem(msname);
5696 final DbSourceProxy[] dassrc = { sproxy };
5697 fetchr.addActionListener(new ActionListener()
5701 public void actionPerformed(ActionEvent e)
5703 new Thread(new Runnable()
5709 boolean isNucleotide = alignPanel.alignFrame
5710 .getViewport().getAlignment()
5712 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5713 alignPanel.av.getSequenceSelection(),
5714 alignPanel.alignFrame, dassrc,
5715 alignPanel.alignFrame.featureSettings,
5718 .addListener(new FetchFinishedListenerI()
5721 public void finished()
5723 AlignFrame.this.setMenusForViewport();
5726 dbRefFetcher.fetchDBRefs(false);
5732 fetchr.setToolTipText("<html>"
5733 + MessageManager.formatMessage(
5734 "label.fetch_retrieve_from", new Object[]
5738 if (++icomp >= mcomp || i == (otherdb.size()))
5740 ifetch.setText(MessageManager.formatMessage(
5741 "label.source_to_target", imname, sname));
5743 ifetch = new JMenu();
5751 if (comp >= mcomp || dbi >= (dbclasses.length))
5753 dfetch.setText(MessageManager.formatMessage(
5754 "label.source_to_target", mname, dbclass));
5756 dfetch = new JMenu();
5769 * Left justify the whole alignment.
5772 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5774 AlignmentI al = viewport.getAlignment();
5776 viewport.firePropertyChange("alignment", null, al);
5780 * Right justify the whole alignment.
5783 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5785 AlignmentI al = viewport.getAlignment();
5787 viewport.firePropertyChange("alignment", null, al);
5791 public void setShowSeqFeatures(boolean b)
5793 showSeqFeatures.setSelected(b);
5794 viewport.setShowSequenceFeatures(b);
5801 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5802 * awt.event.ActionEvent)
5805 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5807 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5808 alignPanel.paintAlignment(true);
5815 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5819 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5821 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5822 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5830 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5831 * .event.ActionEvent)
5834 protected void showGroupConservation_actionPerformed(ActionEvent e)
5836 viewport.setShowGroupConservation(showGroupConservation.getState());
5837 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5844 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5845 * .event.ActionEvent)
5848 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5850 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5851 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5858 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5859 * .event.ActionEvent)
5862 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5864 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5865 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5869 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5871 showSequenceLogo.setState(true);
5872 viewport.setShowSequenceLogo(true);
5873 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5874 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5878 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5880 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5887 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5888 * .event.ActionEvent)
5891 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5893 if (avc.makeGroupsFromSelection())
5895 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5896 alignPanel.updateAnnotation();
5897 alignPanel.paintAlignment(true);
5901 public void clearAlignmentSeqRep()
5903 // TODO refactor alignmentseqrep to controller
5904 if (viewport.getAlignment().hasSeqrep())
5906 viewport.getAlignment().setSeqrep(null);
5907 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5908 alignPanel.updateAnnotation();
5909 alignPanel.paintAlignment(true);
5914 protected void createGroup_actionPerformed(ActionEvent e)
5916 if (avc.createGroup())
5918 alignPanel.alignmentChanged();
5923 protected void unGroup_actionPerformed(ActionEvent e)
5927 alignPanel.alignmentChanged();
5932 * make the given alignmentPanel the currently selected tab
5934 * @param alignmentPanel
5936 public void setDisplayedView(AlignmentPanel alignmentPanel)
5938 if (!viewport.getSequenceSetId().equals(
5939 alignmentPanel.av.getSequenceSetId()))
5943 .getString("error.implementation_error_cannot_show_view_alignment_frame"));
5945 if (tabbedPane != null
5946 && tabbedPane.getTabCount() > 0
5947 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5948 .getSelectedIndex())
5950 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5955 * Action on selection of menu options to Show or Hide annotations.
5958 * @param forSequences
5959 * update sequence-related annotations
5960 * @param forAlignment
5961 * update non-sequence-related annotations
5964 protected void setAnnotationsVisibility(boolean visible,
5965 boolean forSequences, boolean forAlignment)
5967 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5968 .getAlignmentAnnotation();
5973 for (AlignmentAnnotation aa : anns)
5976 * don't display non-positional annotations on an alignment
5978 if (aa.annotations == null)
5982 boolean apply = (aa.sequenceRef == null && forAlignment)
5983 || (aa.sequenceRef != null && forSequences);
5986 aa.visible = visible;
5989 alignPanel.validateAnnotationDimensions(true);
5990 alignPanel.alignmentChanged();
5994 * Store selected annotation sort order for the view and repaint.
5997 protected void sortAnnotations_actionPerformed()
5999 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6001 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6002 alignPanel.paintAlignment(true);
6007 * @return alignment panels in this alignment frame
6009 public List<? extends AlignmentViewPanel> getAlignPanels()
6011 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
6015 * Open a new alignment window, with the cDNA associated with this (protein)
6016 * alignment, aligned as is the protein.
6018 protected void viewAsCdna_actionPerformed()
6020 // TODO no longer a menu action - refactor as required
6021 final AlignmentI alignment = getViewport().getAlignment();
6022 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6023 if (mappings == null)
6027 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6028 for (SequenceI aaSeq : alignment.getSequences())
6030 for (AlignedCodonFrame acf : mappings)
6032 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6036 * There is a cDNA mapping for this protein sequence - add to new
6037 * alignment. It will share the same dataset sequence as other mapped
6038 * cDNA (no new mappings need to be created).
6040 final Sequence newSeq = new Sequence(dnaSeq);
6041 newSeq.setDatasetSequence(dnaSeq);
6042 cdnaSeqs.add(newSeq);
6046 if (cdnaSeqs.size() == 0)
6048 // show a warning dialog no mapped cDNA
6051 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6053 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6054 AlignFrame.DEFAULT_HEIGHT);
6055 cdna.alignAs(alignment);
6056 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6058 Desktop.addInternalFrame(alignFrame, newtitle,
6059 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
6063 * Set visibility of dna/protein complement view (available when shown in a
6069 protected void showComplement_actionPerformed(boolean show)
6071 SplitContainerI sf = getSplitViewContainer();
6074 sf.setComplementVisible(this, show);
6079 * Generate the reverse (optionally complemented) of the selected sequences,
6080 * and add them to the alignment
6083 protected void showReverse_actionPerformed(boolean complement)
6085 AlignmentI al = null;
6088 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
6089 al = dna.reverseCdna(complement);
6090 viewport.addAlignment(al, "");
6091 addHistoryItem(new EditCommand(
6092 MessageManager.getString("label.add_sequences"),
6093 Action.PASTE, al.getSequencesArray(), 0, al.getWidth(),
6094 viewport.getAlignment()));
6095 } catch (Exception ex)
6097 System.err.println(ex.getMessage());
6103 * Try to run a script in the Groovy console, having first ensured that this
6104 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
6105 * be targeted at this alignment.
6108 protected void runGroovy_actionPerformed()
6110 Jalview.setCurrentAlignFrame(this);
6111 groovy.ui.Console console = Desktop.getGroovyConsole();
6112 if (console != null)
6116 console.runScript();
6117 } catch (Exception ex)
6119 System.err.println((ex.toString()));
6121 .showInternalMessageDialog(Desktop.desktop, MessageManager
6122 .getString("label.couldnt_run_groovy_script"),
6124 .getString("label.groovy_support_failed"),
6125 JOptionPane.ERROR_MESSAGE);
6130 System.err.println("Can't run Groovy script as console not found");
6135 * Hides columns containing (or not containing) a specified feature, provided
6136 * that would not leave all columns hidden
6138 * @param featureType
6139 * @param columnsContaining
6142 public boolean hideFeatureColumns(String featureType,
6143 boolean columnsContaining)
6145 boolean notForHiding = avc.markColumnsContainingFeatures(
6146 columnsContaining, false, false, featureType);
6149 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
6150 false, featureType))
6152 getViewport().hideSelectedColumns();
6160 class PrintThread extends Thread
6164 public PrintThread(AlignmentPanel ap)
6169 static PageFormat pf;
6174 PrinterJob printJob = PrinterJob.getPrinterJob();
6178 printJob.setPrintable(ap, pf);
6182 printJob.setPrintable(ap);
6185 if (printJob.printDialog())
6190 } catch (Exception PrintException)
6192 PrintException.printStackTrace();