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 java.awt.BorderLayout;
24 import java.awt.Component;
25 import java.awt.Rectangle;
26 import java.awt.Toolkit;
27 import java.awt.datatransfer.Clipboard;
28 import java.awt.datatransfer.DataFlavor;
29 import java.awt.datatransfer.StringSelection;
30 import java.awt.datatransfer.Transferable;
31 import java.awt.dnd.DnDConstants;
32 import java.awt.dnd.DropTargetDragEvent;
33 import java.awt.dnd.DropTargetDropEvent;
34 import java.awt.dnd.DropTargetEvent;
35 import java.awt.dnd.DropTargetListener;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.ItemEvent;
39 import java.awt.event.ItemListener;
40 import java.awt.event.KeyAdapter;
41 import java.awt.event.KeyEvent;
42 import java.awt.event.MouseAdapter;
43 import java.awt.event.MouseEvent;
44 import java.awt.print.PageFormat;
45 import java.awt.print.PrinterJob;
46 import java.beans.PropertyChangeEvent;
49 import java.util.ArrayList;
50 import java.util.Arrays;
51 import java.util.Deque;
52 import java.util.Enumeration;
53 import java.util.Hashtable;
54 import java.util.List;
56 import java.util.Vector;
58 import javax.swing.JCheckBoxMenuItem;
59 import javax.swing.JEditorPane;
60 import javax.swing.JInternalFrame;
61 import javax.swing.JLayeredPane;
62 import javax.swing.JMenu;
63 import javax.swing.JMenuItem;
64 import javax.swing.JOptionPane;
65 import javax.swing.JRadioButtonMenuItem;
66 import javax.swing.JScrollPane;
67 import javax.swing.SwingUtilities;
69 import jalview.analysis.AAFrequency;
70 import jalview.analysis.AlignmentSorter;
71 import jalview.analysis.AlignmentUtils;
72 import jalview.analysis.Conservation;
73 import jalview.analysis.CrossRef;
74 import jalview.analysis.Dna;
75 import jalview.analysis.ParseProperties;
76 import jalview.analysis.SequenceIdMatcher;
77 import jalview.api.AlignExportSettingI;
78 import jalview.api.AlignViewControllerGuiI;
79 import jalview.api.AlignViewControllerI;
80 import jalview.api.AlignViewportI;
81 import jalview.api.AlignmentViewPanel;
82 import jalview.api.FeatureSettingsControllerI;
83 import jalview.api.SplitContainerI;
84 import jalview.api.ViewStyleI;
85 import jalview.api.analysis.ScoreModelI;
86 import jalview.bin.Cache;
87 import jalview.commands.CommandI;
88 import jalview.commands.EditCommand;
89 import jalview.commands.EditCommand.Action;
90 import jalview.commands.OrderCommand;
91 import jalview.commands.RemoveGapColCommand;
92 import jalview.commands.RemoveGapsCommand;
93 import jalview.commands.SlideSequencesCommand;
94 import jalview.commands.TrimRegionCommand;
95 import jalview.datamodel.AlignedCodonFrame;
96 import jalview.datamodel.Alignment;
97 import jalview.datamodel.AlignmentAnnotation;
98 import jalview.datamodel.AlignmentI;
99 import jalview.datamodel.AlignmentOrder;
100 import jalview.datamodel.AlignmentView;
101 import jalview.datamodel.ColumnSelection;
102 import jalview.datamodel.HiddenSequences;
103 import jalview.datamodel.PDBEntry;
104 import jalview.datamodel.SeqCigar;
105 import jalview.datamodel.Sequence;
106 import jalview.datamodel.SequenceGroup;
107 import jalview.datamodel.SequenceI;
108 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
109 import jalview.io.AlignmentProperties;
110 import jalview.io.AnnotationFile;
111 import jalview.io.BioJsHTMLOutput;
112 import jalview.io.FileLoader;
113 import jalview.io.FormatAdapter;
114 import jalview.io.HtmlSvgOutput;
115 import jalview.io.IdentifyFile;
116 import jalview.io.JalviewFileChooser;
117 import jalview.io.JalviewFileView;
118 import jalview.io.JnetAnnotationMaker;
119 import jalview.io.NewickFile;
120 import jalview.io.TCoffeeScoreFile;
121 import jalview.jbgui.GAlignFrame;
122 import jalview.schemes.Blosum62ColourScheme;
123 import jalview.schemes.BuriedColourScheme;
124 import jalview.schemes.ClustalxColourScheme;
125 import jalview.schemes.ColourSchemeI;
126 import jalview.schemes.ColourSchemeProperty;
127 import jalview.schemes.HelixColourScheme;
128 import jalview.schemes.HydrophobicColourScheme;
129 import jalview.schemes.NucleotideColourScheme;
130 import jalview.schemes.PIDColourScheme;
131 import jalview.schemes.PurinePyrimidineColourScheme;
132 import jalview.schemes.RNAHelicesColourChooser;
133 import jalview.schemes.ResidueProperties;
134 import jalview.schemes.StrandColourScheme;
135 import jalview.schemes.TCoffeeColourScheme;
136 import jalview.schemes.TaylorColourScheme;
137 import jalview.schemes.TurnColourScheme;
138 import jalview.schemes.UserColourScheme;
139 import jalview.schemes.ZappoColourScheme;
140 import jalview.structure.StructureSelectionManager;
141 import jalview.util.MessageManager;
142 import jalview.viewmodel.AlignmentViewport;
143 import jalview.ws.jws1.Discoverer;
144 import jalview.ws.jws2.Jws2Discoverer;
145 import jalview.ws.jws2.jabaws2.Jws2Instance;
146 import jalview.ws.seqfetcher.DbSourceProxy;
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];
1247 FeatureRenderer fr = new FeatureRenderer(this.alignPanel);
1248 viewport.setFeatureRenderer(fr);
1249 HiddenSequences hiddenSeqs = viewport.getAlignment()
1250 .getHiddenSequences();
1253 alignmentToExport = viewport.getAlignment();
1254 alignmentStartEnd = new int[]
1255 { 0, alignmentToExport.getWidth() - 1 };
1257 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1258 AlignExportSettingI settings = new AlignExportSettings(hasHiddenSeqs,
1259 viewport.hasHiddenColumns(), exportFomat);
1260 viewport.setExportSettings(settings);
1261 settings.isExportAnnotations();
1263 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1265 omitHidden = viewport.getViewAsString(false);
1268 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1270 alignmentToExport = hiddenSeqs.getFullAlignment();
1274 alignmentToExport = viewport.getAlignment();
1275 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1276 .getColumnSelection().getHiddenColumns());
1278 return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd,
1282 private static int[] getStartEnd(int[] aligmentStartEnd,
1283 List<int[]> hiddenCols)
1285 int startPos = aligmentStartEnd[0];
1286 int endPos = aligmentStartEnd[1];
1288 int[] lowestRange = new int[2];
1289 int[] higestRange = new int[2];
1291 for (int[] hiddenCol : hiddenCols)
1293 // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
1295 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1296 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1298 // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
1299 // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
1301 if (lowestRange[0] == 0 && lowestRange[1] == 0)
1303 startPos = aligmentStartEnd[0];
1307 startPos = lowestRange[1] + 1;
1310 if (higestRange[0] == 0 && higestRange[1] == 0)
1312 endPos = aligmentStartEnd[1];
1316 endPos = higestRange[0];
1319 // System.out.println("Export range : " + minPos + " - " + maxPos);
1321 { startPos, endPos };
1324 public static void main(String[] args)
1326 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1327 hiddenCols.add(new int[]
1329 hiddenCols.add(new int[]
1331 hiddenCols.add(new int[]
1333 hiddenCols.add(new int[]
1335 hiddenCols.add(new int[]
1338 int[] x = getStartEnd(new int[]
1339 { 0, 50 }, hiddenCols);
1340 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1350 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1352 new HtmlSvgOutput(null, alignPanel);
1356 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1358 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel,
1359 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
1360 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1362 public void createImageMap(File file, String image)
1364 alignPanel.makePNGImageMap(file, image);
1374 public void createPNG(File f)
1376 alignPanel.makePNG(f);
1386 public void createEPS(File f)
1388 alignPanel.makeEPS(f);
1391 public void createSVG(File f)
1393 alignPanel.makeSVG(f);
1396 public void pageSetup_actionPerformed(ActionEvent e)
1398 PrinterJob printJob = PrinterJob.getPrinterJob();
1399 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1409 public void printMenuItem_actionPerformed(ActionEvent e)
1411 // Putting in a thread avoids Swing painting problems
1412 PrintThread thread = new PrintThread(alignPanel);
1417 public void exportFeatures_actionPerformed(ActionEvent e)
1419 new AnnotationExporter().exportFeatures(alignPanel);
1423 public void exportAnnotations_actionPerformed(ActionEvent e)
1425 new AnnotationExporter().exportAnnotations(alignPanel);
1429 public void associatedData_actionPerformed(ActionEvent e)
1431 // Pick the tree file
1432 JalviewFileChooser chooser = new JalviewFileChooser(
1433 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1434 chooser.setFileView(new JalviewFileView());
1435 chooser.setDialogTitle(MessageManager
1436 .getString("label.load_jalview_annotations"));
1437 chooser.setToolTipText(MessageManager
1438 .getString("label.load_jalview_annotations"));
1440 int value = chooser.showOpenDialog(null);
1442 if (value == JalviewFileChooser.APPROVE_OPTION)
1444 String choice = chooser.getSelectedFile().getPath();
1445 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1446 loadJalviewDataFile(choice, null, null, null);
1452 * Close the current view or all views in the alignment frame. If the frame
1453 * only contains one view then the alignment will be removed from memory.
1455 * @param closeAllTabs
1458 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1460 if (alignPanels != null && alignPanels.size() < 2)
1462 closeAllTabs = true;
1467 if (alignPanels != null)
1471 if (this.isClosed())
1473 // really close all the windows - otherwise wait till
1474 // setClosed(true) is called
1475 for (int i = 0; i < alignPanels.size(); i++)
1477 AlignmentPanel ap = alignPanels.get(i);
1484 closeView(alignPanel);
1490 this.setClosed(true);
1492 } catch (Exception ex)
1494 ex.printStackTrace();
1499 * Close the specified panel and close up tabs appropriately.
1501 * @param panelToClose
1503 public void closeView(AlignmentPanel panelToClose)
1505 int index = tabbedPane.getSelectedIndex();
1506 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1507 alignPanels.remove(panelToClose);
1508 panelToClose.closePanel();
1509 panelToClose = null;
1511 tabbedPane.removeTabAt(closedindex);
1512 tabbedPane.validate();
1514 if (index > closedindex || index == tabbedPane.getTabCount())
1516 // modify currently selected tab index if necessary.
1520 this.tabSelectionChanged(index);
1526 void updateEditMenuBar()
1529 if (viewport.getHistoryList().size() > 0)
1531 undoMenuItem.setEnabled(true);
1532 CommandI command = viewport.getHistoryList().peek();
1533 undoMenuItem.setText(MessageManager.formatMessage(
1534 "label.undo_command", new Object[]
1535 { command.getDescription() }));
1539 undoMenuItem.setEnabled(false);
1540 undoMenuItem.setText(MessageManager.getString("action.undo"));
1543 if (viewport.getRedoList().size() > 0)
1545 redoMenuItem.setEnabled(true);
1547 CommandI command = viewport.getRedoList().peek();
1548 redoMenuItem.setText(MessageManager.formatMessage(
1549 "label.redo_command", new Object[]
1550 { command.getDescription() }));
1554 redoMenuItem.setEnabled(false);
1555 redoMenuItem.setText(MessageManager.getString("action.redo"));
1559 public void addHistoryItem(CommandI command)
1561 if (command.getSize() > 0)
1563 viewport.addToHistoryList(command);
1564 viewport.clearRedoList();
1565 updateEditMenuBar();
1566 viewport.updateHiddenColumns();
1567 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1568 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1569 // viewport.getColumnSelection()
1570 // .getHiddenColumns().size() > 0);
1576 * @return alignment objects for all views
1578 AlignmentI[] getViewAlignments()
1580 if (alignPanels != null)
1582 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1584 for (AlignmentPanel ap : alignPanels)
1586 als[i++] = ap.av.getAlignment();
1590 if (viewport != null)
1592 return new AlignmentI[]
1593 { viewport.getAlignment() };
1605 protected void undoMenuItem_actionPerformed(ActionEvent e)
1607 if (viewport.getHistoryList().isEmpty())
1611 CommandI command = viewport.getHistoryList().pop();
1612 viewport.addToRedoList(command);
1613 command.undoCommand(getViewAlignments());
1615 AlignmentViewport originalSource = getOriginatingSource(command);
1616 updateEditMenuBar();
1618 if (originalSource != null)
1620 if (originalSource != viewport)
1623 .warn("Implementation worry: mismatch of viewport origin for undo");
1625 originalSource.updateHiddenColumns();
1626 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1628 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1629 // viewport.getColumnSelection()
1630 // .getHiddenColumns().size() > 0);
1631 originalSource.firePropertyChange("alignment", null, originalSource
1632 .getAlignment().getSequences());
1643 protected void redoMenuItem_actionPerformed(ActionEvent e)
1645 if (viewport.getRedoList().size() < 1)
1650 CommandI command = viewport.getRedoList().pop();
1651 viewport.addToHistoryList(command);
1652 command.doCommand(getViewAlignments());
1654 AlignmentViewport originalSource = getOriginatingSource(command);
1655 updateEditMenuBar();
1657 if (originalSource != null)
1660 if (originalSource != viewport)
1663 .warn("Implementation worry: mismatch of viewport origin for redo");
1665 originalSource.updateHiddenColumns();
1666 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1668 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1669 // viewport.getColumnSelection()
1670 // .getHiddenColumns().size() > 0);
1671 originalSource.firePropertyChange("alignment", null, originalSource
1672 .getAlignment().getSequences());
1676 AlignmentViewport getOriginatingSource(CommandI command)
1678 AlignmentViewport originalSource = null;
1679 // For sequence removal and addition, we need to fire
1680 // the property change event FROM the viewport where the
1681 // original alignment was altered
1682 AlignmentI al = null;
1683 if (command instanceof EditCommand)
1685 EditCommand editCommand = (EditCommand) command;
1686 al = editCommand.getAlignment();
1687 List<Component> comps = PaintRefresher.components.get(viewport
1688 .getSequenceSetId());
1690 for (Component comp : comps)
1692 if (comp instanceof AlignmentPanel)
1694 if (al == ((AlignmentPanel) comp).av.getAlignment())
1696 originalSource = ((AlignmentPanel) comp).av;
1703 if (originalSource == null)
1705 // The original view is closed, we must validate
1706 // the current view against the closed view first
1709 PaintRefresher.validateSequences(al, viewport.getAlignment());
1712 originalSource = viewport;
1715 return originalSource;
1724 public void moveSelectedSequences(boolean up)
1726 SequenceGroup sg = viewport.getSelectionGroup();
1732 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1733 viewport.getHiddenRepSequences(), up);
1734 alignPanel.paintAlignment(true);
1737 synchronized void slideSequences(boolean right, int size)
1739 List<SequenceI> sg = new ArrayList<SequenceI>();
1740 if (viewport.cursorMode)
1742 sg.add(viewport.getAlignment().getSequenceAt(
1743 alignPanel.getSeqPanel().seqCanvas.cursorY));
1745 else if (viewport.getSelectionGroup() != null
1746 && viewport.getSelectionGroup().getSize() != viewport
1747 .getAlignment().getHeight())
1749 sg = viewport.getSelectionGroup().getSequences(
1750 viewport.getHiddenRepSequences());
1758 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1760 for (SequenceI seq : viewport.getAlignment().getSequences())
1762 if (!sg.contains(seq))
1764 invertGroup.add(seq);
1768 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1770 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1771 for (int i = 0; i < invertGroup.size(); i++)
1773 seqs2[i] = invertGroup.get(i);
1776 SlideSequencesCommand ssc;
1779 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1780 size, viewport.getGapCharacter());
1784 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1785 size, viewport.getGapCharacter());
1788 int groupAdjustment = 0;
1789 if (ssc.getGapsInsertedBegin() && right)
1791 if (viewport.cursorMode)
1793 alignPanel.getSeqPanel().moveCursor(size, 0);
1797 groupAdjustment = size;
1800 else if (!ssc.getGapsInsertedBegin() && !right)
1802 if (viewport.cursorMode)
1804 alignPanel.getSeqPanel().moveCursor(-size, 0);
1808 groupAdjustment = -size;
1812 if (groupAdjustment != 0)
1814 viewport.getSelectionGroup().setStartRes(
1815 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1816 viewport.getSelectionGroup().setEndRes(
1817 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1820 boolean appendHistoryItem = false;
1821 Deque<CommandI> historyList = viewport.getHistoryList();
1822 if (historyList != null
1823 && historyList.size() > 0
1824 && historyList.peek() instanceof SlideSequencesCommand)
1826 appendHistoryItem = ssc
1827 .appendSlideCommand((SlideSequencesCommand) historyList
1831 if (!appendHistoryItem)
1833 addHistoryItem(ssc);
1846 protected void copy_actionPerformed(ActionEvent e)
1849 if (viewport.getSelectionGroup() == null)
1853 // TODO: preserve the ordering of displayed alignment annotation in any
1854 // internal paste (particularly sequence associated annotation)
1855 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1856 String[] omitHidden = null;
1858 if (viewport.hasHiddenColumns())
1860 omitHidden = viewport.getViewAsString(true);
1863 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1866 StringSelection ss = new StringSelection(output);
1870 jalview.gui.Desktop.internalCopy = true;
1871 // Its really worth setting the clipboard contents
1872 // to empty before setting the large StringSelection!!
1873 Toolkit.getDefaultToolkit().getSystemClipboard()
1874 .setContents(new StringSelection(""), null);
1876 Toolkit.getDefaultToolkit().getSystemClipboard()
1877 .setContents(ss, Desktop.instance);
1878 } catch (OutOfMemoryError er)
1880 new OOMWarning("copying region", er);
1884 ArrayList<int[]> hiddenColumns = null;
1885 if (viewport.hasHiddenColumns())
1887 hiddenColumns = new ArrayList<int[]>();
1888 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1889 .getSelectionGroup().getEndRes();
1890 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1892 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1894 hiddenColumns.add(new int[]
1895 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1900 Desktop.jalviewClipboard = new Object[]
1901 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1902 statusBar.setText(MessageManager.formatMessage(
1903 "label.copied_sequences_to_clipboard", new Object[]
1904 { Integer.valueOf(seqs.length).toString() }));
1914 protected void pasteNew_actionPerformed(ActionEvent e)
1926 protected void pasteThis_actionPerformed(ActionEvent e)
1932 * Paste contents of Jalview clipboard
1934 * @param newAlignment
1935 * true to paste to a new alignment, otherwise add to this.
1937 void paste(boolean newAlignment)
1939 boolean externalPaste = true;
1942 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1943 Transferable contents = c.getContents(this);
1945 if (contents == null)
1953 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1954 if (str.length() < 1)
1959 format = new IdentifyFile().Identify(str, "Paste");
1961 } catch (OutOfMemoryError er)
1963 new OOMWarning("Out of memory pasting sequences!!", er);
1967 SequenceI[] sequences;
1968 boolean annotationAdded = false;
1969 AlignmentI alignment = null;
1971 if (Desktop.jalviewClipboard != null)
1973 // The clipboard was filled from within Jalview, we must use the
1975 // And dataset from the copied alignment
1976 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1977 // be doubly sure that we create *new* sequence objects.
1978 sequences = new SequenceI[newseq.length];
1979 for (int i = 0; i < newseq.length; i++)
1981 sequences[i] = new Sequence(newseq[i]);
1983 alignment = new Alignment(sequences);
1984 externalPaste = false;
1988 // parse the clipboard as an alignment.
1989 alignment = new FormatAdapter().readFile(str, "Paste", format);
1990 sequences = alignment.getSequencesArray();
1994 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2000 if (Desktop.jalviewClipboard != null)
2002 // dataset is inherited
2003 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2007 // new dataset is constructed
2008 alignment.setDataset(null);
2010 alwidth = alignment.getWidth() + 1;
2014 AlignmentI pastedal = alignment; // preserve pasted alignment object
2015 // Add pasted sequences and dataset into existing alignment.
2016 alignment = viewport.getAlignment();
2017 alwidth = alignment.getWidth() + 1;
2018 // decide if we need to import sequences from an existing dataset
2019 boolean importDs = Desktop.jalviewClipboard != null
2020 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2021 // importDs==true instructs us to copy over new dataset sequences from
2022 // an existing alignment
2023 Vector newDs = (importDs) ? new Vector() : null; // used to create
2024 // minimum dataset set
2026 for (int i = 0; i < sequences.length; i++)
2030 newDs.addElement(null);
2032 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2034 if (importDs && ds != null)
2036 if (!newDs.contains(ds))
2038 newDs.setElementAt(ds, i);
2039 ds = new Sequence(ds);
2040 // update with new dataset sequence
2041 sequences[i].setDatasetSequence(ds);
2045 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2050 // copy and derive new dataset sequence
2051 sequences[i] = sequences[i].deriveSequence();
2052 alignment.getDataset().addSequence(
2053 sequences[i].getDatasetSequence());
2054 // TODO: avoid creation of duplicate dataset sequences with a
2055 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2057 alignment.addSequence(sequences[i]); // merges dataset
2061 newDs.clear(); // tidy up
2063 if (alignment.getAlignmentAnnotation() != null)
2065 for (AlignmentAnnotation alan : alignment
2066 .getAlignmentAnnotation())
2068 if (alan.graphGroup > fgroup)
2070 fgroup = alan.graphGroup;
2074 if (pastedal.getAlignmentAnnotation() != null)
2076 // Add any annotation attached to alignment.
2077 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2078 for (int i = 0; i < alann.length; i++)
2080 annotationAdded = true;
2081 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2083 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2084 if (newann.graphGroup > -1)
2086 if (newGraphGroups.size() <= newann.graphGroup
2087 || newGraphGroups.get(newann.graphGroup) == null)
2089 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2091 newGraphGroups.add(q, null);
2093 newGraphGroups.set(newann.graphGroup, new Integer(
2096 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2100 newann.padAnnotation(alwidth);
2101 alignment.addAnnotation(newann);
2111 addHistoryItem(new EditCommand(
2112 MessageManager.getString("label.add_sequences"),
2114 sequences, 0, alignment.getWidth(), alignment));
2116 // Add any annotations attached to sequences
2117 for (int i = 0; i < sequences.length; i++)
2119 if (sequences[i].getAnnotation() != null)
2121 AlignmentAnnotation newann;
2122 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2124 annotationAdded = true;
2125 newann = sequences[i].getAnnotation()[a];
2126 newann.adjustForAlignment();
2127 newann.padAnnotation(alwidth);
2128 if (newann.graphGroup > -1)
2130 if (newann.graphGroup > -1)
2132 if (newGraphGroups.size() <= newann.graphGroup
2133 || newGraphGroups.get(newann.graphGroup) == null)
2135 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2137 newGraphGroups.add(q, null);
2139 newGraphGroups.set(newann.graphGroup, new Integer(
2142 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2146 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2151 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2158 // propagate alignment changed.
2159 viewport.setEndSeq(alignment.getHeight());
2160 if (annotationAdded)
2162 // Duplicate sequence annotation in all views.
2163 AlignmentI[] alview = this.getViewAlignments();
2164 for (int i = 0; i < sequences.length; i++)
2166 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2171 for (int avnum = 0; avnum < alview.length; avnum++)
2173 if (alview[avnum] != alignment)
2175 // duplicate in a view other than the one with input focus
2176 int avwidth = alview[avnum].getWidth() + 1;
2177 // this relies on sann being preserved after we
2178 // modify the sequence's annotation array for each duplication
2179 for (int a = 0; a < sann.length; a++)
2181 AlignmentAnnotation newann = new AlignmentAnnotation(
2183 sequences[i].addAlignmentAnnotation(newann);
2184 newann.padAnnotation(avwidth);
2185 alview[avnum].addAnnotation(newann); // annotation was
2186 // duplicated earlier
2187 // TODO JAL-1145 graphGroups are not updated for sequence
2188 // annotation added to several views. This may cause
2190 alview[avnum].setAnnotationIndex(newann, a);
2195 buildSortByAnnotationScoresMenu();
2197 viewport.firePropertyChange("alignment", null,
2198 alignment.getSequences());
2199 if (alignPanels != null)
2201 for (AlignmentPanel ap : alignPanels)
2203 ap.validateAnnotationDimensions(false);
2208 alignPanel.validateAnnotationDimensions(false);
2214 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2216 String newtitle = new String("Copied sequences");
2218 if (Desktop.jalviewClipboard != null
2219 && Desktop.jalviewClipboard[2] != null)
2221 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2222 for (int[] region : hc)
2224 af.viewport.hideColumns(region[0], region[1]);
2228 // >>>This is a fix for the moment, until a better solution is
2230 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2232 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2234 // TODO: maintain provenance of an alignment, rather than just make the
2235 // title a concatenation of operations.
2238 if (title.startsWith("Copied sequences"))
2244 newtitle = newtitle.concat("- from " + title);
2249 newtitle = new String("Pasted sequences");
2252 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2257 } catch (Exception ex)
2259 ex.printStackTrace();
2260 System.out.println("Exception whilst pasting: " + ex);
2261 // could be anything being pasted in here
2267 protected void expand_newalign(ActionEvent e)
2271 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2272 .getAlignment(), -1);
2273 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2275 String newtitle = new String("Flanking alignment");
2277 if (Desktop.jalviewClipboard != null
2278 && Desktop.jalviewClipboard[2] != null)
2280 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2281 for (int region[] : hc)
2283 af.viewport.hideColumns(region[0], region[1]);
2287 // >>>This is a fix for the moment, until a better solution is
2289 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2291 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2293 // TODO: maintain provenance of an alignment, rather than just make the
2294 // title a concatenation of operations.
2296 if (title.startsWith("Copied sequences"))
2302 newtitle = newtitle.concat("- from " + title);
2306 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2308 } catch (Exception ex)
2310 ex.printStackTrace();
2311 System.out.println("Exception whilst pasting: " + ex);
2312 // could be anything being pasted in here
2313 } catch (OutOfMemoryError oom)
2315 new OOMWarning("Viewing flanking region of alignment", oom);
2326 protected void cut_actionPerformed(ActionEvent e)
2328 copy_actionPerformed(null);
2329 delete_actionPerformed(null);
2339 protected void delete_actionPerformed(ActionEvent evt)
2342 SequenceGroup sg = viewport.getSelectionGroup();
2349 * If the cut affects all sequences, warn, remove highlighted columns
2351 if (sg.getSize() == viewport.getAlignment().getHeight())
2353 int confirm = JOptionPane.showConfirmDialog(this,
2354 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2355 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2356 JOptionPane.OK_CANCEL_OPTION);
2358 if (confirm == JOptionPane.CANCEL_OPTION
2359 || confirm == JOptionPane.CLOSED_OPTION)
2363 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2364 sg.getEndRes() + 1);
2367 SequenceI[] cut = sg.getSequences()
2368 .toArray(new SequenceI[sg.getSize()]);
2370 addHistoryItem(new EditCommand(
2371 MessageManager.getString("label.cut_sequences"), Action.CUT,
2372 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2373 viewport.getAlignment()));
2375 viewport.setSelectionGroup(null);
2376 viewport.sendSelection();
2377 viewport.getAlignment().deleteGroup(sg);
2379 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2381 if (viewport.getAlignment().getHeight() < 1)
2385 this.setClosed(true);
2386 } catch (Exception ex)
2399 protected void deleteGroups_actionPerformed(ActionEvent e)
2401 if (avc.deleteGroups())
2403 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2404 alignPanel.updateAnnotation();
2405 alignPanel.paintAlignment(true);
2416 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2418 SequenceGroup sg = new SequenceGroup();
2420 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2422 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2425 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2426 viewport.setSelectionGroup(sg);
2427 viewport.sendSelection();
2428 alignPanel.paintAlignment(true);
2429 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2439 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2441 if (viewport.cursorMode)
2443 alignPanel.getSeqPanel().keyboardNo1 = null;
2444 alignPanel.getSeqPanel().keyboardNo2 = null;
2446 viewport.setSelectionGroup(null);
2447 viewport.getColumnSelection().clear();
2448 viewport.setSelectionGroup(null);
2449 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2450 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2451 alignPanel.paintAlignment(true);
2452 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2453 viewport.sendSelection();
2463 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2465 SequenceGroup sg = viewport.getSelectionGroup();
2469 selectAllSequenceMenuItem_actionPerformed(null);
2474 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2476 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2479 alignPanel.paintAlignment(true);
2480 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2481 viewport.sendSelection();
2485 public void invertColSel_actionPerformed(ActionEvent e)
2487 viewport.invertColumnSelection();
2488 alignPanel.paintAlignment(true);
2489 viewport.sendSelection();
2499 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2501 trimAlignment(true);
2511 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2513 trimAlignment(false);
2516 void trimAlignment(boolean trimLeft)
2518 ColumnSelection colSel = viewport.getColumnSelection();
2521 if (colSel.size() > 0)
2525 column = colSel.getMin();
2529 column = colSel.getMax();
2533 if (viewport.getSelectionGroup() != null)
2535 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2536 viewport.getHiddenRepSequences());
2540 seqs = viewport.getAlignment().getSequencesArray();
2543 TrimRegionCommand trimRegion;
2546 trimRegion = new TrimRegionCommand("Remove Left",
2547 TrimRegionCommand.TRIM_LEFT, seqs, column,
2548 viewport.getAlignment(), viewport.getColumnSelection(),
2549 viewport.getSelectionGroup());
2550 viewport.setStartRes(0);
2554 trimRegion = new TrimRegionCommand("Remove Right",
2555 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2556 viewport.getAlignment(), viewport.getColumnSelection(),
2557 viewport.getSelectionGroup());
2560 statusBar.setText(MessageManager.formatMessage(
2561 "label.removed_columns", new String[]
2562 { Integer.valueOf(trimRegion.getSize()).toString() }));
2564 addHistoryItem(trimRegion);
2566 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2568 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2569 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2571 viewport.getAlignment().deleteGroup(sg);
2575 viewport.firePropertyChange("alignment", null, viewport
2576 .getAlignment().getSequences());
2587 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2589 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2592 if (viewport.getSelectionGroup() != null)
2594 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2595 viewport.getHiddenRepSequences());
2596 start = viewport.getSelectionGroup().getStartRes();
2597 end = viewport.getSelectionGroup().getEndRes();
2601 seqs = viewport.getAlignment().getSequencesArray();
2604 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2605 "Remove Gapped Columns", seqs, start, end,
2606 viewport.getAlignment());
2608 addHistoryItem(removeGapCols);
2610 statusBar.setText(MessageManager.formatMessage(
2611 "label.removed_empty_columns", new Object[]
2612 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2614 // This is to maintain viewport position on first residue
2615 // of first sequence
2616 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2617 int startRes = seq.findPosition(viewport.startRes);
2618 // ShiftList shifts;
2619 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2620 // edit.alColumnChanges=shifts.getInverse();
2621 // if (viewport.hasHiddenColumns)
2622 // viewport.getColumnSelection().compensateForEdits(shifts);
2623 viewport.setStartRes(seq.findIndex(startRes) - 1);
2624 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2636 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2638 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2641 if (viewport.getSelectionGroup() != null)
2643 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2644 viewport.getHiddenRepSequences());
2645 start = viewport.getSelectionGroup().getStartRes();
2646 end = viewport.getSelectionGroup().getEndRes();
2650 seqs = viewport.getAlignment().getSequencesArray();
2653 // This is to maintain viewport position on first residue
2654 // of first sequence
2655 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2656 int startRes = seq.findPosition(viewport.startRes);
2658 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2659 viewport.getAlignment()));
2661 viewport.setStartRes(seq.findIndex(startRes) - 1);
2663 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2675 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2677 viewport.setPadGaps(padGapsMenuitem.isSelected());
2678 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2689 public void findMenuItem_actionPerformed(ActionEvent e)
2695 * Create a new view of the current alignment.
2698 public void newView_actionPerformed(ActionEvent e)
2700 newView(null, true);
2704 * Creates and shows a new view of the current alignment.
2707 * title of newly created view; if null, one will be generated
2708 * @param copyAnnotation
2709 * if true then duplicate all annnotation, groups and settings
2710 * @return new alignment panel, already displayed.
2712 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2715 * Create a new AlignmentPanel (with its own, new Viewport)
2717 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2719 if (!copyAnnotation)
2722 * remove all groups and annotation except for the automatic stuff
2724 newap.av.getAlignment().deleteAllGroups();
2725 newap.av.getAlignment().deleteAllAnnotations(false);
2728 newap.av.setGatherViewsHere(false);
2730 if (viewport.viewName == null)
2732 viewport.viewName = MessageManager
2733 .getString("label.view_name_original");
2737 * Views share the same edits, undo and redo stacks, mappings.
2739 newap.av.setHistoryList(viewport.getHistoryList());
2740 newap.av.setRedoList(viewport.getRedoList());
2741 newap.av.getAlignment().setCodonFrames(
2742 viewport.getAlignment().getCodonFrames());
2744 newap.av.viewName = getNewViewName(viewTitle);
2746 addAlignmentPanel(newap, true);
2747 newap.alignmentChanged();
2749 if (alignPanels.size() == 2)
2751 viewport.setGatherViewsHere(true);
2753 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2758 * Make a new name for the view, ensuring it is unique within the current
2759 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2760 * these now use viewId. Unique view names are still desirable for usability.)
2765 protected String getNewViewName(String viewTitle)
2767 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2768 boolean addFirstIndex = false;
2769 if (viewTitle == null || viewTitle.trim().length() == 0)
2771 viewTitle = MessageManager.getString("action.view");
2772 addFirstIndex = true;
2776 index = 1;// we count from 1 if given a specific name
2778 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2780 List<Component> comps = PaintRefresher.components.get(viewport
2781 .getSequenceSetId());
2783 List<String> existingNames = getExistingViewNames(comps);
2785 while (existingNames.contains(newViewName))
2787 newViewName = viewTitle + " " + (++index);
2793 * Returns a list of distinct view names found in the given list of
2794 * components. View names are held on the viewport of an AlignmentPanel.
2799 protected List<String> getExistingViewNames(List<Component> comps)
2801 List<String> existingNames = new ArrayList<String>();
2802 for (Component comp : comps)
2804 if (comp instanceof AlignmentPanel)
2806 AlignmentPanel ap = (AlignmentPanel) comp;
2807 if (!existingNames.contains(ap.av.viewName))
2809 existingNames.add(ap.av.viewName);
2813 return existingNames;
2817 * Explode tabbed views into separate windows.
2820 public void expandViews_actionPerformed(ActionEvent e)
2822 Desktop.instance.explodeViews(this);
2826 * Gather views in separate windows back into a tabbed presentation.
2829 public void gatherViews_actionPerformed(ActionEvent e)
2831 Desktop.instance.gatherViews(this);
2841 public void font_actionPerformed(ActionEvent e)
2843 new FontChooser(alignPanel);
2853 protected void seqLimit_actionPerformed(ActionEvent e)
2855 viewport.setShowJVSuffix(seqLimits.isSelected());
2857 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2858 .calculateIdWidth());
2859 alignPanel.paintAlignment(true);
2863 public void idRightAlign_actionPerformed(ActionEvent e)
2865 viewport.setRightAlignIds(idRightAlign.isSelected());
2866 alignPanel.paintAlignment(true);
2870 public void centreColumnLabels_actionPerformed(ActionEvent e)
2872 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2873 alignPanel.paintAlignment(true);
2879 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2882 protected void followHighlight_actionPerformed()
2885 * Set the 'follow' flag on the Viewport (and scroll to position if now
2888 final boolean state = this.followHighlightMenuItem.getState();
2889 viewport.setFollowHighlight(state);
2892 alignPanel.scrollToPosition(
2893 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2904 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2906 viewport.setColourText(colourTextMenuItem.isSelected());
2907 alignPanel.paintAlignment(true);
2917 public void wrapMenuItem_actionPerformed(ActionEvent e)
2919 scaleAbove.setVisible(wrapMenuItem.isSelected());
2920 scaleLeft.setVisible(wrapMenuItem.isSelected());
2921 scaleRight.setVisible(wrapMenuItem.isSelected());
2922 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2923 alignPanel.updateLayout();
2927 public void showAllSeqs_actionPerformed(ActionEvent e)
2929 viewport.showAllHiddenSeqs();
2933 public void showAllColumns_actionPerformed(ActionEvent e)
2935 viewport.showAllHiddenColumns();
2940 public void hideSelSequences_actionPerformed(ActionEvent e)
2942 viewport.hideAllSelectedSeqs();
2943 // alignPanel.paintAlignment(true);
2947 * called by key handler and the hide all/show all menu items
2952 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2955 boolean hide = false;
2956 SequenceGroup sg = viewport.getSelectionGroup();
2957 if (!toggleSeqs && !toggleCols)
2959 // Hide everything by the current selection - this is a hack - we do the
2960 // invert and then hide
2961 // first check that there will be visible columns after the invert.
2962 if ((viewport.getColumnSelection() != null
2963 && viewport.getColumnSelection().getSelected() != null && viewport
2964 .getColumnSelection().getSelected().size() > 0)
2965 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2968 // now invert the sequence set, if required - empty selection implies
2969 // that no hiding is required.
2972 invertSequenceMenuItem_actionPerformed(null);
2973 sg = viewport.getSelectionGroup();
2977 viewport.expandColSelection(sg, true);
2978 // finally invert the column selection and get the new sequence
2980 invertColSel_actionPerformed(null);
2987 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2989 hideSelSequences_actionPerformed(null);
2992 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2995 showAllSeqs_actionPerformed(null);
3001 if (viewport.getColumnSelection().getSelected().size() > 0)
3003 hideSelColumns_actionPerformed(null);
3006 viewport.setSelectionGroup(sg);
3011 showAllColumns_actionPerformed(null);
3020 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3021 * event.ActionEvent)
3024 public void hideAllButSelection_actionPerformed(ActionEvent e)
3026 toggleHiddenRegions(false, false);
3033 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3037 public void hideAllSelection_actionPerformed(ActionEvent e)
3039 SequenceGroup sg = viewport.getSelectionGroup();
3040 viewport.expandColSelection(sg, false);
3041 viewport.hideAllSelectedSeqs();
3042 viewport.hideSelectedColumns();
3043 alignPanel.paintAlignment(true);
3050 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3054 public void showAllhidden_actionPerformed(ActionEvent e)
3056 viewport.showAllHiddenColumns();
3057 viewport.showAllHiddenSeqs();
3058 alignPanel.paintAlignment(true);
3062 public void hideSelColumns_actionPerformed(ActionEvent e)
3064 viewport.hideSelectedColumns();
3065 alignPanel.paintAlignment(true);
3069 public void hiddenMarkers_actionPerformed(ActionEvent e)
3071 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3082 protected void scaleAbove_actionPerformed(ActionEvent e)
3084 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3085 alignPanel.paintAlignment(true);
3095 protected void scaleLeft_actionPerformed(ActionEvent e)
3097 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3098 alignPanel.paintAlignment(true);
3108 protected void scaleRight_actionPerformed(ActionEvent e)
3110 viewport.setScaleRightWrapped(scaleRight.isSelected());
3111 alignPanel.paintAlignment(true);
3121 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3123 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3124 alignPanel.paintAlignment(true);
3134 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3136 viewport.setShowText(viewTextMenuItem.isSelected());
3137 alignPanel.paintAlignment(true);
3147 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3149 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3150 alignPanel.paintAlignment(true);
3153 public FeatureSettings featureSettings;
3156 public FeatureSettingsControllerI getFeatureSettingsUI()
3158 return featureSettings;
3162 public void featureSettings_actionPerformed(ActionEvent e)
3164 if (featureSettings != null)
3166 featureSettings.close();
3167 featureSettings = null;
3169 if (!showSeqFeatures.isSelected())
3171 // make sure features are actually displayed
3172 showSeqFeatures.setSelected(true);
3173 showSeqFeatures_actionPerformed(null);
3175 featureSettings = new FeatureSettings(this);
3179 * Set or clear 'Show Sequence Features'
3185 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3187 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3188 alignPanel.paintAlignment(true);
3189 if (alignPanel.getOverviewPanel() != null)
3191 alignPanel.getOverviewPanel().updateOverviewImage();
3196 * Set or clear 'Show Sequence Features'
3202 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3204 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3206 if (viewport.isShowSequenceFeaturesHeight())
3208 // ensure we're actually displaying features
3209 viewport.setShowSequenceFeatures(true);
3210 showSeqFeatures.setSelected(true);
3212 alignPanel.paintAlignment(true);
3213 if (alignPanel.getOverviewPanel() != null)
3215 alignPanel.getOverviewPanel().updateOverviewImage();
3220 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3221 * the annotations panel as a whole.
3223 * The options to show/hide all annotations should be enabled when the panel
3224 * is shown, and disabled when the panel is hidden.
3229 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3231 final boolean setVisible = annotationPanelMenuItem.isSelected();
3232 viewport.setShowAnnotation(setVisible);
3233 this.showAllSeqAnnotations.setEnabled(setVisible);
3234 this.hideAllSeqAnnotations.setEnabled(setVisible);
3235 this.showAllAlAnnotations.setEnabled(setVisible);
3236 this.hideAllAlAnnotations.setEnabled(setVisible);
3237 alignPanel.updateLayout();
3241 public void alignmentProperties()
3243 JEditorPane editPane = new JEditorPane("text/html", "");
3244 editPane.setEditable(false);
3245 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3247 editPane.setText(MessageManager.formatMessage("label.html_content",
3249 { contents.toString() }));
3250 JInternalFrame frame = new JInternalFrame();
3251 frame.getContentPane().add(new JScrollPane(editPane));
3253 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3254 "label.alignment_properties", new Object[]
3255 { getTitle() }), 500, 400);
3265 public void overviewMenuItem_actionPerformed(ActionEvent e)
3267 if (alignPanel.overviewPanel != null)
3272 JInternalFrame frame = new JInternalFrame();
3273 OverviewPanel overview = new OverviewPanel(alignPanel);
3274 frame.setContentPane(overview);
3275 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3276 "label.overview_params", new Object[]
3277 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3279 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3280 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3283 public void internalFrameClosed(
3284 javax.swing.event.InternalFrameEvent evt)
3286 alignPanel.setOverviewPanel(null);
3290 alignPanel.setOverviewPanel(overview);
3294 public void textColour_actionPerformed(ActionEvent e)
3296 new TextColourChooser().chooseColour(alignPanel, null);
3306 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3318 public void clustalColour_actionPerformed(ActionEvent e)
3320 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3321 viewport.getHiddenRepSequences()));
3331 public void zappoColour_actionPerformed(ActionEvent e)
3333 changeColour(new ZappoColourScheme());
3343 public void taylorColour_actionPerformed(ActionEvent e)
3345 changeColour(new TaylorColourScheme());
3355 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3357 changeColour(new HydrophobicColourScheme());
3367 public void helixColour_actionPerformed(ActionEvent e)
3369 changeColour(new HelixColourScheme());
3379 public void strandColour_actionPerformed(ActionEvent e)
3381 changeColour(new StrandColourScheme());
3391 public void turnColour_actionPerformed(ActionEvent e)
3393 changeColour(new TurnColourScheme());
3403 public void buriedColour_actionPerformed(ActionEvent e)
3405 changeColour(new BuriedColourScheme());
3415 public void nucleotideColour_actionPerformed(ActionEvent e)
3417 changeColour(new NucleotideColourScheme());
3421 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3423 changeColour(new PurinePyrimidineColourScheme());
3427 * public void covariationColour_actionPerformed(ActionEvent e) {
3429 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3433 public void annotationColour_actionPerformed(ActionEvent e)
3435 new AnnotationColourChooser(viewport, alignPanel);
3439 public void annotationColumn_actionPerformed(ActionEvent e)
3441 new AnnotationColumnChooser(viewport, alignPanel);
3445 public void rnahelicesColour_actionPerformed(ActionEvent e)
3447 new RNAHelicesColourChooser(viewport, alignPanel);
3457 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3459 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3468 public void changeColour(ColourSchemeI cs)
3470 // TODO: compare with applet and pull up to model method
3475 if (viewport.getAbovePIDThreshold())
3477 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3479 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3483 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3486 if (viewport.getConservationSelected())
3489 Alignment al = (Alignment) viewport.getAlignment();
3490 Conservation c = new Conservation("All",
3491 ResidueProperties.propHash, 3, al.getSequences(), 0,
3495 c.verdict(false, viewport.getConsPercGaps());
3497 cs.setConservation(c);
3499 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3504 cs.setConservation(null);
3507 cs.setConsensus(viewport.getSequenceConsensusHash());
3510 viewport.setGlobalColourScheme(cs);
3512 if (viewport.getColourAppliesToAllGroups())
3515 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3523 if (cs instanceof ClustalxColourScheme)
3525 sg.cs = new ClustalxColourScheme(sg,
3526 viewport.getHiddenRepSequences());
3528 else if (cs instanceof UserColourScheme)
3530 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3536 sg.cs = cs.getClass().newInstance();
3537 } catch (Exception ex)
3542 if (viewport.getAbovePIDThreshold()
3543 || cs instanceof PIDColourScheme
3544 || cs instanceof Blosum62ColourScheme)
3546 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3548 sg.cs.setConsensus(AAFrequency.calculate(
3549 sg.getSequences(viewport.getHiddenRepSequences()),
3550 sg.getStartRes(), sg.getEndRes() + 1));
3554 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3557 if (viewport.getConservationSelected())
3559 Conservation c = new Conservation("Group",
3560 ResidueProperties.propHash, 3, sg.getSequences(viewport
3561 .getHiddenRepSequences()), sg.getStartRes(),
3562 sg.getEndRes() + 1);
3564 c.verdict(false, viewport.getConsPercGaps());
3565 sg.cs.setConservation(c);
3569 sg.cs.setConservation(null);
3574 if (alignPanel.getOverviewPanel() != null)
3576 alignPanel.getOverviewPanel().updateOverviewImage();
3579 alignPanel.paintAlignment(true);
3589 protected void modifyPID_actionPerformed(ActionEvent e)
3591 if (viewport.getAbovePIDThreshold()
3592 && viewport.getGlobalColourScheme() != null)
3594 SliderPanel.setPIDSliderSource(alignPanel,
3595 viewport.getGlobalColourScheme(), "Background");
3596 SliderPanel.showPIDSlider();
3607 protected void modifyConservation_actionPerformed(ActionEvent e)
3609 if (viewport.getConservationSelected()
3610 && viewport.getGlobalColourScheme() != null)
3612 SliderPanel.setConservationSlider(alignPanel,
3613 viewport.getGlobalColourScheme(), "Background");
3614 SliderPanel.showConservationSlider();
3625 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3627 viewport.setConservationSelected(conservationMenuItem.isSelected());
3629 viewport.setAbovePIDThreshold(false);
3630 abovePIDThreshold.setSelected(false);
3632 changeColour(viewport.getGlobalColourScheme());
3634 modifyConservation_actionPerformed(null);
3644 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3646 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3648 conservationMenuItem.setSelected(false);
3649 viewport.setConservationSelected(false);
3651 changeColour(viewport.getGlobalColourScheme());
3653 modifyPID_actionPerformed(null);
3663 public void userDefinedColour_actionPerformed(ActionEvent e)
3665 if (e.getActionCommand().equals(
3666 MessageManager.getString("action.user_defined")))
3668 new UserDefinedColours(alignPanel, null);
3672 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3673 .getUserColourSchemes().get(e.getActionCommand());
3679 public void updateUserColourMenu()
3682 Component[] menuItems = colourMenu.getMenuComponents();
3683 int iSize = menuItems.length;
3684 for (int i = 0; i < iSize; i++)
3686 if (menuItems[i].getName() != null
3687 && menuItems[i].getName().equals("USER_DEFINED"))
3689 colourMenu.remove(menuItems[i]);
3693 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3695 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3696 .getUserColourSchemes().keys();
3698 while (userColours.hasMoreElements())
3700 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3701 userColours.nextElement().toString());
3702 radioItem.setName("USER_DEFINED");
3703 radioItem.addMouseListener(new MouseAdapter()
3706 public void mousePressed(MouseEvent evt)
3708 if (evt.isControlDown()
3709 || SwingUtilities.isRightMouseButton(evt))
3711 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3713 int option = JOptionPane.showInternalConfirmDialog(
3714 jalview.gui.Desktop.desktop,
3716 .getString("label.remove_from_default_list"),
3718 .getString("label.remove_user_defined_colour"),
3719 JOptionPane.YES_NO_OPTION);
3720 if (option == JOptionPane.YES_OPTION)
3722 jalview.gui.UserDefinedColours
3723 .removeColourFromDefaults(radioItem.getText());
3724 colourMenu.remove(radioItem);
3728 radioItem.addActionListener(new ActionListener()
3731 public void actionPerformed(ActionEvent evt)
3733 userDefinedColour_actionPerformed(evt);
3740 radioItem.addActionListener(new ActionListener()
3743 public void actionPerformed(ActionEvent evt)
3745 userDefinedColour_actionPerformed(evt);
3749 colourMenu.insert(radioItem, 15);
3750 colours.add(radioItem);
3762 public void PIDColour_actionPerformed(ActionEvent e)
3764 changeColour(new PIDColourScheme());
3774 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3776 changeColour(new Blosum62ColourScheme());
3786 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3788 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3789 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3790 .getAlignment().getSequenceAt(0), null);
3791 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3792 viewport.getAlignment()));
3793 alignPanel.paintAlignment(true);
3803 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3805 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3806 AlignmentSorter.sortByID(viewport.getAlignment());
3807 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3808 viewport.getAlignment()));
3809 alignPanel.paintAlignment(true);
3819 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3821 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3822 AlignmentSorter.sortByLength(viewport.getAlignment());
3823 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3824 viewport.getAlignment()));
3825 alignPanel.paintAlignment(true);
3835 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3837 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3838 AlignmentSorter.sortByGroup(viewport.getAlignment());
3839 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3840 viewport.getAlignment()));
3842 alignPanel.paintAlignment(true);
3852 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3854 new RedundancyPanel(alignPanel, this);
3864 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3866 if ((viewport.getSelectionGroup() == null)
3867 || (viewport.getSelectionGroup().getSize() < 2))
3869 JOptionPane.showInternalMessageDialog(this, MessageManager
3870 .getString("label.you_must_select_least_two_sequences"),
3871 MessageManager.getString("label.invalid_selection"),
3872 JOptionPane.WARNING_MESSAGE);
3876 JInternalFrame frame = new JInternalFrame();
3877 frame.setContentPane(new PairwiseAlignPanel(viewport));
3878 Desktop.addInternalFrame(frame,
3879 MessageManager.getString("action.pairwise_alignment"), 600,
3891 public void PCAMenuItem_actionPerformed(ActionEvent e)
3893 if (((viewport.getSelectionGroup() != null)
3894 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3895 .getSelectionGroup().getSize() > 0))
3896 || (viewport.getAlignment().getHeight() < 4))
3899 .showInternalMessageDialog(
3902 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3904 .getString("label.sequence_selection_insufficient"),
3905 JOptionPane.WARNING_MESSAGE);
3910 new PCAPanel(alignPanel);
3914 public void autoCalculate_actionPerformed(ActionEvent e)
3916 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3917 if (viewport.autoCalculateConsensus)
3919 viewport.firePropertyChange("alignment", null, viewport
3920 .getAlignment().getSequences());
3925 public void sortByTreeOption_actionPerformed(ActionEvent e)
3927 viewport.sortByTree = sortByTree.isSelected();
3931 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3933 viewport.followSelection = listenToViewSelections.isSelected();
3943 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3945 newTreePanel("AV", "PID", "Average distance tree using PID");
3955 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3957 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3967 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3969 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3979 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3981 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3994 void newTreePanel(String type, String pwType, String title)
3998 if (viewport.getSelectionGroup() != null
3999 && viewport.getSelectionGroup().getSize() > 0)
4001 if (viewport.getSelectionGroup().getSize() < 3)
4007 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4009 .getString("label.not_enough_sequences"),
4010 JOptionPane.WARNING_MESSAGE);
4014 SequenceGroup sg = viewport.getSelectionGroup();
4016 /* Decide if the selection is a column region */
4017 for (SequenceI _s : sg.getSequences())
4019 if (_s.getLength() < sg.getEndRes())
4025 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4027 .getString("label.sequences_selection_not_aligned"),
4028 JOptionPane.WARNING_MESSAGE);
4034 title = title + " on region";
4035 tp = new TreePanel(alignPanel, type, pwType);
4039 // are the visible sequences aligned?
4040 if (!viewport.getAlignment().isAligned(false))
4046 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4048 .getString("label.sequences_not_aligned"),
4049 JOptionPane.WARNING_MESSAGE);
4054 if (viewport.getAlignment().getHeight() < 2)
4059 tp = new TreePanel(alignPanel, type, pwType);
4064 if (viewport.viewName != null)
4066 title += viewport.viewName + " of ";
4069 title += this.title;
4071 Desktop.addInternalFrame(tp, title, 600, 500);
4082 public void addSortByOrderMenuItem(String title,
4083 final AlignmentOrder order)
4085 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4087 item.addActionListener(new java.awt.event.ActionListener()
4090 public void actionPerformed(ActionEvent e)
4092 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4094 // TODO: JBPNote - have to map order entries to curent SequenceI
4096 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4098 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4101 alignPanel.paintAlignment(true);
4107 * Add a new sort by annotation score menu item
4110 * the menu to add the option to
4112 * the label used to retrieve scores for each sequence on the
4115 public void addSortByAnnotScoreMenuItem(JMenu sort,
4116 final String scoreLabel)
4118 final JMenuItem item = new JMenuItem(scoreLabel);
4120 item.addActionListener(new java.awt.event.ActionListener()
4123 public void actionPerformed(ActionEvent e)
4125 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4126 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4127 viewport.getAlignment());// ,viewport.getSelectionGroup());
4128 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4129 viewport.getAlignment()));
4130 alignPanel.paintAlignment(true);
4136 * last hash for alignment's annotation array - used to minimise cost of
4139 protected int _annotationScoreVectorHash;
4142 * search the alignment and rebuild the sort by annotation score submenu the
4143 * last alignment annotation vector hash is stored to minimize cost of
4144 * rebuilding in subsequence calls.
4148 public void buildSortByAnnotationScoresMenu()
4150 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4155 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4157 sortByAnnotScore.removeAll();
4158 // almost certainly a quicker way to do this - but we keep it simple
4159 Hashtable scoreSorts = new Hashtable();
4160 AlignmentAnnotation aann[];
4161 for (SequenceI sqa : viewport.getAlignment().getSequences())
4163 aann = sqa.getAnnotation();
4164 for (int i = 0; aann != null && i < aann.length; i++)
4166 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4168 scoreSorts.put(aann[i].label, aann[i].label);
4172 Enumeration labels = scoreSorts.keys();
4173 while (labels.hasMoreElements())
4175 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4176 (String) labels.nextElement());
4178 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4181 _annotationScoreVectorHash = viewport.getAlignment()
4182 .getAlignmentAnnotation().hashCode();
4187 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4188 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4189 * call. Listeners are added to remove the menu item when the treePanel is
4190 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4194 * Displayed tree window.
4196 * SortBy menu item title.
4199 public void buildTreeMenu()
4201 calculateTree.removeAll();
4202 // build the calculate menu
4204 for (final String type : new String[]
4207 String treecalcnm = MessageManager.getString("label.tree_calc_"
4208 + type.toLowerCase());
4209 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4211 JMenuItem tm = new JMenuItem();
4212 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4213 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4215 String smn = MessageManager.getStringOrReturn(
4216 "label.score_model_", sm.getName());
4217 final String title = MessageManager.formatMessage(
4218 "label.treecalc_title", treecalcnm, smn);
4219 tm.setText(title);//
4220 tm.addActionListener(new java.awt.event.ActionListener()
4223 public void actionPerformed(ActionEvent e)
4225 newTreePanel(type, pwtype, title);
4228 calculateTree.add(tm);
4233 sortByTreeMenu.removeAll();
4235 List<Component> comps = PaintRefresher.components.get(viewport
4236 .getSequenceSetId());
4237 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4238 for (Component comp : comps)
4240 if (comp instanceof TreePanel)
4242 treePanels.add((TreePanel) comp);
4246 if (treePanels.size() < 1)
4248 sortByTreeMenu.setVisible(false);
4252 sortByTreeMenu.setVisible(true);
4254 for (final TreePanel tp : treePanels)
4256 final JMenuItem item = new JMenuItem(tp.getTitle());
4257 item.addActionListener(new java.awt.event.ActionListener()
4260 public void actionPerformed(ActionEvent e)
4262 tp.sortByTree_actionPerformed();
4263 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4268 sortByTreeMenu.add(item);
4272 public boolean sortBy(AlignmentOrder alorder, String undoname)
4274 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4275 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4276 if (undoname != null)
4278 addHistoryItem(new OrderCommand(undoname, oldOrder,
4279 viewport.getAlignment()));
4281 alignPanel.paintAlignment(true);
4286 * Work out whether the whole set of sequences or just the selected set will
4287 * be submitted for multiple alignment.
4290 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4292 // Now, check we have enough sequences
4293 AlignmentView msa = null;
4295 if ((viewport.getSelectionGroup() != null)
4296 && (viewport.getSelectionGroup().getSize() > 1))
4298 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4299 // some common interface!
4301 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4302 * SequenceI[sz = seqs.getSize(false)];
4304 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4305 * seqs.getSequenceAt(i); }
4307 msa = viewport.getAlignmentView(true);
4309 else if (viewport.getSelectionGroup() != null
4310 && viewport.getSelectionGroup().getSize() == 1)
4312 int option = JOptionPane.showConfirmDialog(this,
4313 MessageManager.getString("warn.oneseq_msainput_selection"),
4314 MessageManager.getString("label.invalid_selection"),
4315 JOptionPane.OK_CANCEL_OPTION);
4316 if (option == JOptionPane.OK_OPTION)
4318 msa = viewport.getAlignmentView(false);
4323 msa = viewport.getAlignmentView(false);
4329 * Decides what is submitted to a secondary structure prediction service: the
4330 * first sequence in the alignment, or in the current selection, or, if the
4331 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4332 * region or the whole alignment. (where the first sequence in the set is the
4333 * one that the prediction will be for).
4335 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4337 AlignmentView seqs = null;
4339 if ((viewport.getSelectionGroup() != null)
4340 && (viewport.getSelectionGroup().getSize() > 0))
4342 seqs = viewport.getAlignmentView(true);
4346 seqs = viewport.getAlignmentView(false);
4348 // limit sequences - JBPNote in future - could spawn multiple prediction
4350 // TODO: viewport.getAlignment().isAligned is a global state - the local
4351 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4352 if (!viewport.getAlignment().isAligned(false))
4354 seqs.setSequences(new SeqCigar[]
4355 { seqs.getSequences()[0] });
4356 // TODO: if seqs.getSequences().length>1 then should really have warned
4370 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4372 // Pick the tree file
4373 JalviewFileChooser chooser = new JalviewFileChooser(
4374 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4375 chooser.setFileView(new JalviewFileView());
4376 chooser.setDialogTitle(MessageManager
4377 .getString("label.select_newick_like_tree_file"));
4378 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4380 int value = chooser.showOpenDialog(null);
4382 if (value == JalviewFileChooser.APPROVE_OPTION)
4384 String choice = chooser.getSelectedFile().getPath();
4385 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4386 jalview.io.NewickFile fin = null;
4389 fin = new jalview.io.NewickFile(choice, "File");
4390 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4391 } catch (Exception ex)
4398 .getString("label.problem_reading_tree_file"),
4399 JOptionPane.WARNING_MESSAGE);
4400 ex.printStackTrace();
4402 if (fin != null && fin.hasWarningMessage())
4404 JOptionPane.showMessageDialog(Desktop.desktop, fin
4405 .getWarningMessage(), MessageManager
4406 .getString("label.possible_problem_with_tree_file"),
4407 JOptionPane.WARNING_MESSAGE);
4413 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4415 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4418 public TreePanel ShowNewickTree(NewickFile nf, String title)
4420 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4423 public TreePanel ShowNewickTree(NewickFile nf, String title,
4424 AlignmentView input)
4426 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4429 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4430 int h, int x, int y)
4432 return ShowNewickTree(nf, title, null, w, h, x, y);
4436 * Add a treeviewer for the tree extracted from a newick file object to the
4437 * current alignment view
4444 * Associated alignment input data (or null)
4453 * @return TreePanel handle
4455 public TreePanel ShowNewickTree(NewickFile nf, String title,
4456 AlignmentView input, int w, int h, int x, int y)
4458 TreePanel tp = null;
4464 if (nf.getTree() != null)
4466 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4472 tp.setLocation(x, y);
4475 Desktop.addInternalFrame(tp, title, w, h);
4477 } catch (Exception ex)
4479 ex.printStackTrace();
4485 private boolean buildingMenu = false;
4488 * Generates menu items and listener event actions for web service clients
4491 public void BuildWebServiceMenu()
4493 while (buildingMenu)
4497 System.err.println("Waiting for building menu to finish.");
4499 } catch (Exception e)
4503 final AlignFrame me = this;
4504 buildingMenu = true;
4505 new Thread(new Runnable()
4510 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4513 System.err.println("Building ws menu again "
4514 + Thread.currentThread());
4515 // TODO: add support for context dependent disabling of services based
4517 // alignment and current selection
4518 // TODO: add additional serviceHandle parameter to specify abstract
4520 // class independently of AbstractName
4521 // TODO: add in rediscovery GUI function to restart discoverer
4522 // TODO: group services by location as well as function and/or
4524 // object broker mechanism.
4525 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4526 final IProgressIndicator af = me;
4527 final JMenu msawsmenu = new JMenu("Alignment");
4528 final JMenu secstrmenu = new JMenu(
4529 "Secondary Structure Prediction");
4530 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4531 final JMenu analymenu = new JMenu("Analysis");
4532 final JMenu dismenu = new JMenu("Protein Disorder");
4533 // final JMenu msawsmenu = new
4534 // JMenu(MessageManager.getString("label.alignment"));
4535 // final JMenu secstrmenu = new
4536 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4537 // final JMenu seqsrchmenu = new
4538 // JMenu(MessageManager.getString("label.sequence_database_search"));
4539 // final JMenu analymenu = new
4540 // JMenu(MessageManager.getString("label.analysis"));
4541 // final JMenu dismenu = new
4542 // JMenu(MessageManager.getString("label.protein_disorder"));
4543 // JAL-940 - only show secondary structure prediction services from
4544 // the legacy server
4545 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4547 Discoverer.services != null && (Discoverer.services.size() > 0))
4549 // TODO: refactor to allow list of AbstractName/Handler bindings to
4551 // stored or retrieved from elsewhere
4552 // No MSAWS used any more:
4553 // Vector msaws = null; // (Vector)
4554 // Discoverer.services.get("MsaWS");
4555 Vector secstrpr = (Vector) Discoverer.services
4557 if (secstrpr != null)
4559 // Add any secondary structure prediction services
4560 for (int i = 0, j = secstrpr.size(); i < j; i++)
4562 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4564 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4565 .getServiceClient(sh);
4566 int p = secstrmenu.getItemCount();
4567 impl.attachWSMenuEntry(secstrmenu, me);
4568 int q = secstrmenu.getItemCount();
4569 for (int litm = p; litm < q; litm++)
4571 legacyItems.add(secstrmenu.getItem(litm));
4577 // Add all submenus in the order they should appear on the web
4579 wsmenu.add(msawsmenu);
4580 wsmenu.add(secstrmenu);
4581 wsmenu.add(dismenu);
4582 wsmenu.add(analymenu);
4583 // No search services yet
4584 // wsmenu.add(seqsrchmenu);
4586 javax.swing.SwingUtilities.invokeLater(new Runnable()
4593 webService.removeAll();
4594 // first, add discovered services onto the webservices menu
4595 if (wsmenu.size() > 0)
4597 for (int i = 0, j = wsmenu.size(); i < j; i++)
4599 webService.add(wsmenu.get(i));
4604 webService.add(me.webServiceNoServices);
4606 // TODO: move into separate menu builder class.
4607 boolean new_sspred = false;
4608 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4610 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4611 if (jws2servs != null)
4613 if (jws2servs.hasServices())
4615 jws2servs.attachWSMenuEntry(webService, me);
4616 for (Jws2Instance sv : jws2servs.getServices())
4618 if (sv.description.toLowerCase().contains("jpred"))
4620 for (JMenuItem jmi : legacyItems)
4622 jmi.setVisible(false);
4628 if (jws2servs.isRunning())
4630 JMenuItem tm = new JMenuItem(
4631 "Still discovering JABA Services");
4632 tm.setEnabled(false);
4637 build_urlServiceMenu(me.webService);
4638 build_fetchdbmenu(webService);
4639 for (JMenu item : wsmenu)
4641 if (item.getItemCount() == 0)
4643 item.setEnabled(false);
4647 item.setEnabled(true);
4650 } catch (Exception e)
4653 .debug("Exception during web service menu building process.",
4658 } catch (Exception e)
4661 buildingMenu = false;
4668 * construct any groupURL type service menu entries.
4672 private void build_urlServiceMenu(JMenu webService)
4674 // TODO: remove this code when 2.7 is released
4675 // DEBUG - alignmentView
4677 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4678 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4680 * @Override public void actionPerformed(ActionEvent e) {
4681 * jalview.datamodel.AlignmentView
4682 * .testSelectionViews(af.viewport.getAlignment(),
4683 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4685 * }); webService.add(testAlView);
4687 // TODO: refactor to RestClient discoverer and merge menu entries for
4688 // rest-style services with other types of analysis/calculation service
4689 // SHmmr test client - still being implemented.
4690 // DEBUG - alignmentView
4692 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4695 client.attachWSMenuEntry(
4696 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4702 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4703 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4704 * getProperty("LAST_DIRECTORY"));
4706 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4707 * to Vamsas file"); chooser.setToolTipText("Export");
4709 * int value = chooser.showSaveDialog(this);
4711 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4712 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4713 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4714 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4717 * prototype of an automatically enabled/disabled analysis function
4720 protected void setShowProductsEnabled()
4722 SequenceI[] selection = viewport.getSequenceSelection();
4723 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4724 viewport.getAlignment().getDataset()))
4726 showProducts.setEnabled(true);
4731 showProducts.setEnabled(false);
4736 * search selection for sequence xRef products and build the show products
4741 * @return true if showProducts menu should be enabled.
4743 public boolean canShowProducts(SequenceI[] selection,
4744 boolean isRegionSelection, Alignment dataset)
4746 boolean showp = false;
4749 showProducts.removeAll();
4750 final boolean dna = viewport.getAlignment().isNucleotide();
4751 final Alignment ds = dataset;
4752 String[] ptypes = (selection == null || selection.length == 0) ? null
4753 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4755 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4756 // selection, dataset, true);
4757 final SequenceI[] sel = selection;
4758 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4761 final boolean isRegSel = isRegionSelection;
4762 final AlignFrame af = this;
4763 final String source = ptypes[t];
4764 JMenuItem xtype = new JMenuItem(ptypes[t]);
4765 xtype.addActionListener(new ActionListener()
4769 public void actionPerformed(ActionEvent e)
4771 // TODO: new thread for this call with vis-delay
4772 af.showProductsFor(af.viewport.getSequenceSelection(),
4773 isRegSel, dna, source);
4777 showProducts.add(xtype);
4779 showProducts.setVisible(showp);
4780 showProducts.setEnabled(showp);
4781 } catch (Exception e)
4783 jalview.bin.Cache.log
4784 .warn("canTranslate threw an exception - please report to help@jalview.org",
4791 protected void showProductsFor(final SequenceI[] sel,
4792 final boolean isRegSel, final boolean dna, final String source)
4794 Runnable foo = new Runnable()
4800 final long sttime = System.currentTimeMillis();
4801 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4802 "status.searching_for_sequences_from", new Object[]
4803 { source }), sttime);
4806 // update our local dataset reference
4807 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4809 Alignment prods = CrossRef
4810 .findXrefSequences(sel, dna, source, ds);
4813 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4814 for (int s = 0; s < sprods.length; s++)
4816 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4817 if (ds.getSequences() == null
4818 || !ds.getSequences().contains(
4819 sprods[s].getDatasetSequence()))
4821 ds.addSequence(sprods[s].getDatasetSequence());
4823 sprods[s].updatePDBIds();
4825 Alignment al = new Alignment(sprods);
4829 * Copy dna-to-protein mappings to new alignment
4831 // TODO 1: no mappings are set up for EMBL product
4832 // TODO 2: if they were, should add them to protein alignment, not
4834 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4835 for (AlignedCodonFrame acf : cf)
4837 al.addCodonFrame(acf);
4839 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4841 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4842 + " for " + ((isRegSel) ? "selected region of " : "")
4844 naf.setTitle(newtitle);
4846 // temporary flag until SplitFrame is released
4847 boolean asSplitFrame = Cache.getDefault(
4848 Preferences.ENABLE_SPLIT_FRAME, false);
4852 * Make a copy of this alignment (sharing the same dataset
4853 * sequences). If we are DNA, drop introns and update mappings
4855 AlignmentI copyAlignment = null;
4856 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4857 .getSequenceSelection();
4860 copyAlignment = AlignmentUtils.makeExonAlignment(
4861 sequenceSelection, cf);
4862 al.getCodonFrames().clear();
4863 al.getCodonFrames().addAll(cf);
4864 final StructureSelectionManager ssm = StructureSelectionManager
4865 .getStructureSelectionManager(Desktop.instance);
4866 ssm.addMappings(cf);
4870 copyAlignment = new Alignment(new Alignment(
4871 sequenceSelection));
4873 AlignFrame copyThis = new AlignFrame(copyAlignment,
4874 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4875 copyThis.setTitle(AlignFrame.this.getTitle());
4876 // SplitFrame with dna above, protein below
4877 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4878 dna ? naf : copyThis);
4879 naf.setVisible(true);
4880 copyThis.setVisible(true);
4881 String linkedTitle = MessageManager
4882 .getString("label.linked_view_title");
4883 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4887 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4893 System.err.println("No Sequences generated for xRef type "
4896 } catch (Exception e)
4898 jalview.bin.Cache.log.error(
4899 "Exception when finding crossreferences", e);
4900 } catch (OutOfMemoryError e)
4902 new OOMWarning("whilst fetching crossreferences", e);
4905 jalview.bin.Cache.log.error("Error when finding crossreferences",
4908 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4909 "status.finished_searching_for_sequences_from",
4916 Thread frunner = new Thread(foo);
4920 public boolean canShowTranslationProducts(SequenceI[] selection,
4921 AlignmentI alignment)
4926 return (jalview.analysis.Dna.canTranslate(selection,
4927 viewport.getViewAsVisibleContigs(true)));
4928 } catch (Exception e)
4930 jalview.bin.Cache.log
4931 .warn("canTranslate threw an exception - please report to help@jalview.org",
4938 * Construct and display a new frame containing the translation of this
4939 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4942 public void showTranslation_actionPerformed(ActionEvent e)
4944 AlignmentI al = null;
4947 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4949 al = dna.translateCdna();
4950 } catch (Exception ex)
4952 jalview.bin.Cache.log.error(
4953 "Exception during translation. Please report this !", ex);
4954 final String msg = MessageManager
4955 .getString("label.error_when_translating_sequences_submit_bug_report");
4956 final String title = MessageManager
4957 .getString("label.implementation_error")
4958 + MessageManager.getString("translation_failed");
4959 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4960 JOptionPane.ERROR_MESSAGE);
4963 if (al == null || al.getHeight() == 0)
4965 final String msg = MessageManager
4966 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4967 final String title = MessageManager
4968 .getString("label.translation_failed");
4969 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4970 JOptionPane.WARNING_MESSAGE);
4974 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4975 af.setFileFormat(this.currentFileFormat);
4976 final String newTitle = MessageManager.formatMessage(
4977 "label.translation_of_params", new Object[]
4978 { this.getTitle() });
4979 af.setTitle(newTitle);
4980 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
4982 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4983 viewport.openSplitFrame(af, new Alignment(seqs),
4984 al.getCodonFrames());
4988 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4995 * Set the file format
4999 public void setFileFormat(String fileFormat)
5001 this.currentFileFormat = fileFormat;
5005 * Try to load a features file onto the alignment.
5008 * contents or path to retrieve file
5010 * access mode of file (see jalview.io.AlignFile)
5011 * @return true if features file was parsed correctly.
5013 public boolean parseFeaturesFile(String file, String type)
5015 return avc.parseFeaturesFile(file, type,
5016 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5021 public void refreshFeatureUI(boolean enableIfNecessary)
5023 // note - currently this is only still here rather than in the controller
5024 // because of the featureSettings hard reference that is yet to be
5026 if (enableIfNecessary)
5028 viewport.setShowSequenceFeatures(true);
5029 showSeqFeatures.setSelected(true);
5035 public void dragEnter(DropTargetDragEvent evt)
5040 public void dragExit(DropTargetEvent evt)
5045 public void dragOver(DropTargetDragEvent evt)
5050 public void dropActionChanged(DropTargetDragEvent evt)
5055 public void drop(DropTargetDropEvent evt)
5057 Transferable t = evt.getTransferable();
5058 java.util.List files = null;
5062 DataFlavor uriListFlavor = new DataFlavor(
5063 "text/uri-list;class=java.lang.String");
5064 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5066 // Works on Windows and MacOSX
5067 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5068 files = (java.util.List) t
5069 .getTransferData(DataFlavor.javaFileListFlavor);
5071 else if (t.isDataFlavorSupported(uriListFlavor))
5073 // This is used by Unix drag system
5074 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5075 String data = (String) t.getTransferData(uriListFlavor);
5076 files = new java.util.ArrayList(1);
5077 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5078 data, "\r\n"); st.hasMoreTokens();)
5080 String s = st.nextToken();
5081 if (s.startsWith("#"))
5083 // the line is a comment (as per the RFC 2483)
5087 java.net.URI uri = new java.net.URI(s);
5088 // check to see if we can handle this kind of URI
5089 if (uri.getScheme().toLowerCase().startsWith("http"))
5091 files.add(uri.toString());
5095 // otherwise preserve old behaviour: catch all for file objects
5096 java.io.File file = new java.io.File(uri);
5097 files.add(file.toString());
5101 } catch (Exception e)
5103 e.printStackTrace();
5109 // check to see if any of these files have names matching sequences in
5111 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5112 .getAlignment().getSequencesArray());
5114 * Object[] { String,SequenceI}
5116 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5117 ArrayList<String> filesnotmatched = new ArrayList<String>();
5118 for (int i = 0; i < files.size(); i++)
5120 String file = files.get(i).toString();
5122 String protocol = FormatAdapter.checkProtocol(file);
5123 if (protocol == jalview.io.FormatAdapter.FILE)
5125 File fl = new File(file);
5126 pdbfn = fl.getName();
5128 else if (protocol == jalview.io.FormatAdapter.URL)
5130 URL url = new URL(file);
5131 pdbfn = url.getFile();
5133 if (pdbfn.length() > 0)
5135 // attempt to find a match in the alignment
5136 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5137 int l = 0, c = pdbfn.indexOf(".");
5138 while (mtch == null && c != -1)
5143 } while ((c = pdbfn.indexOf(".", l)) > l);
5146 pdbfn = pdbfn.substring(0, l);
5148 mtch = idm.findAllIdMatches(pdbfn);
5155 type = new IdentifyFile().Identify(file, protocol);
5156 } catch (Exception ex)
5162 if (type.equalsIgnoreCase("PDB"))
5164 filesmatched.add(new Object[]
5165 { file, protocol, mtch });
5170 // File wasn't named like one of the sequences or wasn't a PDB file.
5171 filesnotmatched.add(file);
5175 if (filesmatched.size() > 0)
5177 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5183 "label.automatically_associate_pdb_files_with_sequences_same_name",
5190 .getString("label.automatically_associate_pdb_files_by_name"),
5191 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5194 for (Object[] fm : filesmatched)
5196 // try and associate
5197 // TODO: may want to set a standard ID naming formalism for
5198 // associating PDB files which have no IDs.
5199 for (SequenceI toassoc : (SequenceI[]) fm[2])
5201 PDBEntry pe = new AssociatePdbFileWithSeq()
5202 .associatePdbWithSeq((String) fm[0],
5203 (String) fm[1], toassoc, false,
5207 System.err.println("Associated file : "
5208 + ((String) fm[0]) + " with "
5209 + toassoc.getDisplayId(true));
5213 alignPanel.paintAlignment(true);
5217 if (filesnotmatched.size() > 0)
5220 && (Cache.getDefault(
5221 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5224 "<html>"+MessageManager
5226 "label.ignore_unmatched_dropped_files_info",
5231 .toString() })+"</html>",
5233 .getString("label.ignore_unmatched_dropped_files"),
5234 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5238 for (String fn : filesnotmatched)
5240 loadJalviewDataFile(fn, null, null, null);
5244 } catch (Exception ex)
5246 ex.printStackTrace();
5252 * Attempt to load a "dropped" file or URL string: First by testing whether
5253 * it's and Annotation file, then a JNet file, and finally a features file. If
5254 * all are false then the user may have dropped an alignment file onto this
5258 * either a filename or a URL string.
5260 public void loadJalviewDataFile(String file, String protocol,
5261 String format, SequenceI assocSeq)
5265 if (protocol == null)
5267 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5269 // if the file isn't identified, or not positively identified as some
5270 // other filetype (PFAM is default unidentified alignment file type) then
5271 // try to parse as annotation.
5272 boolean isAnnotation = (format == null || format
5273 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5274 .annotateAlignmentView(viewport, file, protocol)
5279 // first see if its a T-COFFEE score file
5280 TCoffeeScoreFile tcf = null;
5283 tcf = new TCoffeeScoreFile(file, protocol);
5286 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5288 tcoffeeColour.setEnabled(true);
5289 tcoffeeColour.setSelected(true);
5290 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5291 isAnnotation = true;
5293 .setText(MessageManager
5294 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5298 // some problem - if no warning its probable that the ID matching
5299 // process didn't work
5303 tcf.getWarningMessage() == null ? MessageManager
5304 .getString("label.check_file_matches_sequence_ids_alignment")
5305 : tcf.getWarningMessage(),
5307 .getString("label.problem_reading_tcoffee_score_file"),
5308 JOptionPane.WARNING_MESSAGE);
5315 } catch (Exception x)
5318 .debug("Exception when processing data source as T-COFFEE score file",
5324 // try to see if its a JNet 'concise' style annotation file *before*
5326 // try to parse it as a features file
5329 format = new IdentifyFile().Identify(file, protocol);
5331 if (format.equalsIgnoreCase("JnetFile"))
5333 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5335 new JnetAnnotationMaker();
5336 JnetAnnotationMaker.add_annotation(predictions,
5337 viewport.getAlignment(), 0, false);
5338 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5339 viewport.getAlignment().setSeqrep(repseq);
5340 ColumnSelection cs = new ColumnSelection();
5341 cs.hideInsertionsFor(repseq);
5342 viewport.setColumnSelection(cs);
5343 isAnnotation = true;
5348 * if (format.equalsIgnoreCase("PDB")) {
5350 * String pdbfn = ""; // try to match up filename with sequence id
5351 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5352 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5353 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5354 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5355 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5356 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5357 * // attempt to find a match in the alignment SequenceI mtch =
5358 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5359 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5360 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5361 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5362 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5363 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5364 * { System.err.println("Associated file : " + file + " with " +
5365 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5366 * TODO: maybe need to load as normal otherwise return; } }
5368 // try to parse it as a features file
5369 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5370 // if it wasn't a features file then we just treat it as a general
5371 // alignment file to load into the current view.
5374 new FileLoader().LoadFile(viewport, file, protocol, format);
5378 alignPanel.paintAlignment(true);
5386 alignPanel.adjustAnnotationHeight();
5387 viewport.updateSequenceIdColours();
5388 buildSortByAnnotationScoresMenu();
5389 alignPanel.paintAlignment(true);
5391 } catch (Exception ex)
5393 ex.printStackTrace();
5394 } catch (OutOfMemoryError oom)
5399 } catch (Exception x)
5405 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5406 : "using " + protocol + " from " + file)
5408 + (format != null ? "(parsing as '" + format
5409 + "' file)" : ""), oom, Desktop.desktop);
5414 * Method invoked by the ChangeListener on the tabbed pane, in other words
5415 * when a different tabbed pane is selected by the user or programmatically.
5418 public void tabSelectionChanged(int index)
5422 alignPanel = alignPanels.get(index);
5423 viewport = alignPanel.av;
5424 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5425 setMenusFromViewport(viewport);
5429 * If there is a frame linked to this one in a SplitPane, switch it to the
5430 * same view tab index. No infinite recursion of calls should happen, since
5431 * tabSelectionChanged() should not get invoked on setting the selected
5432 * index to an unchanged value. Guard against setting an invalid index
5433 * before the new view peer tab has been created.
5435 final AlignViewportI peer = viewport.getCodingComplement();
5438 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5439 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5441 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5447 * On right mouse click on view tab, prompt for and set new view name.
5450 public void tabbedPane_mousePressed(MouseEvent e)
5452 if (SwingUtilities.isRightMouseButton(e))
5454 String msg = MessageManager.getString("label.enter_view_name");
5455 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5456 JOptionPane.QUESTION_MESSAGE);
5460 viewport.viewName = reply;
5461 // TODO warn if reply is in getExistingViewNames()?
5462 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5467 public AlignViewport getCurrentView()
5473 * Open the dialog for regex description parsing.
5476 protected void extractScores_actionPerformed(ActionEvent e)
5478 ParseProperties pp = new jalview.analysis.ParseProperties(
5479 viewport.getAlignment());
5480 // TODO: verify regex and introduce GUI dialog for version 2.5
5481 // if (pp.getScoresFromDescription("col", "score column ",
5482 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5484 if (pp.getScoresFromDescription("description column",
5485 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5487 buildSortByAnnotationScoresMenu();
5495 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5499 protected void showDbRefs_actionPerformed(ActionEvent e)
5501 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5507 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5511 protected void showNpFeats_actionPerformed(ActionEvent e)
5513 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5517 * find the viewport amongst the tabs in this alignment frame and close that
5522 public boolean closeView(AlignViewportI av)
5526 this.closeMenuItem_actionPerformed(false);
5529 Component[] comp = tabbedPane.getComponents();
5530 for (int i = 0; comp != null && i < comp.length; i++)
5532 if (comp[i] instanceof AlignmentPanel)
5534 if (((AlignmentPanel) comp[i]).av == av)
5537 closeView((AlignmentPanel) comp[i]);
5545 protected void build_fetchdbmenu(JMenu webService)
5547 // Temporary hack - DBRef Fetcher always top level ws entry.
5548 // TODO We probably want to store a sequence database checklist in
5549 // preferences and have checkboxes.. rather than individual sources selected
5551 final JMenu rfetch = new JMenu(
5552 MessageManager.getString("action.fetch_db_references"));
5553 rfetch.setToolTipText(MessageManager
5554 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5555 webService.add(rfetch);
5557 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5558 MessageManager.getString("option.trim_retrieved_seqs"));
5559 trimrs.setToolTipText(MessageManager
5560 .getString("label.trim_retrieved_sequences"));
5561 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5562 trimrs.addActionListener(new ActionListener()
5565 public void actionPerformed(ActionEvent e)
5567 trimrs.setSelected(trimrs.isSelected());
5568 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5569 Boolean.valueOf(trimrs.isSelected()).toString());
5573 JMenuItem fetchr = new JMenuItem(
5574 MessageManager.getString("label.standard_databases"));
5575 fetchr.setToolTipText(MessageManager
5576 .getString("label.fetch_embl_uniprot"));
5577 fetchr.addActionListener(new ActionListener()
5581 public void actionPerformed(ActionEvent e)
5583 new Thread(new Runnable()
5589 new jalview.ws.DBRefFetcher(alignPanel.av
5590 .getSequenceSelection(), alignPanel.alignFrame)
5591 .fetchDBRefs(false);
5599 final AlignFrame me = this;
5600 new Thread(new Runnable()
5605 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5606 .getSequenceFetcherSingleton(me);
5607 javax.swing.SwingUtilities.invokeLater(new Runnable()
5612 String[] dbclasses = sf.getOrderedSupportedSources();
5613 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5614 // jalview.util.QuickSort.sort(otherdb, otherdb);
5615 List<DbSourceProxy> otherdb;
5616 JMenu dfetch = new JMenu();
5617 JMenu ifetch = new JMenu();
5618 JMenuItem fetchr = null;
5619 int comp = 0, icomp = 0, mcomp = 15;
5620 String mname = null;
5622 for (String dbclass : dbclasses)
5624 otherdb = sf.getSourceProxy(dbclass);
5625 // add a single entry for this class, or submenu allowing 'fetch
5627 if (otherdb == null || otherdb.size() < 1)
5631 // List<DbSourceProxy> dbs=otherdb;
5632 // otherdb=new ArrayList<DbSourceProxy>();
5633 // for (DbSourceProxy db:dbs)
5635 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5639 mname = "From " + dbclass;
5641 if (otherdb.size() == 1)
5643 final DbSourceProxy[] dassource = otherdb
5644 .toArray(new DbSourceProxy[0]);
5645 DbSourceProxy src = otherdb.get(0);
5646 fetchr = new JMenuItem(src.getDbSource());
5647 fetchr.addActionListener(new ActionListener()
5651 public void actionPerformed(ActionEvent e)
5653 new Thread(new Runnable()
5659 new jalview.ws.DBRefFetcher(alignPanel.av
5660 .getSequenceSelection(),
5661 alignPanel.alignFrame, dassource)
5662 .fetchDBRefs(false);
5668 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5674 final DbSourceProxy[] dassource = otherdb
5675 .toArray(new DbSourceProxy[0]);
5677 DbSourceProxy src = otherdb.get(0);
5678 fetchr = new JMenuItem(MessageManager.formatMessage(
5679 "label.fetch_all_param", new Object[]
5680 { src.getDbSource() }));
5681 fetchr.addActionListener(new ActionListener()
5684 public void actionPerformed(ActionEvent e)
5686 new Thread(new Runnable()
5692 new jalview.ws.DBRefFetcher(alignPanel.av
5693 .getSequenceSelection(),
5694 alignPanel.alignFrame, dassource)
5695 .fetchDBRefs(false);
5701 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5704 // and then build the rest of the individual menus
5705 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5707 String imname = null;
5709 for (DbSourceProxy sproxy : otherdb)
5711 String dbname = sproxy.getDbName();
5712 String sname = dbname.length() > 5 ? dbname.substring(0,
5713 5) + "..." : dbname;
5714 String msname = dbname.length() > 10 ? dbname.substring(
5715 0, 10) + "..." : dbname;
5718 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5720 fetchr = new JMenuItem(msname);
5721 final DbSourceProxy[] dassrc =
5723 fetchr.addActionListener(new ActionListener()
5727 public void actionPerformed(ActionEvent e)
5729 new Thread(new Runnable()
5735 new jalview.ws.DBRefFetcher(alignPanel.av
5736 .getSequenceSelection(),
5737 alignPanel.alignFrame, dassrc)
5738 .fetchDBRefs(false);
5744 fetchr.setToolTipText("<html>"
5745 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5748 if (++icomp >= mcomp || i == (otherdb.size()))
5750 ifetch.setText(MessageManager.formatMessage(
5751 "label.source_to_target", imname, sname));
5753 ifetch = new JMenu();
5761 if (comp >= mcomp || dbi >= (dbclasses.length))
5763 dfetch.setText(MessageManager.formatMessage(
5764 "label.source_to_target", mname, dbclass));
5766 dfetch = new JMenu();
5779 * Left justify the whole alignment.
5782 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5784 AlignmentI al = viewport.getAlignment();
5786 viewport.firePropertyChange("alignment", null, al);
5790 * Right justify the whole alignment.
5793 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5795 AlignmentI al = viewport.getAlignment();
5797 viewport.firePropertyChange("alignment", null, al);
5800 public void setShowSeqFeatures(boolean b)
5802 showSeqFeatures.setSelected(b);
5803 viewport.setShowSequenceFeatures(b);
5810 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5811 * awt.event.ActionEvent)
5814 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5816 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5817 alignPanel.paintAlignment(true);
5824 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5828 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5830 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5831 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5839 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5840 * .event.ActionEvent)
5843 protected void showGroupConservation_actionPerformed(ActionEvent e)
5845 viewport.setShowGroupConservation(showGroupConservation.getState());
5846 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5853 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5854 * .event.ActionEvent)
5857 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5859 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5860 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5867 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5868 * .event.ActionEvent)
5871 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5873 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5874 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5878 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5880 showSequenceLogo.setState(true);
5881 viewport.setShowSequenceLogo(true);
5882 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5883 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5887 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5889 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5896 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5897 * .event.ActionEvent)
5900 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5902 if (avc.makeGroupsFromSelection())
5904 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5905 alignPanel.updateAnnotation();
5906 alignPanel.paintAlignment(true);
5909 public void clearAlignmentSeqRep()
5911 // TODO refactor alignmentseqrep to controller
5912 if (viewport.getAlignment().hasSeqrep()) {
5913 viewport.getAlignment().setSeqrep(null);
5914 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5915 alignPanel.updateAnnotation();
5916 alignPanel.paintAlignment(true);
5921 protected void createGroup_actionPerformed(ActionEvent e)
5923 if (avc.createGroup())
5925 alignPanel.alignmentChanged();
5930 protected void unGroup_actionPerformed(ActionEvent e)
5934 alignPanel.alignmentChanged();
5939 * make the given alignmentPanel the currently selected tab
5941 * @param alignmentPanel
5943 public void setDisplayedView(AlignmentPanel alignmentPanel)
5945 if (!viewport.getSequenceSetId().equals(
5946 alignmentPanel.av.getSequenceSetId()))
5948 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5950 if (tabbedPane != null
5951 && tabbedPane.getTabCount() > 0
5952 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5953 .getSelectedIndex())
5955 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5960 * Action on selection of menu options to Show or Hide annotations.
5963 * @param forSequences
5964 * update sequence-related annotations
5965 * @param forAlignment
5966 * update non-sequence-related annotations
5969 protected void setAnnotationsVisibility(boolean visible,
5970 boolean forSequences, boolean forAlignment)
5972 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5973 .getAlignmentAnnotation())
5976 * don't display non-positional annotations on an alignment
5978 if (aa.annotations == null)
5982 boolean apply = (aa.sequenceRef == null && forAlignment)
5983 || (aa.sequenceRef != null && forSequences);
5986 aa.visible = visible;
5989 alignPanel.validateAnnotationDimensions(false);
5990 alignPanel.alignmentChanged();
5994 * Store selected annotation sort order for the view and repaint.
5997 protected void sortAnnotations_actionPerformed()
5999 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6001 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6002 alignPanel.paintAlignment(true);
6007 * @return alignment panels in this alignment frame
6009 public List<? extends AlignmentViewPanel> getAlignPanels()
6011 return alignPanels == null ? Arrays.asList(alignPanel)
6016 * Open a new alignment window, with the cDNA associated with this (protein)
6017 * alignment, aligned as is the protein.
6019 protected void viewAsCdna_actionPerformed()
6021 // TODO no longer a menu action - refactor as required
6022 final AlignmentI alignment = getViewport().getAlignment();
6023 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6024 if (mappings == null)
6028 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6029 for (SequenceI aaSeq : alignment.getSequences()) {
6030 for (AlignedCodonFrame acf : mappings) {
6031 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6035 * There is a cDNA mapping for this protein sequence - add to new
6036 * alignment. It will share the same dataset sequence as other mapped
6037 * cDNA (no new mappings need to be created).
6039 final Sequence newSeq = new Sequence(dnaSeq);
6040 newSeq.setDatasetSequence(dnaSeq);
6041 cdnaSeqs.add(newSeq);
6045 if (cdnaSeqs.size() == 0)
6047 // show a warning dialog no mapped cDNA
6050 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6052 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6053 AlignFrame.DEFAULT_HEIGHT);
6054 cdna.alignAs(alignment);
6055 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6057 Desktop.addInternalFrame(alignFrame, newtitle,
6058 AlignFrame.DEFAULT_WIDTH,
6059 AlignFrame.DEFAULT_HEIGHT);
6063 * Set visibility of dna/protein complement view (available when shown in a
6069 protected void showComplement_actionPerformed(boolean show)
6071 SplitContainerI sf = getSplitViewContainer();
6073 sf.setComplementVisible(this, show);
6077 public class ExportData
6079 private AlignmentI alignment;
6081 private String[] omitHidden;
6083 private int[] startEnd;
6085 private AlignExportSettingI settings;
6087 public ExportData(AlignmentI align, String[] ommit, int[] startEnd,
6088 AlignExportSettingI settings)
6090 this.alignment = align;
6091 this.omitHidden = ommit;
6092 this.startEnd = startEnd;
6093 this.settings = settings;
6096 public AlignmentI getAlignment()
6101 public void setAlignment(AlignmentI alignment)
6103 this.alignment = alignment;
6106 public String[] getOmitHidden()
6111 public void setOmitHidden(String[] omitHidden)
6113 this.omitHidden = omitHidden;
6116 public int[] getStartEndPostions()
6121 public void setStartEndPostions(int[] startEnd)
6123 this.startEnd = startEnd;
6126 public AlignExportSettingI getSettings()
6131 public void setSettings(AlignExportSettingI settings)
6133 this.settings = settings;
6139 class PrintThread extends Thread
6143 public PrintThread(AlignmentPanel ap)
6148 static PageFormat pf;
6153 PrinterJob printJob = PrinterJob.getPrinterJob();
6157 printJob.setPrintable(ap, pf);
6161 printJob.setPrintable(ap);
6164 if (printJob.printDialog())
6169 } catch (Exception PrintException)
6171 PrintException.printStackTrace();