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.AAFrequency;
24 import jalview.analysis.AlignmentSorter;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.analysis.CrossRef;
28 import jalview.analysis.Dna;
29 import jalview.analysis.ParseProperties;
30 import jalview.analysis.SequenceIdMatcher;
31 import jalview.api.AlignExportSettingI;
32 import jalview.api.AlignViewControllerGuiI;
33 import jalview.api.AlignViewControllerI;
34 import jalview.api.AlignViewportI;
35 import jalview.api.AlignmentViewPanel;
36 import jalview.api.FeatureSettingsControllerI;
37 import jalview.api.SplitContainerI;
38 import jalview.api.ViewStyleI;
39 import jalview.api.analysis.ScoreModelI;
40 import jalview.bin.Cache;
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.AlignmentI;
53 import jalview.datamodel.AlignmentOrder;
54 import jalview.datamodel.AlignmentView;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.HiddenSequences;
57 import jalview.datamodel.PDBEntry;
58 import jalview.datamodel.SeqCigar;
59 import jalview.datamodel.Sequence;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
63 import jalview.io.AlignmentProperties;
64 import jalview.io.AnnotationFile;
65 import jalview.io.BioJsHTMLOutput;
66 import jalview.io.FileLoader;
67 import jalview.io.FormatAdapter;
68 import jalview.io.HtmlSvgOutput;
69 import jalview.io.IdentifyFile;
70 import jalview.io.JalviewFileChooser;
71 import jalview.io.JalviewFileView;
72 import jalview.io.JnetAnnotationMaker;
73 import jalview.io.NewickFile;
74 import jalview.io.TCoffeeScoreFile;
75 import jalview.jbgui.GAlignFrame;
76 import jalview.schemes.Blosum62ColourScheme;
77 import jalview.schemes.BuriedColourScheme;
78 import jalview.schemes.ClustalxColourScheme;
79 import jalview.schemes.ColourSchemeI;
80 import jalview.schemes.ColourSchemeProperty;
81 import jalview.schemes.HelixColourScheme;
82 import jalview.schemes.HydrophobicColourScheme;
83 import jalview.schemes.NucleotideColourScheme;
84 import jalview.schemes.PIDColourScheme;
85 import jalview.schemes.PurinePyrimidineColourScheme;
86 import jalview.schemes.RNAHelicesColourChooser;
87 import jalview.schemes.ResidueProperties;
88 import jalview.schemes.StrandColourScheme;
89 import jalview.schemes.TCoffeeColourScheme;
90 import jalview.schemes.TaylorColourScheme;
91 import jalview.schemes.TurnColourScheme;
92 import jalview.schemes.UserColourScheme;
93 import jalview.schemes.ZappoColourScheme;
94 import jalview.structure.StructureSelectionManager;
95 import jalview.util.MessageManager;
96 import jalview.viewmodel.AlignmentViewport;
97 import jalview.ws.jws1.Discoverer;
98 import jalview.ws.jws2.Jws2Discoverer;
99 import jalview.ws.jws2.jabaws2.Jws2Instance;
100 import jalview.ws.seqfetcher.DbSourceProxy;
102 import java.awt.BorderLayout;
103 import java.awt.Component;
104 import java.awt.Rectangle;
105 import java.awt.Toolkit;
106 import java.awt.datatransfer.Clipboard;
107 import java.awt.datatransfer.DataFlavor;
108 import java.awt.datatransfer.StringSelection;
109 import java.awt.datatransfer.Transferable;
110 import java.awt.dnd.DnDConstants;
111 import java.awt.dnd.DropTargetDragEvent;
112 import java.awt.dnd.DropTargetDropEvent;
113 import java.awt.dnd.DropTargetEvent;
114 import java.awt.dnd.DropTargetListener;
115 import java.awt.event.ActionEvent;
116 import java.awt.event.ActionListener;
117 import java.awt.event.ItemEvent;
118 import java.awt.event.ItemListener;
119 import java.awt.event.KeyAdapter;
120 import java.awt.event.KeyEvent;
121 import java.awt.event.MouseAdapter;
122 import java.awt.event.MouseEvent;
123 import java.awt.print.PageFormat;
124 import java.awt.print.PrinterJob;
125 import java.beans.PropertyChangeEvent;
128 import java.util.ArrayList;
129 import java.util.Arrays;
130 import java.util.Deque;
131 import java.util.Enumeration;
132 import java.util.Hashtable;
133 import java.util.List;
134 import java.util.Set;
135 import java.util.Vector;
137 import javax.swing.JCheckBoxMenuItem;
138 import javax.swing.JEditorPane;
139 import javax.swing.JInternalFrame;
140 import javax.swing.JLayeredPane;
141 import javax.swing.JMenu;
142 import javax.swing.JMenuItem;
143 import javax.swing.JOptionPane;
144 import javax.swing.JRadioButtonMenuItem;
145 import javax.swing.JScrollPane;
146 import javax.swing.SwingUtilities;
152 * @version $Revision$
154 public class AlignFrame extends GAlignFrame implements DropTargetListener,
155 IProgressIndicator, AlignViewControllerGuiI
158 public static final int DEFAULT_WIDTH = 700;
160 public static final int DEFAULT_HEIGHT = 500;
163 * The currently displayed panel (selected tabbed view if more than one)
165 public AlignmentPanel alignPanel;
167 AlignViewport viewport;
169 public AlignViewControllerI avc;
171 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
174 * Last format used to load or save alignments in this window
176 String currentFileFormat = null;
179 * Current filename for this alignment
181 String fileName = null;
184 * Creates a new AlignFrame object with specific width and height.
190 public AlignFrame(AlignmentI al, int width, int height)
192 this(al, null, width, height);
196 * Creates a new AlignFrame object with specific width, height and
202 * @param sequenceSetId
204 public AlignFrame(AlignmentI al, int width, int height,
205 String sequenceSetId)
207 this(al, null, width, height, sequenceSetId);
211 * Creates a new AlignFrame object with specific width, height and
217 * @param sequenceSetId
220 public AlignFrame(AlignmentI al, int width, int height,
221 String sequenceSetId, String viewId)
223 this(al, null, width, height, sequenceSetId, viewId);
227 * new alignment window with hidden columns
231 * @param hiddenColumns
232 * ColumnSelection or null
234 * Width of alignment frame
238 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
239 int width, int height)
241 this(al, hiddenColumns, width, height, null);
246 * Create alignment frame for al with hiddenColumns, a specific width and
247 * height, and specific sequenceId
250 * @param hiddenColumns
253 * @param sequenceSetId
256 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
257 int width, int height, String sequenceSetId)
259 this(al, hiddenColumns, width, height, sequenceSetId, null);
263 * Create alignment frame for al with hiddenColumns, a specific width and
264 * height, and specific sequenceId
267 * @param hiddenColumns
270 * @param sequenceSetId
275 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
276 int width, int height, String sequenceSetId, String viewId)
278 setSize(width, height);
280 if (al.getDataset() == null)
285 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
287 alignPanel = new AlignmentPanel(this, viewport);
290 addAlignmentPanel(alignPanel, true);
294 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
295 ColumnSelection hiddenColumns, int width, int height)
297 setSize(width, height);
299 if (al.getDataset() == null)
304 viewport = new AlignViewport(al, hiddenColumns);
306 if (hiddenSeqs != null && hiddenSeqs.length > 0)
308 viewport.hideSequence(hiddenSeqs);
309 viewport.setHasHiddenRows(true);
311 alignPanel = new AlignmentPanel(this, viewport);
312 addAlignmentPanel(alignPanel, true);
318 * Make a new AlignFrame from existing alignmentPanels
325 public AlignFrame(AlignmentPanel ap)
329 addAlignmentPanel(ap, false);
334 * initalise the alignframe from the underlying viewport data and the
339 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
341 avc = new jalview.controller.AlignViewController(this, viewport,
343 if (viewport.getAlignmentConservationAnnotation() == null)
345 BLOSUM62Colour.setEnabled(false);
346 conservationMenuItem.setEnabled(false);
347 modifyConservation.setEnabled(false);
348 // PIDColour.setEnabled(false);
349 // abovePIDThreshold.setEnabled(false);
350 // modifyPID.setEnabled(false);
353 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
356 if (sortby.equals("Id"))
358 sortIDMenuItem_actionPerformed(null);
360 else if (sortby.equals("Pairwise Identity"))
362 sortPairwiseMenuItem_actionPerformed(null);
365 if (Desktop.desktop != null)
367 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
368 addServiceListeners();
369 setGUINucleotide(viewport.getAlignment().isNucleotide());
372 setMenusFromViewport(viewport);
373 buildSortByAnnotationScoresMenu();
376 if (viewport.getWrapAlignment())
378 wrapMenuItem_actionPerformed(null);
381 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
383 this.overviewMenuItem_actionPerformed(null);
388 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
389 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
390 final String menuLabel = MessageManager
391 .getString("label.copy_format_from");
392 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
393 new ViewSetProvider()
397 public AlignmentPanel[] getAllAlignmentPanels()
400 origview.add(alignPanel);
401 // make an array of all alignment panels except for this one
402 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
403 Arrays.asList(Desktop.getAlignmentPanels(null)));
404 aps.remove(AlignFrame.this.alignPanel);
405 return aps.toArray(new AlignmentPanel[aps.size()]);
407 }, selviews, new ItemListener()
411 public void itemStateChanged(ItemEvent e)
413 if (origview.size() > 0)
415 final AlignmentPanel ap = origview.get(0);
418 * Copy the ViewStyle of the selected panel to 'this one'.
419 * Don't change value of 'scaleProteinAsCdna' unless copying
422 ViewStyleI vs = selviews.get(0).getAlignViewport()
424 boolean fromSplitFrame = selviews.get(0)
425 .getAlignViewport().getCodingComplement() != null;
428 vs.setScaleProteinAsCdna(ap.getAlignViewport()
429 .getViewStyle().isScaleProteinAsCdna());
431 ap.getAlignViewport().setViewStyle(vs);
434 * Also rescale ViewStyle of SplitFrame complement if there is
435 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
436 * the whole ViewStyle (allow cDNA protein to have different
439 AlignViewportI complement = ap.getAlignViewport()
440 .getCodingComplement();
441 if (complement != null && vs.isScaleProteinAsCdna())
443 AlignFrame af = Desktop.getAlignFrameFor(complement);
444 ((SplitFrame) af.getSplitViewContainer())
446 af.setMenusForViewport();
450 ap.setSelected(true);
451 ap.alignFrame.setMenusForViewport();
456 formatMenu.add(vsel);
461 * Change the filename and format for the alignment, and enable the 'reload'
462 * button functionality.
469 public void setFileName(String file, String format)
472 setFileFormat(format);
473 reload.setEnabled(true);
477 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
480 void addKeyListener()
482 addKeyListener(new KeyAdapter()
485 public void keyPressed(KeyEvent evt)
487 if (viewport.cursorMode
488 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
489 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
490 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
491 && Character.isDigit(evt.getKeyChar()))
493 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
496 switch (evt.getKeyCode())
499 case 27: // escape key
500 deselectAllSequenceMenuItem_actionPerformed(null);
504 case KeyEvent.VK_DOWN:
505 if (evt.isAltDown() || !viewport.cursorMode)
507 moveSelectedSequences(false);
509 if (viewport.cursorMode)
511 alignPanel.getSeqPanel().moveCursor(0, 1);
516 if (evt.isAltDown() || !viewport.cursorMode)
518 moveSelectedSequences(true);
520 if (viewport.cursorMode)
522 alignPanel.getSeqPanel().moveCursor(0, -1);
527 case KeyEvent.VK_LEFT:
528 if (evt.isAltDown() || !viewport.cursorMode)
530 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
534 alignPanel.getSeqPanel().moveCursor(-1, 0);
539 case KeyEvent.VK_RIGHT:
540 if (evt.isAltDown() || !viewport.cursorMode)
542 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
546 alignPanel.getSeqPanel().moveCursor(1, 0);
550 case KeyEvent.VK_SPACE:
551 if (viewport.cursorMode)
553 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
554 || evt.isShiftDown() || evt.isAltDown());
558 // case KeyEvent.VK_A:
559 // if (viewport.cursorMode)
561 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
562 // //System.out.println("A");
566 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
567 * System.out.println("closing bracket"); } break;
569 case KeyEvent.VK_DELETE:
570 case KeyEvent.VK_BACK_SPACE:
571 if (!viewport.cursorMode)
573 cut_actionPerformed(null);
577 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
578 || evt.isShiftDown() || evt.isAltDown());
584 if (viewport.cursorMode)
586 alignPanel.getSeqPanel().setCursorRow();
590 if (viewport.cursorMode && !evt.isControlDown())
592 alignPanel.getSeqPanel().setCursorColumn();
596 if (viewport.cursorMode)
598 alignPanel.getSeqPanel().setCursorPosition();
602 case KeyEvent.VK_ENTER:
603 case KeyEvent.VK_COMMA:
604 if (viewport.cursorMode)
606 alignPanel.getSeqPanel().setCursorRowAndColumn();
611 if (viewport.cursorMode)
613 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
617 if (viewport.cursorMode)
619 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
624 viewport.cursorMode = !viewport.cursorMode;
625 statusBar.setText(MessageManager.formatMessage(
626 "label.keyboard_editing_mode", new String[]
627 { (viewport.cursorMode ? "on" : "off") }));
628 if (viewport.cursorMode)
630 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
631 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
633 alignPanel.getSeqPanel().seqCanvas.repaint();
639 Help.showHelpWindow();
640 } catch (Exception ex)
642 ex.printStackTrace();
647 boolean toggleSeqs = !evt.isControlDown();
648 boolean toggleCols = !evt.isShiftDown();
649 toggleHiddenRegions(toggleSeqs, toggleCols);
652 case KeyEvent.VK_PAGE_UP:
653 if (viewport.getWrapAlignment())
655 alignPanel.scrollUp(true);
659 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
660 - viewport.endSeq + viewport.startSeq);
663 case KeyEvent.VK_PAGE_DOWN:
664 if (viewport.getWrapAlignment())
666 alignPanel.scrollUp(false);
670 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
671 + viewport.endSeq - viewport.startSeq);
678 public void keyReleased(KeyEvent evt)
680 switch (evt.getKeyCode())
682 case KeyEvent.VK_LEFT:
683 if (evt.isAltDown() || !viewport.cursorMode)
685 viewport.firePropertyChange("alignment", null, viewport
686 .getAlignment().getSequences());
690 case KeyEvent.VK_RIGHT:
691 if (evt.isAltDown() || !viewport.cursorMode)
693 viewport.firePropertyChange("alignment", null, viewport
694 .getAlignment().getSequences());
702 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
704 ap.alignFrame = this;
705 avc = new jalview.controller.AlignViewController(this, viewport,
710 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
712 int aSize = alignPanels.size();
714 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
716 if (aSize == 1 && ap.av.viewName == null)
718 this.getContentPane().add(ap, BorderLayout.CENTER);
724 setInitialTabVisible();
727 expandViews.setEnabled(true);
728 gatherViews.setEnabled(true);
729 tabbedPane.addTab(ap.av.viewName, ap);
731 ap.setVisible(false);
736 if (ap.av.isPadGaps())
738 ap.av.getAlignment().padGaps();
740 ap.av.updateConservation(ap);
741 ap.av.updateConsensus(ap);
742 ap.av.updateStrucConsensus(ap);
746 public void setInitialTabVisible()
748 expandViews.setEnabled(true);
749 gatherViews.setEnabled(true);
750 tabbedPane.setVisible(true);
751 AlignmentPanel first = alignPanels.get(0);
752 tabbedPane.addTab(first.av.viewName, first);
753 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
756 public AlignViewport getViewport()
761 /* Set up intrinsic listeners for dynamically generated GUI bits. */
762 private void addServiceListeners()
764 final java.beans.PropertyChangeListener thisListener;
765 Desktop.instance.addJalviewPropertyChangeListener("services",
766 thisListener = new java.beans.PropertyChangeListener()
769 public void propertyChange(PropertyChangeEvent evt)
771 // // System.out.println("Discoverer property change.");
772 // if (evt.getPropertyName().equals("services"))
774 SwingUtilities.invokeLater(new Runnable()
781 .println("Rebuild WS Menu for service change");
782 BuildWebServiceMenu();
789 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
792 public void internalFrameClosed(
793 javax.swing.event.InternalFrameEvent evt)
795 System.out.println("deregistering discoverer listener");
796 Desktop.instance.removeJalviewPropertyChangeListener("services",
798 closeMenuItem_actionPerformed(true);
801 // Finally, build the menu once to get current service state
802 new Thread(new Runnable()
807 BuildWebServiceMenu();
813 * Configure menu items that vary according to whether the alignment is
814 * nucleotide or protein
818 public void setGUINucleotide(boolean nucleotide)
820 showTranslation.setVisible(nucleotide);
821 conservationMenuItem.setEnabled(!nucleotide);
822 modifyConservation.setEnabled(!nucleotide);
823 showGroupConservation.setEnabled(!nucleotide);
824 rnahelicesColour.setEnabled(nucleotide);
825 purinePyrimidineColour.setEnabled(nucleotide);
826 showComplementMenuItem.setText(MessageManager
827 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
828 setColourSelected(jalview.bin.Cache.getDefault(
829 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
830 : Preferences.DEFAULT_COLOUR_PROT, "None"));
834 * set up menus for the current viewport. This may be called after any
835 * operation that affects the data in the current view (selection changed,
836 * etc) to update the menus to reflect the new state.
838 public void setMenusForViewport()
840 setMenusFromViewport(viewport);
844 * Need to call this method when tabs are selected for multiple views, or when
845 * loading from Jalview2XML.java
850 void setMenusFromViewport(AlignViewport av)
852 padGapsMenuitem.setSelected(av.isPadGaps());
853 colourTextMenuItem.setSelected(av.isShowColourText());
854 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
855 conservationMenuItem.setSelected(av.getConservationSelected());
856 seqLimits.setSelected(av.getShowJVSuffix());
857 idRightAlign.setSelected(av.isRightAlignIds());
858 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
859 renderGapsMenuItem.setSelected(av.isRenderGaps());
860 wrapMenuItem.setSelected(av.getWrapAlignment());
861 scaleAbove.setVisible(av.getWrapAlignment());
862 scaleLeft.setVisible(av.getWrapAlignment());
863 scaleRight.setVisible(av.getWrapAlignment());
864 annotationPanelMenuItem.setState(av.isShowAnnotation());
866 * Show/hide annotations only enabled if annotation panel is shown
868 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
869 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
870 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
871 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
872 viewBoxesMenuItem.setSelected(av.getShowBoxes());
873 viewTextMenuItem.setSelected(av.getShowText());
874 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
875 showGroupConsensus.setSelected(av.isShowGroupConsensus());
876 showGroupConservation.setSelected(av.isShowGroupConservation());
877 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
878 showSequenceLogo.setSelected(av.isShowSequenceLogo());
879 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
881 setColourSelected(ColourSchemeProperty.getColourName(av
882 .getGlobalColourScheme()));
884 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
885 hiddenMarkers.setState(av.getShowHiddenMarkers());
886 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
887 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
888 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
889 autoCalculate.setSelected(av.autoCalculateConsensus);
890 sortByTree.setSelected(av.sortByTree);
891 listenToViewSelections.setSelected(av.followSelection);
892 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
894 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
895 setShowProductsEnabled();
899 private IProgressIndicator progressBar;
904 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
907 public void setProgressBar(String message, long id)
909 progressBar.setProgressBar(message, id);
913 public void registerHandler(final long id,
914 final IProgressIndicatorHandler handler)
916 progressBar.registerHandler(id, handler);
921 * @return true if any progress bars are still active
924 public boolean operationInProgress()
926 return progressBar.operationInProgress();
930 public void setStatus(String text)
932 statusBar.setText(text);
936 * Added so Castor Mapping file can obtain Jalview Version
938 public String getVersion()
940 return jalview.bin.Cache.getProperty("VERSION");
943 public FeatureRenderer getFeatureRenderer()
945 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
949 public void fetchSequence_actionPerformed(ActionEvent e)
951 new SequenceFetcher(this);
955 public void addFromFile_actionPerformed(ActionEvent e)
957 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
961 public void reload_actionPerformed(ActionEvent e)
963 if (fileName != null)
965 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
966 // originating file's format
967 // TODO: work out how to recover feature settings for correct view(s) when
969 if (currentFileFormat.equals("Jalview"))
971 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
972 for (int i = 0; i < frames.length; i++)
974 if (frames[i] instanceof AlignFrame && frames[i] != this
975 && ((AlignFrame) frames[i]).fileName != null
976 && ((AlignFrame) frames[i]).fileName.equals(fileName))
980 frames[i].setSelected(true);
981 Desktop.instance.closeAssociatedWindows();
982 } catch (java.beans.PropertyVetoException ex)
988 Desktop.instance.closeAssociatedWindows();
990 FileLoader loader = new FileLoader();
991 String protocol = fileName.startsWith("http:") ? "URL" : "File";
992 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
996 Rectangle bounds = this.getBounds();
998 FileLoader loader = new FileLoader();
999 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1000 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1001 protocol, currentFileFormat);
1003 newframe.setBounds(bounds);
1004 if (featureSettings != null && featureSettings.isShowing())
1006 final Rectangle fspos = featureSettings.frame.getBounds();
1007 // TODO: need a 'show feature settings' function that takes bounds -
1008 // need to refactor Desktop.addFrame
1009 newframe.featureSettings_actionPerformed(null);
1010 final FeatureSettings nfs = newframe.featureSettings;
1011 SwingUtilities.invokeLater(new Runnable()
1016 nfs.frame.setBounds(fspos);
1019 this.featureSettings.close();
1020 this.featureSettings = null;
1022 this.closeMenuItem_actionPerformed(true);
1028 public void addFromText_actionPerformed(ActionEvent e)
1030 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1034 public void addFromURL_actionPerformed(ActionEvent e)
1036 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1040 public void save_actionPerformed(ActionEvent e)
1042 if (fileName == null
1043 || (currentFileFormat == null || !jalview.io.FormatAdapter
1044 .isValidIOFormat(currentFileFormat, true))
1045 || fileName.startsWith("http"))
1047 saveAs_actionPerformed(null);
1051 saveAlignment(fileName, currentFileFormat);
1062 public void saveAs_actionPerformed(ActionEvent e)
1064 JalviewFileChooser chooser = new JalviewFileChooser(
1065 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1066 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1067 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1068 currentFileFormat, false);
1070 chooser.setFileView(new JalviewFileView());
1071 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1072 chooser.setToolTipText(MessageManager.getString("action.save"));
1074 int value = chooser.showSaveDialog(this);
1076 if (value == JalviewFileChooser.APPROVE_OPTION)
1078 currentFileFormat = chooser.getSelectedFormat();
1079 while (currentFileFormat == null)
1082 .showInternalMessageDialog(
1085 .getString("label.select_file_format_before_saving"),
1087 .getString("label.file_format_not_specified"),
1088 JOptionPane.WARNING_MESSAGE);
1089 currentFileFormat = chooser.getSelectedFormat();
1090 value = chooser.showSaveDialog(this);
1091 if (value != JalviewFileChooser.APPROVE_OPTION)
1097 fileName = chooser.getSelectedFile().getPath();
1099 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1102 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1103 if (currentFileFormat.indexOf(" ") > -1)
1105 currentFileFormat = currentFileFormat.substring(0,
1106 currentFileFormat.indexOf(" "));
1108 saveAlignment(fileName, currentFileFormat);
1112 public boolean saveAlignment(String file, String format)
1114 boolean success = true;
1116 if (format.equalsIgnoreCase("Jalview"))
1118 String shortName = title;
1120 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1122 shortName = shortName.substring(shortName
1123 .lastIndexOf(java.io.File.separatorChar) + 1);
1126 success = new Jalview2XML().saveAlignment(this, file, shortName);
1128 statusBar.setText(MessageManager.formatMessage(
1129 "label.successfully_saved_to_file_in_format", new Object[]
1130 { fileName, format }));
1135 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1137 warningMessage("Cannot save file " + fileName + " using format "
1138 + format, "Alignment output format not supported");
1139 saveAs_actionPerformed(null);
1140 // JBPNote need to have a raise_gui flag here
1144 ExportData exportData = getAlignmentForExport(format);
1145 FormatAdapter f = new FormatAdapter(viewport);
1146 String output = f.formatSequences(format,
1147 exportData.getAlignment(), // class cast exceptions will
1148 // occur in the distant future
1149 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1150 f.getCacheSuffixDefault(format),
1151 viewport.getColumnSelection());
1161 java.io.PrintWriter out = new java.io.PrintWriter(
1162 new java.io.FileWriter(file));
1166 this.setTitle(file);
1167 statusBar.setText(MessageManager.formatMessage(
1168 "label.successfully_saved_to_file_in_format",
1170 { fileName, format }));
1171 } catch (Exception ex)
1174 ex.printStackTrace();
1181 JOptionPane.showInternalMessageDialog(this, MessageManager
1182 .formatMessage("label.couldnt_save_file", new Object[]
1183 { fileName }), MessageManager
1184 .getString("label.error_saving_file"),
1185 JOptionPane.WARNING_MESSAGE);
1192 private void warningMessage(String warning, String title)
1194 if (new jalview.util.Platform().isHeadless())
1196 System.err.println("Warning: " + title + "\nWarning: " + warning);
1201 JOptionPane.showInternalMessageDialog(this, warning, title,
1202 JOptionPane.WARNING_MESSAGE);
1214 protected void outputText_actionPerformed(ActionEvent e)
1217 ExportData exportData = getAlignmentForExport(e.getActionCommand());
1218 if (exportData.getSettings().isCancelled())
1222 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1223 cap.setForInput(null);
1226 cap.setText(new FormatAdapter(viewport).formatSequences(
1227 e.getActionCommand(),
1228 exportData.getAlignment(),
1229 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1230 viewport.getColumnSelection()));
1231 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1232 "label.alignment_output_command", new Object[]
1233 { e.getActionCommand() }), 600, 500);
1234 } catch (OutOfMemoryError oom)
1236 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1242 public ExportData getAlignmentForExport(String exportFomat)
1244 AlignmentI alignmentToExport = null;
1245 String[] omitHidden = null;
1246 int[] alignmentStartEnd = new int[2];
1248 HiddenSequences hiddenSeqs = viewport.getAlignment()
1249 .getHiddenSequences();
1252 alignmentToExport = viewport.getAlignment();
1253 alignmentStartEnd = new int[]
1254 { 0, alignmentToExport.getWidth() - 1 };
1256 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1257 AlignExportSettingI settings = new AlignExportSettings(hasHiddenSeqs,
1258 viewport.hasHiddenColumns(), exportFomat);
1259 settings.isExportAnnotations();
1261 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1263 omitHidden = viewport.getViewAsString(false);
1266 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1268 alignmentToExport = hiddenSeqs.getFullAlignment();
1272 alignmentToExport = viewport.getAlignment();
1273 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1274 .getColumnSelection().getHiddenColumns());
1276 return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd,
1280 private static int[] getStartEnd(int[] aligmentStartEnd,
1281 List<int[]> hiddenCols)
1283 int startPos = aligmentStartEnd[0];
1284 int endPos = aligmentStartEnd[1];
1286 int[] lowestRange = new int[2];
1287 int[] higestRange = new int[2];
1289 for (int[] hiddenCol : hiddenCols)
1291 // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
1293 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1294 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1296 // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
1297 // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
1299 if (lowestRange[0] == 0 && lowestRange[1] == 0)
1301 startPos = aligmentStartEnd[0];
1305 startPos = lowestRange[1] + 1;
1308 if (higestRange[0] == 0 && higestRange[1] == 0)
1310 endPos = aligmentStartEnd[1];
1314 endPos = higestRange[0];
1317 // System.out.println("Export range : " + minPos + " - " + maxPos);
1319 { startPos, endPos };
1322 public static void main(String[] args)
1324 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1325 hiddenCols.add(new int[]
1327 hiddenCols.add(new int[]
1329 hiddenCols.add(new int[]
1331 hiddenCols.add(new int[]
1333 hiddenCols.add(new int[]
1336 int[] x = getStartEnd(new int[]
1337 { 0, 50 }, hiddenCols);
1338 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1348 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1350 new HtmlSvgOutput(null, alignPanel);
1354 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1356 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1357 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1359 public void createImageMap(File file, String image)
1361 alignPanel.makePNGImageMap(file, image);
1371 public void createPNG(File f)
1373 alignPanel.makePNG(f);
1383 public void createEPS(File f)
1385 alignPanel.makeEPS(f);
1388 public void createSVG(File f)
1390 alignPanel.makeSVG(f);
1393 public void pageSetup_actionPerformed(ActionEvent e)
1395 PrinterJob printJob = PrinterJob.getPrinterJob();
1396 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1406 public void printMenuItem_actionPerformed(ActionEvent e)
1408 // Putting in a thread avoids Swing painting problems
1409 PrintThread thread = new PrintThread(alignPanel);
1414 public void exportFeatures_actionPerformed(ActionEvent e)
1416 new AnnotationExporter().exportFeatures(alignPanel);
1420 public void exportAnnotations_actionPerformed(ActionEvent e)
1422 new AnnotationExporter().exportAnnotations(alignPanel);
1426 public void associatedData_actionPerformed(ActionEvent e)
1428 // Pick the tree file
1429 JalviewFileChooser chooser = new JalviewFileChooser(
1430 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1431 chooser.setFileView(new JalviewFileView());
1432 chooser.setDialogTitle(MessageManager
1433 .getString("label.load_jalview_annotations"));
1434 chooser.setToolTipText(MessageManager
1435 .getString("label.load_jalview_annotations"));
1437 int value = chooser.showOpenDialog(null);
1439 if (value == JalviewFileChooser.APPROVE_OPTION)
1441 String choice = chooser.getSelectedFile().getPath();
1442 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1443 loadJalviewDataFile(choice, null, null, null);
1449 * Close the current view or all views in the alignment frame. If the frame
1450 * only contains one view then the alignment will be removed from memory.
1452 * @param closeAllTabs
1455 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1457 if (alignPanels != null && alignPanels.size() < 2)
1459 closeAllTabs = true;
1464 if (alignPanels != null)
1468 if (this.isClosed())
1470 // really close all the windows - otherwise wait till
1471 // setClosed(true) is called
1472 for (int i = 0; i < alignPanels.size(); i++)
1474 AlignmentPanel ap = alignPanels.get(i);
1481 closeView(alignPanel);
1487 this.setClosed(true);
1489 } catch (Exception ex)
1491 ex.printStackTrace();
1496 * Close the specified panel and close up tabs appropriately.
1498 * @param panelToClose
1500 public void closeView(AlignmentPanel panelToClose)
1502 int index = tabbedPane.getSelectedIndex();
1503 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1504 alignPanels.remove(panelToClose);
1505 panelToClose.closePanel();
1506 panelToClose = null;
1508 tabbedPane.removeTabAt(closedindex);
1509 tabbedPane.validate();
1511 if (index > closedindex || index == tabbedPane.getTabCount())
1513 // modify currently selected tab index if necessary.
1517 this.tabSelectionChanged(index);
1523 void updateEditMenuBar()
1526 if (viewport.getHistoryList().size() > 0)
1528 undoMenuItem.setEnabled(true);
1529 CommandI command = viewport.getHistoryList().peek();
1530 undoMenuItem.setText(MessageManager.formatMessage(
1531 "label.undo_command", new Object[]
1532 { command.getDescription() }));
1536 undoMenuItem.setEnabled(false);
1537 undoMenuItem.setText(MessageManager.getString("action.undo"));
1540 if (viewport.getRedoList().size() > 0)
1542 redoMenuItem.setEnabled(true);
1544 CommandI command = viewport.getRedoList().peek();
1545 redoMenuItem.setText(MessageManager.formatMessage(
1546 "label.redo_command", new Object[]
1547 { command.getDescription() }));
1551 redoMenuItem.setEnabled(false);
1552 redoMenuItem.setText(MessageManager.getString("action.redo"));
1556 public void addHistoryItem(CommandI command)
1558 if (command.getSize() > 0)
1560 viewport.addToHistoryList(command);
1561 viewport.clearRedoList();
1562 updateEditMenuBar();
1563 viewport.updateHiddenColumns();
1564 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1565 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1566 // viewport.getColumnSelection()
1567 // .getHiddenColumns().size() > 0);
1573 * @return alignment objects for all views
1575 AlignmentI[] getViewAlignments()
1577 if (alignPanels != null)
1579 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1581 for (AlignmentPanel ap : alignPanels)
1583 als[i++] = ap.av.getAlignment();
1587 if (viewport != null)
1589 return new AlignmentI[]
1590 { viewport.getAlignment() };
1602 protected void undoMenuItem_actionPerformed(ActionEvent e)
1604 if (viewport.getHistoryList().isEmpty())
1608 CommandI command = viewport.getHistoryList().pop();
1609 viewport.addToRedoList(command);
1610 command.undoCommand(getViewAlignments());
1612 AlignmentViewport originalSource = getOriginatingSource(command);
1613 updateEditMenuBar();
1615 if (originalSource != null)
1617 if (originalSource != viewport)
1620 .warn("Implementation worry: mismatch of viewport origin for undo");
1622 originalSource.updateHiddenColumns();
1623 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1625 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1626 // viewport.getColumnSelection()
1627 // .getHiddenColumns().size() > 0);
1628 originalSource.firePropertyChange("alignment", null, originalSource
1629 .getAlignment().getSequences());
1640 protected void redoMenuItem_actionPerformed(ActionEvent e)
1642 if (viewport.getRedoList().size() < 1)
1647 CommandI command = viewport.getRedoList().pop();
1648 viewport.addToHistoryList(command);
1649 command.doCommand(getViewAlignments());
1651 AlignmentViewport originalSource = getOriginatingSource(command);
1652 updateEditMenuBar();
1654 if (originalSource != null)
1657 if (originalSource != viewport)
1660 .warn("Implementation worry: mismatch of viewport origin for redo");
1662 originalSource.updateHiddenColumns();
1663 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1665 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1666 // viewport.getColumnSelection()
1667 // .getHiddenColumns().size() > 0);
1668 originalSource.firePropertyChange("alignment", null, originalSource
1669 .getAlignment().getSequences());
1673 AlignmentViewport getOriginatingSource(CommandI command)
1675 AlignmentViewport originalSource = null;
1676 // For sequence removal and addition, we need to fire
1677 // the property change event FROM the viewport where the
1678 // original alignment was altered
1679 AlignmentI al = null;
1680 if (command instanceof EditCommand)
1682 EditCommand editCommand = (EditCommand) command;
1683 al = editCommand.getAlignment();
1684 List<Component> comps = PaintRefresher.components.get(viewport
1685 .getSequenceSetId());
1687 for (Component comp : comps)
1689 if (comp instanceof AlignmentPanel)
1691 if (al == ((AlignmentPanel) comp).av.getAlignment())
1693 originalSource = ((AlignmentPanel) comp).av;
1700 if (originalSource == null)
1702 // The original view is closed, we must validate
1703 // the current view against the closed view first
1706 PaintRefresher.validateSequences(al, viewport.getAlignment());
1709 originalSource = viewport;
1712 return originalSource;
1721 public void moveSelectedSequences(boolean up)
1723 SequenceGroup sg = viewport.getSelectionGroup();
1729 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1730 viewport.getHiddenRepSequences(), up);
1731 alignPanel.paintAlignment(true);
1734 synchronized void slideSequences(boolean right, int size)
1736 List<SequenceI> sg = new ArrayList<SequenceI>();
1737 if (viewport.cursorMode)
1739 sg.add(viewport.getAlignment().getSequenceAt(
1740 alignPanel.getSeqPanel().seqCanvas.cursorY));
1742 else if (viewport.getSelectionGroup() != null
1743 && viewport.getSelectionGroup().getSize() != viewport
1744 .getAlignment().getHeight())
1746 sg = viewport.getSelectionGroup().getSequences(
1747 viewport.getHiddenRepSequences());
1755 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1757 for (SequenceI seq : viewport.getAlignment().getSequences())
1759 if (!sg.contains(seq))
1761 invertGroup.add(seq);
1765 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1767 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1768 for (int i = 0; i < invertGroup.size(); i++)
1770 seqs2[i] = invertGroup.get(i);
1773 SlideSequencesCommand ssc;
1776 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1777 size, viewport.getGapCharacter());
1781 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1782 size, viewport.getGapCharacter());
1785 int groupAdjustment = 0;
1786 if (ssc.getGapsInsertedBegin() && right)
1788 if (viewport.cursorMode)
1790 alignPanel.getSeqPanel().moveCursor(size, 0);
1794 groupAdjustment = size;
1797 else if (!ssc.getGapsInsertedBegin() && !right)
1799 if (viewport.cursorMode)
1801 alignPanel.getSeqPanel().moveCursor(-size, 0);
1805 groupAdjustment = -size;
1809 if (groupAdjustment != 0)
1811 viewport.getSelectionGroup().setStartRes(
1812 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1813 viewport.getSelectionGroup().setEndRes(
1814 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1817 boolean appendHistoryItem = false;
1818 Deque<CommandI> historyList = viewport.getHistoryList();
1819 if (historyList != null
1820 && historyList.size() > 0
1821 && historyList.peek() instanceof SlideSequencesCommand)
1823 appendHistoryItem = ssc
1824 .appendSlideCommand((SlideSequencesCommand) historyList
1828 if (!appendHistoryItem)
1830 addHistoryItem(ssc);
1843 protected void copy_actionPerformed(ActionEvent e)
1846 if (viewport.getSelectionGroup() == null)
1850 // TODO: preserve the ordering of displayed alignment annotation in any
1851 // internal paste (particularly sequence associated annotation)
1852 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1853 String[] omitHidden = null;
1855 if (viewport.hasHiddenColumns())
1857 omitHidden = viewport.getViewAsString(true);
1860 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1863 StringSelection ss = new StringSelection(output);
1867 jalview.gui.Desktop.internalCopy = true;
1868 // Its really worth setting the clipboard contents
1869 // to empty before setting the large StringSelection!!
1870 Toolkit.getDefaultToolkit().getSystemClipboard()
1871 .setContents(new StringSelection(""), null);
1873 Toolkit.getDefaultToolkit().getSystemClipboard()
1874 .setContents(ss, Desktop.instance);
1875 } catch (OutOfMemoryError er)
1877 new OOMWarning("copying region", er);
1881 ArrayList<int[]> hiddenColumns = null;
1882 if (viewport.hasHiddenColumns())
1884 hiddenColumns = new ArrayList<int[]>();
1885 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1886 .getSelectionGroup().getEndRes();
1887 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1889 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1891 hiddenColumns.add(new int[]
1892 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1897 Desktop.jalviewClipboard = new Object[]
1898 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1899 statusBar.setText(MessageManager.formatMessage(
1900 "label.copied_sequences_to_clipboard", new Object[]
1901 { Integer.valueOf(seqs.length).toString() }));
1911 protected void pasteNew_actionPerformed(ActionEvent e)
1923 protected void pasteThis_actionPerformed(ActionEvent e)
1929 * Paste contents of Jalview clipboard
1931 * @param newAlignment
1932 * true to paste to a new alignment, otherwise add to this.
1934 void paste(boolean newAlignment)
1936 boolean externalPaste = true;
1939 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1940 Transferable contents = c.getContents(this);
1942 if (contents == null)
1950 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1951 if (str.length() < 1)
1956 format = new IdentifyFile().Identify(str, "Paste");
1958 } catch (OutOfMemoryError er)
1960 new OOMWarning("Out of memory pasting sequences!!", er);
1964 SequenceI[] sequences;
1965 boolean annotationAdded = false;
1966 AlignmentI alignment = null;
1968 if (Desktop.jalviewClipboard != null)
1970 // The clipboard was filled from within Jalview, we must use the
1972 // And dataset from the copied alignment
1973 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1974 // be doubly sure that we create *new* sequence objects.
1975 sequences = new SequenceI[newseq.length];
1976 for (int i = 0; i < newseq.length; i++)
1978 sequences[i] = new Sequence(newseq[i]);
1980 alignment = new Alignment(sequences);
1981 externalPaste = false;
1985 // parse the clipboard as an alignment.
1986 alignment = new FormatAdapter().readFile(str, "Paste", format);
1987 sequences = alignment.getSequencesArray();
1991 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1997 if (Desktop.jalviewClipboard != null)
1999 // dataset is inherited
2000 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2004 // new dataset is constructed
2005 alignment.setDataset(null);
2007 alwidth = alignment.getWidth() + 1;
2011 AlignmentI pastedal = alignment; // preserve pasted alignment object
2012 // Add pasted sequences and dataset into existing alignment.
2013 alignment = viewport.getAlignment();
2014 alwidth = alignment.getWidth() + 1;
2015 // decide if we need to import sequences from an existing dataset
2016 boolean importDs = Desktop.jalviewClipboard != null
2017 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2018 // importDs==true instructs us to copy over new dataset sequences from
2019 // an existing alignment
2020 Vector newDs = (importDs) ? new Vector() : null; // used to create
2021 // minimum dataset set
2023 for (int i = 0; i < sequences.length; i++)
2027 newDs.addElement(null);
2029 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2031 if (importDs && ds != null)
2033 if (!newDs.contains(ds))
2035 newDs.setElementAt(ds, i);
2036 ds = new Sequence(ds);
2037 // update with new dataset sequence
2038 sequences[i].setDatasetSequence(ds);
2042 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2047 // copy and derive new dataset sequence
2048 sequences[i] = sequences[i].deriveSequence();
2049 alignment.getDataset().addSequence(
2050 sequences[i].getDatasetSequence());
2051 // TODO: avoid creation of duplicate dataset sequences with a
2052 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2054 alignment.addSequence(sequences[i]); // merges dataset
2058 newDs.clear(); // tidy up
2060 if (alignment.getAlignmentAnnotation() != null)
2062 for (AlignmentAnnotation alan : alignment
2063 .getAlignmentAnnotation())
2065 if (alan.graphGroup > fgroup)
2067 fgroup = alan.graphGroup;
2071 if (pastedal.getAlignmentAnnotation() != null)
2073 // Add any annotation attached to alignment.
2074 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2075 for (int i = 0; i < alann.length; i++)
2077 annotationAdded = true;
2078 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2080 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2081 if (newann.graphGroup > -1)
2083 if (newGraphGroups.size() <= newann.graphGroup
2084 || newGraphGroups.get(newann.graphGroup) == null)
2086 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2088 newGraphGroups.add(q, null);
2090 newGraphGroups.set(newann.graphGroup, new Integer(
2093 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2097 newann.padAnnotation(alwidth);
2098 alignment.addAnnotation(newann);
2108 addHistoryItem(new EditCommand(
2109 MessageManager.getString("label.add_sequences"),
2111 sequences, 0, alignment.getWidth(), alignment));
2113 // Add any annotations attached to sequences
2114 for (int i = 0; i < sequences.length; i++)
2116 if (sequences[i].getAnnotation() != null)
2118 AlignmentAnnotation newann;
2119 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2121 annotationAdded = true;
2122 newann = sequences[i].getAnnotation()[a];
2123 newann.adjustForAlignment();
2124 newann.padAnnotation(alwidth);
2125 if (newann.graphGroup > -1)
2127 if (newann.graphGroup > -1)
2129 if (newGraphGroups.size() <= newann.graphGroup
2130 || newGraphGroups.get(newann.graphGroup) == null)
2132 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2134 newGraphGroups.add(q, null);
2136 newGraphGroups.set(newann.graphGroup, new Integer(
2139 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2143 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2148 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2155 // propagate alignment changed.
2156 viewport.setEndSeq(alignment.getHeight());
2157 if (annotationAdded)
2159 // Duplicate sequence annotation in all views.
2160 AlignmentI[] alview = this.getViewAlignments();
2161 for (int i = 0; i < sequences.length; i++)
2163 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2168 for (int avnum = 0; avnum < alview.length; avnum++)
2170 if (alview[avnum] != alignment)
2172 // duplicate in a view other than the one with input focus
2173 int avwidth = alview[avnum].getWidth() + 1;
2174 // this relies on sann being preserved after we
2175 // modify the sequence's annotation array for each duplication
2176 for (int a = 0; a < sann.length; a++)
2178 AlignmentAnnotation newann = new AlignmentAnnotation(
2180 sequences[i].addAlignmentAnnotation(newann);
2181 newann.padAnnotation(avwidth);
2182 alview[avnum].addAnnotation(newann); // annotation was
2183 // duplicated earlier
2184 // TODO JAL-1145 graphGroups are not updated for sequence
2185 // annotation added to several views. This may cause
2187 alview[avnum].setAnnotationIndex(newann, a);
2192 buildSortByAnnotationScoresMenu();
2194 viewport.firePropertyChange("alignment", null,
2195 alignment.getSequences());
2196 if (alignPanels != null)
2198 for (AlignmentPanel ap : alignPanels)
2200 ap.validateAnnotationDimensions(false);
2205 alignPanel.validateAnnotationDimensions(false);
2211 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2213 String newtitle = new String("Copied sequences");
2215 if (Desktop.jalviewClipboard != null
2216 && Desktop.jalviewClipboard[2] != null)
2218 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2219 for (int[] region : hc)
2221 af.viewport.hideColumns(region[0], region[1]);
2225 // >>>This is a fix for the moment, until a better solution is
2227 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2229 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2231 // TODO: maintain provenance of an alignment, rather than just make the
2232 // title a concatenation of operations.
2235 if (title.startsWith("Copied sequences"))
2241 newtitle = newtitle.concat("- from " + title);
2246 newtitle = new String("Pasted sequences");
2249 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2254 } catch (Exception ex)
2256 ex.printStackTrace();
2257 System.out.println("Exception whilst pasting: " + ex);
2258 // could be anything being pasted in here
2264 protected void expand_newalign(ActionEvent e)
2268 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2269 .getAlignment(), -1);
2270 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2272 String newtitle = new String("Flanking alignment");
2274 if (Desktop.jalviewClipboard != null
2275 && Desktop.jalviewClipboard[2] != null)
2277 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2278 for (int region[] : hc)
2280 af.viewport.hideColumns(region[0], region[1]);
2284 // >>>This is a fix for the moment, until a better solution is
2286 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2288 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2290 // TODO: maintain provenance of an alignment, rather than just make the
2291 // title a concatenation of operations.
2293 if (title.startsWith("Copied sequences"))
2299 newtitle = newtitle.concat("- from " + title);
2303 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2305 } catch (Exception ex)
2307 ex.printStackTrace();
2308 System.out.println("Exception whilst pasting: " + ex);
2309 // could be anything being pasted in here
2310 } catch (OutOfMemoryError oom)
2312 new OOMWarning("Viewing flanking region of alignment", oom);
2323 protected void cut_actionPerformed(ActionEvent e)
2325 copy_actionPerformed(null);
2326 delete_actionPerformed(null);
2336 protected void delete_actionPerformed(ActionEvent evt)
2339 SequenceGroup sg = viewport.getSelectionGroup();
2346 * If the cut affects all sequences, warn, remove highlighted columns
2348 if (sg.getSize() == viewport.getAlignment().getHeight())
2350 int confirm = JOptionPane.showConfirmDialog(this,
2351 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2352 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2353 JOptionPane.OK_CANCEL_OPTION);
2355 if (confirm == JOptionPane.CANCEL_OPTION
2356 || confirm == JOptionPane.CLOSED_OPTION)
2360 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2361 sg.getEndRes() + 1);
2364 SequenceI[] cut = sg.getSequences()
2365 .toArray(new SequenceI[sg.getSize()]);
2367 addHistoryItem(new EditCommand(
2368 MessageManager.getString("label.cut_sequences"), Action.CUT,
2369 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2370 viewport.getAlignment()));
2372 viewport.setSelectionGroup(null);
2373 viewport.sendSelection();
2374 viewport.getAlignment().deleteGroup(sg);
2376 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2378 if (viewport.getAlignment().getHeight() < 1)
2382 this.setClosed(true);
2383 } catch (Exception ex)
2396 protected void deleteGroups_actionPerformed(ActionEvent e)
2398 if (avc.deleteGroups())
2400 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2401 alignPanel.updateAnnotation();
2402 alignPanel.paintAlignment(true);
2413 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2415 SequenceGroup sg = new SequenceGroup();
2417 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2419 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2422 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2423 viewport.setSelectionGroup(sg);
2424 viewport.sendSelection();
2425 alignPanel.paintAlignment(true);
2426 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2436 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2438 if (viewport.cursorMode)
2440 alignPanel.getSeqPanel().keyboardNo1 = null;
2441 alignPanel.getSeqPanel().keyboardNo2 = null;
2443 viewport.setSelectionGroup(null);
2444 viewport.getColumnSelection().clear();
2445 viewport.setSelectionGroup(null);
2446 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2447 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2448 alignPanel.paintAlignment(true);
2449 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2450 viewport.sendSelection();
2460 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2462 SequenceGroup sg = viewport.getSelectionGroup();
2466 selectAllSequenceMenuItem_actionPerformed(null);
2471 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2473 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2476 alignPanel.paintAlignment(true);
2477 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2478 viewport.sendSelection();
2482 public void invertColSel_actionPerformed(ActionEvent e)
2484 viewport.invertColumnSelection();
2485 alignPanel.paintAlignment(true);
2486 viewport.sendSelection();
2496 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2498 trimAlignment(true);
2508 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2510 trimAlignment(false);
2513 void trimAlignment(boolean trimLeft)
2515 ColumnSelection colSel = viewport.getColumnSelection();
2518 if (colSel.size() > 0)
2522 column = colSel.getMin();
2526 column = colSel.getMax();
2530 if (viewport.getSelectionGroup() != null)
2532 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2533 viewport.getHiddenRepSequences());
2537 seqs = viewport.getAlignment().getSequencesArray();
2540 TrimRegionCommand trimRegion;
2543 trimRegion = new TrimRegionCommand("Remove Left",
2544 TrimRegionCommand.TRIM_LEFT, seqs, column,
2545 viewport.getAlignment(), viewport.getColumnSelection(),
2546 viewport.getSelectionGroup());
2547 viewport.setStartRes(0);
2551 trimRegion = new TrimRegionCommand("Remove Right",
2552 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2553 viewport.getAlignment(), viewport.getColumnSelection(),
2554 viewport.getSelectionGroup());
2557 statusBar.setText(MessageManager.formatMessage(
2558 "label.removed_columns", new String[]
2559 { Integer.valueOf(trimRegion.getSize()).toString() }));
2561 addHistoryItem(trimRegion);
2563 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2565 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2566 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2568 viewport.getAlignment().deleteGroup(sg);
2572 viewport.firePropertyChange("alignment", null, viewport
2573 .getAlignment().getSequences());
2584 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2586 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2589 if (viewport.getSelectionGroup() != null)
2591 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2592 viewport.getHiddenRepSequences());
2593 start = viewport.getSelectionGroup().getStartRes();
2594 end = viewport.getSelectionGroup().getEndRes();
2598 seqs = viewport.getAlignment().getSequencesArray();
2601 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2602 "Remove Gapped Columns", seqs, start, end,
2603 viewport.getAlignment());
2605 addHistoryItem(removeGapCols);
2607 statusBar.setText(MessageManager.formatMessage(
2608 "label.removed_empty_columns", new Object[]
2609 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2611 // This is to maintain viewport position on first residue
2612 // of first sequence
2613 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2614 int startRes = seq.findPosition(viewport.startRes);
2615 // ShiftList shifts;
2616 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2617 // edit.alColumnChanges=shifts.getInverse();
2618 // if (viewport.hasHiddenColumns)
2619 // viewport.getColumnSelection().compensateForEdits(shifts);
2620 viewport.setStartRes(seq.findIndex(startRes) - 1);
2621 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2633 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2635 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2638 if (viewport.getSelectionGroup() != null)
2640 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2641 viewport.getHiddenRepSequences());
2642 start = viewport.getSelectionGroup().getStartRes();
2643 end = viewport.getSelectionGroup().getEndRes();
2647 seqs = viewport.getAlignment().getSequencesArray();
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);
2655 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2656 viewport.getAlignment()));
2658 viewport.setStartRes(seq.findIndex(startRes) - 1);
2660 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2672 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2674 viewport.setPadGaps(padGapsMenuitem.isSelected());
2675 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2686 public void findMenuItem_actionPerformed(ActionEvent e)
2692 * Create a new view of the current alignment.
2695 public void newView_actionPerformed(ActionEvent e)
2697 newView(null, true);
2701 * Creates and shows a new view of the current alignment.
2704 * title of newly created view; if null, one will be generated
2705 * @param copyAnnotation
2706 * if true then duplicate all annnotation, groups and settings
2707 * @return new alignment panel, already displayed.
2709 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2712 * Create a new AlignmentPanel (with its own, new Viewport)
2714 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2716 if (!copyAnnotation)
2719 * remove all groups and annotation except for the automatic stuff
2721 newap.av.getAlignment().deleteAllGroups();
2722 newap.av.getAlignment().deleteAllAnnotations(false);
2725 newap.av.setGatherViewsHere(false);
2727 if (viewport.viewName == null)
2729 viewport.viewName = MessageManager
2730 .getString("label.view_name_original");
2734 * Views share the same edits, undo and redo stacks, mappings.
2736 newap.av.setHistoryList(viewport.getHistoryList());
2737 newap.av.setRedoList(viewport.getRedoList());
2738 newap.av.getAlignment().setCodonFrames(
2739 viewport.getAlignment().getCodonFrames());
2741 newap.av.viewName = getNewViewName(viewTitle);
2743 addAlignmentPanel(newap, true);
2744 newap.alignmentChanged();
2746 if (alignPanels.size() == 2)
2748 viewport.setGatherViewsHere(true);
2750 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2755 * Make a new name for the view, ensuring it is unique within the current
2756 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2757 * these now use viewId. Unique view names are still desirable for usability.)
2762 protected String getNewViewName(String viewTitle)
2764 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2765 boolean addFirstIndex = false;
2766 if (viewTitle == null || viewTitle.trim().length() == 0)
2768 viewTitle = MessageManager.getString("action.view");
2769 addFirstIndex = true;
2773 index = 1;// we count from 1 if given a specific name
2775 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2777 List<Component> comps = PaintRefresher.components.get(viewport
2778 .getSequenceSetId());
2780 List<String> existingNames = getExistingViewNames(comps);
2782 while (existingNames.contains(newViewName))
2784 newViewName = viewTitle + " " + (++index);
2790 * Returns a list of distinct view names found in the given list of
2791 * components. View names are held on the viewport of an AlignmentPanel.
2796 protected List<String> getExistingViewNames(List<Component> comps)
2798 List<String> existingNames = new ArrayList<String>();
2799 for (Component comp : comps)
2801 if (comp instanceof AlignmentPanel)
2803 AlignmentPanel ap = (AlignmentPanel) comp;
2804 if (!existingNames.contains(ap.av.viewName))
2806 existingNames.add(ap.av.viewName);
2810 return existingNames;
2814 * Explode tabbed views into separate windows.
2817 public void expandViews_actionPerformed(ActionEvent e)
2819 Desktop.instance.explodeViews(this);
2823 * Gather views in separate windows back into a tabbed presentation.
2826 public void gatherViews_actionPerformed(ActionEvent e)
2828 Desktop.instance.gatherViews(this);
2838 public void font_actionPerformed(ActionEvent e)
2840 new FontChooser(alignPanel);
2850 protected void seqLimit_actionPerformed(ActionEvent e)
2852 viewport.setShowJVSuffix(seqLimits.isSelected());
2854 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2855 .calculateIdWidth());
2856 alignPanel.paintAlignment(true);
2860 public void idRightAlign_actionPerformed(ActionEvent e)
2862 viewport.setRightAlignIds(idRightAlign.isSelected());
2863 alignPanel.paintAlignment(true);
2867 public void centreColumnLabels_actionPerformed(ActionEvent e)
2869 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2870 alignPanel.paintAlignment(true);
2876 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2879 protected void followHighlight_actionPerformed()
2882 * Set the 'follow' flag on the Viewport (and scroll to position if now
2885 final boolean state = this.followHighlightMenuItem.getState();
2886 viewport.setFollowHighlight(state);
2889 alignPanel.scrollToPosition(
2890 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2901 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2903 viewport.setColourText(colourTextMenuItem.isSelected());
2904 alignPanel.paintAlignment(true);
2914 public void wrapMenuItem_actionPerformed(ActionEvent e)
2916 scaleAbove.setVisible(wrapMenuItem.isSelected());
2917 scaleLeft.setVisible(wrapMenuItem.isSelected());
2918 scaleRight.setVisible(wrapMenuItem.isSelected());
2919 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2920 alignPanel.updateLayout();
2924 public void showAllSeqs_actionPerformed(ActionEvent e)
2926 viewport.showAllHiddenSeqs();
2930 public void showAllColumns_actionPerformed(ActionEvent e)
2932 viewport.showAllHiddenColumns();
2937 public void hideSelSequences_actionPerformed(ActionEvent e)
2939 viewport.hideAllSelectedSeqs();
2940 // alignPanel.paintAlignment(true);
2944 * called by key handler and the hide all/show all menu items
2949 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2952 boolean hide = false;
2953 SequenceGroup sg = viewport.getSelectionGroup();
2954 if (!toggleSeqs && !toggleCols)
2956 // Hide everything by the current selection - this is a hack - we do the
2957 // invert and then hide
2958 // first check that there will be visible columns after the invert.
2959 if ((viewport.getColumnSelection() != null
2960 && viewport.getColumnSelection().getSelected() != null && viewport
2961 .getColumnSelection().getSelected().size() > 0)
2962 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2965 // now invert the sequence set, if required - empty selection implies
2966 // that no hiding is required.
2969 invertSequenceMenuItem_actionPerformed(null);
2970 sg = viewport.getSelectionGroup();
2974 viewport.expandColSelection(sg, true);
2975 // finally invert the column selection and get the new sequence
2977 invertColSel_actionPerformed(null);
2984 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2986 hideSelSequences_actionPerformed(null);
2989 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2992 showAllSeqs_actionPerformed(null);
2998 if (viewport.getColumnSelection().getSelected().size() > 0)
3000 hideSelColumns_actionPerformed(null);
3003 viewport.setSelectionGroup(sg);
3008 showAllColumns_actionPerformed(null);
3017 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3018 * event.ActionEvent)
3021 public void hideAllButSelection_actionPerformed(ActionEvent e)
3023 toggleHiddenRegions(false, false);
3030 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3034 public void hideAllSelection_actionPerformed(ActionEvent e)
3036 SequenceGroup sg = viewport.getSelectionGroup();
3037 viewport.expandColSelection(sg, false);
3038 viewport.hideAllSelectedSeqs();
3039 viewport.hideSelectedColumns();
3040 alignPanel.paintAlignment(true);
3047 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3051 public void showAllhidden_actionPerformed(ActionEvent e)
3053 viewport.showAllHiddenColumns();
3054 viewport.showAllHiddenSeqs();
3055 alignPanel.paintAlignment(true);
3059 public void hideSelColumns_actionPerformed(ActionEvent e)
3061 viewport.hideSelectedColumns();
3062 alignPanel.paintAlignment(true);
3066 public void hiddenMarkers_actionPerformed(ActionEvent e)
3068 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3079 protected void scaleAbove_actionPerformed(ActionEvent e)
3081 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3082 alignPanel.paintAlignment(true);
3092 protected void scaleLeft_actionPerformed(ActionEvent e)
3094 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3095 alignPanel.paintAlignment(true);
3105 protected void scaleRight_actionPerformed(ActionEvent e)
3107 viewport.setScaleRightWrapped(scaleRight.isSelected());
3108 alignPanel.paintAlignment(true);
3118 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3120 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3121 alignPanel.paintAlignment(true);
3131 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3133 viewport.setShowText(viewTextMenuItem.isSelected());
3134 alignPanel.paintAlignment(true);
3144 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3146 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3147 alignPanel.paintAlignment(true);
3150 public FeatureSettings featureSettings;
3153 public FeatureSettingsControllerI getFeatureSettingsUI()
3155 return featureSettings;
3159 public void featureSettings_actionPerformed(ActionEvent e)
3161 if (featureSettings != null)
3163 featureSettings.close();
3164 featureSettings = null;
3166 if (!showSeqFeatures.isSelected())
3168 // make sure features are actually displayed
3169 showSeqFeatures.setSelected(true);
3170 showSeqFeatures_actionPerformed(null);
3172 featureSettings = new FeatureSettings(this);
3176 * Set or clear 'Show Sequence Features'
3182 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3184 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3185 alignPanel.paintAlignment(true);
3186 if (alignPanel.getOverviewPanel() != null)
3188 alignPanel.getOverviewPanel().updateOverviewImage();
3193 * Set or clear 'Show Sequence Features'
3199 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3201 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3203 if (viewport.isShowSequenceFeaturesHeight())
3205 // ensure we're actually displaying features
3206 viewport.setShowSequenceFeatures(true);
3207 showSeqFeatures.setSelected(true);
3209 alignPanel.paintAlignment(true);
3210 if (alignPanel.getOverviewPanel() != null)
3212 alignPanel.getOverviewPanel().updateOverviewImage();
3217 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3218 * the annotations panel as a whole.
3220 * The options to show/hide all annotations should be enabled when the panel
3221 * is shown, and disabled when the panel is hidden.
3226 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3228 final boolean setVisible = annotationPanelMenuItem.isSelected();
3229 viewport.setShowAnnotation(setVisible);
3230 this.showAllSeqAnnotations.setEnabled(setVisible);
3231 this.hideAllSeqAnnotations.setEnabled(setVisible);
3232 this.showAllAlAnnotations.setEnabled(setVisible);
3233 this.hideAllAlAnnotations.setEnabled(setVisible);
3234 alignPanel.updateLayout();
3238 public void alignmentProperties()
3240 JEditorPane editPane = new JEditorPane("text/html", "");
3241 editPane.setEditable(false);
3242 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3244 editPane.setText(MessageManager.formatMessage("label.html_content",
3246 { contents.toString() }));
3247 JInternalFrame frame = new JInternalFrame();
3248 frame.getContentPane().add(new JScrollPane(editPane));
3250 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3251 "label.alignment_properties", new Object[]
3252 { getTitle() }), 500, 400);
3262 public void overviewMenuItem_actionPerformed(ActionEvent e)
3264 if (alignPanel.overviewPanel != null)
3269 JInternalFrame frame = new JInternalFrame();
3270 OverviewPanel overview = new OverviewPanel(alignPanel);
3271 frame.setContentPane(overview);
3272 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3273 "label.overview_params", new Object[]
3274 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3276 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3277 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3280 public void internalFrameClosed(
3281 javax.swing.event.InternalFrameEvent evt)
3283 alignPanel.setOverviewPanel(null);
3287 alignPanel.setOverviewPanel(overview);
3291 public void textColour_actionPerformed(ActionEvent e)
3293 new TextColourChooser().chooseColour(alignPanel, null);
3303 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3315 public void clustalColour_actionPerformed(ActionEvent e)
3317 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3318 viewport.getHiddenRepSequences()));
3328 public void zappoColour_actionPerformed(ActionEvent e)
3330 changeColour(new ZappoColourScheme());
3340 public void taylorColour_actionPerformed(ActionEvent e)
3342 changeColour(new TaylorColourScheme());
3352 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3354 changeColour(new HydrophobicColourScheme());
3364 public void helixColour_actionPerformed(ActionEvent e)
3366 changeColour(new HelixColourScheme());
3376 public void strandColour_actionPerformed(ActionEvent e)
3378 changeColour(new StrandColourScheme());
3388 public void turnColour_actionPerformed(ActionEvent e)
3390 changeColour(new TurnColourScheme());
3400 public void buriedColour_actionPerformed(ActionEvent e)
3402 changeColour(new BuriedColourScheme());
3412 public void nucleotideColour_actionPerformed(ActionEvent e)
3414 changeColour(new NucleotideColourScheme());
3418 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3420 changeColour(new PurinePyrimidineColourScheme());
3424 * public void covariationColour_actionPerformed(ActionEvent e) {
3426 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3430 public void annotationColour_actionPerformed(ActionEvent e)
3432 new AnnotationColourChooser(viewport, alignPanel);
3436 public void annotationColumn_actionPerformed(ActionEvent e)
3438 new AnnotationColumnChooser(viewport, alignPanel);
3442 public void rnahelicesColour_actionPerformed(ActionEvent e)
3444 new RNAHelicesColourChooser(viewport, alignPanel);
3454 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3456 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3465 public void changeColour(ColourSchemeI cs)
3467 // TODO: compare with applet and pull up to model method
3472 if (viewport.getAbovePIDThreshold())
3474 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3476 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3480 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3483 if (viewport.getConservationSelected())
3486 Alignment al = (Alignment) viewport.getAlignment();
3487 Conservation c = new Conservation("All",
3488 ResidueProperties.propHash, 3, al.getSequences(), 0,
3492 c.verdict(false, viewport.getConsPercGaps());
3494 cs.setConservation(c);
3496 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3501 cs.setConservation(null);
3504 cs.setConsensus(viewport.getSequenceConsensusHash());
3507 viewport.setGlobalColourScheme(cs);
3509 if (viewport.getColourAppliesToAllGroups())
3512 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3520 if (cs instanceof ClustalxColourScheme)
3522 sg.cs = new ClustalxColourScheme(sg,
3523 viewport.getHiddenRepSequences());
3525 else if (cs instanceof UserColourScheme)
3527 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3533 sg.cs = cs.getClass().newInstance();
3534 } catch (Exception ex)
3539 if (viewport.getAbovePIDThreshold()
3540 || cs instanceof PIDColourScheme
3541 || cs instanceof Blosum62ColourScheme)
3543 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3545 sg.cs.setConsensus(AAFrequency.calculate(
3546 sg.getSequences(viewport.getHiddenRepSequences()),
3547 sg.getStartRes(), sg.getEndRes() + 1));
3551 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3554 if (viewport.getConservationSelected())
3556 Conservation c = new Conservation("Group",
3557 ResidueProperties.propHash, 3, sg.getSequences(viewport
3558 .getHiddenRepSequences()), sg.getStartRes(),
3559 sg.getEndRes() + 1);
3561 c.verdict(false, viewport.getConsPercGaps());
3562 sg.cs.setConservation(c);
3566 sg.cs.setConservation(null);
3571 if (alignPanel.getOverviewPanel() != null)
3573 alignPanel.getOverviewPanel().updateOverviewImage();
3576 alignPanel.paintAlignment(true);
3586 protected void modifyPID_actionPerformed(ActionEvent e)
3588 if (viewport.getAbovePIDThreshold()
3589 && viewport.getGlobalColourScheme() != null)
3591 SliderPanel.setPIDSliderSource(alignPanel,
3592 viewport.getGlobalColourScheme(), "Background");
3593 SliderPanel.showPIDSlider();
3604 protected void modifyConservation_actionPerformed(ActionEvent e)
3606 if (viewport.getConservationSelected()
3607 && viewport.getGlobalColourScheme() != null)
3609 SliderPanel.setConservationSlider(alignPanel,
3610 viewport.getGlobalColourScheme(), "Background");
3611 SliderPanel.showConservationSlider();
3622 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3624 viewport.setConservationSelected(conservationMenuItem.isSelected());
3626 viewport.setAbovePIDThreshold(false);
3627 abovePIDThreshold.setSelected(false);
3629 changeColour(viewport.getGlobalColourScheme());
3631 modifyConservation_actionPerformed(null);
3641 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3643 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3645 conservationMenuItem.setSelected(false);
3646 viewport.setConservationSelected(false);
3648 changeColour(viewport.getGlobalColourScheme());
3650 modifyPID_actionPerformed(null);
3660 public void userDefinedColour_actionPerformed(ActionEvent e)
3662 if (e.getActionCommand().equals(
3663 MessageManager.getString("action.user_defined")))
3665 new UserDefinedColours(alignPanel, null);
3669 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3670 .getUserColourSchemes().get(e.getActionCommand());
3676 public void updateUserColourMenu()
3679 Component[] menuItems = colourMenu.getMenuComponents();
3680 int iSize = menuItems.length;
3681 for (int i = 0; i < iSize; i++)
3683 if (menuItems[i].getName() != null
3684 && menuItems[i].getName().equals("USER_DEFINED"))
3686 colourMenu.remove(menuItems[i]);
3690 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3692 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3693 .getUserColourSchemes().keys();
3695 while (userColours.hasMoreElements())
3697 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3698 userColours.nextElement().toString());
3699 radioItem.setName("USER_DEFINED");
3700 radioItem.addMouseListener(new MouseAdapter()
3703 public void mousePressed(MouseEvent evt)
3705 if (evt.isControlDown()
3706 || SwingUtilities.isRightMouseButton(evt))
3708 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3710 int option = JOptionPane.showInternalConfirmDialog(
3711 jalview.gui.Desktop.desktop,
3713 .getString("label.remove_from_default_list"),
3715 .getString("label.remove_user_defined_colour"),
3716 JOptionPane.YES_NO_OPTION);
3717 if (option == JOptionPane.YES_OPTION)
3719 jalview.gui.UserDefinedColours
3720 .removeColourFromDefaults(radioItem.getText());
3721 colourMenu.remove(radioItem);
3725 radioItem.addActionListener(new ActionListener()
3728 public void actionPerformed(ActionEvent evt)
3730 userDefinedColour_actionPerformed(evt);
3737 radioItem.addActionListener(new ActionListener()
3740 public void actionPerformed(ActionEvent evt)
3742 userDefinedColour_actionPerformed(evt);
3746 colourMenu.insert(radioItem, 15);
3747 colours.add(radioItem);
3759 public void PIDColour_actionPerformed(ActionEvent e)
3761 changeColour(new PIDColourScheme());
3771 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3773 changeColour(new Blosum62ColourScheme());
3783 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3785 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3786 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3787 .getAlignment().getSequenceAt(0), null);
3788 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3789 viewport.getAlignment()));
3790 alignPanel.paintAlignment(true);
3800 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3802 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3803 AlignmentSorter.sortByID(viewport.getAlignment());
3804 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3805 viewport.getAlignment()));
3806 alignPanel.paintAlignment(true);
3816 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3818 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3819 AlignmentSorter.sortByLength(viewport.getAlignment());
3820 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3821 viewport.getAlignment()));
3822 alignPanel.paintAlignment(true);
3832 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3834 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3835 AlignmentSorter.sortByGroup(viewport.getAlignment());
3836 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3837 viewport.getAlignment()));
3839 alignPanel.paintAlignment(true);
3849 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3851 new RedundancyPanel(alignPanel, this);
3861 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3863 if ((viewport.getSelectionGroup() == null)
3864 || (viewport.getSelectionGroup().getSize() < 2))
3866 JOptionPane.showInternalMessageDialog(this, MessageManager
3867 .getString("label.you_must_select_least_two_sequences"),
3868 MessageManager.getString("label.invalid_selection"),
3869 JOptionPane.WARNING_MESSAGE);
3873 JInternalFrame frame = new JInternalFrame();
3874 frame.setContentPane(new PairwiseAlignPanel(viewport));
3875 Desktop.addInternalFrame(frame,
3876 MessageManager.getString("action.pairwise_alignment"), 600,
3888 public void PCAMenuItem_actionPerformed(ActionEvent e)
3890 if (((viewport.getSelectionGroup() != null)
3891 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3892 .getSelectionGroup().getSize() > 0))
3893 || (viewport.getAlignment().getHeight() < 4))
3896 .showInternalMessageDialog(
3899 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3901 .getString("label.sequence_selection_insufficient"),
3902 JOptionPane.WARNING_MESSAGE);
3907 new PCAPanel(alignPanel);
3911 public void autoCalculate_actionPerformed(ActionEvent e)
3913 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3914 if (viewport.autoCalculateConsensus)
3916 viewport.firePropertyChange("alignment", null, viewport
3917 .getAlignment().getSequences());
3922 public void sortByTreeOption_actionPerformed(ActionEvent e)
3924 viewport.sortByTree = sortByTree.isSelected();
3928 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3930 viewport.followSelection = listenToViewSelections.isSelected();
3940 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3942 newTreePanel("AV", "PID", "Average distance tree using PID");
3952 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3954 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3964 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3966 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3976 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3978 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3991 void newTreePanel(String type, String pwType, String title)
3995 if (viewport.getSelectionGroup() != null
3996 && viewport.getSelectionGroup().getSize() > 0)
3998 if (viewport.getSelectionGroup().getSize() < 3)
4004 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4006 .getString("label.not_enough_sequences"),
4007 JOptionPane.WARNING_MESSAGE);
4011 SequenceGroup sg = viewport.getSelectionGroup();
4013 /* Decide if the selection is a column region */
4014 for (SequenceI _s : sg.getSequences())
4016 if (_s.getLength() < sg.getEndRes())
4022 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4024 .getString("label.sequences_selection_not_aligned"),
4025 JOptionPane.WARNING_MESSAGE);
4031 title = title + " on region";
4032 tp = new TreePanel(alignPanel, type, pwType);
4036 // are the visible sequences aligned?
4037 if (!viewport.getAlignment().isAligned(false))
4043 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4045 .getString("label.sequences_not_aligned"),
4046 JOptionPane.WARNING_MESSAGE);
4051 if (viewport.getAlignment().getHeight() < 2)
4056 tp = new TreePanel(alignPanel, type, pwType);
4061 if (viewport.viewName != null)
4063 title += viewport.viewName + " of ";
4066 title += this.title;
4068 Desktop.addInternalFrame(tp, title, 600, 500);
4079 public void addSortByOrderMenuItem(String title,
4080 final AlignmentOrder order)
4082 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4084 item.addActionListener(new java.awt.event.ActionListener()
4087 public void actionPerformed(ActionEvent e)
4089 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4091 // TODO: JBPNote - have to map order entries to curent SequenceI
4093 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4095 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4098 alignPanel.paintAlignment(true);
4104 * Add a new sort by annotation score menu item
4107 * the menu to add the option to
4109 * the label used to retrieve scores for each sequence on the
4112 public void addSortByAnnotScoreMenuItem(JMenu sort,
4113 final String scoreLabel)
4115 final JMenuItem item = new JMenuItem(scoreLabel);
4117 item.addActionListener(new java.awt.event.ActionListener()
4120 public void actionPerformed(ActionEvent e)
4122 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4123 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4124 viewport.getAlignment());// ,viewport.getSelectionGroup());
4125 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4126 viewport.getAlignment()));
4127 alignPanel.paintAlignment(true);
4133 * last hash for alignment's annotation array - used to minimise cost of
4136 protected int _annotationScoreVectorHash;
4139 * search the alignment and rebuild the sort by annotation score submenu the
4140 * last alignment annotation vector hash is stored to minimize cost of
4141 * rebuilding in subsequence calls.
4145 public void buildSortByAnnotationScoresMenu()
4147 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4152 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4154 sortByAnnotScore.removeAll();
4155 // almost certainly a quicker way to do this - but we keep it simple
4156 Hashtable scoreSorts = new Hashtable();
4157 AlignmentAnnotation aann[];
4158 for (SequenceI sqa : viewport.getAlignment().getSequences())
4160 aann = sqa.getAnnotation();
4161 for (int i = 0; aann != null && i < aann.length; i++)
4163 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4165 scoreSorts.put(aann[i].label, aann[i].label);
4169 Enumeration labels = scoreSorts.keys();
4170 while (labels.hasMoreElements())
4172 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4173 (String) labels.nextElement());
4175 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4178 _annotationScoreVectorHash = viewport.getAlignment()
4179 .getAlignmentAnnotation().hashCode();
4184 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4185 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4186 * call. Listeners are added to remove the menu item when the treePanel is
4187 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4191 * Displayed tree window.
4193 * SortBy menu item title.
4196 public void buildTreeMenu()
4198 calculateTree.removeAll();
4199 // build the calculate menu
4201 for (final String type : new String[]
4204 String treecalcnm = MessageManager.getString("label.tree_calc_"
4205 + type.toLowerCase());
4206 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4208 JMenuItem tm = new JMenuItem();
4209 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4210 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4212 String smn = MessageManager.getStringOrReturn(
4213 "label.score_model_", sm.getName());
4214 final String title = MessageManager.formatMessage(
4215 "label.treecalc_title", treecalcnm, smn);
4216 tm.setText(title);//
4217 tm.addActionListener(new java.awt.event.ActionListener()
4220 public void actionPerformed(ActionEvent e)
4222 newTreePanel(type, pwtype, title);
4225 calculateTree.add(tm);
4230 sortByTreeMenu.removeAll();
4232 List<Component> comps = PaintRefresher.components.get(viewport
4233 .getSequenceSetId());
4234 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4235 for (Component comp : comps)
4237 if (comp instanceof TreePanel)
4239 treePanels.add((TreePanel) comp);
4243 if (treePanels.size() < 1)
4245 sortByTreeMenu.setVisible(false);
4249 sortByTreeMenu.setVisible(true);
4251 for (final TreePanel tp : treePanels)
4253 final JMenuItem item = new JMenuItem(tp.getTitle());
4254 item.addActionListener(new java.awt.event.ActionListener()
4257 public void actionPerformed(ActionEvent e)
4259 tp.sortByTree_actionPerformed();
4260 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4265 sortByTreeMenu.add(item);
4269 public boolean sortBy(AlignmentOrder alorder, String undoname)
4271 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4272 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4273 if (undoname != null)
4275 addHistoryItem(new OrderCommand(undoname, oldOrder,
4276 viewport.getAlignment()));
4278 alignPanel.paintAlignment(true);
4283 * Work out whether the whole set of sequences or just the selected set will
4284 * be submitted for multiple alignment.
4287 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4289 // Now, check we have enough sequences
4290 AlignmentView msa = null;
4292 if ((viewport.getSelectionGroup() != null)
4293 && (viewport.getSelectionGroup().getSize() > 1))
4295 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4296 // some common interface!
4298 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4299 * SequenceI[sz = seqs.getSize(false)];
4301 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4302 * seqs.getSequenceAt(i); }
4304 msa = viewport.getAlignmentView(true);
4306 else if (viewport.getSelectionGroup() != null
4307 && viewport.getSelectionGroup().getSize() == 1)
4309 int option = JOptionPane.showConfirmDialog(this,
4310 MessageManager.getString("warn.oneseq_msainput_selection"),
4311 MessageManager.getString("label.invalid_selection"),
4312 JOptionPane.OK_CANCEL_OPTION);
4313 if (option == JOptionPane.OK_OPTION)
4315 msa = viewport.getAlignmentView(false);
4320 msa = viewport.getAlignmentView(false);
4326 * Decides what is submitted to a secondary structure prediction service: the
4327 * first sequence in the alignment, or in the current selection, or, if the
4328 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4329 * region or the whole alignment. (where the first sequence in the set is the
4330 * one that the prediction will be for).
4332 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4334 AlignmentView seqs = null;
4336 if ((viewport.getSelectionGroup() != null)
4337 && (viewport.getSelectionGroup().getSize() > 0))
4339 seqs = viewport.getAlignmentView(true);
4343 seqs = viewport.getAlignmentView(false);
4345 // limit sequences - JBPNote in future - could spawn multiple prediction
4347 // TODO: viewport.getAlignment().isAligned is a global state - the local
4348 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4349 if (!viewport.getAlignment().isAligned(false))
4351 seqs.setSequences(new SeqCigar[]
4352 { seqs.getSequences()[0] });
4353 // TODO: if seqs.getSequences().length>1 then should really have warned
4367 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4369 // Pick the tree file
4370 JalviewFileChooser chooser = new JalviewFileChooser(
4371 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4372 chooser.setFileView(new JalviewFileView());
4373 chooser.setDialogTitle(MessageManager
4374 .getString("label.select_newick_like_tree_file"));
4375 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4377 int value = chooser.showOpenDialog(null);
4379 if (value == JalviewFileChooser.APPROVE_OPTION)
4381 String choice = chooser.getSelectedFile().getPath();
4382 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4383 jalview.io.NewickFile fin = null;
4386 fin = new jalview.io.NewickFile(choice, "File");
4387 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4388 } catch (Exception ex)
4395 .getString("label.problem_reading_tree_file"),
4396 JOptionPane.WARNING_MESSAGE);
4397 ex.printStackTrace();
4399 if (fin != null && fin.hasWarningMessage())
4401 JOptionPane.showMessageDialog(Desktop.desktop, fin
4402 .getWarningMessage(), MessageManager
4403 .getString("label.possible_problem_with_tree_file"),
4404 JOptionPane.WARNING_MESSAGE);
4410 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4412 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4415 public TreePanel ShowNewickTree(NewickFile nf, String title)
4417 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4420 public TreePanel ShowNewickTree(NewickFile nf, String title,
4421 AlignmentView input)
4423 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4426 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4427 int h, int x, int y)
4429 return ShowNewickTree(nf, title, null, w, h, x, y);
4433 * Add a treeviewer for the tree extracted from a newick file object to the
4434 * current alignment view
4441 * Associated alignment input data (or null)
4450 * @return TreePanel handle
4452 public TreePanel ShowNewickTree(NewickFile nf, String title,
4453 AlignmentView input, int w, int h, int x, int y)
4455 TreePanel tp = null;
4461 if (nf.getTree() != null)
4463 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4469 tp.setLocation(x, y);
4472 Desktop.addInternalFrame(tp, title, w, h);
4474 } catch (Exception ex)
4476 ex.printStackTrace();
4482 private boolean buildingMenu = false;
4485 * Generates menu items and listener event actions for web service clients
4488 public void BuildWebServiceMenu()
4490 while (buildingMenu)
4494 System.err.println("Waiting for building menu to finish.");
4496 } catch (Exception e)
4500 final AlignFrame me = this;
4501 buildingMenu = true;
4502 new Thread(new Runnable()
4507 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4510 System.err.println("Building ws menu again "
4511 + Thread.currentThread());
4512 // TODO: add support for context dependent disabling of services based
4514 // alignment and current selection
4515 // TODO: add additional serviceHandle parameter to specify abstract
4517 // class independently of AbstractName
4518 // TODO: add in rediscovery GUI function to restart discoverer
4519 // TODO: group services by location as well as function and/or
4521 // object broker mechanism.
4522 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4523 final IProgressIndicator af = me;
4524 final JMenu msawsmenu = new JMenu("Alignment");
4525 final JMenu secstrmenu = new JMenu(
4526 "Secondary Structure Prediction");
4527 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4528 final JMenu analymenu = new JMenu("Analysis");
4529 final JMenu dismenu = new JMenu("Protein Disorder");
4530 // final JMenu msawsmenu = new
4531 // JMenu(MessageManager.getString("label.alignment"));
4532 // final JMenu secstrmenu = new
4533 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4534 // final JMenu seqsrchmenu = new
4535 // JMenu(MessageManager.getString("label.sequence_database_search"));
4536 // final JMenu analymenu = new
4537 // JMenu(MessageManager.getString("label.analysis"));
4538 // final JMenu dismenu = new
4539 // JMenu(MessageManager.getString("label.protein_disorder"));
4540 // JAL-940 - only show secondary structure prediction services from
4541 // the legacy server
4542 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4544 Discoverer.services != null && (Discoverer.services.size() > 0))
4546 // TODO: refactor to allow list of AbstractName/Handler bindings to
4548 // stored or retrieved from elsewhere
4549 // No MSAWS used any more:
4550 // Vector msaws = null; // (Vector)
4551 // Discoverer.services.get("MsaWS");
4552 Vector secstrpr = (Vector) Discoverer.services
4554 if (secstrpr != null)
4556 // Add any secondary structure prediction services
4557 for (int i = 0, j = secstrpr.size(); i < j; i++)
4559 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4561 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4562 .getServiceClient(sh);
4563 int p = secstrmenu.getItemCount();
4564 impl.attachWSMenuEntry(secstrmenu, me);
4565 int q = secstrmenu.getItemCount();
4566 for (int litm = p; litm < q; litm++)
4568 legacyItems.add(secstrmenu.getItem(litm));
4574 // Add all submenus in the order they should appear on the web
4576 wsmenu.add(msawsmenu);
4577 wsmenu.add(secstrmenu);
4578 wsmenu.add(dismenu);
4579 wsmenu.add(analymenu);
4580 // No search services yet
4581 // wsmenu.add(seqsrchmenu);
4583 javax.swing.SwingUtilities.invokeLater(new Runnable()
4590 webService.removeAll();
4591 // first, add discovered services onto the webservices menu
4592 if (wsmenu.size() > 0)
4594 for (int i = 0, j = wsmenu.size(); i < j; i++)
4596 webService.add(wsmenu.get(i));
4601 webService.add(me.webServiceNoServices);
4603 // TODO: move into separate menu builder class.
4604 boolean new_sspred = false;
4605 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4607 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4608 if (jws2servs != null)
4610 if (jws2servs.hasServices())
4612 jws2servs.attachWSMenuEntry(webService, me);
4613 for (Jws2Instance sv : jws2servs.getServices())
4615 if (sv.description.toLowerCase().contains("jpred"))
4617 for (JMenuItem jmi : legacyItems)
4619 jmi.setVisible(false);
4625 if (jws2servs.isRunning())
4627 JMenuItem tm = new JMenuItem(
4628 "Still discovering JABA Services");
4629 tm.setEnabled(false);
4634 build_urlServiceMenu(me.webService);
4635 build_fetchdbmenu(webService);
4636 for (JMenu item : wsmenu)
4638 if (item.getItemCount() == 0)
4640 item.setEnabled(false);
4644 item.setEnabled(true);
4647 } catch (Exception e)
4650 .debug("Exception during web service menu building process.",
4655 } catch (Exception e)
4658 buildingMenu = false;
4665 * construct any groupURL type service menu entries.
4669 private void build_urlServiceMenu(JMenu webService)
4671 // TODO: remove this code when 2.7 is released
4672 // DEBUG - alignmentView
4674 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4675 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4677 * @Override public void actionPerformed(ActionEvent e) {
4678 * jalview.datamodel.AlignmentView
4679 * .testSelectionViews(af.viewport.getAlignment(),
4680 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4682 * }); webService.add(testAlView);
4684 // TODO: refactor to RestClient discoverer and merge menu entries for
4685 // rest-style services with other types of analysis/calculation service
4686 // SHmmr test client - still being implemented.
4687 // DEBUG - alignmentView
4689 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4692 client.attachWSMenuEntry(
4693 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4699 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4700 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4701 * getProperty("LAST_DIRECTORY"));
4703 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4704 * to Vamsas file"); chooser.setToolTipText("Export");
4706 * int value = chooser.showSaveDialog(this);
4708 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4709 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4710 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4711 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4714 * prototype of an automatically enabled/disabled analysis function
4717 protected void setShowProductsEnabled()
4719 SequenceI[] selection = viewport.getSequenceSelection();
4720 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4721 viewport.getAlignment().getDataset()))
4723 showProducts.setEnabled(true);
4728 showProducts.setEnabled(false);
4733 * search selection for sequence xRef products and build the show products
4738 * @return true if showProducts menu should be enabled.
4740 public boolean canShowProducts(SequenceI[] selection,
4741 boolean isRegionSelection, Alignment dataset)
4743 boolean showp = false;
4746 showProducts.removeAll();
4747 final boolean dna = viewport.getAlignment().isNucleotide();
4748 final Alignment ds = dataset;
4749 String[] ptypes = (selection == null || selection.length == 0) ? null
4750 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4752 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4753 // selection, dataset, true);
4754 final SequenceI[] sel = selection;
4755 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4758 final boolean isRegSel = isRegionSelection;
4759 final AlignFrame af = this;
4760 final String source = ptypes[t];
4761 JMenuItem xtype = new JMenuItem(ptypes[t]);
4762 xtype.addActionListener(new ActionListener()
4766 public void actionPerformed(ActionEvent e)
4768 // TODO: new thread for this call with vis-delay
4769 af.showProductsFor(af.viewport.getSequenceSelection(),
4770 isRegSel, dna, source);
4774 showProducts.add(xtype);
4776 showProducts.setVisible(showp);
4777 showProducts.setEnabled(showp);
4778 } catch (Exception e)
4780 jalview.bin.Cache.log
4781 .warn("canTranslate threw an exception - please report to help@jalview.org",
4788 protected void showProductsFor(final SequenceI[] sel,
4789 final boolean isRegSel, final boolean dna, final String source)
4791 Runnable foo = new Runnable()
4797 final long sttime = System.currentTimeMillis();
4798 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4799 "status.searching_for_sequences_from", new Object[]
4800 { source }), sttime);
4803 // update our local dataset reference
4804 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4806 Alignment prods = CrossRef
4807 .findXrefSequences(sel, dna, source, ds);
4810 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4811 for (int s = 0; s < sprods.length; s++)
4813 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4814 if (ds.getSequences() == null
4815 || !ds.getSequences().contains(
4816 sprods[s].getDatasetSequence()))
4818 ds.addSequence(sprods[s].getDatasetSequence());
4820 sprods[s].updatePDBIds();
4822 Alignment al = new Alignment(sprods);
4826 * Copy dna-to-protein mappings to new alignment
4828 // TODO 1: no mappings are set up for EMBL product
4829 // TODO 2: if they were, should add them to protein alignment, not
4831 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4832 for (AlignedCodonFrame acf : cf)
4834 al.addCodonFrame(acf);
4836 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4838 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4839 + " for " + ((isRegSel) ? "selected region of " : "")
4841 naf.setTitle(newtitle);
4843 // temporary flag until SplitFrame is released
4844 boolean asSplitFrame = Cache.getDefault(
4845 Preferences.ENABLE_SPLIT_FRAME, false);
4849 * Make a copy of this alignment (sharing the same dataset
4850 * sequences). If we are DNA, drop introns and update mappings
4852 AlignmentI copyAlignment = null;
4853 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4854 .getSequenceSelection();
4857 copyAlignment = AlignmentUtils.makeExonAlignment(
4858 sequenceSelection, cf);
4859 al.getCodonFrames().clear();
4860 al.getCodonFrames().addAll(cf);
4861 final StructureSelectionManager ssm = StructureSelectionManager
4862 .getStructureSelectionManager(Desktop.instance);
4863 ssm.addMappings(cf);
4867 copyAlignment = new Alignment(new Alignment(
4868 sequenceSelection));
4870 AlignFrame copyThis = new AlignFrame(copyAlignment,
4871 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4872 copyThis.setTitle(AlignFrame.this.getTitle());
4873 // SplitFrame with dna above, protein below
4874 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4875 dna ? naf : copyThis);
4876 naf.setVisible(true);
4877 copyThis.setVisible(true);
4878 String linkedTitle = MessageManager
4879 .getString("label.linked_view_title");
4880 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4884 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4890 System.err.println("No Sequences generated for xRef type "
4893 } catch (Exception e)
4895 jalview.bin.Cache.log.error(
4896 "Exception when finding crossreferences", e);
4897 } catch (OutOfMemoryError e)
4899 new OOMWarning("whilst fetching crossreferences", e);
4902 jalview.bin.Cache.log.error("Error when finding crossreferences",
4905 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4906 "status.finished_searching_for_sequences_from",
4913 Thread frunner = new Thread(foo);
4917 public boolean canShowTranslationProducts(SequenceI[] selection,
4918 AlignmentI alignment)
4923 return (jalview.analysis.Dna.canTranslate(selection,
4924 viewport.getViewAsVisibleContigs(true)));
4925 } catch (Exception e)
4927 jalview.bin.Cache.log
4928 .warn("canTranslate threw an exception - please report to help@jalview.org",
4935 * Construct and display a new frame containing the translation of this
4936 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4939 public void showTranslation_actionPerformed(ActionEvent e)
4941 AlignmentI al = null;
4944 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4946 al = dna.translateCdna();
4947 } catch (Exception ex)
4949 jalview.bin.Cache.log.error(
4950 "Exception during translation. Please report this !", ex);
4951 final String msg = MessageManager
4952 .getString("label.error_when_translating_sequences_submit_bug_report");
4953 final String title = MessageManager
4954 .getString("label.implementation_error")
4955 + MessageManager.getString("translation_failed");
4956 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4957 JOptionPane.ERROR_MESSAGE);
4960 if (al == null || al.getHeight() == 0)
4962 final String msg = MessageManager
4963 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4964 final String title = MessageManager
4965 .getString("label.translation_failed");
4966 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4967 JOptionPane.WARNING_MESSAGE);
4971 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4972 af.setFileFormat(this.currentFileFormat);
4973 final String newTitle = MessageManager.formatMessage(
4974 "label.translation_of_params", new Object[]
4975 { this.getTitle() });
4976 af.setTitle(newTitle);
4977 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
4979 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4980 viewport.openSplitFrame(af, new Alignment(seqs),
4981 al.getCodonFrames());
4985 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4992 * Set the file format
4996 public void setFileFormat(String fileFormat)
4998 this.currentFileFormat = fileFormat;
5002 * Try to load a features file onto the alignment.
5005 * contents or path to retrieve file
5007 * access mode of file (see jalview.io.AlignFile)
5008 * @return true if features file was parsed correctly.
5010 public boolean parseFeaturesFile(String file, String type)
5012 return avc.parseFeaturesFile(file, type,
5013 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5018 public void refreshFeatureUI(boolean enableIfNecessary)
5020 // note - currently this is only still here rather than in the controller
5021 // because of the featureSettings hard reference that is yet to be
5023 if (enableIfNecessary)
5025 viewport.setShowSequenceFeatures(true);
5026 showSeqFeatures.setSelected(true);
5032 public void dragEnter(DropTargetDragEvent evt)
5037 public void dragExit(DropTargetEvent evt)
5042 public void dragOver(DropTargetDragEvent evt)
5047 public void dropActionChanged(DropTargetDragEvent evt)
5052 public void drop(DropTargetDropEvent evt)
5054 Transferable t = evt.getTransferable();
5055 java.util.List files = null;
5059 DataFlavor uriListFlavor = new DataFlavor(
5060 "text/uri-list;class=java.lang.String");
5061 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5063 // Works on Windows and MacOSX
5064 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5065 files = (java.util.List) t
5066 .getTransferData(DataFlavor.javaFileListFlavor);
5068 else if (t.isDataFlavorSupported(uriListFlavor))
5070 // This is used by Unix drag system
5071 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5072 String data = (String) t.getTransferData(uriListFlavor);
5073 files = new java.util.ArrayList(1);
5074 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5075 data, "\r\n"); st.hasMoreTokens();)
5077 String s = st.nextToken();
5078 if (s.startsWith("#"))
5080 // the line is a comment (as per the RFC 2483)
5084 java.net.URI uri = new java.net.URI(s);
5085 // check to see if we can handle this kind of URI
5086 if (uri.getScheme().toLowerCase().startsWith("http"))
5088 files.add(uri.toString());
5092 // otherwise preserve old behaviour: catch all for file objects
5093 java.io.File file = new java.io.File(uri);
5094 files.add(file.toString());
5098 } catch (Exception e)
5100 e.printStackTrace();
5106 // check to see if any of these files have names matching sequences in
5108 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5109 .getAlignment().getSequencesArray());
5111 * Object[] { String,SequenceI}
5113 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5114 ArrayList<String> filesnotmatched = new ArrayList<String>();
5115 for (int i = 0; i < files.size(); i++)
5117 String file = files.get(i).toString();
5119 String protocol = FormatAdapter.checkProtocol(file);
5120 if (protocol == jalview.io.FormatAdapter.FILE)
5122 File fl = new File(file);
5123 pdbfn = fl.getName();
5125 else if (protocol == jalview.io.FormatAdapter.URL)
5127 URL url = new URL(file);
5128 pdbfn = url.getFile();
5130 if (pdbfn.length() > 0)
5132 // attempt to find a match in the alignment
5133 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5134 int l = 0, c = pdbfn.indexOf(".");
5135 while (mtch == null && c != -1)
5140 } while ((c = pdbfn.indexOf(".", l)) > l);
5143 pdbfn = pdbfn.substring(0, l);
5145 mtch = idm.findAllIdMatches(pdbfn);
5152 type = new IdentifyFile().Identify(file, protocol);
5153 } catch (Exception ex)
5159 if (type.equalsIgnoreCase("PDB"))
5161 filesmatched.add(new Object[]
5162 { file, protocol, mtch });
5167 // File wasn't named like one of the sequences or wasn't a PDB file.
5168 filesnotmatched.add(file);
5172 if (filesmatched.size() > 0)
5174 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5180 "label.automatically_associate_pdb_files_with_sequences_same_name",
5187 .getString("label.automatically_associate_pdb_files_by_name"),
5188 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5191 for (Object[] fm : filesmatched)
5193 // try and associate
5194 // TODO: may want to set a standard ID naming formalism for
5195 // associating PDB files which have no IDs.
5196 for (SequenceI toassoc : (SequenceI[]) fm[2])
5198 PDBEntry pe = new AssociatePdbFileWithSeq()
5199 .associatePdbWithSeq((String) fm[0],
5200 (String) fm[1], toassoc, false,
5204 System.err.println("Associated file : "
5205 + ((String) fm[0]) + " with "
5206 + toassoc.getDisplayId(true));
5210 alignPanel.paintAlignment(true);
5214 if (filesnotmatched.size() > 0)
5217 && (Cache.getDefault(
5218 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5221 "<html>"+MessageManager
5223 "label.ignore_unmatched_dropped_files_info",
5228 .toString() })+"</html>",
5230 .getString("label.ignore_unmatched_dropped_files"),
5231 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5235 for (String fn : filesnotmatched)
5237 loadJalviewDataFile(fn, null, null, null);
5241 } catch (Exception ex)
5243 ex.printStackTrace();
5249 * Attempt to load a "dropped" file or URL string: First by testing whether
5250 * it's and Annotation file, then a JNet file, and finally a features file. If
5251 * all are false then the user may have dropped an alignment file onto this
5255 * either a filename or a URL string.
5257 public void loadJalviewDataFile(String file, String protocol,
5258 String format, SequenceI assocSeq)
5262 if (protocol == null)
5264 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5266 // if the file isn't identified, or not positively identified as some
5267 // other filetype (PFAM is default unidentified alignment file type) then
5268 // try to parse as annotation.
5269 boolean isAnnotation = (format == null || format
5270 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5271 .annotateAlignmentView(viewport, file, protocol)
5276 // first see if its a T-COFFEE score file
5277 TCoffeeScoreFile tcf = null;
5280 tcf = new TCoffeeScoreFile(file, protocol);
5283 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5285 tcoffeeColour.setEnabled(true);
5286 tcoffeeColour.setSelected(true);
5287 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5288 isAnnotation = true;
5290 .setText(MessageManager
5291 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5295 // some problem - if no warning its probable that the ID matching
5296 // process didn't work
5300 tcf.getWarningMessage() == null ? MessageManager
5301 .getString("label.check_file_matches_sequence_ids_alignment")
5302 : tcf.getWarningMessage(),
5304 .getString("label.problem_reading_tcoffee_score_file"),
5305 JOptionPane.WARNING_MESSAGE);
5312 } catch (Exception x)
5315 .debug("Exception when processing data source as T-COFFEE score file",
5321 // try to see if its a JNet 'concise' style annotation file *before*
5323 // try to parse it as a features file
5326 format = new IdentifyFile().Identify(file, protocol);
5328 if (format.equalsIgnoreCase("JnetFile"))
5330 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5332 new JnetAnnotationMaker();
5333 JnetAnnotationMaker.add_annotation(predictions,
5334 viewport.getAlignment(), 0, false);
5335 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5336 viewport.getAlignment().setSeqrep(repseq);
5337 ColumnSelection cs = new ColumnSelection();
5338 cs.hideInsertionsFor(repseq);
5339 viewport.setColumnSelection(cs);
5340 isAnnotation = true;
5345 * if (format.equalsIgnoreCase("PDB")) {
5347 * String pdbfn = ""; // try to match up filename with sequence id
5348 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5349 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5350 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5351 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5352 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5353 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5354 * // attempt to find a match in the alignment SequenceI mtch =
5355 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5356 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5357 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5358 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5359 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5360 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5361 * { System.err.println("Associated file : " + file + " with " +
5362 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5363 * TODO: maybe need to load as normal otherwise return; } }
5365 // try to parse it as a features file
5366 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5367 // if it wasn't a features file then we just treat it as a general
5368 // alignment file to load into the current view.
5371 new FileLoader().LoadFile(viewport, file, protocol, format);
5375 alignPanel.paintAlignment(true);
5383 alignPanel.adjustAnnotationHeight();
5384 viewport.updateSequenceIdColours();
5385 buildSortByAnnotationScoresMenu();
5386 alignPanel.paintAlignment(true);
5388 } catch (Exception ex)
5390 ex.printStackTrace();
5391 } catch (OutOfMemoryError oom)
5396 } catch (Exception x)
5402 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5403 : "using " + protocol + " from " + file)
5405 + (format != null ? "(parsing as '" + format
5406 + "' file)" : ""), oom, Desktop.desktop);
5411 * Method invoked by the ChangeListener on the tabbed pane, in other words
5412 * when a different tabbed pane is selected by the user or programmatically.
5415 public void tabSelectionChanged(int index)
5419 alignPanel = alignPanels.get(index);
5420 viewport = alignPanel.av;
5421 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5422 setMenusFromViewport(viewport);
5426 * If there is a frame linked to this one in a SplitPane, switch it to the
5427 * same view tab index. No infinite recursion of calls should happen, since
5428 * tabSelectionChanged() should not get invoked on setting the selected
5429 * index to an unchanged value. Guard against setting an invalid index
5430 * before the new view peer tab has been created.
5432 final AlignViewportI peer = viewport.getCodingComplement();
5435 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5436 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5438 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5444 * On right mouse click on view tab, prompt for and set new view name.
5447 public void tabbedPane_mousePressed(MouseEvent e)
5449 if (SwingUtilities.isRightMouseButton(e))
5451 String msg = MessageManager.getString("label.enter_view_name");
5452 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5453 JOptionPane.QUESTION_MESSAGE);
5457 viewport.viewName = reply;
5458 // TODO warn if reply is in getExistingViewNames()?
5459 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5464 public AlignViewport getCurrentView()
5470 * Open the dialog for regex description parsing.
5473 protected void extractScores_actionPerformed(ActionEvent e)
5475 ParseProperties pp = new jalview.analysis.ParseProperties(
5476 viewport.getAlignment());
5477 // TODO: verify regex and introduce GUI dialog for version 2.5
5478 // if (pp.getScoresFromDescription("col", "score column ",
5479 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5481 if (pp.getScoresFromDescription("description column",
5482 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5484 buildSortByAnnotationScoresMenu();
5492 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5496 protected void showDbRefs_actionPerformed(ActionEvent e)
5498 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5504 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5508 protected void showNpFeats_actionPerformed(ActionEvent e)
5510 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5514 * find the viewport amongst the tabs in this alignment frame and close that
5519 public boolean closeView(AlignViewportI av)
5523 this.closeMenuItem_actionPerformed(false);
5526 Component[] comp = tabbedPane.getComponents();
5527 for (int i = 0; comp != null && i < comp.length; i++)
5529 if (comp[i] instanceof AlignmentPanel)
5531 if (((AlignmentPanel) comp[i]).av == av)
5534 closeView((AlignmentPanel) comp[i]);
5542 protected void build_fetchdbmenu(JMenu webService)
5544 // Temporary hack - DBRef Fetcher always top level ws entry.
5545 // TODO We probably want to store a sequence database checklist in
5546 // preferences and have checkboxes.. rather than individual sources selected
5548 final JMenu rfetch = new JMenu(
5549 MessageManager.getString("action.fetch_db_references"));
5550 rfetch.setToolTipText(MessageManager
5551 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5552 webService.add(rfetch);
5554 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5555 MessageManager.getString("option.trim_retrieved_seqs"));
5556 trimrs.setToolTipText(MessageManager
5557 .getString("label.trim_retrieved_sequences"));
5558 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5559 trimrs.addActionListener(new ActionListener()
5562 public void actionPerformed(ActionEvent e)
5564 trimrs.setSelected(trimrs.isSelected());
5565 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5566 Boolean.valueOf(trimrs.isSelected()).toString());
5570 JMenuItem fetchr = new JMenuItem(
5571 MessageManager.getString("label.standard_databases"));
5572 fetchr.setToolTipText(MessageManager
5573 .getString("label.fetch_embl_uniprot"));
5574 fetchr.addActionListener(new ActionListener()
5578 public void actionPerformed(ActionEvent e)
5580 new Thread(new Runnable()
5586 new jalview.ws.DBRefFetcher(alignPanel.av
5587 .getSequenceSelection(), alignPanel.alignFrame)
5588 .fetchDBRefs(false);
5596 final AlignFrame me = this;
5597 new Thread(new Runnable()
5602 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5603 .getSequenceFetcherSingleton(me);
5604 javax.swing.SwingUtilities.invokeLater(new Runnable()
5609 String[] dbclasses = sf.getOrderedSupportedSources();
5610 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5611 // jalview.util.QuickSort.sort(otherdb, otherdb);
5612 List<DbSourceProxy> otherdb;
5613 JMenu dfetch = new JMenu();
5614 JMenu ifetch = new JMenu();
5615 JMenuItem fetchr = null;
5616 int comp = 0, icomp = 0, mcomp = 15;
5617 String mname = null;
5619 for (String dbclass : dbclasses)
5621 otherdb = sf.getSourceProxy(dbclass);
5622 // add a single entry for this class, or submenu allowing 'fetch
5624 if (otherdb == null || otherdb.size() < 1)
5628 // List<DbSourceProxy> dbs=otherdb;
5629 // otherdb=new ArrayList<DbSourceProxy>();
5630 // for (DbSourceProxy db:dbs)
5632 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5636 mname = "From " + dbclass;
5638 if (otherdb.size() == 1)
5640 final DbSourceProxy[] dassource = otherdb
5641 .toArray(new DbSourceProxy[0]);
5642 DbSourceProxy src = otherdb.get(0);
5643 fetchr = new JMenuItem(src.getDbSource());
5644 fetchr.addActionListener(new ActionListener()
5648 public void actionPerformed(ActionEvent e)
5650 new Thread(new Runnable()
5656 new jalview.ws.DBRefFetcher(alignPanel.av
5657 .getSequenceSelection(),
5658 alignPanel.alignFrame, dassource)
5659 .fetchDBRefs(false);
5665 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5671 final DbSourceProxy[] dassource = otherdb
5672 .toArray(new DbSourceProxy[0]);
5674 DbSourceProxy src = otherdb.get(0);
5675 fetchr = new JMenuItem(MessageManager.formatMessage(
5676 "label.fetch_all_param", new Object[]
5677 { src.getDbSource() }));
5678 fetchr.addActionListener(new ActionListener()
5681 public void actionPerformed(ActionEvent e)
5683 new Thread(new Runnable()
5689 new jalview.ws.DBRefFetcher(alignPanel.av
5690 .getSequenceSelection(),
5691 alignPanel.alignFrame, dassource)
5692 .fetchDBRefs(false);
5698 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5701 // and then build the rest of the individual menus
5702 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5704 String imname = null;
5706 for (DbSourceProxy sproxy : otherdb)
5708 String dbname = sproxy.getDbName();
5709 String sname = dbname.length() > 5 ? dbname.substring(0,
5710 5) + "..." : dbname;
5711 String msname = dbname.length() > 10 ? dbname.substring(
5712 0, 10) + "..." : dbname;
5715 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5717 fetchr = new JMenuItem(msname);
5718 final DbSourceProxy[] dassrc =
5720 fetchr.addActionListener(new ActionListener()
5724 public void actionPerformed(ActionEvent e)
5726 new Thread(new Runnable()
5732 new jalview.ws.DBRefFetcher(alignPanel.av
5733 .getSequenceSelection(),
5734 alignPanel.alignFrame, dassrc)
5735 .fetchDBRefs(false);
5741 fetchr.setToolTipText("<html>"
5742 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5745 if (++icomp >= mcomp || i == (otherdb.size()))
5747 ifetch.setText(MessageManager.formatMessage(
5748 "label.source_to_target", imname, sname));
5750 ifetch = new JMenu();
5758 if (comp >= mcomp || dbi >= (dbclasses.length))
5760 dfetch.setText(MessageManager.formatMessage(
5761 "label.source_to_target", mname, dbclass));
5763 dfetch = new JMenu();
5776 * Left justify the whole alignment.
5779 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5781 AlignmentI al = viewport.getAlignment();
5783 viewport.firePropertyChange("alignment", null, al);
5787 * Right justify the whole alignment.
5790 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5792 AlignmentI al = viewport.getAlignment();
5794 viewport.firePropertyChange("alignment", null, al);
5797 public void setShowSeqFeatures(boolean b)
5799 showSeqFeatures.setSelected(b);
5800 viewport.setShowSequenceFeatures(b);
5807 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5808 * awt.event.ActionEvent)
5811 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5813 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5814 alignPanel.paintAlignment(true);
5821 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5825 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5827 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5828 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5836 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5837 * .event.ActionEvent)
5840 protected void showGroupConservation_actionPerformed(ActionEvent e)
5842 viewport.setShowGroupConservation(showGroupConservation.getState());
5843 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5850 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5851 * .event.ActionEvent)
5854 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5856 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5857 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5864 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5865 * .event.ActionEvent)
5868 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5870 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5871 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5875 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5877 showSequenceLogo.setState(true);
5878 viewport.setShowSequenceLogo(true);
5879 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5880 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5884 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5886 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5893 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5894 * .event.ActionEvent)
5897 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5899 if (avc.makeGroupsFromSelection())
5901 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5902 alignPanel.updateAnnotation();
5903 alignPanel.paintAlignment(true);
5906 public void clearAlignmentSeqRep()
5908 // TODO refactor alignmentseqrep to controller
5909 if (viewport.getAlignment().hasSeqrep()) {
5910 viewport.getAlignment().setSeqrep(null);
5911 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5912 alignPanel.updateAnnotation();
5913 alignPanel.paintAlignment(true);
5918 protected void createGroup_actionPerformed(ActionEvent e)
5920 if (avc.createGroup())
5922 alignPanel.alignmentChanged();
5927 protected void unGroup_actionPerformed(ActionEvent e)
5931 alignPanel.alignmentChanged();
5936 * make the given alignmentPanel the currently selected tab
5938 * @param alignmentPanel
5940 public void setDisplayedView(AlignmentPanel alignmentPanel)
5942 if (!viewport.getSequenceSetId().equals(
5943 alignmentPanel.av.getSequenceSetId()))
5945 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5947 if (tabbedPane != null
5948 && tabbedPane.getTabCount() > 0
5949 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5950 .getSelectedIndex())
5952 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5957 * Action on selection of menu options to Show or Hide annotations.
5960 * @param forSequences
5961 * update sequence-related annotations
5962 * @param forAlignment
5963 * update non-sequence-related annotations
5966 protected void setAnnotationsVisibility(boolean visible,
5967 boolean forSequences, boolean forAlignment)
5969 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5970 .getAlignmentAnnotation())
5973 * don't display non-positional annotations on an alignment
5975 if (aa.annotations == null)
5979 boolean apply = (aa.sequenceRef == null && forAlignment)
5980 || (aa.sequenceRef != null && forSequences);
5983 aa.visible = visible;
5986 alignPanel.validateAnnotationDimensions(false);
5987 alignPanel.alignmentChanged();
5991 * Store selected annotation sort order for the view and repaint.
5994 protected void sortAnnotations_actionPerformed()
5996 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5998 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5999 alignPanel.paintAlignment(true);
6004 * @return alignment panels in this alignment frame
6006 public List<? extends AlignmentViewPanel> getAlignPanels()
6008 return alignPanels == null ? Arrays.asList(alignPanel)
6013 * Open a new alignment window, with the cDNA associated with this (protein)
6014 * alignment, aligned as is the protein.
6016 protected void viewAsCdna_actionPerformed()
6018 // TODO no longer a menu action - refactor as required
6019 final AlignmentI alignment = getViewport().getAlignment();
6020 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6021 if (mappings == null)
6025 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6026 for (SequenceI aaSeq : alignment.getSequences()) {
6027 for (AlignedCodonFrame acf : mappings) {
6028 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6032 * There is a cDNA mapping for this protein sequence - add to new
6033 * alignment. It will share the same dataset sequence as other mapped
6034 * cDNA (no new mappings need to be created).
6036 final Sequence newSeq = new Sequence(dnaSeq);
6037 newSeq.setDatasetSequence(dnaSeq);
6038 cdnaSeqs.add(newSeq);
6042 if (cdnaSeqs.size() == 0)
6044 // show a warning dialog no mapped cDNA
6047 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6049 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6050 AlignFrame.DEFAULT_HEIGHT);
6051 cdna.alignAs(alignment);
6052 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6054 Desktop.addInternalFrame(alignFrame, newtitle,
6055 AlignFrame.DEFAULT_WIDTH,
6056 AlignFrame.DEFAULT_HEIGHT);
6060 * Set visibility of dna/protein complement view (available when shown in a
6066 protected void showComplement_actionPerformed(boolean show)
6068 SplitContainerI sf = getSplitViewContainer();
6070 sf.setComplementVisible(this, show);
6074 public class ExportData
6076 private AlignmentI alignment;
6078 private String[] omitHidden;
6080 private int[] startEnd;
6082 private AlignExportSettingI settings;
6084 public ExportData(AlignmentI align, String[] ommit, int[] startEnd,
6085 AlignExportSettingI settings)
6087 this.alignment = align;
6088 this.omitHidden = ommit;
6089 this.startEnd = startEnd;
6090 this.settings = settings;
6093 public AlignmentI getAlignment()
6098 public void setAlignment(AlignmentI alignment)
6100 this.alignment = alignment;
6103 public String[] getOmitHidden()
6108 public void setOmitHidden(String[] omitHidden)
6110 this.omitHidden = omitHidden;
6113 public int[] getStartEndPostions()
6118 public void setStartEndPostions(int[] startEnd)
6120 this.startEnd = startEnd;
6123 public AlignExportSettingI getSettings()
6128 public void setSettings(AlignExportSettingI settings)
6130 this.settings = settings;
6136 class PrintThread extends Thread
6140 public PrintThread(AlignmentPanel ap)
6145 static PageFormat pf;
6150 PrinterJob printJob = PrinterJob.getPrinterJob();
6154 printJob.setPrintable(ap, pf);
6158 printJob.setPrintable(ap);
6161 if (printJob.printDialog())
6166 } catch (Exception PrintException)
6168 PrintException.printStackTrace();