2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentSorter;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.analysis.CrossRef;
28 import jalview.analysis.Dna;
29 import jalview.analysis.ParseProperties;
30 import jalview.analysis.SequenceIdMatcher;
31 import jalview.api.AlignViewControllerGuiI;
32 import jalview.api.AlignViewControllerI;
33 import jalview.api.AlignViewportI;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.api.FeatureSettingsControllerI;
36 import jalview.api.SplitContainerI;
37 import jalview.api.ViewStyleI;
38 import jalview.api.analysis.ScoreModelI;
39 import jalview.bin.Cache;
40 import jalview.bin.Jalview;
41 import jalview.commands.CommandI;
42 import jalview.commands.EditCommand;
43 import jalview.commands.EditCommand.Action;
44 import jalview.commands.OrderCommand;
45 import jalview.commands.RemoveGapColCommand;
46 import jalview.commands.RemoveGapsCommand;
47 import jalview.commands.SlideSequencesCommand;
48 import jalview.commands.TrimRegionCommand;
49 import jalview.controller.AlignViewController;
50 import jalview.datamodel.AlignedCodonFrame;
51 import jalview.datamodel.Alignment;
52 import jalview.datamodel.AlignmentAnnotation;
53 import jalview.datamodel.AlignmentExportData;
54 import jalview.datamodel.AlignmentI;
55 import jalview.datamodel.AlignmentOrder;
56 import jalview.datamodel.AlignmentView;
57 import jalview.datamodel.ColumnSelection;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.PDBEntry;
60 import jalview.datamodel.SeqCigar;
61 import jalview.datamodel.Sequence;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
65 import jalview.io.AlignmentProperties;
66 import jalview.io.AnnotationFile;
67 import jalview.io.AppletFormatAdapter;
68 import jalview.io.BioJsHTMLOutput;
69 import jalview.io.FileLoader;
70 import jalview.io.FormatAdapter;
71 import jalview.io.HtmlSvgOutput;
72 import jalview.io.IdentifyFile;
73 import jalview.io.JPredFile;
74 import jalview.io.JalviewFileChooser;
75 import jalview.io.JalviewFileView;
76 import jalview.io.JnetAnnotationMaker;
77 import jalview.io.NewickFile;
78 import jalview.io.TCoffeeScoreFile;
79 import jalview.jbgui.GAlignFrame;
80 import jalview.schemes.Blosum62ColourScheme;
81 import jalview.schemes.BuriedColourScheme;
82 import jalview.schemes.ClustalxColourScheme;
83 import jalview.schemes.ColourSchemeI;
84 import jalview.schemes.ColourSchemeProperty;
85 import jalview.schemes.HelixColourScheme;
86 import jalview.schemes.HydrophobicColourScheme;
87 import jalview.schemes.NucleotideColourScheme;
88 import jalview.schemes.PIDColourScheme;
89 import jalview.schemes.PurinePyrimidineColourScheme;
90 import jalview.schemes.RNAHelicesColour;
91 import jalview.schemes.RNAHelicesColourChooser;
92 import jalview.schemes.ResidueProperties;
93 import jalview.schemes.StrandColourScheme;
94 import jalview.schemes.TCoffeeColourScheme;
95 import jalview.schemes.TaylorColourScheme;
96 import jalview.schemes.TurnColourScheme;
97 import jalview.schemes.UserColourScheme;
98 import jalview.schemes.ZappoColourScheme;
99 import jalview.structure.StructureSelectionManager;
100 import jalview.util.MessageManager;
101 import jalview.util.Platform;
102 import jalview.viewmodel.AlignmentViewport;
103 import jalview.ws.DBRefFetcher;
104 import jalview.ws.WSMenuEntryProviderI;
105 import jalview.ws.jws1.Discoverer;
106 import jalview.ws.jws2.Jws2Discoverer;
107 import jalview.ws.jws2.jabaws2.Jws2Instance;
108 import jalview.ws.rest.RestClient;
109 import jalview.ws.seqfetcher.DbSourceProxy;
111 import java.awt.BorderLayout;
112 import java.awt.Component;
113 import java.awt.Rectangle;
114 import java.awt.Toolkit;
115 import java.awt.datatransfer.Clipboard;
116 import java.awt.datatransfer.DataFlavor;
117 import java.awt.datatransfer.StringSelection;
118 import java.awt.datatransfer.Transferable;
119 import java.awt.dnd.DnDConstants;
120 import java.awt.dnd.DropTargetDragEvent;
121 import java.awt.dnd.DropTargetDropEvent;
122 import java.awt.dnd.DropTargetEvent;
123 import java.awt.dnd.DropTargetListener;
124 import java.awt.event.ActionEvent;
125 import java.awt.event.ActionListener;
126 import java.awt.event.ItemEvent;
127 import java.awt.event.ItemListener;
128 import java.awt.event.KeyAdapter;
129 import java.awt.event.KeyEvent;
130 import java.awt.event.MouseAdapter;
131 import java.awt.event.MouseEvent;
132 import java.awt.print.PageFormat;
133 import java.awt.print.PrinterJob;
134 import java.beans.PropertyChangeEvent;
137 import java.util.ArrayList;
138 import java.util.Arrays;
139 import java.util.Deque;
140 import java.util.Enumeration;
141 import java.util.Hashtable;
142 import java.util.List;
143 import java.util.Set;
144 import java.util.Vector;
146 import javax.swing.JCheckBoxMenuItem;
147 import javax.swing.JEditorPane;
148 import javax.swing.JInternalFrame;
149 import javax.swing.JLayeredPane;
150 import javax.swing.JMenu;
151 import javax.swing.JMenuItem;
152 import javax.swing.JOptionPane;
153 import javax.swing.JRadioButtonMenuItem;
154 import javax.swing.JScrollPane;
155 import javax.swing.SwingUtilities;
157 import ext.vamsas.ServiceHandle;
163 * @version $Revision$
165 public class AlignFrame extends GAlignFrame implements DropTargetListener,
166 IProgressIndicator, AlignViewControllerGuiI
169 public static final int DEFAULT_WIDTH = 700;
171 public static final int DEFAULT_HEIGHT = 500;
174 * The currently displayed panel (selected tabbed view if more than one)
176 public AlignmentPanel alignPanel;
178 AlignViewport viewport;
180 public AlignViewControllerI avc;
182 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
185 * Last format used to load or save alignments in this window
187 String currentFileFormat = null;
190 * Current filename for this alignment
192 String fileName = null;
195 * Creates a new AlignFrame object with specific width and height.
201 public AlignFrame(AlignmentI al, int width, int height)
203 this(al, null, width, height);
207 * Creates a new AlignFrame object with specific width, height and
213 * @param sequenceSetId
215 public AlignFrame(AlignmentI al, int width, int height,
216 String sequenceSetId)
218 this(al, null, width, height, sequenceSetId);
222 * Creates a new AlignFrame object with specific width, height and
228 * @param sequenceSetId
231 public AlignFrame(AlignmentI al, int width, int height,
232 String sequenceSetId, String viewId)
234 this(al, null, width, height, sequenceSetId, viewId);
238 * new alignment window with hidden columns
242 * @param hiddenColumns
243 * ColumnSelection or null
245 * Width of alignment frame
249 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
250 int width, int height)
252 this(al, hiddenColumns, width, height, null);
257 * Create alignment frame for al with hiddenColumns, a specific width and
258 * height, and specific sequenceId
261 * @param hiddenColumns
264 * @param sequenceSetId
267 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
268 int width, int height, String sequenceSetId)
270 this(al, hiddenColumns, width, height, sequenceSetId, null);
274 * Create alignment frame for al with hiddenColumns, a specific width and
275 * height, and specific sequenceId
278 * @param hiddenColumns
281 * @param sequenceSetId
286 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
287 int width, int height, String sequenceSetId, String viewId)
289 setSize(width, height);
291 if (al.getDataset() == null)
296 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
298 alignPanel = new AlignmentPanel(this, viewport);
301 addAlignmentPanel(alignPanel, true);
305 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
306 ColumnSelection hiddenColumns, int width, int height)
308 setSize(width, height);
310 if (al.getDataset() == null)
315 viewport = new AlignViewport(al, hiddenColumns);
317 if (hiddenSeqs != null && hiddenSeqs.length > 0)
319 viewport.hideSequence(hiddenSeqs);
321 alignPanel = new AlignmentPanel(this, viewport);
322 addAlignmentPanel(alignPanel, true);
328 * Make a new AlignFrame from existing alignmentPanels
335 public AlignFrame(AlignmentPanel ap)
339 addAlignmentPanel(ap, false);
344 * initalise the alignframe from the underlying viewport data and the
349 if (!Jalview.isHeadlessMode())
351 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
354 avc = new AlignViewController(this, viewport,
356 if (viewport.getAlignmentConservationAnnotation() == null)
358 BLOSUM62Colour.setEnabled(false);
359 conservationMenuItem.setEnabled(false);
360 modifyConservation.setEnabled(false);
361 // PIDColour.setEnabled(false);
362 // abovePIDThreshold.setEnabled(false);
363 // modifyPID.setEnabled(false);
366 String sortby = Cache.getDefault("SORT_ALIGNMENT",
369 if (sortby.equals("Id"))
371 sortIDMenuItem_actionPerformed(null);
373 else if (sortby.equals("Pairwise Identity"))
375 sortPairwiseMenuItem_actionPerformed(null);
378 if (Desktop.desktop != null)
380 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
381 addServiceListeners();
382 setGUINucleotide(viewport.getAlignment().isNucleotide());
385 setMenusFromViewport(viewport);
386 buildSortByAnnotationScoresMenu();
389 if (viewport.getWrapAlignment())
391 wrapMenuItem_actionPerformed(null);
394 if (Cache.getDefault("SHOW_OVERVIEW", false))
396 this.overviewMenuItem_actionPerformed(null);
401 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
402 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
403 final String menuLabel = MessageManager
404 .getString("label.copy_format_from");
405 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
406 new ViewSetProvider()
410 public AlignmentPanel[] getAllAlignmentPanels()
413 origview.add(alignPanel);
414 // make an array of all alignment panels except for this one
415 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
416 Arrays.asList(Desktop.getAlignmentPanels(null)));
417 aps.remove(AlignFrame.this.alignPanel);
418 return aps.toArray(new AlignmentPanel[aps.size()]);
420 }, selviews, new ItemListener()
424 public void itemStateChanged(ItemEvent e)
426 if (origview.size() > 0)
428 final AlignmentPanel ap = origview.get(0);
431 * Copy the ViewStyle of the selected panel to 'this one'.
432 * Don't change value of 'scaleProteinAsCdna' unless copying
435 ViewStyleI vs = selviews.get(0).getAlignViewport()
437 boolean fromSplitFrame = selviews.get(0)
438 .getAlignViewport().getCodingComplement() != null;
441 vs.setScaleProteinAsCdna(ap.getAlignViewport()
442 .getViewStyle().isScaleProteinAsCdna());
444 ap.getAlignViewport().setViewStyle(vs);
447 * Also rescale ViewStyle of SplitFrame complement if there is
448 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
449 * the whole ViewStyle (allow cDNA protein to have different
452 AlignViewportI complement = ap.getAlignViewport()
453 .getCodingComplement();
454 if (complement != null && vs.isScaleProteinAsCdna())
456 AlignFrame af = Desktop.getAlignFrameFor(complement);
457 ((SplitFrame) af.getSplitViewContainer())
459 af.setMenusForViewport();
463 ap.setSelected(true);
464 ap.alignFrame.setMenusForViewport();
469 formatMenu.add(vsel);
474 * Change the filename and format for the alignment, and enable the 'reload'
475 * button functionality.
482 public void setFileName(String file, String format)
485 setFileFormat(format);
486 reload.setEnabled(true);
490 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
493 void addKeyListener()
495 addKeyListener(new KeyAdapter()
498 public void keyPressed(KeyEvent evt)
500 if (viewport.cursorMode
501 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
502 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
503 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
504 && Character.isDigit(evt.getKeyChar()))
506 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
509 switch (evt.getKeyCode())
512 case 27: // escape key
513 deselectAllSequenceMenuItem_actionPerformed(null);
517 case KeyEvent.VK_DOWN:
518 if (evt.isAltDown() || !viewport.cursorMode)
520 moveSelectedSequences(false);
522 if (viewport.cursorMode)
524 alignPanel.getSeqPanel().moveCursor(0, 1);
529 if (evt.isAltDown() || !viewport.cursorMode)
531 moveSelectedSequences(true);
533 if (viewport.cursorMode)
535 alignPanel.getSeqPanel().moveCursor(0, -1);
540 case KeyEvent.VK_LEFT:
541 if (evt.isAltDown() || !viewport.cursorMode)
543 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
547 alignPanel.getSeqPanel().moveCursor(-1, 0);
552 case KeyEvent.VK_RIGHT:
553 if (evt.isAltDown() || !viewport.cursorMode)
555 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
559 alignPanel.getSeqPanel().moveCursor(1, 0);
563 case KeyEvent.VK_SPACE:
564 if (viewport.cursorMode)
566 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
567 || evt.isShiftDown() || evt.isAltDown());
571 // case KeyEvent.VK_A:
572 // if (viewport.cursorMode)
574 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
575 // //System.out.println("A");
579 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
580 * System.out.println("closing bracket"); } break;
582 case KeyEvent.VK_DELETE:
583 case KeyEvent.VK_BACK_SPACE:
584 if (!viewport.cursorMode)
586 cut_actionPerformed(null);
590 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
591 || evt.isShiftDown() || evt.isAltDown());
597 if (viewport.cursorMode)
599 alignPanel.getSeqPanel().setCursorRow();
603 if (viewport.cursorMode && !evt.isControlDown())
605 alignPanel.getSeqPanel().setCursorColumn();
609 if (viewport.cursorMode)
611 alignPanel.getSeqPanel().setCursorPosition();
615 case KeyEvent.VK_ENTER:
616 case KeyEvent.VK_COMMA:
617 if (viewport.cursorMode)
619 alignPanel.getSeqPanel().setCursorRowAndColumn();
624 if (viewport.cursorMode)
626 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
630 if (viewport.cursorMode)
632 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
637 viewport.cursorMode = !viewport.cursorMode;
638 statusBar.setText(MessageManager.formatMessage(
639 "label.keyboard_editing_mode", new String[]
640 { (viewport.cursorMode ? "on" : "off") }));
641 if (viewport.cursorMode)
643 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
644 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
646 alignPanel.getSeqPanel().seqCanvas.repaint();
652 Help.showHelpWindow();
653 } catch (Exception ex)
655 ex.printStackTrace();
660 boolean toggleSeqs = !evt.isControlDown();
661 boolean toggleCols = !evt.isShiftDown();
662 toggleHiddenRegions(toggleSeqs, toggleCols);
665 case KeyEvent.VK_PAGE_UP:
666 if (viewport.getWrapAlignment())
668 alignPanel.scrollUp(true);
672 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
673 - viewport.endSeq + viewport.startSeq);
676 case KeyEvent.VK_PAGE_DOWN:
677 if (viewport.getWrapAlignment())
679 alignPanel.scrollUp(false);
683 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
684 + viewport.endSeq - viewport.startSeq);
691 public void keyReleased(KeyEvent evt)
693 switch (evt.getKeyCode())
695 case KeyEvent.VK_LEFT:
696 if (evt.isAltDown() || !viewport.cursorMode)
698 viewport.firePropertyChange("alignment", null, viewport
699 .getAlignment().getSequences());
703 case KeyEvent.VK_RIGHT:
704 if (evt.isAltDown() || !viewport.cursorMode)
706 viewport.firePropertyChange("alignment", null, viewport
707 .getAlignment().getSequences());
715 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
717 ap.alignFrame = this;
718 avc = new AlignViewController(this, viewport, alignPanel);
722 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
724 int aSize = alignPanels.size();
726 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
728 if (aSize == 1 && ap.av.viewName == null)
730 this.getContentPane().add(ap, BorderLayout.CENTER);
736 setInitialTabVisible();
739 expandViews.setEnabled(true);
740 gatherViews.setEnabled(true);
741 tabbedPane.addTab(ap.av.viewName, ap);
743 ap.setVisible(false);
748 if (ap.av.isPadGaps())
750 ap.av.getAlignment().padGaps();
752 ap.av.updateConservation(ap);
753 ap.av.updateConsensus(ap);
754 ap.av.updateStrucConsensus(ap);
758 public void setInitialTabVisible()
760 expandViews.setEnabled(true);
761 gatherViews.setEnabled(true);
762 tabbedPane.setVisible(true);
763 AlignmentPanel first = alignPanels.get(0);
764 tabbedPane.addTab(first.av.viewName, first);
765 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
768 public AlignViewport getViewport()
773 /* Set up intrinsic listeners for dynamically generated GUI bits. */
774 private void addServiceListeners()
776 final java.beans.PropertyChangeListener thisListener;
777 Desktop.instance.addJalviewPropertyChangeListener("services",
778 thisListener = new java.beans.PropertyChangeListener()
781 public void propertyChange(PropertyChangeEvent evt)
783 // // System.out.println("Discoverer property change.");
784 // if (evt.getPropertyName().equals("services"))
786 SwingUtilities.invokeLater(new Runnable()
793 .println("Rebuild WS Menu for service change");
794 BuildWebServiceMenu();
801 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
804 public void internalFrameClosed(
805 javax.swing.event.InternalFrameEvent evt)
807 System.out.println("deregistering discoverer listener");
808 Desktop.instance.removeJalviewPropertyChangeListener("services",
810 closeMenuItem_actionPerformed(true);
813 // Finally, build the menu once to get current service state
814 new Thread(new Runnable()
819 BuildWebServiceMenu();
825 * Configure menu items that vary according to whether the alignment is
826 * nucleotide or protein
830 public void setGUINucleotide(boolean nucleotide)
832 showTranslation.setVisible(nucleotide);
833 conservationMenuItem.setEnabled(!nucleotide);
834 modifyConservation.setEnabled(!nucleotide);
835 showGroupConservation.setEnabled(!nucleotide);
836 rnahelicesColour.setEnabled(nucleotide);
837 purinePyrimidineColour.setEnabled(nucleotide);
838 showComplementMenuItem.setText(MessageManager
839 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
840 setColourSelected(Cache.getDefault(
841 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
842 : Preferences.DEFAULT_COLOUR_PROT, "None"));
846 * set up menus for the current viewport. This may be called after any
847 * operation that affects the data in the current view (selection changed,
848 * etc) to update the menus to reflect the new state.
850 public void setMenusForViewport()
852 setMenusFromViewport(viewport);
856 * Need to call this method when tabs are selected for multiple views, or when
857 * loading from Jalview2XML.java
862 void setMenusFromViewport(AlignViewport av)
864 padGapsMenuitem.setSelected(av.isPadGaps());
865 colourTextMenuItem.setSelected(av.isShowColourText());
866 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
867 conservationMenuItem.setSelected(av.getConservationSelected());
868 seqLimits.setSelected(av.getShowJVSuffix());
869 idRightAlign.setSelected(av.isRightAlignIds());
870 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
871 renderGapsMenuItem.setSelected(av.isRenderGaps());
872 wrapMenuItem.setSelected(av.getWrapAlignment());
873 scaleAbove.setVisible(av.getWrapAlignment());
874 scaleLeft.setVisible(av.getWrapAlignment());
875 scaleRight.setVisible(av.getWrapAlignment());
876 annotationPanelMenuItem.setState(av.isShowAnnotation());
878 * Show/hide annotations only enabled if annotation panel is shown
880 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
881 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
882 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
883 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
884 viewBoxesMenuItem.setSelected(av.getShowBoxes());
885 viewTextMenuItem.setSelected(av.getShowText());
886 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
887 showGroupConsensus.setSelected(av.isShowGroupConsensus());
888 showGroupConservation.setSelected(av.isShowGroupConservation());
889 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
890 showSequenceLogo.setSelected(av.isShowSequenceLogo());
891 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
893 setColourSelected(ColourSchemeProperty.getColourName(av
894 .getGlobalColourScheme()));
896 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
897 hiddenMarkers.setState(av.getShowHiddenMarkers());
898 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
899 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
900 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
901 autoCalculate.setSelected(av.autoCalculateConsensus);
902 sortByTree.setSelected(av.sortByTree);
903 listenToViewSelections.setSelected(av.followSelection);
904 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
906 .setSelected(av.getGlobalColourScheme() instanceof RNAHelicesColour);
907 setShowProductsEnabled();
911 private IProgressIndicator progressBar;
916 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
919 public void setProgressBar(String message, long id)
921 progressBar.setProgressBar(message, id);
925 public void registerHandler(final long id,
926 final IProgressIndicatorHandler handler)
928 progressBar.registerHandler(id, handler);
933 * @return true if any progress bars are still active
936 public boolean operationInProgress()
938 return progressBar.operationInProgress();
942 public void setStatus(String text)
944 statusBar.setText(text);
948 * Added so Castor Mapping file can obtain Jalview Version
950 public String getVersion()
952 return Cache.getProperty("VERSION");
955 public FeatureRenderer getFeatureRenderer()
957 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
961 public void fetchSequence_actionPerformed(ActionEvent e)
963 new SequenceFetcher(this);
967 public void addFromFile_actionPerformed(ActionEvent e)
969 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
973 public void reload_actionPerformed(ActionEvent e)
975 if (fileName != null)
977 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
978 // originating file's format
979 // TODO: work out how to recover feature settings for correct view(s) when
981 if (currentFileFormat.equals("Jalview"))
983 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
984 for (int i = 0; i < frames.length; i++)
986 if (frames[i] instanceof AlignFrame && frames[i] != this
987 && ((AlignFrame) frames[i]).fileName != null
988 && ((AlignFrame) frames[i]).fileName.equals(fileName))
992 frames[i].setSelected(true);
993 Desktop.instance.closeAssociatedWindows();
994 } catch (java.beans.PropertyVetoException ex)
1000 Desktop.instance.closeAssociatedWindows();
1002 FileLoader loader = new FileLoader();
1003 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1004 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1008 Rectangle bounds = this.getBounds();
1010 FileLoader loader = new FileLoader();
1011 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1012 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1013 protocol, currentFileFormat);
1015 newframe.setBounds(bounds);
1016 if (featureSettings != null && featureSettings.isShowing())
1018 final Rectangle fspos = featureSettings.frame.getBounds();
1019 // TODO: need a 'show feature settings' function that takes bounds -
1020 // need to refactor Desktop.addFrame
1021 newframe.featureSettings_actionPerformed(null);
1022 final FeatureSettings nfs = newframe.featureSettings;
1023 SwingUtilities.invokeLater(new Runnable()
1028 nfs.frame.setBounds(fspos);
1031 this.featureSettings.close();
1032 this.featureSettings = null;
1034 this.closeMenuItem_actionPerformed(true);
1040 public void addFromText_actionPerformed(ActionEvent e)
1042 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1046 public void addFromURL_actionPerformed(ActionEvent e)
1048 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1052 public void save_actionPerformed(ActionEvent e)
1054 if (fileName == null
1055 || (currentFileFormat == null || !FormatAdapter
1056 .isValidIOFormat(currentFileFormat, true))
1057 || fileName.startsWith("http"))
1059 saveAs_actionPerformed(null);
1063 saveAlignment(fileName, currentFileFormat);
1074 public void saveAs_actionPerformed(ActionEvent e)
1076 JalviewFileChooser chooser = new JalviewFileChooser(
1077 Cache.getProperty("LAST_DIRECTORY"),
1078 AppletFormatAdapter.WRITABLE_EXTENSIONS,
1079 AppletFormatAdapter.WRITABLE_FNAMES,
1080 currentFileFormat, false);
1082 chooser.setFileView(new JalviewFileView());
1083 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1084 chooser.setToolTipText(MessageManager.getString("action.save"));
1086 int value = chooser.showSaveDialog(this);
1088 if (value == JalviewFileChooser.APPROVE_OPTION)
1090 currentFileFormat = chooser.getSelectedFormat();
1091 while (currentFileFormat == null)
1094 .showInternalMessageDialog(
1097 .getString("label.select_file_format_before_saving"),
1099 .getString("label.file_format_not_specified"),
1100 JOptionPane.WARNING_MESSAGE);
1101 currentFileFormat = chooser.getSelectedFormat();
1102 value = chooser.showSaveDialog(this);
1103 if (value != JalviewFileChooser.APPROVE_OPTION)
1109 fileName = chooser.getSelectedFile().getPath();
1111 Cache.setProperty("DEFAULT_FILE_FORMAT",
1114 Cache.setProperty("LAST_DIRECTORY", fileName);
1115 if (currentFileFormat.indexOf(" ") > -1)
1117 currentFileFormat = currentFileFormat.substring(0,
1118 currentFileFormat.indexOf(" "));
1120 saveAlignment(fileName, currentFileFormat);
1124 public boolean saveAlignment(String file, String format)
1126 boolean success = true;
1128 if (format.equalsIgnoreCase("Jalview"))
1130 String shortName = title;
1132 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1134 shortName = shortName.substring(shortName
1135 .lastIndexOf(java.io.File.separatorChar) + 1);
1138 success = new Jalview2XML().saveAlignment(this, file, shortName);
1140 statusBar.setText(MessageManager.formatMessage(
1141 "label.successfully_saved_to_file_in_format", new Object[]
1142 { fileName, format }));
1147 if (!AppletFormatAdapter.isValidFormat(format, true))
1149 warningMessage("Cannot save file " + fileName + " using format "
1150 + format, "Alignment output format not supported");
1151 if (!Jalview.isHeadlessMode())
1153 saveAs_actionPerformed(null);
1158 AlignmentExportData exportData = getAlignmentForExport(format, viewport);
1159 if (exportData.getSettings().isCancelled())
1163 FormatAdapter f = new FormatAdapter(alignPanel,
1164 exportData.getSettings());
1165 String output = f.formatSequences(format,
1166 exportData.getAlignment(), // class cast exceptions will
1167 // occur in the distant future
1168 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1169 f.getCacheSuffixDefault(format),
1170 viewport.getColumnSelection());
1180 java.io.PrintWriter out = new java.io.PrintWriter(
1181 new java.io.FileWriter(file));
1185 this.setTitle(file);
1186 statusBar.setText(MessageManager.formatMessage(
1187 "label.successfully_saved_to_file_in_format",
1189 { fileName, format }));
1190 } catch (Exception ex)
1193 ex.printStackTrace();
1200 JOptionPane.showInternalMessageDialog(this, MessageManager
1201 .formatMessage("label.couldnt_save_file", new Object[]
1202 { fileName }), MessageManager
1203 .getString("label.error_saving_file"),
1204 JOptionPane.WARNING_MESSAGE);
1211 private void warningMessage(String warning, String title)
1213 if (Platform.isHeadless())
1215 System.err.println("Warning: " + title + "\nWarning: " + warning);
1220 JOptionPane.showInternalMessageDialog(this, warning, title,
1221 JOptionPane.WARNING_MESSAGE);
1233 protected void outputText_actionPerformed(ActionEvent e)
1236 AlignmentExportData exportData = getAlignmentForExport(
1237 e.getActionCommand(), viewport);
1238 if (exportData.getSettings().isCancelled())
1242 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1243 cap.setForInput(null);
1246 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1248 e.getActionCommand(),
1249 exportData.getAlignment(),
1250 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1251 viewport.getColumnSelection()));
1252 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1253 "label.alignment_output_command", new Object[]
1254 { e.getActionCommand() }), 600, 500);
1255 } catch (OutOfMemoryError oom)
1257 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1263 public static AlignmentExportData getAlignmentForExport(String exportFomat,
1264 AlignViewportI viewport)
1266 AlignmentI alignmentToExport = null;
1267 String[] omitHidden = null;
1268 int[] alignmentStartEnd = new int[2];
1270 HiddenSequences hiddenSeqs = viewport.getAlignment()
1271 .getHiddenSequences();
1274 alignmentToExport = viewport.getAlignment();
1275 alignmentStartEnd = new int[]
1276 { 0, alignmentToExport.getWidth() - 1 };
1278 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1279 AlignExportSettings settings = new AlignExportSettings(hasHiddenSeqs,
1280 viewport.hasHiddenColumns(), exportFomat);
1281 settings.isExportAnnotations();
1283 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1285 omitHidden = viewport.getViewAsString(false);
1288 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1290 alignmentToExport = hiddenSeqs.getFullAlignment();
1294 alignmentToExport = viewport.getAlignment();
1295 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1296 .getColumnSelection().getHiddenColumns());
1298 AlignmentExportData ed = new AlignmentExportData(alignmentToExport, omitHidden, alignmentStartEnd,
1303 private static int[] getStartEnd(int[] aligmentStartEnd,
1304 List<int[]> hiddenCols)
1306 int startPos = aligmentStartEnd[0];
1307 int endPos = aligmentStartEnd[1];
1309 int[] lowestRange = new int[2];
1310 int[] higestRange = new int[2];
1312 for (int[] hiddenCol : hiddenCols)
1314 // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
1316 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1317 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1319 // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
1320 // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
1322 if (lowestRange[0] == 0 && lowestRange[1] == 0)
1324 startPos = aligmentStartEnd[0];
1328 startPos = lowestRange[1] + 1;
1331 if (higestRange[0] == 0 && higestRange[1] == 0)
1333 endPos = aligmentStartEnd[1];
1337 endPos = higestRange[0];
1340 // System.out.println("Export range : " + minPos + " - " + maxPos);
1342 { startPos, endPos };
1345 public static void main(String[] args)
1347 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1348 hiddenCols.add(new int[]
1350 hiddenCols.add(new int[]
1352 hiddenCols.add(new int[]
1354 hiddenCols.add(new int[]
1356 hiddenCols.add(new int[]
1359 int[] x = getStartEnd(new int[]
1360 { 0, 50 }, hiddenCols);
1361 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1371 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1373 new HtmlSvgOutput(null, alignPanel);
1377 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1379 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1380 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1382 public void createImageMap(File file, String image)
1384 alignPanel.makePNGImageMap(file, image);
1394 public void createPNG(File f)
1396 alignPanel.makePNG(f);
1406 public void createEPS(File f)
1408 alignPanel.makeEPS(f);
1411 public void createSVG(File f)
1413 alignPanel.makeSVG(f);
1416 public void pageSetup_actionPerformed(ActionEvent e)
1418 PrinterJob printJob = PrinterJob.getPrinterJob();
1419 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1429 public void printMenuItem_actionPerformed(ActionEvent e)
1431 // Putting in a thread avoids Swing painting problems
1432 PrintThread thread = new PrintThread(alignPanel);
1437 public void exportFeatures_actionPerformed(ActionEvent e)
1439 new AnnotationExporter().exportFeatures(alignPanel);
1443 public void exportAnnotations_actionPerformed(ActionEvent e)
1445 new AnnotationExporter().exportAnnotations(alignPanel);
1449 public void associatedData_actionPerformed(ActionEvent e)
1451 // Pick the tree file
1452 JalviewFileChooser chooser = new JalviewFileChooser(
1453 Cache.getProperty("LAST_DIRECTORY"));
1454 chooser.setFileView(new JalviewFileView());
1455 chooser.setDialogTitle(MessageManager
1456 .getString("label.load_jalview_annotations"));
1457 chooser.setToolTipText(MessageManager
1458 .getString("label.load_jalview_annotations"));
1460 int value = chooser.showOpenDialog(null);
1462 if (value == JalviewFileChooser.APPROVE_OPTION)
1464 String choice = chooser.getSelectedFile().getPath();
1465 Cache.setProperty("LAST_DIRECTORY", choice);
1466 loadJalviewDataFile(choice, null, null, null);
1472 * Close the current view or all views in the alignment frame. If the frame
1473 * only contains one view then the alignment will be removed from memory.
1475 * @param closeAllTabs
1478 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1480 if (alignPanels != null && alignPanels.size() < 2)
1482 closeAllTabs = true;
1487 if (alignPanels != null)
1491 if (this.isClosed())
1493 // really close all the windows - otherwise wait till
1494 // setClosed(true) is called
1495 for (int i = 0; i < alignPanels.size(); i++)
1497 AlignmentPanel ap = alignPanels.get(i);
1504 closeView(alignPanel);
1510 this.setClosed(true);
1512 } catch (Exception ex)
1514 ex.printStackTrace();
1519 * Close the specified panel and close up tabs appropriately.
1521 * @param panelToClose
1523 public void closeView(AlignmentPanel panelToClose)
1525 int index = tabbedPane.getSelectedIndex();
1526 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1527 alignPanels.remove(panelToClose);
1528 panelToClose.closePanel();
1529 panelToClose = null;
1531 tabbedPane.removeTabAt(closedindex);
1532 tabbedPane.validate();
1534 if (index > closedindex || index == tabbedPane.getTabCount())
1536 // modify currently selected tab index if necessary.
1540 this.tabSelectionChanged(index);
1546 void updateEditMenuBar()
1549 if (viewport.getHistoryList().size() > 0)
1551 undoMenuItem.setEnabled(true);
1552 CommandI command = viewport.getHistoryList().peek();
1553 undoMenuItem.setText(MessageManager.formatMessage(
1554 "label.undo_command", new Object[]
1555 { command.getDescription() }));
1559 undoMenuItem.setEnabled(false);
1560 undoMenuItem.setText(MessageManager.getString("action.undo"));
1563 if (viewport.getRedoList().size() > 0)
1565 redoMenuItem.setEnabled(true);
1567 CommandI command = viewport.getRedoList().peek();
1568 redoMenuItem.setText(MessageManager.formatMessage(
1569 "label.redo_command", new Object[]
1570 { command.getDescription() }));
1574 redoMenuItem.setEnabled(false);
1575 redoMenuItem.setText(MessageManager.getString("action.redo"));
1579 public void addHistoryItem(CommandI command)
1581 if (command.getSize() > 0)
1583 viewport.addToHistoryList(command);
1584 viewport.clearRedoList();
1585 updateEditMenuBar();
1586 viewport.updateHiddenColumns();
1587 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1588 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1589 // viewport.getColumnSelection()
1590 // .getHiddenColumns().size() > 0);
1596 * @return alignment objects for all views
1598 AlignmentI[] getViewAlignments()
1600 if (alignPanels != null)
1602 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1604 for (AlignmentPanel ap : alignPanels)
1606 als[i++] = ap.av.getAlignment();
1610 if (viewport != null)
1612 return new AlignmentI[]
1613 { viewport.getAlignment() };
1625 protected void undoMenuItem_actionPerformed(ActionEvent e)
1627 if (viewport.getHistoryList().isEmpty())
1631 CommandI command = viewport.getHistoryList().pop();
1632 viewport.addToRedoList(command);
1633 command.undoCommand(getViewAlignments());
1635 AlignmentViewport originalSource = getOriginatingSource(command);
1636 updateEditMenuBar();
1638 if (originalSource != null)
1640 if (originalSource != viewport)
1643 .warn("Implementation worry: mismatch of viewport origin for undo");
1645 originalSource.updateHiddenColumns();
1646 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1648 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1649 // viewport.getColumnSelection()
1650 // .getHiddenColumns().size() > 0);
1651 originalSource.firePropertyChange("alignment", null, originalSource
1652 .getAlignment().getSequences());
1663 protected void redoMenuItem_actionPerformed(ActionEvent e)
1665 if (viewport.getRedoList().size() < 1)
1670 CommandI command = viewport.getRedoList().pop();
1671 viewport.addToHistoryList(command);
1672 command.doCommand(getViewAlignments());
1674 AlignmentViewport originalSource = getOriginatingSource(command);
1675 updateEditMenuBar();
1677 if (originalSource != null)
1680 if (originalSource != viewport)
1683 .warn("Implementation worry: mismatch of viewport origin for redo");
1685 originalSource.updateHiddenColumns();
1686 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1688 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1689 // viewport.getColumnSelection()
1690 // .getHiddenColumns().size() > 0);
1691 originalSource.firePropertyChange("alignment", null, originalSource
1692 .getAlignment().getSequences());
1696 AlignmentViewport getOriginatingSource(CommandI command)
1698 AlignmentViewport originalSource = null;
1699 // For sequence removal and addition, we need to fire
1700 // the property change event FROM the viewport where the
1701 // original alignment was altered
1702 AlignmentI al = null;
1703 if (command instanceof EditCommand)
1705 EditCommand editCommand = (EditCommand) command;
1706 al = editCommand.getAlignment();
1707 List<Component> comps = PaintRefresher.components.get(viewport
1708 .getSequenceSetId());
1710 for (Component comp : comps)
1712 if (comp instanceof AlignmentPanel)
1714 if (al == ((AlignmentPanel) comp).av.getAlignment())
1716 originalSource = ((AlignmentPanel) comp).av;
1723 if (originalSource == null)
1725 // The original view is closed, we must validate
1726 // the current view against the closed view first
1729 PaintRefresher.validateSequences(al, viewport.getAlignment());
1732 originalSource = viewport;
1735 return originalSource;
1744 public void moveSelectedSequences(boolean up)
1746 SequenceGroup sg = viewport.getSelectionGroup();
1752 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1753 viewport.getHiddenRepSequences(), up);
1754 alignPanel.paintAlignment(true);
1757 synchronized void slideSequences(boolean right, int size)
1759 List<SequenceI> sg = new ArrayList<SequenceI>();
1760 if (viewport.cursorMode)
1762 sg.add(viewport.getAlignment().getSequenceAt(
1763 alignPanel.getSeqPanel().seqCanvas.cursorY));
1765 else if (viewport.getSelectionGroup() != null
1766 && viewport.getSelectionGroup().getSize() != viewport
1767 .getAlignment().getHeight())
1769 sg = viewport.getSelectionGroup().getSequences(
1770 viewport.getHiddenRepSequences());
1778 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1780 for (SequenceI seq : viewport.getAlignment().getSequences())
1782 if (!sg.contains(seq))
1784 invertGroup.add(seq);
1788 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1790 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1791 for (int i = 0; i < invertGroup.size(); i++)
1793 seqs2[i] = invertGroup.get(i);
1796 SlideSequencesCommand ssc;
1799 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1800 size, viewport.getGapCharacter());
1804 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1805 size, viewport.getGapCharacter());
1808 int groupAdjustment = 0;
1809 if (ssc.getGapsInsertedBegin() && right)
1811 if (viewport.cursorMode)
1813 alignPanel.getSeqPanel().moveCursor(size, 0);
1817 groupAdjustment = size;
1820 else if (!ssc.getGapsInsertedBegin() && !right)
1822 if (viewport.cursorMode)
1824 alignPanel.getSeqPanel().moveCursor(-size, 0);
1828 groupAdjustment = -size;
1832 if (groupAdjustment != 0)
1834 viewport.getSelectionGroup().setStartRes(
1835 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1836 viewport.getSelectionGroup().setEndRes(
1837 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1841 * just extend the last slide command if compatible; but not if in
1842 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1844 boolean appendHistoryItem = false;
1845 Deque<CommandI> historyList = viewport.getHistoryList();
1846 boolean inSplitFrame = getSplitViewContainer() != null;
1847 if (!inSplitFrame && historyList != null
1848 && historyList.size() > 0
1849 && historyList.peek() instanceof SlideSequencesCommand)
1851 appendHistoryItem = ssc
1852 .appendSlideCommand((SlideSequencesCommand) historyList
1856 if (!appendHistoryItem)
1858 addHistoryItem(ssc);
1871 protected void copy_actionPerformed(ActionEvent e)
1874 if (viewport.getSelectionGroup() == null)
1878 // TODO: preserve the ordering of displayed alignment annotation in any
1879 // internal paste (particularly sequence associated annotation)
1880 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1881 String[] omitHidden = null;
1883 if (viewport.hasHiddenColumns())
1885 omitHidden = viewport.getViewAsString(true);
1888 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1891 StringSelection ss = new StringSelection(output);
1895 Desktop.internalCopy = true;
1896 // Its really worth setting the clipboard contents
1897 // to empty before setting the large StringSelection!!
1898 Toolkit.getDefaultToolkit().getSystemClipboard()
1899 .setContents(new StringSelection(""), null);
1901 Toolkit.getDefaultToolkit().getSystemClipboard()
1902 .setContents(ss, Desktop.instance);
1903 } catch (OutOfMemoryError er)
1905 new OOMWarning("copying region", er);
1909 ArrayList<int[]> hiddenColumns = null;
1910 if (viewport.hasHiddenColumns())
1912 hiddenColumns = new ArrayList<int[]>();
1913 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1914 .getSelectionGroup().getEndRes();
1915 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1917 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1919 hiddenColumns.add(new int[]
1920 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1925 Desktop.jalviewClipboard = new Object[]
1926 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1927 statusBar.setText(MessageManager.formatMessage(
1928 "label.copied_sequences_to_clipboard", new Object[]
1929 { Integer.valueOf(seqs.length).toString() }));
1939 protected void pasteNew_actionPerformed(ActionEvent e)
1951 protected void pasteThis_actionPerformed(ActionEvent e)
1957 * Paste contents of Jalview clipboard
1959 * @param newAlignment
1960 * true to paste to a new alignment, otherwise add to this.
1962 void paste(boolean newAlignment)
1964 boolean externalPaste = true;
1967 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1968 Transferable contents = c.getContents(this);
1970 if (contents == null)
1978 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1979 if (str.length() < 1)
1984 format = new IdentifyFile().Identify(str, "Paste");
1986 } catch (OutOfMemoryError er)
1988 new OOMWarning("Out of memory pasting sequences!!", er);
1992 SequenceI[] sequences;
1993 boolean annotationAdded = false;
1994 AlignmentI alignment = null;
1996 if (Desktop.jalviewClipboard != null)
1998 // The clipboard was filled from within Jalview, we must use the
2000 // And dataset from the copied alignment
2001 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2002 // be doubly sure that we create *new* sequence objects.
2003 sequences = new SequenceI[newseq.length];
2004 for (int i = 0; i < newseq.length; i++)
2006 sequences[i] = new Sequence(newseq[i]);
2008 alignment = new Alignment(sequences);
2009 externalPaste = false;
2013 // parse the clipboard as an alignment.
2014 alignment = new FormatAdapter().readFile(str, "Paste", format);
2015 sequences = alignment.getSequencesArray();
2019 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2025 if (Desktop.jalviewClipboard != null)
2027 // dataset is inherited
2028 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2032 // new dataset is constructed
2033 alignment.setDataset(null);
2035 alwidth = alignment.getWidth() + 1;
2039 AlignmentI pastedal = alignment; // preserve pasted alignment object
2040 // Add pasted sequences and dataset into existing alignment.
2041 alignment = viewport.getAlignment();
2042 alwidth = alignment.getWidth() + 1;
2043 // decide if we need to import sequences from an existing dataset
2044 boolean importDs = Desktop.jalviewClipboard != null
2045 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2046 // importDs==true instructs us to copy over new dataset sequences from
2047 // an existing alignment
2048 Vector newDs = (importDs) ? new Vector() : null; // used to create
2049 // minimum dataset set
2051 for (int i = 0; i < sequences.length; i++)
2055 newDs.addElement(null);
2057 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2059 if (importDs && ds != null)
2061 if (!newDs.contains(ds))
2063 newDs.setElementAt(ds, i);
2064 ds = new Sequence(ds);
2065 // update with new dataset sequence
2066 sequences[i].setDatasetSequence(ds);
2070 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2075 // copy and derive new dataset sequence
2076 sequences[i] = sequences[i].deriveSequence();
2077 alignment.getDataset().addSequence(
2078 sequences[i].getDatasetSequence());
2079 // TODO: avoid creation of duplicate dataset sequences with a
2080 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2082 alignment.addSequence(sequences[i]); // merges dataset
2086 newDs.clear(); // tidy up
2088 if (alignment.getAlignmentAnnotation() != null)
2090 for (AlignmentAnnotation alan : alignment
2091 .getAlignmentAnnotation())
2093 if (alan.graphGroup > fgroup)
2095 fgroup = alan.graphGroup;
2099 if (pastedal.getAlignmentAnnotation() != null)
2101 // Add any annotation attached to alignment.
2102 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2103 for (int i = 0; i < alann.length; i++)
2105 annotationAdded = true;
2106 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2108 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2109 if (newann.graphGroup > -1)
2111 if (newGraphGroups.size() <= newann.graphGroup
2112 || newGraphGroups.get(newann.graphGroup) == null)
2114 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2116 newGraphGroups.add(q, null);
2118 newGraphGroups.set(newann.graphGroup, new Integer(
2121 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2125 newann.padAnnotation(alwidth);
2126 alignment.addAnnotation(newann);
2136 addHistoryItem(new EditCommand(
2137 MessageManager.getString("label.add_sequences"),
2139 sequences, 0, alignment.getWidth(), alignment));
2141 // Add any annotations attached to sequences
2142 for (int i = 0; i < sequences.length; i++)
2144 if (sequences[i].getAnnotation() != null)
2146 AlignmentAnnotation newann;
2147 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2149 annotationAdded = true;
2150 newann = sequences[i].getAnnotation()[a];
2151 newann.adjustForAlignment();
2152 newann.padAnnotation(alwidth);
2153 if (newann.graphGroup > -1)
2155 if (newann.graphGroup > -1)
2157 if (newGraphGroups.size() <= newann.graphGroup
2158 || newGraphGroups.get(newann.graphGroup) == null)
2160 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2162 newGraphGroups.add(q, null);
2164 newGraphGroups.set(newann.graphGroup, new Integer(
2167 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2171 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2176 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2183 // propagate alignment changed.
2184 viewport.setEndSeq(alignment.getHeight());
2185 if (annotationAdded)
2187 // Duplicate sequence annotation in all views.
2188 AlignmentI[] alview = this.getViewAlignments();
2189 for (int i = 0; i < sequences.length; i++)
2191 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2196 for (int avnum = 0; avnum < alview.length; avnum++)
2198 if (alview[avnum] != alignment)
2200 // duplicate in a view other than the one with input focus
2201 int avwidth = alview[avnum].getWidth() + 1;
2202 // this relies on sann being preserved after we
2203 // modify the sequence's annotation array for each duplication
2204 for (int a = 0; a < sann.length; a++)
2206 AlignmentAnnotation newann = new AlignmentAnnotation(
2208 sequences[i].addAlignmentAnnotation(newann);
2209 newann.padAnnotation(avwidth);
2210 alview[avnum].addAnnotation(newann); // annotation was
2211 // duplicated earlier
2212 // TODO JAL-1145 graphGroups are not updated for sequence
2213 // annotation added to several views. This may cause
2215 alview[avnum].setAnnotationIndex(newann, a);
2220 buildSortByAnnotationScoresMenu();
2222 viewport.firePropertyChange("alignment", null,
2223 alignment.getSequences());
2224 if (alignPanels != null)
2226 for (AlignmentPanel ap : alignPanels)
2228 ap.validateAnnotationDimensions(false);
2233 alignPanel.validateAnnotationDimensions(false);
2239 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2241 String newtitle = new String("Copied sequences");
2243 if (Desktop.jalviewClipboard != null
2244 && Desktop.jalviewClipboard[2] != null)
2246 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2247 for (int[] region : hc)
2249 af.viewport.hideColumns(region[0], region[1]);
2253 // >>>This is a fix for the moment, until a better solution is
2255 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2257 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2259 // TODO: maintain provenance of an alignment, rather than just make the
2260 // title a concatenation of operations.
2263 if (title.startsWith("Copied sequences"))
2269 newtitle = newtitle.concat("- from " + title);
2274 newtitle = new String("Pasted sequences");
2277 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2282 } catch (Exception ex)
2284 ex.printStackTrace();
2285 System.out.println("Exception whilst pasting: " + ex);
2286 // could be anything being pasted in here
2292 protected void expand_newalign(ActionEvent e)
2296 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2297 .getAlignment(), -1);
2298 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2300 String newtitle = new String("Flanking alignment");
2302 if (Desktop.jalviewClipboard != null
2303 && Desktop.jalviewClipboard[2] != null)
2305 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2306 for (int region[] : hc)
2308 af.viewport.hideColumns(region[0], region[1]);
2312 // >>>This is a fix for the moment, until a better solution is
2314 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2316 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2318 // TODO: maintain provenance of an alignment, rather than just make the
2319 // title a concatenation of operations.
2321 if (title.startsWith("Copied sequences"))
2327 newtitle = newtitle.concat("- from " + title);
2331 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2333 } catch (Exception ex)
2335 ex.printStackTrace();
2336 System.out.println("Exception whilst pasting: " + ex);
2337 // could be anything being pasted in here
2338 } catch (OutOfMemoryError oom)
2340 new OOMWarning("Viewing flanking region of alignment", oom);
2351 protected void cut_actionPerformed(ActionEvent e)
2353 copy_actionPerformed(null);
2354 delete_actionPerformed(null);
2364 protected void delete_actionPerformed(ActionEvent evt)
2367 SequenceGroup sg = viewport.getSelectionGroup();
2374 * If the cut affects all sequences, warn, remove highlighted columns
2376 if (sg.getSize() == viewport.getAlignment().getHeight())
2378 int confirm = JOptionPane.showConfirmDialog(this,
2379 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2380 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2381 JOptionPane.OK_CANCEL_OPTION);
2383 if (confirm == JOptionPane.CANCEL_OPTION
2384 || confirm == JOptionPane.CLOSED_OPTION)
2388 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2389 sg.getEndRes() + 1);
2392 SequenceI[] cut = sg.getSequences()
2393 .toArray(new SequenceI[sg.getSize()]);
2395 addHistoryItem(new EditCommand(
2396 MessageManager.getString("label.cut_sequences"), Action.CUT,
2397 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2398 viewport.getAlignment()));
2400 viewport.setSelectionGroup(null);
2401 viewport.sendSelection();
2402 viewport.getAlignment().deleteGroup(sg);
2404 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2406 if (viewport.getAlignment().getHeight() < 1)
2410 this.setClosed(true);
2411 } catch (Exception ex)
2424 protected void deleteGroups_actionPerformed(ActionEvent e)
2426 if (avc.deleteGroups())
2428 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2429 alignPanel.updateAnnotation();
2430 alignPanel.paintAlignment(true);
2441 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2443 SequenceGroup sg = new SequenceGroup();
2445 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2447 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2450 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2451 viewport.setSelectionGroup(sg);
2452 viewport.sendSelection();
2453 alignPanel.paintAlignment(true);
2454 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2464 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2466 if (viewport.cursorMode)
2468 alignPanel.getSeqPanel().keyboardNo1 = null;
2469 alignPanel.getSeqPanel().keyboardNo2 = null;
2471 viewport.setSelectionGroup(null);
2472 viewport.getColumnSelection().clear();
2473 viewport.setSelectionGroup(null);
2474 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2475 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2476 alignPanel.paintAlignment(true);
2477 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2478 viewport.sendSelection();
2488 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2490 SequenceGroup sg = viewport.getSelectionGroup();
2494 selectAllSequenceMenuItem_actionPerformed(null);
2499 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2501 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2504 alignPanel.paintAlignment(true);
2505 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2506 viewport.sendSelection();
2510 public void invertColSel_actionPerformed(ActionEvent e)
2512 viewport.invertColumnSelection();
2513 alignPanel.paintAlignment(true);
2514 viewport.sendSelection();
2524 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2526 trimAlignment(true);
2536 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2538 trimAlignment(false);
2541 void trimAlignment(boolean trimLeft)
2543 ColumnSelection colSel = viewport.getColumnSelection();
2546 if (colSel.size() > 0)
2550 column = colSel.getMin();
2554 column = colSel.getMax();
2558 if (viewport.getSelectionGroup() != null)
2560 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2561 viewport.getHiddenRepSequences());
2565 seqs = viewport.getAlignment().getSequencesArray();
2568 TrimRegionCommand trimRegion;
2571 trimRegion = new TrimRegionCommand("Remove Left",
2572 TrimRegionCommand.TRIM_LEFT, seqs, column,
2573 viewport.getAlignment(), viewport.getColumnSelection(),
2574 viewport.getSelectionGroup());
2575 viewport.setStartRes(0);
2579 trimRegion = new TrimRegionCommand("Remove Right",
2580 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2581 viewport.getAlignment(), viewport.getColumnSelection(),
2582 viewport.getSelectionGroup());
2585 statusBar.setText(MessageManager.formatMessage(
2586 "label.removed_columns", new String[]
2587 { Integer.valueOf(trimRegion.getSize()).toString() }));
2589 addHistoryItem(trimRegion);
2591 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2593 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2594 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2596 viewport.getAlignment().deleteGroup(sg);
2600 viewport.firePropertyChange("alignment", null, viewport
2601 .getAlignment().getSequences());
2612 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2614 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2617 if (viewport.getSelectionGroup() != null)
2619 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2620 viewport.getHiddenRepSequences());
2621 start = viewport.getSelectionGroup().getStartRes();
2622 end = viewport.getSelectionGroup().getEndRes();
2626 seqs = viewport.getAlignment().getSequencesArray();
2629 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2630 "Remove Gapped Columns", seqs, start, end,
2631 viewport.getAlignment());
2633 addHistoryItem(removeGapCols);
2635 statusBar.setText(MessageManager.formatMessage(
2636 "label.removed_empty_columns", new Object[]
2637 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2639 // This is to maintain viewport position on first residue
2640 // of first sequence
2641 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2642 int startRes = seq.findPosition(viewport.startRes);
2643 // ShiftList shifts;
2644 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2645 // edit.alColumnChanges=shifts.getInverse();
2646 // if (viewport.hasHiddenColumns)
2647 // viewport.getColumnSelection().compensateForEdits(shifts);
2648 viewport.setStartRes(seq.findIndex(startRes) - 1);
2649 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2661 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2663 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2666 if (viewport.getSelectionGroup() != null)
2668 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2669 viewport.getHiddenRepSequences());
2670 start = viewport.getSelectionGroup().getStartRes();
2671 end = viewport.getSelectionGroup().getEndRes();
2675 seqs = viewport.getAlignment().getSequencesArray();
2678 // This is to maintain viewport position on first residue
2679 // of first sequence
2680 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2681 int startRes = seq.findPosition(viewport.startRes);
2683 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2684 viewport.getAlignment()));
2686 viewport.setStartRes(seq.findIndex(startRes) - 1);
2688 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2700 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2702 viewport.setPadGaps(padGapsMenuitem.isSelected());
2703 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2714 public void findMenuItem_actionPerformed(ActionEvent e)
2720 * Create a new view of the current alignment.
2723 public void newView_actionPerformed(ActionEvent e)
2725 newView(null, true);
2729 * Creates and shows a new view of the current alignment.
2732 * title of newly created view; if null, one will be generated
2733 * @param copyAnnotation
2734 * if true then duplicate all annnotation, groups and settings
2735 * @return new alignment panel, already displayed.
2737 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2740 * Create a new AlignmentPanel (with its own, new Viewport)
2742 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2744 if (!copyAnnotation)
2747 * remove all groups and annotation except for the automatic stuff
2749 newap.av.getAlignment().deleteAllGroups();
2750 newap.av.getAlignment().deleteAllAnnotations(false);
2753 newap.av.setGatherViewsHere(false);
2755 if (viewport.viewName == null)
2757 viewport.viewName = MessageManager
2758 .getString("label.view_name_original");
2762 * Views share the same edits, undo and redo stacks, mappings.
2764 newap.av.setHistoryList(viewport.getHistoryList());
2765 newap.av.setRedoList(viewport.getRedoList());
2766 newap.av.getAlignment().setCodonFrames(
2767 viewport.getAlignment().getCodonFrames());
2769 newap.av.viewName = getNewViewName(viewTitle);
2771 addAlignmentPanel(newap, true);
2772 newap.alignmentChanged();
2774 if (alignPanels.size() == 2)
2776 viewport.setGatherViewsHere(true);
2778 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2783 * Make a new name for the view, ensuring it is unique within the current
2784 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2785 * these now use viewId. Unique view names are still desirable for usability.)
2790 protected String getNewViewName(String viewTitle)
2792 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2793 boolean addFirstIndex = false;
2794 if (viewTitle == null || viewTitle.trim().length() == 0)
2796 viewTitle = MessageManager.getString("action.view");
2797 addFirstIndex = true;
2801 index = 1;// we count from 1 if given a specific name
2803 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2805 List<Component> comps = PaintRefresher.components.get(viewport
2806 .getSequenceSetId());
2808 List<String> existingNames = getExistingViewNames(comps);
2810 while (existingNames.contains(newViewName))
2812 newViewName = viewTitle + " " + (++index);
2818 * Returns a list of distinct view names found in the given list of
2819 * components. View names are held on the viewport of an AlignmentPanel.
2824 protected List<String> getExistingViewNames(List<Component> comps)
2826 List<String> existingNames = new ArrayList<String>();
2827 for (Component comp : comps)
2829 if (comp instanceof AlignmentPanel)
2831 AlignmentPanel ap = (AlignmentPanel) comp;
2832 if (!existingNames.contains(ap.av.viewName))
2834 existingNames.add(ap.av.viewName);
2838 return existingNames;
2842 * Explode tabbed views into separate windows.
2845 public void expandViews_actionPerformed(ActionEvent e)
2847 Desktop.instance.explodeViews(this);
2851 * Gather views in separate windows back into a tabbed presentation.
2854 public void gatherViews_actionPerformed(ActionEvent e)
2856 Desktop.instance.gatherViews(this);
2866 public void font_actionPerformed(ActionEvent e)
2868 new FontChooser(alignPanel);
2878 protected void seqLimit_actionPerformed(ActionEvent e)
2880 viewport.setShowJVSuffix(seqLimits.isSelected());
2882 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2883 .calculateIdWidth());
2884 alignPanel.paintAlignment(true);
2888 public void idRightAlign_actionPerformed(ActionEvent e)
2890 viewport.setRightAlignIds(idRightAlign.isSelected());
2891 alignPanel.paintAlignment(true);
2895 public void centreColumnLabels_actionPerformed(ActionEvent e)
2897 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2898 alignPanel.paintAlignment(true);
2904 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2907 protected void followHighlight_actionPerformed()
2910 * Set the 'follow' flag on the Viewport (and scroll to position if now
2913 final boolean state = this.followHighlightMenuItem.getState();
2914 viewport.setFollowHighlight(state);
2917 alignPanel.scrollToPosition(
2918 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2929 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2931 viewport.setColourText(colourTextMenuItem.isSelected());
2932 alignPanel.paintAlignment(true);
2942 public void wrapMenuItem_actionPerformed(ActionEvent e)
2944 scaleAbove.setVisible(wrapMenuItem.isSelected());
2945 scaleLeft.setVisible(wrapMenuItem.isSelected());
2946 scaleRight.setVisible(wrapMenuItem.isSelected());
2947 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2948 alignPanel.updateLayout();
2952 public void showAllSeqs_actionPerformed(ActionEvent e)
2954 viewport.showAllHiddenSeqs();
2958 public void showAllColumns_actionPerformed(ActionEvent e)
2960 viewport.showAllHiddenColumns();
2965 public void hideSelSequences_actionPerformed(ActionEvent e)
2967 viewport.hideAllSelectedSeqs();
2968 // alignPanel.paintAlignment(true);
2972 * called by key handler and the hide all/show all menu items
2977 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2980 boolean hide = false;
2981 SequenceGroup sg = viewport.getSelectionGroup();
2982 if (!toggleSeqs && !toggleCols)
2984 // Hide everything by the current selection - this is a hack - we do the
2985 // invert and then hide
2986 // first check that there will be visible columns after the invert.
2987 if ((viewport.getColumnSelection() != null
2988 && viewport.getColumnSelection().getSelected() != null && viewport
2989 .getColumnSelection().getSelected().size() > 0)
2990 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2993 // now invert the sequence set, if required - empty selection implies
2994 // that no hiding is required.
2997 invertSequenceMenuItem_actionPerformed(null);
2998 sg = viewport.getSelectionGroup();
3002 viewport.expandColSelection(sg, true);
3003 // finally invert the column selection and get the new sequence
3005 invertColSel_actionPerformed(null);
3012 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3014 hideSelSequences_actionPerformed(null);
3017 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3020 showAllSeqs_actionPerformed(null);
3026 if (viewport.getColumnSelection().getSelected().size() > 0)
3028 hideSelColumns_actionPerformed(null);
3031 viewport.setSelectionGroup(sg);
3036 showAllColumns_actionPerformed(null);
3045 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3046 * event.ActionEvent)
3049 public void hideAllButSelection_actionPerformed(ActionEvent e)
3051 toggleHiddenRegions(false, false);
3058 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3062 public void hideAllSelection_actionPerformed(ActionEvent e)
3064 SequenceGroup sg = viewport.getSelectionGroup();
3065 viewport.expandColSelection(sg, false);
3066 viewport.hideAllSelectedSeqs();
3067 viewport.hideSelectedColumns();
3068 alignPanel.paintAlignment(true);
3075 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3079 public void showAllhidden_actionPerformed(ActionEvent e)
3081 viewport.showAllHiddenColumns();
3082 viewport.showAllHiddenSeqs();
3083 alignPanel.paintAlignment(true);
3087 public void hideSelColumns_actionPerformed(ActionEvent e)
3089 viewport.hideSelectedColumns();
3090 alignPanel.paintAlignment(true);
3094 public void hiddenMarkers_actionPerformed(ActionEvent e)
3096 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3107 protected void scaleAbove_actionPerformed(ActionEvent e)
3109 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3110 alignPanel.paintAlignment(true);
3120 protected void scaleLeft_actionPerformed(ActionEvent e)
3122 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3123 alignPanel.paintAlignment(true);
3133 protected void scaleRight_actionPerformed(ActionEvent e)
3135 viewport.setScaleRightWrapped(scaleRight.isSelected());
3136 alignPanel.paintAlignment(true);
3146 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3148 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3149 alignPanel.paintAlignment(true);
3159 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3161 viewport.setShowText(viewTextMenuItem.isSelected());
3162 alignPanel.paintAlignment(true);
3172 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3174 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3175 alignPanel.paintAlignment(true);
3178 public FeatureSettings featureSettings;
3181 public FeatureSettingsControllerI getFeatureSettingsUI()
3183 return featureSettings;
3187 public void featureSettings_actionPerformed(ActionEvent e)
3189 if (featureSettings != null)
3191 featureSettings.close();
3192 featureSettings = null;
3194 if (!showSeqFeatures.isSelected())
3196 // make sure features are actually displayed
3197 showSeqFeatures.setSelected(true);
3198 showSeqFeatures_actionPerformed(null);
3200 featureSettings = new FeatureSettings(this);
3204 * Set or clear 'Show Sequence Features'
3210 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3212 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3213 alignPanel.paintAlignment(true);
3214 if (alignPanel.getOverviewPanel() != null)
3216 alignPanel.getOverviewPanel().updateOverviewImage();
3221 * Set or clear 'Show Sequence Features'
3227 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3229 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3231 if (viewport.isShowSequenceFeaturesHeight())
3233 // ensure we're actually displaying features
3234 viewport.setShowSequenceFeatures(true);
3235 showSeqFeatures.setSelected(true);
3237 alignPanel.paintAlignment(true);
3238 if (alignPanel.getOverviewPanel() != null)
3240 alignPanel.getOverviewPanel().updateOverviewImage();
3245 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3246 * the annotations panel as a whole.
3248 * The options to show/hide all annotations should be enabled when the panel
3249 * is shown, and disabled when the panel is hidden.
3254 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3256 final boolean setVisible = annotationPanelMenuItem.isSelected();
3257 viewport.setShowAnnotation(setVisible);
3258 this.showAllSeqAnnotations.setEnabled(setVisible);
3259 this.hideAllSeqAnnotations.setEnabled(setVisible);
3260 this.showAllAlAnnotations.setEnabled(setVisible);
3261 this.hideAllAlAnnotations.setEnabled(setVisible);
3262 alignPanel.updateLayout();
3266 public void alignmentProperties()
3268 JEditorPane editPane = new JEditorPane("text/html", "");
3269 editPane.setEditable(false);
3270 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3272 editPane.setText(MessageManager.formatMessage("label.html_content",
3274 { contents.toString() }));
3275 JInternalFrame frame = new JInternalFrame();
3276 frame.getContentPane().add(new JScrollPane(editPane));
3278 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3279 "label.alignment_properties", new Object[]
3280 { getTitle() }), 500, 400);
3290 public void overviewMenuItem_actionPerformed(ActionEvent e)
3292 if (alignPanel.overviewPanel != null)
3297 JInternalFrame frame = new JInternalFrame();
3298 OverviewPanel overview = new OverviewPanel(alignPanel);
3299 frame.setContentPane(overview);
3300 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3301 "label.overview_params", new Object[]
3302 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3304 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3305 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3308 public void internalFrameClosed(
3309 javax.swing.event.InternalFrameEvent evt)
3311 alignPanel.setOverviewPanel(null);
3315 alignPanel.setOverviewPanel(overview);
3319 public void textColour_actionPerformed(ActionEvent e)
3321 new TextColourChooser().chooseColour(alignPanel, null);
3331 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3343 public void clustalColour_actionPerformed(ActionEvent e)
3345 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3346 viewport.getHiddenRepSequences()));
3356 public void zappoColour_actionPerformed(ActionEvent e)
3358 changeColour(new ZappoColourScheme());
3368 public void taylorColour_actionPerformed(ActionEvent e)
3370 changeColour(new TaylorColourScheme());
3380 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3382 changeColour(new HydrophobicColourScheme());
3392 public void helixColour_actionPerformed(ActionEvent e)
3394 changeColour(new HelixColourScheme());
3404 public void strandColour_actionPerformed(ActionEvent e)
3406 changeColour(new StrandColourScheme());
3416 public void turnColour_actionPerformed(ActionEvent e)
3418 changeColour(new TurnColourScheme());
3428 public void buriedColour_actionPerformed(ActionEvent e)
3430 changeColour(new BuriedColourScheme());
3440 public void nucleotideColour_actionPerformed(ActionEvent e)
3442 changeColour(new NucleotideColourScheme());
3446 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3448 changeColour(new PurinePyrimidineColourScheme());
3452 * public void covariationColour_actionPerformed(ActionEvent e) {
3454 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3458 public void annotationColour_actionPerformed(ActionEvent e)
3460 new AnnotationColourChooser(viewport, alignPanel);
3464 public void annotationColumn_actionPerformed(ActionEvent e)
3466 new AnnotationColumnChooser(viewport, alignPanel);
3470 public void rnahelicesColour_actionPerformed(ActionEvent e)
3472 new RNAHelicesColourChooser(viewport, alignPanel);
3482 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3484 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3493 public void changeColour(ColourSchemeI cs)
3495 // TODO: compare with applet and pull up to model method
3500 if (viewport.getAbovePIDThreshold())
3502 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3504 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3508 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3511 if (viewport.getConservationSelected())
3514 Alignment al = (Alignment) viewport.getAlignment();
3515 Conservation c = new Conservation("All",
3516 ResidueProperties.propHash, 3, al.getSequences(), 0,
3520 c.verdict(false, viewport.getConsPercGaps());
3522 cs.setConservation(c);
3524 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3529 cs.setConservation(null);
3532 cs.setConsensus(viewport.getSequenceConsensusHash());
3535 viewport.setGlobalColourScheme(cs);
3537 if (viewport.getColourAppliesToAllGroups())
3540 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3548 if (cs instanceof ClustalxColourScheme)
3550 sg.cs = new ClustalxColourScheme(sg,
3551 viewport.getHiddenRepSequences());
3553 else if (cs instanceof UserColourScheme)
3555 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3561 sg.cs = cs.getClass().newInstance();
3562 } catch (Exception ex)
3567 if (viewport.getAbovePIDThreshold()
3568 || cs instanceof PIDColourScheme
3569 || cs instanceof Blosum62ColourScheme)
3571 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3573 sg.cs.setConsensus(AAFrequency.calculate(
3574 sg.getSequences(viewport.getHiddenRepSequences()),
3575 sg.getStartRes(), sg.getEndRes() + 1));
3579 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3582 if (viewport.getConservationSelected())
3584 Conservation c = new Conservation("Group",
3585 ResidueProperties.propHash, 3, sg.getSequences(viewport
3586 .getHiddenRepSequences()), sg.getStartRes(),
3587 sg.getEndRes() + 1);
3589 c.verdict(false, viewport.getConsPercGaps());
3590 sg.cs.setConservation(c);
3594 sg.cs.setConservation(null);
3599 if (alignPanel.getOverviewPanel() != null)
3601 alignPanel.getOverviewPanel().updateOverviewImage();
3604 alignPanel.paintAlignment(true);
3614 protected void modifyPID_actionPerformed(ActionEvent e)
3616 if (viewport.getAbovePIDThreshold()
3617 && viewport.getGlobalColourScheme() != null)
3619 SliderPanel.setPIDSliderSource(alignPanel,
3620 viewport.getGlobalColourScheme(), "Background");
3621 SliderPanel.showPIDSlider();
3632 protected void modifyConservation_actionPerformed(ActionEvent e)
3634 if (viewport.getConservationSelected()
3635 && viewport.getGlobalColourScheme() != null)
3637 SliderPanel.setConservationSlider(alignPanel,
3638 viewport.getGlobalColourScheme(), "Background");
3639 SliderPanel.showConservationSlider();
3650 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3652 viewport.setConservationSelected(conservationMenuItem.isSelected());
3654 viewport.setAbovePIDThreshold(false);
3655 abovePIDThreshold.setSelected(false);
3657 changeColour(viewport.getGlobalColourScheme());
3659 modifyConservation_actionPerformed(null);
3669 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3671 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3673 conservationMenuItem.setSelected(false);
3674 viewport.setConservationSelected(false);
3676 changeColour(viewport.getGlobalColourScheme());
3678 modifyPID_actionPerformed(null);
3688 public void userDefinedColour_actionPerformed(ActionEvent e)
3690 if (e.getActionCommand().equals(
3691 MessageManager.getString("action.user_defined")))
3693 new UserDefinedColours(alignPanel, null);
3697 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3698 .getUserColourSchemes().get(e.getActionCommand());
3704 public void updateUserColourMenu()
3707 Component[] menuItems = colourMenu.getMenuComponents();
3708 int iSize = menuItems.length;
3709 for (int i = 0; i < iSize; i++)
3711 if (menuItems[i].getName() != null
3712 && menuItems[i].getName().equals("USER_DEFINED"))
3714 colourMenu.remove(menuItems[i]);
3718 if (UserDefinedColours.getUserColourSchemes() != null)
3720 Enumeration userColours = UserDefinedColours
3721 .getUserColourSchemes().keys();
3723 while (userColours.hasMoreElements())
3725 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3726 userColours.nextElement().toString());
3727 radioItem.setName("USER_DEFINED");
3728 radioItem.addMouseListener(new MouseAdapter()
3731 public void mousePressed(MouseEvent evt)
3733 if (evt.isControlDown()
3734 || SwingUtilities.isRightMouseButton(evt))
3736 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3738 int option = JOptionPane.showInternalConfirmDialog(
3741 .getString("label.remove_from_default_list"),
3743 .getString("label.remove_user_defined_colour"),
3744 JOptionPane.YES_NO_OPTION);
3745 if (option == JOptionPane.YES_OPTION)
3747 UserDefinedColours.removeColourFromDefaults(radioItem
3749 colourMenu.remove(radioItem);
3753 radioItem.addActionListener(new ActionListener()
3756 public void actionPerformed(ActionEvent evt)
3758 userDefinedColour_actionPerformed(evt);
3765 radioItem.addActionListener(new ActionListener()
3768 public void actionPerformed(ActionEvent evt)
3770 userDefinedColour_actionPerformed(evt);
3774 colourMenu.insert(radioItem, 15);
3775 colours.add(radioItem);
3787 public void PIDColour_actionPerformed(ActionEvent e)
3789 changeColour(new PIDColourScheme());
3799 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3801 changeColour(new Blosum62ColourScheme());
3811 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3813 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3814 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3815 .getAlignment().getSequenceAt(0), null);
3816 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3817 viewport.getAlignment()));
3818 alignPanel.paintAlignment(true);
3828 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3830 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3831 AlignmentSorter.sortByID(viewport.getAlignment());
3832 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3833 viewport.getAlignment()));
3834 alignPanel.paintAlignment(true);
3844 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3846 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3847 AlignmentSorter.sortByLength(viewport.getAlignment());
3848 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3849 viewport.getAlignment()));
3850 alignPanel.paintAlignment(true);
3860 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3862 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3863 AlignmentSorter.sortByGroup(viewport.getAlignment());
3864 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3865 viewport.getAlignment()));
3867 alignPanel.paintAlignment(true);
3877 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3879 new RedundancyPanel(alignPanel, this);
3889 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3891 if ((viewport.getSelectionGroup() == null)
3892 || (viewport.getSelectionGroup().getSize() < 2))
3894 JOptionPane.showInternalMessageDialog(this, MessageManager
3895 .getString("label.you_must_select_least_two_sequences"),
3896 MessageManager.getString("label.invalid_selection"),
3897 JOptionPane.WARNING_MESSAGE);
3901 JInternalFrame frame = new JInternalFrame();
3902 frame.setContentPane(new PairwiseAlignPanel(viewport));
3903 Desktop.addInternalFrame(frame,
3904 MessageManager.getString("action.pairwise_alignment"), 600,
3916 public void PCAMenuItem_actionPerformed(ActionEvent e)
3918 if (((viewport.getSelectionGroup() != null)
3919 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3920 .getSelectionGroup().getSize() > 0))
3921 || (viewport.getAlignment().getHeight() < 4))
3924 .showInternalMessageDialog(
3927 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3929 .getString("label.sequence_selection_insufficient"),
3930 JOptionPane.WARNING_MESSAGE);
3935 new PCAPanel(alignPanel);
3939 public void autoCalculate_actionPerformed(ActionEvent e)
3941 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3942 if (viewport.autoCalculateConsensus)
3944 viewport.firePropertyChange("alignment", null, viewport
3945 .getAlignment().getSequences());
3950 public void sortByTreeOption_actionPerformed(ActionEvent e)
3952 viewport.sortByTree = sortByTree.isSelected();
3956 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3958 viewport.followSelection = listenToViewSelections.isSelected();
3968 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3970 newTreePanel("AV", "PID", "Average distance tree using PID");
3980 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3982 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3992 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3994 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
4004 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
4006 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
4019 void newTreePanel(String type, String pwType, String title)
4023 if (viewport.getSelectionGroup() != null
4024 && viewport.getSelectionGroup().getSize() > 0)
4026 if (viewport.getSelectionGroup().getSize() < 3)
4032 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4034 .getString("label.not_enough_sequences"),
4035 JOptionPane.WARNING_MESSAGE);
4039 SequenceGroup sg = viewport.getSelectionGroup();
4041 /* Decide if the selection is a column region */
4042 for (SequenceI _s : sg.getSequences())
4044 if (_s.getLength() < sg.getEndRes())
4050 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4052 .getString("label.sequences_selection_not_aligned"),
4053 JOptionPane.WARNING_MESSAGE);
4059 title = title + " on region";
4060 tp = new TreePanel(alignPanel, type, pwType);
4064 // are the visible sequences aligned?
4065 if (!viewport.getAlignment().isAligned(false))
4071 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4073 .getString("label.sequences_not_aligned"),
4074 JOptionPane.WARNING_MESSAGE);
4079 if (viewport.getAlignment().getHeight() < 2)
4084 tp = new TreePanel(alignPanel, type, pwType);
4089 if (viewport.viewName != null)
4091 title += viewport.viewName + " of ";
4094 title += this.title;
4096 Desktop.addInternalFrame(tp, title, 600, 500);
4107 public void addSortByOrderMenuItem(String title,
4108 final AlignmentOrder order)
4110 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4112 item.addActionListener(new java.awt.event.ActionListener()
4115 public void actionPerformed(ActionEvent e)
4117 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4119 // TODO: JBPNote - have to map order entries to curent SequenceI
4121 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4123 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4126 alignPanel.paintAlignment(true);
4132 * Add a new sort by annotation score menu item
4135 * the menu to add the option to
4137 * the label used to retrieve scores for each sequence on the
4140 public void addSortByAnnotScoreMenuItem(JMenu sort,
4141 final String scoreLabel)
4143 final JMenuItem item = new JMenuItem(scoreLabel);
4145 item.addActionListener(new java.awt.event.ActionListener()
4148 public void actionPerformed(ActionEvent e)
4150 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4151 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4152 viewport.getAlignment());// ,viewport.getSelectionGroup());
4153 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4154 viewport.getAlignment()));
4155 alignPanel.paintAlignment(true);
4161 * last hash for alignment's annotation array - used to minimise cost of
4164 protected int _annotationScoreVectorHash;
4167 * search the alignment and rebuild the sort by annotation score submenu the
4168 * last alignment annotation vector hash is stored to minimize cost of
4169 * rebuilding in subsequence calls.
4173 public void buildSortByAnnotationScoresMenu()
4175 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4180 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4182 sortByAnnotScore.removeAll();
4183 // almost certainly a quicker way to do this - but we keep it simple
4184 Hashtable scoreSorts = new Hashtable();
4185 AlignmentAnnotation aann[];
4186 for (SequenceI sqa : viewport.getAlignment().getSequences())
4188 aann = sqa.getAnnotation();
4189 for (int i = 0; aann != null && i < aann.length; i++)
4191 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4193 scoreSorts.put(aann[i].label, aann[i].label);
4197 Enumeration labels = scoreSorts.keys();
4198 while (labels.hasMoreElements())
4200 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4201 (String) labels.nextElement());
4203 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4206 _annotationScoreVectorHash = viewport.getAlignment()
4207 .getAlignmentAnnotation().hashCode();
4212 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4213 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4214 * call. Listeners are added to remove the menu item when the treePanel is
4215 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4219 * Displayed tree window.
4221 * SortBy menu item title.
4224 public void buildTreeMenu()
4226 calculateTree.removeAll();
4227 // build the calculate menu
4229 for (final String type : new String[]
4232 String treecalcnm = MessageManager.getString("label.tree_calc_"
4233 + type.toLowerCase());
4234 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4236 JMenuItem tm = new JMenuItem();
4237 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4238 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4240 String smn = MessageManager.getStringOrReturn(
4241 "label.score_model_", sm.getName());
4242 final String title = MessageManager.formatMessage(
4243 "label.treecalc_title", treecalcnm, smn);
4244 tm.setText(title);//
4245 tm.addActionListener(new java.awt.event.ActionListener()
4248 public void actionPerformed(ActionEvent e)
4250 newTreePanel(type, pwtype, title);
4253 calculateTree.add(tm);
4258 sortByTreeMenu.removeAll();
4260 List<Component> comps = PaintRefresher.components.get(viewport
4261 .getSequenceSetId());
4262 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4263 for (Component comp : comps)
4265 if (comp instanceof TreePanel)
4267 treePanels.add((TreePanel) comp);
4271 if (treePanels.size() < 1)
4273 sortByTreeMenu.setVisible(false);
4277 sortByTreeMenu.setVisible(true);
4279 for (final TreePanel tp : treePanels)
4281 final JMenuItem item = new JMenuItem(tp.getTitle());
4282 item.addActionListener(new java.awt.event.ActionListener()
4285 public void actionPerformed(ActionEvent e)
4287 tp.sortByTree_actionPerformed();
4288 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4293 sortByTreeMenu.add(item);
4297 public boolean sortBy(AlignmentOrder alorder, String undoname)
4299 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4300 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4301 if (undoname != null)
4303 addHistoryItem(new OrderCommand(undoname, oldOrder,
4304 viewport.getAlignment()));
4306 alignPanel.paintAlignment(true);
4311 * Work out whether the whole set of sequences or just the selected set will
4312 * be submitted for multiple alignment.
4315 public AlignmentView gatherSequencesForAlignment()
4317 // Now, check we have enough sequences
4318 AlignmentView msa = null;
4320 if ((viewport.getSelectionGroup() != null)
4321 && (viewport.getSelectionGroup().getSize() > 1))
4323 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4324 // some common interface!
4326 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4327 * SequenceI[sz = seqs.getSize(false)];
4329 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4330 * seqs.getSequenceAt(i); }
4332 msa = viewport.getAlignmentView(true);
4334 else if (viewport.getSelectionGroup() != null
4335 && viewport.getSelectionGroup().getSize() == 1)
4337 int option = JOptionPane.showConfirmDialog(this,
4338 MessageManager.getString("warn.oneseq_msainput_selection"),
4339 MessageManager.getString("label.invalid_selection"),
4340 JOptionPane.OK_CANCEL_OPTION);
4341 if (option == JOptionPane.OK_OPTION)
4343 msa = viewport.getAlignmentView(false);
4348 msa = viewport.getAlignmentView(false);
4354 * Decides what is submitted to a secondary structure prediction service: the
4355 * first sequence in the alignment, or in the current selection, or, if the
4356 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4357 * region or the whole alignment. (where the first sequence in the set is the
4358 * one that the prediction will be for).
4360 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4362 AlignmentView seqs = null;
4364 if ((viewport.getSelectionGroup() != null)
4365 && (viewport.getSelectionGroup().getSize() > 0))
4367 seqs = viewport.getAlignmentView(true);
4371 seqs = viewport.getAlignmentView(false);
4373 // limit sequences - JBPNote in future - could spawn multiple prediction
4375 // TODO: viewport.getAlignment().isAligned is a global state - the local
4376 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4377 if (!viewport.getAlignment().isAligned(false))
4379 seqs.setSequences(new SeqCigar[]
4380 { seqs.getSequences()[0] });
4381 // TODO: if seqs.getSequences().length>1 then should really have warned
4395 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4397 // Pick the tree file
4398 JalviewFileChooser chooser = new JalviewFileChooser(
4399 Cache.getProperty("LAST_DIRECTORY"));
4400 chooser.setFileView(new JalviewFileView());
4401 chooser.setDialogTitle(MessageManager
4402 .getString("label.select_newick_like_tree_file"));
4403 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4405 int value = chooser.showOpenDialog(null);
4407 if (value == JalviewFileChooser.APPROVE_OPTION)
4409 String choice = chooser.getSelectedFile().getPath();
4410 Cache.setProperty("LAST_DIRECTORY", choice);
4411 NewickFile fin = null;
4414 fin = new NewickFile(choice, "File");
4415 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4416 } catch (Exception ex)
4423 .getString("label.problem_reading_tree_file"),
4424 JOptionPane.WARNING_MESSAGE);
4425 ex.printStackTrace();
4427 if (fin != null && fin.hasWarningMessage())
4429 JOptionPane.showMessageDialog(Desktop.desktop, fin
4430 .getWarningMessage(), MessageManager
4431 .getString("label.possible_problem_with_tree_file"),
4432 JOptionPane.WARNING_MESSAGE);
4438 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4440 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4443 public TreePanel ShowNewickTree(NewickFile nf, String title)
4445 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4448 public TreePanel ShowNewickTree(NewickFile nf, String title,
4449 AlignmentView input)
4451 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4454 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4455 int h, int x, int y)
4457 return ShowNewickTree(nf, title, null, w, h, x, y);
4461 * Add a treeviewer for the tree extracted from a newick file object to the
4462 * current alignment view
4469 * Associated alignment input data (or null)
4478 * @return TreePanel handle
4480 public TreePanel ShowNewickTree(NewickFile nf, String title,
4481 AlignmentView input, int w, int h, int x, int y)
4483 TreePanel tp = null;
4489 if (nf.getTree() != null)
4491 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4497 tp.setLocation(x, y);
4500 Desktop.addInternalFrame(tp, title, w, h);
4502 } catch (Exception ex)
4504 ex.printStackTrace();
4510 private boolean buildingMenu = false;
4513 * Generates menu items and listener event actions for web service clients
4516 public void BuildWebServiceMenu()
4518 while (buildingMenu)
4522 System.err.println("Waiting for building menu to finish.");
4524 } catch (Exception e)
4528 final AlignFrame me = this;
4529 buildingMenu = true;
4530 new Thread(new Runnable()
4535 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4538 System.err.println("Building ws menu again "
4539 + Thread.currentThread());
4540 // TODO: add support for context dependent disabling of services based
4542 // alignment and current selection
4543 // TODO: add additional serviceHandle parameter to specify abstract
4545 // class independently of AbstractName
4546 // TODO: add in rediscovery GUI function to restart discoverer
4547 // TODO: group services by location as well as function and/or
4549 // object broker mechanism.
4550 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4551 final IProgressIndicator af = me;
4552 final JMenu msawsmenu = new JMenu("Alignment");
4553 final JMenu secstrmenu = new JMenu(
4554 "Secondary Structure Prediction");
4555 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4556 final JMenu analymenu = new JMenu("Analysis");
4557 final JMenu dismenu = new JMenu("Protein Disorder");
4558 // final JMenu msawsmenu = new
4559 // JMenu(MessageManager.getString("label.alignment"));
4560 // final JMenu secstrmenu = new
4561 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4562 // final JMenu seqsrchmenu = new
4563 // JMenu(MessageManager.getString("label.sequence_database_search"));
4564 // final JMenu analymenu = new
4565 // JMenu(MessageManager.getString("label.analysis"));
4566 // final JMenu dismenu = new
4567 // JMenu(MessageManager.getString("label.protein_disorder"));
4568 // JAL-940 - only show secondary structure prediction services from
4569 // the legacy server
4570 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4572 Discoverer.services != null && (Discoverer.services.size() > 0))
4574 // TODO: refactor to allow list of AbstractName/Handler bindings to
4576 // stored or retrieved from elsewhere
4577 // No MSAWS used any more:
4578 // Vector msaws = null; // (Vector)
4579 // Discoverer.services.get("MsaWS");
4580 Vector secstrpr = (Vector) Discoverer.services
4582 if (secstrpr != null)
4584 // Add any secondary structure prediction services
4585 for (int i = 0, j = secstrpr.size(); i < j; i++)
4587 final ServiceHandle sh = (ServiceHandle) secstrpr.get(i);
4588 WSMenuEntryProviderI impl = Discoverer.getServiceClient(sh);
4589 int p = secstrmenu.getItemCount();
4590 impl.attachWSMenuEntry(secstrmenu, me);
4591 int q = secstrmenu.getItemCount();
4592 for (int litm = p; litm < q; litm++)
4594 legacyItems.add(secstrmenu.getItem(litm));
4600 // Add all submenus in the order they should appear on the web
4602 wsmenu.add(msawsmenu);
4603 wsmenu.add(secstrmenu);
4604 wsmenu.add(dismenu);
4605 wsmenu.add(analymenu);
4606 // No search services yet
4607 // wsmenu.add(seqsrchmenu);
4609 javax.swing.SwingUtilities.invokeLater(new Runnable()
4616 webService.removeAll();
4617 // first, add discovered services onto the webservices menu
4618 if (wsmenu.size() > 0)
4620 for (int i = 0, j = wsmenu.size(); i < j; i++)
4622 webService.add(wsmenu.get(i));
4627 webService.add(me.webServiceNoServices);
4629 // TODO: move into separate menu builder class.
4630 boolean new_sspred = false;
4631 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4633 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4634 if (jws2servs != null)
4636 if (jws2servs.hasServices())
4638 jws2servs.attachWSMenuEntry(webService, me);
4639 for (Jws2Instance sv : jws2servs.getServices())
4641 if (sv.description.toLowerCase().contains("jpred"))
4643 for (JMenuItem jmi : legacyItems)
4645 jmi.setVisible(false);
4651 if (jws2servs.isRunning())
4653 JMenuItem tm = new JMenuItem(
4654 "Still discovering JABA Services");
4655 tm.setEnabled(false);
4660 build_urlServiceMenu(me.webService);
4661 build_fetchdbmenu(webService);
4662 for (JMenu item : wsmenu)
4664 if (item.getItemCount() == 0)
4666 item.setEnabled(false);
4670 item.setEnabled(true);
4673 } catch (Exception e)
4676 .debug("Exception during web service menu building process.",
4681 } catch (Exception e)
4684 buildingMenu = false;
4691 * construct any groupURL type service menu entries.
4695 private void build_urlServiceMenu(JMenu webService)
4697 // TODO: remove this code when 2.7 is released
4698 // DEBUG - alignmentView
4700 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4701 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4703 * @Override public void actionPerformed(ActionEvent e) {
4704 * jalview.datamodel.AlignmentView
4705 * .testSelectionViews(af.viewport.getAlignment(),
4706 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4708 * }); webService.add(testAlView);
4710 // TODO: refactor to RestClient discoverer and merge menu entries for
4711 // rest-style services with other types of analysis/calculation service
4712 // SHmmr test client - still being implemented.
4713 // DEBUG - alignmentView
4715 for (RestClient client : RestClient.getRestClients())
4717 client.attachWSMenuEntry(
4718 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4724 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4725 * chooser = new JalviewFileChooser(Cache.
4726 * getProperty("LAST_DIRECTORY"));
4728 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4729 * to Vamsas file"); chooser.setToolTipText("Export");
4731 * int value = chooser.showSaveDialog(this);
4733 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4734 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4735 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4736 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4739 * prototype of an automatically enabled/disabled analysis function
4742 protected void setShowProductsEnabled()
4744 SequenceI[] selection = viewport.getSequenceSelection();
4745 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4746 viewport.getAlignment().getDataset()))
4748 showProducts.setEnabled(true);
4753 showProducts.setEnabled(false);
4758 * search selection for sequence xRef products and build the show products
4763 * @return true if showProducts menu should be enabled.
4765 public boolean canShowProducts(SequenceI[] selection,
4766 boolean isRegionSelection, Alignment dataset)
4768 boolean showp = false;
4771 showProducts.removeAll();
4772 final boolean dna = viewport.getAlignment().isNucleotide();
4773 final Alignment ds = dataset;
4774 String[] ptypes = (selection == null || selection.length == 0) ? null
4775 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4777 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4778 // selection, dataset, true);
4779 final SequenceI[] sel = selection;
4780 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4783 final boolean isRegSel = isRegionSelection;
4784 final AlignFrame af = this;
4785 final String source = ptypes[t];
4786 JMenuItem xtype = new JMenuItem(ptypes[t]);
4787 xtype.addActionListener(new ActionListener()
4791 public void actionPerformed(ActionEvent e)
4793 // TODO: new thread for this call with vis-delay
4794 af.showProductsFor(af.viewport.getSequenceSelection(),
4795 isRegSel, dna, source);
4799 showProducts.add(xtype);
4801 showProducts.setVisible(showp);
4802 showProducts.setEnabled(showp);
4803 } catch (Exception e)
4806 .warn("canTranslate threw an exception - please report to help@jalview.org",
4813 protected void showProductsFor(final SequenceI[] sel,
4814 final boolean isRegSel, final boolean dna, final String source)
4816 Runnable foo = new Runnable()
4822 final long sttime = System.currentTimeMillis();
4823 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4824 "status.searching_for_sequences_from", new Object[]
4825 { source }), sttime);
4828 // update our local dataset reference
4829 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4831 Alignment prods = CrossRef
4832 .findXrefSequences(sel, dna, source, ds);
4835 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4836 for (int s = 0; s < sprods.length; s++)
4838 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4839 if (ds.getSequences() == null
4840 || !ds.getSequences().contains(
4841 sprods[s].getDatasetSequence()))
4843 ds.addSequence(sprods[s].getDatasetSequence());
4845 sprods[s].updatePDBIds();
4847 Alignment al = new Alignment(sprods);
4851 * Copy dna-to-protein mappings to new alignment
4853 // TODO 1: no mappings are set up for EMBL product
4854 // TODO 2: if they were, should add them to protein alignment, not
4856 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4857 for (AlignedCodonFrame acf : cf)
4859 al.addCodonFrame(acf);
4861 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4863 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4864 + " for " + ((isRegSel) ? "selected region of " : "")
4866 naf.setTitle(newtitle);
4868 // temporary flag until SplitFrame is released
4869 boolean asSplitFrame = Cache.getDefault(
4870 Preferences.ENABLE_SPLIT_FRAME, true);
4874 * Make a copy of this alignment (sharing the same dataset
4875 * sequences). If we are DNA, drop introns and update mappings
4877 AlignmentI copyAlignment = null;
4878 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4879 .getSequenceSelection();
4882 copyAlignment = AlignmentUtils.makeExonAlignment(
4883 sequenceSelection, cf);
4884 al.getCodonFrames().clear();
4885 al.getCodonFrames().addAll(cf);
4886 final StructureSelectionManager ssm = StructureSelectionManager
4887 .getStructureSelectionManager(Desktop.instance);
4888 ssm.addMappings(cf);
4892 copyAlignment = new Alignment(new Alignment(
4893 sequenceSelection));
4895 AlignFrame copyThis = new AlignFrame(copyAlignment,
4896 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4897 copyThis.setTitle(AlignFrame.this.getTitle());
4898 // SplitFrame with dna above, protein below
4899 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4900 dna ? naf : copyThis);
4901 naf.setVisible(true);
4902 copyThis.setVisible(true);
4903 String linkedTitle = MessageManager
4904 .getString("label.linked_view_title");
4905 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4909 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4915 System.err.println("No Sequences generated for xRef type "
4918 } catch (Exception e)
4921 "Exception when finding crossreferences", e);
4922 } catch (OutOfMemoryError e)
4924 new OOMWarning("whilst fetching crossreferences", e);
4927 Cache.log.error("Error when finding crossreferences",
4930 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4931 "status.finished_searching_for_sequences_from",
4938 Thread frunner = new Thread(foo);
4942 public boolean canShowTranslationProducts(SequenceI[] selection,
4943 AlignmentI alignment)
4948 return (Dna.canTranslate(selection,
4949 viewport.getViewAsVisibleContigs(true)));
4950 } catch (Exception e)
4953 .warn("canTranslate threw an exception - please report to help@jalview.org",
4960 * Construct and display a new frame containing the translation of this
4961 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4964 public void showTranslation_actionPerformed(ActionEvent e)
4966 AlignmentI al = null;
4969 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4971 al = dna.translateCdna();
4972 } catch (Exception ex)
4975 "Exception during translation. Please report this !", ex);
4976 final String msg = MessageManager
4977 .getString("label.error_when_translating_sequences_submit_bug_report");
4978 final String title = MessageManager
4979 .getString("label.implementation_error")
4980 + MessageManager.getString("translation_failed");
4981 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4982 JOptionPane.ERROR_MESSAGE);
4985 if (al == null || al.getHeight() == 0)
4987 final String msg = MessageManager
4988 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4989 final String title = MessageManager
4990 .getString("label.translation_failed");
4991 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4992 JOptionPane.WARNING_MESSAGE);
4996 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4997 af.setFileFormat(this.currentFileFormat);
4998 final String newTitle = MessageManager.formatMessage(
4999 "label.translation_of_params", new Object[]
5000 { this.getTitle() });
5001 af.setTitle(newTitle);
5002 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
5004 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
5005 viewport.openSplitFrame(af, new Alignment(seqs),
5006 al.getCodonFrames());
5010 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
5017 * Set the file format
5021 public void setFileFormat(String fileFormat)
5023 this.currentFileFormat = fileFormat;
5027 * Try to load a features file onto the alignment.
5030 * contents or path to retrieve file
5032 * access mode of file (see jalview.io.AlignFile)
5033 * @return true if features file was parsed correctly.
5035 public boolean parseFeaturesFile(String file, String type)
5037 return avc.parseFeaturesFile(file, type,
5038 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5043 public void refreshFeatureUI(boolean enableIfNecessary)
5045 // note - currently this is only still here rather than in the controller
5046 // because of the featureSettings hard reference that is yet to be
5048 if (enableIfNecessary)
5050 viewport.setShowSequenceFeatures(true);
5051 showSeqFeatures.setSelected(true);
5057 public void dragEnter(DropTargetDragEvent evt)
5062 public void dragExit(DropTargetEvent evt)
5067 public void dragOver(DropTargetDragEvent evt)
5072 public void dropActionChanged(DropTargetDragEvent evt)
5077 public void drop(DropTargetDropEvent evt)
5079 Transferable t = evt.getTransferable();
5080 java.util.List files = null;
5084 DataFlavor uriListFlavor = new DataFlavor(
5085 "text/uri-list;class=java.lang.String");
5086 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5088 // Works on Windows and MacOSX
5089 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5090 files = (java.util.List) t
5091 .getTransferData(DataFlavor.javaFileListFlavor);
5093 else if (t.isDataFlavorSupported(uriListFlavor))
5095 // This is used by Unix drag system
5096 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5097 String data = (String) t.getTransferData(uriListFlavor);
5098 files = new java.util.ArrayList(1);
5099 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5100 data, "\r\n"); st.hasMoreTokens();)
5102 String s = st.nextToken();
5103 if (s.startsWith("#"))
5105 // the line is a comment (as per the RFC 2483)
5109 java.net.URI uri = new java.net.URI(s);
5110 // check to see if we can handle this kind of URI
5111 if (uri.getScheme().toLowerCase().startsWith("http"))
5113 files.add(uri.toString());
5117 // otherwise preserve old behaviour: catch all for file objects
5118 java.io.File file = new java.io.File(uri);
5119 files.add(file.toString());
5123 } catch (Exception e)
5125 e.printStackTrace();
5131 // check to see if any of these files have names matching sequences in
5133 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5134 .getAlignment().getSequencesArray());
5136 * Object[] { String,SequenceI}
5138 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5139 ArrayList<String> filesnotmatched = new ArrayList<String>();
5140 for (int i = 0; i < files.size(); i++)
5142 String file = files.get(i).toString();
5144 String protocol = FormatAdapter.checkProtocol(file);
5145 if (protocol == FormatAdapter.FILE)
5147 File fl = new File(file);
5148 pdbfn = fl.getName();
5150 else if (protocol == FormatAdapter.URL)
5152 URL url = new URL(file);
5153 pdbfn = url.getFile();
5155 if (pdbfn.length() > 0)
5157 // attempt to find a match in the alignment
5158 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5159 int l = 0, c = pdbfn.indexOf(".");
5160 while (mtch == null && c != -1)
5165 } while ((c = pdbfn.indexOf(".", l)) > l);
5168 pdbfn = pdbfn.substring(0, l);
5170 mtch = idm.findAllIdMatches(pdbfn);
5177 type = new IdentifyFile().Identify(file, protocol);
5178 } catch (Exception ex)
5184 if (type.equalsIgnoreCase("PDB"))
5186 filesmatched.add(new Object[]
5187 { file, protocol, mtch });
5192 // File wasn't named like one of the sequences or wasn't a PDB file.
5193 filesnotmatched.add(file);
5197 if (filesmatched.size() > 0)
5199 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5205 "label.automatically_associate_pdb_files_with_sequences_same_name",
5212 .getString("label.automatically_associate_pdb_files_by_name"),
5213 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5216 for (Object[] fm : filesmatched)
5218 // try and associate
5219 // TODO: may want to set a standard ID naming formalism for
5220 // associating PDB files which have no IDs.
5221 for (SequenceI toassoc : (SequenceI[]) fm[2])
5223 PDBEntry pe = new AssociatePdbFileWithSeq()
5224 .associatePdbWithSeq((String) fm[0],
5225 (String) fm[1], toassoc, false,
5229 System.err.println("Associated file : "
5230 + ((String) fm[0]) + " with "
5231 + toassoc.getDisplayId(true));
5235 alignPanel.paintAlignment(true);
5239 if (filesnotmatched.size() > 0)
5242 && (Cache.getDefault(
5243 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5246 "<html>"+MessageManager
5248 "label.ignore_unmatched_dropped_files_info",
5253 .toString() })+"</html>",
5255 .getString("label.ignore_unmatched_dropped_files"),
5256 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5260 for (String fn : filesnotmatched)
5262 loadJalviewDataFile(fn, null, null, null);
5266 } catch (Exception ex)
5268 ex.printStackTrace();
5274 * Attempt to load a "dropped" file or URL string: First by testing whether
5275 * it's and Annotation file, then a JNet file, and finally a features file. If
5276 * all are false then the user may have dropped an alignment file onto this
5280 * either a filename or a URL string.
5282 public void loadJalviewDataFile(String file, String protocol,
5283 String format, SequenceI assocSeq)
5287 if (protocol == null)
5289 protocol = FormatAdapter.checkProtocol(file);
5291 // if the file isn't identified, or not positively identified as some
5292 // other filetype (PFAM is default unidentified alignment file type) then
5293 // try to parse as annotation.
5294 boolean isAnnotation = (format == null || format
5295 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5296 .annotateAlignmentView(viewport, file, protocol)
5301 // first see if its a T-COFFEE score file
5302 TCoffeeScoreFile tcf = null;
5305 tcf = new TCoffeeScoreFile(file, protocol);
5308 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5310 tcoffeeColour.setEnabled(true);
5311 tcoffeeColour.setSelected(true);
5312 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5313 isAnnotation = true;
5315 .setText(MessageManager
5316 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5320 // some problem - if no warning its probable that the ID matching
5321 // process didn't work
5325 tcf.getWarningMessage() == null ? MessageManager
5326 .getString("label.check_file_matches_sequence_ids_alignment")
5327 : tcf.getWarningMessage(),
5329 .getString("label.problem_reading_tcoffee_score_file"),
5330 JOptionPane.WARNING_MESSAGE);
5337 } catch (Exception x)
5340 .debug("Exception when processing data source as T-COFFEE score file",
5346 // try to see if its a JNet 'concise' style annotation file *before*
5348 // try to parse it as a features file
5351 format = new IdentifyFile().Identify(file, protocol);
5353 if (format.equalsIgnoreCase("JnetFile"))
5355 JPredFile predictions = new JPredFile(file, protocol);
5356 new JnetAnnotationMaker();
5357 JnetAnnotationMaker.add_annotation(predictions,
5358 viewport.getAlignment(), 0, false);
5359 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5360 viewport.getAlignment().setSeqrep(repseq);
5361 ColumnSelection cs = new ColumnSelection();
5362 cs.hideInsertionsFor(repseq);
5363 viewport.setColumnSelection(cs);
5364 isAnnotation = true;
5369 * if (format.equalsIgnoreCase("PDB")) {
5371 * String pdbfn = ""; // try to match up filename with sequence id
5372 * try { if (protocol == FormatAdapter.FILE) { File fl =
5373 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5374 * FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5375 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5376 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5377 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5378 * // attempt to find a match in the alignment SequenceI mtch =
5379 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5380 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5381 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5382 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5383 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5384 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5385 * { System.err.println("Associated file : " + file + " with " +
5386 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5387 * TODO: maybe need to load as normal otherwise return; } }
5389 // try to parse it as a features file
5390 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5391 // if it wasn't a features file then we just treat it as a general
5392 // alignment file to load into the current view.
5395 new FileLoader().LoadFile(viewport, file, protocol, format);
5399 alignPanel.paintAlignment(true);
5407 alignPanel.adjustAnnotationHeight();
5408 viewport.updateSequenceIdColours();
5409 buildSortByAnnotationScoresMenu();
5410 alignPanel.paintAlignment(true);
5412 } catch (Exception ex)
5414 ex.printStackTrace();
5415 } catch (OutOfMemoryError oom)
5420 } catch (Exception x)
5426 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5427 : "using " + protocol + " from " + file)
5429 + (format != null ? "(parsing as '" + format
5430 + "' file)" : ""), oom, Desktop.desktop);
5435 * Method invoked by the ChangeListener on the tabbed pane, in other words
5436 * when a different tabbed pane is selected by the user or programmatically.
5439 public void tabSelectionChanged(int index)
5443 alignPanel = alignPanels.get(index);
5444 viewport = alignPanel.av;
5445 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5446 setMenusFromViewport(viewport);
5450 * If there is a frame linked to this one in a SplitPane, switch it to the
5451 * same view tab index. No infinite recursion of calls should happen, since
5452 * tabSelectionChanged() should not get invoked on setting the selected
5453 * index to an unchanged value. Guard against setting an invalid index
5454 * before the new view peer tab has been created.
5456 final AlignViewportI peer = viewport.getCodingComplement();
5459 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5460 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5462 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5468 * On right mouse click on view tab, prompt for and set new view name.
5471 public void tabbedPane_mousePressed(MouseEvent e)
5473 if (SwingUtilities.isRightMouseButton(e))
5475 String msg = MessageManager.getString("label.enter_view_name");
5476 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5477 JOptionPane.QUESTION_MESSAGE);
5481 viewport.viewName = reply;
5482 // TODO warn if reply is in getExistingViewNames()?
5483 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5488 public AlignViewport getCurrentView()
5494 * Open the dialog for regex description parsing.
5497 protected void extractScores_actionPerformed(ActionEvent e)
5499 ParseProperties pp = new ParseProperties(viewport.getAlignment());
5500 // TODO: verify regex and introduce GUI dialog for version 2.5
5501 // if (pp.getScoresFromDescription("col", "score column ",
5502 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5504 if (pp.getScoresFromDescription("description column",
5505 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5507 buildSortByAnnotationScoresMenu();
5515 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5519 protected void showDbRefs_actionPerformed(ActionEvent e)
5521 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5527 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5531 protected void showNpFeats_actionPerformed(ActionEvent e)
5533 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5537 * find the viewport amongst the tabs in this alignment frame and close that
5542 public boolean closeView(AlignViewportI av)
5546 this.closeMenuItem_actionPerformed(false);
5549 Component[] comp = tabbedPane.getComponents();
5550 for (int i = 0; comp != null && i < comp.length; i++)
5552 if (comp[i] instanceof AlignmentPanel)
5554 if (((AlignmentPanel) comp[i]).av == av)
5557 closeView((AlignmentPanel) comp[i]);
5565 protected void build_fetchdbmenu(JMenu webService)
5567 // Temporary hack - DBRef Fetcher always top level ws entry.
5568 // TODO We probably want to store a sequence database checklist in
5569 // preferences and have checkboxes.. rather than individual sources selected
5571 final JMenu rfetch = new JMenu(
5572 MessageManager.getString("action.fetch_db_references"));
5573 rfetch.setToolTipText(MessageManager
5574 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5575 webService.add(rfetch);
5577 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5578 MessageManager.getString("option.trim_retrieved_seqs"));
5579 trimrs.setToolTipText(MessageManager
5580 .getString("label.trim_retrieved_sequences"));
5581 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5582 trimrs.addActionListener(new ActionListener()
5585 public void actionPerformed(ActionEvent e)
5587 trimrs.setSelected(trimrs.isSelected());
5588 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5589 Boolean.valueOf(trimrs.isSelected()).toString());
5593 JMenuItem fetchr = new JMenuItem(
5594 MessageManager.getString("label.standard_databases"));
5595 fetchr.setToolTipText(MessageManager
5596 .getString("label.fetch_embl_uniprot"));
5597 fetchr.addActionListener(new ActionListener()
5601 public void actionPerformed(ActionEvent e)
5603 new Thread(new Runnable()
5609 new DBRefFetcher(alignPanel.av
5610 .getSequenceSelection(), alignPanel.alignFrame)
5611 .fetchDBRefs(false);
5619 final AlignFrame me = this;
5620 new Thread(new Runnable()
5625 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5626 .getSequenceFetcherSingleton(me);
5627 SwingUtilities.invokeLater(new Runnable()
5632 String[] dbclasses = sf.getOrderedSupportedSources();
5633 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5634 // jalview.util.QuickSort.sort(otherdb, otherdb);
5635 List<DbSourceProxy> otherdb;
5636 JMenu dfetch = new JMenu();
5637 JMenu ifetch = new JMenu();
5638 JMenuItem fetchr = null;
5639 int comp = 0, icomp = 0, mcomp = 15;
5640 String mname = null;
5642 for (String dbclass : dbclasses)
5644 otherdb = sf.getSourceProxy(dbclass);
5645 // add a single entry for this class, or submenu allowing 'fetch
5647 if (otherdb == null || otherdb.size() < 1)
5651 // List<DbSourceProxy> dbs=otherdb;
5652 // otherdb=new ArrayList<DbSourceProxy>();
5653 // for (DbSourceProxy db:dbs)
5655 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5659 mname = "From " + dbclass;
5661 if (otherdb.size() == 1)
5663 final DbSourceProxy[] dassource = otherdb
5664 .toArray(new DbSourceProxy[0]);
5665 DbSourceProxy src = otherdb.get(0);
5666 fetchr = new JMenuItem(src.getDbSource());
5667 fetchr.addActionListener(new ActionListener()
5671 public void actionPerformed(ActionEvent e)
5673 new Thread(new Runnable()
5679 new DBRefFetcher(alignPanel.av
5680 .getSequenceSelection(),
5681 alignPanel.alignFrame, dassource)
5682 .fetchDBRefs(false);
5688 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5694 final DbSourceProxy[] dassource = otherdb
5695 .toArray(new DbSourceProxy[0]);
5697 DbSourceProxy src = otherdb.get(0);
5698 fetchr = new JMenuItem(MessageManager.formatMessage(
5699 "label.fetch_all_param", new Object[]
5700 { src.getDbSource() }));
5701 fetchr.addActionListener(new ActionListener()
5704 public void actionPerformed(ActionEvent e)
5706 new Thread(new Runnable()
5712 new DBRefFetcher(alignPanel.av
5713 .getSequenceSelection(),
5714 alignPanel.alignFrame, dassource)
5715 .fetchDBRefs(false);
5721 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5724 // and then build the rest of the individual menus
5725 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5727 String imname = null;
5729 for (DbSourceProxy sproxy : otherdb)
5731 String dbname = sproxy.getDbName();
5732 String sname = dbname.length() > 5 ? dbname.substring(0,
5733 5) + "..." : dbname;
5734 String msname = dbname.length() > 10 ? dbname.substring(
5735 0, 10) + "..." : dbname;
5738 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5740 fetchr = new JMenuItem(msname);
5741 final DbSourceProxy[] dassrc =
5743 fetchr.addActionListener(new ActionListener()
5747 public void actionPerformed(ActionEvent e)
5749 new Thread(new Runnable()
5755 new DBRefFetcher(alignPanel.av
5756 .getSequenceSelection(),
5757 alignPanel.alignFrame, dassrc)
5758 .fetchDBRefs(false);
5764 fetchr.setToolTipText("<html>"
5765 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5768 if (++icomp >= mcomp || i == (otherdb.size()))
5770 ifetch.setText(MessageManager.formatMessage(
5771 "label.source_to_target", imname, sname));
5773 ifetch = new JMenu();
5781 if (comp >= mcomp || dbi >= (dbclasses.length))
5783 dfetch.setText(MessageManager.formatMessage(
5784 "label.source_to_target", mname, dbclass));
5786 dfetch = new JMenu();
5799 * Left justify the whole alignment.
5802 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5804 AlignmentI al = viewport.getAlignment();
5806 viewport.firePropertyChange("alignment", null, al);
5810 * Right justify the whole alignment.
5813 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5815 AlignmentI al = viewport.getAlignment();
5817 viewport.firePropertyChange("alignment", null, al);
5820 public void setShowSeqFeatures(boolean b)
5822 showSeqFeatures.setSelected(b);
5823 viewport.setShowSequenceFeatures(b);
5830 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5831 * awt.event.ActionEvent)
5834 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5836 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5837 alignPanel.paintAlignment(true);
5844 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5848 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5850 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5851 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5859 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5860 * .event.ActionEvent)
5863 protected void showGroupConservation_actionPerformed(ActionEvent e)
5865 viewport.setShowGroupConservation(showGroupConservation.getState());
5866 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5873 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5874 * .event.ActionEvent)
5877 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5879 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5880 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5887 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5888 * .event.ActionEvent)
5891 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5893 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5894 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5898 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5900 showSequenceLogo.setState(true);
5901 viewport.setShowSequenceLogo(true);
5902 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5903 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5907 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5909 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5916 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5917 * .event.ActionEvent)
5920 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5922 if (avc.makeGroupsFromSelection())
5924 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5925 alignPanel.updateAnnotation();
5926 alignPanel.paintAlignment(true);
5929 public void clearAlignmentSeqRep()
5931 // TODO refactor alignmentseqrep to controller
5932 if (viewport.getAlignment().hasSeqrep()) {
5933 viewport.getAlignment().setSeqrep(null);
5934 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5935 alignPanel.updateAnnotation();
5936 alignPanel.paintAlignment(true);
5941 protected void createGroup_actionPerformed(ActionEvent e)
5943 if (avc.createGroup())
5945 alignPanel.alignmentChanged();
5950 protected void unGroup_actionPerformed(ActionEvent e)
5954 alignPanel.alignmentChanged();
5959 * make the given alignmentPanel the currently selected tab
5961 * @param alignmentPanel
5963 public void setDisplayedView(AlignmentPanel alignmentPanel)
5965 if (!viewport.getSequenceSetId().equals(
5966 alignmentPanel.av.getSequenceSetId()))
5968 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5970 if (tabbedPane != null
5971 && tabbedPane.getTabCount() > 0
5972 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5973 .getSelectedIndex())
5975 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5980 * Action on selection of menu options to Show or Hide annotations.
5983 * @param forSequences
5984 * update sequence-related annotations
5985 * @param forAlignment
5986 * update non-sequence-related annotations
5989 protected void setAnnotationsVisibility(boolean visible,
5990 boolean forSequences, boolean forAlignment)
5992 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5993 .getAlignmentAnnotation())
5996 * don't display non-positional annotations on an alignment
5998 if (aa.annotations == null)
6002 boolean apply = (aa.sequenceRef == null && forAlignment)
6003 || (aa.sequenceRef != null && forSequences);
6006 aa.visible = visible;
6009 alignPanel.validateAnnotationDimensions(true);
6010 alignPanel.alignmentChanged();
6014 * Store selected annotation sort order for the view and repaint.
6017 protected void sortAnnotations_actionPerformed()
6019 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6021 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6022 alignPanel.paintAlignment(true);
6027 * @return alignment panels in this alignment frame
6029 public List<? extends AlignmentViewPanel> getAlignPanels()
6031 return alignPanels == null ? Arrays.asList(alignPanel)
6036 * Open a new alignment window, with the cDNA associated with this (protein)
6037 * alignment, aligned as is the protein.
6039 protected void viewAsCdna_actionPerformed()
6041 // TODO no longer a menu action - refactor as required
6042 final AlignmentI alignment = getViewport().getAlignment();
6043 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6044 if (mappings == null)
6048 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6049 for (SequenceI aaSeq : alignment.getSequences()) {
6050 for (AlignedCodonFrame acf : mappings) {
6051 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6055 * There is a cDNA mapping for this protein sequence - add to new
6056 * alignment. It will share the same dataset sequence as other mapped
6057 * cDNA (no new mappings need to be created).
6059 final Sequence newSeq = new Sequence(dnaSeq);
6060 newSeq.setDatasetSequence(dnaSeq);
6061 cdnaSeqs.add(newSeq);
6065 if (cdnaSeqs.size() == 0)
6067 // show a warning dialog no mapped cDNA
6070 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6072 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6073 AlignFrame.DEFAULT_HEIGHT);
6074 cdna.alignAs(alignment);
6075 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6077 Desktop.addInternalFrame(alignFrame, newtitle,
6078 AlignFrame.DEFAULT_WIDTH,
6079 AlignFrame.DEFAULT_HEIGHT);
6083 * Set visibility of dna/protein complement view (available when shown in a
6089 protected void showComplement_actionPerformed(boolean show)
6091 SplitContainerI sf = getSplitViewContainer();
6093 sf.setComplementVisible(this, show);
6099 class PrintThread extends Thread
6103 public PrintThread(AlignmentPanel ap)
6108 static PageFormat pf;
6113 PrinterJob printJob = PrinterJob.getPrinterJob();
6117 printJob.setPrintable(ap, pf);
6121 printJob.setPrintable(ap);
6124 if (printJob.printDialog())
6129 } catch (Exception PrintException)
6131 PrintException.printStackTrace();