2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.FeatureSettingsModelI;
36 import jalview.api.SplitContainerI;
37 import jalview.api.ViewStyleI;
38 import jalview.api.analysis.ScoreModelI;
39 import jalview.bin.Cache;
40 import jalview.bin.Jalview;
41 import jalview.commands.CommandI;
42 import jalview.commands.EditCommand;
43 import jalview.commands.EditCommand.Action;
44 import jalview.commands.OrderCommand;
45 import jalview.commands.RemoveGapColCommand;
46 import jalview.commands.RemoveGapsCommand;
47 import jalview.commands.SlideSequencesCommand;
48 import jalview.commands.TrimRegionCommand;
49 import jalview.datamodel.AlignedCodonFrame;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentExportData;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.AlignmentOrder;
55 import jalview.datamodel.AlignmentView;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.DBRefSource;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.PDBEntry;
60 import jalview.datamodel.SeqCigar;
61 import jalview.datamodel.Sequence;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
65 import jalview.io.AlignmentProperties;
66 import jalview.io.AnnotationFile;
67 import jalview.io.BioJsHTMLOutput;
68 import jalview.io.FileLoader;
69 import jalview.io.FormatAdapter;
70 import jalview.io.HtmlSvgOutput;
71 import jalview.io.IdentifyFile;
72 import jalview.io.JalviewFileChooser;
73 import jalview.io.JalviewFileView;
74 import jalview.io.JnetAnnotationMaker;
75 import jalview.io.NewickFile;
76 import jalview.io.TCoffeeScoreFile;
77 import jalview.jbgui.GAlignFrame;
78 import jalview.schemes.Blosum62ColourScheme;
79 import jalview.schemes.BuriedColourScheme;
80 import jalview.schemes.ClustalxColourScheme;
81 import jalview.schemes.ColourSchemeI;
82 import jalview.schemes.ColourSchemeProperty;
83 import jalview.schemes.HelixColourScheme;
84 import jalview.schemes.HydrophobicColourScheme;
85 import jalview.schemes.NucleotideColourScheme;
86 import jalview.schemes.PIDColourScheme;
87 import jalview.schemes.PurinePyrimidineColourScheme;
88 import jalview.schemes.RNAHelicesColourChooser;
89 import jalview.schemes.ResidueProperties;
90 import jalview.schemes.StrandColourScheme;
91 import jalview.schemes.TCoffeeColourScheme;
92 import jalview.schemes.TaylorColourScheme;
93 import jalview.schemes.TurnColourScheme;
94 import jalview.schemes.UserColourScheme;
95 import jalview.schemes.ZappoColourScheme;
96 import jalview.structure.StructureSelectionManager;
97 import jalview.util.MessageManager;
98 import jalview.viewmodel.AlignmentViewport;
99 import jalview.ws.DBRefFetcher;
100 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
101 import jalview.ws.SequenceFetcher;
102 import jalview.ws.jws1.Discoverer;
103 import jalview.ws.jws2.Jws2Discoverer;
104 import jalview.ws.jws2.jabaws2.Jws2Instance;
105 import jalview.ws.seqfetcher.ASequenceFetcher;
106 import jalview.ws.seqfetcher.DbSourceProxy;
108 import java.awt.BorderLayout;
109 import java.awt.Component;
110 import java.awt.Rectangle;
111 import java.awt.Toolkit;
112 import java.awt.datatransfer.Clipboard;
113 import java.awt.datatransfer.DataFlavor;
114 import java.awt.datatransfer.StringSelection;
115 import java.awt.datatransfer.Transferable;
116 import java.awt.dnd.DnDConstants;
117 import java.awt.dnd.DropTargetDragEvent;
118 import java.awt.dnd.DropTargetDropEvent;
119 import java.awt.dnd.DropTargetEvent;
120 import java.awt.dnd.DropTargetListener;
121 import java.awt.event.ActionEvent;
122 import java.awt.event.ActionListener;
123 import java.awt.event.ItemEvent;
124 import java.awt.event.ItemListener;
125 import java.awt.event.KeyAdapter;
126 import java.awt.event.KeyEvent;
127 import java.awt.event.MouseAdapter;
128 import java.awt.event.MouseEvent;
129 import java.awt.print.PageFormat;
130 import java.awt.print.PrinterJob;
131 import java.beans.PropertyChangeEvent;
134 import java.util.ArrayList;
135 import java.util.Arrays;
136 import java.util.Deque;
137 import java.util.Enumeration;
138 import java.util.Hashtable;
139 import java.util.List;
140 import java.util.Vector;
142 import javax.swing.JCheckBoxMenuItem;
143 import javax.swing.JEditorPane;
144 import javax.swing.JInternalFrame;
145 import javax.swing.JLayeredPane;
146 import javax.swing.JMenu;
147 import javax.swing.JMenuItem;
148 import javax.swing.JOptionPane;
149 import javax.swing.JRadioButtonMenuItem;
150 import javax.swing.JScrollPane;
151 import javax.swing.SwingUtilities;
157 * @version $Revision$
159 public class AlignFrame extends GAlignFrame implements DropTargetListener,
160 IProgressIndicator, AlignViewControllerGuiI
163 public static final int DEFAULT_WIDTH = 700;
165 public static final int DEFAULT_HEIGHT = 500;
168 * The currently displayed panel (selected tabbed view if more than one)
170 public AlignmentPanel alignPanel;
172 AlignViewport viewport;
174 public AlignViewControllerI avc;
176 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
179 * Last format used to load or save alignments in this window
181 String currentFileFormat = null;
184 * Current filename for this alignment
186 String fileName = null;
189 * Creates a new AlignFrame object with specific width and height.
195 public AlignFrame(AlignmentI al, int width, int height)
197 this(al, null, width, height);
201 * Creates a new AlignFrame object with specific width, height and
207 * @param sequenceSetId
209 public AlignFrame(AlignmentI al, int width, int height,
210 String sequenceSetId)
212 this(al, null, width, height, sequenceSetId);
216 * Creates a new AlignFrame object with specific width, height and
222 * @param sequenceSetId
225 public AlignFrame(AlignmentI al, int width, int height,
226 String sequenceSetId, String viewId)
228 this(al, null, width, height, sequenceSetId, viewId);
232 * new alignment window with hidden columns
236 * @param hiddenColumns
237 * ColumnSelection or null
239 * Width of alignment frame
243 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
244 int width, int height)
246 this(al, hiddenColumns, width, height, null);
250 * Create alignment frame for al with hiddenColumns, a specific width and
251 * height, and specific sequenceId
254 * @param hiddenColumns
257 * @param sequenceSetId
260 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
261 int width, int height, String sequenceSetId)
263 this(al, hiddenColumns, width, height, sequenceSetId, null);
267 * Create alignment frame for al with hiddenColumns, a specific width and
268 * height, and specific sequenceId
271 * @param hiddenColumns
274 * @param sequenceSetId
279 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
280 int width, int height, String sequenceSetId, String viewId)
282 setSize(width, height);
284 if (al.getDataset() == null)
289 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
291 alignPanel = new AlignmentPanel(this, viewport);
293 addAlignmentPanel(alignPanel, true);
297 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
298 ColumnSelection hiddenColumns, int width, int height)
300 setSize(width, height);
302 if (al.getDataset() == null)
307 viewport = new AlignViewport(al, hiddenColumns);
309 if (hiddenSeqs != null && hiddenSeqs.length > 0)
311 viewport.hideSequence(hiddenSeqs);
313 alignPanel = new AlignmentPanel(this, viewport);
314 addAlignmentPanel(alignPanel, true);
319 * Make a new AlignFrame from existing alignmentPanels
326 public AlignFrame(AlignmentPanel ap)
330 addAlignmentPanel(ap, false);
335 * initalise the alignframe from the underlying viewport data and the
340 if (!Jalview.isHeadlessMode())
342 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
345 avc = new jalview.controller.AlignViewController(this, viewport,
347 if (viewport.getAlignmentConservationAnnotation() == null)
349 BLOSUM62Colour.setEnabled(false);
350 conservationMenuItem.setEnabled(false);
351 modifyConservation.setEnabled(false);
352 // PIDColour.setEnabled(false);
353 // abovePIDThreshold.setEnabled(false);
354 // modifyPID.setEnabled(false);
357 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
360 if (sortby.equals("Id"))
362 sortIDMenuItem_actionPerformed(null);
364 else if (sortby.equals("Pairwise Identity"))
366 sortPairwiseMenuItem_actionPerformed(null);
369 if (Desktop.desktop != null)
371 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
372 addServiceListeners();
373 setGUINucleotide(viewport.getAlignment().isNucleotide());
377 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
379 setMenusFromViewport(viewport);
380 buildSortByAnnotationScoresMenu();
383 if (viewport.getWrapAlignment())
385 wrapMenuItem_actionPerformed(null);
388 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
390 this.overviewMenuItem_actionPerformed(null);
395 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
396 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
397 final String menuLabel = MessageManager
398 .getString("label.copy_format_from");
399 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
400 new ViewSetProvider()
404 public AlignmentPanel[] getAllAlignmentPanels()
407 origview.add(alignPanel);
408 // make an array of all alignment panels except for this one
409 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
410 Arrays.asList(Desktop.getAlignmentPanels(null)));
411 aps.remove(AlignFrame.this.alignPanel);
412 return aps.toArray(new AlignmentPanel[aps.size()]);
414 }, selviews, new ItemListener()
418 public void itemStateChanged(ItemEvent e)
420 if (origview.size() > 0)
422 final AlignmentPanel ap = origview.get(0);
425 * Copy the ViewStyle of the selected panel to 'this one'.
426 * Don't change value of 'scaleProteinAsCdna' unless copying
429 ViewStyleI vs = selviews.get(0).getAlignViewport()
431 boolean fromSplitFrame = selviews.get(0)
432 .getAlignViewport().getCodingComplement() != null;
435 vs.setScaleProteinAsCdna(ap.getAlignViewport()
436 .getViewStyle().isScaleProteinAsCdna());
438 ap.getAlignViewport().setViewStyle(vs);
441 * Also rescale ViewStyle of SplitFrame complement if there is
442 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
443 * the whole ViewStyle (allow cDNA protein to have different
446 AlignViewportI complement = ap.getAlignViewport()
447 .getCodingComplement();
448 if (complement != null && vs.isScaleProteinAsCdna())
450 AlignFrame af = Desktop.getAlignFrameFor(complement);
451 ((SplitFrame) af.getSplitViewContainer())
453 af.setMenusForViewport();
457 ap.setSelected(true);
458 ap.alignFrame.setMenusForViewport();
463 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
464 .indexOf("devel") > -1
465 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
466 .indexOf("test") > -1)
468 formatMenu.add(vsel);
474 * Change the filename and format for the alignment, and enable the 'reload'
475 * button functionality.
482 public void setFileName(String file, String format)
485 setFileFormat(format);
486 reload.setEnabled(true);
490 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
493 void addKeyListener()
495 addKeyListener(new KeyAdapter()
498 public void keyPressed(KeyEvent evt)
500 if (viewport.cursorMode
501 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
502 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
503 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
504 && Character.isDigit(evt.getKeyChar()))
506 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
509 switch (evt.getKeyCode())
512 case 27: // escape key
513 deselectAllSequenceMenuItem_actionPerformed(null);
517 case KeyEvent.VK_DOWN:
518 if (evt.isAltDown() || !viewport.cursorMode)
520 moveSelectedSequences(false);
522 if (viewport.cursorMode)
524 alignPanel.getSeqPanel().moveCursor(0, 1);
529 if (evt.isAltDown() || !viewport.cursorMode)
531 moveSelectedSequences(true);
533 if (viewport.cursorMode)
535 alignPanel.getSeqPanel().moveCursor(0, -1);
540 case KeyEvent.VK_LEFT:
541 if (evt.isAltDown() || !viewport.cursorMode)
543 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
547 alignPanel.getSeqPanel().moveCursor(-1, 0);
552 case KeyEvent.VK_RIGHT:
553 if (evt.isAltDown() || !viewport.cursorMode)
555 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
559 alignPanel.getSeqPanel().moveCursor(1, 0);
563 case KeyEvent.VK_SPACE:
564 if (viewport.cursorMode)
566 alignPanel.getSeqPanel().insertGapAtCursor(
567 evt.isControlDown() || evt.isShiftDown()
572 // case KeyEvent.VK_A:
573 // if (viewport.cursorMode)
575 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
576 // //System.out.println("A");
580 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
581 * System.out.println("closing bracket"); } break;
583 case KeyEvent.VK_DELETE:
584 case KeyEvent.VK_BACK_SPACE:
585 if (!viewport.cursorMode)
587 cut_actionPerformed(null);
591 alignPanel.getSeqPanel().deleteGapAtCursor(
592 evt.isControlDown() || evt.isShiftDown()
599 if (viewport.cursorMode)
601 alignPanel.getSeqPanel().setCursorRow();
605 if (viewport.cursorMode && !evt.isControlDown())
607 alignPanel.getSeqPanel().setCursorColumn();
611 if (viewport.cursorMode)
613 alignPanel.getSeqPanel().setCursorPosition();
617 case KeyEvent.VK_ENTER:
618 case KeyEvent.VK_COMMA:
619 if (viewport.cursorMode)
621 alignPanel.getSeqPanel().setCursorRowAndColumn();
626 if (viewport.cursorMode)
628 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
632 if (viewport.cursorMode)
634 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
639 viewport.cursorMode = !viewport.cursorMode;
640 statusBar.setText(MessageManager.formatMessage(
641 "label.keyboard_editing_mode",
642 new String[] { (viewport.cursorMode ? "on" : "off") }));
643 if (viewport.cursorMode)
645 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
646 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
648 alignPanel.getSeqPanel().seqCanvas.repaint();
654 Help.showHelpWindow();
655 } catch (Exception ex)
657 ex.printStackTrace();
662 boolean toggleSeqs = !evt.isControlDown();
663 boolean toggleCols = !evt.isShiftDown();
664 toggleHiddenRegions(toggleSeqs, toggleCols);
667 case KeyEvent.VK_PAGE_UP:
668 if (viewport.getWrapAlignment())
670 alignPanel.scrollUp(true);
674 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
675 - viewport.endSeq + viewport.startSeq);
678 case KeyEvent.VK_PAGE_DOWN:
679 if (viewport.getWrapAlignment())
681 alignPanel.scrollUp(false);
685 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
686 + viewport.endSeq - viewport.startSeq);
693 public void keyReleased(KeyEvent evt)
695 switch (evt.getKeyCode())
697 case KeyEvent.VK_LEFT:
698 if (evt.isAltDown() || !viewport.cursorMode)
700 viewport.firePropertyChange("alignment", null, viewport
701 .getAlignment().getSequences());
705 case KeyEvent.VK_RIGHT:
706 if (evt.isAltDown() || !viewport.cursorMode)
708 viewport.firePropertyChange("alignment", null, viewport
709 .getAlignment().getSequences());
717 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
719 ap.alignFrame = this;
720 avc = new jalview.controller.AlignViewController(this, viewport,
725 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
727 int aSize = alignPanels.size();
729 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
731 if (aSize == 1 && ap.av.viewName == null)
733 this.getContentPane().add(ap, BorderLayout.CENTER);
739 setInitialTabVisible();
742 expandViews.setEnabled(true);
743 gatherViews.setEnabled(true);
744 tabbedPane.addTab(ap.av.viewName, ap);
746 ap.setVisible(false);
751 if (ap.av.isPadGaps())
753 ap.av.getAlignment().padGaps();
755 ap.av.updateConservation(ap);
756 ap.av.updateConsensus(ap);
757 ap.av.updateStrucConsensus(ap);
761 public void setInitialTabVisible()
763 expandViews.setEnabled(true);
764 gatherViews.setEnabled(true);
765 tabbedPane.setVisible(true);
766 AlignmentPanel first = alignPanels.get(0);
767 tabbedPane.addTab(first.av.viewName, first);
768 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
771 public AlignViewport getViewport()
776 /* Set up intrinsic listeners for dynamically generated GUI bits. */
777 private void addServiceListeners()
779 final java.beans.PropertyChangeListener thisListener;
780 Desktop.instance.addJalviewPropertyChangeListener("services",
781 thisListener = new java.beans.PropertyChangeListener()
784 public void propertyChange(PropertyChangeEvent evt)
786 // // System.out.println("Discoverer property change.");
787 // if (evt.getPropertyName().equals("services"))
789 SwingUtilities.invokeLater(new Runnable()
796 .println("Rebuild WS Menu for service change");
797 BuildWebServiceMenu();
804 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
807 public void internalFrameClosed(
808 javax.swing.event.InternalFrameEvent evt)
810 // System.out.println("deregistering discoverer listener");
811 Desktop.instance.removeJalviewPropertyChangeListener("services",
813 closeMenuItem_actionPerformed(true);
816 // Finally, build the menu once to get current service state
817 new Thread(new Runnable()
822 BuildWebServiceMenu();
828 * Configure menu items that vary according to whether the alignment is
829 * nucleotide or protein
833 public void setGUINucleotide(boolean nucleotide)
835 showTranslation.setVisible(nucleotide);
836 showReverse.setVisible(nucleotide);
837 showReverseComplement.setVisible(nucleotide);
838 conservationMenuItem.setEnabled(!nucleotide);
839 modifyConservation.setEnabled(!nucleotide);
840 showGroupConservation.setEnabled(!nucleotide);
841 rnahelicesColour.setEnabled(nucleotide);
842 purinePyrimidineColour.setEnabled(nucleotide);
843 showComplementMenuItem.setText(MessageManager
844 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
845 setColourSelected(jalview.bin.Cache.getDefault(
846 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
847 : Preferences.DEFAULT_COLOUR_PROT, "None"));
851 * set up menus for the current viewport. This may be called after any
852 * operation that affects the data in the current view (selection changed,
853 * etc) to update the menus to reflect the new state.
856 public void setMenusForViewport()
858 setMenusFromViewport(viewport);
862 * Need to call this method when tabs are selected for multiple views, or when
863 * loading from Jalview2XML.java
868 void setMenusFromViewport(AlignViewport av)
870 padGapsMenuitem.setSelected(av.isPadGaps());
871 colourTextMenuItem.setSelected(av.isShowColourText());
872 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
873 conservationMenuItem.setSelected(av.getConservationSelected());
874 seqLimits.setSelected(av.getShowJVSuffix());
875 idRightAlign.setSelected(av.isRightAlignIds());
876 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
877 renderGapsMenuItem.setSelected(av.isRenderGaps());
878 wrapMenuItem.setSelected(av.getWrapAlignment());
879 scaleAbove.setVisible(av.getWrapAlignment());
880 scaleLeft.setVisible(av.getWrapAlignment());
881 scaleRight.setVisible(av.getWrapAlignment());
882 annotationPanelMenuItem.setState(av.isShowAnnotation());
884 * Show/hide annotations only enabled if annotation panel is shown
886 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
887 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
888 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
889 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
890 viewBoxesMenuItem.setSelected(av.getShowBoxes());
891 viewTextMenuItem.setSelected(av.getShowText());
892 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
893 showGroupConsensus.setSelected(av.isShowGroupConsensus());
894 showGroupConservation.setSelected(av.isShowGroupConservation());
895 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
896 showSequenceLogo.setSelected(av.isShowSequenceLogo());
897 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
899 setColourSelected(ColourSchemeProperty.getColourName(av
900 .getGlobalColourScheme()));
902 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
903 hiddenMarkers.setState(av.getShowHiddenMarkers());
904 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
905 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
906 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
907 autoCalculate.setSelected(av.autoCalculateConsensus);
908 sortByTree.setSelected(av.sortByTree);
909 listenToViewSelections.setSelected(av.followSelection);
910 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
912 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
914 showProducts.setEnabled(canShowProducts());
919 private IProgressIndicator progressBar;
924 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
927 public void setProgressBar(String message, long id)
929 progressBar.setProgressBar(message, id);
933 public void registerHandler(final long id,
934 final IProgressIndicatorHandler handler)
936 progressBar.registerHandler(id, handler);
941 * @return true if any progress bars are still active
944 public boolean operationInProgress()
946 return progressBar.operationInProgress();
950 public void setStatus(String text)
952 statusBar.setText(text);
956 * Added so Castor Mapping file can obtain Jalview Version
958 public String getVersion()
960 return jalview.bin.Cache.getProperty("VERSION");
963 public FeatureRenderer getFeatureRenderer()
965 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
969 public void fetchSequence_actionPerformed(ActionEvent e)
971 new jalview.gui.SequenceFetcher(this);
975 public void addFromFile_actionPerformed(ActionEvent e)
977 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
981 public void reload_actionPerformed(ActionEvent e)
983 if (fileName != null)
985 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
986 // originating file's format
987 // TODO: work out how to recover feature settings for correct view(s) when
989 if (currentFileFormat.equals("Jalview"))
991 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
992 for (int i = 0; i < frames.length; i++)
994 if (frames[i] instanceof AlignFrame && frames[i] != this
995 && ((AlignFrame) frames[i]).fileName != null
996 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1000 frames[i].setSelected(true);
1001 Desktop.instance.closeAssociatedWindows();
1002 } catch (java.beans.PropertyVetoException ex)
1008 Desktop.instance.closeAssociatedWindows();
1010 FileLoader loader = new FileLoader();
1011 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1012 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1016 Rectangle bounds = this.getBounds();
1018 FileLoader loader = new FileLoader();
1019 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1020 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1021 protocol, currentFileFormat);
1023 newframe.setBounds(bounds);
1024 if (featureSettings != null && featureSettings.isShowing())
1026 final Rectangle fspos = featureSettings.frame.getBounds();
1027 // TODO: need a 'show feature settings' function that takes bounds -
1028 // need to refactor Desktop.addFrame
1029 newframe.featureSettings_actionPerformed(null);
1030 final FeatureSettings nfs = newframe.featureSettings;
1031 SwingUtilities.invokeLater(new Runnable()
1036 nfs.frame.setBounds(fspos);
1039 this.featureSettings.close();
1040 this.featureSettings = null;
1042 this.closeMenuItem_actionPerformed(true);
1048 public void addFromText_actionPerformed(ActionEvent e)
1050 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1055 public void addFromURL_actionPerformed(ActionEvent e)
1057 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1061 public void save_actionPerformed(ActionEvent e)
1063 if (fileName == null
1064 || (currentFileFormat == null || !jalview.io.FormatAdapter
1065 .isValidIOFormat(currentFileFormat, true))
1066 || fileName.startsWith("http"))
1068 saveAs_actionPerformed(null);
1072 saveAlignment(fileName, currentFileFormat);
1083 public void saveAs_actionPerformed(ActionEvent e)
1085 JalviewFileChooser chooser = new JalviewFileChooser(
1086 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1087 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1088 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1089 currentFileFormat, false);
1091 chooser.setFileView(new JalviewFileView());
1092 chooser.setDialogTitle(MessageManager
1093 .getString("label.save_alignment_to_file"));
1094 chooser.setToolTipText(MessageManager.getString("action.save"));
1096 int value = chooser.showSaveDialog(this);
1098 if (value == JalviewFileChooser.APPROVE_OPTION)
1100 currentFileFormat = chooser.getSelectedFormat();
1101 while (currentFileFormat == null)
1104 .showInternalMessageDialog(
1107 .getString("label.select_file_format_before_saving"),
1109 .getString("label.file_format_not_specified"),
1110 JOptionPane.WARNING_MESSAGE);
1111 currentFileFormat = chooser.getSelectedFormat();
1112 value = chooser.showSaveDialog(this);
1113 if (value != JalviewFileChooser.APPROVE_OPTION)
1119 fileName = chooser.getSelectedFile().getPath();
1121 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1124 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1125 if (currentFileFormat.indexOf(" ") > -1)
1127 currentFileFormat = currentFileFormat.substring(0,
1128 currentFileFormat.indexOf(" "));
1130 saveAlignment(fileName, currentFileFormat);
1134 public boolean saveAlignment(String file, String format)
1136 boolean success = true;
1138 if (format.equalsIgnoreCase("Jalview"))
1140 String shortName = title;
1142 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1144 shortName = shortName.substring(shortName
1145 .lastIndexOf(java.io.File.separatorChar) + 1);
1148 success = new Jalview2XML().saveAlignment(this, file, shortName);
1150 statusBar.setText(MessageManager.formatMessage(
1151 "label.successfully_saved_to_file_in_format", new Object[] {
1152 fileName, format }));
1157 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1159 warningMessage("Cannot save file " + fileName + " using format "
1160 + format, "Alignment output format not supported");
1161 if (!Jalview.isHeadlessMode())
1163 saveAs_actionPerformed(null);
1168 AlignmentExportData exportData = getAlignmentForExport(format,
1170 if (exportData.getSettings().isCancelled())
1174 FormatAdapter f = new FormatAdapter(alignPanel,
1175 exportData.getSettings());
1176 String output = f.formatSequences(
1178 exportData.getAlignment(), // class cast exceptions will
1179 // occur in the distant future
1180 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1181 f.getCacheSuffixDefault(format),
1182 viewport.getColumnSelection());
1192 java.io.PrintWriter out = new java.io.PrintWriter(
1193 new java.io.FileWriter(file));
1197 this.setTitle(file);
1198 statusBar.setText(MessageManager.formatMessage(
1199 "label.successfully_saved_to_file_in_format",
1200 new Object[] { fileName, format }));
1201 } catch (Exception ex)
1204 ex.printStackTrace();
1211 JOptionPane.showInternalMessageDialog(this, MessageManager
1212 .formatMessage("label.couldnt_save_file",
1213 new Object[] { fileName }), MessageManager
1214 .getString("label.error_saving_file"),
1215 JOptionPane.WARNING_MESSAGE);
1221 private void warningMessage(String warning, String title)
1223 if (new jalview.util.Platform().isHeadless())
1225 System.err.println("Warning: " + title + "\nWarning: " + warning);
1230 JOptionPane.showInternalMessageDialog(this, warning, title,
1231 JOptionPane.WARNING_MESSAGE);
1243 protected void outputText_actionPerformed(ActionEvent e)
1246 AlignmentExportData exportData = getAlignmentForExport(
1247 e.getActionCommand(), viewport, null);
1248 if (exportData.getSettings().isCancelled())
1252 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1253 cap.setForInput(null);
1256 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1257 .formatSequences(e.getActionCommand(),
1258 exportData.getAlignment(),
1259 exportData.getOmitHidden(),
1260 exportData.getStartEndPostions(),
1261 viewport.getColumnSelection()));
1262 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1263 "label.alignment_output_command",
1264 new Object[] { e.getActionCommand() }), 600, 500);
1265 } catch (OutOfMemoryError oom)
1267 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1273 public static AlignmentExportData getAlignmentForExport(
1274 String exportFormat, AlignViewportI viewport,
1275 AlignExportSettingI exportSettings)
1277 AlignmentI alignmentToExport = null;
1278 AlignExportSettingI settings = exportSettings;
1279 String[] omitHidden = null;
1280 int[] alignmentStartEnd = new int[2];
1282 HiddenSequences hiddenSeqs = viewport.getAlignment()
1283 .getHiddenSequences();
1285 alignmentToExport = viewport.getAlignment();
1286 alignmentStartEnd = new int[] { 0, alignmentToExport.getWidth() - 1 };
1288 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1289 if (settings == null)
1291 settings = new AlignExportSettings(hasHiddenSeqs,
1292 viewport.hasHiddenColumns(), exportFormat);
1294 // settings.isExportAnnotations();
1296 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1298 omitHidden = viewport.getViewAsString(false);
1301 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1303 alignmentToExport = hiddenSeqs.getFullAlignment();
1307 alignmentToExport = viewport.getAlignment();
1308 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1309 .getColumnSelection().getHiddenColumns());
1311 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1312 omitHidden, alignmentStartEnd, settings);
1316 public static int[] getStartEnd(int[] aligmentStartEnd,
1317 List<int[]> hiddenCols)
1319 int startPos = aligmentStartEnd[0];
1320 int endPos = aligmentStartEnd[1];
1322 int[] lowestRange = new int[] { -1, -1 };
1323 int[] higestRange = new int[] { -1, -1 };
1325 for (int[] hiddenCol : hiddenCols)
1327 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1328 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1331 if (lowestRange[0] == -1 && lowestRange[1] == -1)
1333 startPos = aligmentStartEnd[0];
1337 startPos = lowestRange[1] + 1;
1340 if (higestRange[0] == -1 && higestRange[1] == -1)
1342 endPos = aligmentStartEnd[1];
1346 endPos = higestRange[0] - 1;
1349 // System.out.println("Export range : " + startPos + " - " + endPos);
1350 return new int[] { startPos, endPos };
1353 public static void main(String[] args)
1355 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1356 hiddenCols.add(new int[] { 0, 0 });
1357 hiddenCols.add(new int[] { 6, 9 });
1358 hiddenCols.add(new int[] { 11, 12 });
1359 hiddenCols.add(new int[] { 33, 33 });
1360 hiddenCols.add(new int[] { 50, 50 });
1362 int[] x = getStartEnd(new int[] { 0, 50 }, hiddenCols);
1363 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1373 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1375 new HtmlSvgOutput(null, alignPanel);
1379 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1381 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
1382 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1385 public void createImageMap(File file, String image)
1387 alignPanel.makePNGImageMap(file, image);
1397 public void createPNG(File f)
1399 alignPanel.makePNG(f);
1409 public void createEPS(File f)
1411 alignPanel.makeEPS(f);
1415 public void createSVG(File f)
1417 alignPanel.makeSVG(f);
1421 public void pageSetup_actionPerformed(ActionEvent e)
1423 PrinterJob printJob = PrinterJob.getPrinterJob();
1424 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1434 public void printMenuItem_actionPerformed(ActionEvent e)
1436 // Putting in a thread avoids Swing painting problems
1437 PrintThread thread = new PrintThread(alignPanel);
1442 public void exportFeatures_actionPerformed(ActionEvent e)
1444 new AnnotationExporter().exportFeatures(alignPanel);
1448 public void exportAnnotations_actionPerformed(ActionEvent e)
1450 new AnnotationExporter().exportAnnotations(alignPanel);
1454 public void associatedData_actionPerformed(ActionEvent e)
1456 // Pick the tree file
1457 JalviewFileChooser chooser = new JalviewFileChooser(
1458 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1459 chooser.setFileView(new JalviewFileView());
1460 chooser.setDialogTitle(MessageManager
1461 .getString("label.load_jalview_annotations"));
1462 chooser.setToolTipText(MessageManager
1463 .getString("label.load_jalview_annotations"));
1465 int value = chooser.showOpenDialog(null);
1467 if (value == JalviewFileChooser.APPROVE_OPTION)
1469 String choice = chooser.getSelectedFile().getPath();
1470 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1471 loadJalviewDataFile(choice, null, null, null);
1477 * Close the current view or all views in the alignment frame. If the frame
1478 * only contains one view then the alignment will be removed from memory.
1480 * @param closeAllTabs
1483 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1485 if (alignPanels != null && alignPanels.size() < 2)
1487 closeAllTabs = true;
1492 if (alignPanels != null)
1496 if (this.isClosed())
1498 // really close all the windows - otherwise wait till
1499 // setClosed(true) is called
1500 for (int i = 0; i < alignPanels.size(); i++)
1502 AlignmentPanel ap = alignPanels.get(i);
1509 closeView(alignPanel);
1516 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1517 * be called recursively, with the frame now in 'closed' state
1519 this.setClosed(true);
1521 } catch (Exception ex)
1523 ex.printStackTrace();
1528 * Close the specified panel and close up tabs appropriately.
1530 * @param panelToClose
1532 public void closeView(AlignmentPanel panelToClose)
1534 int index = tabbedPane.getSelectedIndex();
1535 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1536 alignPanels.remove(panelToClose);
1537 panelToClose.closePanel();
1538 panelToClose = null;
1540 tabbedPane.removeTabAt(closedindex);
1541 tabbedPane.validate();
1543 if (index > closedindex || index == tabbedPane.getTabCount())
1545 // modify currently selected tab index if necessary.
1549 this.tabSelectionChanged(index);
1555 void updateEditMenuBar()
1558 if (viewport.getHistoryList().size() > 0)
1560 undoMenuItem.setEnabled(true);
1561 CommandI command = viewport.getHistoryList().peek();
1562 undoMenuItem.setText(MessageManager.formatMessage(
1563 "label.undo_command",
1564 new Object[] { command.getDescription() }));
1568 undoMenuItem.setEnabled(false);
1569 undoMenuItem.setText(MessageManager.getString("action.undo"));
1572 if (viewport.getRedoList().size() > 0)
1574 redoMenuItem.setEnabled(true);
1576 CommandI command = viewport.getRedoList().peek();
1577 redoMenuItem.setText(MessageManager.formatMessage(
1578 "label.redo_command",
1579 new Object[] { command.getDescription() }));
1583 redoMenuItem.setEnabled(false);
1584 redoMenuItem.setText(MessageManager.getString("action.redo"));
1589 public void addHistoryItem(CommandI command)
1591 if (command.getSize() > 0)
1593 viewport.addToHistoryList(command);
1594 viewport.clearRedoList();
1595 updateEditMenuBar();
1596 viewport.updateHiddenColumns();
1597 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1598 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1599 // viewport.getColumnSelection()
1600 // .getHiddenColumns().size() > 0);
1606 * @return alignment objects for all views
1608 AlignmentI[] getViewAlignments()
1610 if (alignPanels != null)
1612 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1614 for (AlignmentPanel ap : alignPanels)
1616 als[i++] = ap.av.getAlignment();
1620 if (viewport != null)
1622 return new AlignmentI[] { viewport.getAlignment() };
1634 protected void undoMenuItem_actionPerformed(ActionEvent e)
1636 if (viewport.getHistoryList().isEmpty())
1640 CommandI command = viewport.getHistoryList().pop();
1641 viewport.addToRedoList(command);
1642 command.undoCommand(getViewAlignments());
1644 AlignmentViewport originalSource = getOriginatingSource(command);
1645 updateEditMenuBar();
1647 if (originalSource != null)
1649 if (originalSource != viewport)
1652 .warn("Implementation worry: mismatch of viewport origin for undo");
1654 originalSource.updateHiddenColumns();
1655 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1657 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1658 // viewport.getColumnSelection()
1659 // .getHiddenColumns().size() > 0);
1660 originalSource.firePropertyChange("alignment", null, originalSource
1661 .getAlignment().getSequences());
1672 protected void redoMenuItem_actionPerformed(ActionEvent e)
1674 if (viewport.getRedoList().size() < 1)
1679 CommandI command = viewport.getRedoList().pop();
1680 viewport.addToHistoryList(command);
1681 command.doCommand(getViewAlignments());
1683 AlignmentViewport originalSource = getOriginatingSource(command);
1684 updateEditMenuBar();
1686 if (originalSource != null)
1689 if (originalSource != viewport)
1692 .warn("Implementation worry: mismatch of viewport origin for redo");
1694 originalSource.updateHiddenColumns();
1695 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1697 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1698 // viewport.getColumnSelection()
1699 // .getHiddenColumns().size() > 0);
1700 originalSource.firePropertyChange("alignment", null, originalSource
1701 .getAlignment().getSequences());
1705 AlignmentViewport getOriginatingSource(CommandI command)
1707 AlignmentViewport originalSource = null;
1708 // For sequence removal and addition, we need to fire
1709 // the property change event FROM the viewport where the
1710 // original alignment was altered
1711 AlignmentI al = null;
1712 if (command instanceof EditCommand)
1714 EditCommand editCommand = (EditCommand) command;
1715 al = editCommand.getAlignment();
1716 List<Component> comps = PaintRefresher.components.get(viewport
1717 .getSequenceSetId());
1719 for (Component comp : comps)
1721 if (comp instanceof AlignmentPanel)
1723 if (al == ((AlignmentPanel) comp).av.getAlignment())
1725 originalSource = ((AlignmentPanel) comp).av;
1732 if (originalSource == null)
1734 // The original view is closed, we must validate
1735 // the current view against the closed view first
1738 PaintRefresher.validateSequences(al, viewport.getAlignment());
1741 originalSource = viewport;
1744 return originalSource;
1753 public void moveSelectedSequences(boolean up)
1755 SequenceGroup sg = viewport.getSelectionGroup();
1761 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1762 viewport.getHiddenRepSequences(), up);
1763 alignPanel.paintAlignment(true);
1766 synchronized void slideSequences(boolean right, int size)
1768 List<SequenceI> sg = new ArrayList<SequenceI>();
1769 if (viewport.cursorMode)
1771 sg.add(viewport.getAlignment().getSequenceAt(
1772 alignPanel.getSeqPanel().seqCanvas.cursorY));
1774 else if (viewport.getSelectionGroup() != null
1775 && viewport.getSelectionGroup().getSize() != viewport
1776 .getAlignment().getHeight())
1778 sg = viewport.getSelectionGroup().getSequences(
1779 viewport.getHiddenRepSequences());
1787 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1789 for (SequenceI seq : viewport.getAlignment().getSequences())
1791 if (!sg.contains(seq))
1793 invertGroup.add(seq);
1797 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1799 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1800 for (int i = 0; i < invertGroup.size(); i++)
1802 seqs2[i] = invertGroup.get(i);
1805 SlideSequencesCommand ssc;
1808 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1809 size, viewport.getGapCharacter());
1813 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1814 size, viewport.getGapCharacter());
1817 int groupAdjustment = 0;
1818 if (ssc.getGapsInsertedBegin() && right)
1820 if (viewport.cursorMode)
1822 alignPanel.getSeqPanel().moveCursor(size, 0);
1826 groupAdjustment = size;
1829 else if (!ssc.getGapsInsertedBegin() && !right)
1831 if (viewport.cursorMode)
1833 alignPanel.getSeqPanel().moveCursor(-size, 0);
1837 groupAdjustment = -size;
1841 if (groupAdjustment != 0)
1843 viewport.getSelectionGroup().setStartRes(
1844 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1845 viewport.getSelectionGroup().setEndRes(
1846 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1850 * just extend the last slide command if compatible; but not if in
1851 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1853 boolean appendHistoryItem = false;
1854 Deque<CommandI> historyList = viewport.getHistoryList();
1855 boolean inSplitFrame = getSplitViewContainer() != null;
1856 if (!inSplitFrame && historyList != null && historyList.size() > 0
1857 && historyList.peek() instanceof SlideSequencesCommand)
1859 appendHistoryItem = ssc
1860 .appendSlideCommand((SlideSequencesCommand) historyList
1864 if (!appendHistoryItem)
1866 addHistoryItem(ssc);
1879 protected void copy_actionPerformed(ActionEvent e)
1882 if (viewport.getSelectionGroup() == null)
1886 // TODO: preserve the ordering of displayed alignment annotation in any
1887 // internal paste (particularly sequence associated annotation)
1888 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1889 String[] omitHidden = null;
1891 if (viewport.hasHiddenColumns())
1893 omitHidden = viewport.getViewAsString(true);
1896 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1899 StringSelection ss = new StringSelection(output);
1903 jalview.gui.Desktop.internalCopy = true;
1904 // Its really worth setting the clipboard contents
1905 // to empty before setting the large StringSelection!!
1906 Toolkit.getDefaultToolkit().getSystemClipboard()
1907 .setContents(new StringSelection(""), null);
1909 Toolkit.getDefaultToolkit().getSystemClipboard()
1910 .setContents(ss, Desktop.instance);
1911 } catch (OutOfMemoryError er)
1913 new OOMWarning("copying region", er);
1917 ArrayList<int[]> hiddenColumns = null;
1918 if (viewport.hasHiddenColumns())
1920 hiddenColumns = new ArrayList<int[]>();
1921 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1922 .getSelectionGroup().getEndRes();
1923 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1925 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1927 hiddenColumns.add(new int[] { region[0] - hiddenOffset,
1928 region[1] - hiddenOffset });
1933 Desktop.jalviewClipboard = new Object[] { seqs,
1934 viewport.getAlignment().getDataset(), hiddenColumns };
1935 statusBar.setText(MessageManager.formatMessage(
1936 "label.copied_sequences_to_clipboard", new Object[] { Integer
1937 .valueOf(seqs.length).toString() }));
1947 protected void pasteNew_actionPerformed(ActionEvent e)
1959 protected void pasteThis_actionPerformed(ActionEvent e)
1965 * Paste contents of Jalview clipboard
1967 * @param newAlignment
1968 * true to paste to a new alignment, otherwise add to this.
1970 void paste(boolean newAlignment)
1972 boolean externalPaste = true;
1975 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1976 Transferable contents = c.getContents(this);
1978 if (contents == null)
1986 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1987 if (str.length() < 1)
1992 format = new IdentifyFile().identify(str, "Paste");
1994 } catch (OutOfMemoryError er)
1996 new OOMWarning("Out of memory pasting sequences!!", er);
2000 SequenceI[] sequences;
2001 boolean annotationAdded = false;
2002 AlignmentI alignment = null;
2004 if (Desktop.jalviewClipboard != null)
2006 // The clipboard was filled from within Jalview, we must use the
2008 // And dataset from the copied alignment
2009 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2010 // be doubly sure that we create *new* sequence objects.
2011 sequences = new SequenceI[newseq.length];
2012 for (int i = 0; i < newseq.length; i++)
2014 sequences[i] = new Sequence(newseq[i]);
2016 alignment = new Alignment(sequences);
2017 externalPaste = false;
2021 // parse the clipboard as an alignment.
2022 alignment = new FormatAdapter().readFile(str, "Paste", format);
2023 sequences = alignment.getSequencesArray();
2027 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2033 if (Desktop.jalviewClipboard != null)
2035 // dataset is inherited
2036 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2040 // new dataset is constructed
2041 alignment.setDataset(null);
2043 alwidth = alignment.getWidth() + 1;
2047 AlignmentI pastedal = alignment; // preserve pasted alignment object
2048 // Add pasted sequences and dataset into existing alignment.
2049 alignment = viewport.getAlignment();
2050 alwidth = alignment.getWidth() + 1;
2051 // decide if we need to import sequences from an existing dataset
2052 boolean importDs = Desktop.jalviewClipboard != null
2053 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2054 // importDs==true instructs us to copy over new dataset sequences from
2055 // an existing alignment
2056 Vector newDs = (importDs) ? new Vector() : null; // used to create
2057 // minimum dataset set
2059 for (int i = 0; i < sequences.length; i++)
2063 newDs.addElement(null);
2065 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2067 if (importDs && ds != null)
2069 if (!newDs.contains(ds))
2071 newDs.setElementAt(ds, i);
2072 ds = new Sequence(ds);
2073 // update with new dataset sequence
2074 sequences[i].setDatasetSequence(ds);
2078 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2083 // copy and derive new dataset sequence
2084 sequences[i] = sequences[i].deriveSequence();
2085 alignment.getDataset().addSequence(
2086 sequences[i].getDatasetSequence());
2087 // TODO: avoid creation of duplicate dataset sequences with a
2088 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2090 alignment.addSequence(sequences[i]); // merges dataset
2094 newDs.clear(); // tidy up
2096 if (alignment.getAlignmentAnnotation() != null)
2098 for (AlignmentAnnotation alan : alignment
2099 .getAlignmentAnnotation())
2101 if (alan.graphGroup > fgroup)
2103 fgroup = alan.graphGroup;
2107 if (pastedal.getAlignmentAnnotation() != null)
2109 // Add any annotation attached to alignment.
2110 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2111 for (int i = 0; i < alann.length; i++)
2113 annotationAdded = true;
2114 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2116 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2117 if (newann.graphGroup > -1)
2119 if (newGraphGroups.size() <= newann.graphGroup
2120 || newGraphGroups.get(newann.graphGroup) == null)
2122 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2124 newGraphGroups.add(q, null);
2126 newGraphGroups.set(newann.graphGroup, new Integer(
2129 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2133 newann.padAnnotation(alwidth);
2134 alignment.addAnnotation(newann);
2144 addHistoryItem(new EditCommand(
2145 MessageManager.getString("label.add_sequences"),
2146 Action.PASTE, sequences, 0, alignment.getWidth(), alignment));
2148 // Add any annotations attached to sequences
2149 for (int i = 0; i < sequences.length; i++)
2151 if (sequences[i].getAnnotation() != null)
2153 AlignmentAnnotation newann;
2154 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2156 annotationAdded = true;
2157 newann = sequences[i].getAnnotation()[a];
2158 newann.adjustForAlignment();
2159 newann.padAnnotation(alwidth);
2160 if (newann.graphGroup > -1)
2162 if (newann.graphGroup > -1)
2164 if (newGraphGroups.size() <= newann.graphGroup
2165 || newGraphGroups.get(newann.graphGroup) == null)
2167 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2169 newGraphGroups.add(q, null);
2171 newGraphGroups.set(newann.graphGroup, new Integer(
2174 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2178 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2183 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2190 // propagate alignment changed.
2191 viewport.setEndSeq(alignment.getHeight());
2192 if (annotationAdded)
2194 // Duplicate sequence annotation in all views.
2195 AlignmentI[] alview = this.getViewAlignments();
2196 for (int i = 0; i < sequences.length; i++)
2198 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2203 for (int avnum = 0; avnum < alview.length; avnum++)
2205 if (alview[avnum] != alignment)
2207 // duplicate in a view other than the one with input focus
2208 int avwidth = alview[avnum].getWidth() + 1;
2209 // this relies on sann being preserved after we
2210 // modify the sequence's annotation array for each duplication
2211 for (int a = 0; a < sann.length; a++)
2213 AlignmentAnnotation newann = new AlignmentAnnotation(
2215 sequences[i].addAlignmentAnnotation(newann);
2216 newann.padAnnotation(avwidth);
2217 alview[avnum].addAnnotation(newann); // annotation was
2218 // duplicated earlier
2219 // TODO JAL-1145 graphGroups are not updated for sequence
2220 // annotation added to several views. This may cause
2222 alview[avnum].setAnnotationIndex(newann, a);
2227 buildSortByAnnotationScoresMenu();
2229 viewport.firePropertyChange("alignment", null,
2230 alignment.getSequences());
2231 if (alignPanels != null)
2233 for (AlignmentPanel ap : alignPanels)
2235 ap.validateAnnotationDimensions(false);
2240 alignPanel.validateAnnotationDimensions(false);
2246 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2248 String newtitle = new String("Copied sequences");
2250 if (Desktop.jalviewClipboard != null
2251 && Desktop.jalviewClipboard[2] != null)
2253 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2254 for (int[] region : hc)
2256 af.viewport.hideColumns(region[0], region[1]);
2260 // >>>This is a fix for the moment, until a better solution is
2262 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2264 alignPanel.getSeqPanel().seqCanvas
2265 .getFeatureRenderer());
2267 // TODO: maintain provenance of an alignment, rather than just make the
2268 // title a concatenation of operations.
2271 if (title.startsWith("Copied sequences"))
2277 newtitle = newtitle.concat("- from " + title);
2282 newtitle = new String("Pasted sequences");
2285 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2290 } catch (Exception ex)
2292 ex.printStackTrace();
2293 System.out.println("Exception whilst pasting: " + ex);
2294 // could be anything being pasted in here
2300 protected void expand_newalign(ActionEvent e)
2304 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2305 .getAlignment(), -1);
2306 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2308 String newtitle = new String("Flanking alignment");
2310 if (Desktop.jalviewClipboard != null
2311 && Desktop.jalviewClipboard[2] != null)
2313 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2314 for (int region[] : hc)
2316 af.viewport.hideColumns(region[0], region[1]);
2320 // >>>This is a fix for the moment, until a better solution is
2322 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2324 alignPanel.getSeqPanel().seqCanvas
2325 .getFeatureRenderer());
2327 // TODO: maintain provenance of an alignment, rather than just make the
2328 // title a concatenation of operations.
2330 if (title.startsWith("Copied sequences"))
2336 newtitle = newtitle.concat("- from " + title);
2340 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2342 } catch (Exception ex)
2344 ex.printStackTrace();
2345 System.out.println("Exception whilst pasting: " + ex);
2346 // could be anything being pasted in here
2347 } catch (OutOfMemoryError oom)
2349 new OOMWarning("Viewing flanking region of alignment", oom);
2360 protected void cut_actionPerformed(ActionEvent e)
2362 copy_actionPerformed(null);
2363 delete_actionPerformed(null);
2373 protected void delete_actionPerformed(ActionEvent evt)
2376 SequenceGroup sg = viewport.getSelectionGroup();
2383 * If the cut affects all sequences, warn, remove highlighted columns
2385 if (sg.getSize() == viewport.getAlignment().getHeight())
2387 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2388 .getAlignment().getWidth()) ? true : false;
2389 if (isEntireAlignWidth)
2391 int confirm = JOptionPane.showConfirmDialog(this,
2392 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2393 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2394 JOptionPane.OK_CANCEL_OPTION);
2396 if (confirm == JOptionPane.CANCEL_OPTION
2397 || confirm == JOptionPane.CLOSED_OPTION)
2402 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2403 sg.getEndRes() + 1);
2405 SequenceI[] cut = sg.getSequences()
2406 .toArray(new SequenceI[sg.getSize()]);
2408 addHistoryItem(new EditCommand(
2409 MessageManager.getString("label.cut_sequences"), Action.CUT,
2410 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2411 viewport.getAlignment()));
2413 viewport.setSelectionGroup(null);
2414 viewport.sendSelection();
2415 viewport.getAlignment().deleteGroup(sg);
2417 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2419 if (viewport.getAlignment().getHeight() < 1)
2423 this.setClosed(true);
2424 } catch (Exception ex)
2437 protected void deleteGroups_actionPerformed(ActionEvent e)
2439 if (avc.deleteGroups())
2441 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2442 alignPanel.updateAnnotation();
2443 alignPanel.paintAlignment(true);
2454 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2456 SequenceGroup sg = new SequenceGroup();
2458 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2460 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2463 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2464 viewport.setSelectionGroup(sg);
2465 viewport.sendSelection();
2466 alignPanel.paintAlignment(true);
2467 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2477 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2479 if (viewport.cursorMode)
2481 alignPanel.getSeqPanel().keyboardNo1 = null;
2482 alignPanel.getSeqPanel().keyboardNo2 = null;
2484 viewport.setSelectionGroup(null);
2485 viewport.getColumnSelection().clear();
2486 viewport.setSelectionGroup(null);
2487 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2488 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2489 alignPanel.paintAlignment(true);
2490 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2491 viewport.sendSelection();
2501 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2503 SequenceGroup sg = viewport.getSelectionGroup();
2507 selectAllSequenceMenuItem_actionPerformed(null);
2512 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2514 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2517 alignPanel.paintAlignment(true);
2518 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2519 viewport.sendSelection();
2523 public void invertColSel_actionPerformed(ActionEvent e)
2525 viewport.invertColumnSelection();
2526 alignPanel.paintAlignment(true);
2527 viewport.sendSelection();
2537 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2539 trimAlignment(true);
2549 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2551 trimAlignment(false);
2554 void trimAlignment(boolean trimLeft)
2556 ColumnSelection colSel = viewport.getColumnSelection();
2559 if (!colSel.isEmpty())
2563 column = colSel.getMin();
2567 column = colSel.getMax();
2571 if (viewport.getSelectionGroup() != null)
2573 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2574 viewport.getHiddenRepSequences());
2578 seqs = viewport.getAlignment().getSequencesArray();
2581 TrimRegionCommand trimRegion;
2584 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2585 column, viewport.getAlignment());
2586 viewport.setStartRes(0);
2590 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2591 column, viewport.getAlignment());
2594 statusBar.setText(MessageManager.formatMessage(
2595 "label.removed_columns",
2596 new String[] { Integer.valueOf(trimRegion.getSize())
2599 addHistoryItem(trimRegion);
2601 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2603 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2604 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2606 viewport.getAlignment().deleteGroup(sg);
2610 viewport.firePropertyChange("alignment", null, viewport
2611 .getAlignment().getSequences());
2622 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2624 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2627 if (viewport.getSelectionGroup() != null)
2629 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2630 viewport.getHiddenRepSequences());
2631 start = viewport.getSelectionGroup().getStartRes();
2632 end = viewport.getSelectionGroup().getEndRes();
2636 seqs = viewport.getAlignment().getSequencesArray();
2639 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2640 "Remove Gapped Columns", seqs, start, end,
2641 viewport.getAlignment());
2643 addHistoryItem(removeGapCols);
2645 statusBar.setText(MessageManager.formatMessage(
2646 "label.removed_empty_columns",
2647 new Object[] { Integer.valueOf(removeGapCols.getSize())
2650 // This is to maintain viewport position on first residue
2651 // of first sequence
2652 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2653 int startRes = seq.findPosition(viewport.startRes);
2654 // ShiftList shifts;
2655 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2656 // edit.alColumnChanges=shifts.getInverse();
2657 // if (viewport.hasHiddenColumns)
2658 // viewport.getColumnSelection().compensateForEdits(shifts);
2659 viewport.setStartRes(seq.findIndex(startRes) - 1);
2660 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2672 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2674 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2677 if (viewport.getSelectionGroup() != null)
2679 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2680 viewport.getHiddenRepSequences());
2681 start = viewport.getSelectionGroup().getStartRes();
2682 end = viewport.getSelectionGroup().getEndRes();
2686 seqs = viewport.getAlignment().getSequencesArray();
2689 // This is to maintain viewport position on first residue
2690 // of first sequence
2691 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2692 int startRes = seq.findPosition(viewport.startRes);
2694 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2695 viewport.getAlignment()));
2697 viewport.setStartRes(seq.findIndex(startRes) - 1);
2699 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2711 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2713 viewport.setPadGaps(padGapsMenuitem.isSelected());
2714 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2725 public void findMenuItem_actionPerformed(ActionEvent e)
2731 * Create a new view of the current alignment.
2734 public void newView_actionPerformed(ActionEvent e)
2736 newView(null, true);
2740 * Creates and shows a new view of the current alignment.
2743 * title of newly created view; if null, one will be generated
2744 * @param copyAnnotation
2745 * if true then duplicate all annnotation, groups and settings
2746 * @return new alignment panel, already displayed.
2748 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2751 * Create a new AlignmentPanel (with its own, new Viewport)
2753 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2755 if (!copyAnnotation)
2758 * remove all groups and annotation except for the automatic stuff
2760 newap.av.getAlignment().deleteAllGroups();
2761 newap.av.getAlignment().deleteAllAnnotations(false);
2764 newap.av.setGatherViewsHere(false);
2766 if (viewport.viewName == null)
2768 viewport.viewName = MessageManager
2769 .getString("label.view_name_original");
2773 * Views share the same edits undo and redo stacks
2775 newap.av.setHistoryList(viewport.getHistoryList());
2776 newap.av.setRedoList(viewport.getRedoList());
2779 * Views share the same mappings; need to deregister any new mappings
2780 * created by copyAlignPanel, and register the new reference to the shared
2783 newap.av.replaceMappings(viewport.getAlignment());
2785 newap.av.viewName = getNewViewName(viewTitle);
2787 addAlignmentPanel(newap, true);
2788 newap.alignmentChanged();
2790 if (alignPanels.size() == 2)
2792 viewport.setGatherViewsHere(true);
2794 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2799 * Make a new name for the view, ensuring it is unique within the current
2800 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2801 * these now use viewId. Unique view names are still desirable for usability.)
2806 protected String getNewViewName(String viewTitle)
2808 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2809 boolean addFirstIndex = false;
2810 if (viewTitle == null || viewTitle.trim().length() == 0)
2812 viewTitle = MessageManager.getString("action.view");
2813 addFirstIndex = true;
2817 index = 1;// we count from 1 if given a specific name
2819 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2821 List<Component> comps = PaintRefresher.components.get(viewport
2822 .getSequenceSetId());
2824 List<String> existingNames = getExistingViewNames(comps);
2826 while (existingNames.contains(newViewName))
2828 newViewName = viewTitle + " " + (++index);
2834 * Returns a list of distinct view names found in the given list of
2835 * components. View names are held on the viewport of an AlignmentPanel.
2840 protected List<String> getExistingViewNames(List<Component> comps)
2842 List<String> existingNames = new ArrayList<String>();
2843 for (Component comp : comps)
2845 if (comp instanceof AlignmentPanel)
2847 AlignmentPanel ap = (AlignmentPanel) comp;
2848 if (!existingNames.contains(ap.av.viewName))
2850 existingNames.add(ap.av.viewName);
2854 return existingNames;
2858 * Explode tabbed views into separate windows.
2861 public void expandViews_actionPerformed(ActionEvent e)
2863 Desktop.instance.explodeViews(this);
2867 * Gather views in separate windows back into a tabbed presentation.
2870 public void gatherViews_actionPerformed(ActionEvent e)
2872 Desktop.instance.gatherViews(this);
2882 public void font_actionPerformed(ActionEvent e)
2884 new FontChooser(alignPanel);
2894 protected void seqLimit_actionPerformed(ActionEvent e)
2896 viewport.setShowJVSuffix(seqLimits.isSelected());
2898 alignPanel.getIdPanel().getIdCanvas()
2899 .setPreferredSize(alignPanel.calculateIdWidth());
2900 alignPanel.paintAlignment(true);
2904 public void idRightAlign_actionPerformed(ActionEvent e)
2906 viewport.setRightAlignIds(idRightAlign.isSelected());
2907 alignPanel.paintAlignment(true);
2911 public void centreColumnLabels_actionPerformed(ActionEvent e)
2913 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2914 alignPanel.paintAlignment(true);
2920 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2923 protected void followHighlight_actionPerformed()
2926 * Set the 'follow' flag on the Viewport (and scroll to position if now
2929 final boolean state = this.followHighlightMenuItem.getState();
2930 viewport.setFollowHighlight(state);
2933 alignPanel.scrollToPosition(
2934 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2945 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2947 viewport.setColourText(colourTextMenuItem.isSelected());
2948 alignPanel.paintAlignment(true);
2958 public void wrapMenuItem_actionPerformed(ActionEvent e)
2960 scaleAbove.setVisible(wrapMenuItem.isSelected());
2961 scaleLeft.setVisible(wrapMenuItem.isSelected());
2962 scaleRight.setVisible(wrapMenuItem.isSelected());
2963 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2964 alignPanel.updateLayout();
2968 public void showAllSeqs_actionPerformed(ActionEvent e)
2970 viewport.showAllHiddenSeqs();
2974 public void showAllColumns_actionPerformed(ActionEvent e)
2976 viewport.showAllHiddenColumns();
2978 viewport.sendSelection();
2982 public void hideSelSequences_actionPerformed(ActionEvent e)
2984 viewport.hideAllSelectedSeqs();
2985 // alignPanel.paintAlignment(true);
2989 * called by key handler and the hide all/show all menu items
2994 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2997 boolean hide = false;
2998 SequenceGroup sg = viewport.getSelectionGroup();
2999 if (!toggleSeqs && !toggleCols)
3001 // Hide everything by the current selection - this is a hack - we do the
3002 // invert and then hide
3003 // first check that there will be visible columns after the invert.
3004 if ((viewport.getColumnSelection() != null
3005 && viewport.getColumnSelection().getSelected() != null && viewport
3006 .getColumnSelection().getSelected().size() > 0)
3007 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
3010 // now invert the sequence set, if required - empty selection implies
3011 // that no hiding is required.
3014 invertSequenceMenuItem_actionPerformed(null);
3015 sg = viewport.getSelectionGroup();
3019 viewport.expandColSelection(sg, true);
3020 // finally invert the column selection and get the new sequence
3022 invertColSel_actionPerformed(null);
3029 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3031 hideSelSequences_actionPerformed(null);
3034 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3037 showAllSeqs_actionPerformed(null);
3043 if (viewport.getColumnSelection().getSelected().size() > 0)
3045 hideSelColumns_actionPerformed(null);
3048 viewport.setSelectionGroup(sg);
3053 showAllColumns_actionPerformed(null);
3062 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3063 * event.ActionEvent)
3066 public void hideAllButSelection_actionPerformed(ActionEvent e)
3068 toggleHiddenRegions(false, false);
3069 viewport.sendSelection();
3076 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3080 public void hideAllSelection_actionPerformed(ActionEvent e)
3082 SequenceGroup sg = viewport.getSelectionGroup();
3083 viewport.expandColSelection(sg, false);
3084 viewport.hideAllSelectedSeqs();
3085 viewport.hideSelectedColumns();
3086 alignPanel.paintAlignment(true);
3087 viewport.sendSelection();
3094 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3098 public void showAllhidden_actionPerformed(ActionEvent e)
3100 viewport.showAllHiddenColumns();
3101 viewport.showAllHiddenSeqs();
3102 alignPanel.paintAlignment(true);
3103 viewport.sendSelection();
3107 public void hideSelColumns_actionPerformed(ActionEvent e)
3109 viewport.hideSelectedColumns();
3110 alignPanel.paintAlignment(true);
3111 viewport.sendSelection();
3115 public void hiddenMarkers_actionPerformed(ActionEvent e)
3117 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3128 protected void scaleAbove_actionPerformed(ActionEvent e)
3130 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3131 alignPanel.paintAlignment(true);
3141 protected void scaleLeft_actionPerformed(ActionEvent e)
3143 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3144 alignPanel.paintAlignment(true);
3154 protected void scaleRight_actionPerformed(ActionEvent e)
3156 viewport.setScaleRightWrapped(scaleRight.isSelected());
3157 alignPanel.paintAlignment(true);
3167 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3169 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3170 alignPanel.paintAlignment(true);
3180 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3182 viewport.setShowText(viewTextMenuItem.isSelected());
3183 alignPanel.paintAlignment(true);
3193 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3195 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3196 alignPanel.paintAlignment(true);
3199 public FeatureSettings featureSettings;
3202 public FeatureSettingsControllerI getFeatureSettingsUI()
3204 return featureSettings;
3208 public void featureSettings_actionPerformed(ActionEvent e)
3210 if (featureSettings != null)
3212 featureSettings.close();
3213 featureSettings = null;
3215 if (!showSeqFeatures.isSelected())
3217 // make sure features are actually displayed
3218 showSeqFeatures.setSelected(true);
3219 showSeqFeatures_actionPerformed(null);
3221 featureSettings = new FeatureSettings(this);
3225 * Set or clear 'Show Sequence Features'
3231 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3233 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3234 alignPanel.paintAlignment(true);
3235 if (alignPanel.getOverviewPanel() != null)
3237 alignPanel.getOverviewPanel().updateOverviewImage();
3242 * Set or clear 'Show Sequence Features'
3248 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3250 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3252 if (viewport.isShowSequenceFeaturesHeight())
3254 // ensure we're actually displaying features
3255 viewport.setShowSequenceFeatures(true);
3256 showSeqFeatures.setSelected(true);
3258 alignPanel.paintAlignment(true);
3259 if (alignPanel.getOverviewPanel() != null)
3261 alignPanel.getOverviewPanel().updateOverviewImage();
3266 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3267 * the annotations panel as a whole.
3269 * The options to show/hide all annotations should be enabled when the panel
3270 * is shown, and disabled when the panel is hidden.
3275 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3277 final boolean setVisible = annotationPanelMenuItem.isSelected();
3278 viewport.setShowAnnotation(setVisible);
3279 this.showAllSeqAnnotations.setEnabled(setVisible);
3280 this.hideAllSeqAnnotations.setEnabled(setVisible);
3281 this.showAllAlAnnotations.setEnabled(setVisible);
3282 this.hideAllAlAnnotations.setEnabled(setVisible);
3283 alignPanel.updateLayout();
3287 public void alignmentProperties()
3289 JEditorPane editPane = new JEditorPane("text/html", "");
3290 editPane.setEditable(false);
3291 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3293 editPane.setText(MessageManager.formatMessage("label.html_content",
3294 new Object[] { contents.toString() }));
3295 JInternalFrame frame = new JInternalFrame();
3296 frame.getContentPane().add(new JScrollPane(editPane));
3298 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3299 "label.alignment_properties", new Object[] { getTitle() }),
3310 public void overviewMenuItem_actionPerformed(ActionEvent e)
3312 if (alignPanel.overviewPanel != null)
3317 JInternalFrame frame = new JInternalFrame();
3318 OverviewPanel overview = new OverviewPanel(alignPanel);
3319 frame.setContentPane(overview);
3320 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3321 "label.overview_params", new Object[] { this.getTitle() }),
3322 frame.getWidth(), frame.getHeight());
3324 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3325 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3328 public void internalFrameClosed(
3329 javax.swing.event.InternalFrameEvent evt)
3331 alignPanel.setOverviewPanel(null);
3335 alignPanel.setOverviewPanel(overview);
3339 public void textColour_actionPerformed(ActionEvent e)
3341 new TextColourChooser().chooseColour(alignPanel, null);
3351 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3363 public void clustalColour_actionPerformed(ActionEvent e)
3365 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3366 viewport.getHiddenRepSequences()));
3376 public void zappoColour_actionPerformed(ActionEvent e)
3378 changeColour(new ZappoColourScheme());
3388 public void taylorColour_actionPerformed(ActionEvent e)
3390 changeColour(new TaylorColourScheme());
3400 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3402 changeColour(new HydrophobicColourScheme());
3412 public void helixColour_actionPerformed(ActionEvent e)
3414 changeColour(new HelixColourScheme());
3424 public void strandColour_actionPerformed(ActionEvent e)
3426 changeColour(new StrandColourScheme());
3436 public void turnColour_actionPerformed(ActionEvent e)
3438 changeColour(new TurnColourScheme());
3448 public void buriedColour_actionPerformed(ActionEvent e)
3450 changeColour(new BuriedColourScheme());
3460 public void nucleotideColour_actionPerformed(ActionEvent e)
3462 changeColour(new NucleotideColourScheme());
3466 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3468 changeColour(new PurinePyrimidineColourScheme());
3472 * public void covariationColour_actionPerformed(ActionEvent e) {
3474 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3478 public void annotationColour_actionPerformed(ActionEvent e)
3480 new AnnotationColourChooser(viewport, alignPanel);
3484 public void annotationColumn_actionPerformed(ActionEvent e)
3486 new AnnotationColumnChooser(viewport, alignPanel);
3490 public void rnahelicesColour_actionPerformed(ActionEvent e)
3492 new RNAHelicesColourChooser(viewport, alignPanel);
3502 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3504 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3514 public void changeColour(ColourSchemeI cs)
3516 // TODO: pull up to controller method
3520 // Make sure viewport is up to date w.r.t. any sliders
3521 if (viewport.getAbovePIDThreshold())
3523 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3525 viewport.setThreshold(threshold);
3528 if (viewport.getConservationSelected())
3530 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3533 if (cs instanceof TCoffeeColourScheme)
3535 tcoffeeColour.setEnabled(true);
3536 tcoffeeColour.setSelected(true);
3540 viewport.setGlobalColourScheme(cs);
3542 alignPanel.paintAlignment(true);
3552 protected void modifyPID_actionPerformed(ActionEvent e)
3554 if (viewport.getAbovePIDThreshold()
3555 && viewport.getGlobalColourScheme() != null)
3557 SliderPanel.setPIDSliderSource(alignPanel,
3558 viewport.getGlobalColourScheme(), "Background");
3559 SliderPanel.showPIDSlider();
3570 protected void modifyConservation_actionPerformed(ActionEvent e)
3572 if (viewport.getConservationSelected()
3573 && viewport.getGlobalColourScheme() != null)
3575 SliderPanel.setConservationSlider(alignPanel,
3576 viewport.getGlobalColourScheme(), "Background");
3577 SliderPanel.showConservationSlider();
3588 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3590 viewport.setConservationSelected(conservationMenuItem.isSelected());
3592 viewport.setAbovePIDThreshold(false);
3593 abovePIDThreshold.setSelected(false);
3595 changeColour(viewport.getGlobalColourScheme());
3597 modifyConservation_actionPerformed(null);
3607 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3609 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3611 conservationMenuItem.setSelected(false);
3612 viewport.setConservationSelected(false);
3614 changeColour(viewport.getGlobalColourScheme());
3616 modifyPID_actionPerformed(null);
3626 public void userDefinedColour_actionPerformed(ActionEvent e)
3628 if (e.getActionCommand().equals(
3629 MessageManager.getString("action.user_defined")))
3631 new UserDefinedColours(alignPanel, null);
3635 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3636 .getUserColourSchemes().get(e.getActionCommand());
3642 public void updateUserColourMenu()
3645 Component[] menuItems = colourMenu.getMenuComponents();
3646 int iSize = menuItems.length;
3647 for (int i = 0; i < iSize; i++)
3649 if (menuItems[i].getName() != null
3650 && menuItems[i].getName().equals("USER_DEFINED"))
3652 colourMenu.remove(menuItems[i]);
3656 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3658 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3659 .getUserColourSchemes().keys();
3661 while (userColours.hasMoreElements())
3663 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3664 userColours.nextElement().toString());
3665 radioItem.setName("USER_DEFINED");
3666 radioItem.addMouseListener(new MouseAdapter()
3669 public void mousePressed(MouseEvent evt)
3671 if (evt.isControlDown()
3672 || SwingUtilities.isRightMouseButton(evt))
3674 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3676 int option = JOptionPane.showInternalConfirmDialog(
3677 jalview.gui.Desktop.desktop,
3679 .getString("label.remove_from_default_list"),
3681 .getString("label.remove_user_defined_colour"),
3682 JOptionPane.YES_NO_OPTION);
3683 if (option == JOptionPane.YES_OPTION)
3685 jalview.gui.UserDefinedColours
3686 .removeColourFromDefaults(radioItem.getText());
3687 colourMenu.remove(radioItem);
3691 radioItem.addActionListener(new ActionListener()
3694 public void actionPerformed(ActionEvent evt)
3696 userDefinedColour_actionPerformed(evt);
3703 radioItem.addActionListener(new ActionListener()
3706 public void actionPerformed(ActionEvent evt)
3708 userDefinedColour_actionPerformed(evt);
3712 colourMenu.insert(radioItem, 15);
3713 colours.add(radioItem);
3725 public void PIDColour_actionPerformed(ActionEvent e)
3727 changeColour(new PIDColourScheme());
3737 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3739 changeColour(new Blosum62ColourScheme());
3749 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3751 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3752 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3753 .getAlignment().getSequenceAt(0), null);
3754 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3755 viewport.getAlignment()));
3756 alignPanel.paintAlignment(true);
3766 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3768 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3769 AlignmentSorter.sortByID(viewport.getAlignment());
3770 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3771 viewport.getAlignment()));
3772 alignPanel.paintAlignment(true);
3782 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3784 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3785 AlignmentSorter.sortByLength(viewport.getAlignment());
3786 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3787 viewport.getAlignment()));
3788 alignPanel.paintAlignment(true);
3798 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3800 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3801 AlignmentSorter.sortByGroup(viewport.getAlignment());
3802 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3803 viewport.getAlignment()));
3805 alignPanel.paintAlignment(true);
3815 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3817 new RedundancyPanel(alignPanel, this);
3827 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3829 if ((viewport.getSelectionGroup() == null)
3830 || (viewport.getSelectionGroup().getSize() < 2))
3832 JOptionPane.showInternalMessageDialog(this, MessageManager
3833 .getString("label.you_must_select_least_two_sequences"),
3834 MessageManager.getString("label.invalid_selection"),
3835 JOptionPane.WARNING_MESSAGE);
3839 JInternalFrame frame = new JInternalFrame();
3840 frame.setContentPane(new PairwiseAlignPanel(viewport));
3841 Desktop.addInternalFrame(frame,
3842 MessageManager.getString("action.pairwise_alignment"), 600,
3854 public void PCAMenuItem_actionPerformed(ActionEvent e)
3856 if (((viewport.getSelectionGroup() != null)
3857 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3858 .getSelectionGroup().getSize() > 0))
3859 || (viewport.getAlignment().getHeight() < 4))
3862 .showInternalMessageDialog(
3865 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3867 .getString("label.sequence_selection_insufficient"),
3868 JOptionPane.WARNING_MESSAGE);
3873 new PCAPanel(alignPanel);
3877 public void autoCalculate_actionPerformed(ActionEvent e)
3879 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3880 if (viewport.autoCalculateConsensus)
3882 viewport.firePropertyChange("alignment", null, viewport
3883 .getAlignment().getSequences());
3888 public void sortByTreeOption_actionPerformed(ActionEvent e)
3890 viewport.sortByTree = sortByTree.isSelected();
3894 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3896 viewport.followSelection = listenToViewSelections.isSelected();
3906 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3908 newTreePanel("AV", "PID", "Average distance tree using PID");
3918 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3920 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3930 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3932 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3942 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3944 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3957 void newTreePanel(String type, String pwType, String title)
3961 if (viewport.getSelectionGroup() != null
3962 && viewport.getSelectionGroup().getSize() > 0)
3964 if (viewport.getSelectionGroup().getSize() < 3)
3970 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3972 .getString("label.not_enough_sequences"),
3973 JOptionPane.WARNING_MESSAGE);
3977 SequenceGroup sg = viewport.getSelectionGroup();
3979 /* Decide if the selection is a column region */
3980 for (SequenceI _s : sg.getSequences())
3982 if (_s.getLength() < sg.getEndRes())
3988 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3990 .getString("label.sequences_selection_not_aligned"),
3991 JOptionPane.WARNING_MESSAGE);
3997 title = title + " on region";
3998 tp = new TreePanel(alignPanel, type, pwType);
4002 // are the visible sequences aligned?
4003 if (!viewport.getAlignment().isAligned(false))
4009 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4011 .getString("label.sequences_not_aligned"),
4012 JOptionPane.WARNING_MESSAGE);
4017 if (viewport.getAlignment().getHeight() < 2)
4022 tp = new TreePanel(alignPanel, type, pwType);
4027 if (viewport.viewName != null)
4029 title += viewport.viewName + " of ";
4032 title += this.title;
4034 Desktop.addInternalFrame(tp, title, 600, 500);
4045 public void addSortByOrderMenuItem(String title,
4046 final AlignmentOrder order)
4048 final JMenuItem item = new JMenuItem(MessageManager.formatMessage(
4049 "action.by_title_param", new Object[] { title }));
4051 item.addActionListener(new java.awt.event.ActionListener()
4054 public void actionPerformed(ActionEvent e)
4056 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4058 // TODO: JBPNote - have to map order entries to curent SequenceI
4060 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4062 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4065 alignPanel.paintAlignment(true);
4071 * Add a new sort by annotation score menu item
4074 * the menu to add the option to
4076 * the label used to retrieve scores for each sequence on the
4079 public void addSortByAnnotScoreMenuItem(JMenu sort,
4080 final String scoreLabel)
4082 final JMenuItem item = new JMenuItem(scoreLabel);
4084 item.addActionListener(new java.awt.event.ActionListener()
4087 public void actionPerformed(ActionEvent e)
4089 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4090 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4091 viewport.getAlignment());// ,viewport.getSelectionGroup());
4092 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4093 viewport.getAlignment()));
4094 alignPanel.paintAlignment(true);
4100 * last hash for alignment's annotation array - used to minimise cost of
4103 protected int _annotationScoreVectorHash;
4106 * search the alignment and rebuild the sort by annotation score submenu the
4107 * last alignment annotation vector hash is stored to minimize cost of
4108 * rebuilding in subsequence calls.
4112 public void buildSortByAnnotationScoresMenu()
4114 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4119 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4121 sortByAnnotScore.removeAll();
4122 // almost certainly a quicker way to do this - but we keep it simple
4123 Hashtable scoreSorts = new Hashtable();
4124 AlignmentAnnotation aann[];
4125 for (SequenceI sqa : viewport.getAlignment().getSequences())
4127 aann = sqa.getAnnotation();
4128 for (int i = 0; aann != null && i < aann.length; i++)
4130 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4132 scoreSorts.put(aann[i].label, aann[i].label);
4136 Enumeration labels = scoreSorts.keys();
4137 while (labels.hasMoreElements())
4139 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4140 (String) labels.nextElement());
4142 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4145 _annotationScoreVectorHash = viewport.getAlignment()
4146 .getAlignmentAnnotation().hashCode();
4151 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4152 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4153 * call. Listeners are added to remove the menu item when the treePanel is
4154 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4158 * Displayed tree window.
4160 * SortBy menu item title.
4163 public void buildTreeMenu()
4165 calculateTree.removeAll();
4166 // build the calculate menu
4168 for (final String type : new String[] { "NJ", "AV" })
4170 String treecalcnm = MessageManager.getString("label.tree_calc_"
4171 + type.toLowerCase());
4172 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4174 JMenuItem tm = new JMenuItem();
4175 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4176 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4178 String smn = MessageManager.getStringOrReturn(
4179 "label.score_model_", sm.getName());
4180 final String title = MessageManager.formatMessage(
4181 "label.treecalc_title", treecalcnm, smn);
4182 tm.setText(title);//
4183 tm.addActionListener(new java.awt.event.ActionListener()
4186 public void actionPerformed(ActionEvent e)
4188 newTreePanel(type, pwtype, title);
4191 calculateTree.add(tm);
4196 sortByTreeMenu.removeAll();
4198 List<Component> comps = PaintRefresher.components.get(viewport
4199 .getSequenceSetId());
4200 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4201 for (Component comp : comps)
4203 if (comp instanceof TreePanel)
4205 treePanels.add((TreePanel) comp);
4209 if (treePanels.size() < 1)
4211 sortByTreeMenu.setVisible(false);
4215 sortByTreeMenu.setVisible(true);
4217 for (final TreePanel tp : treePanels)
4219 final JMenuItem item = new JMenuItem(tp.getTitle());
4220 item.addActionListener(new java.awt.event.ActionListener()
4223 public void actionPerformed(ActionEvent e)
4225 tp.sortByTree_actionPerformed();
4226 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4231 sortByTreeMenu.add(item);
4235 public boolean sortBy(AlignmentOrder alorder, String undoname)
4237 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4238 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4239 if (undoname != null)
4241 addHistoryItem(new OrderCommand(undoname, oldOrder,
4242 viewport.getAlignment()));
4244 alignPanel.paintAlignment(true);
4249 * Work out whether the whole set of sequences or just the selected set will
4250 * be submitted for multiple alignment.
4253 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4255 // Now, check we have enough sequences
4256 AlignmentView msa = null;
4258 if ((viewport.getSelectionGroup() != null)
4259 && (viewport.getSelectionGroup().getSize() > 1))
4261 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4262 // some common interface!
4264 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4265 * SequenceI[sz = seqs.getSize(false)];
4267 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4268 * seqs.getSequenceAt(i); }
4270 msa = viewport.getAlignmentView(true);
4272 else if (viewport.getSelectionGroup() != null
4273 && viewport.getSelectionGroup().getSize() == 1)
4275 int option = JOptionPane.showConfirmDialog(this,
4276 MessageManager.getString("warn.oneseq_msainput_selection"),
4277 MessageManager.getString("label.invalid_selection"),
4278 JOptionPane.OK_CANCEL_OPTION);
4279 if (option == JOptionPane.OK_OPTION)
4281 msa = viewport.getAlignmentView(false);
4286 msa = viewport.getAlignmentView(false);
4292 * Decides what is submitted to a secondary structure prediction service: the
4293 * first sequence in the alignment, or in the current selection, or, if the
4294 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4295 * region or the whole alignment. (where the first sequence in the set is the
4296 * one that the prediction will be for).
4298 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4300 AlignmentView seqs = null;
4302 if ((viewport.getSelectionGroup() != null)
4303 && (viewport.getSelectionGroup().getSize() > 0))
4305 seqs = viewport.getAlignmentView(true);
4309 seqs = viewport.getAlignmentView(false);
4311 // limit sequences - JBPNote in future - could spawn multiple prediction
4313 // TODO: viewport.getAlignment().isAligned is a global state - the local
4314 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4315 if (!viewport.getAlignment().isAligned(false))
4317 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4318 // TODO: if seqs.getSequences().length>1 then should really have warned
4332 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4334 // Pick the tree file
4335 JalviewFileChooser chooser = new JalviewFileChooser(
4336 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4337 chooser.setFileView(new JalviewFileView());
4338 chooser.setDialogTitle(MessageManager
4339 .getString("label.select_newick_like_tree_file"));
4340 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4342 int value = chooser.showOpenDialog(null);
4344 if (value == JalviewFileChooser.APPROVE_OPTION)
4346 String choice = chooser.getSelectedFile().getPath();
4347 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4348 jalview.io.NewickFile fin = null;
4351 fin = new jalview.io.NewickFile(choice, "File");
4352 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4353 } catch (Exception ex)
4360 .getString("label.problem_reading_tree_file"),
4361 JOptionPane.WARNING_MESSAGE);
4362 ex.printStackTrace();
4364 if (fin != null && fin.hasWarningMessage())
4366 JOptionPane.showMessageDialog(Desktop.desktop, fin
4367 .getWarningMessage(), MessageManager
4368 .getString("label.possible_problem_with_tree_file"),
4369 JOptionPane.WARNING_MESSAGE);
4375 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4377 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4380 public TreePanel ShowNewickTree(NewickFile nf, String title)
4382 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4385 public TreePanel ShowNewickTree(NewickFile nf, String title,
4386 AlignmentView input)
4388 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4391 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4392 int h, int x, int y)
4394 return ShowNewickTree(nf, title, null, w, h, x, y);
4398 * Add a treeviewer for the tree extracted from a newick file object to the
4399 * current alignment view
4406 * Associated alignment input data (or null)
4415 * @return TreePanel handle
4417 public TreePanel ShowNewickTree(NewickFile nf, String title,
4418 AlignmentView input, int w, int h, int x, int y)
4420 TreePanel tp = null;
4426 if (nf.getTree() != null)
4428 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4434 tp.setLocation(x, y);
4437 Desktop.addInternalFrame(tp, title, w, h);
4439 } catch (Exception ex)
4441 ex.printStackTrace();
4447 private boolean buildingMenu = false;
4450 * Generates menu items and listener event actions for web service clients
4453 public void BuildWebServiceMenu()
4455 while (buildingMenu)
4459 System.err.println("Waiting for building menu to finish.");
4461 } catch (Exception e)
4465 final AlignFrame me = this;
4466 buildingMenu = true;
4467 new Thread(new Runnable()
4472 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4475 // System.err.println("Building ws menu again "
4476 // + Thread.currentThread());
4477 // TODO: add support for context dependent disabling of services based
4479 // alignment and current selection
4480 // TODO: add additional serviceHandle parameter to specify abstract
4482 // class independently of AbstractName
4483 // TODO: add in rediscovery GUI function to restart discoverer
4484 // TODO: group services by location as well as function and/or
4486 // object broker mechanism.
4487 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4488 final IProgressIndicator af = me;
4489 final JMenu msawsmenu = new JMenu("Alignment");
4490 final JMenu secstrmenu = new JMenu(
4491 "Secondary Structure Prediction");
4492 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4493 final JMenu analymenu = new JMenu("Analysis");
4494 final JMenu dismenu = new JMenu("Protein Disorder");
4495 // final JMenu msawsmenu = new
4496 // JMenu(MessageManager.getString("label.alignment"));
4497 // final JMenu secstrmenu = new
4498 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4499 // final JMenu seqsrchmenu = new
4500 // JMenu(MessageManager.getString("label.sequence_database_search"));
4501 // final JMenu analymenu = new
4502 // JMenu(MessageManager.getString("label.analysis"));
4503 // final JMenu dismenu = new
4504 // JMenu(MessageManager.getString("label.protein_disorder"));
4505 // JAL-940 - only show secondary structure prediction services from
4506 // the legacy server
4507 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4509 Discoverer.services != null && (Discoverer.services.size() > 0))
4511 // TODO: refactor to allow list of AbstractName/Handler bindings to
4513 // stored or retrieved from elsewhere
4514 // No MSAWS used any more:
4515 // Vector msaws = null; // (Vector)
4516 // Discoverer.services.get("MsaWS");
4517 Vector secstrpr = (Vector) Discoverer.services
4519 if (secstrpr != null)
4521 // Add any secondary structure prediction services
4522 for (int i = 0, j = secstrpr.size(); i < j; i++)
4524 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4526 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4527 .getServiceClient(sh);
4528 int p = secstrmenu.getItemCount();
4529 impl.attachWSMenuEntry(secstrmenu, me);
4530 int q = secstrmenu.getItemCount();
4531 for (int litm = p; litm < q; litm++)
4533 legacyItems.add(secstrmenu.getItem(litm));
4539 // Add all submenus in the order they should appear on the web
4541 wsmenu.add(msawsmenu);
4542 wsmenu.add(secstrmenu);
4543 wsmenu.add(dismenu);
4544 wsmenu.add(analymenu);
4545 // No search services yet
4546 // wsmenu.add(seqsrchmenu);
4548 javax.swing.SwingUtilities.invokeLater(new Runnable()
4555 webService.removeAll();
4556 // first, add discovered services onto the webservices menu
4557 if (wsmenu.size() > 0)
4559 for (int i = 0, j = wsmenu.size(); i < j; i++)
4561 webService.add(wsmenu.get(i));
4566 webService.add(me.webServiceNoServices);
4568 // TODO: move into separate menu builder class.
4569 boolean new_sspred = false;
4570 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4572 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4573 if (jws2servs != null)
4575 if (jws2servs.hasServices())
4577 jws2servs.attachWSMenuEntry(webService, me);
4578 for (Jws2Instance sv : jws2servs.getServices())
4580 if (sv.description.toLowerCase().contains("jpred"))
4582 for (JMenuItem jmi : legacyItems)
4584 jmi.setVisible(false);
4590 if (jws2servs.isRunning())
4592 JMenuItem tm = new JMenuItem(
4593 "Still discovering JABA Services");
4594 tm.setEnabled(false);
4599 build_urlServiceMenu(me.webService);
4600 build_fetchdbmenu(webService);
4601 for (JMenu item : wsmenu)
4603 if (item.getItemCount() == 0)
4605 item.setEnabled(false);
4609 item.setEnabled(true);
4612 } catch (Exception e)
4615 .debug("Exception during web service menu building process.",
4620 } catch (Exception e)
4623 buildingMenu = false;
4630 * construct any groupURL type service menu entries.
4634 private void build_urlServiceMenu(JMenu webService)
4636 // TODO: remove this code when 2.7 is released
4637 // DEBUG - alignmentView
4639 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4640 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4642 * @Override public void actionPerformed(ActionEvent e) {
4643 * jalview.datamodel.AlignmentView
4644 * .testSelectionViews(af.viewport.getAlignment(),
4645 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4647 * }); webService.add(testAlView);
4649 // TODO: refactor to RestClient discoverer and merge menu entries for
4650 // rest-style services with other types of analysis/calculation service
4651 // SHmmr test client - still being implemented.
4652 // DEBUG - alignmentView
4654 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4657 client.attachWSMenuEntry(
4658 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4664 * Searches selected sequences for xRef products and builds the Show
4665 * Cross-References menu (formerly called Show Products)
4667 * @return true if Show Cross-references menu should be enabled.
4669 public boolean canShowProducts()
4671 SequenceI[] selection = viewport.getSequenceSelection();
4672 AlignmentI dataset = viewport.getAlignment().getDataset();
4673 boolean showp = false;
4676 showProducts.removeAll();
4677 final boolean dna = viewport.getAlignment().isNucleotide();
4678 String[] ptypes = (selection == null || selection.length == 0) ? null
4679 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4681 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4684 final AlignFrame af = this;
4685 final String source = ptypes[t];
4686 JMenuItem xtype = new JMenuItem(ptypes[t]);
4687 xtype.addActionListener(new ActionListener()
4691 public void actionPerformed(ActionEvent e)
4693 showProductsFor(af.viewport.getSequenceSelection(), dna, source);
4697 showProducts.add(xtype);
4699 showProducts.setVisible(showp);
4700 showProducts.setEnabled(showp);
4701 } catch (Exception e)
4703 jalview.bin.Cache.log
4704 .warn("canShowProducts threw an exception - please report to help@jalview.org",
4711 protected void showProductsFor(final SequenceI[] sel, final boolean dna,
4712 final String source)
4714 Runnable foo = new Runnable()
4720 final long sttime = System.currentTimeMillis();
4721 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4722 "status.searching_for_sequences_from",
4723 new Object[] { source }), sttime);
4727 * 'peer' sequences are any to add to this alignment, for example
4728 * alternative protein products for my protein's gene
4730 List<SequenceI> addedPeers = new ArrayList<SequenceI>();
4731 AlignmentI alignment = AlignFrame.this.getViewport()
4733 Alignment xrefs = CrossRef.findXrefSequences(sel, dna, source,
4734 alignment, addedPeers);
4738 * figure out colour scheme if any to apply to features
4740 ASequenceFetcher sftch = new SequenceFetcher();
4741 List<DbSourceProxy> proxies = sftch.getSourceProxy(source);
4742 FeatureSettingsModelI featureColourScheme = null;
4743 for (DbSourceProxy proxy : proxies)
4745 FeatureSettingsModelI preferredColours = proxy
4746 .getFeatureColourScheme();
4747 if (preferredColours != null)
4749 featureColourScheme = preferredColours;
4753 AlignmentI al = makeCrossReferencesAlignment(
4754 alignment.getDataset(), xrefs);
4756 AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH,
4758 String newtitle = String.format("%s %s %s",
4759 MessageManager.getString(dna ? "label.proteins"
4760 : "label.nucleotides"), MessageManager
4761 .getString("label.for"), getTitle());
4762 newFrame.setTitle(newtitle);
4764 boolean asSplitFrame = Cache.getDefault(
4765 Preferences.ENABLE_SPLIT_FRAME, true);
4769 * Make a copy of this alignment (sharing the same dataset
4770 * sequences). If we are DNA, drop introns and update mappings
4772 AlignmentI copyAlignment = null;
4773 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4774 .getSequenceSelection();
4775 List<AlignedCodonFrame> cf = xrefs.getCodonFrames();
4778 copyAlignment = AlignmentUtils.makeCdsAlignment(
4779 sequenceSelection, cf, alignment);
4780 if (copyAlignment.getHeight() == 0)
4782 System.err.println("Failed to make CDS alignment");
4784 al.getCodonFrames().clear();
4785 al.getCodonFrames().addAll(cf);
4789 copyAlignment = new Alignment(new Alignment(
4790 sequenceSelection));
4791 copyAlignment.getCodonFrames().addAll(cf);
4793 copyAlignment.setGapCharacter(AlignFrame.this.viewport
4794 .getGapCharacter());
4795 StructureSelectionManager ssm = StructureSelectionManager
4796 .getStructureSelectionManager(Desktop.instance);
4797 ssm.registerMappings(cf);
4800 * add in any extra 'peer' sequences discovered
4801 * (e.g. alternative protein products)
4803 for (SequenceI peer : addedPeers)
4805 copyAlignment.addSequence(peer);
4808 if (copyAlignment.getHeight() > 0)
4811 * align protein to dna
4813 // FIXME what if the dna is not aligned :-O
4816 al.alignAs(copyAlignment);
4821 * align cdna to protein - currently only if
4822 * fetching and aligning Ensembl transcripts!
4824 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source))
4826 copyAlignment.alignAs(al);
4830 AlignFrame copyThis = new AlignFrame(copyAlignment,
4831 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4832 copyThis.setTitle(AlignFrame.this.getTitle());
4834 boolean showSequenceFeatures = viewport
4835 .isShowSequenceFeatures();
4836 newFrame.setShowSeqFeatures(showSequenceFeatures);
4837 copyThis.setShowSeqFeatures(showSequenceFeatures);
4838 FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
4839 .getFeatureRenderer();
4842 * copy feature rendering settings to split frame
4844 newFrame.alignPanel.getSeqPanel().seqCanvas
4845 .getFeatureRenderer().transferSettings(
4847 copyThis.alignPanel.getSeqPanel().seqCanvas
4848 .getFeatureRenderer().transferSettings(
4852 * apply 'database source' feature configuration
4855 // TODO is this the feature colouring for the original
4856 // alignment or the fetched xrefs? either could be Ensembl
4857 newFrame.getViewport().applyFeaturesStyle(
4858 featureColourScheme);
4859 copyThis.getViewport().applyFeaturesStyle(
4860 featureColourScheme);
4862 SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
4863 dna ? newFrame : copyThis);
4864 newFrame.setVisible(true);
4865 copyThis.setVisible(true);
4866 String linkedTitle = MessageManager
4867 .getString("label.linked_view_title");
4868 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4874 Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
4880 System.err.println("No Sequences generated for xRef type "
4883 } catch (Exception e)
4885 jalview.bin.Cache.log.error(
4886 "Exception when finding crossreferences", e);
4887 } catch (OutOfMemoryError e)
4889 new OOMWarning("whilst fetching crossreferences", e);
4892 jalview.bin.Cache.log.error("Error when finding crossreferences",
4895 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4896 "status.finished_searching_for_sequences_from",
4897 new Object[] { source }), sttime);
4901 * Makes an alignment containing the given sequences. If this is of the
4902 * same type as the given dataset (nucleotide/protein), then the new
4903 * alignment shares the same dataset, and its dataset sequences are added
4904 * to it. Otherwise a new dataset sequence is created for the
4911 protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
4914 boolean sameType = dataset.isNucleotide() == seqs.isNucleotide();
4916 SequenceI[] sprods = new SequenceI[seqs.getHeight()];
4917 for (int s = 0; s < sprods.length; s++)
4919 sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
4922 if (dataset.getSequences() == null
4923 || !dataset.getSequences().contains(
4924 sprods[s].getDatasetSequence()))
4926 dataset.addSequence(sprods[s].getDatasetSequence());
4929 sprods[s].updatePDBIds();
4931 Alignment al = new Alignment(sprods);
4934 al.setDataset((Alignment) dataset);
4938 al.createDatasetAlignment();
4944 Thread frunner = new Thread(foo);
4948 public boolean canShowTranslationProducts(SequenceI[] selection,
4949 AlignmentI alignment)
4954 return (jalview.analysis.Dna.canTranslate(selection,
4955 viewport.getViewAsVisibleContigs(true)));
4956 } catch (Exception e)
4958 jalview.bin.Cache.log
4959 .warn("canTranslate threw an exception - please report to help@jalview.org",
4966 * Construct and display a new frame containing the translation of this
4967 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4970 public void showTranslation_actionPerformed(ActionEvent e)
4972 AlignmentI al = null;
4975 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4977 al = dna.translateCdna();
4978 } catch (Exception ex)
4980 jalview.bin.Cache.log.error(
4981 "Exception during translation. Please report this !", ex);
4982 final String msg = MessageManager
4983 .getString("label.error_when_translating_sequences_submit_bug_report");
4984 final String errorTitle = MessageManager
4985 .getString("label.implementation_error")
4986 + MessageManager.getString("translation_failed");
4987 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4988 JOptionPane.ERROR_MESSAGE);
4991 if (al == null || al.getHeight() == 0)
4993 final String msg = MessageManager
4994 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4995 final String errorTitle = MessageManager
4996 .getString("label.translation_failed");
4997 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4998 JOptionPane.WARNING_MESSAGE);
5002 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
5003 af.setFileFormat(this.currentFileFormat);
5004 final String newTitle = MessageManager.formatMessage(
5005 "label.translation_of_params",
5006 new Object[] { this.getTitle() });
5007 af.setTitle(newTitle);
5008 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
5010 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
5011 viewport.openSplitFrame(af, new Alignment(seqs));
5015 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
5022 * Set the file format
5026 public void setFileFormat(String fileFormat)
5028 this.currentFileFormat = fileFormat;
5032 * Try to load a features file onto the alignment.
5035 * contents or path to retrieve file
5037 * access mode of file (see jalview.io.AlignFile)
5038 * @return true if features file was parsed correctly.
5040 public boolean parseFeaturesFile(String file, String type)
5042 return avc.parseFeaturesFile(file, type,
5043 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5048 public void refreshFeatureUI(boolean enableIfNecessary)
5050 // note - currently this is only still here rather than in the controller
5051 // because of the featureSettings hard reference that is yet to be
5053 if (enableIfNecessary)
5055 viewport.setShowSequenceFeatures(true);
5056 showSeqFeatures.setSelected(true);
5062 public void dragEnter(DropTargetDragEvent evt)
5067 public void dragExit(DropTargetEvent evt)
5072 public void dragOver(DropTargetDragEvent evt)
5077 public void dropActionChanged(DropTargetDragEvent evt)
5082 public void drop(DropTargetDropEvent evt)
5084 Transferable t = evt.getTransferable();
5085 java.util.List files = null;
5089 DataFlavor uriListFlavor = new DataFlavor(
5090 "text/uri-list;class=java.lang.String");
5091 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5093 // Works on Windows and MacOSX
5094 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5095 files = (java.util.List) t
5096 .getTransferData(DataFlavor.javaFileListFlavor);
5098 else if (t.isDataFlavorSupported(uriListFlavor))
5100 // This is used by Unix drag system
5101 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5102 String data = (String) t.getTransferData(uriListFlavor);
5103 files = new java.util.ArrayList(1);
5104 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5105 data, "\r\n"); st.hasMoreTokens();)
5107 String s = st.nextToken();
5108 if (s.startsWith("#"))
5110 // the line is a comment (as per the RFC 2483)
5114 java.net.URI uri = new java.net.URI(s);
5115 // check to see if we can handle this kind of URI
5116 if (uri.getScheme().toLowerCase().startsWith("http"))
5118 files.add(uri.toString());
5122 // otherwise preserve old behaviour: catch all for file objects
5123 java.io.File file = new java.io.File(uri);
5124 files.add(file.toString());
5128 } catch (Exception e)
5130 e.printStackTrace();
5136 // check to see if any of these files have names matching sequences in
5138 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5139 .getAlignment().getSequencesArray());
5141 * Object[] { String,SequenceI}
5143 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5144 ArrayList<String> filesnotmatched = new ArrayList<String>();
5145 for (int i = 0; i < files.size(); i++)
5147 String file = files.get(i).toString();
5149 String protocol = FormatAdapter.checkProtocol(file);
5150 if (protocol == jalview.io.FormatAdapter.FILE)
5152 File fl = new File(file);
5153 pdbfn = fl.getName();
5155 else if (protocol == jalview.io.FormatAdapter.URL)
5157 URL url = new URL(file);
5158 pdbfn = url.getFile();
5160 if (pdbfn.length() > 0)
5162 // attempt to find a match in the alignment
5163 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5164 int l = 0, c = pdbfn.indexOf(".");
5165 while (mtch == null && c != -1)
5170 } while ((c = pdbfn.indexOf(".", l)) > l);
5173 pdbfn = pdbfn.substring(0, l);
5175 mtch = idm.findAllIdMatches(pdbfn);
5182 type = new IdentifyFile().identify(file, protocol);
5183 } catch (Exception ex)
5189 if (type.equalsIgnoreCase("PDB"))
5191 filesmatched.add(new Object[] { file, protocol, mtch });
5196 // File wasn't named like one of the sequences or wasn't a PDB file.
5197 filesnotmatched.add(file);
5201 if (filesmatched.size() > 0)
5203 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5209 "label.automatically_associate_pdb_files_with_sequences_same_name",
5210 new Object[] { Integer
5216 .getString("label.automatically_associate_pdb_files_by_name"),
5217 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5220 for (Object[] fm : filesmatched)
5222 // try and associate
5223 // TODO: may want to set a standard ID naming formalism for
5224 // associating PDB files which have no IDs.
5225 for (SequenceI toassoc : (SequenceI[]) fm[2])
5227 PDBEntry pe = new AssociatePdbFileWithSeq()
5228 .associatePdbWithSeq((String) fm[0],
5229 (String) fm[1], toassoc, false,
5233 System.err.println("Associated file : "
5234 + ((String) fm[0]) + " with "
5235 + toassoc.getDisplayId(true));
5239 alignPanel.paintAlignment(true);
5243 if (filesnotmatched.size() > 0)
5246 && (Cache.getDefault(
5247 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5253 "label.ignore_unmatched_dropped_files_info",
5254 new Object[] { Integer
5261 .getString("label.ignore_unmatched_dropped_files"),
5262 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5266 for (String fn : filesnotmatched)
5268 loadJalviewDataFile(fn, null, null, null);
5272 } catch (Exception ex)
5274 ex.printStackTrace();
5280 * Attempt to load a "dropped" file or URL string: First by testing whether
5281 * it's an Annotation file, then a JNet file, and finally a features file. If
5282 * all are false then the user may have dropped an alignment file onto this
5286 * either a filename or a URL string.
5288 public void loadJalviewDataFile(String file, String protocol,
5289 String format, SequenceI assocSeq)
5293 if (protocol == null)
5295 protocol = FormatAdapter.checkProtocol(file);
5297 // if the file isn't identified, or not positively identified as some
5298 // other filetype (PFAM is default unidentified alignment file type) then
5299 // try to parse as annotation.
5300 boolean isAnnotation = (format == null || format
5301 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5302 .annotateAlignmentView(viewport, file, protocol) : false;
5306 // first see if its a T-COFFEE score file
5307 TCoffeeScoreFile tcf = null;
5310 tcf = new TCoffeeScoreFile(file, protocol);
5313 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5315 tcoffeeColour.setEnabled(true);
5316 tcoffeeColour.setSelected(true);
5317 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5318 isAnnotation = true;
5320 .setText(MessageManager
5321 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5325 // some problem - if no warning its probable that the ID matching
5326 // process didn't work
5330 tcf.getWarningMessage() == null ? MessageManager
5331 .getString("label.check_file_matches_sequence_ids_alignment")
5332 : tcf.getWarningMessage(),
5334 .getString("label.problem_reading_tcoffee_score_file"),
5335 JOptionPane.WARNING_MESSAGE);
5342 } catch (Exception x)
5345 .debug("Exception when processing data source as T-COFFEE score file",
5351 // try to see if its a JNet 'concise' style annotation file *before*
5353 // try to parse it as a features file
5356 format = new IdentifyFile().identify(file, protocol);
5358 if (format.equalsIgnoreCase("JnetFile"))
5360 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5362 new JnetAnnotationMaker();
5363 JnetAnnotationMaker.add_annotation(predictions,
5364 viewport.getAlignment(), 0, false);
5365 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5366 viewport.getAlignment().setSeqrep(repseq);
5367 ColumnSelection cs = new ColumnSelection();
5368 cs.hideInsertionsFor(repseq);
5369 viewport.setColumnSelection(cs);
5370 isAnnotation = true;
5372 else if (IdentifyFile.FeaturesFile.equals(format))
5374 if (parseFeaturesFile(file, protocol))
5376 alignPanel.paintAlignment(true);
5381 new FileLoader().LoadFile(viewport, file, protocol, format);
5388 alignPanel.adjustAnnotationHeight();
5389 viewport.updateSequenceIdColours();
5390 buildSortByAnnotationScoresMenu();
5391 alignPanel.paintAlignment(true);
5393 } catch (Exception ex)
5395 ex.printStackTrace();
5396 } catch (OutOfMemoryError oom)
5401 } catch (Exception x)
5406 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5407 : "using " + protocol + " from " + file)
5409 + (format != null ? "(parsing as '" + format
5410 + "' file)" : ""), oom, Desktop.desktop);
5415 * Method invoked by the ChangeListener on the tabbed pane, in other words
5416 * when a different tabbed pane is selected by the user or programmatically.
5419 public void tabSelectionChanged(int index)
5423 alignPanel = alignPanels.get(index);
5424 viewport = alignPanel.av;
5425 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5426 setMenusFromViewport(viewport);
5430 * If there is a frame linked to this one in a SplitPane, switch it to the
5431 * same view tab index. No infinite recursion of calls should happen, since
5432 * tabSelectionChanged() should not get invoked on setting the selected
5433 * index to an unchanged value. Guard against setting an invalid index
5434 * before the new view peer tab has been created.
5436 final AlignViewportI peer = viewport.getCodingComplement();
5439 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5440 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5442 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5448 * On right mouse click on view tab, prompt for and set new view name.
5451 public void tabbedPane_mousePressed(MouseEvent e)
5453 if (SwingUtilities.isRightMouseButton(e))
5455 String msg = MessageManager.getString("label.enter_view_name");
5456 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5457 JOptionPane.QUESTION_MESSAGE);
5461 viewport.viewName = reply;
5462 // TODO warn if reply is in getExistingViewNames()?
5463 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5468 public AlignViewport getCurrentView()
5474 * Open the dialog for regex description parsing.
5477 protected void extractScores_actionPerformed(ActionEvent e)
5479 ParseProperties pp = new jalview.analysis.ParseProperties(
5480 viewport.getAlignment());
5481 // TODO: verify regex and introduce GUI dialog for version 2.5
5482 // if (pp.getScoresFromDescription("col", "score column ",
5483 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5485 if (pp.getScoresFromDescription("description column",
5486 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5488 buildSortByAnnotationScoresMenu();
5496 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5500 protected void showDbRefs_actionPerformed(ActionEvent e)
5502 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5508 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5512 protected void showNpFeats_actionPerformed(ActionEvent e)
5514 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5518 * find the viewport amongst the tabs in this alignment frame and close that
5523 public boolean closeView(AlignViewportI av)
5527 this.closeMenuItem_actionPerformed(false);
5530 Component[] comp = tabbedPane.getComponents();
5531 for (int i = 0; comp != null && i < comp.length; i++)
5533 if (comp[i] instanceof AlignmentPanel)
5535 if (((AlignmentPanel) comp[i]).av == av)
5538 closeView((AlignmentPanel) comp[i]);
5546 protected void build_fetchdbmenu(JMenu webService)
5548 // Temporary hack - DBRef Fetcher always top level ws entry.
5549 // TODO We probably want to store a sequence database checklist in
5550 // preferences and have checkboxes.. rather than individual sources selected
5552 final JMenu rfetch = new JMenu(
5553 MessageManager.getString("action.fetch_db_references"));
5554 rfetch.setToolTipText(MessageManager
5555 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5556 webService.add(rfetch);
5558 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5559 MessageManager.getString("option.trim_retrieved_seqs"));
5560 trimrs.setToolTipText(MessageManager
5561 .getString("label.trim_retrieved_sequences"));
5562 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5563 trimrs.addActionListener(new ActionListener()
5566 public void actionPerformed(ActionEvent e)
5568 trimrs.setSelected(trimrs.isSelected());
5569 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5570 Boolean.valueOf(trimrs.isSelected()).toString());
5574 JMenuItem fetchr = new JMenuItem(
5575 MessageManager.getString("label.standard_databases"));
5576 fetchr.setToolTipText(MessageManager
5577 .getString("label.fetch_embl_uniprot"));
5578 fetchr.addActionListener(new ActionListener()
5582 public void actionPerformed(ActionEvent e)
5584 new Thread(new Runnable()
5589 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5590 .getAlignment().isNucleotide();
5591 DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
5592 .getSequenceSelection(), alignPanel.alignFrame, null,
5593 alignPanel.alignFrame.featureSettings, isNucleotide);
5594 dbRefFetcher.addListener(new FetchFinishedListenerI()
5597 public void finished()
5599 AlignFrame.this.setMenusForViewport();
5603 .fetchDBRefs(false);
5611 final AlignFrame me = this;
5612 new Thread(new Runnable()
5617 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5618 .getSequenceFetcherSingleton(me);
5619 javax.swing.SwingUtilities.invokeLater(new Runnable()
5624 String[] dbclasses = sf.getOrderedSupportedSources();
5625 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5626 // jalview.util.QuickSort.sort(otherdb, otherdb);
5627 List<DbSourceProxy> otherdb;
5628 JMenu dfetch = new JMenu();
5629 JMenu ifetch = new JMenu();
5630 JMenuItem fetchr = null;
5631 int comp = 0, icomp = 0, mcomp = 15;
5632 String mname = null;
5634 for (String dbclass : dbclasses)
5636 otherdb = sf.getSourceProxy(dbclass);
5637 // add a single entry for this class, or submenu allowing 'fetch
5639 if (otherdb == null || otherdb.size() < 1)
5643 // List<DbSourceProxy> dbs=otherdb;
5644 // otherdb=new ArrayList<DbSourceProxy>();
5645 // for (DbSourceProxy db:dbs)
5647 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5651 mname = "From " + dbclass;
5653 if (otherdb.size() == 1)
5655 final DbSourceProxy[] dassource = otherdb
5656 .toArray(new DbSourceProxy[0]);
5657 DbSourceProxy src = otherdb.get(0);
5658 fetchr = new JMenuItem(src.getDbSource());
5659 fetchr.addActionListener(new ActionListener()
5663 public void actionPerformed(ActionEvent e)
5665 new Thread(new Runnable()
5671 boolean isNucleotide = alignPanel.alignFrame
5672 .getViewport().getAlignment()
5674 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5675 alignPanel.av.getSequenceSelection(),
5676 alignPanel.alignFrame, dassource,
5677 alignPanel.alignFrame.featureSettings,
5680 .addListener(new FetchFinishedListenerI()
5683 public void finished()
5685 AlignFrame.this.setMenusForViewport();
5688 dbRefFetcher.fetchDBRefs(false);
5694 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5695 MessageManager.formatMessage(
5696 "label.fetch_retrieve_from",
5697 new Object[] { src.getDbName() })));
5703 final DbSourceProxy[] dassource = otherdb
5704 .toArray(new DbSourceProxy[0]);
5706 DbSourceProxy src = otherdb.get(0);
5707 fetchr = new JMenuItem(MessageManager.formatMessage(
5708 "label.fetch_all_param",
5709 new Object[] { src.getDbSource() }));
5710 fetchr.addActionListener(new ActionListener()
5713 public void actionPerformed(ActionEvent e)
5715 new Thread(new Runnable()
5721 boolean isNucleotide = alignPanel.alignFrame
5722 .getViewport().getAlignment()
5724 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5725 alignPanel.av.getSequenceSelection(),
5726 alignPanel.alignFrame, dassource,
5727 alignPanel.alignFrame.featureSettings,
5730 .addListener(new FetchFinishedListenerI()
5733 public void finished()
5735 AlignFrame.this.setMenusForViewport();
5738 dbRefFetcher.fetchDBRefs(false);
5744 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5745 MessageManager.formatMessage(
5746 "label.fetch_retrieve_from_all_sources",
5748 Integer.valueOf(otherdb.size())
5749 .toString(), src.getDbSource(),
5750 src.getDbName() })));
5753 // and then build the rest of the individual menus
5754 ifetch = new JMenu(MessageManager.formatMessage(
5755 "label.source_from_db_source",
5756 new Object[] { src.getDbSource() }));
5758 String imname = null;
5760 for (DbSourceProxy sproxy : otherdb)
5762 String dbname = sproxy.getDbName();
5763 String sname = dbname.length() > 5 ? dbname.substring(0,
5764 5) + "..." : dbname;
5765 String msname = dbname.length() > 10 ? dbname.substring(
5766 0, 10) + "..." : dbname;
5769 imname = MessageManager.formatMessage(
5770 "label.from_msname", new Object[] { sname });
5772 fetchr = new JMenuItem(msname);
5773 final DbSourceProxy[] dassrc = { sproxy };
5774 fetchr.addActionListener(new ActionListener()
5778 public void actionPerformed(ActionEvent e)
5780 new Thread(new Runnable()
5786 boolean isNucleotide = alignPanel.alignFrame
5787 .getViewport().getAlignment()
5789 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5790 alignPanel.av.getSequenceSelection(),
5791 alignPanel.alignFrame, dassrc,
5792 alignPanel.alignFrame.featureSettings,
5795 .addListener(new FetchFinishedListenerI()
5798 public void finished()
5800 AlignFrame.this.setMenusForViewport();
5803 dbRefFetcher.fetchDBRefs(false);
5809 fetchr.setToolTipText("<html>"
5810 + MessageManager.formatMessage(
5811 "label.fetch_retrieve_from", new Object[]
5815 if (++icomp >= mcomp || i == (otherdb.size()))
5817 ifetch.setText(MessageManager.formatMessage(
5818 "label.source_to_target", imname, sname));
5820 ifetch = new JMenu();
5828 if (comp >= mcomp || dbi >= (dbclasses.length))
5830 dfetch.setText(MessageManager.formatMessage(
5831 "label.source_to_target", mname, dbclass));
5833 dfetch = new JMenu();
5846 * Left justify the whole alignment.
5849 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5851 AlignmentI al = viewport.getAlignment();
5853 viewport.firePropertyChange("alignment", null, al);
5857 * Right justify the whole alignment.
5860 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5862 AlignmentI al = viewport.getAlignment();
5864 viewport.firePropertyChange("alignment", null, al);
5868 public void setShowSeqFeatures(boolean b)
5870 showSeqFeatures.setSelected(b);
5871 viewport.setShowSequenceFeatures(b);
5878 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5879 * awt.event.ActionEvent)
5882 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5884 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5885 alignPanel.paintAlignment(true);
5892 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5896 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5898 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5899 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5907 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5908 * .event.ActionEvent)
5911 protected void showGroupConservation_actionPerformed(ActionEvent e)
5913 viewport.setShowGroupConservation(showGroupConservation.getState());
5914 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5921 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5922 * .event.ActionEvent)
5925 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5927 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5928 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5935 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5936 * .event.ActionEvent)
5939 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5941 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5942 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5946 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5948 showSequenceLogo.setState(true);
5949 viewport.setShowSequenceLogo(true);
5950 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5951 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5955 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5957 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5964 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5965 * .event.ActionEvent)
5968 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5970 if (avc.makeGroupsFromSelection())
5972 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5973 alignPanel.updateAnnotation();
5974 alignPanel.paintAlignment(true);
5978 public void clearAlignmentSeqRep()
5980 // TODO refactor alignmentseqrep to controller
5981 if (viewport.getAlignment().hasSeqrep())
5983 viewport.getAlignment().setSeqrep(null);
5984 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5985 alignPanel.updateAnnotation();
5986 alignPanel.paintAlignment(true);
5991 protected void createGroup_actionPerformed(ActionEvent e)
5993 if (avc.createGroup())
5995 alignPanel.alignmentChanged();
6000 protected void unGroup_actionPerformed(ActionEvent e)
6004 alignPanel.alignmentChanged();
6009 * make the given alignmentPanel the currently selected tab
6011 * @param alignmentPanel
6013 public void setDisplayedView(AlignmentPanel alignmentPanel)
6015 if (!viewport.getSequenceSetId().equals(
6016 alignmentPanel.av.getSequenceSetId()))
6020 .getString("error.implementation_error_cannot_show_view_alignment_frame"));
6022 if (tabbedPane != null
6023 && tabbedPane.getTabCount() > 0
6024 && alignPanels.indexOf(alignmentPanel) != tabbedPane
6025 .getSelectedIndex())
6027 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
6032 * Action on selection of menu options to Show or Hide annotations.
6035 * @param forSequences
6036 * update sequence-related annotations
6037 * @param forAlignment
6038 * update non-sequence-related annotations
6041 protected void setAnnotationsVisibility(boolean visible,
6042 boolean forSequences, boolean forAlignment)
6044 for (AlignmentAnnotation aa : alignPanel.getAlignment()
6045 .getAlignmentAnnotation())
6048 * don't display non-positional annotations on an alignment
6050 if (aa.annotations == null)
6054 boolean apply = (aa.sequenceRef == null && forAlignment)
6055 || (aa.sequenceRef != null && forSequences);
6058 aa.visible = visible;
6061 alignPanel.validateAnnotationDimensions(true);
6062 alignPanel.alignmentChanged();
6066 * Store selected annotation sort order for the view and repaint.
6069 protected void sortAnnotations_actionPerformed()
6071 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6073 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6074 alignPanel.paintAlignment(true);
6079 * @return alignment panels in this alignment frame
6081 public List<? extends AlignmentViewPanel> getAlignPanels()
6083 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
6087 * Open a new alignment window, with the cDNA associated with this (protein)
6088 * alignment, aligned as is the protein.
6090 protected void viewAsCdna_actionPerformed()
6092 // TODO no longer a menu action - refactor as required
6093 final AlignmentI alignment = getViewport().getAlignment();
6094 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6095 if (mappings == null)
6099 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6100 for (SequenceI aaSeq : alignment.getSequences())
6102 for (AlignedCodonFrame acf : mappings)
6104 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6108 * There is a cDNA mapping for this protein sequence - add to new
6109 * alignment. It will share the same dataset sequence as other mapped
6110 * cDNA (no new mappings need to be created).
6112 final Sequence newSeq = new Sequence(dnaSeq);
6113 newSeq.setDatasetSequence(dnaSeq);
6114 cdnaSeqs.add(newSeq);
6118 if (cdnaSeqs.size() == 0)
6120 // show a warning dialog no mapped cDNA
6123 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6125 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6126 AlignFrame.DEFAULT_HEIGHT);
6127 cdna.alignAs(alignment);
6128 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6130 Desktop.addInternalFrame(alignFrame, newtitle,
6131 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
6135 * Set visibility of dna/protein complement view (available when shown in a
6141 protected void showComplement_actionPerformed(boolean show)
6143 SplitContainerI sf = getSplitViewContainer();
6146 sf.setComplementVisible(this, show);
6151 * Generate the reverse (optionally complemented) of the selected sequences,
6152 * and add them to the alignment
6155 protected void showReverse_actionPerformed(boolean complement)
6157 AlignmentI al = null;
6160 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
6162 al = dna.reverseCdna(complement);
6163 viewport.addAlignment(al, "");
6164 } catch (Exception ex)
6166 System.err.println(ex.getMessage());
6172 class PrintThread extends Thread
6176 public PrintThread(AlignmentPanel ap)
6181 static PageFormat pf;
6186 PrinterJob printJob = PrinterJob.getPrinterJob();
6190 printJob.setPrintable(ap, pf);
6194 printJob.setPrintable(ap);
6197 if (printJob.printDialog())
6202 } catch (Exception PrintException)
6204 PrintException.printStackTrace();