2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentSorter;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.analysis.CrossRef;
28 import jalview.analysis.Dna;
29 import jalview.analysis.ParseProperties;
30 import jalview.analysis.SequenceIdMatcher;
31 import jalview.api.AlignViewControllerGuiI;
32 import jalview.api.AlignViewControllerI;
33 import jalview.api.AlignViewportI;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.api.FeatureSettingsControllerI;
36 import jalview.api.SplitContainerI;
37 import jalview.api.ViewStyleI;
38 import jalview.api.analysis.ScoreModelI;
39 import jalview.bin.Cache;
40 import jalview.commands.CommandI;
41 import jalview.commands.EditCommand;
42 import jalview.commands.EditCommand.Action;
43 import jalview.commands.OrderCommand;
44 import jalview.commands.RemoveGapColCommand;
45 import jalview.commands.RemoveGapsCommand;
46 import jalview.commands.SlideSequencesCommand;
47 import jalview.commands.TrimRegionCommand;
48 import jalview.datamodel.AlignedCodonFrame;
49 import jalview.datamodel.Alignment;
50 import jalview.datamodel.AlignmentAnnotation;
51 import jalview.datamodel.AlignmentExportData;
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 AlignmentExportData exportData = getAlignmentForExport(format, viewport);
1144 if (exportData.getSettings().isCancelled())
1148 FormatAdapter f = new FormatAdapter(alignPanel,
1149 exportData.getSettings());
1150 String output = f.formatSequences(format,
1151 exportData.getAlignment(), // class cast exceptions will
1152 // occur in the distant future
1153 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1154 f.getCacheSuffixDefault(format),
1155 viewport.getColumnSelection());
1165 java.io.PrintWriter out = new java.io.PrintWriter(
1166 new java.io.FileWriter(file));
1170 this.setTitle(file);
1171 statusBar.setText(MessageManager.formatMessage(
1172 "label.successfully_saved_to_file_in_format",
1174 { fileName, format }));
1175 } catch (Exception ex)
1178 ex.printStackTrace();
1185 JOptionPane.showInternalMessageDialog(this, MessageManager
1186 .formatMessage("label.couldnt_save_file", new Object[]
1187 { fileName }), MessageManager
1188 .getString("label.error_saving_file"),
1189 JOptionPane.WARNING_MESSAGE);
1196 private void warningMessage(String warning, String title)
1198 if (new jalview.util.Platform().isHeadless())
1200 System.err.println("Warning: " + title + "\nWarning: " + warning);
1205 JOptionPane.showInternalMessageDialog(this, warning, title,
1206 JOptionPane.WARNING_MESSAGE);
1218 protected void outputText_actionPerformed(ActionEvent e)
1221 AlignmentExportData exportData = getAlignmentForExport(
1222 e.getActionCommand(), viewport);
1223 if (exportData.getSettings().isCancelled())
1227 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1228 cap.setForInput(null);
1231 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1233 e.getActionCommand(),
1234 exportData.getAlignment(),
1235 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1236 viewport.getColumnSelection()));
1237 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1238 "label.alignment_output_command", new Object[]
1239 { e.getActionCommand() }), 600, 500);
1240 } catch (OutOfMemoryError oom)
1242 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1248 public static AlignmentExportData getAlignmentForExport(String exportFomat,
1249 AlignViewportI viewport)
1251 AlignmentI alignmentToExport = null;
1252 String[] omitHidden = null;
1253 int[] alignmentStartEnd = new int[2];
1255 HiddenSequences hiddenSeqs = viewport.getAlignment()
1256 .getHiddenSequences();
1259 alignmentToExport = viewport.getAlignment();
1260 alignmentStartEnd = new int[]
1261 { 0, alignmentToExport.getWidth() - 1 };
1263 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1264 AlignExportSettings settings = new AlignExportSettings(hasHiddenSeqs,
1265 viewport.hasHiddenColumns(), exportFomat);
1266 settings.isExportAnnotations();
1268 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1270 omitHidden = viewport.getViewAsString(false);
1273 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1275 alignmentToExport = hiddenSeqs.getFullAlignment();
1279 alignmentToExport = viewport.getAlignment();
1280 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1281 .getColumnSelection().getHiddenColumns());
1283 AlignmentExportData ed = new AlignmentExportData(alignmentToExport, omitHidden, alignmentStartEnd,
1288 private static int[] getStartEnd(int[] aligmentStartEnd,
1289 List<int[]> hiddenCols)
1291 int startPos = aligmentStartEnd[0];
1292 int endPos = aligmentStartEnd[1];
1294 int[] lowestRange = new int[2];
1295 int[] higestRange = new int[2];
1297 for (int[] hiddenCol : hiddenCols)
1299 // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
1301 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1302 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1304 // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
1305 // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
1307 if (lowestRange[0] == 0 && lowestRange[1] == 0)
1309 startPos = aligmentStartEnd[0];
1313 startPos = lowestRange[1] + 1;
1316 if (higestRange[0] == 0 && higestRange[1] == 0)
1318 endPos = aligmentStartEnd[1];
1322 endPos = higestRange[0];
1325 // System.out.println("Export range : " + minPos + " - " + maxPos);
1327 { startPos, endPos };
1330 public static void main(String[] args)
1332 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1333 hiddenCols.add(new int[]
1335 hiddenCols.add(new int[]
1337 hiddenCols.add(new int[]
1339 hiddenCols.add(new int[]
1341 hiddenCols.add(new int[]
1344 int[] x = getStartEnd(new int[]
1345 { 0, 50 }, hiddenCols);
1346 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1356 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1358 new HtmlSvgOutput(null, alignPanel);
1362 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1364 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1365 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1367 public void createImageMap(File file, String image)
1369 alignPanel.makePNGImageMap(file, image);
1379 public void createPNG(File f)
1381 alignPanel.makePNG(f);
1391 public void createEPS(File f)
1393 alignPanel.makeEPS(f);
1396 public void createSVG(File f)
1398 alignPanel.makeSVG(f);
1401 public void pageSetup_actionPerformed(ActionEvent e)
1403 PrinterJob printJob = PrinterJob.getPrinterJob();
1404 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1414 public void printMenuItem_actionPerformed(ActionEvent e)
1416 // Putting in a thread avoids Swing painting problems
1417 PrintThread thread = new PrintThread(alignPanel);
1422 public void exportFeatures_actionPerformed(ActionEvent e)
1424 new AnnotationExporter().exportFeatures(alignPanel);
1428 public void exportAnnotations_actionPerformed(ActionEvent e)
1430 new AnnotationExporter().exportAnnotations(alignPanel);
1434 public void associatedData_actionPerformed(ActionEvent e)
1436 // Pick the tree file
1437 JalviewFileChooser chooser = new JalviewFileChooser(
1438 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1439 chooser.setFileView(new JalviewFileView());
1440 chooser.setDialogTitle(MessageManager
1441 .getString("label.load_jalview_annotations"));
1442 chooser.setToolTipText(MessageManager
1443 .getString("label.load_jalview_annotations"));
1445 int value = chooser.showOpenDialog(null);
1447 if (value == JalviewFileChooser.APPROVE_OPTION)
1449 String choice = chooser.getSelectedFile().getPath();
1450 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1451 loadJalviewDataFile(choice, null, null, null);
1457 * Close the current view or all views in the alignment frame. If the frame
1458 * only contains one view then the alignment will be removed from memory.
1460 * @param closeAllTabs
1463 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1465 if (alignPanels != null && alignPanels.size() < 2)
1467 closeAllTabs = true;
1472 if (alignPanels != null)
1476 if (this.isClosed())
1478 // really close all the windows - otherwise wait till
1479 // setClosed(true) is called
1480 for (int i = 0; i < alignPanels.size(); i++)
1482 AlignmentPanel ap = alignPanels.get(i);
1489 closeView(alignPanel);
1495 this.setClosed(true);
1497 } catch (Exception ex)
1499 ex.printStackTrace();
1504 * Close the specified panel and close up tabs appropriately.
1506 * @param panelToClose
1508 public void closeView(AlignmentPanel panelToClose)
1510 int index = tabbedPane.getSelectedIndex();
1511 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1512 alignPanels.remove(panelToClose);
1513 panelToClose.closePanel();
1514 panelToClose = null;
1516 tabbedPane.removeTabAt(closedindex);
1517 tabbedPane.validate();
1519 if (index > closedindex || index == tabbedPane.getTabCount())
1521 // modify currently selected tab index if necessary.
1525 this.tabSelectionChanged(index);
1531 void updateEditMenuBar()
1534 if (viewport.getHistoryList().size() > 0)
1536 undoMenuItem.setEnabled(true);
1537 CommandI command = viewport.getHistoryList().peek();
1538 undoMenuItem.setText(MessageManager.formatMessage(
1539 "label.undo_command", new Object[]
1540 { command.getDescription() }));
1544 undoMenuItem.setEnabled(false);
1545 undoMenuItem.setText(MessageManager.getString("action.undo"));
1548 if (viewport.getRedoList().size() > 0)
1550 redoMenuItem.setEnabled(true);
1552 CommandI command = viewport.getRedoList().peek();
1553 redoMenuItem.setText(MessageManager.formatMessage(
1554 "label.redo_command", new Object[]
1555 { command.getDescription() }));
1559 redoMenuItem.setEnabled(false);
1560 redoMenuItem.setText(MessageManager.getString("action.redo"));
1564 public void addHistoryItem(CommandI command)
1566 if (command.getSize() > 0)
1568 viewport.addToHistoryList(command);
1569 viewport.clearRedoList();
1570 updateEditMenuBar();
1571 viewport.updateHiddenColumns();
1572 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1573 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1574 // viewport.getColumnSelection()
1575 // .getHiddenColumns().size() > 0);
1581 * @return alignment objects for all views
1583 AlignmentI[] getViewAlignments()
1585 if (alignPanels != null)
1587 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1589 for (AlignmentPanel ap : alignPanels)
1591 als[i++] = ap.av.getAlignment();
1595 if (viewport != null)
1597 return new AlignmentI[]
1598 { viewport.getAlignment() };
1610 protected void undoMenuItem_actionPerformed(ActionEvent e)
1612 if (viewport.getHistoryList().isEmpty())
1616 CommandI command = viewport.getHistoryList().pop();
1617 viewport.addToRedoList(command);
1618 command.undoCommand(getViewAlignments());
1620 AlignmentViewport originalSource = getOriginatingSource(command);
1621 updateEditMenuBar();
1623 if (originalSource != null)
1625 if (originalSource != viewport)
1628 .warn("Implementation worry: mismatch of viewport origin for undo");
1630 originalSource.updateHiddenColumns();
1631 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1633 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1634 // viewport.getColumnSelection()
1635 // .getHiddenColumns().size() > 0);
1636 originalSource.firePropertyChange("alignment", null, originalSource
1637 .getAlignment().getSequences());
1648 protected void redoMenuItem_actionPerformed(ActionEvent e)
1650 if (viewport.getRedoList().size() < 1)
1655 CommandI command = viewport.getRedoList().pop();
1656 viewport.addToHistoryList(command);
1657 command.doCommand(getViewAlignments());
1659 AlignmentViewport originalSource = getOriginatingSource(command);
1660 updateEditMenuBar();
1662 if (originalSource != null)
1665 if (originalSource != viewport)
1668 .warn("Implementation worry: mismatch of viewport origin for redo");
1670 originalSource.updateHiddenColumns();
1671 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1673 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1674 // viewport.getColumnSelection()
1675 // .getHiddenColumns().size() > 0);
1676 originalSource.firePropertyChange("alignment", null, originalSource
1677 .getAlignment().getSequences());
1681 AlignmentViewport getOriginatingSource(CommandI command)
1683 AlignmentViewport originalSource = null;
1684 // For sequence removal and addition, we need to fire
1685 // the property change event FROM the viewport where the
1686 // original alignment was altered
1687 AlignmentI al = null;
1688 if (command instanceof EditCommand)
1690 EditCommand editCommand = (EditCommand) command;
1691 al = editCommand.getAlignment();
1692 List<Component> comps = PaintRefresher.components.get(viewport
1693 .getSequenceSetId());
1695 for (Component comp : comps)
1697 if (comp instanceof AlignmentPanel)
1699 if (al == ((AlignmentPanel) comp).av.getAlignment())
1701 originalSource = ((AlignmentPanel) comp).av;
1708 if (originalSource == null)
1710 // The original view is closed, we must validate
1711 // the current view against the closed view first
1714 PaintRefresher.validateSequences(al, viewport.getAlignment());
1717 originalSource = viewport;
1720 return originalSource;
1729 public void moveSelectedSequences(boolean up)
1731 SequenceGroup sg = viewport.getSelectionGroup();
1737 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1738 viewport.getHiddenRepSequences(), up);
1739 alignPanel.paintAlignment(true);
1742 synchronized void slideSequences(boolean right, int size)
1744 List<SequenceI> sg = new ArrayList<SequenceI>();
1745 if (viewport.cursorMode)
1747 sg.add(viewport.getAlignment().getSequenceAt(
1748 alignPanel.getSeqPanel().seqCanvas.cursorY));
1750 else if (viewport.getSelectionGroup() != null
1751 && viewport.getSelectionGroup().getSize() != viewport
1752 .getAlignment().getHeight())
1754 sg = viewport.getSelectionGroup().getSequences(
1755 viewport.getHiddenRepSequences());
1763 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1765 for (SequenceI seq : viewport.getAlignment().getSequences())
1767 if (!sg.contains(seq))
1769 invertGroup.add(seq);
1773 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1775 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1776 for (int i = 0; i < invertGroup.size(); i++)
1778 seqs2[i] = invertGroup.get(i);
1781 SlideSequencesCommand ssc;
1784 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1785 size, viewport.getGapCharacter());
1789 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1790 size, viewport.getGapCharacter());
1793 int groupAdjustment = 0;
1794 if (ssc.getGapsInsertedBegin() && right)
1796 if (viewport.cursorMode)
1798 alignPanel.getSeqPanel().moveCursor(size, 0);
1802 groupAdjustment = size;
1805 else if (!ssc.getGapsInsertedBegin() && !right)
1807 if (viewport.cursorMode)
1809 alignPanel.getSeqPanel().moveCursor(-size, 0);
1813 groupAdjustment = -size;
1817 if (groupAdjustment != 0)
1819 viewport.getSelectionGroup().setStartRes(
1820 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1821 viewport.getSelectionGroup().setEndRes(
1822 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1825 boolean appendHistoryItem = false;
1826 Deque<CommandI> historyList = viewport.getHistoryList();
1827 if (historyList != null
1828 && historyList.size() > 0
1829 && historyList.peek() instanceof SlideSequencesCommand)
1831 appendHistoryItem = ssc
1832 .appendSlideCommand((SlideSequencesCommand) historyList
1836 if (!appendHistoryItem)
1838 addHistoryItem(ssc);
1851 protected void copy_actionPerformed(ActionEvent e)
1854 if (viewport.getSelectionGroup() == null)
1858 // TODO: preserve the ordering of displayed alignment annotation in any
1859 // internal paste (particularly sequence associated annotation)
1860 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1861 String[] omitHidden = null;
1863 if (viewport.hasHiddenColumns())
1865 omitHidden = viewport.getViewAsString(true);
1868 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1871 StringSelection ss = new StringSelection(output);
1875 jalview.gui.Desktop.internalCopy = true;
1876 // Its really worth setting the clipboard contents
1877 // to empty before setting the large StringSelection!!
1878 Toolkit.getDefaultToolkit().getSystemClipboard()
1879 .setContents(new StringSelection(""), null);
1881 Toolkit.getDefaultToolkit().getSystemClipboard()
1882 .setContents(ss, Desktop.instance);
1883 } catch (OutOfMemoryError er)
1885 new OOMWarning("copying region", er);
1889 ArrayList<int[]> hiddenColumns = null;
1890 if (viewport.hasHiddenColumns())
1892 hiddenColumns = new ArrayList<int[]>();
1893 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1894 .getSelectionGroup().getEndRes();
1895 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1897 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1899 hiddenColumns.add(new int[]
1900 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1905 Desktop.jalviewClipboard = new Object[]
1906 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1907 statusBar.setText(MessageManager.formatMessage(
1908 "label.copied_sequences_to_clipboard", new Object[]
1909 { Integer.valueOf(seqs.length).toString() }));
1919 protected void pasteNew_actionPerformed(ActionEvent e)
1931 protected void pasteThis_actionPerformed(ActionEvent e)
1937 * Paste contents of Jalview clipboard
1939 * @param newAlignment
1940 * true to paste to a new alignment, otherwise add to this.
1942 void paste(boolean newAlignment)
1944 boolean externalPaste = true;
1947 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1948 Transferable contents = c.getContents(this);
1950 if (contents == null)
1958 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1959 if (str.length() < 1)
1964 format = new IdentifyFile().Identify(str, "Paste");
1966 } catch (OutOfMemoryError er)
1968 new OOMWarning("Out of memory pasting sequences!!", er);
1972 SequenceI[] sequences;
1973 boolean annotationAdded = false;
1974 AlignmentI alignment = null;
1976 if (Desktop.jalviewClipboard != null)
1978 // The clipboard was filled from within Jalview, we must use the
1980 // And dataset from the copied alignment
1981 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1982 // be doubly sure that we create *new* sequence objects.
1983 sequences = new SequenceI[newseq.length];
1984 for (int i = 0; i < newseq.length; i++)
1986 sequences[i] = new Sequence(newseq[i]);
1988 alignment = new Alignment(sequences);
1989 externalPaste = false;
1993 // parse the clipboard as an alignment.
1994 alignment = new FormatAdapter().readFile(str, "Paste", format);
1995 sequences = alignment.getSequencesArray();
1999 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2005 if (Desktop.jalviewClipboard != null)
2007 // dataset is inherited
2008 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2012 // new dataset is constructed
2013 alignment.setDataset(null);
2015 alwidth = alignment.getWidth() + 1;
2019 AlignmentI pastedal = alignment; // preserve pasted alignment object
2020 // Add pasted sequences and dataset into existing alignment.
2021 alignment = viewport.getAlignment();
2022 alwidth = alignment.getWidth() + 1;
2023 // decide if we need to import sequences from an existing dataset
2024 boolean importDs = Desktop.jalviewClipboard != null
2025 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2026 // importDs==true instructs us to copy over new dataset sequences from
2027 // an existing alignment
2028 Vector newDs = (importDs) ? new Vector() : null; // used to create
2029 // minimum dataset set
2031 for (int i = 0; i < sequences.length; i++)
2035 newDs.addElement(null);
2037 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2039 if (importDs && ds != null)
2041 if (!newDs.contains(ds))
2043 newDs.setElementAt(ds, i);
2044 ds = new Sequence(ds);
2045 // update with new dataset sequence
2046 sequences[i].setDatasetSequence(ds);
2050 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2055 // copy and derive new dataset sequence
2056 sequences[i] = sequences[i].deriveSequence();
2057 alignment.getDataset().addSequence(
2058 sequences[i].getDatasetSequence());
2059 // TODO: avoid creation of duplicate dataset sequences with a
2060 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2062 alignment.addSequence(sequences[i]); // merges dataset
2066 newDs.clear(); // tidy up
2068 if (alignment.getAlignmentAnnotation() != null)
2070 for (AlignmentAnnotation alan : alignment
2071 .getAlignmentAnnotation())
2073 if (alan.graphGroup > fgroup)
2075 fgroup = alan.graphGroup;
2079 if (pastedal.getAlignmentAnnotation() != null)
2081 // Add any annotation attached to alignment.
2082 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2083 for (int i = 0; i < alann.length; i++)
2085 annotationAdded = true;
2086 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2088 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2089 if (newann.graphGroup > -1)
2091 if (newGraphGroups.size() <= newann.graphGroup
2092 || newGraphGroups.get(newann.graphGroup) == null)
2094 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2096 newGraphGroups.add(q, null);
2098 newGraphGroups.set(newann.graphGroup, new Integer(
2101 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2105 newann.padAnnotation(alwidth);
2106 alignment.addAnnotation(newann);
2116 addHistoryItem(new EditCommand(
2117 MessageManager.getString("label.add_sequences"),
2119 sequences, 0, alignment.getWidth(), alignment));
2121 // Add any annotations attached to sequences
2122 for (int i = 0; i < sequences.length; i++)
2124 if (sequences[i].getAnnotation() != null)
2126 AlignmentAnnotation newann;
2127 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2129 annotationAdded = true;
2130 newann = sequences[i].getAnnotation()[a];
2131 newann.adjustForAlignment();
2132 newann.padAnnotation(alwidth);
2133 if (newann.graphGroup > -1)
2135 if (newann.graphGroup > -1)
2137 if (newGraphGroups.size() <= newann.graphGroup
2138 || newGraphGroups.get(newann.graphGroup) == null)
2140 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2142 newGraphGroups.add(q, null);
2144 newGraphGroups.set(newann.graphGroup, new Integer(
2147 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2151 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2156 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2163 // propagate alignment changed.
2164 viewport.setEndSeq(alignment.getHeight());
2165 if (annotationAdded)
2167 // Duplicate sequence annotation in all views.
2168 AlignmentI[] alview = this.getViewAlignments();
2169 for (int i = 0; i < sequences.length; i++)
2171 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2176 for (int avnum = 0; avnum < alview.length; avnum++)
2178 if (alview[avnum] != alignment)
2180 // duplicate in a view other than the one with input focus
2181 int avwidth = alview[avnum].getWidth() + 1;
2182 // this relies on sann being preserved after we
2183 // modify the sequence's annotation array for each duplication
2184 for (int a = 0; a < sann.length; a++)
2186 AlignmentAnnotation newann = new AlignmentAnnotation(
2188 sequences[i].addAlignmentAnnotation(newann);
2189 newann.padAnnotation(avwidth);
2190 alview[avnum].addAnnotation(newann); // annotation was
2191 // duplicated earlier
2192 // TODO JAL-1145 graphGroups are not updated for sequence
2193 // annotation added to several views. This may cause
2195 alview[avnum].setAnnotationIndex(newann, a);
2200 buildSortByAnnotationScoresMenu();
2202 viewport.firePropertyChange("alignment", null,
2203 alignment.getSequences());
2204 if (alignPanels != null)
2206 for (AlignmentPanel ap : alignPanels)
2208 ap.validateAnnotationDimensions(false);
2213 alignPanel.validateAnnotationDimensions(false);
2219 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2221 String newtitle = new String("Copied sequences");
2223 if (Desktop.jalviewClipboard != null
2224 && Desktop.jalviewClipboard[2] != null)
2226 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2227 for (int[] region : hc)
2229 af.viewport.hideColumns(region[0], region[1]);
2233 // >>>This is a fix for the moment, until a better solution is
2235 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2237 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2239 // TODO: maintain provenance of an alignment, rather than just make the
2240 // title a concatenation of operations.
2243 if (title.startsWith("Copied sequences"))
2249 newtitle = newtitle.concat("- from " + title);
2254 newtitle = new String("Pasted sequences");
2257 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2262 } catch (Exception ex)
2264 ex.printStackTrace();
2265 System.out.println("Exception whilst pasting: " + ex);
2266 // could be anything being pasted in here
2272 protected void expand_newalign(ActionEvent e)
2276 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2277 .getAlignment(), -1);
2278 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2280 String newtitle = new String("Flanking alignment");
2282 if (Desktop.jalviewClipboard != null
2283 && Desktop.jalviewClipboard[2] != null)
2285 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2286 for (int region[] : hc)
2288 af.viewport.hideColumns(region[0], region[1]);
2292 // >>>This is a fix for the moment, until a better solution is
2294 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2296 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2298 // TODO: maintain provenance of an alignment, rather than just make the
2299 // title a concatenation of operations.
2301 if (title.startsWith("Copied sequences"))
2307 newtitle = newtitle.concat("- from " + title);
2311 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2313 } catch (Exception ex)
2315 ex.printStackTrace();
2316 System.out.println("Exception whilst pasting: " + ex);
2317 // could be anything being pasted in here
2318 } catch (OutOfMemoryError oom)
2320 new OOMWarning("Viewing flanking region of alignment", oom);
2331 protected void cut_actionPerformed(ActionEvent e)
2333 copy_actionPerformed(null);
2334 delete_actionPerformed(null);
2344 protected void delete_actionPerformed(ActionEvent evt)
2347 SequenceGroup sg = viewport.getSelectionGroup();
2354 * If the cut affects all sequences, warn, remove highlighted columns
2356 if (sg.getSize() == viewport.getAlignment().getHeight())
2358 int confirm = JOptionPane.showConfirmDialog(this,
2359 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2360 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2361 JOptionPane.OK_CANCEL_OPTION);
2363 if (confirm == JOptionPane.CANCEL_OPTION
2364 || confirm == JOptionPane.CLOSED_OPTION)
2368 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2369 sg.getEndRes() + 1);
2372 SequenceI[] cut = sg.getSequences()
2373 .toArray(new SequenceI[sg.getSize()]);
2375 addHistoryItem(new EditCommand(
2376 MessageManager.getString("label.cut_sequences"), Action.CUT,
2377 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2378 viewport.getAlignment()));
2380 viewport.setSelectionGroup(null);
2381 viewport.sendSelection();
2382 viewport.getAlignment().deleteGroup(sg);
2384 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2386 if (viewport.getAlignment().getHeight() < 1)
2390 this.setClosed(true);
2391 } catch (Exception ex)
2404 protected void deleteGroups_actionPerformed(ActionEvent e)
2406 if (avc.deleteGroups())
2408 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2409 alignPanel.updateAnnotation();
2410 alignPanel.paintAlignment(true);
2421 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2423 SequenceGroup sg = new SequenceGroup();
2425 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2427 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2430 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2431 viewport.setSelectionGroup(sg);
2432 viewport.sendSelection();
2433 alignPanel.paintAlignment(true);
2434 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2444 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2446 if (viewport.cursorMode)
2448 alignPanel.getSeqPanel().keyboardNo1 = null;
2449 alignPanel.getSeqPanel().keyboardNo2 = null;
2451 viewport.setSelectionGroup(null);
2452 viewport.getColumnSelection().clear();
2453 viewport.setSelectionGroup(null);
2454 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2455 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2456 alignPanel.paintAlignment(true);
2457 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2458 viewport.sendSelection();
2468 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2470 SequenceGroup sg = viewport.getSelectionGroup();
2474 selectAllSequenceMenuItem_actionPerformed(null);
2479 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2481 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2484 alignPanel.paintAlignment(true);
2485 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2486 viewport.sendSelection();
2490 public void invertColSel_actionPerformed(ActionEvent e)
2492 viewport.invertColumnSelection();
2493 alignPanel.paintAlignment(true);
2494 viewport.sendSelection();
2504 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2506 trimAlignment(true);
2516 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2518 trimAlignment(false);
2521 void trimAlignment(boolean trimLeft)
2523 ColumnSelection colSel = viewport.getColumnSelection();
2526 if (colSel.size() > 0)
2530 column = colSel.getMin();
2534 column = colSel.getMax();
2538 if (viewport.getSelectionGroup() != null)
2540 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2541 viewport.getHiddenRepSequences());
2545 seqs = viewport.getAlignment().getSequencesArray();
2548 TrimRegionCommand trimRegion;
2551 trimRegion = new TrimRegionCommand("Remove Left",
2552 TrimRegionCommand.TRIM_LEFT, seqs, column,
2553 viewport.getAlignment(), viewport.getColumnSelection(),
2554 viewport.getSelectionGroup());
2555 viewport.setStartRes(0);
2559 trimRegion = new TrimRegionCommand("Remove Right",
2560 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2561 viewport.getAlignment(), viewport.getColumnSelection(),
2562 viewport.getSelectionGroup());
2565 statusBar.setText(MessageManager.formatMessage(
2566 "label.removed_columns", new String[]
2567 { Integer.valueOf(trimRegion.getSize()).toString() }));
2569 addHistoryItem(trimRegion);
2571 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2573 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2574 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2576 viewport.getAlignment().deleteGroup(sg);
2580 viewport.firePropertyChange("alignment", null, viewport
2581 .getAlignment().getSequences());
2592 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2594 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2597 if (viewport.getSelectionGroup() != null)
2599 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2600 viewport.getHiddenRepSequences());
2601 start = viewport.getSelectionGroup().getStartRes();
2602 end = viewport.getSelectionGroup().getEndRes();
2606 seqs = viewport.getAlignment().getSequencesArray();
2609 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2610 "Remove Gapped Columns", seqs, start, end,
2611 viewport.getAlignment());
2613 addHistoryItem(removeGapCols);
2615 statusBar.setText(MessageManager.formatMessage(
2616 "label.removed_empty_columns", new Object[]
2617 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2619 // This is to maintain viewport position on first residue
2620 // of first sequence
2621 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2622 int startRes = seq.findPosition(viewport.startRes);
2623 // ShiftList shifts;
2624 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2625 // edit.alColumnChanges=shifts.getInverse();
2626 // if (viewport.hasHiddenColumns)
2627 // viewport.getColumnSelection().compensateForEdits(shifts);
2628 viewport.setStartRes(seq.findIndex(startRes) - 1);
2629 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2641 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2643 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2646 if (viewport.getSelectionGroup() != null)
2648 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2649 viewport.getHiddenRepSequences());
2650 start = viewport.getSelectionGroup().getStartRes();
2651 end = viewport.getSelectionGroup().getEndRes();
2655 seqs = viewport.getAlignment().getSequencesArray();
2658 // This is to maintain viewport position on first residue
2659 // of first sequence
2660 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2661 int startRes = seq.findPosition(viewport.startRes);
2663 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2664 viewport.getAlignment()));
2666 viewport.setStartRes(seq.findIndex(startRes) - 1);
2668 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2680 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2682 viewport.setPadGaps(padGapsMenuitem.isSelected());
2683 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2694 public void findMenuItem_actionPerformed(ActionEvent e)
2700 * Create a new view of the current alignment.
2703 public void newView_actionPerformed(ActionEvent e)
2705 newView(null, true);
2709 * Creates and shows a new view of the current alignment.
2712 * title of newly created view; if null, one will be generated
2713 * @param copyAnnotation
2714 * if true then duplicate all annnotation, groups and settings
2715 * @return new alignment panel, already displayed.
2717 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2720 * Create a new AlignmentPanel (with its own, new Viewport)
2722 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2724 if (!copyAnnotation)
2727 * remove all groups and annotation except for the automatic stuff
2729 newap.av.getAlignment().deleteAllGroups();
2730 newap.av.getAlignment().deleteAllAnnotations(false);
2733 newap.av.setGatherViewsHere(false);
2735 if (viewport.viewName == null)
2737 viewport.viewName = MessageManager
2738 .getString("label.view_name_original");
2742 * Views share the same edits, undo and redo stacks, mappings.
2744 newap.av.setHistoryList(viewport.getHistoryList());
2745 newap.av.setRedoList(viewport.getRedoList());
2746 newap.av.getAlignment().setCodonFrames(
2747 viewport.getAlignment().getCodonFrames());
2749 newap.av.viewName = getNewViewName(viewTitle);
2751 addAlignmentPanel(newap, true);
2752 newap.alignmentChanged();
2754 if (alignPanels.size() == 2)
2756 viewport.setGatherViewsHere(true);
2758 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2763 * Make a new name for the view, ensuring it is unique within the current
2764 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2765 * these now use viewId. Unique view names are still desirable for usability.)
2770 protected String getNewViewName(String viewTitle)
2772 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2773 boolean addFirstIndex = false;
2774 if (viewTitle == null || viewTitle.trim().length() == 0)
2776 viewTitle = MessageManager.getString("action.view");
2777 addFirstIndex = true;
2781 index = 1;// we count from 1 if given a specific name
2783 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2785 List<Component> comps = PaintRefresher.components.get(viewport
2786 .getSequenceSetId());
2788 List<String> existingNames = getExistingViewNames(comps);
2790 while (existingNames.contains(newViewName))
2792 newViewName = viewTitle + " " + (++index);
2798 * Returns a list of distinct view names found in the given list of
2799 * components. View names are held on the viewport of an AlignmentPanel.
2804 protected List<String> getExistingViewNames(List<Component> comps)
2806 List<String> existingNames = new ArrayList<String>();
2807 for (Component comp : comps)
2809 if (comp instanceof AlignmentPanel)
2811 AlignmentPanel ap = (AlignmentPanel) comp;
2812 if (!existingNames.contains(ap.av.viewName))
2814 existingNames.add(ap.av.viewName);
2818 return existingNames;
2822 * Explode tabbed views into separate windows.
2825 public void expandViews_actionPerformed(ActionEvent e)
2827 Desktop.instance.explodeViews(this);
2831 * Gather views in separate windows back into a tabbed presentation.
2834 public void gatherViews_actionPerformed(ActionEvent e)
2836 Desktop.instance.gatherViews(this);
2846 public void font_actionPerformed(ActionEvent e)
2848 new FontChooser(alignPanel);
2858 protected void seqLimit_actionPerformed(ActionEvent e)
2860 viewport.setShowJVSuffix(seqLimits.isSelected());
2862 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2863 .calculateIdWidth());
2864 alignPanel.paintAlignment(true);
2868 public void idRightAlign_actionPerformed(ActionEvent e)
2870 viewport.setRightAlignIds(idRightAlign.isSelected());
2871 alignPanel.paintAlignment(true);
2875 public void centreColumnLabels_actionPerformed(ActionEvent e)
2877 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2878 alignPanel.paintAlignment(true);
2884 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2887 protected void followHighlight_actionPerformed()
2890 * Set the 'follow' flag on the Viewport (and scroll to position if now
2893 final boolean state = this.followHighlightMenuItem.getState();
2894 viewport.setFollowHighlight(state);
2897 alignPanel.scrollToPosition(
2898 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2909 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2911 viewport.setColourText(colourTextMenuItem.isSelected());
2912 alignPanel.paintAlignment(true);
2922 public void wrapMenuItem_actionPerformed(ActionEvent e)
2924 scaleAbove.setVisible(wrapMenuItem.isSelected());
2925 scaleLeft.setVisible(wrapMenuItem.isSelected());
2926 scaleRight.setVisible(wrapMenuItem.isSelected());
2927 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2928 alignPanel.updateLayout();
2932 public void showAllSeqs_actionPerformed(ActionEvent e)
2934 viewport.showAllHiddenSeqs();
2938 public void showAllColumns_actionPerformed(ActionEvent e)
2940 viewport.showAllHiddenColumns();
2945 public void hideSelSequences_actionPerformed(ActionEvent e)
2947 viewport.hideAllSelectedSeqs();
2948 // alignPanel.paintAlignment(true);
2952 * called by key handler and the hide all/show all menu items
2957 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2960 boolean hide = false;
2961 SequenceGroup sg = viewport.getSelectionGroup();
2962 if (!toggleSeqs && !toggleCols)
2964 // Hide everything by the current selection - this is a hack - we do the
2965 // invert and then hide
2966 // first check that there will be visible columns after the invert.
2967 if ((viewport.getColumnSelection() != null
2968 && viewport.getColumnSelection().getSelected() != null && viewport
2969 .getColumnSelection().getSelected().size() > 0)
2970 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2973 // now invert the sequence set, if required - empty selection implies
2974 // that no hiding is required.
2977 invertSequenceMenuItem_actionPerformed(null);
2978 sg = viewport.getSelectionGroup();
2982 viewport.expandColSelection(sg, true);
2983 // finally invert the column selection and get the new sequence
2985 invertColSel_actionPerformed(null);
2992 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2994 hideSelSequences_actionPerformed(null);
2997 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3000 showAllSeqs_actionPerformed(null);
3006 if (viewport.getColumnSelection().getSelected().size() > 0)
3008 hideSelColumns_actionPerformed(null);
3011 viewport.setSelectionGroup(sg);
3016 showAllColumns_actionPerformed(null);
3025 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3026 * event.ActionEvent)
3029 public void hideAllButSelection_actionPerformed(ActionEvent e)
3031 toggleHiddenRegions(false, false);
3038 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3042 public void hideAllSelection_actionPerformed(ActionEvent e)
3044 SequenceGroup sg = viewport.getSelectionGroup();
3045 viewport.expandColSelection(sg, false);
3046 viewport.hideAllSelectedSeqs();
3047 viewport.hideSelectedColumns();
3048 alignPanel.paintAlignment(true);
3055 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3059 public void showAllhidden_actionPerformed(ActionEvent e)
3061 viewport.showAllHiddenColumns();
3062 viewport.showAllHiddenSeqs();
3063 alignPanel.paintAlignment(true);
3067 public void hideSelColumns_actionPerformed(ActionEvent e)
3069 viewport.hideSelectedColumns();
3070 alignPanel.paintAlignment(true);
3074 public void hiddenMarkers_actionPerformed(ActionEvent e)
3076 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3087 protected void scaleAbove_actionPerformed(ActionEvent e)
3089 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3090 alignPanel.paintAlignment(true);
3100 protected void scaleLeft_actionPerformed(ActionEvent e)
3102 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3103 alignPanel.paintAlignment(true);
3113 protected void scaleRight_actionPerformed(ActionEvent e)
3115 viewport.setScaleRightWrapped(scaleRight.isSelected());
3116 alignPanel.paintAlignment(true);
3126 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3128 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3129 alignPanel.paintAlignment(true);
3139 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3141 viewport.setShowText(viewTextMenuItem.isSelected());
3142 alignPanel.paintAlignment(true);
3152 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3154 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3155 alignPanel.paintAlignment(true);
3158 public FeatureSettings featureSettings;
3161 public FeatureSettingsControllerI getFeatureSettingsUI()
3163 return featureSettings;
3167 public void featureSettings_actionPerformed(ActionEvent e)
3169 if (featureSettings != null)
3171 featureSettings.close();
3172 featureSettings = null;
3174 if (!showSeqFeatures.isSelected())
3176 // make sure features are actually displayed
3177 showSeqFeatures.setSelected(true);
3178 showSeqFeatures_actionPerformed(null);
3180 featureSettings = new FeatureSettings(this);
3184 * Set or clear 'Show Sequence Features'
3190 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3192 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3193 alignPanel.paintAlignment(true);
3194 if (alignPanel.getOverviewPanel() != null)
3196 alignPanel.getOverviewPanel().updateOverviewImage();
3201 * Set or clear 'Show Sequence Features'
3207 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3209 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3211 if (viewport.isShowSequenceFeaturesHeight())
3213 // ensure we're actually displaying features
3214 viewport.setShowSequenceFeatures(true);
3215 showSeqFeatures.setSelected(true);
3217 alignPanel.paintAlignment(true);
3218 if (alignPanel.getOverviewPanel() != null)
3220 alignPanel.getOverviewPanel().updateOverviewImage();
3225 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3226 * the annotations panel as a whole.
3228 * The options to show/hide all annotations should be enabled when the panel
3229 * is shown, and disabled when the panel is hidden.
3234 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3236 final boolean setVisible = annotationPanelMenuItem.isSelected();
3237 viewport.setShowAnnotation(setVisible);
3238 this.showAllSeqAnnotations.setEnabled(setVisible);
3239 this.hideAllSeqAnnotations.setEnabled(setVisible);
3240 this.showAllAlAnnotations.setEnabled(setVisible);
3241 this.hideAllAlAnnotations.setEnabled(setVisible);
3242 alignPanel.updateLayout();
3246 public void alignmentProperties()
3248 JEditorPane editPane = new JEditorPane("text/html", "");
3249 editPane.setEditable(false);
3250 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3252 editPane.setText(MessageManager.formatMessage("label.html_content",
3254 { contents.toString() }));
3255 JInternalFrame frame = new JInternalFrame();
3256 frame.getContentPane().add(new JScrollPane(editPane));
3258 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3259 "label.alignment_properties", new Object[]
3260 { getTitle() }), 500, 400);
3270 public void overviewMenuItem_actionPerformed(ActionEvent e)
3272 if (alignPanel.overviewPanel != null)
3277 JInternalFrame frame = new JInternalFrame();
3278 OverviewPanel overview = new OverviewPanel(alignPanel);
3279 frame.setContentPane(overview);
3280 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3281 "label.overview_params", new Object[]
3282 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3284 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3285 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3288 public void internalFrameClosed(
3289 javax.swing.event.InternalFrameEvent evt)
3291 alignPanel.setOverviewPanel(null);
3295 alignPanel.setOverviewPanel(overview);
3299 public void textColour_actionPerformed(ActionEvent e)
3301 new TextColourChooser().chooseColour(alignPanel, null);
3311 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3323 public void clustalColour_actionPerformed(ActionEvent e)
3325 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3326 viewport.getHiddenRepSequences()));
3336 public void zappoColour_actionPerformed(ActionEvent e)
3338 changeColour(new ZappoColourScheme());
3348 public void taylorColour_actionPerformed(ActionEvent e)
3350 changeColour(new TaylorColourScheme());
3360 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3362 changeColour(new HydrophobicColourScheme());
3372 public void helixColour_actionPerformed(ActionEvent e)
3374 changeColour(new HelixColourScheme());
3384 public void strandColour_actionPerformed(ActionEvent e)
3386 changeColour(new StrandColourScheme());
3396 public void turnColour_actionPerformed(ActionEvent e)
3398 changeColour(new TurnColourScheme());
3408 public void buriedColour_actionPerformed(ActionEvent e)
3410 changeColour(new BuriedColourScheme());
3420 public void nucleotideColour_actionPerformed(ActionEvent e)
3422 changeColour(new NucleotideColourScheme());
3426 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3428 changeColour(new PurinePyrimidineColourScheme());
3432 * public void covariationColour_actionPerformed(ActionEvent e) {
3434 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3438 public void annotationColour_actionPerformed(ActionEvent e)
3440 new AnnotationColourChooser(viewport, alignPanel);
3444 public void annotationColumn_actionPerformed(ActionEvent e)
3446 new AnnotationColumnChooser(viewport, alignPanel);
3450 public void rnahelicesColour_actionPerformed(ActionEvent e)
3452 new RNAHelicesColourChooser(viewport, alignPanel);
3462 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3464 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3473 public void changeColour(ColourSchemeI cs)
3475 // TODO: compare with applet and pull up to model method
3480 if (viewport.getAbovePIDThreshold())
3482 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3484 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3488 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3491 if (viewport.getConservationSelected())
3494 Alignment al = (Alignment) viewport.getAlignment();
3495 Conservation c = new Conservation("All",
3496 ResidueProperties.propHash, 3, al.getSequences(), 0,
3500 c.verdict(false, viewport.getConsPercGaps());
3502 cs.setConservation(c);
3504 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3509 cs.setConservation(null);
3512 cs.setConsensus(viewport.getSequenceConsensusHash());
3515 viewport.setGlobalColourScheme(cs);
3517 if (viewport.getColourAppliesToAllGroups())
3520 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3528 if (cs instanceof ClustalxColourScheme)
3530 sg.cs = new ClustalxColourScheme(sg,
3531 viewport.getHiddenRepSequences());
3533 else if (cs instanceof UserColourScheme)
3535 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3541 sg.cs = cs.getClass().newInstance();
3542 } catch (Exception ex)
3547 if (viewport.getAbovePIDThreshold()
3548 || cs instanceof PIDColourScheme
3549 || cs instanceof Blosum62ColourScheme)
3551 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3553 sg.cs.setConsensus(AAFrequency.calculate(
3554 sg.getSequences(viewport.getHiddenRepSequences()),
3555 sg.getStartRes(), sg.getEndRes() + 1));
3559 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3562 if (viewport.getConservationSelected())
3564 Conservation c = new Conservation("Group",
3565 ResidueProperties.propHash, 3, sg.getSequences(viewport
3566 .getHiddenRepSequences()), sg.getStartRes(),
3567 sg.getEndRes() + 1);
3569 c.verdict(false, viewport.getConsPercGaps());
3570 sg.cs.setConservation(c);
3574 sg.cs.setConservation(null);
3579 if (alignPanel.getOverviewPanel() != null)
3581 alignPanel.getOverviewPanel().updateOverviewImage();
3584 alignPanel.paintAlignment(true);
3594 protected void modifyPID_actionPerformed(ActionEvent e)
3596 if (viewport.getAbovePIDThreshold()
3597 && viewport.getGlobalColourScheme() != null)
3599 SliderPanel.setPIDSliderSource(alignPanel,
3600 viewport.getGlobalColourScheme(), "Background");
3601 SliderPanel.showPIDSlider();
3612 protected void modifyConservation_actionPerformed(ActionEvent e)
3614 if (viewport.getConservationSelected()
3615 && viewport.getGlobalColourScheme() != null)
3617 SliderPanel.setConservationSlider(alignPanel,
3618 viewport.getGlobalColourScheme(), "Background");
3619 SliderPanel.showConservationSlider();
3630 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3632 viewport.setConservationSelected(conservationMenuItem.isSelected());
3634 viewport.setAbovePIDThreshold(false);
3635 abovePIDThreshold.setSelected(false);
3637 changeColour(viewport.getGlobalColourScheme());
3639 modifyConservation_actionPerformed(null);
3649 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3651 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3653 conservationMenuItem.setSelected(false);
3654 viewport.setConservationSelected(false);
3656 changeColour(viewport.getGlobalColourScheme());
3658 modifyPID_actionPerformed(null);
3668 public void userDefinedColour_actionPerformed(ActionEvent e)
3670 if (e.getActionCommand().equals(
3671 MessageManager.getString("action.user_defined")))
3673 new UserDefinedColours(alignPanel, null);
3677 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3678 .getUserColourSchemes().get(e.getActionCommand());
3684 public void updateUserColourMenu()
3687 Component[] menuItems = colourMenu.getMenuComponents();
3688 int iSize = menuItems.length;
3689 for (int i = 0; i < iSize; i++)
3691 if (menuItems[i].getName() != null
3692 && menuItems[i].getName().equals("USER_DEFINED"))
3694 colourMenu.remove(menuItems[i]);
3698 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3700 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3701 .getUserColourSchemes().keys();
3703 while (userColours.hasMoreElements())
3705 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3706 userColours.nextElement().toString());
3707 radioItem.setName("USER_DEFINED");
3708 radioItem.addMouseListener(new MouseAdapter()
3711 public void mousePressed(MouseEvent evt)
3713 if (evt.isControlDown()
3714 || SwingUtilities.isRightMouseButton(evt))
3716 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3718 int option = JOptionPane.showInternalConfirmDialog(
3719 jalview.gui.Desktop.desktop,
3721 .getString("label.remove_from_default_list"),
3723 .getString("label.remove_user_defined_colour"),
3724 JOptionPane.YES_NO_OPTION);
3725 if (option == JOptionPane.YES_OPTION)
3727 jalview.gui.UserDefinedColours
3728 .removeColourFromDefaults(radioItem.getText());
3729 colourMenu.remove(radioItem);
3733 radioItem.addActionListener(new ActionListener()
3736 public void actionPerformed(ActionEvent evt)
3738 userDefinedColour_actionPerformed(evt);
3745 radioItem.addActionListener(new ActionListener()
3748 public void actionPerformed(ActionEvent evt)
3750 userDefinedColour_actionPerformed(evt);
3754 colourMenu.insert(radioItem, 15);
3755 colours.add(radioItem);
3767 public void PIDColour_actionPerformed(ActionEvent e)
3769 changeColour(new PIDColourScheme());
3779 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3781 changeColour(new Blosum62ColourScheme());
3791 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3793 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3794 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3795 .getAlignment().getSequenceAt(0), null);
3796 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3797 viewport.getAlignment()));
3798 alignPanel.paintAlignment(true);
3808 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3810 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3811 AlignmentSorter.sortByID(viewport.getAlignment());
3812 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3813 viewport.getAlignment()));
3814 alignPanel.paintAlignment(true);
3824 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3826 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3827 AlignmentSorter.sortByLength(viewport.getAlignment());
3828 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3829 viewport.getAlignment()));
3830 alignPanel.paintAlignment(true);
3840 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3842 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3843 AlignmentSorter.sortByGroup(viewport.getAlignment());
3844 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3845 viewport.getAlignment()));
3847 alignPanel.paintAlignment(true);
3857 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3859 new RedundancyPanel(alignPanel, this);
3869 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3871 if ((viewport.getSelectionGroup() == null)
3872 || (viewport.getSelectionGroup().getSize() < 2))
3874 JOptionPane.showInternalMessageDialog(this, MessageManager
3875 .getString("label.you_must_select_least_two_sequences"),
3876 MessageManager.getString("label.invalid_selection"),
3877 JOptionPane.WARNING_MESSAGE);
3881 JInternalFrame frame = new JInternalFrame();
3882 frame.setContentPane(new PairwiseAlignPanel(viewport));
3883 Desktop.addInternalFrame(frame,
3884 MessageManager.getString("action.pairwise_alignment"), 600,
3896 public void PCAMenuItem_actionPerformed(ActionEvent e)
3898 if (((viewport.getSelectionGroup() != null)
3899 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3900 .getSelectionGroup().getSize() > 0))
3901 || (viewport.getAlignment().getHeight() < 4))
3904 .showInternalMessageDialog(
3907 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3909 .getString("label.sequence_selection_insufficient"),
3910 JOptionPane.WARNING_MESSAGE);
3915 new PCAPanel(alignPanel);
3919 public void autoCalculate_actionPerformed(ActionEvent e)
3921 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3922 if (viewport.autoCalculateConsensus)
3924 viewport.firePropertyChange("alignment", null, viewport
3925 .getAlignment().getSequences());
3930 public void sortByTreeOption_actionPerformed(ActionEvent e)
3932 viewport.sortByTree = sortByTree.isSelected();
3936 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3938 viewport.followSelection = listenToViewSelections.isSelected();
3948 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3950 newTreePanel("AV", "PID", "Average distance tree using PID");
3960 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3962 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3972 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3974 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3984 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3986 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3999 void newTreePanel(String type, String pwType, String title)
4003 if (viewport.getSelectionGroup() != null
4004 && viewport.getSelectionGroup().getSize() > 0)
4006 if (viewport.getSelectionGroup().getSize() < 3)
4012 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4014 .getString("label.not_enough_sequences"),
4015 JOptionPane.WARNING_MESSAGE);
4019 SequenceGroup sg = viewport.getSelectionGroup();
4021 /* Decide if the selection is a column region */
4022 for (SequenceI _s : sg.getSequences())
4024 if (_s.getLength() < sg.getEndRes())
4030 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4032 .getString("label.sequences_selection_not_aligned"),
4033 JOptionPane.WARNING_MESSAGE);
4039 title = title + " on region";
4040 tp = new TreePanel(alignPanel, type, pwType);
4044 // are the visible sequences aligned?
4045 if (!viewport.getAlignment().isAligned(false))
4051 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4053 .getString("label.sequences_not_aligned"),
4054 JOptionPane.WARNING_MESSAGE);
4059 if (viewport.getAlignment().getHeight() < 2)
4064 tp = new TreePanel(alignPanel, type, pwType);
4069 if (viewport.viewName != null)
4071 title += viewport.viewName + " of ";
4074 title += this.title;
4076 Desktop.addInternalFrame(tp, title, 600, 500);
4087 public void addSortByOrderMenuItem(String title,
4088 final AlignmentOrder order)
4090 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4092 item.addActionListener(new java.awt.event.ActionListener()
4095 public void actionPerformed(ActionEvent e)
4097 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4099 // TODO: JBPNote - have to map order entries to curent SequenceI
4101 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4103 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4106 alignPanel.paintAlignment(true);
4112 * Add a new sort by annotation score menu item
4115 * the menu to add the option to
4117 * the label used to retrieve scores for each sequence on the
4120 public void addSortByAnnotScoreMenuItem(JMenu sort,
4121 final String scoreLabel)
4123 final JMenuItem item = new JMenuItem(scoreLabel);
4125 item.addActionListener(new java.awt.event.ActionListener()
4128 public void actionPerformed(ActionEvent e)
4130 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4131 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4132 viewport.getAlignment());// ,viewport.getSelectionGroup());
4133 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4134 viewport.getAlignment()));
4135 alignPanel.paintAlignment(true);
4141 * last hash for alignment's annotation array - used to minimise cost of
4144 protected int _annotationScoreVectorHash;
4147 * search the alignment and rebuild the sort by annotation score submenu the
4148 * last alignment annotation vector hash is stored to minimize cost of
4149 * rebuilding in subsequence calls.
4153 public void buildSortByAnnotationScoresMenu()
4155 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4160 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4162 sortByAnnotScore.removeAll();
4163 // almost certainly a quicker way to do this - but we keep it simple
4164 Hashtable scoreSorts = new Hashtable();
4165 AlignmentAnnotation aann[];
4166 for (SequenceI sqa : viewport.getAlignment().getSequences())
4168 aann = sqa.getAnnotation();
4169 for (int i = 0; aann != null && i < aann.length; i++)
4171 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4173 scoreSorts.put(aann[i].label, aann[i].label);
4177 Enumeration labels = scoreSorts.keys();
4178 while (labels.hasMoreElements())
4180 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4181 (String) labels.nextElement());
4183 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4186 _annotationScoreVectorHash = viewport.getAlignment()
4187 .getAlignmentAnnotation().hashCode();
4192 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4193 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4194 * call. Listeners are added to remove the menu item when the treePanel is
4195 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4199 * Displayed tree window.
4201 * SortBy menu item title.
4204 public void buildTreeMenu()
4206 calculateTree.removeAll();
4207 // build the calculate menu
4209 for (final String type : new String[]
4212 String treecalcnm = MessageManager.getString("label.tree_calc_"
4213 + type.toLowerCase());
4214 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4216 JMenuItem tm = new JMenuItem();
4217 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4218 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4220 String smn = MessageManager.getStringOrReturn(
4221 "label.score_model_", sm.getName());
4222 final String title = MessageManager.formatMessage(
4223 "label.treecalc_title", treecalcnm, smn);
4224 tm.setText(title);//
4225 tm.addActionListener(new java.awt.event.ActionListener()
4228 public void actionPerformed(ActionEvent e)
4230 newTreePanel(type, pwtype, title);
4233 calculateTree.add(tm);
4238 sortByTreeMenu.removeAll();
4240 List<Component> comps = PaintRefresher.components.get(viewport
4241 .getSequenceSetId());
4242 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4243 for (Component comp : comps)
4245 if (comp instanceof TreePanel)
4247 treePanels.add((TreePanel) comp);
4251 if (treePanels.size() < 1)
4253 sortByTreeMenu.setVisible(false);
4257 sortByTreeMenu.setVisible(true);
4259 for (final TreePanel tp : treePanels)
4261 final JMenuItem item = new JMenuItem(tp.getTitle());
4262 item.addActionListener(new java.awt.event.ActionListener()
4265 public void actionPerformed(ActionEvent e)
4267 tp.sortByTree_actionPerformed();
4268 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4273 sortByTreeMenu.add(item);
4277 public boolean sortBy(AlignmentOrder alorder, String undoname)
4279 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4280 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4281 if (undoname != null)
4283 addHistoryItem(new OrderCommand(undoname, oldOrder,
4284 viewport.getAlignment()));
4286 alignPanel.paintAlignment(true);
4291 * Work out whether the whole set of sequences or just the selected set will
4292 * be submitted for multiple alignment.
4295 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4297 // Now, check we have enough sequences
4298 AlignmentView msa = null;
4300 if ((viewport.getSelectionGroup() != null)
4301 && (viewport.getSelectionGroup().getSize() > 1))
4303 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4304 // some common interface!
4306 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4307 * SequenceI[sz = seqs.getSize(false)];
4309 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4310 * seqs.getSequenceAt(i); }
4312 msa = viewport.getAlignmentView(true);
4314 else if (viewport.getSelectionGroup() != null
4315 && viewport.getSelectionGroup().getSize() == 1)
4317 int option = JOptionPane.showConfirmDialog(this,
4318 MessageManager.getString("warn.oneseq_msainput_selection"),
4319 MessageManager.getString("label.invalid_selection"),
4320 JOptionPane.OK_CANCEL_OPTION);
4321 if (option == JOptionPane.OK_OPTION)
4323 msa = viewport.getAlignmentView(false);
4328 msa = viewport.getAlignmentView(false);
4334 * Decides what is submitted to a secondary structure prediction service: the
4335 * first sequence in the alignment, or in the current selection, or, if the
4336 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4337 * region or the whole alignment. (where the first sequence in the set is the
4338 * one that the prediction will be for).
4340 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4342 AlignmentView seqs = null;
4344 if ((viewport.getSelectionGroup() != null)
4345 && (viewport.getSelectionGroup().getSize() > 0))
4347 seqs = viewport.getAlignmentView(true);
4351 seqs = viewport.getAlignmentView(false);
4353 // limit sequences - JBPNote in future - could spawn multiple prediction
4355 // TODO: viewport.getAlignment().isAligned is a global state - the local
4356 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4357 if (!viewport.getAlignment().isAligned(false))
4359 seqs.setSequences(new SeqCigar[]
4360 { seqs.getSequences()[0] });
4361 // TODO: if seqs.getSequences().length>1 then should really have warned
4375 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4377 // Pick the tree file
4378 JalviewFileChooser chooser = new JalviewFileChooser(
4379 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4380 chooser.setFileView(new JalviewFileView());
4381 chooser.setDialogTitle(MessageManager
4382 .getString("label.select_newick_like_tree_file"));
4383 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4385 int value = chooser.showOpenDialog(null);
4387 if (value == JalviewFileChooser.APPROVE_OPTION)
4389 String choice = chooser.getSelectedFile().getPath();
4390 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4391 jalview.io.NewickFile fin = null;
4394 fin = new jalview.io.NewickFile(choice, "File");
4395 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4396 } catch (Exception ex)
4403 .getString("label.problem_reading_tree_file"),
4404 JOptionPane.WARNING_MESSAGE);
4405 ex.printStackTrace();
4407 if (fin != null && fin.hasWarningMessage())
4409 JOptionPane.showMessageDialog(Desktop.desktop, fin
4410 .getWarningMessage(), MessageManager
4411 .getString("label.possible_problem_with_tree_file"),
4412 JOptionPane.WARNING_MESSAGE);
4418 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4420 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4423 public TreePanel ShowNewickTree(NewickFile nf, String title)
4425 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4428 public TreePanel ShowNewickTree(NewickFile nf, String title,
4429 AlignmentView input)
4431 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4434 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4435 int h, int x, int y)
4437 return ShowNewickTree(nf, title, null, w, h, x, y);
4441 * Add a treeviewer for the tree extracted from a newick file object to the
4442 * current alignment view
4449 * Associated alignment input data (or null)
4458 * @return TreePanel handle
4460 public TreePanel ShowNewickTree(NewickFile nf, String title,
4461 AlignmentView input, int w, int h, int x, int y)
4463 TreePanel tp = null;
4469 if (nf.getTree() != null)
4471 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4477 tp.setLocation(x, y);
4480 Desktop.addInternalFrame(tp, title, w, h);
4482 } catch (Exception ex)
4484 ex.printStackTrace();
4490 private boolean buildingMenu = false;
4493 * Generates menu items and listener event actions for web service clients
4496 public void BuildWebServiceMenu()
4498 while (buildingMenu)
4502 System.err.println("Waiting for building menu to finish.");
4504 } catch (Exception e)
4508 final AlignFrame me = this;
4509 buildingMenu = true;
4510 new Thread(new Runnable()
4515 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4518 System.err.println("Building ws menu again "
4519 + Thread.currentThread());
4520 // TODO: add support for context dependent disabling of services based
4522 // alignment and current selection
4523 // TODO: add additional serviceHandle parameter to specify abstract
4525 // class independently of AbstractName
4526 // TODO: add in rediscovery GUI function to restart discoverer
4527 // TODO: group services by location as well as function and/or
4529 // object broker mechanism.
4530 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4531 final IProgressIndicator af = me;
4532 final JMenu msawsmenu = new JMenu("Alignment");
4533 final JMenu secstrmenu = new JMenu(
4534 "Secondary Structure Prediction");
4535 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4536 final JMenu analymenu = new JMenu("Analysis");
4537 final JMenu dismenu = new JMenu("Protein Disorder");
4538 // final JMenu msawsmenu = new
4539 // JMenu(MessageManager.getString("label.alignment"));
4540 // final JMenu secstrmenu = new
4541 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4542 // final JMenu seqsrchmenu = new
4543 // JMenu(MessageManager.getString("label.sequence_database_search"));
4544 // final JMenu analymenu = new
4545 // JMenu(MessageManager.getString("label.analysis"));
4546 // final JMenu dismenu = new
4547 // JMenu(MessageManager.getString("label.protein_disorder"));
4548 // JAL-940 - only show secondary structure prediction services from
4549 // the legacy server
4550 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4552 Discoverer.services != null && (Discoverer.services.size() > 0))
4554 // TODO: refactor to allow list of AbstractName/Handler bindings to
4556 // stored or retrieved from elsewhere
4557 // No MSAWS used any more:
4558 // Vector msaws = null; // (Vector)
4559 // Discoverer.services.get("MsaWS");
4560 Vector secstrpr = (Vector) Discoverer.services
4562 if (secstrpr != null)
4564 // Add any secondary structure prediction services
4565 for (int i = 0, j = secstrpr.size(); i < j; i++)
4567 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4569 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4570 .getServiceClient(sh);
4571 int p = secstrmenu.getItemCount();
4572 impl.attachWSMenuEntry(secstrmenu, me);
4573 int q = secstrmenu.getItemCount();
4574 for (int litm = p; litm < q; litm++)
4576 legacyItems.add(secstrmenu.getItem(litm));
4582 // Add all submenus in the order they should appear on the web
4584 wsmenu.add(msawsmenu);
4585 wsmenu.add(secstrmenu);
4586 wsmenu.add(dismenu);
4587 wsmenu.add(analymenu);
4588 // No search services yet
4589 // wsmenu.add(seqsrchmenu);
4591 javax.swing.SwingUtilities.invokeLater(new Runnable()
4598 webService.removeAll();
4599 // first, add discovered services onto the webservices menu
4600 if (wsmenu.size() > 0)
4602 for (int i = 0, j = wsmenu.size(); i < j; i++)
4604 webService.add(wsmenu.get(i));
4609 webService.add(me.webServiceNoServices);
4611 // TODO: move into separate menu builder class.
4612 boolean new_sspred = false;
4613 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4615 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4616 if (jws2servs != null)
4618 if (jws2servs.hasServices())
4620 jws2servs.attachWSMenuEntry(webService, me);
4621 for (Jws2Instance sv : jws2servs.getServices())
4623 if (sv.description.toLowerCase().contains("jpred"))
4625 for (JMenuItem jmi : legacyItems)
4627 jmi.setVisible(false);
4633 if (jws2servs.isRunning())
4635 JMenuItem tm = new JMenuItem(
4636 "Still discovering JABA Services");
4637 tm.setEnabled(false);
4642 build_urlServiceMenu(me.webService);
4643 build_fetchdbmenu(webService);
4644 for (JMenu item : wsmenu)
4646 if (item.getItemCount() == 0)
4648 item.setEnabled(false);
4652 item.setEnabled(true);
4655 } catch (Exception e)
4658 .debug("Exception during web service menu building process.",
4663 } catch (Exception e)
4666 buildingMenu = false;
4673 * construct any groupURL type service menu entries.
4677 private void build_urlServiceMenu(JMenu webService)
4679 // TODO: remove this code when 2.7 is released
4680 // DEBUG - alignmentView
4682 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4683 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4685 * @Override public void actionPerformed(ActionEvent e) {
4686 * jalview.datamodel.AlignmentView
4687 * .testSelectionViews(af.viewport.getAlignment(),
4688 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4690 * }); webService.add(testAlView);
4692 // TODO: refactor to RestClient discoverer and merge menu entries for
4693 // rest-style services with other types of analysis/calculation service
4694 // SHmmr test client - still being implemented.
4695 // DEBUG - alignmentView
4697 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4700 client.attachWSMenuEntry(
4701 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4707 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4708 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4709 * getProperty("LAST_DIRECTORY"));
4711 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4712 * to Vamsas file"); chooser.setToolTipText("Export");
4714 * int value = chooser.showSaveDialog(this);
4716 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4717 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4718 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4719 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4722 * prototype of an automatically enabled/disabled analysis function
4725 protected void setShowProductsEnabled()
4727 SequenceI[] selection = viewport.getSequenceSelection();
4728 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4729 viewport.getAlignment().getDataset()))
4731 showProducts.setEnabled(true);
4736 showProducts.setEnabled(false);
4741 * search selection for sequence xRef products and build the show products
4746 * @return true if showProducts menu should be enabled.
4748 public boolean canShowProducts(SequenceI[] selection,
4749 boolean isRegionSelection, Alignment dataset)
4751 boolean showp = false;
4754 showProducts.removeAll();
4755 final boolean dna = viewport.getAlignment().isNucleotide();
4756 final Alignment ds = dataset;
4757 String[] ptypes = (selection == null || selection.length == 0) ? null
4758 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4760 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4761 // selection, dataset, true);
4762 final SequenceI[] sel = selection;
4763 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4766 final boolean isRegSel = isRegionSelection;
4767 final AlignFrame af = this;
4768 final String source = ptypes[t];
4769 JMenuItem xtype = new JMenuItem(ptypes[t]);
4770 xtype.addActionListener(new ActionListener()
4774 public void actionPerformed(ActionEvent e)
4776 // TODO: new thread for this call with vis-delay
4777 af.showProductsFor(af.viewport.getSequenceSelection(),
4778 isRegSel, dna, source);
4782 showProducts.add(xtype);
4784 showProducts.setVisible(showp);
4785 showProducts.setEnabled(showp);
4786 } catch (Exception e)
4788 jalview.bin.Cache.log
4789 .warn("canTranslate threw an exception - please report to help@jalview.org",
4796 protected void showProductsFor(final SequenceI[] sel,
4797 final boolean isRegSel, final boolean dna, final String source)
4799 Runnable foo = new Runnable()
4805 final long sttime = System.currentTimeMillis();
4806 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4807 "status.searching_for_sequences_from", new Object[]
4808 { source }), sttime);
4811 // update our local dataset reference
4812 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4814 Alignment prods = CrossRef
4815 .findXrefSequences(sel, dna, source, ds);
4818 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4819 for (int s = 0; s < sprods.length; s++)
4821 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4822 if (ds.getSequences() == null
4823 || !ds.getSequences().contains(
4824 sprods[s].getDatasetSequence()))
4826 ds.addSequence(sprods[s].getDatasetSequence());
4828 sprods[s].updatePDBIds();
4830 Alignment al = new Alignment(sprods);
4834 * Copy dna-to-protein mappings to new alignment
4836 // TODO 1: no mappings are set up for EMBL product
4837 // TODO 2: if they were, should add them to protein alignment, not
4839 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4840 for (AlignedCodonFrame acf : cf)
4842 al.addCodonFrame(acf);
4844 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4846 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4847 + " for " + ((isRegSel) ? "selected region of " : "")
4849 naf.setTitle(newtitle);
4851 // temporary flag until SplitFrame is released
4852 boolean asSplitFrame = Cache.getDefault(
4853 Preferences.ENABLE_SPLIT_FRAME, false);
4857 * Make a copy of this alignment (sharing the same dataset
4858 * sequences). If we are DNA, drop introns and update mappings
4860 AlignmentI copyAlignment = null;
4861 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4862 .getSequenceSelection();
4865 copyAlignment = AlignmentUtils.makeExonAlignment(
4866 sequenceSelection, cf);
4867 al.getCodonFrames().clear();
4868 al.getCodonFrames().addAll(cf);
4869 final StructureSelectionManager ssm = StructureSelectionManager
4870 .getStructureSelectionManager(Desktop.instance);
4871 ssm.addMappings(cf);
4875 copyAlignment = new Alignment(new Alignment(
4876 sequenceSelection));
4878 AlignFrame copyThis = new AlignFrame(copyAlignment,
4879 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4880 copyThis.setTitle(AlignFrame.this.getTitle());
4881 // SplitFrame with dna above, protein below
4882 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4883 dna ? naf : copyThis);
4884 naf.setVisible(true);
4885 copyThis.setVisible(true);
4886 String linkedTitle = MessageManager
4887 .getString("label.linked_view_title");
4888 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4892 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4898 System.err.println("No Sequences generated for xRef type "
4901 } catch (Exception e)
4903 jalview.bin.Cache.log.error(
4904 "Exception when finding crossreferences", e);
4905 } catch (OutOfMemoryError e)
4907 new OOMWarning("whilst fetching crossreferences", e);
4910 jalview.bin.Cache.log.error("Error when finding crossreferences",
4913 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4914 "status.finished_searching_for_sequences_from",
4921 Thread frunner = new Thread(foo);
4925 public boolean canShowTranslationProducts(SequenceI[] selection,
4926 AlignmentI alignment)
4931 return (jalview.analysis.Dna.canTranslate(selection,
4932 viewport.getViewAsVisibleContigs(true)));
4933 } catch (Exception e)
4935 jalview.bin.Cache.log
4936 .warn("canTranslate threw an exception - please report to help@jalview.org",
4943 * Construct and display a new frame containing the translation of this
4944 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4947 public void showTranslation_actionPerformed(ActionEvent e)
4949 AlignmentI al = null;
4952 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4954 al = dna.translateCdna();
4955 } catch (Exception ex)
4957 jalview.bin.Cache.log.error(
4958 "Exception during translation. Please report this !", ex);
4959 final String msg = MessageManager
4960 .getString("label.error_when_translating_sequences_submit_bug_report");
4961 final String title = MessageManager
4962 .getString("label.implementation_error")
4963 + MessageManager.getString("translation_failed");
4964 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4965 JOptionPane.ERROR_MESSAGE);
4968 if (al == null || al.getHeight() == 0)
4970 final String msg = MessageManager
4971 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4972 final String title = MessageManager
4973 .getString("label.translation_failed");
4974 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4975 JOptionPane.WARNING_MESSAGE);
4979 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4980 af.setFileFormat(this.currentFileFormat);
4981 final String newTitle = MessageManager.formatMessage(
4982 "label.translation_of_params", new Object[]
4983 { this.getTitle() });
4984 af.setTitle(newTitle);
4985 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
4987 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4988 viewport.openSplitFrame(af, new Alignment(seqs),
4989 al.getCodonFrames());
4993 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
5000 * Set the file format
5004 public void setFileFormat(String fileFormat)
5006 this.currentFileFormat = fileFormat;
5010 * Try to load a features file onto the alignment.
5013 * contents or path to retrieve file
5015 * access mode of file (see jalview.io.AlignFile)
5016 * @return true if features file was parsed correctly.
5018 public boolean parseFeaturesFile(String file, String type)
5020 return avc.parseFeaturesFile(file, type,
5021 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5026 public void refreshFeatureUI(boolean enableIfNecessary)
5028 // note - currently this is only still here rather than in the controller
5029 // because of the featureSettings hard reference that is yet to be
5031 if (enableIfNecessary)
5033 viewport.setShowSequenceFeatures(true);
5034 showSeqFeatures.setSelected(true);
5040 public void dragEnter(DropTargetDragEvent evt)
5045 public void dragExit(DropTargetEvent evt)
5050 public void dragOver(DropTargetDragEvent evt)
5055 public void dropActionChanged(DropTargetDragEvent evt)
5060 public void drop(DropTargetDropEvent evt)
5062 Transferable t = evt.getTransferable();
5063 java.util.List files = null;
5067 DataFlavor uriListFlavor = new DataFlavor(
5068 "text/uri-list;class=java.lang.String");
5069 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5071 // Works on Windows and MacOSX
5072 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5073 files = (java.util.List) t
5074 .getTransferData(DataFlavor.javaFileListFlavor);
5076 else if (t.isDataFlavorSupported(uriListFlavor))
5078 // This is used by Unix drag system
5079 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5080 String data = (String) t.getTransferData(uriListFlavor);
5081 files = new java.util.ArrayList(1);
5082 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5083 data, "\r\n"); st.hasMoreTokens();)
5085 String s = st.nextToken();
5086 if (s.startsWith("#"))
5088 // the line is a comment (as per the RFC 2483)
5092 java.net.URI uri = new java.net.URI(s);
5093 // check to see if we can handle this kind of URI
5094 if (uri.getScheme().toLowerCase().startsWith("http"))
5096 files.add(uri.toString());
5100 // otherwise preserve old behaviour: catch all for file objects
5101 java.io.File file = new java.io.File(uri);
5102 files.add(file.toString());
5106 } catch (Exception e)
5108 e.printStackTrace();
5114 // check to see if any of these files have names matching sequences in
5116 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5117 .getAlignment().getSequencesArray());
5119 * Object[] { String,SequenceI}
5121 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5122 ArrayList<String> filesnotmatched = new ArrayList<String>();
5123 for (int i = 0; i < files.size(); i++)
5125 String file = files.get(i).toString();
5127 String protocol = FormatAdapter.checkProtocol(file);
5128 if (protocol == jalview.io.FormatAdapter.FILE)
5130 File fl = new File(file);
5131 pdbfn = fl.getName();
5133 else if (protocol == jalview.io.FormatAdapter.URL)
5135 URL url = new URL(file);
5136 pdbfn = url.getFile();
5138 if (pdbfn.length() > 0)
5140 // attempt to find a match in the alignment
5141 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5142 int l = 0, c = pdbfn.indexOf(".");
5143 while (mtch == null && c != -1)
5148 } while ((c = pdbfn.indexOf(".", l)) > l);
5151 pdbfn = pdbfn.substring(0, l);
5153 mtch = idm.findAllIdMatches(pdbfn);
5160 type = new IdentifyFile().Identify(file, protocol);
5161 } catch (Exception ex)
5167 if (type.equalsIgnoreCase("PDB"))
5169 filesmatched.add(new Object[]
5170 { file, protocol, mtch });
5175 // File wasn't named like one of the sequences or wasn't a PDB file.
5176 filesnotmatched.add(file);
5180 if (filesmatched.size() > 0)
5182 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5188 "label.automatically_associate_pdb_files_with_sequences_same_name",
5195 .getString("label.automatically_associate_pdb_files_by_name"),
5196 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5199 for (Object[] fm : filesmatched)
5201 // try and associate
5202 // TODO: may want to set a standard ID naming formalism for
5203 // associating PDB files which have no IDs.
5204 for (SequenceI toassoc : (SequenceI[]) fm[2])
5206 PDBEntry pe = new AssociatePdbFileWithSeq()
5207 .associatePdbWithSeq((String) fm[0],
5208 (String) fm[1], toassoc, false,
5212 System.err.println("Associated file : "
5213 + ((String) fm[0]) + " with "
5214 + toassoc.getDisplayId(true));
5218 alignPanel.paintAlignment(true);
5222 if (filesnotmatched.size() > 0)
5225 && (Cache.getDefault(
5226 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5229 "<html>"+MessageManager
5231 "label.ignore_unmatched_dropped_files_info",
5236 .toString() })+"</html>",
5238 .getString("label.ignore_unmatched_dropped_files"),
5239 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5243 for (String fn : filesnotmatched)
5245 loadJalviewDataFile(fn, null, null, null);
5249 } catch (Exception ex)
5251 ex.printStackTrace();
5257 * Attempt to load a "dropped" file or URL string: First by testing whether
5258 * it's and Annotation file, then a JNet file, and finally a features file. If
5259 * all are false then the user may have dropped an alignment file onto this
5263 * either a filename or a URL string.
5265 public void loadJalviewDataFile(String file, String protocol,
5266 String format, SequenceI assocSeq)
5270 if (protocol == null)
5272 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5274 // if the file isn't identified, or not positively identified as some
5275 // other filetype (PFAM is default unidentified alignment file type) then
5276 // try to parse as annotation.
5277 boolean isAnnotation = (format == null || format
5278 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5279 .annotateAlignmentView(viewport, file, protocol)
5284 // first see if its a T-COFFEE score file
5285 TCoffeeScoreFile tcf = null;
5288 tcf = new TCoffeeScoreFile(file, protocol);
5291 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5293 tcoffeeColour.setEnabled(true);
5294 tcoffeeColour.setSelected(true);
5295 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5296 isAnnotation = true;
5298 .setText(MessageManager
5299 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5303 // some problem - if no warning its probable that the ID matching
5304 // process didn't work
5308 tcf.getWarningMessage() == null ? MessageManager
5309 .getString("label.check_file_matches_sequence_ids_alignment")
5310 : tcf.getWarningMessage(),
5312 .getString("label.problem_reading_tcoffee_score_file"),
5313 JOptionPane.WARNING_MESSAGE);
5320 } catch (Exception x)
5323 .debug("Exception when processing data source as T-COFFEE score file",
5329 // try to see if its a JNet 'concise' style annotation file *before*
5331 // try to parse it as a features file
5334 format = new IdentifyFile().Identify(file, protocol);
5336 if (format.equalsIgnoreCase("JnetFile"))
5338 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5340 new JnetAnnotationMaker();
5341 JnetAnnotationMaker.add_annotation(predictions,
5342 viewport.getAlignment(), 0, false);
5343 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5344 viewport.getAlignment().setSeqrep(repseq);
5345 ColumnSelection cs = new ColumnSelection();
5346 cs.hideInsertionsFor(repseq);
5347 viewport.setColumnSelection(cs);
5348 isAnnotation = true;
5353 * if (format.equalsIgnoreCase("PDB")) {
5355 * String pdbfn = ""; // try to match up filename with sequence id
5356 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5357 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5358 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5359 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5360 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5361 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5362 * // attempt to find a match in the alignment SequenceI mtch =
5363 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5364 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5365 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5366 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5367 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5368 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5369 * { System.err.println("Associated file : " + file + " with " +
5370 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5371 * TODO: maybe need to load as normal otherwise return; } }
5373 // try to parse it as a features file
5374 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5375 // if it wasn't a features file then we just treat it as a general
5376 // alignment file to load into the current view.
5379 new FileLoader().LoadFile(viewport, file, protocol, format);
5383 alignPanel.paintAlignment(true);
5391 alignPanel.adjustAnnotationHeight();
5392 viewport.updateSequenceIdColours();
5393 buildSortByAnnotationScoresMenu();
5394 alignPanel.paintAlignment(true);
5396 } catch (Exception ex)
5398 ex.printStackTrace();
5399 } catch (OutOfMemoryError oom)
5404 } catch (Exception x)
5410 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5411 : "using " + protocol + " from " + file)
5413 + (format != null ? "(parsing as '" + format
5414 + "' file)" : ""), oom, Desktop.desktop);
5419 * Method invoked by the ChangeListener on the tabbed pane, in other words
5420 * when a different tabbed pane is selected by the user or programmatically.
5423 public void tabSelectionChanged(int index)
5427 alignPanel = alignPanels.get(index);
5428 viewport = alignPanel.av;
5429 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5430 setMenusFromViewport(viewport);
5434 * If there is a frame linked to this one in a SplitPane, switch it to the
5435 * same view tab index. No infinite recursion of calls should happen, since
5436 * tabSelectionChanged() should not get invoked on setting the selected
5437 * index to an unchanged value. Guard against setting an invalid index
5438 * before the new view peer tab has been created.
5440 final AlignViewportI peer = viewport.getCodingComplement();
5443 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5444 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5446 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5452 * On right mouse click on view tab, prompt for and set new view name.
5455 public void tabbedPane_mousePressed(MouseEvent e)
5457 if (SwingUtilities.isRightMouseButton(e))
5459 String msg = MessageManager.getString("label.enter_view_name");
5460 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5461 JOptionPane.QUESTION_MESSAGE);
5465 viewport.viewName = reply;
5466 // TODO warn if reply is in getExistingViewNames()?
5467 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5472 public AlignViewport getCurrentView()
5478 * Open the dialog for regex description parsing.
5481 protected void extractScores_actionPerformed(ActionEvent e)
5483 ParseProperties pp = new jalview.analysis.ParseProperties(
5484 viewport.getAlignment());
5485 // TODO: verify regex and introduce GUI dialog for version 2.5
5486 // if (pp.getScoresFromDescription("col", "score column ",
5487 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5489 if (pp.getScoresFromDescription("description column",
5490 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5492 buildSortByAnnotationScoresMenu();
5500 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5504 protected void showDbRefs_actionPerformed(ActionEvent e)
5506 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5512 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5516 protected void showNpFeats_actionPerformed(ActionEvent e)
5518 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5522 * find the viewport amongst the tabs in this alignment frame and close that
5527 public boolean closeView(AlignViewportI av)
5531 this.closeMenuItem_actionPerformed(false);
5534 Component[] comp = tabbedPane.getComponents();
5535 for (int i = 0; comp != null && i < comp.length; i++)
5537 if (comp[i] instanceof AlignmentPanel)
5539 if (((AlignmentPanel) comp[i]).av == av)
5542 closeView((AlignmentPanel) comp[i]);
5550 protected void build_fetchdbmenu(JMenu webService)
5552 // Temporary hack - DBRef Fetcher always top level ws entry.
5553 // TODO We probably want to store a sequence database checklist in
5554 // preferences and have checkboxes.. rather than individual sources selected
5556 final JMenu rfetch = new JMenu(
5557 MessageManager.getString("action.fetch_db_references"));
5558 rfetch.setToolTipText(MessageManager
5559 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5560 webService.add(rfetch);
5562 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5563 MessageManager.getString("option.trim_retrieved_seqs"));
5564 trimrs.setToolTipText(MessageManager
5565 .getString("label.trim_retrieved_sequences"));
5566 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5567 trimrs.addActionListener(new ActionListener()
5570 public void actionPerformed(ActionEvent e)
5572 trimrs.setSelected(trimrs.isSelected());
5573 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5574 Boolean.valueOf(trimrs.isSelected()).toString());
5578 JMenuItem fetchr = new JMenuItem(
5579 MessageManager.getString("label.standard_databases"));
5580 fetchr.setToolTipText(MessageManager
5581 .getString("label.fetch_embl_uniprot"));
5582 fetchr.addActionListener(new ActionListener()
5586 public void actionPerformed(ActionEvent e)
5588 new Thread(new Runnable()
5594 new jalview.ws.DBRefFetcher(alignPanel.av
5595 .getSequenceSelection(), alignPanel.alignFrame)
5596 .fetchDBRefs(false);
5604 final AlignFrame me = this;
5605 new Thread(new Runnable()
5610 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5611 .getSequenceFetcherSingleton(me);
5612 javax.swing.SwingUtilities.invokeLater(new Runnable()
5617 String[] dbclasses = sf.getOrderedSupportedSources();
5618 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5619 // jalview.util.QuickSort.sort(otherdb, otherdb);
5620 List<DbSourceProxy> otherdb;
5621 JMenu dfetch = new JMenu();
5622 JMenu ifetch = new JMenu();
5623 JMenuItem fetchr = null;
5624 int comp = 0, icomp = 0, mcomp = 15;
5625 String mname = null;
5627 for (String dbclass : dbclasses)
5629 otherdb = sf.getSourceProxy(dbclass);
5630 // add a single entry for this class, or submenu allowing 'fetch
5632 if (otherdb == null || otherdb.size() < 1)
5636 // List<DbSourceProxy> dbs=otherdb;
5637 // otherdb=new ArrayList<DbSourceProxy>();
5638 // for (DbSourceProxy db:dbs)
5640 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5644 mname = "From " + dbclass;
5646 if (otherdb.size() == 1)
5648 final DbSourceProxy[] dassource = otherdb
5649 .toArray(new DbSourceProxy[0]);
5650 DbSourceProxy src = otherdb.get(0);
5651 fetchr = new JMenuItem(src.getDbSource());
5652 fetchr.addActionListener(new ActionListener()
5656 public void actionPerformed(ActionEvent e)
5658 new Thread(new Runnable()
5664 new jalview.ws.DBRefFetcher(alignPanel.av
5665 .getSequenceSelection(),
5666 alignPanel.alignFrame, dassource)
5667 .fetchDBRefs(false);
5673 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5679 final DbSourceProxy[] dassource = otherdb
5680 .toArray(new DbSourceProxy[0]);
5682 DbSourceProxy src = otherdb.get(0);
5683 fetchr = new JMenuItem(MessageManager.formatMessage(
5684 "label.fetch_all_param", new Object[]
5685 { src.getDbSource() }));
5686 fetchr.addActionListener(new ActionListener()
5689 public void actionPerformed(ActionEvent e)
5691 new Thread(new Runnable()
5697 new jalview.ws.DBRefFetcher(alignPanel.av
5698 .getSequenceSelection(),
5699 alignPanel.alignFrame, dassource)
5700 .fetchDBRefs(false);
5706 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5709 // and then build the rest of the individual menus
5710 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5712 String imname = null;
5714 for (DbSourceProxy sproxy : otherdb)
5716 String dbname = sproxy.getDbName();
5717 String sname = dbname.length() > 5 ? dbname.substring(0,
5718 5) + "..." : dbname;
5719 String msname = dbname.length() > 10 ? dbname.substring(
5720 0, 10) + "..." : dbname;
5723 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5725 fetchr = new JMenuItem(msname);
5726 final DbSourceProxy[] dassrc =
5728 fetchr.addActionListener(new ActionListener()
5732 public void actionPerformed(ActionEvent e)
5734 new Thread(new Runnable()
5740 new jalview.ws.DBRefFetcher(alignPanel.av
5741 .getSequenceSelection(),
5742 alignPanel.alignFrame, dassrc)
5743 .fetchDBRefs(false);
5749 fetchr.setToolTipText("<html>"
5750 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5753 if (++icomp >= mcomp || i == (otherdb.size()))
5755 ifetch.setText(MessageManager.formatMessage(
5756 "label.source_to_target", imname, sname));
5758 ifetch = new JMenu();
5766 if (comp >= mcomp || dbi >= (dbclasses.length))
5768 dfetch.setText(MessageManager.formatMessage(
5769 "label.source_to_target", mname, dbclass));
5771 dfetch = new JMenu();
5784 * Left justify the whole alignment.
5787 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5789 AlignmentI al = viewport.getAlignment();
5791 viewport.firePropertyChange("alignment", null, al);
5795 * Right justify the whole alignment.
5798 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5800 AlignmentI al = viewport.getAlignment();
5802 viewport.firePropertyChange("alignment", null, al);
5805 public void setShowSeqFeatures(boolean b)
5807 showSeqFeatures.setSelected(b);
5808 viewport.setShowSequenceFeatures(b);
5815 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5816 * awt.event.ActionEvent)
5819 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5821 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5822 alignPanel.paintAlignment(true);
5829 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5833 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5835 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5836 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5844 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5845 * .event.ActionEvent)
5848 protected void showGroupConservation_actionPerformed(ActionEvent e)
5850 viewport.setShowGroupConservation(showGroupConservation.getState());
5851 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5858 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5859 * .event.ActionEvent)
5862 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5864 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5865 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5872 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5873 * .event.ActionEvent)
5876 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5878 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5879 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5883 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5885 showSequenceLogo.setState(true);
5886 viewport.setShowSequenceLogo(true);
5887 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5888 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5892 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5894 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5901 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5902 * .event.ActionEvent)
5905 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5907 if (avc.makeGroupsFromSelection())
5909 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5910 alignPanel.updateAnnotation();
5911 alignPanel.paintAlignment(true);
5914 public void clearAlignmentSeqRep()
5916 // TODO refactor alignmentseqrep to controller
5917 if (viewport.getAlignment().hasSeqrep()) {
5918 viewport.getAlignment().setSeqrep(null);
5919 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5920 alignPanel.updateAnnotation();
5921 alignPanel.paintAlignment(true);
5926 protected void createGroup_actionPerformed(ActionEvent e)
5928 if (avc.createGroup())
5930 alignPanel.alignmentChanged();
5935 protected void unGroup_actionPerformed(ActionEvent e)
5939 alignPanel.alignmentChanged();
5944 * make the given alignmentPanel the currently selected tab
5946 * @param alignmentPanel
5948 public void setDisplayedView(AlignmentPanel alignmentPanel)
5950 if (!viewport.getSequenceSetId().equals(
5951 alignmentPanel.av.getSequenceSetId()))
5953 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5955 if (tabbedPane != null
5956 && tabbedPane.getTabCount() > 0
5957 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5958 .getSelectedIndex())
5960 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5965 * Action on selection of menu options to Show or Hide annotations.
5968 * @param forSequences
5969 * update sequence-related annotations
5970 * @param forAlignment
5971 * update non-sequence-related annotations
5974 protected void setAnnotationsVisibility(boolean visible,
5975 boolean forSequences, boolean forAlignment)
5977 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5978 .getAlignmentAnnotation())
5981 * don't display non-positional annotations on an alignment
5983 if (aa.annotations == null)
5987 boolean apply = (aa.sequenceRef == null && forAlignment)
5988 || (aa.sequenceRef != null && forSequences);
5991 aa.visible = visible;
5994 alignPanel.validateAnnotationDimensions(true);
5995 alignPanel.alignmentChanged();
5999 * Store selected annotation sort order for the view and repaint.
6002 protected void sortAnnotations_actionPerformed()
6004 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6006 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6007 alignPanel.paintAlignment(true);
6012 * @return alignment panels in this alignment frame
6014 public List<? extends AlignmentViewPanel> getAlignPanels()
6016 return alignPanels == null ? Arrays.asList(alignPanel)
6021 * Open a new alignment window, with the cDNA associated with this (protein)
6022 * alignment, aligned as is the protein.
6024 protected void viewAsCdna_actionPerformed()
6026 // TODO no longer a menu action - refactor as required
6027 final AlignmentI alignment = getViewport().getAlignment();
6028 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6029 if (mappings == null)
6033 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6034 for (SequenceI aaSeq : alignment.getSequences()) {
6035 for (AlignedCodonFrame acf : mappings) {
6036 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6040 * There is a cDNA mapping for this protein sequence - add to new
6041 * alignment. It will share the same dataset sequence as other mapped
6042 * cDNA (no new mappings need to be created).
6044 final Sequence newSeq = new Sequence(dnaSeq);
6045 newSeq.setDatasetSequence(dnaSeq);
6046 cdnaSeqs.add(newSeq);
6050 if (cdnaSeqs.size() == 0)
6052 // show a warning dialog no mapped cDNA
6055 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6057 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6058 AlignFrame.DEFAULT_HEIGHT);
6059 cdna.alignAs(alignment);
6060 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6062 Desktop.addInternalFrame(alignFrame, newtitle,
6063 AlignFrame.DEFAULT_WIDTH,
6064 AlignFrame.DEFAULT_HEIGHT);
6068 * Set visibility of dna/protein complement view (available when shown in a
6074 protected void showComplement_actionPerformed(boolean show)
6076 SplitContainerI sf = getSplitViewContainer();
6078 sf.setComplementVisible(this, show);
6084 class PrintThread extends Thread
6088 public PrintThread(AlignmentPanel ap)
6093 static PageFormat pf;
6098 PrinterJob printJob = PrinterJob.getPrinterJob();
6102 printJob.setPrintable(ap, pf);
6106 printJob.setPrintable(ap);
6109 if (printJob.printDialog())
6114 } catch (Exception PrintException)
6116 PrintException.printStackTrace();