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.
21 package jalview.appletgui;
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
25 import jalview.analysis.TreeBuilder;
26 import jalview.analysis.scoremodels.PIDModel;
27 import jalview.analysis.scoremodels.ScoreModels;
28 import jalview.api.AlignViewControllerGuiI;
29 import jalview.api.AlignViewControllerI;
30 import jalview.api.AlignViewportI;
31 import jalview.api.FeatureColourI;
32 import jalview.api.FeatureRenderer;
33 import jalview.api.FeatureSettingsControllerI;
34 import jalview.api.SequenceStructureBinding;
35 import jalview.bin.JalviewLite;
36 import jalview.commands.CommandI;
37 import jalview.commands.EditCommand;
38 import jalview.commands.EditCommand.Action;
39 import jalview.commands.OrderCommand;
40 import jalview.commands.RemoveGapColCommand;
41 import jalview.commands.RemoveGapsCommand;
42 import jalview.commands.SlideSequencesCommand;
43 import jalview.commands.TrimRegionCommand;
44 import jalview.datamodel.Alignment;
45 import jalview.datamodel.AlignmentAnnotation;
46 import jalview.datamodel.AlignmentI;
47 import jalview.datamodel.AlignmentOrder;
48 import jalview.datamodel.ColumnSelection;
49 import jalview.datamodel.HiddenColumns;
50 import jalview.datamodel.PDBEntry;
51 import jalview.datamodel.Sequence;
52 import jalview.datamodel.SequenceGroup;
53 import jalview.datamodel.SequenceI;
54 import jalview.io.AnnotationFile;
55 import jalview.io.AppletFormatAdapter;
56 import jalview.io.DataSourceType;
57 import jalview.io.FeaturesFile;
58 import jalview.io.FileFormat;
59 import jalview.io.FileFormatI;
60 import jalview.io.FileFormats;
61 import jalview.io.TCoffeeScoreFile;
62 import jalview.schemes.Blosum62ColourScheme;
63 import jalview.schemes.BuriedColourScheme;
64 import jalview.schemes.ClustalxColourScheme;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.HelixColourScheme;
67 import jalview.schemes.HydrophobicColourScheme;
68 import jalview.schemes.NucleotideColourScheme;
69 import jalview.schemes.PIDColourScheme;
70 import jalview.schemes.PurinePyrimidineColourScheme;
71 import jalview.schemes.RNAHelicesColour;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.ZappoColourScheme;
77 import jalview.structure.StructureSelectionManager;
78 import jalview.structures.models.AAStructureBindingModel;
79 import jalview.util.MappingUtils;
80 import jalview.util.MessageManager;
81 import jalview.viewmodel.AlignmentViewport;
82 import jalview.viewmodel.ViewportRanges;
84 import java.awt.BorderLayout;
85 import java.awt.Canvas;
86 import java.awt.CheckboxMenuItem;
87 import java.awt.Color;
88 import java.awt.FlowLayout;
90 import java.awt.FontMetrics;
91 import java.awt.Frame;
92 import java.awt.Graphics;
93 import java.awt.Label;
95 import java.awt.MenuBar;
96 import java.awt.MenuItem;
97 import java.awt.Panel;
98 import java.awt.event.ActionEvent;
99 import java.awt.event.ActionListener;
100 import java.awt.event.FocusEvent;
101 import java.awt.event.FocusListener;
102 import java.awt.event.ItemEvent;
103 import java.awt.event.ItemListener;
104 import java.awt.event.KeyEvent;
105 import java.awt.event.KeyListener;
106 import java.awt.event.WindowAdapter;
107 import java.awt.event.WindowEvent;
108 import java.io.IOException;
110 import java.net.URLEncoder;
111 import java.util.Arrays;
112 import java.util.Deque;
113 import java.util.HashMap;
114 import java.util.List;
115 import java.util.Map;
116 import java.util.StringTokenizer;
117 import java.util.Vector;
119 import org.jmol.viewer.Viewer;
121 public class AlignFrame extends EmbmenuFrame implements ActionListener,
122 ItemListener, KeyListener, AlignViewControllerGuiI
124 public AlignViewControllerI avc;
126 public AlignmentPanel alignPanel;
128 public AlignViewport viewport;
130 // width and height may be overridden by applet parameters
131 int frameWidth = 700;
133 int frameHeight = 500;
135 String jalviewServletURL;
138 * Flag for showing autocalculated consensus above or below other consensus
141 private boolean showAutoCalculatedAbove;
143 private SequenceAnnotationOrder annotationSortOrder;
146 * Constructor that creates the frame and adds it to the display.
153 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
156 this(al, applet, title, embedded, true);
160 * Constructor that optionally allows the frame to be displayed or only
167 * @param addToDisplay
169 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
170 boolean embedded, boolean addToDisplay)
172 this(al, null, null, applet, title, embedded, addToDisplay);
175 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
176 HiddenColumns hidden, JalviewLite applet, String title,
179 this(al, hiddenSeqs, hidden, applet, title, embedded, true);
182 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
183 HiddenColumns hidden, JalviewLite applet, String title,
184 boolean embedded, boolean addToDisplay)
188 jalviewServletURL = applet.getParameter("APPLICATION_URL");
194 } catch (Exception ex)
196 ex.printStackTrace();
198 // need to get window geometry before we calculate alignment layout
204 param = applet.getParameter("windowWidth");
207 int width = Integer.parseInt(param);
210 param = applet.getParameter("windowHeight");
213 int height = Integer.parseInt(param);
214 frameHeight = height;
216 } catch (Exception ex)
220 viewport = new AlignViewport(al, applet);
222 if (hiddenSeqs != null && hiddenSeqs.length > 0)
224 viewport.hideSequence(hiddenSeqs);
228 viewport.getAlignment().setHiddenColumns(hidden);
230 viewport.setScaleAboveWrapped(scaleAbove.getState());
232 alignPanel = new AlignmentPanel(this, viewport);
233 avc = new jalview.controller.AlignViewController(this, viewport,
235 viewport.updateConservation(alignPanel);
236 viewport.updateConsensus(alignPanel);
238 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
239 followMouseOverFlag.setState(viewport.isFollowHighlight());
240 showGroupConsensus.setState(viewport.isShowGroupConsensus());
241 showGroupConservation.setState(viewport.isShowGroupConservation());
242 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
243 showSequenceLogo.setState(viewport.isShowSequenceLogo());
244 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
245 applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
246 annotationPanelMenuItem.setState(viewport.isShowAnnotation());
247 showAlignmentAnnotations.setEnabled(annotationPanelMenuItem.getState());
248 showSequenceAnnotations.setEnabled(annotationPanelMenuItem.getState());
249 showAlignmentAnnotations.setState(true);
250 showSequenceAnnotations.setState(false);
252 seqLimits.setState(viewport.getShowJVSuffix());
256 String param = applet.getParameter("sortBy");
259 if (param.equalsIgnoreCase("Id"))
261 sortIDMenuItem_actionPerformed();
263 else if (param.equalsIgnoreCase("Pairwise Identity"))
265 sortPairwiseMenuItem_actionPerformed();
267 else if (param.equalsIgnoreCase("Length"))
269 sortLengthMenuItem_actionPerformed();
273 param = applet.getParameter("wrap");
276 if (param.equalsIgnoreCase("true"))
278 wrapMenuItem.setState(true);
279 wrapMenuItem_actionPerformed();
282 param = applet.getParameter("centrecolumnlabels");
285 centreColumnLabelFlag.setState(true);
286 centreColumnLabelFlag_stateChanged();
290 if (viewport.getAlignment().isNucleotide())
292 conservationMenuItem.setEnabled(false);
293 clustalColour.setEnabled(false);
294 BLOSUM62Colour.setEnabled(false);
295 zappoColour.setEnabled(false);
296 taylorColour.setEnabled(false);
297 hydrophobicityColour.setEnabled(false);
298 helixColour.setEnabled(false);
299 strandColour.setEnabled(false);
300 turnColour.setEnabled(false);
301 buriedColour.setEnabled(false);
302 viewport.updateStrucConsensus(alignPanel);
303 if (viewport.getAlignment().hasRNAStructure())
305 RNAHelixColour.setEnabled(true);
309 RNAHelixColour.setEnabled(false);
314 RNAHelixColour.setEnabled(false);
315 purinePyrimidineColour.setEnabled(false);
316 nucleotideColour.setEnabled(false);
318 // Some JVMS send keyevents to Top frame or lowest panel,
319 // Havent worked out why yet. So add to both this frame and seqCanvas for
321 this.addKeyListener(this);
322 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
323 alignPanel.idPanel.idCanvas.addKeyListener(this);
324 alignPanel.scalePanel.addKeyListener(this);
325 alignPanel.annotationPanel.addKeyListener(this);
326 alignPanel.annotationPanelHolder.addKeyListener(this);
327 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
328 alignPanel.alabels.addKeyListener(this);
330 setAnnotationsVisibility();
334 addToDisplay(embedded);
341 public void addToDisplay(boolean embedded)
343 createAlignFrameWindow(embedded);
345 alignPanel.adjustAnnotationHeight();
346 alignPanel.paintAlignment(true);
349 public AlignViewport getAlignViewport()
354 public SeqCanvas getSeqcanvas()
356 return alignPanel.seqPanel.seqCanvas;
360 * Load a features file onto the alignment
363 * file URL, content, or other resolvable path
365 * is protocol for accessing data referred to by file
368 public boolean parseFeaturesFile(String file, DataSourceType type)
370 return parseFeaturesFile(file, type, true);
374 * Load a features file onto the alignment
377 * file URL, content, or other resolvable path
379 * is protocol for accessing data referred to by file
380 * @param autoenabledisplay
381 * when true, display features flag will be automatically enabled if
382 * features are loaded
383 * @return true if data parsed as a features file
385 public boolean parseFeaturesFile(String file, DataSourceType sourceType,
386 boolean autoenabledisplay)
388 boolean featuresFile = false;
391 Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
392 .getFeatureRenderer().getFeatureColours();
393 boolean relaxedIdMatching = viewport.applet
394 .getDefaultParameter("relaxedidmatch", false);
395 featuresFile = new FeaturesFile(file, sourceType).parse(
396 viewport.getAlignment(), colours, true, relaxedIdMatching);
397 } catch (Exception ex)
399 ex.printStackTrace();
404 if (autoenabledisplay)
406 viewport.setShowSequenceFeatures(true);
407 sequenceFeatures.setState(true);
409 if (alignPanel.seqPanel.seqCanvas.fr != null)
411 // update the min/max ranges where necessary
412 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
414 if (viewport.featureSettings != null)
416 viewport.featureSettings.refreshTable();
418 alignPanel.paintAlignment(true);
419 statusBar.setText(MessageManager
420 .getString("label.successfully_added_features_alignment"));
426 public void keyPressed(KeyEvent evt)
428 ViewportRanges ranges = viewport.getRanges();
430 if (viewport.cursorMode
431 && ((evt.getKeyCode() >= KeyEvent.VK_0
432 && evt.getKeyCode() <= KeyEvent.VK_9)
433 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
434 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
435 && Character.isDigit(evt.getKeyChar()))
437 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
440 switch (evt.getKeyCode())
442 case 27: // escape key
443 deselectAllSequenceMenuItem_actionPerformed();
445 alignPanel.alabels.cancelDrag();
448 if (evt.isControlDown() || evt.isMetaDown())
450 cut_actionPerformed();
454 if (viewport.cursorMode && !evt.isControlDown())
456 alignPanel.seqPanel.setCursorColumn();
458 if (evt.isControlDown() || evt.isMetaDown())
460 copy_actionPerformed();
464 if (evt.isControlDown())
466 paste(evt.isShiftDown());
470 if (evt.isControlDown() || evt.isMetaDown())
472 selectAllSequenceMenuItem_actionPerformed();
475 case KeyEvent.VK_DOWN:
476 if (viewport.cursorMode)
478 alignPanel.seqPanel.moveCursor(0, 1);
482 moveSelectedSequences(false);
487 if (viewport.cursorMode)
489 alignPanel.seqPanel.moveCursor(0, -1);
493 moveSelectedSequences(true);
497 case KeyEvent.VK_LEFT:
498 if (evt.isAltDown() || !viewport.cursorMode)
500 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
504 alignPanel.seqPanel.moveCursor(-1, 0);
508 case KeyEvent.VK_RIGHT:
509 if (evt.isAltDown() || !viewport.cursorMode)
511 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
515 alignPanel.seqPanel.moveCursor(1, 0);
519 case KeyEvent.VK_SPACE:
520 if (viewport.cursorMode)
522 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
523 || evt.isShiftDown() || evt.isAltDown());
527 case KeyEvent.VK_DELETE:
528 case KeyEvent.VK_BACK_SPACE:
529 if (viewport.cursorMode)
531 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
532 || evt.isShiftDown() || evt.isAltDown());
536 cut_actionPerformed();
537 alignPanel.seqPanel.seqCanvas.repaint();
542 if (viewport.cursorMode)
544 alignPanel.seqPanel.setCursorRow();
548 if (viewport.cursorMode)
550 alignPanel.seqPanel.setCursorPosition();
554 case KeyEvent.VK_ENTER:
555 case KeyEvent.VK_COMMA:
556 if (viewport.cursorMode)
558 alignPanel.seqPanel.setCursorRowAndColumn();
563 if (viewport.cursorMode)
565 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
569 if (viewport.cursorMode)
571 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
576 viewport.cursorMode = !viewport.cursorMode;
577 statusBar.setText(MessageManager
578 .formatMessage("label.keyboard_editing_mode", new String[]
579 { (viewport.cursorMode ? "on" : "off") }));
580 if (viewport.cursorMode)
582 alignPanel.seqPanel.seqCanvas.cursorX = ranges.getStartRes();
583 alignPanel.seqPanel.seqCanvas.cursorY = ranges.getStartSeq();
588 if (evt.isControlDown())
590 findMenuItem_actionPerformed();
596 boolean toggleSeqs = !evt.isControlDown();
597 boolean toggleCols = !evt.isShiftDown();
598 toggleHiddenRegions(toggleSeqs, toggleCols);
602 case KeyEvent.VK_PAGE_UP:
606 case KeyEvent.VK_PAGE_DOWN:
611 if (evt.isControlDown())
613 undoMenuItem_actionPerformed();
618 if (evt.isControlDown())
620 redoMenuItem_actionPerformed();
625 if (evt.isControlDown())
632 if (evt.isControlDown())
634 trimAlignment(false);
639 if (evt.isControlDown())
641 if (evt.isShiftDown())
643 this.removeAllGapsMenuItem_actionPerformed();
647 removeGappedColumnMenuItem_actionPerformed();
652 if (evt.isControlDown())
656 invertColSel_actionPerformed();
660 invertSequenceMenuItem_actionPerformed();
666 if (evt.isControlDown())
668 if (evt.isShiftDown())
670 this.unGroup_actionPerformed();
674 this.createGroup_actionPerformed();
680 if (evt.isControlDown())
682 this.deleteGroups_actionPerformed();
687 if (evt.isControlDown())
694 alignPanel.paintAlignment(true);
698 * called by key handler and the hide all/show all menu items
703 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
705 boolean hide = false;
706 SequenceGroup sg = viewport.getSelectionGroup();
707 if (!toggleSeqs && !toggleCols)
709 // Hide everything by the current selection - this is a hack - we do the
710 // invert and then hide
711 // first check that there will be visible columns after the invert.
712 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
713 && sg.getStartRes() <= sg.getEndRes()))
715 // now invert the sequence set, if required - empty selection implies
716 // that no hiding is required.
719 invertSequenceMenuItem_actionPerformed();
720 sg = viewport.getSelectionGroup();
724 viewport.expandColSelection(sg, true);
725 // finally invert the column selection and get the new sequence
726 // selection and indicate it should be hidden.
727 invertColSel_actionPerformed();
734 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
737 viewport.hideAllSelectedSeqs();
739 else if (!(toggleCols && viewport.hasSelectedColumns()))
741 viewport.showAllHiddenSeqs();
747 if (viewport.hasSelectedColumns())
749 viewport.hideSelectedColumns();
752 viewport.setSelectionGroup(sg);
757 viewport.showAllHiddenColumns();
759 viewport.sendSelection();
764 public void keyReleased(KeyEvent evt)
769 public void keyTyped(KeyEvent evt)
774 public void itemStateChanged(ItemEvent evt)
776 final Object source = evt.getSource();
777 if (source == displayNonconservedMenuItem)
779 displayNonconservedMenuItem_actionPerformed();
781 else if (source == colourTextMenuItem)
783 colourTextMenuItem_actionPerformed();
785 else if (source == wrapMenuItem)
787 wrapMenuItem_actionPerformed();
789 else if (source == scaleAbove)
791 viewport.setScaleAboveWrapped(scaleAbove.getState());
793 else if (source == scaleLeft)
795 viewport.setScaleLeftWrapped(scaleLeft.getState());
797 else if (source == scaleRight)
799 viewport.setScaleRightWrapped(scaleRight.getState());
801 else if (source == seqLimits)
803 seqLimits_itemStateChanged();
805 else if (source == viewBoxesMenuItem)
807 viewport.setShowBoxes(viewBoxesMenuItem.getState());
809 else if (source == viewTextMenuItem)
811 viewport.setShowText(viewTextMenuItem.getState());
813 else if (source == renderGapsMenuItem)
815 viewport.setRenderGaps(renderGapsMenuItem.getState());
817 else if (source == annotationPanelMenuItem)
819 boolean showAnnotations = annotationPanelMenuItem.getState();
820 showAlignmentAnnotations.setEnabled(showAnnotations);
821 showSequenceAnnotations.setEnabled(showAnnotations);
822 viewport.setShowAnnotation(showAnnotations);
823 alignPanel.setAnnotationVisible(showAnnotations);
825 else if (source == sequenceFeatures)
827 viewport.setShowSequenceFeatures(sequenceFeatures.getState());
828 alignPanel.seqPanel.seqCanvas.repaint();
830 else if (source == showAlignmentAnnotations)
832 setAnnotationsVisibility();
834 else if (source == showSequenceAnnotations)
836 setAnnotationsVisibility();
838 else if (source == sortAnnBySequence)
840 boolean newState = sortAnnBySequence.getState();
841 sortAnnByLabel.setState(false);
842 setAnnotationSortOrder(
843 newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
844 : SequenceAnnotationOrder.NONE);
845 setViewportAnnotationOrder();
847 else if (source == sortAnnByLabel)
849 boolean newState = sortAnnByLabel.getState();
850 sortAnnBySequence.setState(false);
851 setAnnotationSortOrder(
852 newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
853 : SequenceAnnotationOrder.NONE);
854 setViewportAnnotationOrder();
856 else if (source == showAutoFirst)
858 showAutoLast.setState(!showAutoFirst.getState());
859 setShowAutoCalculatedAbove(showAutoFirst.getState());
860 setViewportAnnotationOrder();
862 else if (source == showAutoLast)
864 showAutoFirst.setState(!showAutoLast.getState());
865 setShowAutoCalculatedAbove(showAutoFirst.getState());
866 setViewportAnnotationOrder();
868 else if (source == conservationMenuItem)
870 conservationMenuItem_actionPerformed();
872 else if (source == abovePIDThreshold)
874 abovePIDThreshold_actionPerformed();
876 else if (source == applyToAllGroups)
878 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
880 else if (source == autoCalculate)
882 viewport.autoCalculateConsensus = autoCalculate.getState();
884 else if (source == sortByTree)
886 viewport.sortByTree = sortByTree.getState();
888 else if (source == this.centreColumnLabelFlag)
890 centreColumnLabelFlag_stateChanged();
892 else if (source == this.followMouseOverFlag)
894 mouseOverFlag_stateChanged();
896 else if (source == showGroupConsensus)
898 showGroupConsensus_actionPerformed();
900 else if (source == showGroupConservation)
902 showGroupConservation_actionPerformed();
904 else if (source == showSequenceLogo)
906 showSequenceLogo_actionPerformed();
908 else if (source == normSequenceLogo)
910 normSequenceLogo_actionPerformed();
912 else if (source == showConsensusHistogram)
914 showConsensusHistogram_actionPerformed();
916 else if (source == applyAutoAnnotationSettings)
918 applyAutoAnnotationSettings_actionPerformed();
920 alignPanel.paintAlignment(true);
924 * Set the visibility state of sequence-related and/or alignment-related
925 * annotations depending on checkbox selections, and repaint.
929 private void setAnnotationsVisibility()
931 boolean showForAlignment = showAlignmentAnnotations.getState();
932 boolean showForSequences = showSequenceAnnotations.getState();
933 if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
935 for (AlignmentAnnotation aa : alignPanel.getAlignment()
936 .getAlignmentAnnotation())
938 boolean visible = (aa.sequenceRef == null ? showForAlignment
940 aa.visible = visible;
943 alignPanel.validateAnnotationDimensions(true);
948 private void setAnnotationSortOrder(SequenceAnnotationOrder order)
950 this.annotationSortOrder = order;
954 * Set flags on the viewport that control annotation ordering
956 private void setViewportAnnotationOrder()
958 this.alignPanel.av.setSortAnnotationsBy(this.annotationSortOrder);
960 .setShowAutocalculatedAbove(this.showAutoCalculatedAbove);
963 private void setShowAutoCalculatedAbove(boolean showAbove)
965 this.showAutoCalculatedAbove = showAbove;
968 private void mouseOverFlag_stateChanged()
970 viewport.setFollowHighlight(followMouseOverFlag.getState());
971 // TODO: could kick the scrollTo mechanism to reset view for current
975 private void centreColumnLabelFlag_stateChanged()
977 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
978 this.alignPanel.annotationPanel.repaint();
982 public void actionPerformed(ActionEvent evt)
984 viewport.applet.currentAlignFrame = this;
986 Object source = evt.getSource();
988 if (source == inputText)
990 inputText_actionPerformed();
992 else if (source == loadTree)
994 loadTree_actionPerformed();
996 else if (source == loadApplication)
998 launchFullApplication();
1000 else if (source == loadAnnotations)
1004 else if (source == outputAnnotations)
1006 outputAnnotations(true);
1008 else if (source == outputFeatures)
1010 outputFeatures(true, "Jalview");
1012 else if (source == closeMenuItem)
1014 closeMenuItem_actionPerformed();
1016 else if (source == copy)
1018 copy_actionPerformed();
1020 else if (source == undoMenuItem)
1022 undoMenuItem_actionPerformed();
1024 else if (source == redoMenuItem)
1026 redoMenuItem_actionPerformed();
1028 else if (source == inputText)
1030 inputText_actionPerformed();
1032 else if (source == closeMenuItem)
1034 closeMenuItem_actionPerformed();
1036 else if (source == undoMenuItem)
1038 undoMenuItem_actionPerformed();
1040 else if (source == redoMenuItem)
1042 redoMenuItem_actionPerformed();
1044 else if (source == copy)
1046 copy_actionPerformed();
1048 else if (source == pasteNew)
1050 pasteNew_actionPerformed();
1052 else if (source == pasteThis)
1054 pasteThis_actionPerformed();
1056 else if (source == cut)
1058 cut_actionPerformed();
1060 else if (source == delete)
1062 delete_actionPerformed();
1064 else if (source == createGroup)
1066 createGroup_actionPerformed();
1068 else if (source == unGroup)
1070 unGroup_actionPerformed();
1072 else if (source == grpsFromSelection)
1074 makeGrpsFromSelection_actionPerformed();
1076 else if (source == deleteGroups)
1078 deleteGroups_actionPerformed();
1080 else if (source == selectAllSequenceMenuItem)
1082 selectAllSequenceMenuItem_actionPerformed();
1084 else if (source == deselectAllSequenceMenuItem)
1086 deselectAllSequenceMenuItem_actionPerformed();
1088 else if (source == invertSequenceMenuItem)
1090 invertSequenceMenuItem_actionPerformed();
1091 // uncomment to slave sequence selections in split frame
1092 // viewport.sendSelection();
1094 else if (source == invertColSel)
1096 viewport.invertColumnSelection();
1097 alignPanel.paintAlignment(true);
1098 viewport.sendSelection();
1100 else if (source == remove2LeftMenuItem)
1102 trimAlignment(true);
1104 else if (source == remove2RightMenuItem)
1106 trimAlignment(false);
1108 else if (source == removeGappedColumnMenuItem)
1110 removeGappedColumnMenuItem_actionPerformed();
1112 else if (source == removeAllGapsMenuItem)
1114 removeAllGapsMenuItem_actionPerformed();
1116 else if (source == findMenuItem)
1118 findMenuItem_actionPerformed();
1120 else if (source == font)
1122 new FontChooser(alignPanel);
1124 else if (source == newView)
1128 else if (source == showColumns)
1130 viewport.showAllHiddenColumns();
1131 alignPanel.paintAlignment(true);
1132 viewport.sendSelection();
1134 else if (source == showSeqs)
1136 viewport.showAllHiddenSeqs();
1137 alignPanel.paintAlignment(true);
1138 // uncomment if we want to slave sequence selections in split frame
1139 // viewport.sendSelection();
1141 else if (source == hideColumns)
1143 viewport.hideSelectedColumns();
1144 alignPanel.paintAlignment(true);
1145 viewport.sendSelection();
1147 else if (source == hideSequences
1148 && viewport.getSelectionGroup() != null)
1150 viewport.hideAllSelectedSeqs();
1151 alignPanel.paintAlignment(true);
1152 // uncomment if we want to slave sequence selections in split frame
1153 // viewport.sendSelection();
1155 else if (source == hideAllButSelection)
1157 toggleHiddenRegions(false, false);
1158 alignPanel.paintAlignment(true);
1159 viewport.sendSelection();
1161 else if (source == hideAllSelection)
1163 SequenceGroup sg = viewport.getSelectionGroup();
1164 viewport.expandColSelection(sg, false);
1165 viewport.hideAllSelectedSeqs();
1166 viewport.hideSelectedColumns();
1167 alignPanel.paintAlignment(true);
1168 viewport.sendSelection();
1170 else if (source == showAllHidden)
1172 viewport.showAllHiddenColumns();
1173 viewport.showAllHiddenSeqs();
1174 alignPanel.paintAlignment(true);
1175 viewport.sendSelection();
1177 else if (source == showGroupConsensus)
1179 showGroupConsensus_actionPerformed();
1181 else if (source == showGroupConservation)
1183 showGroupConservation_actionPerformed();
1185 else if (source == showSequenceLogo)
1187 showSequenceLogo_actionPerformed();
1189 else if (source == normSequenceLogo)
1191 normSequenceLogo_actionPerformed();
1193 else if (source == showConsensusHistogram)
1195 showConsensusHistogram_actionPerformed();
1197 else if (source == applyAutoAnnotationSettings)
1199 applyAutoAnnotationSettings_actionPerformed();
1201 else if (source == featureSettings)
1203 new FeatureSettings(alignPanel);
1205 else if (source == alProperties)
1207 StringBuffer contents = new jalview.io.AlignmentProperties(
1208 viewport.getAlignment()).formatAsString();
1209 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1210 cap.setText(contents.toString());
1211 Frame frame = new Frame();
1213 jalview.bin.JalviewLite.addFrame(frame, MessageManager
1214 .formatMessage("label.alignment_properties", new String[]
1215 { getTitle() }), 400, 250);
1217 else if (source == overviewMenuItem)
1219 overviewMenuItem_actionPerformed();
1221 else if (source == noColourmenuItem)
1225 else if (source == clustalColour)
1227 abovePIDThreshold.setState(false);
1228 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1230 else if (source == zappoColour)
1232 changeColour(new ZappoColourScheme());
1234 else if (source == taylorColour)
1236 changeColour(new TaylorColourScheme());
1238 else if (source == hydrophobicityColour)
1240 changeColour(new HydrophobicColourScheme());
1242 else if (source == helixColour)
1244 changeColour(new HelixColourScheme());
1246 else if (source == strandColour)
1248 changeColour(new StrandColourScheme());
1250 else if (source == turnColour)
1252 changeColour(new TurnColourScheme());
1254 else if (source == buriedColour)
1256 changeColour(new BuriedColourScheme());
1258 else if (source == nucleotideColour)
1260 changeColour(new NucleotideColourScheme());
1262 else if (source == purinePyrimidineColour)
1264 changeColour(new PurinePyrimidineColourScheme());
1266 // else if (source == RNAInteractionColour)
1268 // changeColour(new RNAInteractionColourScheme());
1270 else if (source == RNAHelixColour)
1272 changeColour(new RNAHelicesColour(viewport.getAlignment()));
1273 // new RNAHelicesColourChooser(viewport, alignPanel);
1275 else if (source == modifyPID)
1277 modifyPID_actionPerformed();
1279 else if (source == modifyConservation)
1281 modifyConservation_actionPerformed();
1283 else if (source == userDefinedColour)
1285 new UserDefinedColours(alignPanel, null);
1287 else if (source == PIDColour)
1289 changeColour(new PIDColourScheme());
1291 else if (source == BLOSUM62Colour)
1293 changeColour(new Blosum62ColourScheme());
1295 else if (source == tcoffeeColour)
1297 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1299 else if (source == annotationColour)
1301 new AnnotationColourChooser(viewport, alignPanel);
1303 else if (source == annotationColumnSelection)
1305 new AnnotationColumnChooser(viewport, alignPanel);
1307 else if (source == sortPairwiseMenuItem)
1309 sortPairwiseMenuItem_actionPerformed();
1311 else if (source == sortIDMenuItem)
1313 sortIDMenuItem_actionPerformed();
1315 else if (source == sortLengthMenuItem)
1317 sortLengthMenuItem_actionPerformed();
1319 else if (source == sortGroupMenuItem)
1321 sortGroupMenuItem_actionPerformed();
1323 else if (source == removeRedundancyMenuItem)
1325 removeRedundancyMenuItem_actionPerformed();
1327 else if (source == pairwiseAlignmentMenuItem)
1329 pairwiseAlignmentMenuItem_actionPerformed();
1331 else if (source == PCAMenuItem)
1333 PCAMenuItem_actionPerformed();
1335 else if (source == averageDistanceTreeMenuItem)
1337 averageDistanceTreeMenuItem_actionPerformed();
1339 else if (source == neighbourTreeMenuItem)
1341 neighbourTreeMenuItem_actionPerformed();
1343 else if (source == njTreeBlosumMenuItem)
1345 njTreeBlosumMenuItem_actionPerformed();
1347 else if (source == avDistanceTreeBlosumMenuItem)
1349 avTreeBlosumMenuItem_actionPerformed();
1351 else if (source == documentation)
1353 documentation_actionPerformed();
1355 else if (source == about)
1357 about_actionPerformed();
1362 public void inputText_actionPerformed()
1364 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1365 Frame frame = new Frame();
1367 jalview.bin.JalviewLite.addFrame(frame,
1368 MessageManager.getString("label.input_cut_paste"), 500, 500);
1371 protected void outputText_actionPerformed(ActionEvent e)
1373 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1374 Frame frame = new Frame();
1376 JalviewLite.addFrame(frame, MessageManager
1377 .formatMessage("label.alignment_output_command", new Object[]
1378 { e.getActionCommand() }), 600, 500);
1380 FileFormatI fileFormat = FileFormats.getInstance()
1381 .forName(e.getActionCommand());
1383 new AppletFormatAdapter(alignPanel).formatSequences(fileFormat,
1384 viewport.getAlignment(), viewport.getShowJVSuffix()));
1387 public void loadAnnotations()
1389 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1390 cap.setText(MessageManager
1391 .getString("label.paste_features_annotations_Tcoffee_here"));
1392 cap.setAnnotationImport();
1393 Frame frame = new Frame();
1395 jalview.bin.JalviewLite.addFrame(frame,
1396 MessageManager.getString("action.paste_annotations"), 400, 300);
1400 public String outputAnnotations(boolean displayTextbox)
1402 String annotation = new AnnotationFile()
1403 .printAnnotationsForView(viewport);
1407 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1408 Frame frame = new Frame();
1410 jalview.bin.JalviewLite.addFrame(frame,
1411 MessageManager.getString("label.annotations"), 600, 500);
1412 cap.setText(annotation);
1418 private Map<String, FeatureColourI> getDisplayedFeatureCols()
1420 if (alignPanel.getFeatureRenderer() != null
1421 && viewport.getFeaturesDisplayed() != null)
1423 return alignPanel.getFeatureRenderer().getDisplayedFeatureCols();
1429 private List<String> getDisplayedFeatureGroups()
1431 if (alignPanel.getFeatureRenderer() != null
1432 && viewport.getFeaturesDisplayed() != null)
1434 return alignPanel.getFeatureRenderer().getDisplayedFeatureGroups();
1440 public String outputFeatures(boolean displayTextbox, String format)
1443 FeaturesFile formatter = new FeaturesFile();
1444 if (format.equalsIgnoreCase("Jalview"))
1446 features = formatter.printJalviewFormat(viewport.getAlignment()
1447 .getSequencesArray(), getDisplayedFeatureCols(),
1448 getDisplayedFeatureGroups(), true);
1452 features = formatter.printGffFormat(viewport.getAlignment()
1453 .getSequencesArray(), getDisplayedFeatureCols(),
1454 getDisplayedFeatureGroups(), true);
1459 boolean frimport = false;
1460 if (features == null || features.equals("No Features Visible"))
1462 features = "# No features visible - paste some and import them here.";
1466 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1469 cap.setAnnotationImport();
1471 Frame frame = new Frame();
1473 jalview.bin.JalviewLite.addFrame(frame,
1474 MessageManager.getString("label.features"), 600, 500);
1475 cap.setText(features);
1479 if (features == null)
1488 void launchFullApplication()
1490 StringBuffer url = new StringBuffer(jalviewServletURL);
1492 // allow servlet parameters to be passed in applet parameter
1493 String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
1495 url.append(firstSep);
1498 "open=" + appendProtocol(viewport.applet.getParameter("file")));
1500 if (viewport.applet.getParameter("features") != null)
1502 url.append("&features=");
1503 url.append(appendProtocol(viewport.applet.getParameter("features")));
1506 if (viewport.applet.getParameter("annotations") != null)
1508 url.append("&annotations=");
1510 appendProtocol(viewport.applet.getParameter("annotations")));
1513 if (viewport.applet.getParameter("jnetfile") != null
1514 || viewport.applet.getParameter("jpredfile") != null)
1516 url.append("&annotations=");
1517 url.append(appendProtocol(
1518 viewport.applet.getParameter("jnetfile") != null
1519 ? viewport.applet.getParameter("jnetfile")
1520 : viewport.applet.getParameter("jpredfile")));
1523 if (viewport.applet.getParameter("defaultColour") != null)
1525 url.append("&colour=" + removeWhiteSpace(
1526 viewport.applet.getParameter("defaultColour")));
1529 if (viewport.applet.getParameter("userDefinedColour") != null)
1531 url.append("&colour=" + removeWhiteSpace(
1532 viewport.applet.getParameter("userDefinedColour")));
1534 if (viewport.applet.getParameter("tree") != null)
1537 + appendProtocol(viewport.applet.getParameter("tree")));
1539 if (viewport.applet.getParameter("treeFile") != null)
1542 + appendProtocol(viewport.applet.getParameter("treeFile")));
1545 showURL(url.toString(), "FULL_APP");
1548 String removeWhiteSpace(String colour)
1550 StringBuffer sb = new StringBuffer();
1551 for (int i = 0; i < colour.length(); i++)
1553 if (Character.isWhitespace(colour.charAt(i)))
1559 sb.append(colour.charAt(i));
1563 return sb.toString();
1566 String appendProtocol(String url)
1571 url = URLEncoder.encode(url);
1574 * When we finally deprecate 1.1 compatibility, we can start to use
1575 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1576 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1577 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1578 * ex.printStackTrace(); }
1580 catch (java.net.MalformedURLException ex)
1582 url = viewport.applet.getCodeBase() + url;
1587 public void closeMenuItem_actionPerformed()
1589 PaintRefresher.RemoveComponent(alignPanel);
1590 if (alignPanel.seqPanel != null
1591 && alignPanel.seqPanel.seqCanvas != null)
1593 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1595 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1597 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1600 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1615 void updateEditMenuBar()
1618 if (viewport.getHistoryList().size() > 0)
1620 undoMenuItem.setEnabled(true);
1621 CommandI command = viewport.getHistoryList().peek();
1622 undoMenuItem.setLabel(MessageManager
1623 .formatMessage("label.undo_command", new Object[]
1624 { command.getDescription() }));
1628 undoMenuItem.setEnabled(false);
1629 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1632 if (viewport.getRedoList().size() > 0)
1634 redoMenuItem.setEnabled(true);
1636 CommandI command = viewport.getRedoList().peek();
1637 redoMenuItem.setLabel(MessageManager
1638 .formatMessage("label.redo_command", new Object[]
1639 { command.getDescription() }));
1643 redoMenuItem.setEnabled(false);
1644 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1652 public void addHistoryItem(CommandI command)
1654 if (command.getSize() > 0)
1656 viewport.addToHistoryList(command);
1657 viewport.clearRedoList();
1658 updateEditMenuBar();
1659 viewport.updateHiddenColumns();
1664 * TODO: JAL-1104 DOCUMENT ME!
1669 protected void undoMenuItem_actionPerformed()
1671 if (viewport.getHistoryList().isEmpty())
1676 CommandI command = viewport.getHistoryList().pop();
1677 viewport.addToRedoList(command);
1678 command.undoCommand(null);
1680 AlignmentViewport originalSource = getOriginatingSource(command);
1682 if (originalSource != viewport)
1685 .println("Warning: Viewport object mismatch whilst undoing");
1687 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1688 // viewport.getColumnSelection().getHiddenColumns()
1690 updateEditMenuBar();
1691 originalSource.firePropertyChange("alignment", null,
1692 originalSource.getAlignment().getSequences());
1696 * TODO: JAL-1104 DOCUMENT ME!
1701 protected void redoMenuItem_actionPerformed()
1703 if (viewport.getRedoList().isEmpty())
1708 CommandI command = viewport.getRedoList().pop();
1709 viewport.addToHistoryList(command);
1710 command.doCommand(null);
1712 AlignmentViewport originalSource = getOriginatingSource(command);
1714 if (originalSource != viewport)
1717 .println("Warning: Viewport object mismatch whilst re-doing");
1719 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1720 // viewport.getColumnSelection().getHiddenColumns()
1723 updateEditMenuBar();
1724 originalSource.firePropertyChange("alignment", null,
1725 originalSource.getAlignment().getSequences());
1728 AlignmentViewport getOriginatingSource(CommandI command)
1730 AlignmentViewport originalSource = null;
1731 // For sequence removal and addition, we need to fire
1732 // the property change event FROM the viewport where the
1733 // original alignment was altered
1734 AlignmentI al = null;
1735 if (command instanceof EditCommand)
1737 EditCommand editCommand = (EditCommand) command;
1738 al = editCommand.getAlignment();
1739 Vector comps = PaintRefresher.components
1740 .get(viewport.getSequenceSetId());
1741 for (int i = 0; i < comps.size(); i++)
1743 if (comps.elementAt(i) instanceof AlignmentPanel)
1745 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1747 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1754 if (originalSource == null)
1756 // The original view is closed, we must validate
1757 // the current view against the closed view first
1760 PaintRefresher.validateSequences(al, viewport.getAlignment());
1763 originalSource = viewport;
1766 return originalSource;
1770 * Move the currently selected sequences up or down one position in the
1775 public void moveSelectedSequences(boolean up)
1777 SequenceGroup sg = viewport.getSelectionGroup();
1782 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1783 up ? null : viewport.getHiddenRepSequences(), up);
1784 alignPanel.paintAlignment(true);
1787 * Also move cDNA/protein complement sequences
1789 AlignViewportI complement = viewport.getCodingComplement();
1790 if (complement != null)
1792 SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
1793 viewport, complement);
1794 complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
1795 up ? null : complement.getHiddenRepSequences(), up);
1796 getSplitFrame().getComplement(this).alignPanel.paintAlignment(true);
1800 synchronized void slideSequences(boolean right, int size)
1802 List<SequenceI> sg = new Vector<>();
1803 if (viewport.cursorMode)
1805 sg.add(viewport.getAlignment()
1806 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1808 else if (viewport.getSelectionGroup() != null
1809 && viewport.getSelectionGroup().getSize() != viewport
1810 .getAlignment().getHeight())
1812 sg = viewport.getSelectionGroup()
1813 .getSequences(viewport.getHiddenRepSequences());
1821 Vector<SequenceI> invertGroup = new Vector();
1823 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1825 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1827 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1831 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1833 SequenceI[] seqs2 = invertGroup
1834 .toArray(new SequenceI[invertGroup.size()]);
1835 for (int i = 0; i < invertGroup.size(); i++)
1837 seqs2[i] = invertGroup.elementAt(i);
1840 SlideSequencesCommand ssc;
1843 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1844 viewport.getGapCharacter());
1848 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1849 viewport.getGapCharacter());
1852 int groupAdjustment = 0;
1853 if (ssc.getGapsInsertedBegin() && right)
1855 if (viewport.cursorMode)
1857 alignPanel.seqPanel.moveCursor(size, 0);
1861 groupAdjustment = size;
1864 else if (!ssc.getGapsInsertedBegin() && !right)
1866 if (viewport.cursorMode)
1868 alignPanel.seqPanel.moveCursor(-size, 0);
1872 groupAdjustment = -size;
1876 if (groupAdjustment != 0)
1878 viewport.getSelectionGroup().setStartRes(
1879 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1880 viewport.getSelectionGroup().setEndRes(
1881 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1884 boolean appendHistoryItem = false;
1885 Deque<CommandI> historyList = viewport.getHistoryList();
1886 if (historyList != null && historyList.size() > 0
1887 && historyList.peek() instanceof SlideSequencesCommand)
1889 appendHistoryItem = ssc.appendSlideCommand(
1890 (SlideSequencesCommand) historyList.peek());
1893 if (!appendHistoryItem)
1895 addHistoryItem(ssc);
1901 static StringBuffer copiedSequences;
1903 static Vector<int[]> copiedHiddenColumns;
1905 protected void copy_actionPerformed()
1907 if (viewport.getSelectionGroup() == null)
1912 SequenceGroup sg = viewport.getSelectionGroup();
1913 copiedSequences = new StringBuffer();
1914 Map<Integer, SequenceI> orderedSeqs = new HashMap<>();
1915 for (int i = 0; i < sg.getSize(); i++)
1917 SequenceI seq = sg.getSequenceAt(i);
1918 int index = viewport.getAlignment().findIndex(seq);
1919 orderedSeqs.put(index, seq);
1922 int index = 0, startRes, endRes;
1925 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1927 copiedHiddenColumns = new Vector<>(viewport.getAlignment()
1928 .getHiddenColumns().getHiddenColumnsCopy());
1929 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1930 for (int[] region : copiedHiddenColumns)
1932 region[0] = region[0] - hiddenOffset;
1933 region[1] = region[1] - hiddenOffset;
1938 copiedHiddenColumns = null;
1941 for (int i = 0; i < sg.getSize(); i++)
1943 SequenceI seq = null;
1947 if (orderedSeqs.containsKey(index))
1949 seq = orderedSeqs.get(index);
1960 // Returns residue following index if gap
1961 startRes = seq.findPosition(sg.getStartRes());
1964 // Need to find the residue preceeding index if gap
1967 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1969 ch = seq.getCharAt(j);
1970 if (!jalview.util.Comparison.isGap((ch)))
1978 endRes += seq.getStart() - 1;
1981 copiedSequences.append(seq.getName() + "\t" + startRes + "\t" + endRes
1982 + "\t" + seq.getSequenceAsString(sg.getStartRes(),
1989 protected void pasteNew_actionPerformed()
1994 protected void pasteThis_actionPerformed()
1999 void paste(boolean newAlignment)
2004 if (copiedSequences == null)
2009 StringTokenizer st = new StringTokenizer(copiedSequences.toString());
2010 Vector seqs = new Vector();
2011 while (st.hasMoreElements())
2013 String name = st.nextToken();
2014 int start = Integer.parseInt(st.nextToken());
2015 int end = Integer.parseInt(st.nextToken());
2016 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
2018 SequenceI[] newSeqs = new SequenceI[seqs.size()];
2019 for (int i = 0; i < seqs.size(); i++)
2021 newSeqs[i] = (SequenceI) seqs.elementAt(i);
2026 String newtitle = MessageManager
2027 .getString("label.copied_sequences");
2028 if (getTitle().startsWith(
2029 MessageManager.getString("label.copied_sequences")))
2031 newtitle = getTitle();
2035 newtitle = newtitle.concat(MessageManager
2036 .formatMessage("label.from_msname", new String[]
2039 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
2040 viewport.applet, newtitle, false);
2041 if (copiedHiddenColumns != null)
2043 for (int i = 0; i < copiedHiddenColumns.size(); i++)
2045 int[] region = copiedHiddenColumns.elementAt(i);
2046 af.viewport.hideColumns(region[0], region[1]);
2050 jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
2055 addSequences(newSeqs);
2058 } catch (Exception ex)
2060 } // could be anything being pasted in here
2064 void addSequences(SequenceI[] seqs)
2066 for (int i = 0; i < seqs.length; i++)
2068 viewport.getAlignment().addSequence(seqs[i]);
2072 addHistoryItem(new EditCommand(
2073 MessageManager.getString("label.add_sequences"), Action.PASTE,
2074 seqs, 0, viewport.getAlignment().getWidth(),
2075 viewport.getAlignment()));
2077 viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight());
2078 viewport.getAlignment().getWidth();
2079 viewport.firePropertyChange("alignment", null,
2080 viewport.getAlignment().getSequences());
2084 protected void cut_actionPerformed()
2086 copy_actionPerformed();
2087 delete_actionPerformed();
2090 protected void delete_actionPerformed()
2093 SequenceGroup sg = viewport.getSelectionGroup();
2099 Vector seqs = new Vector();
2101 for (int i = 0; i < sg.getSize(); i++)
2103 seq = sg.getSequenceAt(i);
2104 seqs.addElement(seq);
2108 * If the cut affects all sequences, warn, remove highlighted columns
2110 if (sg.getSize() == viewport.getAlignment().getHeight())
2112 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
2113 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2114 if (isEntireAlignWidth)
2116 String title = MessageManager.getString("label.delete_all");
2117 Panel infoPanel = new Panel();
2118 infoPanel.setLayout(new FlowLayout());
2120 new Label(MessageManager.getString("warn.delete_all")));
2122 final JVDialog dialog = new JVDialog(this, title, true, 400, 200);
2123 dialog.setMainPanel(infoPanel);
2124 dialog.ok.setLabel(MessageManager.getString("action.ok"));
2125 dialog.cancel.setLabel(MessageManager.getString("action.cancel"));
2126 dialog.setVisible(true);
2133 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2134 sg.getEndRes() + 1);
2137 SequenceI[] cut = new SequenceI[seqs.size()];
2138 for (int i = 0; i < seqs.size(); i++)
2140 cut[i] = (SequenceI) seqs.elementAt(i);
2144 * //ADD HISTORY ITEM
2146 addHistoryItem(new EditCommand(
2147 MessageManager.getString("label.cut_sequences"), Action.CUT,
2148 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2149 viewport.getAlignment()));
2151 viewport.setSelectionGroup(null);
2152 viewport.getAlignment().deleteGroup(sg);
2154 viewport.firePropertyChange("alignment", null,
2155 viewport.getAlignment().getSequences());
2157 if (viewport.getAlignment().getHeight() < 1)
2159 this.setVisible(false);
2161 viewport.sendSelection();
2165 * group consensus toggled
2168 protected void showGroupConsensus_actionPerformed()
2170 viewport.setShowGroupConsensus(showGroupConsensus.getState());
2171 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2176 * group conservation toggled.
2178 protected void showGroupConservation_actionPerformed()
2180 viewport.setShowGroupConservation(showGroupConservation.getState());
2181 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2188 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
2189 * .event.ActionEvent)
2191 protected void showConsensusHistogram_actionPerformed()
2193 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
2194 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2201 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
2202 * .event.ActionEvent)
2204 protected void showSequenceLogo_actionPerformed()
2206 viewport.setShowSequenceLogo(showSequenceLogo.getState());
2207 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2210 protected void normSequenceLogo_actionPerformed()
2212 showSequenceLogo.setState(true);
2213 viewport.setShowSequenceLogo(true);
2214 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
2215 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2218 protected void applyAutoAnnotationSettings_actionPerformed()
2220 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2223 protected void makeGrpsFromSelection_actionPerformed()
2225 if (avc.makeGroupsFromSelection())
2227 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2228 alignPanel.updateAnnotation();
2229 alignPanel.paintAlignment(true);
2233 protected void createGroup_actionPerformed()
2238 protected void unGroup_actionPerformed()
2242 alignPanel.alignmentChanged();
2246 protected void deleteGroups_actionPerformed()
2248 if (avc.deleteGroups())
2250 alignPanel.alignmentChanged();
2254 public void selectAllSequenceMenuItem_actionPerformed()
2256 SequenceGroup sg = new SequenceGroup();
2257 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2259 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2261 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2262 viewport.setSelectionGroup(sg);
2263 // JAL-2034 - should delegate to
2264 // alignPanel to decide if overview needs
2266 alignPanel.paintAlignment(false);
2267 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2268 viewport.sendSelection();
2271 public void deselectAllSequenceMenuItem_actionPerformed()
2273 if (viewport.cursorMode)
2275 alignPanel.seqPanel.keyboardNo1 = null;
2276 alignPanel.seqPanel.keyboardNo2 = null;
2278 viewport.setSelectionGroup(null);
2279 viewport.getColumnSelection().clear();
2280 viewport.setSelectionGroup(null);
2281 alignPanel.idPanel.idCanvas.searchResults = null;
2282 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2283 // JAL-2034 - should delegate to
2284 // alignPanel to decide if overview needs
2286 alignPanel.paintAlignment(false);
2287 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2288 viewport.sendSelection();
2291 public void invertSequenceMenuItem_actionPerformed()
2293 SequenceGroup sg = viewport.getSelectionGroup();
2294 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2296 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2299 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2300 viewport.sendSelection();
2303 public void invertColSel_actionPerformed()
2305 viewport.invertColumnSelection();
2306 alignPanel.paintAlignment(true);
2307 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2308 viewport.sendSelection();
2311 void trimAlignment(boolean trimLeft)
2313 AlignmentI al = viewport.getAlignment();
2314 ViewportRanges ranges = viewport.getRanges();
2315 ColumnSelection colSel = viewport.getColumnSelection();
2318 if (!colSel.isEmpty())
2322 column = colSel.getMin();
2326 column = colSel.getMax();
2330 if (viewport.getSelectionGroup() != null)
2332 seqs = viewport.getSelectionGroup()
2333 .getSequencesAsArray(viewport.getHiddenRepSequences());
2337 seqs = al.getSequencesArray();
2340 TrimRegionCommand trimRegion;
2343 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2345 ranges.setStartRes(0);
2349 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2353 statusBar.setText(MessageManager
2354 .formatMessage("label.removed_columns", new String[]
2355 { Integer.valueOf(trimRegion.getSize()).toString() }));
2356 addHistoryItem(trimRegion);
2358 for (SequenceGroup sg : al.getGroups())
2360 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2361 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2367 viewport.firePropertyChange("alignment", null, al.getSequences());
2371 public void removeGappedColumnMenuItem_actionPerformed()
2373 AlignmentI al = viewport.getAlignment();
2374 ViewportRanges ranges = viewport.getRanges();
2376 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2379 if (viewport.getSelectionGroup() != null)
2381 seqs = viewport.getSelectionGroup()
2382 .getSequencesAsArray(viewport.getHiddenRepSequences());
2383 start = viewport.getSelectionGroup().getStartRes();
2384 end = viewport.getSelectionGroup().getEndRes();
2388 seqs = viewport.getAlignment().getSequencesArray();
2391 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2392 "Remove Gapped Columns", seqs, start, end,
2393 viewport.getAlignment());
2395 addHistoryItem(removeGapCols);
2397 statusBar.setText(MessageManager
2398 .formatMessage("label.removed_empty_columns", new String[]
2399 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2401 // This is to maintain viewport position on first residue
2402 // of first sequence
2403 SequenceI seq = al.getSequenceAt(0);
2404 int startRes = seq.findPosition(ranges.getStartRes());
2405 // ShiftList shifts;
2406 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2407 // edit.alColumnChanges=shifts.getInverse();
2408 // if (viewport.hasHiddenColumns)
2409 // viewport.getColumnSelection().compensateForEdits(shifts);
2410 ranges.setStartRes(seq.findIndex(startRes) - 1);
2411 viewport.firePropertyChange("alignment", null, al.getSequences());
2415 public void removeAllGapsMenuItem_actionPerformed()
2417 AlignmentI al = viewport.getAlignment();
2418 ViewportRanges ranges = viewport.getRanges();
2420 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2423 if (viewport.getSelectionGroup() != null)
2425 seqs = viewport.getSelectionGroup()
2426 .getSequencesAsArray(viewport.getHiddenRepSequences());
2427 start = viewport.getSelectionGroup().getStartRes();
2428 end = viewport.getSelectionGroup().getEndRes();
2432 seqs = viewport.getAlignment().getSequencesArray();
2435 // This is to maintain viewport position on first residue
2436 // of first sequence
2437 SequenceI seq = al.getSequenceAt(0);
2438 int startRes = seq.findPosition(ranges.getStartRes());
2441 new RemoveGapsCommand("Remove Gaps", seqs, start, end, al));
2443 ranges.setStartRes(seq.findIndex(startRes) - 1);
2445 viewport.firePropertyChange("alignment", null, al.getSequences());
2449 public void findMenuItem_actionPerformed()
2451 new Finder(alignPanel);
2455 * create a new view derived from the current view
2458 * @return frame for the new view
2460 public AlignFrame newView(String viewtitle)
2463 if (viewport.hasHiddenRows())
2465 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2466 .getFullAlignment().getSequencesArray());
2470 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2473 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2475 for (int i = 0; i < viewport.getAlignment()
2476 .getAlignmentAnnotation().length; i++)
2478 if (!viewport.getAlignment()
2479 .getAlignmentAnnotation()[i].autoCalculated)
2481 newal.addAnnotation(
2482 viewport.getAlignment().getAlignmentAnnotation()[i]);
2487 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2489 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2490 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2491 PaintRefresher.Register(newaf.alignPanel,
2492 newaf.alignPanel.av.getSequenceSetId());
2494 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2495 newaf.alignPanel.av.getSequenceSetId());
2496 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2497 newaf.alignPanel.av.getSequenceSetId());
2499 Vector comps = PaintRefresher.components
2500 .get(viewport.getSequenceSetId());
2502 for (int i = 0; i < comps.size(); i++)
2504 if (comps.elementAt(i) instanceof AlignmentPanel)
2510 String title = new String(this.getTitle());
2511 if (viewtitle != null)
2513 title = viewtitle + " ( " + title + ")";
2517 if (title.indexOf("(View") > -1)
2519 title = title.substring(0, title.indexOf("(View"));
2521 title += "(View " + viewSize + ")";
2524 newaf.setTitle(title.toString());
2526 newaf.viewport.setHistoryList(viewport.getHistoryList());
2527 newaf.viewport.setRedoList(viewport.getRedoList());
2533 * @return list of feature groups on the view
2535 public String[] getFeatureGroups()
2537 FeatureRenderer fr = null;
2538 if (alignPanel != null
2539 && (fr = alignPanel.getFeatureRenderer()) != null)
2541 List<String> gps = fr.getFeatureGroups();
2542 String[] _gps = gps.toArray(new String[gps.size()]);
2549 * get sequence feature groups that are hidden or shown
2555 public String[] getFeatureGroupsOfState(boolean visible)
2557 FeatureRenderer fr = null;
2558 if (alignPanel != null
2559 && (fr = alignPanel.getFeatureRenderer()) != null)
2561 List<String> gps = fr.getGroups(visible);
2562 String[] _gps = gps.toArray(new String[gps.size()]);
2569 * Change the display state for the given feature groups
2572 * list of group strings
2574 * visible or invisible
2576 public void setFeatureGroupState(String[] groups, boolean state)
2578 FeatureRenderer fr = null;
2579 this.sequenceFeatures.setState(true);
2580 viewport.setShowSequenceFeatures(true);
2581 if (alignPanel != null
2582 && (fr = alignPanel.getFeatureRenderer()) != null)
2585 fr.setGroupVisibility(Arrays.asList(groups), state);
2586 alignPanel.seqPanel.seqCanvas.repaint();
2587 if (alignPanel.overviewPanel != null)
2589 alignPanel.overviewPanel.updateOverviewImage();
2594 public void seqLimits_itemStateChanged()
2596 viewport.setShowJVSuffix(seqLimits.getState());
2597 alignPanel.fontChanged();
2598 alignPanel.paintAlignment(true);
2601 protected void colourTextMenuItem_actionPerformed()
2603 viewport.setColourText(colourTextMenuItem.getState());
2604 alignPanel.paintAlignment(true);
2607 protected void displayNonconservedMenuItem_actionPerformed()
2609 viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
2610 alignPanel.paintAlignment(true);
2613 protected void wrapMenuItem_actionPerformed()
2615 viewport.setWrapAlignment(wrapMenuItem.getState());
2616 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2617 scaleAbove.setEnabled(wrapMenuItem.getState());
2618 scaleLeft.setEnabled(wrapMenuItem.getState());
2619 scaleRight.setEnabled(wrapMenuItem.getState());
2620 alignPanel.paintAlignment(true);
2623 public void overviewMenuItem_actionPerformed()
2625 if (alignPanel.overviewPanel != null)
2630 Frame frame = new Frame();
2631 final OverviewPanel overview = new OverviewPanel(alignPanel);
2632 frame.add(overview);
2633 // +50 must allow for applet frame window
2634 jalview.bin.JalviewLite.addFrame(frame, MessageManager
2635 .formatMessage("label.overview_params", new String[]
2636 { this.getTitle() }), overview.getPreferredSize().width,
2637 overview.getPreferredSize().height + 50);
2640 final AlignmentPanel ap = alignPanel;
2641 frame.addWindowListener(new WindowAdapter()
2644 public void windowClosing(WindowEvent e)
2649 ap.setOverviewPanel(null);
2654 alignPanel.setOverviewPanel(overview);
2659 public void changeColour(ColourSchemeI cs)
2661 viewport.setGlobalColourScheme(cs);
2663 alignPanel.paintAlignment(true);
2666 protected void modifyPID_actionPerformed()
2668 if (viewport.getAbovePIDThreshold()
2669 && viewport.getGlobalColourScheme() != null)
2671 SliderPanel.setPIDSliderSource(alignPanel,
2672 viewport.getResidueShading(), alignPanel.getViewName());
2673 SliderPanel.showPIDSlider();
2677 protected void modifyConservation_actionPerformed()
2679 if (viewport.getConservationSelected()
2680 && viewport.getGlobalColourScheme() != null)
2682 SliderPanel.setConservationSlider(alignPanel,
2683 viewport.getResidueShading(), alignPanel.getViewName());
2684 SliderPanel.showConservationSlider();
2688 protected void conservationMenuItem_actionPerformed()
2690 boolean selected = conservationMenuItem.getState();
2691 modifyConservation.setEnabled(selected);
2692 viewport.setConservationSelected(selected);
2693 viewport.getResidueShading().setConservationApplied(selected);
2695 changeColour(viewport.getGlobalColourScheme());
2699 modifyConservation_actionPerformed();
2703 SliderPanel.hideConservationSlider();
2707 public void abovePIDThreshold_actionPerformed()
2709 boolean selected = abovePIDThreshold.getState();
2710 modifyPID.setEnabled(selected);
2711 viewport.setAbovePIDThreshold(selected);
2714 viewport.getResidueShading().setThreshold(0,
2715 viewport.isIgnoreGapsConsensus());
2718 changeColour(viewport.getGlobalColourScheme());
2722 modifyPID_actionPerformed();
2726 SliderPanel.hidePIDSlider();
2730 public void sortPairwiseMenuItem_actionPerformed()
2732 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2733 AlignmentSorter.sortByPID(viewport.getAlignment(),
2734 viewport.getAlignment().getSequenceAt(0));
2736 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2737 viewport.getAlignment()));
2738 alignPanel.paintAlignment(true);
2741 public void sortIDMenuItem_actionPerformed()
2743 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2744 AlignmentSorter.sortByID(viewport.getAlignment());
2746 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
2747 alignPanel.paintAlignment(true);
2750 public void sortLengthMenuItem_actionPerformed()
2752 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2753 AlignmentSorter.sortByLength(viewport.getAlignment());
2754 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2755 viewport.getAlignment()));
2756 alignPanel.paintAlignment(true);
2759 public void sortGroupMenuItem_actionPerformed()
2761 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2762 AlignmentSorter.sortByGroup(viewport.getAlignment());
2763 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2764 viewport.getAlignment()));
2765 alignPanel.paintAlignment(true);
2769 public void removeRedundancyMenuItem_actionPerformed()
2771 new RedundancyPanel(alignPanel);
2774 public void pairwiseAlignmentMenuItem_actionPerformed()
2776 if (viewport.getSelectionGroup() != null
2777 && viewport.getSelectionGroup().getSize() > 1)
2779 Frame frame = new Frame();
2780 frame.add(new PairwiseAlignPanel(alignPanel));
2781 jalview.bin.JalviewLite.addFrame(frame,
2782 MessageManager.getString("action.pairwise_alignment"), 600,
2787 public void PCAMenuItem_actionPerformed()
2789 // are the sequences aligned?
2790 if (!viewport.getAlignment().isAligned(false))
2793 int Width = viewport.getAlignment().getWidth();
2795 for (int i = 0; i < viewport.getAlignment().getSequences()
2798 current = viewport.getAlignment().getSequenceAt(i);
2800 if (current.getLength() < Width)
2802 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2805 alignPanel.paintAlignment(true);
2808 if ((viewport.getSelectionGroup() != null
2809 && viewport.getSelectionGroup().getSize() < 4
2810 && viewport.getSelectionGroup().getSize() > 0)
2811 || viewport.getAlignment().getHeight() < 4)
2818 new PCAPanel(viewport);
2819 } catch (java.lang.OutOfMemoryError ex)
2825 public void averageDistanceTreeMenuItem_actionPerformed()
2827 newTreePanel(TreeBuilder.AVERAGE_DISTANCE, new PIDModel().getName(),
2828 "Average distance tree using PID");
2831 public void neighbourTreeMenuItem_actionPerformed()
2833 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING, new PIDModel().getName(),
2834 "Neighbour joining tree using PID");
2837 protected void njTreeBlosumMenuItem_actionPerformed()
2839 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING,
2840 ScoreModels.getInstance().getBlosum62().getName(),
2841 "Neighbour joining tree using BLOSUM62");
2844 protected void avTreeBlosumMenuItem_actionPerformed()
2846 newTreePanel(TreeBuilder.AVERAGE_DISTANCE,
2847 ScoreModels.getInstance().getBlosum62().getName(),
2848 "Average distance tree using BLOSUM62");
2851 void newTreePanel(String type, String pwType, String title)
2853 // are the sequences aligned?
2854 if (!viewport.getAlignment().isAligned(false))
2857 int Width = viewport.getAlignment().getWidth();
2859 for (int i = 0; i < viewport.getAlignment().getSequences()
2862 current = viewport.getAlignment().getSequenceAt(i);
2864 if (current.getLength() < Width)
2866 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2869 alignPanel.paintAlignment(true);
2873 if ((viewport.getSelectionGroup() != null
2874 && viewport.getSelectionGroup().getSize() > 1)
2875 || (viewport.getAlignment().getHeight() > 1))
2877 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2879 addTreeMenuItem(tp, title);
2881 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2885 void loadTree_actionPerformed()
2887 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2888 cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2889 cap.setTreeImport();
2890 Frame frame = new Frame();
2892 jalview.bin.JalviewLite.addFrame(frame,
2893 MessageManager.getString("label.paste_newick_file"), 400, 300);
2896 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2898 TreePanel tp = new TreePanel(alignPanel, treeFile,
2899 MessageManager.getString("label.load_tree_from_file"), tree);
2900 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2901 addTreeMenuItem(tp, treeFile);
2905 * sort the alignment using the given treePanel
2908 * tree used to sort view
2910 * string used for undo event name
2912 public void sortByTree(TreePanel treePanel, String title)
2914 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2915 AlignmentSorter.sortByTree(viewport.getAlignment(),
2916 treePanel.getTree());
2917 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2918 // HistoryItem.SORT));
2919 addHistoryItem(new OrderCommand(MessageManager
2920 .formatMessage("label.order_by_params", new String[]
2921 { title }), oldOrder, viewport.getAlignment()));
2922 alignPanel.paintAlignment(true);
2926 * Do any automatic reordering of the alignment and add the necessary bits to
2927 * the menu structure for the new tree
2932 protected void addTreeMenuItem(final TreePanel treePanel,
2935 final MenuItem item = new MenuItem(title);
2936 sortByTreeMenu.add(item);
2937 item.addActionListener(new java.awt.event.ActionListener()
2940 public void actionPerformed(ActionEvent evt)
2942 sortByTree(treePanel, title); // treePanel.getTitle());
2946 treePanel.addWindowListener(new WindowAdapter()
2949 public void windowOpened(WindowEvent e)
2951 if (viewport.sortByTree)
2953 sortByTree(treePanel, title);
2955 super.windowOpened(e);
2959 public void windowClosing(WindowEvent e)
2961 sortByTreeMenu.remove(item);
2966 public boolean sortBy(AlignmentOrder alorder, String undoname)
2968 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2969 if (viewport.applet.debug)
2971 System.err.println("Sorting " + alorder.getOrder().size()
2972 + " in alignment '" + getTitle() + "'");
2974 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2975 if (undoname != null)
2977 addHistoryItem(new OrderCommand(undoname, oldOrder,
2978 viewport.getAlignment()));
2980 alignPanel.paintAlignment(true);
2984 protected void documentation_actionPerformed()
2986 alignPanel.av.applet.openJalviewHelpUrl();
2989 protected void about_actionPerformed()
2992 class AboutPanel extends Canvas
2998 public AboutPanel(String version, String builddate)
3000 this.version = version;
3001 this.builddate = builddate;
3005 public void paint(Graphics g)
3007 g.setColor(Color.white);
3008 g.fillRect(0, 0, getSize().width, getSize().height);
3009 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3010 FontMetrics fm = g.getFontMetrics();
3011 int fh = fm.getHeight();
3013 g.setColor(Color.black);
3014 // TODO: update this text for each release or centrally store it for
3015 // lite and application
3016 g.setFont(new Font("Helvetica", Font.BOLD, 14));
3017 g.drawString(MessageManager
3018 .formatMessage("label.jalviewLite_release", new String[]
3019 { version }), x, y += fh);
3020 g.setFont(new Font("Helvetica", Font.BOLD, 12));
3021 g.drawString(MessageManager.formatMessage("label.jaview_build_date",
3023 { builddate }), x, y += fh);
3024 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3025 g.drawString(MessageManager.getString("label.jalview_authors_1"), x,
3027 g.drawString(MessageManager.getString("label.jalview_authors_2"),
3028 x + 50, y += fh + 8);
3029 g.drawString(MessageManager.getString("label.jalview_dev_managers"),
3031 g.drawString(MessageManager
3032 .getString("label.jalview_distribution_lists"), x, y += fh);
3033 g.drawString(MessageManager.getString("label.jalview_please_cite"),
3036 MessageManager.getString("label.jalview_cite_1_authors"), x,
3038 g.drawString(MessageManager.getString("label.jalview_cite_1_title"),
3040 g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
3045 Frame frame = new Frame();
3046 frame.add(new AboutPanel(JalviewLite.getVersion(),
3047 JalviewLite.getBuildDate()));
3048 jalview.bin.JalviewLite.addFrame(frame,
3049 MessageManager.getString("label.jalview"), 580, 220);
3053 public void showURL(String url, String target)
3055 if (viewport.applet == null)
3057 System.out.println("Not running as applet - no browser available.");
3061 viewport.applet.showURL(url, target);
3065 // ////////////////////////////////////////////////////////////////////////////////
3066 // JBuilder Graphics here
3068 MenuBar alignFrameMenuBar = new MenuBar();
3070 Menu fileMenu = new Menu(MessageManager.getString("action.file"));
3072 MenuItem loadApplication = new MenuItem(
3073 MessageManager.getString("label.view_full_application"));
3075 MenuItem loadTree = new MenuItem(
3076 MessageManager.getString("label.load_associated_tree"));
3078 MenuItem loadAnnotations = new MenuItem(
3079 MessageManager.getString("label.load_features_annotations"));
3081 MenuItem outputFeatures = new MenuItem(
3082 MessageManager.getString("label.export_features"));
3084 MenuItem outputAnnotations = new MenuItem(
3085 MessageManager.getString("label.export_annotations"));
3087 MenuItem closeMenuItem = new MenuItem(
3088 MessageManager.getString("action.close"));
3090 MenuItem selectAllSequenceMenuItem = new MenuItem(
3091 MessageManager.getString("action.select_all"));
3093 MenuItem deselectAllSequenceMenuItem = new MenuItem(
3094 MessageManager.getString("action.deselect_all"));
3096 MenuItem invertSequenceMenuItem = new MenuItem(
3097 MessageManager.getString("action.invert_selection"));
3099 MenuItem remove2LeftMenuItem = new MenuItem();
3101 MenuItem remove2RightMenuItem = new MenuItem();
3103 MenuItem removeGappedColumnMenuItem = new MenuItem();
3105 MenuItem removeAllGapsMenuItem = new MenuItem();
3107 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
3109 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
3111 MenuItem sortPairwiseMenuItem = new MenuItem();
3113 MenuItem sortIDMenuItem = new MenuItem();
3115 MenuItem sortLengthMenuItem = new MenuItem();
3117 MenuItem sortGroupMenuItem = new MenuItem();
3119 MenuItem removeRedundancyMenuItem = new MenuItem();
3121 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
3123 MenuItem PCAMenuItem = new MenuItem();
3125 MenuItem averageDistanceTreeMenuItem = new MenuItem();
3127 MenuItem neighbourTreeMenuItem = new MenuItem();
3129 BorderLayout borderLayout1 = new BorderLayout();
3131 public Label statusBar = new Label();
3133 MenuItem clustalColour = new MenuItem();
3135 MenuItem zappoColour = new MenuItem();
3137 MenuItem taylorColour = new MenuItem();
3139 MenuItem hydrophobicityColour = new MenuItem();
3141 MenuItem helixColour = new MenuItem();
3143 MenuItem strandColour = new MenuItem();
3145 MenuItem turnColour = new MenuItem();
3147 MenuItem buriedColour = new MenuItem();
3149 MenuItem purinePyrimidineColour = new MenuItem();
3151 // MenuItem RNAInteractionColour = new MenuItem();
3153 MenuItem RNAHelixColour = new MenuItem();
3155 MenuItem userDefinedColour = new MenuItem();
3157 MenuItem PIDColour = new MenuItem();
3159 MenuItem BLOSUM62Colour = new MenuItem();
3161 MenuItem tcoffeeColour = new MenuItem();
3163 MenuItem njTreeBlosumMenuItem = new MenuItem();
3165 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
3167 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
3169 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
3171 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
3173 MenuItem alProperties = new MenuItem(
3174 MessageManager.getString("label.alignment_props"));
3176 MenuItem overviewMenuItem = new MenuItem();
3178 MenuItem undoMenuItem = new MenuItem();
3180 MenuItem redoMenuItem = new MenuItem();
3182 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
3184 MenuItem noColourmenuItem = new MenuItem();
3186 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
3188 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
3190 MenuItem findMenuItem = new MenuItem();
3192 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
3194 MenuItem nucleotideColour = new MenuItem();
3196 MenuItem deleteGroups = new MenuItem();
3198 MenuItem grpsFromSelection = new MenuItem();
3200 MenuItem createGroup = new MenuItem();
3202 MenuItem unGroup = new MenuItem();
3204 MenuItem delete = new MenuItem();
3206 MenuItem copy = new MenuItem();
3208 MenuItem cut = new MenuItem();
3210 Menu pasteMenu = new Menu();
3212 MenuItem pasteNew = new MenuItem();
3214 MenuItem pasteThis = new MenuItem();
3216 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
3218 MenuItem font = new MenuItem();
3220 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
3222 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
3224 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
3226 MenuItem modifyPID = new MenuItem();
3228 MenuItem modifyConservation = new MenuItem();
3230 CheckboxMenuItem autoCalculate = null;
3232 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
3233 "Sort Alignment With New Tree", true);
3235 Menu sortByTreeMenu = new Menu();
3237 MenuItem inputText = new MenuItem();
3239 MenuItem documentation = new MenuItem();
3241 MenuItem about = new MenuItem();
3243 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
3245 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
3247 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
3249 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
3251 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
3253 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
3255 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
3257 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
3259 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
3262 * Initialise menus and other items
3266 private void jbInit() throws Exception
3268 setMenuBar(alignFrameMenuBar);
3271 * Configure File menu items and actions
3274 .setLabel(MessageManager.getString("label.input_from_textbox"));
3275 inputText.addActionListener(this);
3276 Menu outputTextboxMenu = new Menu(
3277 MessageManager.getString("label.out_to_textbox"));
3278 for (String ff : FileFormats.getInstance().getWritableFormats(true))
3280 MenuItem item = new MenuItem(ff);
3282 item.addActionListener(new java.awt.event.ActionListener()
3285 public void actionPerformed(ActionEvent e)
3287 outputText_actionPerformed(e);
3291 outputTextboxMenu.add(item);
3293 closeMenuItem.addActionListener(this);
3294 loadApplication.addActionListener(this);
3295 loadTree.addActionListener(this);
3296 loadAnnotations.addActionListener(this);
3297 outputFeatures.addActionListener(this);
3298 outputAnnotations.addActionListener(this);
3301 * Configure Edit menu items and actions
3303 undoMenuItem.setEnabled(false);
3304 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3305 undoMenuItem.addActionListener(this);
3306 redoMenuItem.setEnabled(false);
3307 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3308 redoMenuItem.addActionListener(this);
3309 copy.setLabel(MessageManager.getString("action.copy"));
3310 copy.addActionListener(this);
3311 cut.setLabel(MessageManager.getString("action.cut"));
3312 cut.addActionListener(this);
3313 delete.setLabel(MessageManager.getString("action.delete"));
3314 delete.addActionListener(this);
3315 pasteMenu.setLabel(MessageManager.getString("action.paste"));
3316 pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3317 pasteNew.addActionListener(this);
3318 pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3319 pasteThis.addActionListener(this);
3321 .setLabel(MessageManager.getString("action.remove_left"));
3322 remove2LeftMenuItem.addActionListener(this);
3323 remove2RightMenuItem
3324 .setLabel(MessageManager.getString("action.remove_right"));
3325 remove2RightMenuItem.addActionListener(this);
3326 removeGappedColumnMenuItem.setLabel(
3327 MessageManager.getString("action.remove_empty_columns"));
3328 removeGappedColumnMenuItem.addActionListener(this);
3329 removeAllGapsMenuItem
3330 .setLabel(MessageManager.getString("action.remove_all_gaps"));
3331 removeAllGapsMenuItem.addActionListener(this);
3332 removeRedundancyMenuItem
3333 .setLabel(MessageManager.getString("action.remove_redundancy"));
3334 removeRedundancyMenuItem.addActionListener(this);
3337 * Configure Select menu items and actions
3339 findMenuItem.setLabel(MessageManager.getString("action.find"));
3340 findMenuItem.addActionListener(this);
3341 selectAllSequenceMenuItem.addActionListener(this);
3342 deselectAllSequenceMenuItem.addActionListener(this);
3343 invertSequenceMenuItem.setLabel(
3344 MessageManager.getString("action.invert_sequence_selection"));
3345 invertSequenceMenuItem.addActionListener(this);
3346 invertColSel.setLabel(
3347 MessageManager.getString("action.invert_column_selection"));
3348 invertColSel.addActionListener(this);
3350 .setLabel(MessageManager.getString("action.undefine_groups"));
3351 deleteGroups.addActionListener(this);
3352 grpsFromSelection.setLabel(
3353 MessageManager.getString("action.make_groups_selection"));
3354 grpsFromSelection.addActionListener(this);
3355 createGroup.setLabel(MessageManager.getString("action.create_group"));
3356 createGroup.addActionListener(this);
3357 unGroup.setLabel(MessageManager.getString("action.remove_group"));
3358 unGroup.addActionListener(this);
3360 annotationColumnSelection.setLabel(
3361 MessageManager.getString("action.select_by_annotation"));
3362 annotationColumnSelection.addActionListener(this);
3365 * Configure View menu items and actions
3367 newView.setLabel(MessageManager.getString("action.new_view"));
3368 newView.addActionListener(this);
3369 Menu showMenu = new Menu(MessageManager.getString("action.show"));
3370 showColumns.setLabel(MessageManager.getString("label.all_columns"));
3371 showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3372 Menu hideMenu = new Menu(MessageManager.getString("action.hide"));
3374 .setLabel(MessageManager.getString("label.selected_columns"));
3376 .setLabel(MessageManager.getString("label.selected_sequences"));
3377 hideAllButSelection.setLabel(
3378 MessageManager.getString("label.all_but_selected_region"));
3380 .setLabel(MessageManager.getString("label.selected_region"));
3381 showAllHidden.setLabel(
3382 MessageManager.getString("label.all_sequences_columns"));
3383 showColumns.addActionListener(this);
3384 showSeqs.addActionListener(this);
3385 hideColumns.addActionListener(this);
3386 hideSequences.addActionListener(this);
3387 hideAllButSelection.addActionListener(this);
3388 hideAllSelection.addActionListener(this);
3389 showAllHidden.addActionListener(this);
3391 .setLabel(MessageManager.getString("action.feature_settings"));
3392 featureSettings.addActionListener(this);
3393 sequenceFeatures.setLabel(
3394 MessageManager.getString("label.show_sequence_features"));
3395 sequenceFeatures.addItemListener(this);
3396 sequenceFeatures.setState(false);
3397 followMouseOverFlag.setLabel(
3398 MessageManager.getString("label.automatic_scrolling"));
3399 followMouseOverFlag.addItemListener(this);
3400 alProperties.addActionListener(this);
3402 .setLabel(MessageManager.getString("label.overview_window"));
3403 overviewMenuItem.addActionListener(this);
3406 * Configure Annotations menu items and actions
3408 annotationPanelMenuItem
3409 .setLabel(MessageManager.getString("label.show_annotations"));
3410 annotationPanelMenuItem.addItemListener(this);
3412 .setLabel(MessageManager.getString("label.group_consensus"));
3413 showGroupConservation
3414 .setLabel(MessageManager.getString("label.group_conservation"));
3415 showConsensusHistogram.setLabel(
3416 MessageManager.getString("label.show_consensus_histogram"));
3417 showSequenceLogo.setLabel(
3418 MessageManager.getString("label.show_consensus_logo"));
3419 normSequenceLogo.setLabel(
3420 MessageManager.getString("label.norm_consensus_logo"));
3421 applyAutoAnnotationSettings
3422 .setLabel(MessageManager.getString("label.apply_all_groups"));
3423 applyAutoAnnotationSettings.setState(true);
3424 Menu autoAnnMenu = new Menu(
3425 MessageManager.getString("label.autocalculated_annotation"));
3426 showGroupConsensus.addItemListener(this);
3427 showGroupConservation.addItemListener(this);
3428 showConsensusHistogram.addItemListener(this);
3429 showSequenceLogo.addItemListener(this);
3430 normSequenceLogo.addItemListener(this);
3431 applyAutoAnnotationSettings.addItemListener(this);
3432 showAlignmentAnnotations = new CheckboxMenuItem(
3433 MessageManager.getString("label.show_all_al_annotations"));
3434 showSequenceAnnotations = new CheckboxMenuItem(
3435 MessageManager.getString("label.show_all_seq_annotations"));
3436 sortAnnBySequence = new CheckboxMenuItem(
3437 MessageManager.getString("label.sort_annotations_by_sequence"));
3438 sortAnnByLabel = new CheckboxMenuItem(
3439 MessageManager.getString("label.sort_annotations_by_label"));
3440 showAutoFirst = new CheckboxMenuItem(
3441 MessageManager.getString("label.show_first"));
3442 showAutoFirst.setState(false); // pending applet parameter
3443 setShowAutoCalculatedAbove(showAutoFirst.getState());
3444 showAutoLast = new CheckboxMenuItem(
3445 MessageManager.getString("label.show_last"));
3446 showAutoLast.setState(!showAutoFirst.getState());
3447 showAlignmentAnnotations.addItemListener(this);
3448 showSequenceAnnotations.addItemListener(this);
3449 sortAnnBySequence.addItemListener(this);
3450 sortAnnByLabel.addItemListener(this);
3451 showAutoFirst.addItemListener(this);
3452 showAutoLast.addItemListener(this);
3455 * Configure Format menu items and actions
3457 font.setLabel(MessageManager.getString("action.font"));
3458 font.addActionListener(this);
3459 scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3460 scaleAbove.setState(true);
3461 scaleAbove.setEnabled(false);
3462 scaleAbove.addItemListener(this);
3463 scaleLeft.setEnabled(false);
3464 scaleLeft.setState(true);
3465 scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3466 scaleLeft.addItemListener(this);
3467 scaleRight.setEnabled(false);
3468 scaleRight.setState(true);
3469 scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3470 scaleRight.addItemListener(this);
3471 viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
3472 viewBoxesMenuItem.setState(true);
3473 viewBoxesMenuItem.addItemListener(this);
3474 viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
3475 viewTextMenuItem.setState(true);
3476 viewTextMenuItem.addItemListener(this);
3478 .setLabel(MessageManager.getString("label.colour_text"));
3479 colourTextMenuItem.addItemListener(this);
3480 displayNonconservedMenuItem
3481 .setLabel(MessageManager.getString("label.show_non_conserved"));
3482 displayNonconservedMenuItem.addItemListener(this);
3483 wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3484 wrapMenuItem.addItemListener(this);
3486 .setLabel(MessageManager.getString("action.show_gaps"));
3487 renderGapsMenuItem.setState(true);
3488 renderGapsMenuItem.addItemListener(this);
3489 centreColumnLabelFlag.setLabel(
3490 MessageManager.getString("label.centre_column_labels"));
3491 centreColumnLabelFlag.addItemListener(this);
3492 seqLimits.setState(true);
3494 MessageManager.getString("label.show_sequence_limits"));
3495 seqLimits.addItemListener(this);
3498 * Configure Colour menu items and actions
3500 applyToAllGroups.setLabel(
3501 MessageManager.getString("label.apply_colour_to_all_groups"));
3502 applyToAllGroups.setState(true);
3503 applyToAllGroups.addItemListener(this);
3504 clustalColour.setLabel(
3505 MessageManager.getString("label.colourScheme_clustal"));
3506 clustalColour.addActionListener(this);
3508 .setLabel(MessageManager.getString("label.colourScheme_zappo"));
3509 zappoColour.addActionListener(this);
3510 taylorColour.setLabel(
3511 MessageManager.getString("label.colourScheme_taylor"));
3512 taylorColour.addActionListener(this);
3513 hydrophobicityColour.setLabel(
3514 MessageManager.getString("label.colourScheme_hydrophobic"));
3515 hydrophobicityColour.addActionListener(this);
3516 helixColour.setLabel(MessageManager
3517 .getString("label.colourScheme_helix_propensity"));
3518 helixColour.addActionListener(this);
3519 strandColour.setLabel(MessageManager
3520 .getString("label.colourScheme_strand_propensity"));
3521 strandColour.addActionListener(this);
3522 turnColour.setLabel(
3523 MessageManager.getString("label.colourScheme_turn_propensity"));
3524 turnColour.addActionListener(this);
3525 buriedColour.setLabel(
3526 MessageManager.getString("label.colourScheme_buried_index"));
3527 buriedColour.addActionListener(this);
3528 purinePyrimidineColour.setLabel(MessageManager
3529 .getString("label.colourScheme_purine/pyrimidine"));
3530 purinePyrimidineColour.addActionListener(this);
3531 // RNAInteractionColour.setLabel(MessageManager
3532 // .getString("label.rna_interaction"));
3533 // RNAInteractionColour.addActionListener(this);
3534 RNAHelixColour.setLabel(
3535 MessageManager.getString("label.colourScheme_rna_helices"));
3536 RNAHelixColour.addActionListener(this);
3538 .setLabel(MessageManager.getString("action.user_defined"));
3539 userDefinedColour.addActionListener(this);
3541 MessageManager.getString("label.colourScheme_%_identity"));
3542 PIDColour.addActionListener(this);
3543 BLOSUM62Colour.setLabel(
3544 MessageManager.getString("label.colourScheme_blosum62"));
3545 BLOSUM62Colour.addActionListener(this);
3546 tcoffeeColour.setLabel(
3547 MessageManager.getString("label.colourScheme_t-coffee_scores"));
3548 // it will be enabled only if a score file is provided
3549 tcoffeeColour.setEnabled(false);
3550 tcoffeeColour.addActionListener(this);
3551 conservationMenuItem
3552 .setLabel(MessageManager.getString("action.by_conservation"));
3553 conservationMenuItem.addItemListener(this);
3554 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3555 noColourmenuItem.addActionListener(this);
3556 abovePIDThreshold.setLabel(
3557 MessageManager.getString("label.above_identity_threshold"));
3558 abovePIDThreshold.addItemListener(this);
3559 nucleotideColour.setLabel(
3560 MessageManager.getString("label.colourScheme_nucleotide"));
3561 nucleotideColour.addActionListener(this);
3563 MessageManager.getString("label.modify_identity_threshold"));
3564 modifyPID.setEnabled(abovePIDThreshold.getState());
3565 modifyPID.addActionListener(this);
3566 modifyConservation.setLabel(MessageManager
3567 .getString("label.modify_conservation_threshold"));
3568 modifyConservation.setEnabled(conservationMenuItem.getState());
3569 modifyConservation.addActionListener(this);
3571 .setLabel(MessageManager.getString("action.by_annotation"));
3572 annotationColour.addActionListener(this);
3575 * Configure Calculate menu items and actions
3577 sortPairwiseMenuItem
3578 .setLabel(MessageManager.getString("action.by_pairwise_id"));
3579 sortPairwiseMenuItem.addActionListener(this);
3580 sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
3581 sortIDMenuItem.addActionListener(this);
3583 .setLabel(MessageManager.getString("action.by_length"));
3584 sortLengthMenuItem.addActionListener(this);
3585 sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3586 sortGroupMenuItem.addActionListener(this);
3587 pairwiseAlignmentMenuItem.setLabel(
3588 MessageManager.getString("action.pairwise_alignment"));
3589 pairwiseAlignmentMenuItem.addActionListener(this);
3590 PCAMenuItem.setLabel(
3591 MessageManager.getString("label.principal_component_analysis"));
3592 PCAMenuItem.addActionListener(this);
3593 autoCalculate = new CheckboxMenuItem(
3594 MessageManager.getString("label.autocalculate_consensus"),
3596 averageDistanceTreeMenuItem.setLabel(
3597 MessageManager.getString("label.average_distance_identity"));
3598 averageDistanceTreeMenuItem.addActionListener(this);
3599 neighbourTreeMenuItem.setLabel(
3600 MessageManager.getString("label.neighbour_joining_identity"));
3601 neighbourTreeMenuItem.addActionListener(this);
3602 avDistanceTreeBlosumMenuItem.setLabel(
3603 MessageManager.getString("label.average_distance_blosum62"));
3604 avDistanceTreeBlosumMenuItem.addActionListener(this);
3605 njTreeBlosumMenuItem
3606 .setLabel(MessageManager.getString("label.neighbour_blosum62"));
3607 njTreeBlosumMenuItem.addActionListener(this);
3609 .setLabel(MessageManager.getString("action.by_tree_order"));
3610 Menu sortMenu = new Menu(MessageManager.getString("action.sort"));
3611 Menu calculateTreeMenu = new Menu(
3612 MessageManager.getString("action.calculate_tree"));
3613 autoCalculate.addItemListener(this);
3614 sortByTree.addItemListener(this);
3617 * Configure Help menu items and actions
3619 Menu helpMenu = new Menu(MessageManager.getString("action.help"));
3620 documentation.setLabel(MessageManager.getString("label.documentation"));
3621 documentation.addActionListener(this);
3622 about.setLabel(MessageManager.getString("label.about"));
3623 about.addActionListener(this);
3626 * Add top level menus to frame
3628 alignFrameMenuBar.add(fileMenu);
3629 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
3630 alignFrameMenuBar.add(editMenu);
3631 Menu selectMenu = new Menu(MessageManager.getString("action.select"));
3632 alignFrameMenuBar.add(selectMenu);
3633 Menu viewMenu = new Menu(MessageManager.getString("action.view"));
3634 alignFrameMenuBar.add(viewMenu);
3635 Menu annotationsMenu = new Menu(
3636 MessageManager.getString("action.annotations"));
3637 alignFrameMenuBar.add(annotationsMenu);
3638 Menu formatMenu = new Menu(MessageManager.getString("action.format"));
3639 alignFrameMenuBar.add(formatMenu);
3640 Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
3641 alignFrameMenuBar.add(colourMenu);
3642 Menu calculateMenu = new Menu(
3643 MessageManager.getString("action.calculate"));
3644 alignFrameMenuBar.add(calculateMenu);
3645 alignFrameMenuBar.add(helpMenu);
3650 fileMenu.add(inputText);
3651 fileMenu.add(loadTree);
3652 fileMenu.add(loadAnnotations);
3653 fileMenu.addSeparator();
3654 fileMenu.add(outputTextboxMenu);
3655 fileMenu.add(outputFeatures);
3656 fileMenu.add(outputAnnotations);
3657 if (jalviewServletURL != null)
3659 fileMenu.add(loadApplication);
3661 fileMenu.addSeparator();
3662 fileMenu.add(closeMenuItem);
3667 editMenu.add(undoMenuItem);
3668 editMenu.add(redoMenuItem);
3671 pasteMenu.add(pasteNew);
3672 pasteMenu.add(pasteThis);
3673 editMenu.add(pasteMenu);
3674 editMenu.add(delete);
3675 editMenu.addSeparator();
3676 editMenu.add(remove2LeftMenuItem);
3677 editMenu.add(remove2RightMenuItem);
3678 editMenu.add(removeGappedColumnMenuItem);
3679 editMenu.add(removeAllGapsMenuItem);
3680 editMenu.add(removeRedundancyMenuItem);
3685 selectMenu.add(findMenuItem);
3686 selectMenu.addSeparator();
3687 selectMenu.add(selectAllSequenceMenuItem);
3688 selectMenu.add(deselectAllSequenceMenuItem);
3689 selectMenu.add(invertSequenceMenuItem);
3690 selectMenu.add(invertColSel);
3691 selectMenu.add(createGroup);
3692 selectMenu.add(unGroup);
3693 selectMenu.add(grpsFromSelection);
3694 selectMenu.add(deleteGroups);
3695 selectMenu.add(annotationColumnSelection);
3700 viewMenu.add(newView);
3701 viewMenu.addSeparator();
3702 showMenu.add(showColumns);
3703 showMenu.add(showSeqs);
3704 showMenu.add(showAllHidden);
3705 viewMenu.add(showMenu);
3706 hideMenu.add(hideColumns);
3707 hideMenu.add(hideSequences);
3708 hideMenu.add(hideAllSelection);
3709 hideMenu.add(hideAllButSelection);
3710 viewMenu.add(hideMenu);
3711 viewMenu.addSeparator();
3712 viewMenu.add(followMouseOverFlag);
3713 viewMenu.addSeparator();
3714 viewMenu.add(sequenceFeatures);
3715 viewMenu.add(featureSettings);
3716 viewMenu.addSeparator();
3717 viewMenu.add(alProperties);
3718 viewMenu.addSeparator();
3719 viewMenu.add(overviewMenuItem);
3724 annotationsMenu.add(annotationPanelMenuItem);
3725 annotationsMenu.addSeparator();
3726 annotationsMenu.add(showAlignmentAnnotations);
3727 annotationsMenu.add(showSequenceAnnotations);
3728 annotationsMenu.add(sortAnnBySequence);
3729 annotationsMenu.add(sortAnnByLabel);
3730 annotationsMenu.addSeparator();
3731 autoAnnMenu.add(showAutoFirst);
3732 autoAnnMenu.add(showAutoLast);
3733 autoAnnMenu.addSeparator();
3734 autoAnnMenu.add(applyAutoAnnotationSettings);
3735 autoAnnMenu.add(showConsensusHistogram);
3736 autoAnnMenu.add(showSequenceLogo);
3737 autoAnnMenu.add(normSequenceLogo);
3738 autoAnnMenu.addSeparator();
3739 autoAnnMenu.add(showGroupConservation);
3740 autoAnnMenu.add(showGroupConsensus);
3741 annotationsMenu.add(autoAnnMenu);
3746 formatMenu.add(font);
3747 formatMenu.add(seqLimits);
3748 formatMenu.add(wrapMenuItem);
3749 formatMenu.add(scaleAbove);
3750 formatMenu.add(scaleLeft);
3751 formatMenu.add(scaleRight);
3752 formatMenu.add(viewBoxesMenuItem);
3753 formatMenu.add(viewTextMenuItem);
3754 formatMenu.add(colourTextMenuItem);
3755 formatMenu.add(displayNonconservedMenuItem);
3756 formatMenu.add(renderGapsMenuItem);
3757 formatMenu.add(centreColumnLabelFlag);
3762 colourMenu.add(applyToAllGroups);
3763 colourMenu.addSeparator();
3764 colourMenu.add(noColourmenuItem);
3765 colourMenu.add(clustalColour);
3766 colourMenu.add(BLOSUM62Colour);
3767 colourMenu.add(PIDColour);
3768 colourMenu.add(zappoColour);
3769 colourMenu.add(taylorColour);
3770 colourMenu.add(hydrophobicityColour);
3771 colourMenu.add(helixColour);
3772 colourMenu.add(strandColour);
3773 colourMenu.add(turnColour);
3774 colourMenu.add(buriedColour);
3775 colourMenu.add(nucleotideColour);
3776 colourMenu.add(purinePyrimidineColour);
3777 // colourMenu.add(RNAInteractionColour);
3778 colourMenu.add(tcoffeeColour);
3779 colourMenu.add(userDefinedColour);
3780 colourMenu.addSeparator();
3781 colourMenu.add(conservationMenuItem);
3782 colourMenu.add(modifyConservation);
3783 colourMenu.add(abovePIDThreshold);
3784 colourMenu.add(modifyPID);
3785 colourMenu.add(annotationColour);
3786 colourMenu.add(RNAHelixColour);
3791 sortMenu.add(sortIDMenuItem);
3792 sortMenu.add(sortLengthMenuItem);
3793 sortMenu.add(sortByTreeMenu);
3794 sortMenu.add(sortGroupMenuItem);
3795 sortMenu.add(sortPairwiseMenuItem);
3796 calculateMenu.add(sortMenu);
3797 calculateTreeMenu.add(averageDistanceTreeMenuItem);
3798 calculateTreeMenu.add(neighbourTreeMenuItem);
3799 calculateTreeMenu.add(avDistanceTreeBlosumMenuItem);
3800 calculateTreeMenu.add(njTreeBlosumMenuItem);
3801 calculateMenu.add(calculateTreeMenu);
3802 calculateMenu.addSeparator();
3803 calculateMenu.add(pairwiseAlignmentMenuItem);
3804 calculateMenu.add(PCAMenuItem);
3805 calculateMenu.add(autoCalculate);
3806 calculateMenu.add(sortByTree);
3811 helpMenu.add(documentation);
3812 helpMenu.add(about);
3817 statusBar.setBackground(Color.white);
3818 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3819 statusBar.setText(MessageManager.getString("label.status_bar"));
3820 this.add(statusBar, BorderLayout.SOUTH);
3824 public void setStatus(String string)
3826 statusBar.setText(string);
3829 MenuItem featureSettings = new MenuItem();
3831 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3833 MenuItem annotationColour = new MenuItem();
3835 MenuItem annotationColumnSelection = new MenuItem();
3837 MenuItem invertColSel = new MenuItem();
3839 MenuItem showColumns = new MenuItem();
3841 MenuItem showSeqs = new MenuItem();
3843 MenuItem hideColumns = new MenuItem();
3845 MenuItem hideSequences = new MenuItem();
3847 MenuItem hideAllButSelection = new MenuItem();
3849 MenuItem hideAllSelection = new MenuItem();
3851 MenuItem showAllHidden = new MenuItem();
3853 MenuItem newView = new MenuItem();
3855 private CheckboxMenuItem showAlignmentAnnotations;
3857 private CheckboxMenuItem showSequenceAnnotations;
3859 private CheckboxMenuItem sortAnnBySequence;
3861 private CheckboxMenuItem sortAnnByLabel;
3863 private CheckboxMenuItem showAutoFirst;
3865 private CheckboxMenuItem showAutoLast;
3867 private SplitFrame splitFrame;
3870 * Attach the alignFrame panels after embedding menus, if necessary. This used
3871 * to be called setEmbedded, but is now creates the dropdown menus in a
3872 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3874 * @param reallyEmbedded
3875 * true to attach the view to the applet area on the page rather than
3878 public void createAlignFrameWindow(boolean reallyEmbedded)
3882 embedAlignFrameInApplet(viewport.applet);
3887 // test and embed menu bar if necessary.
3889 if (embedMenuIfNeeded(alignPanel))
3892 * adjust for status bar height too. ? pointless as overridden by layout
3895 alignPanel.setSize(getSize().width,
3896 getSize().height - statusBar.getHeight());
3898 add(statusBar, BorderLayout.SOUTH);
3899 add(alignPanel, BorderLayout.CENTER);
3900 // and register with the applet so it can pass external API calls to us
3901 jalview.bin.JalviewLite.addFrame(this, this.getTitle(), frameWidth,
3907 * Add the components of this AlignFrame to the applet container.
3911 public void embedAlignFrameInApplet(final JalviewLite theApplet)
3914 // Explicitly build the embedded menu panel for the on-page applet
3916 // view cannot be closed if its actually on the page
3917 fileMenu.remove(closeMenuItem);
3918 fileMenu.remove(3); // Remove Separator
3919 // construct embedded menu, using default font
3920 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
3921 // and actually add the components to the applet area
3922 theApplet.setLayout(new BorderLayout());
3923 theApplet.add(embeddedMenu, BorderLayout.NORTH);
3924 theApplet.add(statusBar, BorderLayout.SOUTH);
3925 // TODO should size be left to the layout manager?
3926 alignPanel.setSize(theApplet.getSize().width, theApplet.getSize().height
3927 - embeddedMenu.getHeight() - statusBar.getHeight());
3928 theApplet.add(alignPanel, BorderLayout.CENTER);
3929 final AlignFrame me = this;
3930 theApplet.addFocusListener(new FocusListener()
3934 public void focusLost(FocusEvent e)
3936 if (theApplet.currentAlignFrame == me)
3938 theApplet.currentAlignFrame = null;
3943 public void focusGained(FocusEvent e)
3945 theApplet.currentAlignFrame = me;
3948 theApplet.validate();
3952 * create a new binding between structures in an existing jmol viewer instance
3953 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3954 * this does not open a new Jmol window, or modify the display of the
3955 * structures in the original jmol window. Note This method doesn't work
3956 * without an additional javascript library to exchange messages between the
3957 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3960 * JmolViewer instance
3961 * @param sequenceIds
3962 * - sequence Ids to search for associations
3964 public SequenceStructureBinding addStructureViewInstance(
3965 Object jmolviewer, String[] sequenceIds)
3967 Viewer viewer = null;
3970 viewer = (Viewer) jmolviewer;
3971 } catch (ClassCastException ex)
3974 "Unsupported viewer object :" + jmolviewer.getClass());
3978 System.err.println("Can't use this object as a structure viewer:"
3979 + jmolviewer.getClass());
3982 SequenceI[] seqs = null;
3983 if (sequenceIds == null || sequenceIds.length == 0)
3985 seqs = viewport.getAlignment().getSequencesArray();
3989 Vector sqi = new Vector();
3990 AlignmentI al = viewport.getAlignment();
3991 for (int sid = 0; sid < sequenceIds.length; sid++)
3993 SequenceI sq = al.findName(sequenceIds[sid]);
4001 seqs = new SequenceI[sqi.size()];
4002 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
4004 seqs[sid] = (SequenceI) sqi.elementAt(sid);
4012 AAStructureBindingModel jmv = null;
4013 // TODO: search for a jmv that involves viewer
4015 { // create a new viewer/jalview binding.
4016 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] { seqs });
4023 * bind a pdb file to a sequence in the current view
4026 * - sequenceId within the dataset.
4027 * @param pdbEntryString
4028 * - the short name for the PDB file
4030 * - pdb file - either a URL or a valid PDB file.
4031 * @return true if binding was as success TODO: consider making an exception
4032 * structure for indicating when PDB parsing or sequenceId location
4035 public boolean addPdbFile(String sequenceId, String pdbEntryString,
4038 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
4039 boolean needtoadd = false;
4040 if (toaddpdb != null)
4042 Vector pdbe = toaddpdb.getAllPDBEntries();
4043 PDBEntry pdbentry = null;
4044 if (pdbe != null && pdbe.size() > 0)
4046 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
4048 pdbentry = (PDBEntry) pdbe.elementAt(pe);
4049 if (!pdbentry.getId().equals(pdbEntryString)
4050 && !pdbentry.getFile().equals(pdbFile))
4060 if (pdbentry == null)
4062 pdbentry = new PDBEntry();
4063 pdbentry.setId(pdbEntryString);
4064 pdbentry.setFile(pdbFile);
4065 needtoadd = true; // add this new entry to sequence.
4067 // resolve data source
4068 // TODO: this code should be a refactored to an io package
4069 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(pdbFile,
4071 if (protocol == null)
4077 pdbentry.setProperty("protocol", protocol);
4078 toaddpdb.addPDBId(pdbentry);
4079 alignPanel.getStructureSelectionManager()
4080 .registerPDBEntry(pdbentry);
4086 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
4090 Vector sequences = new Vector();
4091 for (int i = 0; i < seqs.length; i++)
4093 if (seqs[i] != null)
4096 .addElement(new Object[]
4097 { seqs[i], (chains != null) ? chains[i] : null });
4100 seqs = new SequenceI[sequences.size()];
4101 chains = new String[sequences.size()];
4102 for (int i = 0, isize = sequences.size(); i < isize; i++)
4104 Object[] oj = (Object[]) sequences.elementAt(i);
4106 seqs[i] = (SequenceI) oj[0];
4107 chains[i] = (String) oj[1];
4110 return new Object[] { seqs, chains };
4114 public void newStructureView(JalviewLite applet, PDBEntry pdb,
4115 SequenceI[] seqs, String[] chains, DataSourceType protocol)
4117 // Scrub any null sequences from the array
4118 Object[] sqch = cleanSeqChainArrays(seqs, chains);
4119 seqs = (SequenceI[]) sqch[0];
4120 chains = (String[]) sqch[1];
4121 if (seqs == null || seqs.length == 0)
4124 "JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
4126 if (protocol == null)
4128 String sourceType = (String) pdb.getProperty("protocol");
4131 protocol = DataSourceType.valueOf(sourceType);
4132 } catch (IllegalArgumentException e)
4136 if (protocol == null)
4138 System.err.println("Couldn't work out protocol to open structure: "
4143 if (applet.useXtrnalSviewer)
4145 // register the association(s) and quit, don't create any windows.
4146 if (StructureSelectionManager.getStructureSelectionManager(applet)
4147 .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
4149 System.err.println("Failed to map " + pdb.getFile() + " ("
4150 + protocol + ") to any sequences");
4154 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
4156 // can only do alignments with Jmol
4157 // find the last jmol window assigned to this alignment
4158 AppletJmol ajm = null, tajm;
4159 Vector jmols = applet.getAppletWindow(AppletJmol.class);
4160 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
4162 tajm = (AppletJmol) jmols.elementAt(i);
4163 if (tajm.ap.alignFrame == this)
4172 "Incremental adding and aligning structure to existing Jmol view not yet implemented.");
4173 // try and add the pdb structure
4178 // otherwise, create a new window
4179 if (applet.jmolAvailable)
4181 new AppletJmol(pdb, seqs, chains, alignPanel, protocol);
4182 applet.lastFrameX += 40;
4183 applet.lastFrameY += 40;
4187 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
4192 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
4193 SequenceI[][] seqs, String[][] chains, String[] protocols)
4195 // TODO Auto-generated method stub
4196 System.err.println("Aligned Structure View: Not yet implemented.");
4200 * modify the current selection, providing the user has not made a selection
4204 * - sequences from this alignment
4206 * - columns to be selected on the alignment
4208 public void select(SequenceGroup sel, ColumnSelection csel,
4209 HiddenColumns hidden)
4211 alignPanel.seqPanel.selection(sel, csel, hidden, null);
4214 public void scrollTo(int row, int column)
4216 alignPanel.seqPanel.scrollTo(row, column);
4219 public void scrollToRow(int row)
4221 alignPanel.seqPanel.scrollToRow(row);
4224 public void scrollToColumn(int column)
4226 alignPanel.seqPanel.scrollToColumn(column);
4230 * @return the alignments unique ID.
4232 public String getSequenceSetId()
4234 return viewport.getSequenceSetId();
4238 * Load the (T-Coffee) score file from the specified url
4241 * File/URL/T-COFFEE score file contents
4242 * @throws IOException
4243 * @return true if alignment was annotated with data from source
4245 public boolean loadScoreFile(String source) throws IOException
4248 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
4249 AppletFormatAdapter.checkProtocol(source));
4250 if (!file.isValid())
4252 // TODO: raise dialog for gui
4253 System.err.println("Problems parsing T-Coffee scores: "
4254 + file.getWarningMessage());
4255 System.err.println("Origin was:\n" + source);
4260 * check that the score matrix matches the alignment dimensions
4263 if ((aln = viewport.getAlignment()) != null
4264 && (aln.getHeight() != file.getHeight()
4265 || aln.getWidth() != file.getWidth()))
4267 // TODO: raise a dialog box here rather than bomb out.
4269 "The scores matrix does not match the alignment dimensions");
4273 // TODO add parameter to indicate if matching should be done
4274 if (file.annotateAlignment(alignPanel.getAlignment(), false))
4276 alignPanel.fontChanged();
4277 tcoffeeColour.setEnabled(true);
4278 // switch to this color
4279 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4284 System.err.println("Problems resolving T-Coffee scores:");
4285 if (file.getWarningMessage() != null)
4287 System.err.println(file.getWarningMessage());
4293 public SplitFrame getSplitFrame()
4295 return this.splitFrame;
4298 public void setSplitFrame(SplitFrame sf)
4300 this.splitFrame = sf;
4303 // may not need this
4305 public void setShowSeqFeatures(boolean b)
4307 // showSeqFeatures.setSelected(b);
4308 viewport.setShowSequenceFeatures(b);
4313 public void setMenusForViewport()
4315 // setMenusFromViewport(viewport);
4320 public void refreshFeatureUI(boolean enableIfNecessary)
4322 if (enableIfNecessary)
4324 sequenceFeatures.setState(true);
4325 alignPanel.av.setShowSequenceFeatures(true);
4330 public FeatureSettingsControllerI getFeatureSettingsUI()
4332 return alignPanel.av.featureSettings;