2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentSorter;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.analysis.CrossRef;
28 import jalview.analysis.Dna;
29 import jalview.analysis.ParseProperties;
30 import jalview.analysis.SequenceIdMatcher;
31 import jalview.api.AlignExportSettingI;
32 import jalview.api.AlignViewControllerGuiI;
33 import jalview.api.AlignViewControllerI;
34 import jalview.api.AlignViewportI;
35 import jalview.api.AlignmentViewPanel;
36 import jalview.api.FeatureSettingsControllerI;
37 import jalview.api.SplitContainerI;
38 import jalview.api.ViewStyleI;
39 import jalview.api.analysis.ScoreModelI;
40 import jalview.bin.Cache;
41 import jalview.commands.CommandI;
42 import jalview.commands.EditCommand;
43 import jalview.commands.EditCommand.Action;
44 import jalview.commands.OrderCommand;
45 import jalview.commands.RemoveGapColCommand;
46 import jalview.commands.RemoveGapsCommand;
47 import jalview.commands.SlideSequencesCommand;
48 import jalview.commands.TrimRegionCommand;
49 import jalview.datamodel.AlignedCodonFrame;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentI;
53 import jalview.datamodel.AlignmentOrder;
54 import jalview.datamodel.AlignmentView;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.HiddenSequences;
57 import jalview.datamodel.PDBEntry;
58 import jalview.datamodel.SeqCigar;
59 import jalview.datamodel.Sequence;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
63 import jalview.io.AlignmentProperties;
64 import jalview.io.AnnotationFile;
65 import jalview.io.BioJsHTMLOutput;
66 import jalview.io.FileLoader;
67 import jalview.io.FormatAdapter;
68 import jalview.io.HtmlSvgOutput;
69 import jalview.io.IdentifyFile;
70 import jalview.io.JalviewFileChooser;
71 import jalview.io.JalviewFileView;
72 import jalview.io.JnetAnnotationMaker;
73 import jalview.io.NewickFile;
74 import jalview.io.TCoffeeScoreFile;
75 import jalview.jbgui.GAlignFrame;
76 import jalview.schemes.Blosum62ColourScheme;
77 import jalview.schemes.BuriedColourScheme;
78 import jalview.schemes.ClustalxColourScheme;
79 import jalview.schemes.ColourSchemeI;
80 import jalview.schemes.ColourSchemeProperty;
81 import jalview.schemes.HelixColourScheme;
82 import jalview.schemes.HydrophobicColourScheme;
83 import jalview.schemes.NucleotideColourScheme;
84 import jalview.schemes.PIDColourScheme;
85 import jalview.schemes.PurinePyrimidineColourScheme;
86 import jalview.schemes.RNAHelicesColourChooser;
87 import jalview.schemes.ResidueProperties;
88 import jalview.schemes.StrandColourScheme;
89 import jalview.schemes.TCoffeeColourScheme;
90 import jalview.schemes.TaylorColourScheme;
91 import jalview.schemes.TurnColourScheme;
92 import jalview.schemes.UserColourScheme;
93 import jalview.schemes.ZappoColourScheme;
94 import jalview.structure.StructureSelectionManager;
95 import jalview.util.MessageManager;
96 import jalview.viewmodel.AlignmentViewport;
97 import jalview.ws.jws1.Discoverer;
98 import jalview.ws.jws2.Jws2Discoverer;
99 import jalview.ws.jws2.jabaws2.Jws2Instance;
100 import jalview.ws.seqfetcher.DbSourceProxy;
102 import java.awt.BorderLayout;
103 import java.awt.Component;
104 import java.awt.Rectangle;
105 import java.awt.Toolkit;
106 import java.awt.datatransfer.Clipboard;
107 import java.awt.datatransfer.DataFlavor;
108 import java.awt.datatransfer.StringSelection;
109 import java.awt.datatransfer.Transferable;
110 import java.awt.dnd.DnDConstants;
111 import java.awt.dnd.DropTargetDragEvent;
112 import java.awt.dnd.DropTargetDropEvent;
113 import java.awt.dnd.DropTargetEvent;
114 import java.awt.dnd.DropTargetListener;
115 import java.awt.event.ActionEvent;
116 import java.awt.event.ActionListener;
117 import java.awt.event.ItemEvent;
118 import java.awt.event.ItemListener;
119 import java.awt.event.KeyAdapter;
120 import java.awt.event.KeyEvent;
121 import java.awt.event.MouseAdapter;
122 import java.awt.event.MouseEvent;
123 import java.awt.print.PageFormat;
124 import java.awt.print.PrinterJob;
125 import java.beans.PropertyChangeEvent;
128 import java.util.ArrayList;
129 import java.util.Arrays;
130 import java.util.Deque;
131 import java.util.Enumeration;
132 import java.util.Hashtable;
133 import java.util.List;
134 import java.util.Set;
135 import java.util.Vector;
137 import javax.swing.JCheckBoxMenuItem;
138 import javax.swing.JEditorPane;
139 import javax.swing.JInternalFrame;
140 import javax.swing.JLayeredPane;
141 import javax.swing.JMenu;
142 import javax.swing.JMenuItem;
143 import javax.swing.JOptionPane;
144 import javax.swing.JRadioButtonMenuItem;
145 import javax.swing.JScrollPane;
146 import javax.swing.SwingUtilities;
152 * @version $Revision$
154 public class AlignFrame extends GAlignFrame implements DropTargetListener,
155 IProgressIndicator, AlignViewControllerGuiI
158 public static final int DEFAULT_WIDTH = 700;
160 public static final int DEFAULT_HEIGHT = 500;
163 * The currently displayed panel (selected tabbed view if more than one)
165 public AlignmentPanel alignPanel;
167 AlignViewport viewport;
169 public AlignViewControllerI avc;
171 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
174 * Last format used to load or save alignments in this window
176 String currentFileFormat = null;
179 * Current filename for this alignment
181 String fileName = null;
184 * Creates a new AlignFrame object with specific width and height.
190 public AlignFrame(AlignmentI al, int width, int height)
192 this(al, null, width, height);
196 * Creates a new AlignFrame object with specific width, height and
202 * @param sequenceSetId
204 public AlignFrame(AlignmentI al, int width, int height,
205 String sequenceSetId)
207 this(al, null, width, height, sequenceSetId);
211 * Creates a new AlignFrame object with specific width, height and
217 * @param sequenceSetId
220 public AlignFrame(AlignmentI al, int width, int height,
221 String sequenceSetId, String viewId)
223 this(al, null, width, height, sequenceSetId, viewId);
227 * new alignment window with hidden columns
231 * @param hiddenColumns
232 * ColumnSelection or null
234 * Width of alignment frame
238 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
239 int width, int height)
241 this(al, hiddenColumns, width, height, null);
246 * Create alignment frame for al with hiddenColumns, a specific width and
247 * height, and specific sequenceId
250 * @param hiddenColumns
253 * @param sequenceSetId
256 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
257 int width, int height, String sequenceSetId)
259 this(al, hiddenColumns, width, height, sequenceSetId, null);
263 * Create alignment frame for al with hiddenColumns, a specific width and
264 * height, and specific sequenceId
267 * @param hiddenColumns
270 * @param sequenceSetId
275 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
276 int width, int height, String sequenceSetId, String viewId)
278 setSize(width, height);
280 if (al.getDataset() == null)
285 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
287 alignPanel = new AlignmentPanel(this, viewport);
290 addAlignmentPanel(alignPanel, true);
294 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
295 ColumnSelection hiddenColumns, int width, int height)
297 setSize(width, height);
299 if (al.getDataset() == null)
304 viewport = new AlignViewport(al, hiddenColumns);
306 if (hiddenSeqs != null && hiddenSeqs.length > 0)
308 viewport.hideSequence(hiddenSeqs);
310 alignPanel = new AlignmentPanel(this, viewport);
311 addAlignmentPanel(alignPanel, true);
317 * Make a new AlignFrame from existing alignmentPanels
324 public AlignFrame(AlignmentPanel ap)
328 addAlignmentPanel(ap, false);
333 * initalise the alignframe from the underlying viewport data and the
338 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
340 avc = new jalview.controller.AlignViewController(this, viewport,
342 if (viewport.getAlignmentConservationAnnotation() == null)
344 BLOSUM62Colour.setEnabled(false);
345 conservationMenuItem.setEnabled(false);
346 modifyConservation.setEnabled(false);
347 // PIDColour.setEnabled(false);
348 // abovePIDThreshold.setEnabled(false);
349 // modifyPID.setEnabled(false);
352 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
355 if (sortby.equals("Id"))
357 sortIDMenuItem_actionPerformed(null);
359 else if (sortby.equals("Pairwise Identity"))
361 sortPairwiseMenuItem_actionPerformed(null);
364 if (Desktop.desktop != null)
366 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
367 addServiceListeners();
368 setGUINucleotide(viewport.getAlignment().isNucleotide());
371 setMenusFromViewport(viewport);
372 buildSortByAnnotationScoresMenu();
375 if (viewport.getWrapAlignment())
377 wrapMenuItem_actionPerformed(null);
380 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
382 this.overviewMenuItem_actionPerformed(null);
387 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
388 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
389 final String menuLabel = MessageManager
390 .getString("label.copy_format_from");
391 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
392 new ViewSetProvider()
396 public AlignmentPanel[] getAllAlignmentPanels()
399 origview.add(alignPanel);
400 // make an array of all alignment panels except for this one
401 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
402 Arrays.asList(Desktop.getAlignmentPanels(null)));
403 aps.remove(AlignFrame.this.alignPanel);
404 return aps.toArray(new AlignmentPanel[aps.size()]);
406 }, selviews, new ItemListener()
410 public void itemStateChanged(ItemEvent e)
412 if (origview.size() > 0)
414 final AlignmentPanel ap = origview.get(0);
417 * Copy the ViewStyle of the selected panel to 'this one'.
418 * Don't change value of 'scaleProteinAsCdna' unless copying
421 ViewStyleI vs = selviews.get(0).getAlignViewport()
423 boolean fromSplitFrame = selviews.get(0)
424 .getAlignViewport().getCodingComplement() != null;
427 vs.setScaleProteinAsCdna(ap.getAlignViewport()
428 .getViewStyle().isScaleProteinAsCdna());
430 ap.getAlignViewport().setViewStyle(vs);
433 * Also rescale ViewStyle of SplitFrame complement if there is
434 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
435 * the whole ViewStyle (allow cDNA protein to have different
438 AlignViewportI complement = ap.getAlignViewport()
439 .getCodingComplement();
440 if (complement != null && vs.isScaleProteinAsCdna())
442 AlignFrame af = Desktop.getAlignFrameFor(complement);
443 ((SplitFrame) af.getSplitViewContainer())
445 af.setMenusForViewport();
449 ap.setSelected(true);
450 ap.alignFrame.setMenusForViewport();
455 formatMenu.add(vsel);
460 * Change the filename and format for the alignment, and enable the 'reload'
461 * button functionality.
468 public void setFileName(String file, String format)
471 setFileFormat(format);
472 reload.setEnabled(true);
476 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
479 void addKeyListener()
481 addKeyListener(new KeyAdapter()
484 public void keyPressed(KeyEvent evt)
486 if (viewport.cursorMode
487 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
488 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
489 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
490 && Character.isDigit(evt.getKeyChar()))
492 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
495 switch (evt.getKeyCode())
498 case 27: // escape key
499 deselectAllSequenceMenuItem_actionPerformed(null);
503 case KeyEvent.VK_DOWN:
504 if (evt.isAltDown() || !viewport.cursorMode)
506 moveSelectedSequences(false);
508 if (viewport.cursorMode)
510 alignPanel.getSeqPanel().moveCursor(0, 1);
515 if (evt.isAltDown() || !viewport.cursorMode)
517 moveSelectedSequences(true);
519 if (viewport.cursorMode)
521 alignPanel.getSeqPanel().moveCursor(0, -1);
526 case KeyEvent.VK_LEFT:
527 if (evt.isAltDown() || !viewport.cursorMode)
529 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
533 alignPanel.getSeqPanel().moveCursor(-1, 0);
538 case KeyEvent.VK_RIGHT:
539 if (evt.isAltDown() || !viewport.cursorMode)
541 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
545 alignPanel.getSeqPanel().moveCursor(1, 0);
549 case KeyEvent.VK_SPACE:
550 if (viewport.cursorMode)
552 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
553 || evt.isShiftDown() || evt.isAltDown());
557 // case KeyEvent.VK_A:
558 // if (viewport.cursorMode)
560 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
561 // //System.out.println("A");
565 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
566 * System.out.println("closing bracket"); } break;
568 case KeyEvent.VK_DELETE:
569 case KeyEvent.VK_BACK_SPACE:
570 if (!viewport.cursorMode)
572 cut_actionPerformed(null);
576 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
577 || evt.isShiftDown() || evt.isAltDown());
583 if (viewport.cursorMode)
585 alignPanel.getSeqPanel().setCursorRow();
589 if (viewport.cursorMode && !evt.isControlDown())
591 alignPanel.getSeqPanel().setCursorColumn();
595 if (viewport.cursorMode)
597 alignPanel.getSeqPanel().setCursorPosition();
601 case KeyEvent.VK_ENTER:
602 case KeyEvent.VK_COMMA:
603 if (viewport.cursorMode)
605 alignPanel.getSeqPanel().setCursorRowAndColumn();
610 if (viewport.cursorMode)
612 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
616 if (viewport.cursorMode)
618 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
623 viewport.cursorMode = !viewport.cursorMode;
624 statusBar.setText(MessageManager.formatMessage(
625 "label.keyboard_editing_mode", new String[]
626 { (viewport.cursorMode ? "on" : "off") }));
627 if (viewport.cursorMode)
629 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
630 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
632 alignPanel.getSeqPanel().seqCanvas.repaint();
638 Help.showHelpWindow();
639 } catch (Exception ex)
641 ex.printStackTrace();
646 boolean toggleSeqs = !evt.isControlDown();
647 boolean toggleCols = !evt.isShiftDown();
648 toggleHiddenRegions(toggleSeqs, toggleCols);
651 case KeyEvent.VK_PAGE_UP:
652 if (viewport.getWrapAlignment())
654 alignPanel.scrollUp(true);
658 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
659 - viewport.endSeq + viewport.startSeq);
662 case KeyEvent.VK_PAGE_DOWN:
663 if (viewport.getWrapAlignment())
665 alignPanel.scrollUp(false);
669 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
670 + viewport.endSeq - viewport.startSeq);
677 public void keyReleased(KeyEvent evt)
679 switch (evt.getKeyCode())
681 case KeyEvent.VK_LEFT:
682 if (evt.isAltDown() || !viewport.cursorMode)
684 viewport.firePropertyChange("alignment", null, viewport
685 .getAlignment().getSequences());
689 case KeyEvent.VK_RIGHT:
690 if (evt.isAltDown() || !viewport.cursorMode)
692 viewport.firePropertyChange("alignment", null, viewport
693 .getAlignment().getSequences());
701 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
703 ap.alignFrame = this;
704 avc = new jalview.controller.AlignViewController(this, viewport,
709 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
711 int aSize = alignPanels.size();
713 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
715 if (aSize == 1 && ap.av.viewName == null)
717 this.getContentPane().add(ap, BorderLayout.CENTER);
723 setInitialTabVisible();
726 expandViews.setEnabled(true);
727 gatherViews.setEnabled(true);
728 tabbedPane.addTab(ap.av.viewName, ap);
730 ap.setVisible(false);
735 if (ap.av.isPadGaps())
737 ap.av.getAlignment().padGaps();
739 ap.av.updateConservation(ap);
740 ap.av.updateConsensus(ap);
741 ap.av.updateStrucConsensus(ap);
745 public void setInitialTabVisible()
747 expandViews.setEnabled(true);
748 gatherViews.setEnabled(true);
749 tabbedPane.setVisible(true);
750 AlignmentPanel first = alignPanels.get(0);
751 tabbedPane.addTab(first.av.viewName, first);
752 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
755 public AlignViewport getViewport()
760 /* Set up intrinsic listeners for dynamically generated GUI bits. */
761 private void addServiceListeners()
763 final java.beans.PropertyChangeListener thisListener;
764 Desktop.instance.addJalviewPropertyChangeListener("services",
765 thisListener = new java.beans.PropertyChangeListener()
768 public void propertyChange(PropertyChangeEvent evt)
770 // // System.out.println("Discoverer property change.");
771 // if (evt.getPropertyName().equals("services"))
773 SwingUtilities.invokeLater(new Runnable()
780 .println("Rebuild WS Menu for service change");
781 BuildWebServiceMenu();
788 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
791 public void internalFrameClosed(
792 javax.swing.event.InternalFrameEvent evt)
794 System.out.println("deregistering discoverer listener");
795 Desktop.instance.removeJalviewPropertyChangeListener("services",
797 closeMenuItem_actionPerformed(true);
800 // Finally, build the menu once to get current service state
801 new Thread(new Runnable()
806 BuildWebServiceMenu();
812 * Configure menu items that vary according to whether the alignment is
813 * nucleotide or protein
817 public void setGUINucleotide(boolean nucleotide)
819 showTranslation.setVisible(nucleotide);
820 conservationMenuItem.setEnabled(!nucleotide);
821 modifyConservation.setEnabled(!nucleotide);
822 showGroupConservation.setEnabled(!nucleotide);
823 rnahelicesColour.setEnabled(nucleotide);
824 purinePyrimidineColour.setEnabled(nucleotide);
825 showComplementMenuItem.setText(MessageManager
826 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
827 setColourSelected(jalview.bin.Cache.getDefault(
828 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
829 : Preferences.DEFAULT_COLOUR_PROT, "None"));
833 * set up menus for the current viewport. This may be called after any
834 * operation that affects the data in the current view (selection changed,
835 * etc) to update the menus to reflect the new state.
837 public void setMenusForViewport()
839 setMenusFromViewport(viewport);
843 * Need to call this method when tabs are selected for multiple views, or when
844 * loading from Jalview2XML.java
849 void setMenusFromViewport(AlignViewport av)
851 padGapsMenuitem.setSelected(av.isPadGaps());
852 colourTextMenuItem.setSelected(av.isShowColourText());
853 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
854 conservationMenuItem.setSelected(av.getConservationSelected());
855 seqLimits.setSelected(av.getShowJVSuffix());
856 idRightAlign.setSelected(av.isRightAlignIds());
857 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
858 renderGapsMenuItem.setSelected(av.isRenderGaps());
859 wrapMenuItem.setSelected(av.getWrapAlignment());
860 scaleAbove.setVisible(av.getWrapAlignment());
861 scaleLeft.setVisible(av.getWrapAlignment());
862 scaleRight.setVisible(av.getWrapAlignment());
863 annotationPanelMenuItem.setState(av.isShowAnnotation());
865 * Show/hide annotations only enabled if annotation panel is shown
867 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
868 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
869 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
870 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
871 viewBoxesMenuItem.setSelected(av.getShowBoxes());
872 viewTextMenuItem.setSelected(av.getShowText());
873 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
874 showGroupConsensus.setSelected(av.isShowGroupConsensus());
875 showGroupConservation.setSelected(av.isShowGroupConservation());
876 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
877 showSequenceLogo.setSelected(av.isShowSequenceLogo());
878 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
880 setColourSelected(ColourSchemeProperty.getColourName(av
881 .getGlobalColourScheme()));
883 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
884 hiddenMarkers.setState(av.getShowHiddenMarkers());
885 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
886 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
887 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
888 autoCalculate.setSelected(av.autoCalculateConsensus);
889 sortByTree.setSelected(av.sortByTree);
890 listenToViewSelections.setSelected(av.followSelection);
891 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
893 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
894 setShowProductsEnabled();
898 private IProgressIndicator progressBar;
903 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
906 public void setProgressBar(String message, long id)
908 progressBar.setProgressBar(message, id);
912 public void registerHandler(final long id,
913 final IProgressIndicatorHandler handler)
915 progressBar.registerHandler(id, handler);
920 * @return true if any progress bars are still active
923 public boolean operationInProgress()
925 return progressBar.operationInProgress();
929 public void setStatus(String text)
931 statusBar.setText(text);
935 * Added so Castor Mapping file can obtain Jalview Version
937 public String getVersion()
939 return jalview.bin.Cache.getProperty("VERSION");
942 public FeatureRenderer getFeatureRenderer()
944 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
948 public void fetchSequence_actionPerformed(ActionEvent e)
950 new SequenceFetcher(this);
954 public void addFromFile_actionPerformed(ActionEvent e)
956 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
960 public void reload_actionPerformed(ActionEvent e)
962 if (fileName != null)
964 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
965 // originating file's format
966 // TODO: work out how to recover feature settings for correct view(s) when
968 if (currentFileFormat.equals("Jalview"))
970 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
971 for (int i = 0; i < frames.length; i++)
973 if (frames[i] instanceof AlignFrame && frames[i] != this
974 && ((AlignFrame) frames[i]).fileName != null
975 && ((AlignFrame) frames[i]).fileName.equals(fileName))
979 frames[i].setSelected(true);
980 Desktop.instance.closeAssociatedWindows();
981 } catch (java.beans.PropertyVetoException ex)
987 Desktop.instance.closeAssociatedWindows();
989 FileLoader loader = new FileLoader();
990 String protocol = fileName.startsWith("http:") ? "URL" : "File";
991 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
995 Rectangle bounds = this.getBounds();
997 FileLoader loader = new FileLoader();
998 String protocol = fileName.startsWith("http:") ? "URL" : "File";
999 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1000 protocol, currentFileFormat);
1002 newframe.setBounds(bounds);
1003 if (featureSettings != null && featureSettings.isShowing())
1005 final Rectangle fspos = featureSettings.frame.getBounds();
1006 // TODO: need a 'show feature settings' function that takes bounds -
1007 // need to refactor Desktop.addFrame
1008 newframe.featureSettings_actionPerformed(null);
1009 final FeatureSettings nfs = newframe.featureSettings;
1010 SwingUtilities.invokeLater(new Runnable()
1015 nfs.frame.setBounds(fspos);
1018 this.featureSettings.close();
1019 this.featureSettings = null;
1021 this.closeMenuItem_actionPerformed(true);
1027 public void addFromText_actionPerformed(ActionEvent e)
1029 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1033 public void addFromURL_actionPerformed(ActionEvent e)
1035 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1039 public void save_actionPerformed(ActionEvent e)
1041 if (fileName == null
1042 || (currentFileFormat == null || !jalview.io.FormatAdapter
1043 .isValidIOFormat(currentFileFormat, true))
1044 || fileName.startsWith("http"))
1046 saveAs_actionPerformed(null);
1050 saveAlignment(fileName, currentFileFormat);
1061 public void saveAs_actionPerformed(ActionEvent e)
1063 JalviewFileChooser chooser = new JalviewFileChooser(
1064 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1065 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1066 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1067 currentFileFormat, false);
1069 chooser.setFileView(new JalviewFileView());
1070 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1071 chooser.setToolTipText(MessageManager.getString("action.save"));
1073 int value = chooser.showSaveDialog(this);
1075 if (value == JalviewFileChooser.APPROVE_OPTION)
1077 currentFileFormat = chooser.getSelectedFormat();
1078 while (currentFileFormat == null)
1081 .showInternalMessageDialog(
1084 .getString("label.select_file_format_before_saving"),
1086 .getString("label.file_format_not_specified"),
1087 JOptionPane.WARNING_MESSAGE);
1088 currentFileFormat = chooser.getSelectedFormat();
1089 value = chooser.showSaveDialog(this);
1090 if (value != JalviewFileChooser.APPROVE_OPTION)
1096 fileName = chooser.getSelectedFile().getPath();
1098 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1101 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1102 if (currentFileFormat.indexOf(" ") > -1)
1104 currentFileFormat = currentFileFormat.substring(0,
1105 currentFileFormat.indexOf(" "));
1107 saveAlignment(fileName, currentFileFormat);
1111 public boolean saveAlignment(String file, String format)
1113 boolean success = true;
1115 if (format.equalsIgnoreCase("Jalview"))
1117 String shortName = title;
1119 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1121 shortName = shortName.substring(shortName
1122 .lastIndexOf(java.io.File.separatorChar) + 1);
1125 success = new Jalview2XML().saveAlignment(this, file, shortName);
1127 statusBar.setText(MessageManager.formatMessage(
1128 "label.successfully_saved_to_file_in_format", new Object[]
1129 { fileName, format }));
1134 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1136 warningMessage("Cannot save file " + fileName + " using format "
1137 + format, "Alignment output format not supported");
1138 saveAs_actionPerformed(null);
1139 // JBPNote need to have a raise_gui flag here
1143 ExportData exportData = getAlignmentForExport(format);
1144 FormatAdapter f = new FormatAdapter(viewport);
1145 String output = f.formatSequences(format,
1146 exportData.getAlignment(), // class cast exceptions will
1147 // occur in the distant future
1148 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1149 f.getCacheSuffixDefault(format),
1150 viewport.getColumnSelection());
1160 java.io.PrintWriter out = new java.io.PrintWriter(
1161 new java.io.FileWriter(file));
1165 this.setTitle(file);
1166 statusBar.setText(MessageManager.formatMessage(
1167 "label.successfully_saved_to_file_in_format",
1169 { fileName, format }));
1170 } catch (Exception ex)
1173 ex.printStackTrace();
1180 JOptionPane.showInternalMessageDialog(this, MessageManager
1181 .formatMessage("label.couldnt_save_file", new Object[]
1182 { fileName }), MessageManager
1183 .getString("label.error_saving_file"),
1184 JOptionPane.WARNING_MESSAGE);
1191 private void warningMessage(String warning, String title)
1193 if (new jalview.util.Platform().isHeadless())
1195 System.err.println("Warning: " + title + "\nWarning: " + warning);
1200 JOptionPane.showInternalMessageDialog(this, warning, title,
1201 JOptionPane.WARNING_MESSAGE);
1213 protected void outputText_actionPerformed(ActionEvent e)
1216 ExportData exportData = getAlignmentForExport(e.getActionCommand());
1217 if (exportData.getSettings().isCancelled())
1221 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1222 cap.setForInput(null);
1225 cap.setText(new FormatAdapter(viewport).formatSequences(
1226 e.getActionCommand(),
1227 exportData.getAlignment(),
1228 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1229 viewport.getColumnSelection()));
1230 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1231 "label.alignment_output_command", new Object[]
1232 { e.getActionCommand() }), 600, 500);
1233 } catch (OutOfMemoryError oom)
1235 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1241 public ExportData getAlignmentForExport(String exportFomat)
1243 AlignmentI alignmentToExport = null;
1244 String[] omitHidden = null;
1245 int[] alignmentStartEnd = new int[2];
1247 HiddenSequences hiddenSeqs = viewport.getAlignment()
1248 .getHiddenSequences();
1251 alignmentToExport = viewport.getAlignment();
1252 alignmentStartEnd = new int[]
1253 { 0, alignmentToExport.getWidth() - 1 };
1255 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1256 AlignExportSettingI settings = new AlignExportSettings(hasHiddenSeqs,
1257 viewport.hasHiddenColumns(), exportFomat);
1258 settings.isExportAnnotations();
1260 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1262 omitHidden = viewport.getViewAsString(false);
1265 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1267 alignmentToExport = hiddenSeqs.getFullAlignment();
1271 alignmentToExport = viewport.getAlignment();
1272 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1273 .getColumnSelection().getHiddenColumns());
1275 return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd,
1279 private static int[] getStartEnd(int[] aligmentStartEnd,
1280 List<int[]> hiddenCols)
1282 int startPos = aligmentStartEnd[0];
1283 int endPos = aligmentStartEnd[1];
1285 int[] lowestRange = new int[2];
1286 int[] higestRange = new int[2];
1288 for (int[] hiddenCol : hiddenCols)
1290 // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
1292 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1293 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1295 // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
1296 // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
1298 if (lowestRange[0] == 0 && lowestRange[1] == 0)
1300 startPos = aligmentStartEnd[0];
1304 startPos = lowestRange[1] + 1;
1307 if (higestRange[0] == 0 && higestRange[1] == 0)
1309 endPos = aligmentStartEnd[1];
1313 endPos = higestRange[0];
1316 // System.out.println("Export range : " + minPos + " - " + maxPos);
1318 { startPos, endPos };
1321 public static void main(String[] args)
1323 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1324 hiddenCols.add(new int[]
1326 hiddenCols.add(new int[]
1328 hiddenCols.add(new int[]
1330 hiddenCols.add(new int[]
1332 hiddenCols.add(new int[]
1335 int[] x = getStartEnd(new int[]
1336 { 0, 50 }, hiddenCols);
1337 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1347 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1349 new HtmlSvgOutput(null, alignPanel);
1353 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1355 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1356 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1358 public void createImageMap(File file, String image)
1360 alignPanel.makePNGImageMap(file, image);
1370 public void createPNG(File f)
1372 alignPanel.makePNG(f);
1382 public void createEPS(File f)
1384 alignPanel.makeEPS(f);
1387 public void createSVG(File f)
1389 alignPanel.makeSVG(f);
1392 public void pageSetup_actionPerformed(ActionEvent e)
1394 PrinterJob printJob = PrinterJob.getPrinterJob();
1395 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1405 public void printMenuItem_actionPerformed(ActionEvent e)
1407 // Putting in a thread avoids Swing painting problems
1408 PrintThread thread = new PrintThread(alignPanel);
1413 public void exportFeatures_actionPerformed(ActionEvent e)
1415 new AnnotationExporter().exportFeatures(alignPanel);
1419 public void exportAnnotations_actionPerformed(ActionEvent e)
1421 new AnnotationExporter().exportAnnotations(alignPanel);
1425 public void associatedData_actionPerformed(ActionEvent e)
1427 // Pick the tree file
1428 JalviewFileChooser chooser = new JalviewFileChooser(
1429 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1430 chooser.setFileView(new JalviewFileView());
1431 chooser.setDialogTitle(MessageManager
1432 .getString("label.load_jalview_annotations"));
1433 chooser.setToolTipText(MessageManager
1434 .getString("label.load_jalview_annotations"));
1436 int value = chooser.showOpenDialog(null);
1438 if (value == JalviewFileChooser.APPROVE_OPTION)
1440 String choice = chooser.getSelectedFile().getPath();
1441 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1442 loadJalviewDataFile(choice, null, null, null);
1448 * Close the current view or all views in the alignment frame. If the frame
1449 * only contains one view then the alignment will be removed from memory.
1451 * @param closeAllTabs
1454 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1456 if (alignPanels != null && alignPanels.size() < 2)
1458 closeAllTabs = true;
1463 if (alignPanels != null)
1467 if (this.isClosed())
1469 // really close all the windows - otherwise wait till
1470 // setClosed(true) is called
1471 for (int i = 0; i < alignPanels.size(); i++)
1473 AlignmentPanel ap = alignPanels.get(i);
1480 closeView(alignPanel);
1486 this.setClosed(true);
1488 } catch (Exception ex)
1490 ex.printStackTrace();
1495 * Close the specified panel and close up tabs appropriately.
1497 * @param panelToClose
1499 public void closeView(AlignmentPanel panelToClose)
1501 int index = tabbedPane.getSelectedIndex();
1502 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1503 alignPanels.remove(panelToClose);
1504 panelToClose.closePanel();
1505 panelToClose = null;
1507 tabbedPane.removeTabAt(closedindex);
1508 tabbedPane.validate();
1510 if (index > closedindex || index == tabbedPane.getTabCount())
1512 // modify currently selected tab index if necessary.
1516 this.tabSelectionChanged(index);
1522 void updateEditMenuBar()
1525 if (viewport.getHistoryList().size() > 0)
1527 undoMenuItem.setEnabled(true);
1528 CommandI command = viewport.getHistoryList().peek();
1529 undoMenuItem.setText(MessageManager.formatMessage(
1530 "label.undo_command", new Object[]
1531 { command.getDescription() }));
1535 undoMenuItem.setEnabled(false);
1536 undoMenuItem.setText(MessageManager.getString("action.undo"));
1539 if (viewport.getRedoList().size() > 0)
1541 redoMenuItem.setEnabled(true);
1543 CommandI command = viewport.getRedoList().peek();
1544 redoMenuItem.setText(MessageManager.formatMessage(
1545 "label.redo_command", new Object[]
1546 { command.getDescription() }));
1550 redoMenuItem.setEnabled(false);
1551 redoMenuItem.setText(MessageManager.getString("action.redo"));
1555 public void addHistoryItem(CommandI command)
1557 if (command.getSize() > 0)
1559 viewport.addToHistoryList(command);
1560 viewport.clearRedoList();
1561 updateEditMenuBar();
1562 viewport.updateHiddenColumns();
1563 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1564 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1565 // viewport.getColumnSelection()
1566 // .getHiddenColumns().size() > 0);
1572 * @return alignment objects for all views
1574 AlignmentI[] getViewAlignments()
1576 if (alignPanels != null)
1578 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1580 for (AlignmentPanel ap : alignPanels)
1582 als[i++] = ap.av.getAlignment();
1586 if (viewport != null)
1588 return new AlignmentI[]
1589 { viewport.getAlignment() };
1601 protected void undoMenuItem_actionPerformed(ActionEvent e)
1603 if (viewport.getHistoryList().isEmpty())
1607 CommandI command = viewport.getHistoryList().pop();
1608 viewport.addToRedoList(command);
1609 command.undoCommand(getViewAlignments());
1611 AlignmentViewport originalSource = getOriginatingSource(command);
1612 updateEditMenuBar();
1614 if (originalSource != null)
1616 if (originalSource != viewport)
1619 .warn("Implementation worry: mismatch of viewport origin for undo");
1621 originalSource.updateHiddenColumns();
1622 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1624 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1625 // viewport.getColumnSelection()
1626 // .getHiddenColumns().size() > 0);
1627 originalSource.firePropertyChange("alignment", null, originalSource
1628 .getAlignment().getSequences());
1639 protected void redoMenuItem_actionPerformed(ActionEvent e)
1641 if (viewport.getRedoList().size() < 1)
1646 CommandI command = viewport.getRedoList().pop();
1647 viewport.addToHistoryList(command);
1648 command.doCommand(getViewAlignments());
1650 AlignmentViewport originalSource = getOriginatingSource(command);
1651 updateEditMenuBar();
1653 if (originalSource != null)
1656 if (originalSource != viewport)
1659 .warn("Implementation worry: mismatch of viewport origin for redo");
1661 originalSource.updateHiddenColumns();
1662 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1664 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1665 // viewport.getColumnSelection()
1666 // .getHiddenColumns().size() > 0);
1667 originalSource.firePropertyChange("alignment", null, originalSource
1668 .getAlignment().getSequences());
1672 AlignmentViewport getOriginatingSource(CommandI command)
1674 AlignmentViewport originalSource = null;
1675 // For sequence removal and addition, we need to fire
1676 // the property change event FROM the viewport where the
1677 // original alignment was altered
1678 AlignmentI al = null;
1679 if (command instanceof EditCommand)
1681 EditCommand editCommand = (EditCommand) command;
1682 al = editCommand.getAlignment();
1683 List<Component> comps = PaintRefresher.components.get(viewport
1684 .getSequenceSetId());
1686 for (Component comp : comps)
1688 if (comp instanceof AlignmentPanel)
1690 if (al == ((AlignmentPanel) comp).av.getAlignment())
1692 originalSource = ((AlignmentPanel) comp).av;
1699 if (originalSource == null)
1701 // The original view is closed, we must validate
1702 // the current view against the closed view first
1705 PaintRefresher.validateSequences(al, viewport.getAlignment());
1708 originalSource = viewport;
1711 return originalSource;
1720 public void moveSelectedSequences(boolean up)
1722 SequenceGroup sg = viewport.getSelectionGroup();
1728 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1729 viewport.getHiddenRepSequences(), up);
1730 alignPanel.paintAlignment(true);
1733 synchronized void slideSequences(boolean right, int size)
1735 List<SequenceI> sg = new ArrayList<SequenceI>();
1736 if (viewport.cursorMode)
1738 sg.add(viewport.getAlignment().getSequenceAt(
1739 alignPanel.getSeqPanel().seqCanvas.cursorY));
1741 else if (viewport.getSelectionGroup() != null
1742 && viewport.getSelectionGroup().getSize() != viewport
1743 .getAlignment().getHeight())
1745 sg = viewport.getSelectionGroup().getSequences(
1746 viewport.getHiddenRepSequences());
1754 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1756 for (SequenceI seq : viewport.getAlignment().getSequences())
1758 if (!sg.contains(seq))
1760 invertGroup.add(seq);
1764 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1766 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1767 for (int i = 0; i < invertGroup.size(); i++)
1769 seqs2[i] = invertGroup.get(i);
1772 SlideSequencesCommand ssc;
1775 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1776 size, viewport.getGapCharacter());
1780 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1781 size, viewport.getGapCharacter());
1784 int groupAdjustment = 0;
1785 if (ssc.getGapsInsertedBegin() && right)
1787 if (viewport.cursorMode)
1789 alignPanel.getSeqPanel().moveCursor(size, 0);
1793 groupAdjustment = size;
1796 else if (!ssc.getGapsInsertedBegin() && !right)
1798 if (viewport.cursorMode)
1800 alignPanel.getSeqPanel().moveCursor(-size, 0);
1804 groupAdjustment = -size;
1808 if (groupAdjustment != 0)
1810 viewport.getSelectionGroup().setStartRes(
1811 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1812 viewport.getSelectionGroup().setEndRes(
1813 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1816 boolean appendHistoryItem = false;
1817 Deque<CommandI> historyList = viewport.getHistoryList();
1818 if (historyList != null
1819 && historyList.size() > 0
1820 && historyList.peek() instanceof SlideSequencesCommand)
1822 appendHistoryItem = ssc
1823 .appendSlideCommand((SlideSequencesCommand) historyList
1827 if (!appendHistoryItem)
1829 addHistoryItem(ssc);
1842 protected void copy_actionPerformed(ActionEvent e)
1845 if (viewport.getSelectionGroup() == null)
1849 // TODO: preserve the ordering of displayed alignment annotation in any
1850 // internal paste (particularly sequence associated annotation)
1851 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1852 String[] omitHidden = null;
1854 if (viewport.hasHiddenColumns())
1856 omitHidden = viewport.getViewAsString(true);
1859 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1862 StringSelection ss = new StringSelection(output);
1866 jalview.gui.Desktop.internalCopy = true;
1867 // Its really worth setting the clipboard contents
1868 // to empty before setting the large StringSelection!!
1869 Toolkit.getDefaultToolkit().getSystemClipboard()
1870 .setContents(new StringSelection(""), null);
1872 Toolkit.getDefaultToolkit().getSystemClipboard()
1873 .setContents(ss, Desktop.instance);
1874 } catch (OutOfMemoryError er)
1876 new OOMWarning("copying region", er);
1880 ArrayList<int[]> hiddenColumns = null;
1881 if (viewport.hasHiddenColumns())
1883 hiddenColumns = new ArrayList<int[]>();
1884 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1885 .getSelectionGroup().getEndRes();
1886 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1888 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1890 hiddenColumns.add(new int[]
1891 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1896 Desktop.jalviewClipboard = new Object[]
1897 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1898 statusBar.setText(MessageManager.formatMessage(
1899 "label.copied_sequences_to_clipboard", new Object[]
1900 { Integer.valueOf(seqs.length).toString() }));
1910 protected void pasteNew_actionPerformed(ActionEvent e)
1922 protected void pasteThis_actionPerformed(ActionEvent e)
1928 * Paste contents of Jalview clipboard
1930 * @param newAlignment
1931 * true to paste to a new alignment, otherwise add to this.
1933 void paste(boolean newAlignment)
1935 boolean externalPaste = true;
1938 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1939 Transferable contents = c.getContents(this);
1941 if (contents == null)
1949 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1950 if (str.length() < 1)
1955 format = new IdentifyFile().Identify(str, "Paste");
1957 } catch (OutOfMemoryError er)
1959 new OOMWarning("Out of memory pasting sequences!!", er);
1963 SequenceI[] sequences;
1964 boolean annotationAdded = false;
1965 AlignmentI alignment = null;
1967 if (Desktop.jalviewClipboard != null)
1969 // The clipboard was filled from within Jalview, we must use the
1971 // And dataset from the copied alignment
1972 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1973 // be doubly sure that we create *new* sequence objects.
1974 sequences = new SequenceI[newseq.length];
1975 for (int i = 0; i < newseq.length; i++)
1977 sequences[i] = new Sequence(newseq[i]);
1979 alignment = new Alignment(sequences);
1980 externalPaste = false;
1984 // parse the clipboard as an alignment.
1985 alignment = new FormatAdapter().readFile(str, "Paste", format);
1986 sequences = alignment.getSequencesArray();
1990 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1996 if (Desktop.jalviewClipboard != null)
1998 // dataset is inherited
1999 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2003 // new dataset is constructed
2004 alignment.setDataset(null);
2006 alwidth = alignment.getWidth() + 1;
2010 AlignmentI pastedal = alignment; // preserve pasted alignment object
2011 // Add pasted sequences and dataset into existing alignment.
2012 alignment = viewport.getAlignment();
2013 alwidth = alignment.getWidth() + 1;
2014 // decide if we need to import sequences from an existing dataset
2015 boolean importDs = Desktop.jalviewClipboard != null
2016 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2017 // importDs==true instructs us to copy over new dataset sequences from
2018 // an existing alignment
2019 Vector newDs = (importDs) ? new Vector() : null; // used to create
2020 // minimum dataset set
2022 for (int i = 0; i < sequences.length; i++)
2026 newDs.addElement(null);
2028 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2030 if (importDs && ds != null)
2032 if (!newDs.contains(ds))
2034 newDs.setElementAt(ds, i);
2035 ds = new Sequence(ds);
2036 // update with new dataset sequence
2037 sequences[i].setDatasetSequence(ds);
2041 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2046 // copy and derive new dataset sequence
2047 sequences[i] = sequences[i].deriveSequence();
2048 alignment.getDataset().addSequence(
2049 sequences[i].getDatasetSequence());
2050 // TODO: avoid creation of duplicate dataset sequences with a
2051 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2053 alignment.addSequence(sequences[i]); // merges dataset
2057 newDs.clear(); // tidy up
2059 if (alignment.getAlignmentAnnotation() != null)
2061 for (AlignmentAnnotation alan : alignment
2062 .getAlignmentAnnotation())
2064 if (alan.graphGroup > fgroup)
2066 fgroup = alan.graphGroup;
2070 if (pastedal.getAlignmentAnnotation() != null)
2072 // Add any annotation attached to alignment.
2073 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2074 for (int i = 0; i < alann.length; i++)
2076 annotationAdded = true;
2077 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2079 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2080 if (newann.graphGroup > -1)
2082 if (newGraphGroups.size() <= newann.graphGroup
2083 || newGraphGroups.get(newann.graphGroup) == null)
2085 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2087 newGraphGroups.add(q, null);
2089 newGraphGroups.set(newann.graphGroup, new Integer(
2092 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2096 newann.padAnnotation(alwidth);
2097 alignment.addAnnotation(newann);
2107 addHistoryItem(new EditCommand(
2108 MessageManager.getString("label.add_sequences"),
2110 sequences, 0, alignment.getWidth(), alignment));
2112 // Add any annotations attached to sequences
2113 for (int i = 0; i < sequences.length; i++)
2115 if (sequences[i].getAnnotation() != null)
2117 AlignmentAnnotation newann;
2118 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2120 annotationAdded = true;
2121 newann = sequences[i].getAnnotation()[a];
2122 newann.adjustForAlignment();
2123 newann.padAnnotation(alwidth);
2124 if (newann.graphGroup > -1)
2126 if (newann.graphGroup > -1)
2128 if (newGraphGroups.size() <= newann.graphGroup
2129 || newGraphGroups.get(newann.graphGroup) == null)
2131 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2133 newGraphGroups.add(q, null);
2135 newGraphGroups.set(newann.graphGroup, new Integer(
2138 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2142 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2147 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2154 // propagate alignment changed.
2155 viewport.setEndSeq(alignment.getHeight());
2156 if (annotationAdded)
2158 // Duplicate sequence annotation in all views.
2159 AlignmentI[] alview = this.getViewAlignments();
2160 for (int i = 0; i < sequences.length; i++)
2162 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2167 for (int avnum = 0; avnum < alview.length; avnum++)
2169 if (alview[avnum] != alignment)
2171 // duplicate in a view other than the one with input focus
2172 int avwidth = alview[avnum].getWidth() + 1;
2173 // this relies on sann being preserved after we
2174 // modify the sequence's annotation array for each duplication
2175 for (int a = 0; a < sann.length; a++)
2177 AlignmentAnnotation newann = new AlignmentAnnotation(
2179 sequences[i].addAlignmentAnnotation(newann);
2180 newann.padAnnotation(avwidth);
2181 alview[avnum].addAnnotation(newann); // annotation was
2182 // duplicated earlier
2183 // TODO JAL-1145 graphGroups are not updated for sequence
2184 // annotation added to several views. This may cause
2186 alview[avnum].setAnnotationIndex(newann, a);
2191 buildSortByAnnotationScoresMenu();
2193 viewport.firePropertyChange("alignment", null,
2194 alignment.getSequences());
2195 if (alignPanels != null)
2197 for (AlignmentPanel ap : alignPanels)
2199 ap.validateAnnotationDimensions(false);
2204 alignPanel.validateAnnotationDimensions(false);
2210 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2212 String newtitle = new String("Copied sequences");
2214 if (Desktop.jalviewClipboard != null
2215 && Desktop.jalviewClipboard[2] != null)
2217 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2218 for (int[] region : hc)
2220 af.viewport.hideColumns(region[0], region[1]);
2224 // >>>This is a fix for the moment, until a better solution is
2226 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2228 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2230 // TODO: maintain provenance of an alignment, rather than just make the
2231 // title a concatenation of operations.
2234 if (title.startsWith("Copied sequences"))
2240 newtitle = newtitle.concat("- from " + title);
2245 newtitle = new String("Pasted sequences");
2248 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2253 } catch (Exception ex)
2255 ex.printStackTrace();
2256 System.out.println("Exception whilst pasting: " + ex);
2257 // could be anything being pasted in here
2263 protected void expand_newalign(ActionEvent e)
2267 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2268 .getAlignment(), -1);
2269 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2271 String newtitle = new String("Flanking alignment");
2273 if (Desktop.jalviewClipboard != null
2274 && Desktop.jalviewClipboard[2] != null)
2276 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2277 for (int region[] : hc)
2279 af.viewport.hideColumns(region[0], region[1]);
2283 // >>>This is a fix for the moment, until a better solution is
2285 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2287 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2289 // TODO: maintain provenance of an alignment, rather than just make the
2290 // title a concatenation of operations.
2292 if (title.startsWith("Copied sequences"))
2298 newtitle = newtitle.concat("- from " + title);
2302 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2304 } catch (Exception ex)
2306 ex.printStackTrace();
2307 System.out.println("Exception whilst pasting: " + ex);
2308 // could be anything being pasted in here
2309 } catch (OutOfMemoryError oom)
2311 new OOMWarning("Viewing flanking region of alignment", oom);
2322 protected void cut_actionPerformed(ActionEvent e)
2324 copy_actionPerformed(null);
2325 delete_actionPerformed(null);
2335 protected void delete_actionPerformed(ActionEvent evt)
2338 SequenceGroup sg = viewport.getSelectionGroup();
2345 * If the cut affects all sequences, warn, remove highlighted columns
2347 if (sg.getSize() == viewport.getAlignment().getHeight())
2349 int confirm = JOptionPane.showConfirmDialog(this,
2350 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2351 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2352 JOptionPane.OK_CANCEL_OPTION);
2354 if (confirm == JOptionPane.CANCEL_OPTION
2355 || confirm == JOptionPane.CLOSED_OPTION)
2359 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2360 sg.getEndRes() + 1);
2363 SequenceI[] cut = sg.getSequences()
2364 .toArray(new SequenceI[sg.getSize()]);
2366 addHistoryItem(new EditCommand(
2367 MessageManager.getString("label.cut_sequences"), Action.CUT,
2368 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2369 viewport.getAlignment()));
2371 viewport.setSelectionGroup(null);
2372 viewport.sendSelection();
2373 viewport.getAlignment().deleteGroup(sg);
2375 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2377 if (viewport.getAlignment().getHeight() < 1)
2381 this.setClosed(true);
2382 } catch (Exception ex)
2395 protected void deleteGroups_actionPerformed(ActionEvent e)
2397 if (avc.deleteGroups())
2399 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2400 alignPanel.updateAnnotation();
2401 alignPanel.paintAlignment(true);
2412 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2414 SequenceGroup sg = new SequenceGroup();
2416 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2418 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2421 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2422 viewport.setSelectionGroup(sg);
2423 viewport.sendSelection();
2424 alignPanel.paintAlignment(true);
2425 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2435 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2437 if (viewport.cursorMode)
2439 alignPanel.getSeqPanel().keyboardNo1 = null;
2440 alignPanel.getSeqPanel().keyboardNo2 = null;
2442 viewport.setSelectionGroup(null);
2443 viewport.getColumnSelection().clear();
2444 viewport.setSelectionGroup(null);
2445 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2446 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2447 alignPanel.paintAlignment(true);
2448 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2449 viewport.sendSelection();
2459 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2461 SequenceGroup sg = viewport.getSelectionGroup();
2465 selectAllSequenceMenuItem_actionPerformed(null);
2470 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2472 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2475 alignPanel.paintAlignment(true);
2476 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2477 viewport.sendSelection();
2481 public void invertColSel_actionPerformed(ActionEvent e)
2483 viewport.invertColumnSelection();
2484 alignPanel.paintAlignment(true);
2485 viewport.sendSelection();
2495 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2497 trimAlignment(true);
2507 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2509 trimAlignment(false);
2512 void trimAlignment(boolean trimLeft)
2514 ColumnSelection colSel = viewport.getColumnSelection();
2517 if (colSel.size() > 0)
2521 column = colSel.getMin();
2525 column = colSel.getMax();
2529 if (viewport.getSelectionGroup() != null)
2531 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2532 viewport.getHiddenRepSequences());
2536 seqs = viewport.getAlignment().getSequencesArray();
2539 TrimRegionCommand trimRegion;
2542 trimRegion = new TrimRegionCommand("Remove Left",
2543 TrimRegionCommand.TRIM_LEFT, seqs, column,
2544 viewport.getAlignment(), viewport.getColumnSelection(),
2545 viewport.getSelectionGroup());
2546 viewport.setStartRes(0);
2550 trimRegion = new TrimRegionCommand("Remove Right",
2551 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2552 viewport.getAlignment(), viewport.getColumnSelection(),
2553 viewport.getSelectionGroup());
2556 statusBar.setText(MessageManager.formatMessage(
2557 "label.removed_columns", new String[]
2558 { Integer.valueOf(trimRegion.getSize()).toString() }));
2560 addHistoryItem(trimRegion);
2562 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2564 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2565 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2567 viewport.getAlignment().deleteGroup(sg);
2571 viewport.firePropertyChange("alignment", null, viewport
2572 .getAlignment().getSequences());
2583 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2585 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2588 if (viewport.getSelectionGroup() != null)
2590 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2591 viewport.getHiddenRepSequences());
2592 start = viewport.getSelectionGroup().getStartRes();
2593 end = viewport.getSelectionGroup().getEndRes();
2597 seqs = viewport.getAlignment().getSequencesArray();
2600 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2601 "Remove Gapped Columns", seqs, start, end,
2602 viewport.getAlignment());
2604 addHistoryItem(removeGapCols);
2606 statusBar.setText(MessageManager.formatMessage(
2607 "label.removed_empty_columns", new Object[]
2608 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2610 // This is to maintain viewport position on first residue
2611 // of first sequence
2612 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2613 int startRes = seq.findPosition(viewport.startRes);
2614 // ShiftList shifts;
2615 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2616 // edit.alColumnChanges=shifts.getInverse();
2617 // if (viewport.hasHiddenColumns)
2618 // viewport.getColumnSelection().compensateForEdits(shifts);
2619 viewport.setStartRes(seq.findIndex(startRes) - 1);
2620 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2632 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2634 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2637 if (viewport.getSelectionGroup() != null)
2639 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2640 viewport.getHiddenRepSequences());
2641 start = viewport.getSelectionGroup().getStartRes();
2642 end = viewport.getSelectionGroup().getEndRes();
2646 seqs = viewport.getAlignment().getSequencesArray();
2649 // This is to maintain viewport position on first residue
2650 // of first sequence
2651 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2652 int startRes = seq.findPosition(viewport.startRes);
2654 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2655 viewport.getAlignment()));
2657 viewport.setStartRes(seq.findIndex(startRes) - 1);
2659 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2671 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2673 viewport.setPadGaps(padGapsMenuitem.isSelected());
2674 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2685 public void findMenuItem_actionPerformed(ActionEvent e)
2691 * Create a new view of the current alignment.
2694 public void newView_actionPerformed(ActionEvent e)
2696 newView(null, true);
2700 * Creates and shows a new view of the current alignment.
2703 * title of newly created view; if null, one will be generated
2704 * @param copyAnnotation
2705 * if true then duplicate all annnotation, groups and settings
2706 * @return new alignment panel, already displayed.
2708 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2711 * Create a new AlignmentPanel (with its own, new Viewport)
2713 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2715 if (!copyAnnotation)
2718 * remove all groups and annotation except for the automatic stuff
2720 newap.av.getAlignment().deleteAllGroups();
2721 newap.av.getAlignment().deleteAllAnnotations(false);
2724 newap.av.setGatherViewsHere(false);
2726 if (viewport.viewName == null)
2728 viewport.viewName = MessageManager
2729 .getString("label.view_name_original");
2733 * Views share the same edits, undo and redo stacks, mappings.
2735 newap.av.setHistoryList(viewport.getHistoryList());
2736 newap.av.setRedoList(viewport.getRedoList());
2737 newap.av.getAlignment().setCodonFrames(
2738 viewport.getAlignment().getCodonFrames());
2740 newap.av.viewName = getNewViewName(viewTitle);
2742 addAlignmentPanel(newap, true);
2743 newap.alignmentChanged();
2745 if (alignPanels.size() == 2)
2747 viewport.setGatherViewsHere(true);
2749 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2754 * Make a new name for the view, ensuring it is unique within the current
2755 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2756 * these now use viewId. Unique view names are still desirable for usability.)
2761 protected String getNewViewName(String viewTitle)
2763 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2764 boolean addFirstIndex = false;
2765 if (viewTitle == null || viewTitle.trim().length() == 0)
2767 viewTitle = MessageManager.getString("action.view");
2768 addFirstIndex = true;
2772 index = 1;// we count from 1 if given a specific name
2774 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2776 List<Component> comps = PaintRefresher.components.get(viewport
2777 .getSequenceSetId());
2779 List<String> existingNames = getExistingViewNames(comps);
2781 while (existingNames.contains(newViewName))
2783 newViewName = viewTitle + " " + (++index);
2789 * Returns a list of distinct view names found in the given list of
2790 * components. View names are held on the viewport of an AlignmentPanel.
2795 protected List<String> getExistingViewNames(List<Component> comps)
2797 List<String> existingNames = new ArrayList<String>();
2798 for (Component comp : comps)
2800 if (comp instanceof AlignmentPanel)
2802 AlignmentPanel ap = (AlignmentPanel) comp;
2803 if (!existingNames.contains(ap.av.viewName))
2805 existingNames.add(ap.av.viewName);
2809 return existingNames;
2813 * Explode tabbed views into separate windows.
2816 public void expandViews_actionPerformed(ActionEvent e)
2818 Desktop.instance.explodeViews(this);
2822 * Gather views in separate windows back into a tabbed presentation.
2825 public void gatherViews_actionPerformed(ActionEvent e)
2827 Desktop.instance.gatherViews(this);
2837 public void font_actionPerformed(ActionEvent e)
2839 new FontChooser(alignPanel);
2849 protected void seqLimit_actionPerformed(ActionEvent e)
2851 viewport.setShowJVSuffix(seqLimits.isSelected());
2853 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2854 .calculateIdWidth());
2855 alignPanel.paintAlignment(true);
2859 public void idRightAlign_actionPerformed(ActionEvent e)
2861 viewport.setRightAlignIds(idRightAlign.isSelected());
2862 alignPanel.paintAlignment(true);
2866 public void centreColumnLabels_actionPerformed(ActionEvent e)
2868 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2869 alignPanel.paintAlignment(true);
2875 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2878 protected void followHighlight_actionPerformed()
2881 * Set the 'follow' flag on the Viewport (and scroll to position if now
2884 final boolean state = this.followHighlightMenuItem.getState();
2885 viewport.setFollowHighlight(state);
2888 alignPanel.scrollToPosition(
2889 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2900 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2902 viewport.setColourText(colourTextMenuItem.isSelected());
2903 alignPanel.paintAlignment(true);
2913 public void wrapMenuItem_actionPerformed(ActionEvent e)
2915 scaleAbove.setVisible(wrapMenuItem.isSelected());
2916 scaleLeft.setVisible(wrapMenuItem.isSelected());
2917 scaleRight.setVisible(wrapMenuItem.isSelected());
2918 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2919 alignPanel.updateLayout();
2923 public void showAllSeqs_actionPerformed(ActionEvent e)
2925 viewport.showAllHiddenSeqs();
2929 public void showAllColumns_actionPerformed(ActionEvent e)
2931 viewport.showAllHiddenColumns();
2936 public void hideSelSequences_actionPerformed(ActionEvent e)
2938 viewport.hideAllSelectedSeqs();
2939 // alignPanel.paintAlignment(true);
2943 * called by key handler and the hide all/show all menu items
2948 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2951 boolean hide = false;
2952 SequenceGroup sg = viewport.getSelectionGroup();
2953 if (!toggleSeqs && !toggleCols)
2955 // Hide everything by the current selection - this is a hack - we do the
2956 // invert and then hide
2957 // first check that there will be visible columns after the invert.
2958 if ((viewport.getColumnSelection() != null
2959 && viewport.getColumnSelection().getSelected() != null && viewport
2960 .getColumnSelection().getSelected().size() > 0)
2961 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2964 // now invert the sequence set, if required - empty selection implies
2965 // that no hiding is required.
2968 invertSequenceMenuItem_actionPerformed(null);
2969 sg = viewport.getSelectionGroup();
2973 viewport.expandColSelection(sg, true);
2974 // finally invert the column selection and get the new sequence
2976 invertColSel_actionPerformed(null);
2983 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2985 hideSelSequences_actionPerformed(null);
2988 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2991 showAllSeqs_actionPerformed(null);
2997 if (viewport.getColumnSelection().getSelected().size() > 0)
2999 hideSelColumns_actionPerformed(null);
3002 viewport.setSelectionGroup(sg);
3007 showAllColumns_actionPerformed(null);
3016 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3017 * event.ActionEvent)
3020 public void hideAllButSelection_actionPerformed(ActionEvent e)
3022 toggleHiddenRegions(false, false);
3029 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3033 public void hideAllSelection_actionPerformed(ActionEvent e)
3035 SequenceGroup sg = viewport.getSelectionGroup();
3036 viewport.expandColSelection(sg, false);
3037 viewport.hideAllSelectedSeqs();
3038 viewport.hideSelectedColumns();
3039 alignPanel.paintAlignment(true);
3046 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3050 public void showAllhidden_actionPerformed(ActionEvent e)
3052 viewport.showAllHiddenColumns();
3053 viewport.showAllHiddenSeqs();
3054 alignPanel.paintAlignment(true);
3058 public void hideSelColumns_actionPerformed(ActionEvent e)
3060 viewport.hideSelectedColumns();
3061 alignPanel.paintAlignment(true);
3065 public void hiddenMarkers_actionPerformed(ActionEvent e)
3067 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3078 protected void scaleAbove_actionPerformed(ActionEvent e)
3080 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3081 alignPanel.paintAlignment(true);
3091 protected void scaleLeft_actionPerformed(ActionEvent e)
3093 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3094 alignPanel.paintAlignment(true);
3104 protected void scaleRight_actionPerformed(ActionEvent e)
3106 viewport.setScaleRightWrapped(scaleRight.isSelected());
3107 alignPanel.paintAlignment(true);
3117 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3119 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3120 alignPanel.paintAlignment(true);
3130 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3132 viewport.setShowText(viewTextMenuItem.isSelected());
3133 alignPanel.paintAlignment(true);
3143 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3145 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3146 alignPanel.paintAlignment(true);
3149 public FeatureSettings featureSettings;
3152 public FeatureSettingsControllerI getFeatureSettingsUI()
3154 return featureSettings;
3158 public void featureSettings_actionPerformed(ActionEvent e)
3160 if (featureSettings != null)
3162 featureSettings.close();
3163 featureSettings = null;
3165 if (!showSeqFeatures.isSelected())
3167 // make sure features are actually displayed
3168 showSeqFeatures.setSelected(true);
3169 showSeqFeatures_actionPerformed(null);
3171 featureSettings = new FeatureSettings(this);
3175 * Set or clear 'Show Sequence Features'
3181 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3183 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3184 alignPanel.paintAlignment(true);
3185 if (alignPanel.getOverviewPanel() != null)
3187 alignPanel.getOverviewPanel().updateOverviewImage();
3192 * Set or clear 'Show Sequence Features'
3198 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3200 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3202 if (viewport.isShowSequenceFeaturesHeight())
3204 // ensure we're actually displaying features
3205 viewport.setShowSequenceFeatures(true);
3206 showSeqFeatures.setSelected(true);
3208 alignPanel.paintAlignment(true);
3209 if (alignPanel.getOverviewPanel() != null)
3211 alignPanel.getOverviewPanel().updateOverviewImage();
3216 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3217 * the annotations panel as a whole.
3219 * The options to show/hide all annotations should be enabled when the panel
3220 * is shown, and disabled when the panel is hidden.
3225 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3227 final boolean setVisible = annotationPanelMenuItem.isSelected();
3228 viewport.setShowAnnotation(setVisible);
3229 this.showAllSeqAnnotations.setEnabled(setVisible);
3230 this.hideAllSeqAnnotations.setEnabled(setVisible);
3231 this.showAllAlAnnotations.setEnabled(setVisible);
3232 this.hideAllAlAnnotations.setEnabled(setVisible);
3233 alignPanel.updateLayout();
3237 public void alignmentProperties()
3239 JEditorPane editPane = new JEditorPane("text/html", "");
3240 editPane.setEditable(false);
3241 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3243 editPane.setText(MessageManager.formatMessage("label.html_content",
3245 { contents.toString() }));
3246 JInternalFrame frame = new JInternalFrame();
3247 frame.getContentPane().add(new JScrollPane(editPane));
3249 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3250 "label.alignment_properties", new Object[]
3251 { getTitle() }), 500, 400);
3261 public void overviewMenuItem_actionPerformed(ActionEvent e)
3263 if (alignPanel.overviewPanel != null)
3268 JInternalFrame frame = new JInternalFrame();
3269 OverviewPanel overview = new OverviewPanel(alignPanel);
3270 frame.setContentPane(overview);
3271 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3272 "label.overview_params", new Object[]
3273 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3275 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3276 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3279 public void internalFrameClosed(
3280 javax.swing.event.InternalFrameEvent evt)
3282 alignPanel.setOverviewPanel(null);
3286 alignPanel.setOverviewPanel(overview);
3290 public void textColour_actionPerformed(ActionEvent e)
3292 new TextColourChooser().chooseColour(alignPanel, null);
3302 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3314 public void clustalColour_actionPerformed(ActionEvent e)
3316 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3317 viewport.getHiddenRepSequences()));
3327 public void zappoColour_actionPerformed(ActionEvent e)
3329 changeColour(new ZappoColourScheme());
3339 public void taylorColour_actionPerformed(ActionEvent e)
3341 changeColour(new TaylorColourScheme());
3351 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3353 changeColour(new HydrophobicColourScheme());
3363 public void helixColour_actionPerformed(ActionEvent e)
3365 changeColour(new HelixColourScheme());
3375 public void strandColour_actionPerformed(ActionEvent e)
3377 changeColour(new StrandColourScheme());
3387 public void turnColour_actionPerformed(ActionEvent e)
3389 changeColour(new TurnColourScheme());
3399 public void buriedColour_actionPerformed(ActionEvent e)
3401 changeColour(new BuriedColourScheme());
3411 public void nucleotideColour_actionPerformed(ActionEvent e)
3413 changeColour(new NucleotideColourScheme());
3417 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3419 changeColour(new PurinePyrimidineColourScheme());
3423 * public void covariationColour_actionPerformed(ActionEvent e) {
3425 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3429 public void annotationColour_actionPerformed(ActionEvent e)
3431 new AnnotationColourChooser(viewport, alignPanel);
3435 public void annotationColumn_actionPerformed(ActionEvent e)
3437 new AnnotationColumnChooser(viewport, alignPanel);
3441 public void rnahelicesColour_actionPerformed(ActionEvent e)
3443 new RNAHelicesColourChooser(viewport, alignPanel);
3453 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3455 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3464 public void changeColour(ColourSchemeI cs)
3466 // TODO: compare with applet and pull up to model method
3471 if (viewport.getAbovePIDThreshold())
3473 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3475 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3479 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3482 if (viewport.getConservationSelected())
3485 Alignment al = (Alignment) viewport.getAlignment();
3486 Conservation c = new Conservation("All",
3487 ResidueProperties.propHash, 3, al.getSequences(), 0,
3491 c.verdict(false, viewport.getConsPercGaps());
3493 cs.setConservation(c);
3495 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3500 cs.setConservation(null);
3503 cs.setConsensus(viewport.getSequenceConsensusHash());
3506 viewport.setGlobalColourScheme(cs);
3508 if (viewport.getColourAppliesToAllGroups())
3511 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3519 if (cs instanceof ClustalxColourScheme)
3521 sg.cs = new ClustalxColourScheme(sg,
3522 viewport.getHiddenRepSequences());
3524 else if (cs instanceof UserColourScheme)
3526 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3532 sg.cs = cs.getClass().newInstance();
3533 } catch (Exception ex)
3538 if (viewport.getAbovePIDThreshold()
3539 || cs instanceof PIDColourScheme
3540 || cs instanceof Blosum62ColourScheme)
3542 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3544 sg.cs.setConsensus(AAFrequency.calculate(
3545 sg.getSequences(viewport.getHiddenRepSequences()),
3546 sg.getStartRes(), sg.getEndRes() + 1));
3550 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3553 if (viewport.getConservationSelected())
3555 Conservation c = new Conservation("Group",
3556 ResidueProperties.propHash, 3, sg.getSequences(viewport
3557 .getHiddenRepSequences()), sg.getStartRes(),
3558 sg.getEndRes() + 1);
3560 c.verdict(false, viewport.getConsPercGaps());
3561 sg.cs.setConservation(c);
3565 sg.cs.setConservation(null);
3570 if (alignPanel.getOverviewPanel() != null)
3572 alignPanel.getOverviewPanel().updateOverviewImage();
3575 alignPanel.paintAlignment(true);
3585 protected void modifyPID_actionPerformed(ActionEvent e)
3587 if (viewport.getAbovePIDThreshold()
3588 && viewport.getGlobalColourScheme() != null)
3590 SliderPanel.setPIDSliderSource(alignPanel,
3591 viewport.getGlobalColourScheme(), "Background");
3592 SliderPanel.showPIDSlider();
3603 protected void modifyConservation_actionPerformed(ActionEvent e)
3605 if (viewport.getConservationSelected()
3606 && viewport.getGlobalColourScheme() != null)
3608 SliderPanel.setConservationSlider(alignPanel,
3609 viewport.getGlobalColourScheme(), "Background");
3610 SliderPanel.showConservationSlider();
3621 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3623 viewport.setConservationSelected(conservationMenuItem.isSelected());
3625 viewport.setAbovePIDThreshold(false);
3626 abovePIDThreshold.setSelected(false);
3628 changeColour(viewport.getGlobalColourScheme());
3630 modifyConservation_actionPerformed(null);
3640 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3642 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3644 conservationMenuItem.setSelected(false);
3645 viewport.setConservationSelected(false);
3647 changeColour(viewport.getGlobalColourScheme());
3649 modifyPID_actionPerformed(null);
3659 public void userDefinedColour_actionPerformed(ActionEvent e)
3661 if (e.getActionCommand().equals(
3662 MessageManager.getString("action.user_defined")))
3664 new UserDefinedColours(alignPanel, null);
3668 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3669 .getUserColourSchemes().get(e.getActionCommand());
3675 public void updateUserColourMenu()
3678 Component[] menuItems = colourMenu.getMenuComponents();
3679 int iSize = menuItems.length;
3680 for (int i = 0; i < iSize; i++)
3682 if (menuItems[i].getName() != null
3683 && menuItems[i].getName().equals("USER_DEFINED"))
3685 colourMenu.remove(menuItems[i]);
3689 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3691 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3692 .getUserColourSchemes().keys();
3694 while (userColours.hasMoreElements())
3696 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3697 userColours.nextElement().toString());
3698 radioItem.setName("USER_DEFINED");
3699 radioItem.addMouseListener(new MouseAdapter()
3702 public void mousePressed(MouseEvent evt)
3704 if (evt.isControlDown()
3705 || SwingUtilities.isRightMouseButton(evt))
3707 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3709 int option = JOptionPane.showInternalConfirmDialog(
3710 jalview.gui.Desktop.desktop,
3712 .getString("label.remove_from_default_list"),
3714 .getString("label.remove_user_defined_colour"),
3715 JOptionPane.YES_NO_OPTION);
3716 if (option == JOptionPane.YES_OPTION)
3718 jalview.gui.UserDefinedColours
3719 .removeColourFromDefaults(radioItem.getText());
3720 colourMenu.remove(radioItem);
3724 radioItem.addActionListener(new ActionListener()
3727 public void actionPerformed(ActionEvent evt)
3729 userDefinedColour_actionPerformed(evt);
3736 radioItem.addActionListener(new ActionListener()
3739 public void actionPerformed(ActionEvent evt)
3741 userDefinedColour_actionPerformed(evt);
3745 colourMenu.insert(radioItem, 15);
3746 colours.add(radioItem);
3758 public void PIDColour_actionPerformed(ActionEvent e)
3760 changeColour(new PIDColourScheme());
3770 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3772 changeColour(new Blosum62ColourScheme());
3782 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3784 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3785 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3786 .getAlignment().getSequenceAt(0), null);
3787 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3788 viewport.getAlignment()));
3789 alignPanel.paintAlignment(true);
3799 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3801 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3802 AlignmentSorter.sortByID(viewport.getAlignment());
3803 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3804 viewport.getAlignment()));
3805 alignPanel.paintAlignment(true);
3815 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3817 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3818 AlignmentSorter.sortByLength(viewport.getAlignment());
3819 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3820 viewport.getAlignment()));
3821 alignPanel.paintAlignment(true);
3831 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3833 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3834 AlignmentSorter.sortByGroup(viewport.getAlignment());
3835 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3836 viewport.getAlignment()));
3838 alignPanel.paintAlignment(true);
3848 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3850 new RedundancyPanel(alignPanel, this);
3860 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3862 if ((viewport.getSelectionGroup() == null)
3863 || (viewport.getSelectionGroup().getSize() < 2))
3865 JOptionPane.showInternalMessageDialog(this, MessageManager
3866 .getString("label.you_must_select_least_two_sequences"),
3867 MessageManager.getString("label.invalid_selection"),
3868 JOptionPane.WARNING_MESSAGE);
3872 JInternalFrame frame = new JInternalFrame();
3873 frame.setContentPane(new PairwiseAlignPanel(viewport));
3874 Desktop.addInternalFrame(frame,
3875 MessageManager.getString("action.pairwise_alignment"), 600,
3887 public void PCAMenuItem_actionPerformed(ActionEvent e)
3889 if (((viewport.getSelectionGroup() != null)
3890 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3891 .getSelectionGroup().getSize() > 0))
3892 || (viewport.getAlignment().getHeight() < 4))
3895 .showInternalMessageDialog(
3898 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3900 .getString("label.sequence_selection_insufficient"),
3901 JOptionPane.WARNING_MESSAGE);
3906 new PCAPanel(alignPanel);
3910 public void autoCalculate_actionPerformed(ActionEvent e)
3912 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3913 if (viewport.autoCalculateConsensus)
3915 viewport.firePropertyChange("alignment", null, viewport
3916 .getAlignment().getSequences());
3921 public void sortByTreeOption_actionPerformed(ActionEvent e)
3923 viewport.sortByTree = sortByTree.isSelected();
3927 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3929 viewport.followSelection = listenToViewSelections.isSelected();
3939 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3941 newTreePanel("AV", "PID", "Average distance tree using PID");
3951 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3953 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3963 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3965 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3975 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3977 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3990 void newTreePanel(String type, String pwType, String title)
3994 if (viewport.getSelectionGroup() != null
3995 && viewport.getSelectionGroup().getSize() > 0)
3997 if (viewport.getSelectionGroup().getSize() < 3)
4003 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4005 .getString("label.not_enough_sequences"),
4006 JOptionPane.WARNING_MESSAGE);
4010 SequenceGroup sg = viewport.getSelectionGroup();
4012 /* Decide if the selection is a column region */
4013 for (SequenceI _s : sg.getSequences())
4015 if (_s.getLength() < sg.getEndRes())
4021 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4023 .getString("label.sequences_selection_not_aligned"),
4024 JOptionPane.WARNING_MESSAGE);
4030 title = title + " on region";
4031 tp = new TreePanel(alignPanel, type, pwType);
4035 // are the visible sequences aligned?
4036 if (!viewport.getAlignment().isAligned(false))
4042 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4044 .getString("label.sequences_not_aligned"),
4045 JOptionPane.WARNING_MESSAGE);
4050 if (viewport.getAlignment().getHeight() < 2)
4055 tp = new TreePanel(alignPanel, type, pwType);
4060 if (viewport.viewName != null)
4062 title += viewport.viewName + " of ";
4065 title += this.title;
4067 Desktop.addInternalFrame(tp, title, 600, 500);
4078 public void addSortByOrderMenuItem(String title,
4079 final AlignmentOrder order)
4081 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4083 item.addActionListener(new java.awt.event.ActionListener()
4086 public void actionPerformed(ActionEvent e)
4088 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4090 // TODO: JBPNote - have to map order entries to curent SequenceI
4092 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4094 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4097 alignPanel.paintAlignment(true);
4103 * Add a new sort by annotation score menu item
4106 * the menu to add the option to
4108 * the label used to retrieve scores for each sequence on the
4111 public void addSortByAnnotScoreMenuItem(JMenu sort,
4112 final String scoreLabel)
4114 final JMenuItem item = new JMenuItem(scoreLabel);
4116 item.addActionListener(new java.awt.event.ActionListener()
4119 public void actionPerformed(ActionEvent e)
4121 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4122 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4123 viewport.getAlignment());// ,viewport.getSelectionGroup());
4124 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4125 viewport.getAlignment()));
4126 alignPanel.paintAlignment(true);
4132 * last hash for alignment's annotation array - used to minimise cost of
4135 protected int _annotationScoreVectorHash;
4138 * search the alignment and rebuild the sort by annotation score submenu the
4139 * last alignment annotation vector hash is stored to minimize cost of
4140 * rebuilding in subsequence calls.
4144 public void buildSortByAnnotationScoresMenu()
4146 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4151 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4153 sortByAnnotScore.removeAll();
4154 // almost certainly a quicker way to do this - but we keep it simple
4155 Hashtable scoreSorts = new Hashtable();
4156 AlignmentAnnotation aann[];
4157 for (SequenceI sqa : viewport.getAlignment().getSequences())
4159 aann = sqa.getAnnotation();
4160 for (int i = 0; aann != null && i < aann.length; i++)
4162 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4164 scoreSorts.put(aann[i].label, aann[i].label);
4168 Enumeration labels = scoreSorts.keys();
4169 while (labels.hasMoreElements())
4171 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4172 (String) labels.nextElement());
4174 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4177 _annotationScoreVectorHash = viewport.getAlignment()
4178 .getAlignmentAnnotation().hashCode();
4183 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4184 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4185 * call. Listeners are added to remove the menu item when the treePanel is
4186 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4190 * Displayed tree window.
4192 * SortBy menu item title.
4195 public void buildTreeMenu()
4197 calculateTree.removeAll();
4198 // build the calculate menu
4200 for (final String type : new String[]
4203 String treecalcnm = MessageManager.getString("label.tree_calc_"
4204 + type.toLowerCase());
4205 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4207 JMenuItem tm = new JMenuItem();
4208 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4209 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4211 String smn = MessageManager.getStringOrReturn(
4212 "label.score_model_", sm.getName());
4213 final String title = MessageManager.formatMessage(
4214 "label.treecalc_title", treecalcnm, smn);
4215 tm.setText(title);//
4216 tm.addActionListener(new java.awt.event.ActionListener()
4219 public void actionPerformed(ActionEvent e)
4221 newTreePanel(type, pwtype, title);
4224 calculateTree.add(tm);
4229 sortByTreeMenu.removeAll();
4231 List<Component> comps = PaintRefresher.components.get(viewport
4232 .getSequenceSetId());
4233 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4234 for (Component comp : comps)
4236 if (comp instanceof TreePanel)
4238 treePanels.add((TreePanel) comp);
4242 if (treePanels.size() < 1)
4244 sortByTreeMenu.setVisible(false);
4248 sortByTreeMenu.setVisible(true);
4250 for (final TreePanel tp : treePanels)
4252 final JMenuItem item = new JMenuItem(tp.getTitle());
4253 item.addActionListener(new java.awt.event.ActionListener()
4256 public void actionPerformed(ActionEvent e)
4258 tp.sortByTree_actionPerformed();
4259 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4264 sortByTreeMenu.add(item);
4268 public boolean sortBy(AlignmentOrder alorder, String undoname)
4270 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4271 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4272 if (undoname != null)
4274 addHistoryItem(new OrderCommand(undoname, oldOrder,
4275 viewport.getAlignment()));
4277 alignPanel.paintAlignment(true);
4282 * Work out whether the whole set of sequences or just the selected set will
4283 * be submitted for multiple alignment.
4286 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4288 // Now, check we have enough sequences
4289 AlignmentView msa = null;
4291 if ((viewport.getSelectionGroup() != null)
4292 && (viewport.getSelectionGroup().getSize() > 1))
4294 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4295 // some common interface!
4297 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4298 * SequenceI[sz = seqs.getSize(false)];
4300 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4301 * seqs.getSequenceAt(i); }
4303 msa = viewport.getAlignmentView(true);
4305 else if (viewport.getSelectionGroup() != null
4306 && viewport.getSelectionGroup().getSize() == 1)
4308 int option = JOptionPane.showConfirmDialog(this,
4309 MessageManager.getString("warn.oneseq_msainput_selection"),
4310 MessageManager.getString("label.invalid_selection"),
4311 JOptionPane.OK_CANCEL_OPTION);
4312 if (option == JOptionPane.OK_OPTION)
4314 msa = viewport.getAlignmentView(false);
4319 msa = viewport.getAlignmentView(false);
4325 * Decides what is submitted to a secondary structure prediction service: the
4326 * first sequence in the alignment, or in the current selection, or, if the
4327 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4328 * region or the whole alignment. (where the first sequence in the set is the
4329 * one that the prediction will be for).
4331 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4333 AlignmentView seqs = null;
4335 if ((viewport.getSelectionGroup() != null)
4336 && (viewport.getSelectionGroup().getSize() > 0))
4338 seqs = viewport.getAlignmentView(true);
4342 seqs = viewport.getAlignmentView(false);
4344 // limit sequences - JBPNote in future - could spawn multiple prediction
4346 // TODO: viewport.getAlignment().isAligned is a global state - the local
4347 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4348 if (!viewport.getAlignment().isAligned(false))
4350 seqs.setSequences(new SeqCigar[]
4351 { seqs.getSequences()[0] });
4352 // TODO: if seqs.getSequences().length>1 then should really have warned
4366 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4368 // Pick the tree file
4369 JalviewFileChooser chooser = new JalviewFileChooser(
4370 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4371 chooser.setFileView(new JalviewFileView());
4372 chooser.setDialogTitle(MessageManager
4373 .getString("label.select_newick_like_tree_file"));
4374 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4376 int value = chooser.showOpenDialog(null);
4378 if (value == JalviewFileChooser.APPROVE_OPTION)
4380 String choice = chooser.getSelectedFile().getPath();
4381 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4382 jalview.io.NewickFile fin = null;
4385 fin = new jalview.io.NewickFile(choice, "File");
4386 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4387 } catch (Exception ex)
4394 .getString("label.problem_reading_tree_file"),
4395 JOptionPane.WARNING_MESSAGE);
4396 ex.printStackTrace();
4398 if (fin != null && fin.hasWarningMessage())
4400 JOptionPane.showMessageDialog(Desktop.desktop, fin
4401 .getWarningMessage(), MessageManager
4402 .getString("label.possible_problem_with_tree_file"),
4403 JOptionPane.WARNING_MESSAGE);
4409 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4411 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4414 public TreePanel ShowNewickTree(NewickFile nf, String title)
4416 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4419 public TreePanel ShowNewickTree(NewickFile nf, String title,
4420 AlignmentView input)
4422 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4425 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4426 int h, int x, int y)
4428 return ShowNewickTree(nf, title, null, w, h, x, y);
4432 * Add a treeviewer for the tree extracted from a newick file object to the
4433 * current alignment view
4440 * Associated alignment input data (or null)
4449 * @return TreePanel handle
4451 public TreePanel ShowNewickTree(NewickFile nf, String title,
4452 AlignmentView input, int w, int h, int x, int y)
4454 TreePanel tp = null;
4460 if (nf.getTree() != null)
4462 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4468 tp.setLocation(x, y);
4471 Desktop.addInternalFrame(tp, title, w, h);
4473 } catch (Exception ex)
4475 ex.printStackTrace();
4481 private boolean buildingMenu = false;
4484 * Generates menu items and listener event actions for web service clients
4487 public void BuildWebServiceMenu()
4489 while (buildingMenu)
4493 System.err.println("Waiting for building menu to finish.");
4495 } catch (Exception e)
4499 final AlignFrame me = this;
4500 buildingMenu = true;
4501 new Thread(new Runnable()
4506 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4509 System.err.println("Building ws menu again "
4510 + Thread.currentThread());
4511 // TODO: add support for context dependent disabling of services based
4513 // alignment and current selection
4514 // TODO: add additional serviceHandle parameter to specify abstract
4516 // class independently of AbstractName
4517 // TODO: add in rediscovery GUI function to restart discoverer
4518 // TODO: group services by location as well as function and/or
4520 // object broker mechanism.
4521 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4522 final IProgressIndicator af = me;
4523 final JMenu msawsmenu = new JMenu("Alignment");
4524 final JMenu secstrmenu = new JMenu(
4525 "Secondary Structure Prediction");
4526 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4527 final JMenu analymenu = new JMenu("Analysis");
4528 final JMenu dismenu = new JMenu("Protein Disorder");
4529 // final JMenu msawsmenu = new
4530 // JMenu(MessageManager.getString("label.alignment"));
4531 // final JMenu secstrmenu = new
4532 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4533 // final JMenu seqsrchmenu = new
4534 // JMenu(MessageManager.getString("label.sequence_database_search"));
4535 // final JMenu analymenu = new
4536 // JMenu(MessageManager.getString("label.analysis"));
4537 // final JMenu dismenu = new
4538 // JMenu(MessageManager.getString("label.protein_disorder"));
4539 // JAL-940 - only show secondary structure prediction services from
4540 // the legacy server
4541 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4543 Discoverer.services != null && (Discoverer.services.size() > 0))
4545 // TODO: refactor to allow list of AbstractName/Handler bindings to
4547 // stored or retrieved from elsewhere
4548 // No MSAWS used any more:
4549 // Vector msaws = null; // (Vector)
4550 // Discoverer.services.get("MsaWS");
4551 Vector secstrpr = (Vector) Discoverer.services
4553 if (secstrpr != null)
4555 // Add any secondary structure prediction services
4556 for (int i = 0, j = secstrpr.size(); i < j; i++)
4558 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4560 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4561 .getServiceClient(sh);
4562 int p = secstrmenu.getItemCount();
4563 impl.attachWSMenuEntry(secstrmenu, me);
4564 int q = secstrmenu.getItemCount();
4565 for (int litm = p; litm < q; litm++)
4567 legacyItems.add(secstrmenu.getItem(litm));
4573 // Add all submenus in the order they should appear on the web
4575 wsmenu.add(msawsmenu);
4576 wsmenu.add(secstrmenu);
4577 wsmenu.add(dismenu);
4578 wsmenu.add(analymenu);
4579 // No search services yet
4580 // wsmenu.add(seqsrchmenu);
4582 javax.swing.SwingUtilities.invokeLater(new Runnable()
4589 webService.removeAll();
4590 // first, add discovered services onto the webservices menu
4591 if (wsmenu.size() > 0)
4593 for (int i = 0, j = wsmenu.size(); i < j; i++)
4595 webService.add(wsmenu.get(i));
4600 webService.add(me.webServiceNoServices);
4602 // TODO: move into separate menu builder class.
4603 boolean new_sspred = false;
4604 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4606 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4607 if (jws2servs != null)
4609 if (jws2servs.hasServices())
4611 jws2servs.attachWSMenuEntry(webService, me);
4612 for (Jws2Instance sv : jws2servs.getServices())
4614 if (sv.description.toLowerCase().contains("jpred"))
4616 for (JMenuItem jmi : legacyItems)
4618 jmi.setVisible(false);
4624 if (jws2servs.isRunning())
4626 JMenuItem tm = new JMenuItem(
4627 "Still discovering JABA Services");
4628 tm.setEnabled(false);
4633 build_urlServiceMenu(me.webService);
4634 build_fetchdbmenu(webService);
4635 for (JMenu item : wsmenu)
4637 if (item.getItemCount() == 0)
4639 item.setEnabled(false);
4643 item.setEnabled(true);
4646 } catch (Exception e)
4649 .debug("Exception during web service menu building process.",
4654 } catch (Exception e)
4657 buildingMenu = false;
4664 * construct any groupURL type service menu entries.
4668 private void build_urlServiceMenu(JMenu webService)
4670 // TODO: remove this code when 2.7 is released
4671 // DEBUG - alignmentView
4673 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4674 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4676 * @Override public void actionPerformed(ActionEvent e) {
4677 * jalview.datamodel.AlignmentView
4678 * .testSelectionViews(af.viewport.getAlignment(),
4679 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4681 * }); webService.add(testAlView);
4683 // TODO: refactor to RestClient discoverer and merge menu entries for
4684 // rest-style services with other types of analysis/calculation service
4685 // SHmmr test client - still being implemented.
4686 // DEBUG - alignmentView
4688 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4691 client.attachWSMenuEntry(
4692 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4698 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4699 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4700 * getProperty("LAST_DIRECTORY"));
4702 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4703 * to Vamsas file"); chooser.setToolTipText("Export");
4705 * int value = chooser.showSaveDialog(this);
4707 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4708 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4709 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4710 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4713 * prototype of an automatically enabled/disabled analysis function
4716 protected void setShowProductsEnabled()
4718 SequenceI[] selection = viewport.getSequenceSelection();
4719 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4720 viewport.getAlignment().getDataset()))
4722 showProducts.setEnabled(true);
4727 showProducts.setEnabled(false);
4732 * search selection for sequence xRef products and build the show products
4737 * @return true if showProducts menu should be enabled.
4739 public boolean canShowProducts(SequenceI[] selection,
4740 boolean isRegionSelection, Alignment dataset)
4742 boolean showp = false;
4745 showProducts.removeAll();
4746 final boolean dna = viewport.getAlignment().isNucleotide();
4747 final Alignment ds = dataset;
4748 String[] ptypes = (selection == null || selection.length == 0) ? null
4749 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4751 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4752 // selection, dataset, true);
4753 final SequenceI[] sel = selection;
4754 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4757 final boolean isRegSel = isRegionSelection;
4758 final AlignFrame af = this;
4759 final String source = ptypes[t];
4760 JMenuItem xtype = new JMenuItem(ptypes[t]);
4761 xtype.addActionListener(new ActionListener()
4765 public void actionPerformed(ActionEvent e)
4767 // TODO: new thread for this call with vis-delay
4768 af.showProductsFor(af.viewport.getSequenceSelection(),
4769 isRegSel, dna, source);
4773 showProducts.add(xtype);
4775 showProducts.setVisible(showp);
4776 showProducts.setEnabled(showp);
4777 } catch (Exception e)
4779 jalview.bin.Cache.log
4780 .warn("canTranslate threw an exception - please report to help@jalview.org",
4787 protected void showProductsFor(final SequenceI[] sel,
4788 final boolean isRegSel, final boolean dna, final String source)
4790 Runnable foo = new Runnable()
4796 final long sttime = System.currentTimeMillis();
4797 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4798 "status.searching_for_sequences_from", new Object[]
4799 { source }), sttime);
4802 // update our local dataset reference
4803 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4805 Alignment prods = CrossRef
4806 .findXrefSequences(sel, dna, source, ds);
4809 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4810 for (int s = 0; s < sprods.length; s++)
4812 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4813 if (ds.getSequences() == null
4814 || !ds.getSequences().contains(
4815 sprods[s].getDatasetSequence()))
4817 ds.addSequence(sprods[s].getDatasetSequence());
4819 sprods[s].updatePDBIds();
4821 Alignment al = new Alignment(sprods);
4825 * Copy dna-to-protein mappings to new alignment
4827 // TODO 1: no mappings are set up for EMBL product
4828 // TODO 2: if they were, should add them to protein alignment, not
4830 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4831 for (AlignedCodonFrame acf : cf)
4833 al.addCodonFrame(acf);
4835 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4837 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4838 + " for " + ((isRegSel) ? "selected region of " : "")
4840 naf.setTitle(newtitle);
4842 // temporary flag until SplitFrame is released
4843 boolean asSplitFrame = Cache.getDefault(
4844 Preferences.ENABLE_SPLIT_FRAME, false);
4848 * Make a copy of this alignment (sharing the same dataset
4849 * sequences). If we are DNA, drop introns and update mappings
4851 AlignmentI copyAlignment = null;
4852 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4853 .getSequenceSelection();
4856 copyAlignment = AlignmentUtils.makeExonAlignment(
4857 sequenceSelection, cf);
4858 al.getCodonFrames().clear();
4859 al.getCodonFrames().addAll(cf);
4860 final StructureSelectionManager ssm = StructureSelectionManager
4861 .getStructureSelectionManager(Desktop.instance);
4862 ssm.addMappings(cf);
4866 copyAlignment = new Alignment(new Alignment(
4867 sequenceSelection));
4869 AlignFrame copyThis = new AlignFrame(copyAlignment,
4870 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4871 copyThis.setTitle(AlignFrame.this.getTitle());
4872 // SplitFrame with dna above, protein below
4873 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4874 dna ? naf : copyThis);
4875 naf.setVisible(true);
4876 copyThis.setVisible(true);
4877 String linkedTitle = MessageManager
4878 .getString("label.linked_view_title");
4879 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4883 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4889 System.err.println("No Sequences generated for xRef type "
4892 } catch (Exception e)
4894 jalview.bin.Cache.log.error(
4895 "Exception when finding crossreferences", e);
4896 } catch (OutOfMemoryError e)
4898 new OOMWarning("whilst fetching crossreferences", e);
4901 jalview.bin.Cache.log.error("Error when finding crossreferences",
4904 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4905 "status.finished_searching_for_sequences_from",
4912 Thread frunner = new Thread(foo);
4916 public boolean canShowTranslationProducts(SequenceI[] selection,
4917 AlignmentI alignment)
4922 return (jalview.analysis.Dna.canTranslate(selection,
4923 viewport.getViewAsVisibleContigs(true)));
4924 } catch (Exception e)
4926 jalview.bin.Cache.log
4927 .warn("canTranslate threw an exception - please report to help@jalview.org",
4934 * Construct and display a new frame containing the translation of this
4935 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4938 public void showTranslation_actionPerformed(ActionEvent e)
4940 AlignmentI al = null;
4943 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4945 al = dna.translateCdna();
4946 } catch (Exception ex)
4948 jalview.bin.Cache.log.error(
4949 "Exception during translation. Please report this !", ex);
4950 final String msg = MessageManager
4951 .getString("label.error_when_translating_sequences_submit_bug_report");
4952 final String title = MessageManager
4953 .getString("label.implementation_error")
4954 + MessageManager.getString("translation_failed");
4955 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4956 JOptionPane.ERROR_MESSAGE);
4959 if (al == null || al.getHeight() == 0)
4961 final String msg = MessageManager
4962 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4963 final String title = MessageManager
4964 .getString("label.translation_failed");
4965 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4966 JOptionPane.WARNING_MESSAGE);
4970 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4971 af.setFileFormat(this.currentFileFormat);
4972 final String newTitle = MessageManager.formatMessage(
4973 "label.translation_of_params", new Object[]
4974 { this.getTitle() });
4975 af.setTitle(newTitle);
4976 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
4978 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4979 viewport.openSplitFrame(af, new Alignment(seqs),
4980 al.getCodonFrames());
4984 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4991 * Set the file format
4995 public void setFileFormat(String fileFormat)
4997 this.currentFileFormat = fileFormat;
5001 * Try to load a features file onto the alignment.
5004 * contents or path to retrieve file
5006 * access mode of file (see jalview.io.AlignFile)
5007 * @return true if features file was parsed correctly.
5009 public boolean parseFeaturesFile(String file, String type)
5011 return avc.parseFeaturesFile(file, type,
5012 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5017 public void refreshFeatureUI(boolean enableIfNecessary)
5019 // note - currently this is only still here rather than in the controller
5020 // because of the featureSettings hard reference that is yet to be
5022 if (enableIfNecessary)
5024 viewport.setShowSequenceFeatures(true);
5025 showSeqFeatures.setSelected(true);
5031 public void dragEnter(DropTargetDragEvent evt)
5036 public void dragExit(DropTargetEvent evt)
5041 public void dragOver(DropTargetDragEvent evt)
5046 public void dropActionChanged(DropTargetDragEvent evt)
5051 public void drop(DropTargetDropEvent evt)
5053 Transferable t = evt.getTransferable();
5054 java.util.List files = null;
5058 DataFlavor uriListFlavor = new DataFlavor(
5059 "text/uri-list;class=java.lang.String");
5060 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5062 // Works on Windows and MacOSX
5063 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5064 files = (java.util.List) t
5065 .getTransferData(DataFlavor.javaFileListFlavor);
5067 else if (t.isDataFlavorSupported(uriListFlavor))
5069 // This is used by Unix drag system
5070 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5071 String data = (String) t.getTransferData(uriListFlavor);
5072 files = new java.util.ArrayList(1);
5073 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5074 data, "\r\n"); st.hasMoreTokens();)
5076 String s = st.nextToken();
5077 if (s.startsWith("#"))
5079 // the line is a comment (as per the RFC 2483)
5083 java.net.URI uri = new java.net.URI(s);
5084 // check to see if we can handle this kind of URI
5085 if (uri.getScheme().toLowerCase().startsWith("http"))
5087 files.add(uri.toString());
5091 // otherwise preserve old behaviour: catch all for file objects
5092 java.io.File file = new java.io.File(uri);
5093 files.add(file.toString());
5097 } catch (Exception e)
5099 e.printStackTrace();
5105 // check to see if any of these files have names matching sequences in
5107 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5108 .getAlignment().getSequencesArray());
5110 * Object[] { String,SequenceI}
5112 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5113 ArrayList<String> filesnotmatched = new ArrayList<String>();
5114 for (int i = 0; i < files.size(); i++)
5116 String file = files.get(i).toString();
5118 String protocol = FormatAdapter.checkProtocol(file);
5119 if (protocol == jalview.io.FormatAdapter.FILE)
5121 File fl = new File(file);
5122 pdbfn = fl.getName();
5124 else if (protocol == jalview.io.FormatAdapter.URL)
5126 URL url = new URL(file);
5127 pdbfn = url.getFile();
5129 if (pdbfn.length() > 0)
5131 // attempt to find a match in the alignment
5132 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5133 int l = 0, c = pdbfn.indexOf(".");
5134 while (mtch == null && c != -1)
5139 } while ((c = pdbfn.indexOf(".", l)) > l);
5142 pdbfn = pdbfn.substring(0, l);
5144 mtch = idm.findAllIdMatches(pdbfn);
5151 type = new IdentifyFile().Identify(file, protocol);
5152 } catch (Exception ex)
5158 if (type.equalsIgnoreCase("PDB"))
5160 filesmatched.add(new Object[]
5161 { file, protocol, mtch });
5166 // File wasn't named like one of the sequences or wasn't a PDB file.
5167 filesnotmatched.add(file);
5171 if (filesmatched.size() > 0)
5173 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5179 "label.automatically_associate_pdb_files_with_sequences_same_name",
5186 .getString("label.automatically_associate_pdb_files_by_name"),
5187 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5190 for (Object[] fm : filesmatched)
5192 // try and associate
5193 // TODO: may want to set a standard ID naming formalism for
5194 // associating PDB files which have no IDs.
5195 for (SequenceI toassoc : (SequenceI[]) fm[2])
5197 PDBEntry pe = new AssociatePdbFileWithSeq()
5198 .associatePdbWithSeq((String) fm[0],
5199 (String) fm[1], toassoc, false,
5203 System.err.println("Associated file : "
5204 + ((String) fm[0]) + " with "
5205 + toassoc.getDisplayId(true));
5209 alignPanel.paintAlignment(true);
5213 if (filesnotmatched.size() > 0)
5216 && (Cache.getDefault(
5217 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5220 "<html>"+MessageManager
5222 "label.ignore_unmatched_dropped_files_info",
5227 .toString() })+"</html>",
5229 .getString("label.ignore_unmatched_dropped_files"),
5230 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5234 for (String fn : filesnotmatched)
5236 loadJalviewDataFile(fn, null, null, null);
5240 } catch (Exception ex)
5242 ex.printStackTrace();
5248 * Attempt to load a "dropped" file or URL string: First by testing whether
5249 * it's and Annotation file, then a JNet file, and finally a features file. If
5250 * all are false then the user may have dropped an alignment file onto this
5254 * either a filename or a URL string.
5256 public void loadJalviewDataFile(String file, String protocol,
5257 String format, SequenceI assocSeq)
5261 if (protocol == null)
5263 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5265 // if the file isn't identified, or not positively identified as some
5266 // other filetype (PFAM is default unidentified alignment file type) then
5267 // try to parse as annotation.
5268 boolean isAnnotation = (format == null || format
5269 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5270 .annotateAlignmentView(viewport, file, protocol)
5275 // first see if its a T-COFFEE score file
5276 TCoffeeScoreFile tcf = null;
5279 tcf = new TCoffeeScoreFile(file, protocol);
5282 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5284 tcoffeeColour.setEnabled(true);
5285 tcoffeeColour.setSelected(true);
5286 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5287 isAnnotation = true;
5289 .setText(MessageManager
5290 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5294 // some problem - if no warning its probable that the ID matching
5295 // process didn't work
5299 tcf.getWarningMessage() == null ? MessageManager
5300 .getString("label.check_file_matches_sequence_ids_alignment")
5301 : tcf.getWarningMessage(),
5303 .getString("label.problem_reading_tcoffee_score_file"),
5304 JOptionPane.WARNING_MESSAGE);
5311 } catch (Exception x)
5314 .debug("Exception when processing data source as T-COFFEE score file",
5320 // try to see if its a JNet 'concise' style annotation file *before*
5322 // try to parse it as a features file
5325 format = new IdentifyFile().Identify(file, protocol);
5327 if (format.equalsIgnoreCase("JnetFile"))
5329 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5331 new JnetAnnotationMaker();
5332 JnetAnnotationMaker.add_annotation(predictions,
5333 viewport.getAlignment(), 0, false);
5334 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5335 viewport.getAlignment().setSeqrep(repseq);
5336 ColumnSelection cs = new ColumnSelection();
5337 cs.hideInsertionsFor(repseq);
5338 viewport.setColumnSelection(cs);
5339 isAnnotation = true;
5344 * if (format.equalsIgnoreCase("PDB")) {
5346 * String pdbfn = ""; // try to match up filename with sequence id
5347 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5348 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5349 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5350 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5351 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5352 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5353 * // attempt to find a match in the alignment SequenceI mtch =
5354 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5355 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5356 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5357 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5358 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5359 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5360 * { System.err.println("Associated file : " + file + " with " +
5361 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5362 * TODO: maybe need to load as normal otherwise return; } }
5364 // try to parse it as a features file
5365 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5366 // if it wasn't a features file then we just treat it as a general
5367 // alignment file to load into the current view.
5370 new FileLoader().LoadFile(viewport, file, protocol, format);
5374 alignPanel.paintAlignment(true);
5382 alignPanel.adjustAnnotationHeight();
5383 viewport.updateSequenceIdColours();
5384 buildSortByAnnotationScoresMenu();
5385 alignPanel.paintAlignment(true);
5387 } catch (Exception ex)
5389 ex.printStackTrace();
5390 } catch (OutOfMemoryError oom)
5395 } catch (Exception x)
5401 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5402 : "using " + protocol + " from " + file)
5404 + (format != null ? "(parsing as '" + format
5405 + "' file)" : ""), oom, Desktop.desktop);
5410 * Method invoked by the ChangeListener on the tabbed pane, in other words
5411 * when a different tabbed pane is selected by the user or programmatically.
5414 public void tabSelectionChanged(int index)
5418 alignPanel = alignPanels.get(index);
5419 viewport = alignPanel.av;
5420 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5421 setMenusFromViewport(viewport);
5425 * If there is a frame linked to this one in a SplitPane, switch it to the
5426 * same view tab index. No infinite recursion of calls should happen, since
5427 * tabSelectionChanged() should not get invoked on setting the selected
5428 * index to an unchanged value. Guard against setting an invalid index
5429 * before the new view peer tab has been created.
5431 final AlignViewportI peer = viewport.getCodingComplement();
5434 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5435 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5437 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5443 * On right mouse click on view tab, prompt for and set new view name.
5446 public void tabbedPane_mousePressed(MouseEvent e)
5448 if (SwingUtilities.isRightMouseButton(e))
5450 String msg = MessageManager.getString("label.enter_view_name");
5451 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5452 JOptionPane.QUESTION_MESSAGE);
5456 viewport.viewName = reply;
5457 // TODO warn if reply is in getExistingViewNames()?
5458 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5463 public AlignViewport getCurrentView()
5469 * Open the dialog for regex description parsing.
5472 protected void extractScores_actionPerformed(ActionEvent e)
5474 ParseProperties pp = new jalview.analysis.ParseProperties(
5475 viewport.getAlignment());
5476 // TODO: verify regex and introduce GUI dialog for version 2.5
5477 // if (pp.getScoresFromDescription("col", "score column ",
5478 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5480 if (pp.getScoresFromDescription("description column",
5481 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5483 buildSortByAnnotationScoresMenu();
5491 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5495 protected void showDbRefs_actionPerformed(ActionEvent e)
5497 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5503 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5507 protected void showNpFeats_actionPerformed(ActionEvent e)
5509 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5513 * find the viewport amongst the tabs in this alignment frame and close that
5518 public boolean closeView(AlignViewportI av)
5522 this.closeMenuItem_actionPerformed(false);
5525 Component[] comp = tabbedPane.getComponents();
5526 for (int i = 0; comp != null && i < comp.length; i++)
5528 if (comp[i] instanceof AlignmentPanel)
5530 if (((AlignmentPanel) comp[i]).av == av)
5533 closeView((AlignmentPanel) comp[i]);
5541 protected void build_fetchdbmenu(JMenu webService)
5543 // Temporary hack - DBRef Fetcher always top level ws entry.
5544 // TODO We probably want to store a sequence database checklist in
5545 // preferences and have checkboxes.. rather than individual sources selected
5547 final JMenu rfetch = new JMenu(
5548 MessageManager.getString("action.fetch_db_references"));
5549 rfetch.setToolTipText(MessageManager
5550 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5551 webService.add(rfetch);
5553 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5554 MessageManager.getString("option.trim_retrieved_seqs"));
5555 trimrs.setToolTipText(MessageManager
5556 .getString("label.trim_retrieved_sequences"));
5557 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5558 trimrs.addActionListener(new ActionListener()
5561 public void actionPerformed(ActionEvent e)
5563 trimrs.setSelected(trimrs.isSelected());
5564 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5565 Boolean.valueOf(trimrs.isSelected()).toString());
5569 JMenuItem fetchr = new JMenuItem(
5570 MessageManager.getString("label.standard_databases"));
5571 fetchr.setToolTipText(MessageManager
5572 .getString("label.fetch_embl_uniprot"));
5573 fetchr.addActionListener(new ActionListener()
5577 public void actionPerformed(ActionEvent e)
5579 new Thread(new Runnable()
5585 new jalview.ws.DBRefFetcher(alignPanel.av
5586 .getSequenceSelection(), alignPanel.alignFrame)
5587 .fetchDBRefs(false);
5595 final AlignFrame me = this;
5596 new Thread(new Runnable()
5601 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5602 .getSequenceFetcherSingleton(me);
5603 javax.swing.SwingUtilities.invokeLater(new Runnable()
5608 String[] dbclasses = sf.getOrderedSupportedSources();
5609 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5610 // jalview.util.QuickSort.sort(otherdb, otherdb);
5611 List<DbSourceProxy> otherdb;
5612 JMenu dfetch = new JMenu();
5613 JMenu ifetch = new JMenu();
5614 JMenuItem fetchr = null;
5615 int comp = 0, icomp = 0, mcomp = 15;
5616 String mname = null;
5618 for (String dbclass : dbclasses)
5620 otherdb = sf.getSourceProxy(dbclass);
5621 // add a single entry for this class, or submenu allowing 'fetch
5623 if (otherdb == null || otherdb.size() < 1)
5627 // List<DbSourceProxy> dbs=otherdb;
5628 // otherdb=new ArrayList<DbSourceProxy>();
5629 // for (DbSourceProxy db:dbs)
5631 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5635 mname = "From " + dbclass;
5637 if (otherdb.size() == 1)
5639 final DbSourceProxy[] dassource = otherdb
5640 .toArray(new DbSourceProxy[0]);
5641 DbSourceProxy src = otherdb.get(0);
5642 fetchr = new JMenuItem(src.getDbSource());
5643 fetchr.addActionListener(new ActionListener()
5647 public void actionPerformed(ActionEvent e)
5649 new Thread(new Runnable()
5655 new jalview.ws.DBRefFetcher(alignPanel.av
5656 .getSequenceSelection(),
5657 alignPanel.alignFrame, dassource)
5658 .fetchDBRefs(false);
5664 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5670 final DbSourceProxy[] dassource = otherdb
5671 .toArray(new DbSourceProxy[0]);
5673 DbSourceProxy src = otherdb.get(0);
5674 fetchr = new JMenuItem(MessageManager.formatMessage(
5675 "label.fetch_all_param", new Object[]
5676 { src.getDbSource() }));
5677 fetchr.addActionListener(new ActionListener()
5680 public void actionPerformed(ActionEvent e)
5682 new Thread(new Runnable()
5688 new jalview.ws.DBRefFetcher(alignPanel.av
5689 .getSequenceSelection(),
5690 alignPanel.alignFrame, dassource)
5691 .fetchDBRefs(false);
5697 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5700 // and then build the rest of the individual menus
5701 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5703 String imname = null;
5705 for (DbSourceProxy sproxy : otherdb)
5707 String dbname = sproxy.getDbName();
5708 String sname = dbname.length() > 5 ? dbname.substring(0,
5709 5) + "..." : dbname;
5710 String msname = dbname.length() > 10 ? dbname.substring(
5711 0, 10) + "..." : dbname;
5714 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5716 fetchr = new JMenuItem(msname);
5717 final DbSourceProxy[] dassrc =
5719 fetchr.addActionListener(new ActionListener()
5723 public void actionPerformed(ActionEvent e)
5725 new Thread(new Runnable()
5731 new jalview.ws.DBRefFetcher(alignPanel.av
5732 .getSequenceSelection(),
5733 alignPanel.alignFrame, dassrc)
5734 .fetchDBRefs(false);
5740 fetchr.setToolTipText("<html>"
5741 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5744 if (++icomp >= mcomp || i == (otherdb.size()))
5746 ifetch.setText(MessageManager.formatMessage(
5747 "label.source_to_target", imname, sname));
5749 ifetch = new JMenu();
5757 if (comp >= mcomp || dbi >= (dbclasses.length))
5759 dfetch.setText(MessageManager.formatMessage(
5760 "label.source_to_target", mname, dbclass));
5762 dfetch = new JMenu();
5775 * Left justify the whole alignment.
5778 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5780 AlignmentI al = viewport.getAlignment();
5782 viewport.firePropertyChange("alignment", null, al);
5786 * Right justify the whole alignment.
5789 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5791 AlignmentI al = viewport.getAlignment();
5793 viewport.firePropertyChange("alignment", null, al);
5796 public void setShowSeqFeatures(boolean b)
5798 showSeqFeatures.setSelected(b);
5799 viewport.setShowSequenceFeatures(b);
5806 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5807 * awt.event.ActionEvent)
5810 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5812 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5813 alignPanel.paintAlignment(true);
5820 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5824 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5826 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5827 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5835 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5836 * .event.ActionEvent)
5839 protected void showGroupConservation_actionPerformed(ActionEvent e)
5841 viewport.setShowGroupConservation(showGroupConservation.getState());
5842 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5849 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5850 * .event.ActionEvent)
5853 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5855 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5856 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5863 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5864 * .event.ActionEvent)
5867 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5869 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5870 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5874 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5876 showSequenceLogo.setState(true);
5877 viewport.setShowSequenceLogo(true);
5878 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5879 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5883 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5885 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5892 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5893 * .event.ActionEvent)
5896 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5898 if (avc.makeGroupsFromSelection())
5900 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5901 alignPanel.updateAnnotation();
5902 alignPanel.paintAlignment(true);
5905 public void clearAlignmentSeqRep()
5907 // TODO refactor alignmentseqrep to controller
5908 if (viewport.getAlignment().hasSeqrep()) {
5909 viewport.getAlignment().setSeqrep(null);
5910 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5911 alignPanel.updateAnnotation();
5912 alignPanel.paintAlignment(true);
5917 protected void createGroup_actionPerformed(ActionEvent e)
5919 if (avc.createGroup())
5921 alignPanel.alignmentChanged();
5926 protected void unGroup_actionPerformed(ActionEvent e)
5930 alignPanel.alignmentChanged();
5935 * make the given alignmentPanel the currently selected tab
5937 * @param alignmentPanel
5939 public void setDisplayedView(AlignmentPanel alignmentPanel)
5941 if (!viewport.getSequenceSetId().equals(
5942 alignmentPanel.av.getSequenceSetId()))
5944 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5946 if (tabbedPane != null
5947 && tabbedPane.getTabCount() > 0
5948 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5949 .getSelectedIndex())
5951 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5956 * Action on selection of menu options to Show or Hide annotations.
5959 * @param forSequences
5960 * update sequence-related annotations
5961 * @param forAlignment
5962 * update non-sequence-related annotations
5965 protected void setAnnotationsVisibility(boolean visible,
5966 boolean forSequences, boolean forAlignment)
5968 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5969 .getAlignmentAnnotation())
5972 * don't display non-positional annotations on an alignment
5974 if (aa.annotations == null)
5978 boolean apply = (aa.sequenceRef == null && forAlignment)
5979 || (aa.sequenceRef != null && forSequences);
5982 aa.visible = visible;
5985 alignPanel.validateAnnotationDimensions(false);
5986 alignPanel.alignmentChanged();
5990 * Store selected annotation sort order for the view and repaint.
5993 protected void sortAnnotations_actionPerformed()
5995 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5997 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5998 alignPanel.paintAlignment(true);
6003 * @return alignment panels in this alignment frame
6005 public List<? extends AlignmentViewPanel> getAlignPanels()
6007 return alignPanels == null ? Arrays.asList(alignPanel)
6012 * Open a new alignment window, with the cDNA associated with this (protein)
6013 * alignment, aligned as is the protein.
6015 protected void viewAsCdna_actionPerformed()
6017 // TODO no longer a menu action - refactor as required
6018 final AlignmentI alignment = getViewport().getAlignment();
6019 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6020 if (mappings == null)
6024 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6025 for (SequenceI aaSeq : alignment.getSequences()) {
6026 for (AlignedCodonFrame acf : mappings) {
6027 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6031 * There is a cDNA mapping for this protein sequence - add to new
6032 * alignment. It will share the same dataset sequence as other mapped
6033 * cDNA (no new mappings need to be created).
6035 final Sequence newSeq = new Sequence(dnaSeq);
6036 newSeq.setDatasetSequence(dnaSeq);
6037 cdnaSeqs.add(newSeq);
6041 if (cdnaSeqs.size() == 0)
6043 // show a warning dialog no mapped cDNA
6046 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6048 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6049 AlignFrame.DEFAULT_HEIGHT);
6050 cdna.alignAs(alignment);
6051 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6053 Desktop.addInternalFrame(alignFrame, newtitle,
6054 AlignFrame.DEFAULT_WIDTH,
6055 AlignFrame.DEFAULT_HEIGHT);
6059 * Set visibility of dna/protein complement view (available when shown in a
6065 protected void showComplement_actionPerformed(boolean show)
6067 SplitContainerI sf = getSplitViewContainer();
6069 sf.setComplementVisible(this, show);
6073 public class ExportData
6075 private AlignmentI alignment;
6077 private String[] omitHidden;
6079 private int[] startEnd;
6081 private AlignExportSettingI settings;
6083 public ExportData(AlignmentI align, String[] ommit, int[] startEnd,
6084 AlignExportSettingI settings)
6086 this.alignment = align;
6087 this.omitHidden = ommit;
6088 this.startEnd = startEnd;
6089 this.settings = settings;
6092 public AlignmentI getAlignment()
6097 public void setAlignment(AlignmentI alignment)
6099 this.alignment = alignment;
6102 public String[] getOmitHidden()
6107 public void setOmitHidden(String[] omitHidden)
6109 this.omitHidden = omitHidden;
6112 public int[] getStartEndPostions()
6117 public void setStartEndPostions(int[] startEnd)
6119 this.startEnd = startEnd;
6122 public AlignExportSettingI getSettings()
6127 public void setSettings(AlignExportSettingI settings)
6129 this.settings = settings;
6135 class PrintThread extends Thread
6139 public PrintThread(AlignmentPanel ap)
6144 static PageFormat pf;
6149 PrinterJob printJob = PrinterJob.getPrinterJob();
6153 printJob.setPrintable(ap, pf);
6157 printJob.setPrintable(ap);
6160 if (printJob.printDialog())
6165 } catch (Exception PrintException)
6167 PrintException.printStackTrace();