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;
109 import java.io.UnsupportedEncodingException;
111 import java.net.URLEncoder;
112 import java.util.Arrays;
113 import java.util.Deque;
114 import java.util.HashMap;
115 import java.util.List;
116 import java.util.Map;
117 import java.util.StringTokenizer;
118 import java.util.Vector;
120 import org.jmol.viewer.Viewer;
122 public class AlignFrame extends EmbmenuFrame implements ActionListener,
123 ItemListener, KeyListener, AlignViewControllerGuiI
125 public AlignViewControllerI avc;
127 public AlignmentPanel alignPanel;
129 public AlignViewport viewport;
131 // width and height may be overridden by applet parameters
132 int frameWidth = 700;
134 int frameHeight = 500;
136 String jalviewServletURL;
139 * Flag for showing autocalculated consensus above or below other consensus
142 private boolean showAutoCalculatedAbove;
144 private SequenceAnnotationOrder annotationSortOrder;
147 * Constructor that creates the frame and adds it to the display.
154 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
157 this(al, applet, title, embedded, true);
161 * Constructor that optionally allows the frame to be displayed or only
168 * @param addToDisplay
170 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
171 boolean embedded, boolean addToDisplay)
173 this(al, null, null, applet, title, embedded, addToDisplay);
176 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
177 HiddenColumns hidden, JalviewLite applet, String title,
180 this(al, hiddenSeqs, hidden, applet, title, embedded, true);
183 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
184 HiddenColumns hidden, JalviewLite applet, String title,
185 boolean embedded, boolean addToDisplay)
189 jalviewServletURL = applet.getParameter("APPLICATION_URL");
195 } catch (Exception ex)
197 ex.printStackTrace();
199 // need to get window geometry before we calculate alignment layout
205 param = applet.getParameter("windowWidth");
208 int width = Integer.parseInt(param);
211 param = applet.getParameter("windowHeight");
214 int height = Integer.parseInt(param);
215 frameHeight = height;
217 } catch (Exception ex)
221 viewport = new AlignViewport(al, applet);
223 if (hiddenSeqs != null && hiddenSeqs.length > 0)
225 viewport.hideSequence(hiddenSeqs);
229 viewport.getAlignment().setHiddenColumns(hidden);
231 viewport.setScaleAboveWrapped(scaleAbove.getState());
233 alignPanel = new AlignmentPanel(this, viewport);
234 avc = new jalview.controller.AlignViewController(this, viewport,
236 viewport.updateConservation(alignPanel);
237 viewport.updateConsensus(alignPanel);
239 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
240 followMouseOverFlag.setState(viewport.isFollowHighlight());
241 showGroupConsensus.setState(viewport.isShowGroupConsensus());
242 showGroupConservation.setState(viewport.isShowGroupConservation());
243 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
244 showSequenceLogo.setState(viewport.isShowSequenceLogo());
245 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
246 applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
247 annotationPanelMenuItem.setState(viewport.isShowAnnotation());
248 showAlignmentAnnotations.setEnabled(annotationPanelMenuItem.getState());
249 showSequenceAnnotations.setEnabled(annotationPanelMenuItem.getState());
250 showAlignmentAnnotations.setState(true);
251 showSequenceAnnotations.setState(false);
253 seqLimits.setState(viewport.getShowJVSuffix());
257 String param = applet.getParameter("sortBy");
260 if (param.equalsIgnoreCase("Id"))
262 sortIDMenuItem_actionPerformed();
264 else if (param.equalsIgnoreCase("Pairwise Identity"))
266 sortPairwiseMenuItem_actionPerformed();
268 else if (param.equalsIgnoreCase("Length"))
270 sortLengthMenuItem_actionPerformed();
274 param = applet.getParameter("wrap");
277 if (param.equalsIgnoreCase("true"))
279 wrapMenuItem.setState(true);
280 wrapMenuItem_actionPerformed();
283 param = applet.getParameter("centrecolumnlabels");
286 centreColumnLabelFlag.setState(true);
287 centreColumnLabelFlag_stateChanged();
291 if (viewport.getAlignment().isNucleotide())
293 conservationMenuItem.setEnabled(false);
294 clustalColour.setEnabled(false);
295 BLOSUM62Colour.setEnabled(false);
296 zappoColour.setEnabled(false);
297 taylorColour.setEnabled(false);
298 hydrophobicityColour.setEnabled(false);
299 helixColour.setEnabled(false);
300 strandColour.setEnabled(false);
301 turnColour.setEnabled(false);
302 buriedColour.setEnabled(false);
303 viewport.updateStrucConsensus(alignPanel);
304 if (viewport.getAlignment().hasRNAStructure())
306 RNAHelixColour.setEnabled(true);
310 RNAHelixColour.setEnabled(false);
315 RNAHelixColour.setEnabled(false);
316 purinePyrimidineColour.setEnabled(false);
317 nucleotideColour.setEnabled(false);
319 // Some JVMS send keyevents to Top frame or lowest panel,
320 // Havent worked out why yet. So add to both this frame and seqCanvas for
322 this.addKeyListener(this);
323 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
324 alignPanel.idPanel.idCanvas.addKeyListener(this);
325 alignPanel.scalePanel.addKeyListener(this);
326 alignPanel.annotationPanel.addKeyListener(this);
327 alignPanel.annotationPanelHolder.addKeyListener(this);
328 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
329 alignPanel.alabels.addKeyListener(this);
331 setAnnotationsVisibility();
335 addToDisplay(embedded);
342 public void addToDisplay(boolean embedded)
344 createAlignFrameWindow(embedded);
346 alignPanel.adjustAnnotationHeight();
347 alignPanel.paintAlignment(true, true);
350 public AlignViewport getAlignViewport()
355 public SeqCanvas getSeqcanvas()
357 return alignPanel.seqPanel.seqCanvas;
361 * Load a features file onto the alignment
364 * file URL, content, or other resolvable path
366 * is protocol for accessing data referred to by file
369 public boolean parseFeaturesFile(String file, DataSourceType type)
371 return parseFeaturesFile(file, type, true);
375 * Load a features file onto the alignment
378 * file URL, content, or other resolvable path
380 * is protocol for accessing data referred to by file
381 * @param autoenabledisplay
382 * when true, display features flag will be automatically enabled if
383 * features are loaded
384 * @return true if data parsed as a features file
386 public boolean parseFeaturesFile(String file, DataSourceType sourceType,
387 boolean autoenabledisplay)
389 boolean featuresFile = false;
392 Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
393 .getFeatureRenderer().getFeatureColours();
394 boolean relaxedIdMatching = viewport.applet
395 .getDefaultParameter("relaxedidmatch", false);
396 featuresFile = new FeaturesFile(file, sourceType).parse(
397 viewport.getAlignment(), colours, true, relaxedIdMatching);
398 } catch (Exception ex)
400 ex.printStackTrace();
405 if (autoenabledisplay)
407 viewport.setShowSequenceFeatures(true);
408 sequenceFeatures.setState(true);
410 if (alignPanel.seqPanel.seqCanvas.fr != null)
412 // update the min/max ranges where necessary
413 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
415 if (viewport.featureSettings != null)
417 viewport.featureSettings.refreshTable();
419 alignPanel.paintAlignment(true, true);
420 statusBar.setText(MessageManager
421 .getString("label.successfully_added_features_alignment"));
427 public void keyPressed(KeyEvent evt)
429 ViewportRanges ranges = viewport.getRanges();
431 if (viewport.cursorMode
432 && ((evt.getKeyCode() >= KeyEvent.VK_0
433 && evt.getKeyCode() <= KeyEvent.VK_9)
434 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
435 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
436 && Character.isDigit(evt.getKeyChar()))
438 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
441 switch (evt.getKeyCode())
443 case 27: // escape key
444 deselectAllSequenceMenuItem_actionPerformed();
446 alignPanel.alabels.cancelDrag();
449 if (evt.isControlDown() || evt.isMetaDown())
451 cut_actionPerformed();
455 if (viewport.cursorMode && !evt.isControlDown())
457 alignPanel.seqPanel.setCursorColumn();
459 if (evt.isControlDown() || evt.isMetaDown())
461 copy_actionPerformed();
465 if (evt.isControlDown())
467 paste(evt.isShiftDown());
471 if (evt.isControlDown() || evt.isMetaDown())
473 selectAllSequenceMenuItem_actionPerformed();
476 case KeyEvent.VK_DOWN:
477 if (viewport.cursorMode)
479 alignPanel.seqPanel.moveCursor(0, 1);
483 moveSelectedSequences(false);
488 if (viewport.cursorMode)
490 alignPanel.seqPanel.moveCursor(0, -1);
494 moveSelectedSequences(true);
498 case KeyEvent.VK_LEFT:
499 if (evt.isAltDown() || !viewport.cursorMode)
501 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
505 alignPanel.seqPanel.moveCursor(-1, 0);
509 case KeyEvent.VK_RIGHT:
510 if (evt.isAltDown() || !viewport.cursorMode)
512 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
516 alignPanel.seqPanel.moveCursor(1, 0);
520 case KeyEvent.VK_SPACE:
521 if (viewport.cursorMode)
523 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
524 || evt.isShiftDown() || evt.isAltDown());
528 case KeyEvent.VK_DELETE:
529 case KeyEvent.VK_BACK_SPACE:
530 if (viewport.cursorMode)
532 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
533 || evt.isShiftDown() || evt.isAltDown());
537 cut_actionPerformed();
538 alignPanel.seqPanel.seqCanvas.repaint();
543 if (viewport.cursorMode)
545 alignPanel.seqPanel.setCursorRow();
549 if (viewport.cursorMode)
551 alignPanel.seqPanel.setCursorPosition();
555 case KeyEvent.VK_ENTER:
556 case KeyEvent.VK_COMMA:
557 if (viewport.cursorMode)
559 alignPanel.seqPanel.setCursorRowAndColumn();
564 if (viewport.cursorMode)
566 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
570 if (viewport.cursorMode)
572 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
577 viewport.cursorMode = !viewport.cursorMode;
578 statusBar.setText(MessageManager
579 .formatMessage("label.keyboard_editing_mode", new String[]
580 { (viewport.cursorMode ? "on" : "off") }));
581 if (viewport.cursorMode)
583 alignPanel.seqPanel.seqCanvas.cursorX = ranges.getStartRes();
584 alignPanel.seqPanel.seqCanvas.cursorY = ranges.getStartSeq();
589 if (evt.isControlDown())
591 findMenuItem_actionPerformed();
597 boolean toggleSeqs = !evt.isControlDown();
598 boolean toggleCols = !evt.isShiftDown();
599 toggleHiddenRegions(toggleSeqs, toggleCols);
603 case KeyEvent.VK_PAGE_UP:
607 case KeyEvent.VK_PAGE_DOWN:
612 if (evt.isControlDown())
614 undoMenuItem_actionPerformed();
619 if (evt.isControlDown())
621 redoMenuItem_actionPerformed();
626 if (evt.isControlDown())
633 if (evt.isControlDown())
635 trimAlignment(false);
640 if (evt.isControlDown())
642 if (evt.isShiftDown())
644 this.removeAllGapsMenuItem_actionPerformed();
648 removeGappedColumnMenuItem_actionPerformed();
653 if (evt.isControlDown())
657 invertColSel_actionPerformed();
661 invertSequenceMenuItem_actionPerformed();
667 if (evt.isControlDown())
669 if (evt.isShiftDown())
671 this.unGroup_actionPerformed();
675 this.createGroup_actionPerformed();
681 if (evt.isControlDown())
683 this.deleteGroups_actionPerformed();
688 if (evt.isControlDown())
695 // TODO: repaint flags set only if the keystroke warrants it
696 alignPanel.paintAlignment(true, true);
700 * called by key handler and the hide all/show all menu items
705 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
707 boolean hide = false;
708 SequenceGroup sg = viewport.getSelectionGroup();
709 if (!toggleSeqs && !toggleCols)
711 // Hide everything by the current selection - this is a hack - we do the
712 // invert and then hide
713 // first check that there will be visible columns after the invert.
714 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
715 && sg.getStartRes() <= sg.getEndRes()))
717 // now invert the sequence set, if required - empty selection implies
718 // that no hiding is required.
721 invertSequenceMenuItem_actionPerformed();
722 sg = viewport.getSelectionGroup();
726 viewport.expandColSelection(sg, true);
727 // finally invert the column selection and get the new sequence
728 // selection and indicate it should be hidden.
729 invertColSel_actionPerformed();
736 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
739 viewport.hideAllSelectedSeqs();
741 else if (!(toggleCols && viewport.hasSelectedColumns()))
743 viewport.showAllHiddenSeqs();
749 if (viewport.hasSelectedColumns())
751 viewport.hideSelectedColumns();
754 viewport.setSelectionGroup(sg);
759 viewport.showAllHiddenColumns();
761 viewport.sendSelection();
766 public void keyReleased(KeyEvent evt)
771 public void keyTyped(KeyEvent evt)
776 public void itemStateChanged(ItemEvent evt)
778 final Object source = evt.getSource();
779 if (source == displayNonconservedMenuItem)
781 displayNonconservedMenuItem_actionPerformed();
783 else if (source == colourTextMenuItem)
785 colourTextMenuItem_actionPerformed();
787 else if (source == wrapMenuItem)
789 wrapMenuItem_actionPerformed();
791 else if (source == scaleAbove)
793 viewport.setScaleAboveWrapped(scaleAbove.getState());
795 else if (source == scaleLeft)
797 viewport.setScaleLeftWrapped(scaleLeft.getState());
799 else if (source == scaleRight)
801 viewport.setScaleRightWrapped(scaleRight.getState());
803 else if (source == seqLimits)
805 seqLimits_itemStateChanged();
807 else if (source == viewBoxesMenuItem)
809 viewport.setShowBoxes(viewBoxesMenuItem.getState());
811 else if (source == viewTextMenuItem)
813 viewport.setShowText(viewTextMenuItem.getState());
815 else if (source == renderGapsMenuItem)
817 viewport.setRenderGaps(renderGapsMenuItem.getState());
819 else if (source == annotationPanelMenuItem)
821 boolean showAnnotations = annotationPanelMenuItem.getState();
822 showAlignmentAnnotations.setEnabled(showAnnotations);
823 showSequenceAnnotations.setEnabled(showAnnotations);
824 viewport.setShowAnnotation(showAnnotations);
825 alignPanel.setAnnotationVisible(showAnnotations);
827 else if (source == sequenceFeatures)
829 viewport.setShowSequenceFeatures(sequenceFeatures.getState());
830 alignPanel.seqPanel.seqCanvas.repaint();
832 else if (source == showAlignmentAnnotations)
834 setAnnotationsVisibility();
836 else if (source == showSequenceAnnotations)
838 setAnnotationsVisibility();
840 else if (source == sortAnnBySequence)
842 boolean newState = sortAnnBySequence.getState();
843 sortAnnByLabel.setState(false);
844 setAnnotationSortOrder(
845 newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
846 : SequenceAnnotationOrder.NONE);
847 setViewportAnnotationOrder();
849 else if (source == sortAnnByLabel)
851 boolean newState = sortAnnByLabel.getState();
852 sortAnnBySequence.setState(false);
853 setAnnotationSortOrder(
854 newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
855 : SequenceAnnotationOrder.NONE);
856 setViewportAnnotationOrder();
858 else if (source == showAutoFirst)
860 showAutoLast.setState(!showAutoFirst.getState());
861 setShowAutoCalculatedAbove(showAutoFirst.getState());
862 setViewportAnnotationOrder();
864 else if (source == showAutoLast)
866 showAutoFirst.setState(!showAutoLast.getState());
867 setShowAutoCalculatedAbove(showAutoFirst.getState());
868 setViewportAnnotationOrder();
870 else if (source == conservationMenuItem)
872 conservationMenuItem_actionPerformed();
874 else if (source == abovePIDThreshold)
876 abovePIDThreshold_actionPerformed();
878 else if (source == applyToAllGroups)
880 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
882 else if (source == autoCalculate)
884 viewport.autoCalculateConsensus = autoCalculate.getState();
886 else if (source == sortByTree)
888 viewport.sortByTree = sortByTree.getState();
890 else if (source == this.centreColumnLabelFlag)
892 centreColumnLabelFlag_stateChanged();
894 else if (source == this.followMouseOverFlag)
896 mouseOverFlag_stateChanged();
898 else if (source == showGroupConsensus)
900 showGroupConsensus_actionPerformed();
902 else if (source == showGroupConservation)
904 showGroupConservation_actionPerformed();
906 else if (source == showSequenceLogo)
908 showSequenceLogo_actionPerformed();
910 else if (source == normSequenceLogo)
912 normSequenceLogo_actionPerformed();
914 else if (source == showConsensusHistogram)
916 showConsensusHistogram_actionPerformed();
918 else if (source == applyAutoAnnotationSettings)
920 applyAutoAnnotationSettings_actionPerformed();
922 // TODO: repaint flags set only if warranted
923 alignPanel.paintAlignment(true, true);
927 * Set the visibility state of sequence-related and/or alignment-related
928 * annotations depending on checkbox selections, and repaint.
932 private void setAnnotationsVisibility()
934 boolean showForAlignment = showAlignmentAnnotations.getState();
935 boolean showForSequences = showSequenceAnnotations.getState();
936 if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
938 for (AlignmentAnnotation aa : alignPanel.getAlignment()
939 .getAlignmentAnnotation())
941 boolean visible = (aa.sequenceRef == null ? showForAlignment
943 aa.visible = visible;
946 alignPanel.validateAnnotationDimensions(true);
951 private void setAnnotationSortOrder(SequenceAnnotationOrder order)
953 this.annotationSortOrder = order;
957 * Set flags on the viewport that control annotation ordering
959 private void setViewportAnnotationOrder()
961 this.alignPanel.av.setSortAnnotationsBy(this.annotationSortOrder);
963 .setShowAutocalculatedAbove(this.showAutoCalculatedAbove);
966 private void setShowAutoCalculatedAbove(boolean showAbove)
968 this.showAutoCalculatedAbove = showAbove;
971 private void mouseOverFlag_stateChanged()
973 viewport.setFollowHighlight(followMouseOverFlag.getState());
974 // TODO: could kick the scrollTo mechanism to reset view for current
978 private void centreColumnLabelFlag_stateChanged()
980 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
981 this.alignPanel.annotationPanel.repaint();
985 public void actionPerformed(ActionEvent evt)
987 viewport.applet.currentAlignFrame = this;
989 Object source = evt.getSource();
991 if (source == inputText)
993 inputText_actionPerformed();
995 else if (source == loadTree)
997 loadTree_actionPerformed();
999 else if (source == loadApplication)
1001 launchFullApplication();
1003 else if (source == loadAnnotations)
1007 else if (source == outputAnnotations)
1009 outputAnnotations(true);
1011 else if (source == outputFeatures)
1013 outputFeatures(true, "Jalview");
1015 else if (source == closeMenuItem)
1017 closeMenuItem_actionPerformed();
1019 else if (source == copy)
1021 copy_actionPerformed();
1023 else if (source == undoMenuItem)
1025 undoMenuItem_actionPerformed();
1027 else if (source == redoMenuItem)
1029 redoMenuItem_actionPerformed();
1031 else if (source == inputText)
1033 inputText_actionPerformed();
1035 else if (source == closeMenuItem)
1037 closeMenuItem_actionPerformed();
1039 else if (source == undoMenuItem)
1041 undoMenuItem_actionPerformed();
1043 else if (source == redoMenuItem)
1045 redoMenuItem_actionPerformed();
1047 else if (source == copy)
1049 copy_actionPerformed();
1051 else if (source == pasteNew)
1053 pasteNew_actionPerformed();
1055 else if (source == pasteThis)
1057 pasteThis_actionPerformed();
1059 else if (source == cut)
1061 cut_actionPerformed();
1063 else if (source == delete)
1065 delete_actionPerformed();
1067 else if (source == createGroup)
1069 createGroup_actionPerformed();
1071 else if (source == unGroup)
1073 unGroup_actionPerformed();
1075 else if (source == grpsFromSelection)
1077 makeGrpsFromSelection_actionPerformed();
1079 else if (source == deleteGroups)
1081 deleteGroups_actionPerformed();
1083 else if (source == selectAllSequenceMenuItem)
1085 selectAllSequenceMenuItem_actionPerformed();
1087 else if (source == deselectAllSequenceMenuItem)
1089 deselectAllSequenceMenuItem_actionPerformed();
1091 else if (source == invertSequenceMenuItem)
1093 invertSequenceMenuItem_actionPerformed();
1094 // uncomment to slave sequence selections in split frame
1095 // viewport.sendSelection();
1097 else if (source == invertColSel)
1099 viewport.invertColumnSelection();
1100 alignPanel.paintAlignment(false, false);
1101 viewport.sendSelection();
1103 else if (source == remove2LeftMenuItem)
1105 trimAlignment(true);
1107 else if (source == remove2RightMenuItem)
1109 trimAlignment(false);
1111 else if (source == removeGappedColumnMenuItem)
1113 removeGappedColumnMenuItem_actionPerformed();
1115 else if (source == removeAllGapsMenuItem)
1117 removeAllGapsMenuItem_actionPerformed();
1119 else if (source == findMenuItem)
1121 findMenuItem_actionPerformed();
1123 else if (source == font)
1125 new FontChooser(alignPanel);
1127 else if (source == newView)
1131 else if (source == showColumns)
1133 viewport.showAllHiddenColumns();
1134 alignPanel.paintAlignment(true, true);
1135 viewport.sendSelection();
1137 else if (source == showSeqs)
1139 viewport.showAllHiddenSeqs();
1140 alignPanel.paintAlignment(true, true);
1141 // uncomment if we want to slave sequence selections in split frame
1142 // viewport.sendSelection();
1144 else if (source == hideColumns)
1146 viewport.hideSelectedColumns();
1147 alignPanel.paintAlignment(true, true);
1148 viewport.sendSelection();
1150 else if (source == hideSequences
1151 && viewport.getSelectionGroup() != null)
1153 viewport.hideAllSelectedSeqs();
1154 alignPanel.paintAlignment(true, true);
1155 // uncomment if we want to slave sequence selections in split frame
1156 // viewport.sendSelection();
1158 else if (source == hideAllButSelection)
1160 toggleHiddenRegions(false, false);
1161 alignPanel.paintAlignment(true, true);
1162 viewport.sendSelection();
1164 else if (source == hideAllSelection)
1166 SequenceGroup sg = viewport.getSelectionGroup();
1167 viewport.expandColSelection(sg, false);
1168 viewport.hideAllSelectedSeqs();
1169 viewport.hideSelectedColumns();
1170 alignPanel.paintAlignment(true, true);
1171 viewport.sendSelection();
1173 else if (source == showAllHidden)
1175 viewport.showAllHiddenColumns();
1176 viewport.showAllHiddenSeqs();
1177 alignPanel.paintAlignment(true, true);
1178 viewport.sendSelection();
1180 else if (source == showGroupConsensus)
1182 showGroupConsensus_actionPerformed();
1184 else if (source == showGroupConservation)
1186 showGroupConservation_actionPerformed();
1188 else if (source == showSequenceLogo)
1190 showSequenceLogo_actionPerformed();
1192 else if (source == normSequenceLogo)
1194 normSequenceLogo_actionPerformed();
1196 else if (source == showConsensusHistogram)
1198 showConsensusHistogram_actionPerformed();
1200 else if (source == applyAutoAnnotationSettings)
1202 applyAutoAnnotationSettings_actionPerformed();
1204 else if (source == featureSettings)
1206 new FeatureSettings(alignPanel);
1208 else if (source == alProperties)
1210 StringBuffer contents = new jalview.io.AlignmentProperties(
1211 viewport.getAlignment()).formatAsString();
1212 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1213 cap.setText(contents.toString());
1214 Frame frame = new Frame();
1216 jalview.bin.JalviewLite.addFrame(frame, MessageManager
1217 .formatMessage("label.alignment_properties", new String[]
1218 { getTitle() }), 400, 250);
1220 else if (source == overviewMenuItem)
1222 overviewMenuItem_actionPerformed();
1224 else if (source == noColourmenuItem)
1228 else if (source == clustalColour)
1230 abovePIDThreshold.setState(false);
1231 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1233 else if (source == zappoColour)
1235 changeColour(new ZappoColourScheme());
1237 else if (source == taylorColour)
1239 changeColour(new TaylorColourScheme());
1241 else if (source == hydrophobicityColour)
1243 changeColour(new HydrophobicColourScheme());
1245 else if (source == helixColour)
1247 changeColour(new HelixColourScheme());
1249 else if (source == strandColour)
1251 changeColour(new StrandColourScheme());
1253 else if (source == turnColour)
1255 changeColour(new TurnColourScheme());
1257 else if (source == buriedColour)
1259 changeColour(new BuriedColourScheme());
1261 else if (source == nucleotideColour)
1263 changeColour(new NucleotideColourScheme());
1265 else if (source == purinePyrimidineColour)
1267 changeColour(new PurinePyrimidineColourScheme());
1269 // else if (source == RNAInteractionColour)
1271 // changeColour(new RNAInteractionColourScheme());
1273 else if (source == RNAHelixColour)
1275 changeColour(new RNAHelicesColour(viewport.getAlignment()));
1276 // new RNAHelicesColourChooser(viewport, alignPanel);
1278 else if (source == modifyPID)
1280 modifyPID_actionPerformed();
1282 else if (source == modifyConservation)
1284 modifyConservation_actionPerformed();
1286 else if (source == userDefinedColour)
1288 new UserDefinedColours(alignPanel, null);
1290 else if (source == PIDColour)
1292 changeColour(new PIDColourScheme());
1294 else if (source == BLOSUM62Colour)
1296 changeColour(new Blosum62ColourScheme());
1298 else if (source == tcoffeeColour)
1300 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1302 else if (source == annotationColour)
1304 new AnnotationColourChooser(viewport, alignPanel);
1306 else if (source == annotationColumnSelection)
1308 new AnnotationColumnChooser(viewport, alignPanel);
1310 else if (source == sortPairwiseMenuItem)
1312 sortPairwiseMenuItem_actionPerformed();
1314 else if (source == sortIDMenuItem)
1316 sortIDMenuItem_actionPerformed();
1318 else if (source == sortLengthMenuItem)
1320 sortLengthMenuItem_actionPerformed();
1322 else if (source == sortGroupMenuItem)
1324 sortGroupMenuItem_actionPerformed();
1326 else if (source == removeRedundancyMenuItem)
1328 removeRedundancyMenuItem_actionPerformed();
1330 else if (source == pairwiseAlignmentMenuItem)
1332 pairwiseAlignmentMenuItem_actionPerformed();
1334 else if (source == PCAMenuItem)
1336 PCAMenuItem_actionPerformed();
1338 else if (source == averageDistanceTreeMenuItem)
1340 averageDistanceTreeMenuItem_actionPerformed();
1342 else if (source == neighbourTreeMenuItem)
1344 neighbourTreeMenuItem_actionPerformed();
1346 else if (source == njTreeBlosumMenuItem)
1348 njTreeBlosumMenuItem_actionPerformed();
1350 else if (source == avDistanceTreeBlosumMenuItem)
1352 avTreeBlosumMenuItem_actionPerformed();
1354 else if (source == documentation)
1356 documentation_actionPerformed();
1358 else if (source == about)
1360 about_actionPerformed();
1365 public void inputText_actionPerformed()
1367 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1368 Frame frame = new Frame();
1370 jalview.bin.JalviewLite.addFrame(frame,
1371 MessageManager.getString("label.input_cut_paste"), 500, 500);
1374 protected void outputText_actionPerformed(ActionEvent e)
1376 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1377 Frame frame = new Frame();
1379 JalviewLite.addFrame(frame, MessageManager
1380 .formatMessage("label.alignment_output_command", new Object[]
1381 { e.getActionCommand() }), 600, 500);
1383 FileFormatI fileFormat = FileFormats.getInstance()
1384 .forName(e.getActionCommand());
1386 new AppletFormatAdapter(alignPanel).formatSequences(fileFormat,
1387 viewport.getAlignment(), viewport.getShowJVSuffix()));
1390 public void loadAnnotations()
1392 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1393 cap.setText(MessageManager
1394 .getString("label.paste_features_annotations_Tcoffee_here"));
1395 cap.setAnnotationImport();
1396 Frame frame = new Frame();
1398 jalview.bin.JalviewLite.addFrame(frame,
1399 MessageManager.getString("action.paste_annotations"), 400, 300);
1403 public String outputAnnotations(boolean displayTextbox)
1405 String annotation = new AnnotationFile()
1406 .printAnnotationsForView(viewport);
1410 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1411 Frame frame = new Frame();
1413 jalview.bin.JalviewLite.addFrame(frame,
1414 MessageManager.getString("label.annotations"), 600, 500);
1415 cap.setText(annotation);
1421 private Map<String, FeatureColourI> getDisplayedFeatureCols()
1423 if (alignPanel.getFeatureRenderer() != null
1424 && viewport.getFeaturesDisplayed() != null)
1426 return alignPanel.getFeatureRenderer().getDisplayedFeatureCols();
1432 private List<String> getDisplayedFeatureGroups()
1434 if (alignPanel.getFeatureRenderer() != null
1435 && viewport.getFeaturesDisplayed() != null)
1437 return alignPanel.getFeatureRenderer().getDisplayedFeatureGroups();
1443 public String outputFeatures(boolean displayTextbox, String format)
1446 FeaturesFile formatter = new FeaturesFile();
1447 if (format.equalsIgnoreCase("Jalview"))
1449 features = formatter.printJalviewFormat(
1450 viewport.getAlignment().getSequencesArray(),
1451 alignPanel.getFeatureRenderer(), true, false);
1455 features = formatter.printGffFormat(viewport.getAlignment()
1456 .getSequencesArray(), alignPanel.getFeatureRenderer(), true,
1462 boolean frimport = false;
1463 if (features == null || features.equals("No Features Visible"))
1465 features = "# No features visible - paste some and import them here.";
1469 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1472 cap.setAnnotationImport();
1474 Frame frame = new Frame();
1476 jalview.bin.JalviewLite.addFrame(frame,
1477 MessageManager.getString("label.features"), 600, 500);
1478 cap.setText(features);
1482 if (features == null)
1491 void launchFullApplication()
1493 StringBuffer url = new StringBuffer(jalviewServletURL);
1495 // allow servlet parameters to be passed in applet parameter
1496 String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
1498 url.append(firstSep);
1501 "open=" + appendProtocol(viewport.applet.getParameter("file")));
1503 if (viewport.applet.getParameter("features") != null)
1505 url.append("&features=");
1506 url.append(appendProtocol(viewport.applet.getParameter("features")));
1509 if (viewport.applet.getParameter("annotations") != null)
1511 url.append("&annotations=");
1513 appendProtocol(viewport.applet.getParameter("annotations")));
1516 if (viewport.applet.getParameter("jnetfile") != null
1517 || viewport.applet.getParameter("jpredfile") != null)
1519 url.append("&annotations=");
1520 url.append(appendProtocol(
1521 viewport.applet.getParameter("jnetfile") != null
1522 ? viewport.applet.getParameter("jnetfile")
1523 : viewport.applet.getParameter("jpredfile")));
1526 if (viewport.applet.getParameter("defaultColour") != null)
1528 url.append("&colour=" + removeWhiteSpace(
1529 viewport.applet.getParameter("defaultColour")));
1532 if (viewport.applet.getParameter("userDefinedColour") != null)
1534 url.append("&colour=" + removeWhiteSpace(
1535 viewport.applet.getParameter("userDefinedColour")));
1537 if (viewport.applet.getParameter("tree") != null)
1540 + appendProtocol(viewport.applet.getParameter("tree")));
1542 if (viewport.applet.getParameter("treeFile") != null)
1545 + appendProtocol(viewport.applet.getParameter("treeFile")));
1548 showURL(url.toString(), "FULL_APP");
1551 String removeWhiteSpace(String colour)
1553 StringBuffer sb = new StringBuffer();
1554 for (int i = 0; i < colour.length(); i++)
1556 if (Character.isWhitespace(colour.charAt(i)))
1562 sb.append(colour.charAt(i));
1566 return sb.toString();
1569 String appendProtocol(String url)
1574 url = URLEncoder.encode(url, "UTF-8");
1577 * When we finally deprecate 1.1 compatibility, we can start to use
1578 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1579 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1580 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1581 * ex.printStackTrace(); }
1583 catch (java.net.MalformedURLException ex)
1585 url = viewport.applet.getCodeBase() + url;
1587 catch (UnsupportedEncodingException ex)
1590 "WARNING = IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "
1592 ex.printStackTrace();
1597 public void closeMenuItem_actionPerformed()
1599 PaintRefresher.RemoveComponent(alignPanel);
1600 if (alignPanel.seqPanel != null
1601 && alignPanel.seqPanel.seqCanvas != null)
1603 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1605 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1607 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1610 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1616 if (alignPanel != null && alignPanel.overviewPanel != null)
1618 alignPanel.overviewPanel.dispose();
1627 void updateEditMenuBar()
1630 if (viewport.getHistoryList().size() > 0)
1632 undoMenuItem.setEnabled(true);
1633 CommandI command = viewport.getHistoryList().peek();
1634 undoMenuItem.setLabel(MessageManager
1635 .formatMessage("label.undo_command", new Object[]
1636 { command.getDescription() }));
1640 undoMenuItem.setEnabled(false);
1641 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1644 if (viewport.getRedoList().size() > 0)
1646 redoMenuItem.setEnabled(true);
1648 CommandI command = viewport.getRedoList().peek();
1649 redoMenuItem.setLabel(MessageManager
1650 .formatMessage("label.redo_command", new Object[]
1651 { command.getDescription() }));
1655 redoMenuItem.setEnabled(false);
1656 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1664 public void addHistoryItem(CommandI command)
1666 if (command.getSize() > 0)
1668 viewport.addToHistoryList(command);
1669 viewport.clearRedoList();
1670 updateEditMenuBar();
1671 viewport.updateHiddenColumns();
1676 * TODO: JAL-1104 DOCUMENT ME!
1681 protected void undoMenuItem_actionPerformed()
1683 if (viewport.getHistoryList().isEmpty())
1688 CommandI command = viewport.getHistoryList().pop();
1689 viewport.addToRedoList(command);
1690 command.undoCommand(null);
1692 AlignmentViewport originalSource = getOriginatingSource(command);
1694 if (originalSource != viewport)
1697 .println("Warning: Viewport object mismatch whilst undoing");
1699 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1700 // viewport.getColumnSelection().getHiddenColumns()
1702 updateEditMenuBar();
1703 originalSource.firePropertyChange("alignment", null,
1704 originalSource.getAlignment().getSequences());
1708 * TODO: JAL-1104 DOCUMENT ME!
1713 protected void redoMenuItem_actionPerformed()
1715 if (viewport.getRedoList().isEmpty())
1720 CommandI command = viewport.getRedoList().pop();
1721 viewport.addToHistoryList(command);
1722 command.doCommand(null);
1724 AlignmentViewport originalSource = getOriginatingSource(command);
1726 if (originalSource != viewport)
1729 .println("Warning: Viewport object mismatch whilst re-doing");
1731 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1732 // viewport.getColumnSelection().getHiddenColumns()
1735 updateEditMenuBar();
1736 originalSource.firePropertyChange("alignment", null,
1737 originalSource.getAlignment().getSequences());
1740 AlignmentViewport getOriginatingSource(CommandI command)
1742 AlignmentViewport originalSource = null;
1743 // For sequence removal and addition, we need to fire
1744 // the property change event FROM the viewport where the
1745 // original alignment was altered
1746 AlignmentI al = null;
1747 if (command instanceof EditCommand)
1749 EditCommand editCommand = (EditCommand) command;
1750 al = editCommand.getAlignment();
1751 Vector comps = PaintRefresher.components
1752 .get(viewport.getSequenceSetId());
1753 for (int i = 0; i < comps.size(); i++)
1755 if (comps.elementAt(i) instanceof AlignmentPanel)
1757 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1759 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1766 if (originalSource == null)
1768 // The original view is closed, we must validate
1769 // the current view against the closed view first
1772 PaintRefresher.validateSequences(al, viewport.getAlignment());
1775 originalSource = viewport;
1778 return originalSource;
1782 * Move the currently selected sequences up or down one position in the
1787 public void moveSelectedSequences(boolean up)
1789 SequenceGroup sg = viewport.getSelectionGroup();
1794 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1795 up ? null : viewport.getHiddenRepSequences(), up);
1796 alignPanel.paintAlignment(true, false);
1799 * Also move cDNA/protein complement sequences
1801 AlignViewportI complement = viewport.getCodingComplement();
1802 if (complement != null)
1804 SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
1805 viewport, complement);
1806 complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
1807 up ? null : complement.getHiddenRepSequences(), up);
1808 getSplitFrame().getComplement(this).alignPanel.paintAlignment(true,
1813 synchronized void slideSequences(boolean right, int size)
1815 List<SequenceI> sg = new Vector<>();
1816 if (viewport.cursorMode)
1818 sg.add(viewport.getAlignment()
1819 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1821 else if (viewport.getSelectionGroup() != null
1822 && viewport.getSelectionGroup().getSize() != viewport
1823 .getAlignment().getHeight())
1825 sg = viewport.getSelectionGroup()
1826 .getSequences(viewport.getHiddenRepSequences());
1834 Vector<SequenceI> invertGroup = new Vector();
1836 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1838 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1840 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1844 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1846 SequenceI[] seqs2 = invertGroup
1847 .toArray(new SequenceI[invertGroup.size()]);
1848 for (int i = 0; i < invertGroup.size(); i++)
1850 seqs2[i] = invertGroup.elementAt(i);
1853 SlideSequencesCommand ssc;
1856 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1857 viewport.getGapCharacter());
1861 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1862 viewport.getGapCharacter());
1865 int groupAdjustment = 0;
1866 if (ssc.getGapsInsertedBegin() && right)
1868 if (viewport.cursorMode)
1870 alignPanel.seqPanel.moveCursor(size, 0);
1874 groupAdjustment = size;
1877 else if (!ssc.getGapsInsertedBegin() && !right)
1879 if (viewport.cursorMode)
1881 alignPanel.seqPanel.moveCursor(-size, 0);
1885 groupAdjustment = -size;
1889 if (groupAdjustment != 0)
1891 viewport.getSelectionGroup().setStartRes(
1892 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1893 viewport.getSelectionGroup().setEndRes(
1894 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1897 boolean appendHistoryItem = false;
1898 Deque<CommandI> historyList = viewport.getHistoryList();
1899 if (historyList != null && historyList.size() > 0
1900 && historyList.peek() instanceof SlideSequencesCommand)
1902 appendHistoryItem = ssc.appendSlideCommand(
1903 (SlideSequencesCommand) historyList.peek());
1906 if (!appendHistoryItem)
1908 addHistoryItem(ssc);
1914 static StringBuffer copiedSequences;
1916 static HiddenColumns copiedHiddenColumns;
1918 protected void copy_actionPerformed()
1920 if (viewport.getSelectionGroup() == null)
1925 SequenceGroup sg = viewport.getSelectionGroup();
1926 copiedSequences = new StringBuffer();
1927 Map<Integer, SequenceI> orderedSeqs = new HashMap<>();
1928 for (int i = 0; i < sg.getSize(); i++)
1930 SequenceI seq = sg.getSequenceAt(i);
1931 int index = viewport.getAlignment().findIndex(seq);
1932 orderedSeqs.put(index, seq);
1935 int index = 0, startRes, endRes;
1938 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1940 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1941 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
1943 // create new HiddenColumns object with copy of hidden regions
1944 // between startRes and endRes, offset by startRes
1945 copiedHiddenColumns = new HiddenColumns(
1946 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
1947 hiddenCutoff, hiddenOffset);
1951 copiedHiddenColumns = null;
1954 for (int i = 0; i < sg.getSize(); i++)
1956 SequenceI seq = null;
1960 if (orderedSeqs.containsKey(index))
1962 seq = orderedSeqs.get(index);
1973 // Returns residue following index if gap
1974 startRes = seq.findPosition(sg.getStartRes());
1977 // Need to find the residue preceeding index if gap
1980 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1982 ch = seq.getCharAt(j);
1983 if (!jalview.util.Comparison.isGap((ch)))
1991 endRes += seq.getStart() - 1;
1994 copiedSequences.append(seq.getName() + "\t" + startRes + "\t" + endRes
1995 + "\t" + seq.getSequenceAsString(sg.getStartRes(),
2002 protected void pasteNew_actionPerformed()
2007 protected void pasteThis_actionPerformed()
2012 void paste(boolean newAlignment)
2016 if (copiedSequences == null)
2021 StringTokenizer st = new StringTokenizer(copiedSequences.toString(),
2023 Vector seqs = new Vector();
2024 while (st.hasMoreElements())
2026 String name = st.nextToken();
2027 int start = Integer.parseInt(st.nextToken());
2028 int end = Integer.parseInt(st.nextToken());
2029 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
2031 SequenceI[] newSeqs = new SequenceI[seqs.size()];
2032 for (int i = 0; i < seqs.size(); i++)
2034 newSeqs[i] = (SequenceI) seqs.elementAt(i);
2039 String newtitle = MessageManager
2040 .getString("label.copied_sequences");
2041 if (getTitle().startsWith(
2042 MessageManager.getString("label.copied_sequences")))
2044 newtitle = getTitle();
2048 newtitle = newtitle.concat(MessageManager
2049 .formatMessage("label.from_msname", new String[]
2052 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
2053 viewport.applet, newtitle, false);
2054 af.viewport.setHiddenColumns(copiedHiddenColumns);
2056 jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
2061 addSequences(newSeqs);
2064 } catch (Exception ex)
2066 } // could be anything being pasted in here
2070 void addSequences(SequenceI[] seqs)
2072 for (int i = 0; i < seqs.length; i++)
2074 viewport.getAlignment().addSequence(seqs[i]);
2078 addHistoryItem(new EditCommand(
2079 MessageManager.getString("label.add_sequences"), Action.PASTE,
2080 seqs, 0, viewport.getAlignment().getWidth(),
2081 viewport.getAlignment()));
2083 viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight());
2084 viewport.getAlignment().getWidth();
2085 viewport.firePropertyChange("alignment", null,
2086 viewport.getAlignment().getSequences());
2090 protected void cut_actionPerformed()
2092 copy_actionPerformed();
2093 delete_actionPerformed();
2096 protected void delete_actionPerformed()
2099 SequenceGroup sg = viewport.getSelectionGroup();
2105 Vector seqs = new Vector();
2107 for (int i = 0; i < sg.getSize(); i++)
2109 seq = sg.getSequenceAt(i);
2110 seqs.addElement(seq);
2114 * If the cut affects all sequences, warn, remove highlighted columns
2116 if (sg.getSize() == viewport.getAlignment().getHeight())
2118 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
2119 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2120 if (isEntireAlignWidth)
2122 String title = MessageManager.getString("label.delete_all");
2123 Panel infoPanel = new Panel();
2124 infoPanel.setLayout(new FlowLayout());
2126 new Label(MessageManager.getString("warn.delete_all")));
2128 final JVDialog dialog = new JVDialog(this, title, true, 400, 200);
2129 dialog.setMainPanel(infoPanel);
2130 dialog.ok.setLabel(MessageManager.getString("action.ok"));
2131 dialog.cancel.setLabel(MessageManager.getString("action.cancel"));
2132 dialog.setVisible(true);
2139 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2140 sg.getEndRes() + 1);
2143 SequenceI[] cut = new SequenceI[seqs.size()];
2144 for (int i = 0; i < seqs.size(); i++)
2146 cut[i] = (SequenceI) seqs.elementAt(i);
2150 * //ADD HISTORY ITEM
2152 addHistoryItem(new EditCommand(
2153 MessageManager.getString("label.cut_sequences"), Action.CUT,
2154 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2155 viewport.getAlignment()));
2157 viewport.setSelectionGroup(null);
2158 viewport.getAlignment().deleteGroup(sg);
2160 viewport.firePropertyChange("alignment", null,
2161 viewport.getAlignment().getSequences());
2163 if (viewport.getAlignment().getHeight() < 1)
2165 this.setVisible(false);
2167 viewport.sendSelection();
2171 * group consensus toggled
2174 protected void showGroupConsensus_actionPerformed()
2176 viewport.setShowGroupConsensus(showGroupConsensus.getState());
2177 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2182 * group conservation toggled.
2184 protected void showGroupConservation_actionPerformed()
2186 viewport.setShowGroupConservation(showGroupConservation.getState());
2187 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2194 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
2195 * .event.ActionEvent)
2197 protected void showConsensusHistogram_actionPerformed()
2199 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
2200 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2207 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
2208 * .event.ActionEvent)
2210 protected void showSequenceLogo_actionPerformed()
2212 viewport.setShowSequenceLogo(showSequenceLogo.getState());
2213 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2216 protected void normSequenceLogo_actionPerformed()
2218 showSequenceLogo.setState(true);
2219 viewport.setShowSequenceLogo(true);
2220 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
2221 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2224 protected void applyAutoAnnotationSettings_actionPerformed()
2226 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2229 protected void makeGrpsFromSelection_actionPerformed()
2231 if (avc.makeGroupsFromSelection())
2233 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2234 alignPanel.updateAnnotation();
2235 alignPanel.paintAlignment(true, true);
2239 protected void createGroup_actionPerformed()
2244 protected void unGroup_actionPerformed()
2248 alignPanel.alignmentChanged();
2252 protected void deleteGroups_actionPerformed()
2254 if (avc.deleteGroups())
2256 alignPanel.alignmentChanged();
2260 public void selectAllSequenceMenuItem_actionPerformed()
2262 SequenceGroup sg = new SequenceGroup();
2263 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2265 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2267 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2268 viewport.setSelectionGroup(sg);
2269 // JAL-2034 - should delegate to
2270 // alignPanel to decide if overview needs
2272 alignPanel.paintAlignment(false, false);
2273 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2274 viewport.sendSelection();
2277 public void deselectAllSequenceMenuItem_actionPerformed()
2279 if (viewport.cursorMode)
2281 alignPanel.seqPanel.keyboardNo1 = null;
2282 alignPanel.seqPanel.keyboardNo2 = null;
2284 viewport.setSelectionGroup(null);
2285 viewport.getColumnSelection().clear();
2286 viewport.setSelectionGroup(null);
2287 alignPanel.idPanel.idCanvas.searchResults = null;
2288 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2289 // JAL-2034 - should delegate to
2290 // alignPanel to decide if overview needs
2292 alignPanel.paintAlignment(false, false);
2293 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2294 viewport.sendSelection();
2297 public void invertSequenceMenuItem_actionPerformed()
2299 SequenceGroup sg = viewport.getSelectionGroup();
2300 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2302 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2305 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2306 viewport.sendSelection();
2309 public void invertColSel_actionPerformed()
2311 viewport.invertColumnSelection();
2312 alignPanel.paintAlignment(true, false);
2313 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2314 viewport.sendSelection();
2317 void trimAlignment(boolean trimLeft)
2319 AlignmentI al = viewport.getAlignment();
2320 ViewportRanges ranges = viewport.getRanges();
2321 ColumnSelection colSel = viewport.getColumnSelection();
2324 if (!colSel.isEmpty())
2328 column = colSel.getMin();
2332 column = colSel.getMax();
2336 if (viewport.getSelectionGroup() != null)
2338 seqs = viewport.getSelectionGroup()
2339 .getSequencesAsArray(viewport.getHiddenRepSequences());
2343 seqs = al.getSequencesArray();
2346 TrimRegionCommand trimRegion;
2349 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2351 ranges.setStartRes(0);
2355 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2359 statusBar.setText(MessageManager
2360 .formatMessage("label.removed_columns", new String[]
2361 { Integer.valueOf(trimRegion.getSize()).toString() }));
2362 addHistoryItem(trimRegion);
2364 for (SequenceGroup sg : al.getGroups())
2366 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2367 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2373 viewport.firePropertyChange("alignment", null, al.getSequences());
2377 public void removeGappedColumnMenuItem_actionPerformed()
2379 AlignmentI al = viewport.getAlignment();
2380 ViewportRanges ranges = viewport.getRanges();
2382 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2385 if (viewport.getSelectionGroup() != null)
2387 seqs = viewport.getSelectionGroup()
2388 .getSequencesAsArray(viewport.getHiddenRepSequences());
2389 start = viewport.getSelectionGroup().getStartRes();
2390 end = viewport.getSelectionGroup().getEndRes();
2394 seqs = viewport.getAlignment().getSequencesArray();
2397 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2398 "Remove Gapped Columns", seqs, start, end,
2399 viewport.getAlignment());
2401 addHistoryItem(removeGapCols);
2403 statusBar.setText(MessageManager
2404 .formatMessage("label.removed_empty_columns", new String[]
2405 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2407 // This is to maintain viewport position on first residue
2408 // of first sequence
2409 SequenceI seq = al.getSequenceAt(0);
2410 int startRes = seq.findPosition(ranges.getStartRes());
2411 // ShiftList shifts;
2412 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2413 // edit.alColumnChanges=shifts.getInverse();
2414 // if (viewport.hasHiddenColumns)
2415 // viewport.getColumnSelection().compensateForEdits(shifts);
2416 ranges.setStartRes(seq.findIndex(startRes) - 1);
2417 viewport.firePropertyChange("alignment", null, al.getSequences());
2421 public void removeAllGapsMenuItem_actionPerformed()
2423 AlignmentI al = viewport.getAlignment();
2424 ViewportRanges ranges = viewport.getRanges();
2426 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2429 if (viewport.getSelectionGroup() != null)
2431 seqs = viewport.getSelectionGroup()
2432 .getSequencesAsArray(viewport.getHiddenRepSequences());
2433 start = viewport.getSelectionGroup().getStartRes();
2434 end = viewport.getSelectionGroup().getEndRes();
2438 seqs = viewport.getAlignment().getSequencesArray();
2441 // This is to maintain viewport position on first residue
2442 // of first sequence
2443 SequenceI seq = al.getSequenceAt(0);
2444 int startRes = seq.findPosition(ranges.getStartRes());
2447 new RemoveGapsCommand("Remove Gaps", seqs, start, end, al));
2449 ranges.setStartRes(seq.findIndex(startRes) - 1);
2451 viewport.firePropertyChange("alignment", null, al.getSequences());
2455 public void findMenuItem_actionPerformed()
2457 new Finder(alignPanel);
2461 * create a new view derived from the current view
2464 * @return frame for the new view
2466 public AlignFrame newView(String viewtitle)
2469 if (viewport.hasHiddenRows())
2471 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2472 .getFullAlignment().getSequencesArray());
2476 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2479 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2481 for (int i = 0; i < viewport.getAlignment()
2482 .getAlignmentAnnotation().length; i++)
2484 if (!viewport.getAlignment()
2485 .getAlignmentAnnotation()[i].autoCalculated)
2487 newal.addAnnotation(
2488 viewport.getAlignment().getAlignmentAnnotation()[i]);
2493 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2495 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2496 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2497 PaintRefresher.Register(newaf.alignPanel,
2498 newaf.alignPanel.av.getSequenceSetId());
2500 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2501 newaf.alignPanel.av.getSequenceSetId());
2502 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2503 newaf.alignPanel.av.getSequenceSetId());
2505 Vector comps = PaintRefresher.components
2506 .get(viewport.getSequenceSetId());
2508 for (int i = 0; i < comps.size(); i++)
2510 if (comps.elementAt(i) instanceof AlignmentPanel)
2516 String title = new String(this.getTitle());
2517 if (viewtitle != null)
2519 title = viewtitle + " ( " + title + ")";
2523 if (title.indexOf("(View") > -1)
2525 title = title.substring(0, title.indexOf("(View"));
2527 title += "(View " + viewSize + ")";
2530 newaf.setTitle(title.toString());
2532 newaf.viewport.setHistoryList(viewport.getHistoryList());
2533 newaf.viewport.setRedoList(viewport.getRedoList());
2539 * @return list of feature groups on the view
2541 public String[] getFeatureGroups()
2543 FeatureRenderer fr = null;
2544 if (alignPanel != null
2545 && (fr = alignPanel.getFeatureRenderer()) != null)
2547 List<String> gps = fr.getFeatureGroups();
2548 String[] _gps = gps.toArray(new String[gps.size()]);
2555 * get sequence feature groups that are hidden or shown
2561 public String[] getFeatureGroupsOfState(boolean visible)
2563 FeatureRenderer fr = null;
2564 if (alignPanel != null
2565 && (fr = alignPanel.getFeatureRenderer()) != null)
2567 List<String> gps = fr.getGroups(visible);
2568 String[] _gps = gps.toArray(new String[gps.size()]);
2575 * Change the display state for the given feature groups
2578 * list of group strings
2580 * visible or invisible
2582 public void setFeatureGroupState(String[] groups, boolean state)
2584 FeatureRenderer fr = null;
2585 this.sequenceFeatures.setState(true);
2586 viewport.setShowSequenceFeatures(true);
2587 if (alignPanel != null
2588 && (fr = alignPanel.getFeatureRenderer()) != null)
2591 fr.setGroupVisibility(Arrays.asList(groups), state);
2592 alignPanel.seqPanel.seqCanvas.repaint();
2593 if (alignPanel.overviewPanel != null)
2595 alignPanel.overviewPanel.updateOverviewImage();
2600 public void seqLimits_itemStateChanged()
2602 viewport.setShowJVSuffix(seqLimits.getState());
2603 alignPanel.fontChanged();
2604 alignPanel.paintAlignment(true, false);
2607 protected void colourTextMenuItem_actionPerformed()
2609 viewport.setColourText(colourTextMenuItem.getState());
2610 alignPanel.paintAlignment(false, false);
2613 protected void displayNonconservedMenuItem_actionPerformed()
2615 viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
2616 alignPanel.paintAlignment(false, false);
2619 protected void wrapMenuItem_actionPerformed()
2621 viewport.setWrapAlignment(wrapMenuItem.getState());
2622 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2623 scaleAbove.setEnabled(wrapMenuItem.getState());
2624 scaleLeft.setEnabled(wrapMenuItem.getState());
2625 scaleRight.setEnabled(wrapMenuItem.getState());
2626 alignPanel.paintAlignment(true, false);
2629 public void overviewMenuItem_actionPerformed()
2631 if (alignPanel.overviewPanel != null)
2636 Frame frame = new Frame();
2637 final OverviewPanel overview = new OverviewPanel(alignPanel);
2638 frame.add(overview);
2639 // +50 must allow for applet frame window
2640 jalview.bin.JalviewLite.addFrame(frame, MessageManager
2641 .formatMessage("label.overview_params", new String[]
2642 { this.getTitle() }), overview.getPreferredSize().width,
2643 overview.getPreferredSize().height + 50);
2646 final AlignmentPanel ap = alignPanel;
2647 frame.addWindowListener(new WindowAdapter()
2650 public void windowClosing(WindowEvent e)
2655 ap.setOverviewPanel(null);
2660 alignPanel.setOverviewPanel(overview);
2665 public void changeColour(ColourSchemeI cs)
2667 viewport.setGlobalColourScheme(cs);
2669 alignPanel.paintAlignment(true, true);
2672 protected void modifyPID_actionPerformed()
2674 if (viewport.getAbovePIDThreshold()
2675 && viewport.getGlobalColourScheme() != null)
2677 SliderPanel.setPIDSliderSource(alignPanel,
2678 viewport.getResidueShading(), alignPanel.getViewName());
2679 SliderPanel.showPIDSlider();
2683 protected void modifyConservation_actionPerformed()
2685 if (viewport.getConservationSelected()
2686 && viewport.getGlobalColourScheme() != null)
2688 SliderPanel.setConservationSlider(alignPanel,
2689 viewport.getResidueShading(), alignPanel.getViewName());
2690 SliderPanel.showConservationSlider();
2694 protected void conservationMenuItem_actionPerformed()
2696 boolean selected = conservationMenuItem.getState();
2697 modifyConservation.setEnabled(selected);
2698 viewport.setConservationSelected(selected);
2699 viewport.getResidueShading().setConservationApplied(selected);
2701 changeColour(viewport.getGlobalColourScheme());
2705 modifyConservation_actionPerformed();
2709 SliderPanel.hideConservationSlider();
2713 public void abovePIDThreshold_actionPerformed()
2715 boolean selected = abovePIDThreshold.getState();
2716 modifyPID.setEnabled(selected);
2717 viewport.setAbovePIDThreshold(selected);
2720 viewport.getResidueShading().setThreshold(0,
2721 viewport.isIgnoreGapsConsensus());
2724 changeColour(viewport.getGlobalColourScheme());
2728 modifyPID_actionPerformed();
2732 SliderPanel.hidePIDSlider();
2736 public void sortPairwiseMenuItem_actionPerformed()
2738 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2739 AlignmentSorter.sortByPID(viewport.getAlignment(),
2740 viewport.getAlignment().getSequenceAt(0));
2742 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2743 viewport.getAlignment()));
2744 alignPanel.paintAlignment(true, false);
2747 public void sortIDMenuItem_actionPerformed()
2749 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2750 AlignmentSorter.sortByID(viewport.getAlignment());
2752 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
2753 alignPanel.paintAlignment(true, false);
2756 public void sortLengthMenuItem_actionPerformed()
2758 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2759 AlignmentSorter.sortByLength(viewport.getAlignment());
2760 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2761 viewport.getAlignment()));
2762 alignPanel.paintAlignment(true, false);
2765 public void sortGroupMenuItem_actionPerformed()
2767 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2768 AlignmentSorter.sortByGroup(viewport.getAlignment());
2769 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2770 viewport.getAlignment()));
2771 alignPanel.paintAlignment(true, false);
2775 public void removeRedundancyMenuItem_actionPerformed()
2777 new RedundancyPanel(alignPanel);
2780 public void pairwiseAlignmentMenuItem_actionPerformed()
2782 if (viewport.getSelectionGroup() != null
2783 && viewport.getSelectionGroup().getSize() > 1)
2785 Frame frame = new Frame();
2786 frame.add(new PairwiseAlignPanel(alignPanel));
2787 jalview.bin.JalviewLite.addFrame(frame,
2788 MessageManager.getString("action.pairwise_alignment"), 600,
2793 public void PCAMenuItem_actionPerformed()
2795 // are the sequences aligned?
2796 if (!viewport.getAlignment().isAligned(false))
2799 int Width = viewport.getAlignment().getWidth();
2801 for (int i = 0; i < viewport.getAlignment().getSequences()
2804 current = viewport.getAlignment().getSequenceAt(i);
2806 if (current.getLength() < Width)
2808 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2811 alignPanel.paintAlignment(false, false);
2814 if ((viewport.getSelectionGroup() != null
2815 && viewport.getSelectionGroup().getSize() < 4
2816 && viewport.getSelectionGroup().getSize() > 0)
2817 || viewport.getAlignment().getHeight() < 4)
2824 new PCAPanel(viewport);
2825 } catch (java.lang.OutOfMemoryError ex)
2831 public void averageDistanceTreeMenuItem_actionPerformed()
2833 newTreePanel(TreeBuilder.AVERAGE_DISTANCE, new PIDModel().getName(),
2834 "Average distance tree using PID");
2837 public void neighbourTreeMenuItem_actionPerformed()
2839 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING, new PIDModel().getName(),
2840 "Neighbour joining tree using PID");
2843 protected void njTreeBlosumMenuItem_actionPerformed()
2845 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING,
2846 ScoreModels.getInstance().getBlosum62().getName(),
2847 "Neighbour joining tree using BLOSUM62");
2850 protected void avTreeBlosumMenuItem_actionPerformed()
2852 newTreePanel(TreeBuilder.AVERAGE_DISTANCE,
2853 ScoreModels.getInstance().getBlosum62().getName(),
2854 "Average distance tree using BLOSUM62");
2857 void newTreePanel(String type, String pwType, String title)
2859 // are the sequences aligned?
2860 if (!viewport.getAlignment().isAligned(false))
2863 int Width = viewport.getAlignment().getWidth();
2865 for (int i = 0; i < viewport.getAlignment().getSequences()
2868 current = viewport.getAlignment().getSequenceAt(i);
2870 if (current.getLength() < Width)
2872 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2875 alignPanel.paintAlignment(false, false);
2879 if ((viewport.getSelectionGroup() != null
2880 && viewport.getSelectionGroup().getSize() > 1)
2881 || (viewport.getAlignment().getHeight() > 1))
2883 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2885 addTreeMenuItem(tp, title);
2887 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2891 void loadTree_actionPerformed()
2893 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2894 cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2895 cap.setTreeImport();
2896 Frame frame = new Frame();
2898 jalview.bin.JalviewLite.addFrame(frame,
2899 MessageManager.getString("label.paste_newick_file"), 400, 300);
2902 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2904 TreePanel tp = new TreePanel(alignPanel, treeFile,
2905 MessageManager.getString("label.load_tree_from_file"), tree);
2906 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2907 addTreeMenuItem(tp, treeFile);
2911 * sort the alignment using the given treePanel
2914 * tree used to sort view
2916 * string used for undo event name
2918 public void sortByTree(TreePanel treePanel, String title)
2920 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2921 AlignmentSorter.sortByTree(viewport.getAlignment(),
2922 treePanel.getTree());
2923 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2924 // HistoryItem.SORT));
2925 addHistoryItem(new OrderCommand(MessageManager
2926 .formatMessage("label.order_by_params", new String[]
2927 { title }), oldOrder, viewport.getAlignment()));
2928 alignPanel.paintAlignment(true, false);
2932 * Do any automatic reordering of the alignment and add the necessary bits to
2933 * the menu structure for the new tree
2938 protected void addTreeMenuItem(final TreePanel treePanel,
2941 final MenuItem item = new MenuItem(title);
2942 sortByTreeMenu.add(item);
2943 item.addActionListener(new java.awt.event.ActionListener()
2946 public void actionPerformed(ActionEvent evt)
2948 sortByTree(treePanel, title); // treePanel.getTitle());
2952 treePanel.addWindowListener(new WindowAdapter()
2955 public void windowOpened(WindowEvent e)
2957 if (viewport.sortByTree)
2959 sortByTree(treePanel, title);
2961 super.windowOpened(e);
2965 public void windowClosing(WindowEvent e)
2967 sortByTreeMenu.remove(item);
2972 public boolean sortBy(AlignmentOrder alorder, String undoname)
2974 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2975 if (viewport.applet.debug)
2977 System.err.println("Sorting " + alorder.getOrder().size()
2978 + " in alignment '" + getTitle() + "'");
2980 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2981 if (undoname != null)
2983 addHistoryItem(new OrderCommand(undoname, oldOrder,
2984 viewport.getAlignment()));
2986 alignPanel.paintAlignment(true, false);
2990 protected void documentation_actionPerformed()
2992 alignPanel.av.applet.openJalviewHelpUrl();
2995 protected void about_actionPerformed()
2998 class AboutPanel extends Canvas
3004 public AboutPanel(String version, String builddate)
3006 this.version = version;
3007 this.builddate = builddate;
3011 public void paint(Graphics g)
3013 g.setColor(Color.white);
3014 g.fillRect(0, 0, getSize().width, getSize().height);
3015 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3016 FontMetrics fm = g.getFontMetrics();
3017 int fh = fm.getHeight();
3019 g.setColor(Color.black);
3020 // TODO: update this text for each release or centrally store it for
3021 // lite and application
3022 g.setFont(new Font("Helvetica", Font.BOLD, 14));
3023 g.drawString(MessageManager
3024 .formatMessage("label.jalviewLite_release", new String[]
3025 { version }), x, y += fh);
3026 g.setFont(new Font("Helvetica", Font.BOLD, 12));
3027 g.drawString(MessageManager.formatMessage("label.jaview_build_date",
3029 { builddate }), x, y += fh);
3030 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3031 g.drawString(MessageManager.getString("label.jalview_authors_1"), x,
3033 g.drawString(MessageManager.getString("label.jalview_authors_2"),
3034 x + 50, y += fh + 8);
3035 g.drawString(MessageManager.getString("label.jalview_dev_managers"),
3037 g.drawString(MessageManager
3038 .getString("label.jalview_distribution_lists"), x, y += fh);
3039 g.drawString(MessageManager.getString("label.jalview_please_cite"),
3042 MessageManager.getString("label.jalview_cite_1_authors"), x,
3044 g.drawString(MessageManager.getString("label.jalview_cite_1_title"),
3046 g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
3051 Frame frame = new Frame();
3052 frame.add(new AboutPanel(JalviewLite.getVersion(),
3053 JalviewLite.getBuildDate()));
3054 jalview.bin.JalviewLite.addFrame(frame,
3055 MessageManager.getString("label.jalview"), 580, 220);
3059 public void showURL(String url, String target)
3061 if (viewport.applet == null)
3063 System.out.println("Not running as applet - no browser available.");
3067 viewport.applet.showURL(url, target);
3071 // ////////////////////////////////////////////////////////////////////////////////
3072 // JBuilder Graphics here
3074 MenuBar alignFrameMenuBar = new MenuBar();
3076 Menu fileMenu = new Menu(MessageManager.getString("action.file"));
3078 MenuItem loadApplication = new MenuItem(
3079 MessageManager.getString("label.view_full_application"));
3081 MenuItem loadTree = new MenuItem(
3082 MessageManager.getString("label.load_associated_tree"));
3084 MenuItem loadAnnotations = new MenuItem(
3085 MessageManager.getString("label.load_features_annotations"));
3087 MenuItem outputFeatures = new MenuItem(
3088 MessageManager.getString("label.export_features"));
3090 MenuItem outputAnnotations = new MenuItem(
3091 MessageManager.getString("label.export_annotations"));
3093 MenuItem closeMenuItem = new MenuItem(
3094 MessageManager.getString("action.close"));
3096 MenuItem selectAllSequenceMenuItem = new MenuItem(
3097 MessageManager.getString("action.select_all"));
3099 MenuItem deselectAllSequenceMenuItem = new MenuItem(
3100 MessageManager.getString("action.deselect_all"));
3102 MenuItem invertSequenceMenuItem = new MenuItem(
3103 MessageManager.getString("action.invert_selection"));
3105 MenuItem remove2LeftMenuItem = new MenuItem();
3107 MenuItem remove2RightMenuItem = new MenuItem();
3109 MenuItem removeGappedColumnMenuItem = new MenuItem();
3111 MenuItem removeAllGapsMenuItem = new MenuItem();
3113 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
3115 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
3117 MenuItem sortPairwiseMenuItem = new MenuItem();
3119 MenuItem sortIDMenuItem = new MenuItem();
3121 MenuItem sortLengthMenuItem = new MenuItem();
3123 MenuItem sortGroupMenuItem = new MenuItem();
3125 MenuItem removeRedundancyMenuItem = new MenuItem();
3127 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
3129 MenuItem PCAMenuItem = new MenuItem();
3131 MenuItem averageDistanceTreeMenuItem = new MenuItem();
3133 MenuItem neighbourTreeMenuItem = new MenuItem();
3135 BorderLayout borderLayout1 = new BorderLayout();
3137 public Label statusBar = new Label();
3139 MenuItem clustalColour = new MenuItem();
3141 MenuItem zappoColour = new MenuItem();
3143 MenuItem taylorColour = new MenuItem();
3145 MenuItem hydrophobicityColour = new MenuItem();
3147 MenuItem helixColour = new MenuItem();
3149 MenuItem strandColour = new MenuItem();
3151 MenuItem turnColour = new MenuItem();
3153 MenuItem buriedColour = new MenuItem();
3155 MenuItem purinePyrimidineColour = new MenuItem();
3157 // MenuItem RNAInteractionColour = new MenuItem();
3159 MenuItem RNAHelixColour = new MenuItem();
3161 MenuItem userDefinedColour = new MenuItem();
3163 MenuItem PIDColour = new MenuItem();
3165 MenuItem BLOSUM62Colour = new MenuItem();
3167 MenuItem tcoffeeColour = new MenuItem();
3169 MenuItem njTreeBlosumMenuItem = new MenuItem();
3171 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
3173 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
3175 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
3177 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
3179 MenuItem alProperties = new MenuItem(
3180 MessageManager.getString("label.alignment_props"));
3182 MenuItem overviewMenuItem = new MenuItem();
3184 MenuItem undoMenuItem = new MenuItem();
3186 MenuItem redoMenuItem = new MenuItem();
3188 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
3190 MenuItem noColourmenuItem = new MenuItem();
3192 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
3194 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
3196 MenuItem findMenuItem = new MenuItem();
3198 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
3200 MenuItem nucleotideColour = new MenuItem();
3202 MenuItem deleteGroups = new MenuItem();
3204 MenuItem grpsFromSelection = new MenuItem();
3206 MenuItem createGroup = new MenuItem();
3208 MenuItem unGroup = new MenuItem();
3210 MenuItem delete = new MenuItem();
3212 MenuItem copy = new MenuItem();
3214 MenuItem cut = new MenuItem();
3216 Menu pasteMenu = new Menu();
3218 MenuItem pasteNew = new MenuItem();
3220 MenuItem pasteThis = new MenuItem();
3222 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
3224 MenuItem font = new MenuItem();
3226 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
3228 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
3230 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
3232 MenuItem modifyPID = new MenuItem();
3234 MenuItem modifyConservation = new MenuItem();
3236 CheckboxMenuItem autoCalculate = null;
3238 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
3239 "Sort Alignment With New Tree", true);
3241 Menu sortByTreeMenu = new Menu();
3243 MenuItem inputText = new MenuItem();
3245 MenuItem documentation = new MenuItem();
3247 MenuItem about = new MenuItem();
3249 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
3251 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
3253 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
3255 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
3257 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
3259 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
3261 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
3263 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
3265 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
3268 * Initialise menus and other items
3272 private void jbInit() throws Exception
3274 setMenuBar(alignFrameMenuBar);
3277 * Configure File menu items and actions
3280 .setLabel(MessageManager.getString("label.input_from_textbox"));
3281 inputText.addActionListener(this);
3282 Menu outputTextboxMenu = new Menu(
3283 MessageManager.getString("label.out_to_textbox"));
3284 for (String ff : FileFormats.getInstance().getWritableFormats(true))
3286 MenuItem item = new MenuItem(ff);
3288 item.addActionListener(new java.awt.event.ActionListener()
3291 public void actionPerformed(ActionEvent e)
3293 outputText_actionPerformed(e);
3297 outputTextboxMenu.add(item);
3299 closeMenuItem.addActionListener(this);
3300 loadApplication.addActionListener(this);
3301 loadTree.addActionListener(this);
3302 loadAnnotations.addActionListener(this);
3303 outputFeatures.addActionListener(this);
3304 outputAnnotations.addActionListener(this);
3307 * Configure Edit menu items and actions
3309 undoMenuItem.setEnabled(false);
3310 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3311 undoMenuItem.addActionListener(this);
3312 redoMenuItem.setEnabled(false);
3313 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3314 redoMenuItem.addActionListener(this);
3315 copy.setLabel(MessageManager.getString("action.copy"));
3316 copy.addActionListener(this);
3317 cut.setLabel(MessageManager.getString("action.cut"));
3318 cut.addActionListener(this);
3319 delete.setLabel(MessageManager.getString("action.delete"));
3320 delete.addActionListener(this);
3321 pasteMenu.setLabel(MessageManager.getString("action.paste"));
3322 pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3323 pasteNew.addActionListener(this);
3324 pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3325 pasteThis.addActionListener(this);
3327 .setLabel(MessageManager.getString("action.remove_left"));
3328 remove2LeftMenuItem.addActionListener(this);
3329 remove2RightMenuItem
3330 .setLabel(MessageManager.getString("action.remove_right"));
3331 remove2RightMenuItem.addActionListener(this);
3332 removeGappedColumnMenuItem.setLabel(
3333 MessageManager.getString("action.remove_empty_columns"));
3334 removeGappedColumnMenuItem.addActionListener(this);
3335 removeAllGapsMenuItem
3336 .setLabel(MessageManager.getString("action.remove_all_gaps"));
3337 removeAllGapsMenuItem.addActionListener(this);
3338 removeRedundancyMenuItem
3339 .setLabel(MessageManager.getString("action.remove_redundancy"));
3340 removeRedundancyMenuItem.addActionListener(this);
3343 * Configure Select menu items and actions
3345 findMenuItem.setLabel(MessageManager.getString("action.find"));
3346 findMenuItem.addActionListener(this);
3347 selectAllSequenceMenuItem.addActionListener(this);
3348 deselectAllSequenceMenuItem.addActionListener(this);
3349 invertSequenceMenuItem.setLabel(
3350 MessageManager.getString("action.invert_sequence_selection"));
3351 invertSequenceMenuItem.addActionListener(this);
3352 invertColSel.setLabel(
3353 MessageManager.getString("action.invert_column_selection"));
3354 invertColSel.addActionListener(this);
3356 .setLabel(MessageManager.getString("action.undefine_groups"));
3357 deleteGroups.addActionListener(this);
3358 grpsFromSelection.setLabel(
3359 MessageManager.getString("action.make_groups_selection"));
3360 grpsFromSelection.addActionListener(this);
3361 createGroup.setLabel(MessageManager.getString("action.create_group"));
3362 createGroup.addActionListener(this);
3363 unGroup.setLabel(MessageManager.getString("action.remove_group"));
3364 unGroup.addActionListener(this);
3366 annotationColumnSelection.setLabel(
3367 MessageManager.getString("action.select_by_annotation"));
3368 annotationColumnSelection.addActionListener(this);
3371 * Configure View menu items and actions
3373 newView.setLabel(MessageManager.getString("action.new_view"));
3374 newView.addActionListener(this);
3375 Menu showMenu = new Menu(MessageManager.getString("action.show"));
3376 showColumns.setLabel(MessageManager.getString("label.all_columns"));
3377 showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3378 Menu hideMenu = new Menu(MessageManager.getString("action.hide"));
3380 .setLabel(MessageManager.getString("label.selected_columns"));
3382 .setLabel(MessageManager.getString("label.selected_sequences"));
3383 hideAllButSelection.setLabel(
3384 MessageManager.getString("label.all_but_selected_region"));
3386 .setLabel(MessageManager.getString("label.selected_region"));
3387 showAllHidden.setLabel(
3388 MessageManager.getString("label.all_sequences_columns"));
3389 showColumns.addActionListener(this);
3390 showSeqs.addActionListener(this);
3391 hideColumns.addActionListener(this);
3392 hideSequences.addActionListener(this);
3393 hideAllButSelection.addActionListener(this);
3394 hideAllSelection.addActionListener(this);
3395 showAllHidden.addActionListener(this);
3397 .setLabel(MessageManager.getString("action.feature_settings"));
3398 featureSettings.addActionListener(this);
3399 sequenceFeatures.setLabel(
3400 MessageManager.getString("label.show_sequence_features"));
3401 sequenceFeatures.addItemListener(this);
3402 sequenceFeatures.setState(false);
3403 followMouseOverFlag.setLabel(
3404 MessageManager.getString("label.automatic_scrolling"));
3405 followMouseOverFlag.addItemListener(this);
3406 alProperties.addActionListener(this);
3408 .setLabel(MessageManager.getString("label.overview_window"));
3409 overviewMenuItem.addActionListener(this);
3412 * Configure Annotations menu items and actions
3414 annotationPanelMenuItem
3415 .setLabel(MessageManager.getString("label.show_annotations"));
3416 annotationPanelMenuItem.addItemListener(this);
3418 .setLabel(MessageManager.getString("label.group_consensus"));
3419 showGroupConservation
3420 .setLabel(MessageManager.getString("label.group_conservation"));
3421 showConsensusHistogram.setLabel(
3422 MessageManager.getString("label.show_consensus_histogram"));
3423 showSequenceLogo.setLabel(
3424 MessageManager.getString("label.show_consensus_logo"));
3425 normSequenceLogo.setLabel(
3426 MessageManager.getString("label.norm_consensus_logo"));
3427 applyAutoAnnotationSettings
3428 .setLabel(MessageManager.getString("label.apply_all_groups"));
3429 applyAutoAnnotationSettings.setState(true);
3430 Menu autoAnnMenu = new Menu(
3431 MessageManager.getString("label.autocalculated_annotation"));
3432 showGroupConsensus.addItemListener(this);
3433 showGroupConservation.addItemListener(this);
3434 showConsensusHistogram.addItemListener(this);
3435 showSequenceLogo.addItemListener(this);
3436 normSequenceLogo.addItemListener(this);
3437 applyAutoAnnotationSettings.addItemListener(this);
3438 showAlignmentAnnotations = new CheckboxMenuItem(
3439 MessageManager.getString("label.show_all_al_annotations"));
3440 showSequenceAnnotations = new CheckboxMenuItem(
3441 MessageManager.getString("label.show_all_seq_annotations"));
3442 sortAnnBySequence = new CheckboxMenuItem(
3443 MessageManager.getString("label.sort_annotations_by_sequence"));
3444 sortAnnByLabel = new CheckboxMenuItem(
3445 MessageManager.getString("label.sort_annotations_by_label"));
3446 showAutoFirst = new CheckboxMenuItem(
3447 MessageManager.getString("label.show_first"));
3448 showAutoFirst.setState(false); // pending applet parameter
3449 setShowAutoCalculatedAbove(showAutoFirst.getState());
3450 showAutoLast = new CheckboxMenuItem(
3451 MessageManager.getString("label.show_last"));
3452 showAutoLast.setState(!showAutoFirst.getState());
3453 showAlignmentAnnotations.addItemListener(this);
3454 showSequenceAnnotations.addItemListener(this);
3455 sortAnnBySequence.addItemListener(this);
3456 sortAnnByLabel.addItemListener(this);
3457 showAutoFirst.addItemListener(this);
3458 showAutoLast.addItemListener(this);
3461 * Configure Format menu items and actions
3463 font.setLabel(MessageManager.getString("action.font"));
3464 font.addActionListener(this);
3465 scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3466 scaleAbove.setState(true);
3467 scaleAbove.setEnabled(false);
3468 scaleAbove.addItemListener(this);
3469 scaleLeft.setEnabled(false);
3470 scaleLeft.setState(true);
3471 scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3472 scaleLeft.addItemListener(this);
3473 scaleRight.setEnabled(false);
3474 scaleRight.setState(true);
3475 scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3476 scaleRight.addItemListener(this);
3477 viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
3478 viewBoxesMenuItem.setState(true);
3479 viewBoxesMenuItem.addItemListener(this);
3480 viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
3481 viewTextMenuItem.setState(true);
3482 viewTextMenuItem.addItemListener(this);
3484 .setLabel(MessageManager.getString("label.colour_text"));
3485 colourTextMenuItem.addItemListener(this);
3486 displayNonconservedMenuItem
3487 .setLabel(MessageManager.getString("label.show_non_conserved"));
3488 displayNonconservedMenuItem.addItemListener(this);
3489 wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3490 wrapMenuItem.addItemListener(this);
3492 .setLabel(MessageManager.getString("action.show_gaps"));
3493 renderGapsMenuItem.setState(true);
3494 renderGapsMenuItem.addItemListener(this);
3495 centreColumnLabelFlag.setLabel(
3496 MessageManager.getString("label.centre_column_labels"));
3497 centreColumnLabelFlag.addItemListener(this);
3498 seqLimits.setState(true);
3500 MessageManager.getString("label.show_sequence_limits"));
3501 seqLimits.addItemListener(this);
3504 * Configure Colour menu items and actions
3506 applyToAllGroups.setLabel(
3507 MessageManager.getString("label.apply_colour_to_all_groups"));
3508 applyToAllGroups.setState(true);
3509 applyToAllGroups.addItemListener(this);
3510 clustalColour.setLabel(
3511 MessageManager.getString("label.colourScheme_clustal"));
3512 clustalColour.addActionListener(this);
3514 .setLabel(MessageManager.getString("label.colourScheme_zappo"));
3515 zappoColour.addActionListener(this);
3516 taylorColour.setLabel(
3517 MessageManager.getString("label.colourScheme_taylor"));
3518 taylorColour.addActionListener(this);
3519 hydrophobicityColour.setLabel(
3520 MessageManager.getString("label.colourScheme_hydrophobic"));
3521 hydrophobicityColour.addActionListener(this);
3522 helixColour.setLabel(MessageManager
3523 .getString("label.colourScheme_helix_propensity"));
3524 helixColour.addActionListener(this);
3525 strandColour.setLabel(MessageManager
3526 .getString("label.colourScheme_strand_propensity"));
3527 strandColour.addActionListener(this);
3528 turnColour.setLabel(
3529 MessageManager.getString("label.colourScheme_turn_propensity"));
3530 turnColour.addActionListener(this);
3531 buriedColour.setLabel(
3532 MessageManager.getString("label.colourScheme_buried_index"));
3533 buriedColour.addActionListener(this);
3534 purinePyrimidineColour.setLabel(MessageManager
3535 .getString("label.colourScheme_purine/pyrimidine"));
3536 purinePyrimidineColour.addActionListener(this);
3537 // RNAInteractionColour.setLabel(MessageManager
3538 // .getString("label.rna_interaction"));
3539 // RNAInteractionColour.addActionListener(this);
3540 RNAHelixColour.setLabel(
3541 MessageManager.getString("label.colourScheme_rna_helices"));
3542 RNAHelixColour.addActionListener(this);
3544 .setLabel(MessageManager.getString("action.user_defined"));
3545 userDefinedColour.addActionListener(this);
3547 MessageManager.getString("label.colourScheme_%_identity"));
3548 PIDColour.addActionListener(this);
3549 BLOSUM62Colour.setLabel(
3550 MessageManager.getString("label.colourScheme_blosum62"));
3551 BLOSUM62Colour.addActionListener(this);
3552 tcoffeeColour.setLabel(
3553 MessageManager.getString("label.colourScheme_t-coffee_scores"));
3554 // it will be enabled only if a score file is provided
3555 tcoffeeColour.setEnabled(false);
3556 tcoffeeColour.addActionListener(this);
3557 conservationMenuItem
3558 .setLabel(MessageManager.getString("action.by_conservation"));
3559 conservationMenuItem.addItemListener(this);
3560 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3561 noColourmenuItem.addActionListener(this);
3562 abovePIDThreshold.setLabel(
3563 MessageManager.getString("label.above_identity_threshold"));
3564 abovePIDThreshold.addItemListener(this);
3565 nucleotideColour.setLabel(
3566 MessageManager.getString("label.colourScheme_nucleotide"));
3567 nucleotideColour.addActionListener(this);
3569 MessageManager.getString("label.modify_identity_threshold"));
3570 modifyPID.setEnabled(abovePIDThreshold.getState());
3571 modifyPID.addActionListener(this);
3572 modifyConservation.setLabel(MessageManager
3573 .getString("label.modify_conservation_threshold"));
3574 modifyConservation.setEnabled(conservationMenuItem.getState());
3575 modifyConservation.addActionListener(this);
3577 .setLabel(MessageManager.getString("action.by_annotation"));
3578 annotationColour.addActionListener(this);
3581 * Configure Calculate menu items and actions
3583 sortPairwiseMenuItem
3584 .setLabel(MessageManager.getString("action.by_pairwise_id"));
3585 sortPairwiseMenuItem.addActionListener(this);
3586 sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
3587 sortIDMenuItem.addActionListener(this);
3589 .setLabel(MessageManager.getString("action.by_length"));
3590 sortLengthMenuItem.addActionListener(this);
3591 sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3592 sortGroupMenuItem.addActionListener(this);
3593 pairwiseAlignmentMenuItem.setLabel(
3594 MessageManager.getString("action.pairwise_alignment"));
3595 pairwiseAlignmentMenuItem.addActionListener(this);
3596 PCAMenuItem.setLabel(
3597 MessageManager.getString("label.principal_component_analysis"));
3598 PCAMenuItem.addActionListener(this);
3599 autoCalculate = new CheckboxMenuItem(
3600 MessageManager.getString("label.autocalculate_consensus"),
3602 averageDistanceTreeMenuItem.setLabel(
3603 MessageManager.getString("label.average_distance_identity"));
3604 averageDistanceTreeMenuItem.addActionListener(this);
3605 neighbourTreeMenuItem.setLabel(
3606 MessageManager.getString("label.neighbour_joining_identity"));
3607 neighbourTreeMenuItem.addActionListener(this);
3608 avDistanceTreeBlosumMenuItem.setLabel(
3609 MessageManager.getString("label.average_distance_blosum62"));
3610 avDistanceTreeBlosumMenuItem.addActionListener(this);
3611 njTreeBlosumMenuItem
3612 .setLabel(MessageManager.getString("label.neighbour_blosum62"));
3613 njTreeBlosumMenuItem.addActionListener(this);
3615 .setLabel(MessageManager.getString("action.by_tree_order"));
3616 Menu sortMenu = new Menu(MessageManager.getString("action.sort"));
3617 Menu calculateTreeMenu = new Menu(
3618 MessageManager.getString("action.calculate_tree"));
3619 autoCalculate.addItemListener(this);
3620 sortByTree.addItemListener(this);
3623 * Configure Help menu items and actions
3625 Menu helpMenu = new Menu(MessageManager.getString("action.help"));
3626 documentation.setLabel(MessageManager.getString("label.documentation"));
3627 documentation.addActionListener(this);
3628 about.setLabel(MessageManager.getString("label.about"));
3629 about.addActionListener(this);
3632 * Add top level menus to frame
3634 alignFrameMenuBar.add(fileMenu);
3635 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
3636 alignFrameMenuBar.add(editMenu);
3637 Menu selectMenu = new Menu(MessageManager.getString("action.select"));
3638 alignFrameMenuBar.add(selectMenu);
3639 Menu viewMenu = new Menu(MessageManager.getString("action.view"));
3640 alignFrameMenuBar.add(viewMenu);
3641 Menu annotationsMenu = new Menu(
3642 MessageManager.getString("action.annotations"));
3643 alignFrameMenuBar.add(annotationsMenu);
3644 Menu formatMenu = new Menu(MessageManager.getString("action.format"));
3645 alignFrameMenuBar.add(formatMenu);
3646 Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
3647 alignFrameMenuBar.add(colourMenu);
3648 Menu calculateMenu = new Menu(
3649 MessageManager.getString("action.calculate"));
3650 alignFrameMenuBar.add(calculateMenu);
3651 alignFrameMenuBar.add(helpMenu);
3656 fileMenu.add(inputText);
3657 fileMenu.add(loadTree);
3658 fileMenu.add(loadAnnotations);
3659 fileMenu.addSeparator();
3660 fileMenu.add(outputTextboxMenu);
3661 fileMenu.add(outputFeatures);
3662 fileMenu.add(outputAnnotations);
3663 if (jalviewServletURL != null)
3665 fileMenu.add(loadApplication);
3667 fileMenu.addSeparator();
3668 fileMenu.add(closeMenuItem);
3673 editMenu.add(undoMenuItem);
3674 editMenu.add(redoMenuItem);
3677 pasteMenu.add(pasteNew);
3678 pasteMenu.add(pasteThis);
3679 editMenu.add(pasteMenu);
3680 editMenu.add(delete);
3681 editMenu.addSeparator();
3682 editMenu.add(remove2LeftMenuItem);
3683 editMenu.add(remove2RightMenuItem);
3684 editMenu.add(removeGappedColumnMenuItem);
3685 editMenu.add(removeAllGapsMenuItem);
3686 editMenu.add(removeRedundancyMenuItem);
3691 selectMenu.add(findMenuItem);
3692 selectMenu.addSeparator();
3693 selectMenu.add(selectAllSequenceMenuItem);
3694 selectMenu.add(deselectAllSequenceMenuItem);
3695 selectMenu.add(invertSequenceMenuItem);
3696 selectMenu.add(invertColSel);
3697 selectMenu.add(createGroup);
3698 selectMenu.add(unGroup);
3699 selectMenu.add(grpsFromSelection);
3700 selectMenu.add(deleteGroups);
3701 selectMenu.add(annotationColumnSelection);
3706 viewMenu.add(newView);
3707 viewMenu.addSeparator();
3708 showMenu.add(showColumns);
3709 showMenu.add(showSeqs);
3710 showMenu.add(showAllHidden);
3711 viewMenu.add(showMenu);
3712 hideMenu.add(hideColumns);
3713 hideMenu.add(hideSequences);
3714 hideMenu.add(hideAllSelection);
3715 hideMenu.add(hideAllButSelection);
3716 viewMenu.add(hideMenu);
3717 viewMenu.addSeparator();
3718 viewMenu.add(followMouseOverFlag);
3719 viewMenu.addSeparator();
3720 viewMenu.add(sequenceFeatures);
3721 viewMenu.add(featureSettings);
3722 viewMenu.addSeparator();
3723 viewMenu.add(alProperties);
3724 viewMenu.addSeparator();
3725 viewMenu.add(overviewMenuItem);
3730 annotationsMenu.add(annotationPanelMenuItem);
3731 annotationsMenu.addSeparator();
3732 annotationsMenu.add(showAlignmentAnnotations);
3733 annotationsMenu.add(showSequenceAnnotations);
3734 annotationsMenu.add(sortAnnBySequence);
3735 annotationsMenu.add(sortAnnByLabel);
3736 annotationsMenu.addSeparator();
3737 autoAnnMenu.add(showAutoFirst);
3738 autoAnnMenu.add(showAutoLast);
3739 autoAnnMenu.addSeparator();
3740 autoAnnMenu.add(applyAutoAnnotationSettings);
3741 autoAnnMenu.add(showConsensusHistogram);
3742 autoAnnMenu.add(showSequenceLogo);
3743 autoAnnMenu.add(normSequenceLogo);
3744 autoAnnMenu.addSeparator();
3745 autoAnnMenu.add(showGroupConservation);
3746 autoAnnMenu.add(showGroupConsensus);
3747 annotationsMenu.add(autoAnnMenu);
3752 formatMenu.add(font);
3753 formatMenu.add(seqLimits);
3754 formatMenu.add(wrapMenuItem);
3755 formatMenu.add(scaleAbove);
3756 formatMenu.add(scaleLeft);
3757 formatMenu.add(scaleRight);
3758 formatMenu.add(viewBoxesMenuItem);
3759 formatMenu.add(viewTextMenuItem);
3760 formatMenu.add(colourTextMenuItem);
3761 formatMenu.add(displayNonconservedMenuItem);
3762 formatMenu.add(renderGapsMenuItem);
3763 formatMenu.add(centreColumnLabelFlag);
3768 colourMenu.add(applyToAllGroups);
3769 colourMenu.addSeparator();
3770 colourMenu.add(noColourmenuItem);
3771 colourMenu.add(clustalColour);
3772 colourMenu.add(BLOSUM62Colour);
3773 colourMenu.add(PIDColour);
3774 colourMenu.add(zappoColour);
3775 colourMenu.add(taylorColour);
3776 colourMenu.add(hydrophobicityColour);
3777 colourMenu.add(helixColour);
3778 colourMenu.add(strandColour);
3779 colourMenu.add(turnColour);
3780 colourMenu.add(buriedColour);
3781 colourMenu.add(nucleotideColour);
3782 colourMenu.add(purinePyrimidineColour);
3783 // colourMenu.add(RNAInteractionColour);
3784 colourMenu.add(tcoffeeColour);
3785 colourMenu.add(userDefinedColour);
3786 colourMenu.addSeparator();
3787 colourMenu.add(conservationMenuItem);
3788 colourMenu.add(modifyConservation);
3789 colourMenu.add(abovePIDThreshold);
3790 colourMenu.add(modifyPID);
3791 colourMenu.add(annotationColour);
3792 colourMenu.add(RNAHelixColour);
3797 sortMenu.add(sortIDMenuItem);
3798 sortMenu.add(sortLengthMenuItem);
3799 sortMenu.add(sortByTreeMenu);
3800 sortMenu.add(sortGroupMenuItem);
3801 sortMenu.add(sortPairwiseMenuItem);
3802 calculateMenu.add(sortMenu);
3803 calculateTreeMenu.add(averageDistanceTreeMenuItem);
3804 calculateTreeMenu.add(neighbourTreeMenuItem);
3805 calculateTreeMenu.add(avDistanceTreeBlosumMenuItem);
3806 calculateTreeMenu.add(njTreeBlosumMenuItem);
3807 calculateMenu.add(calculateTreeMenu);
3808 calculateMenu.addSeparator();
3809 calculateMenu.add(pairwiseAlignmentMenuItem);
3810 calculateMenu.add(PCAMenuItem);
3811 calculateMenu.add(autoCalculate);
3812 calculateMenu.add(sortByTree);
3817 helpMenu.add(documentation);
3818 helpMenu.add(about);
3823 statusBar.setBackground(Color.white);
3824 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3825 statusBar.setText(MessageManager.getString("label.status_bar"));
3826 this.add(statusBar, BorderLayout.SOUTH);
3830 public void setStatus(String string)
3832 statusBar.setText(string);
3835 MenuItem featureSettings = new MenuItem();
3837 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3839 MenuItem annotationColour = new MenuItem();
3841 MenuItem annotationColumnSelection = new MenuItem();
3843 MenuItem invertColSel = new MenuItem();
3845 MenuItem showColumns = new MenuItem();
3847 MenuItem showSeqs = new MenuItem();
3849 MenuItem hideColumns = new MenuItem();
3851 MenuItem hideSequences = new MenuItem();
3853 MenuItem hideAllButSelection = new MenuItem();
3855 MenuItem hideAllSelection = new MenuItem();
3857 MenuItem showAllHidden = new MenuItem();
3859 MenuItem newView = new MenuItem();
3861 private CheckboxMenuItem showAlignmentAnnotations;
3863 private CheckboxMenuItem showSequenceAnnotations;
3865 private CheckboxMenuItem sortAnnBySequence;
3867 private CheckboxMenuItem sortAnnByLabel;
3869 private CheckboxMenuItem showAutoFirst;
3871 private CheckboxMenuItem showAutoLast;
3873 private SplitFrame splitFrame;
3876 * Attach the alignFrame panels after embedding menus, if necessary. This used
3877 * to be called setEmbedded, but is now creates the dropdown menus in a
3878 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3880 * @param reallyEmbedded
3881 * true to attach the view to the applet area on the page rather than
3884 public void createAlignFrameWindow(boolean reallyEmbedded)
3888 embedAlignFrameInApplet(viewport.applet);
3893 // test and embed menu bar if necessary.
3895 if (embedMenuIfNeeded(alignPanel))
3898 * adjust for status bar height too. ? pointless as overridden by layout
3901 alignPanel.setSize(getSize().width,
3902 getSize().height - statusBar.getHeight());
3904 add(statusBar, BorderLayout.SOUTH);
3905 add(alignPanel, BorderLayout.CENTER);
3906 // and register with the applet so it can pass external API calls to us
3907 jalview.bin.JalviewLite.addFrame(this, this.getTitle(), frameWidth,
3913 * Add the components of this AlignFrame to the applet container.
3917 public void embedAlignFrameInApplet(final JalviewLite theApplet)
3920 // Explicitly build the embedded menu panel for the on-page applet
3922 // view cannot be closed if its actually on the page
3923 fileMenu.remove(closeMenuItem);
3924 fileMenu.remove(3); // Remove Separator
3925 // construct embedded menu, using default font
3926 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
3927 // and actually add the components to the applet area
3928 theApplet.setLayout(new BorderLayout());
3929 theApplet.add(embeddedMenu, BorderLayout.NORTH);
3930 theApplet.add(statusBar, BorderLayout.SOUTH);
3931 // TODO should size be left to the layout manager?
3932 alignPanel.setSize(theApplet.getSize().width, theApplet.getSize().height
3933 - embeddedMenu.getHeight() - statusBar.getHeight());
3934 theApplet.add(alignPanel, BorderLayout.CENTER);
3935 final AlignFrame me = this;
3936 theApplet.addFocusListener(new FocusListener()
3940 public void focusLost(FocusEvent e)
3942 if (theApplet.currentAlignFrame == me)
3944 theApplet.currentAlignFrame = null;
3949 public void focusGained(FocusEvent e)
3951 theApplet.currentAlignFrame = me;
3954 theApplet.validate();
3958 * create a new binding between structures in an existing jmol viewer instance
3959 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3960 * this does not open a new Jmol window, or modify the display of the
3961 * structures in the original jmol window. Note This method doesn't work
3962 * without an additional javascript library to exchange messages between the
3963 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3966 * JmolViewer instance
3967 * @param sequenceIds
3968 * - sequence Ids to search for associations
3970 public SequenceStructureBinding addStructureViewInstance(
3971 Object jmolviewer, String[] sequenceIds)
3973 Viewer viewer = null;
3976 viewer = (Viewer) jmolviewer;
3977 } catch (ClassCastException ex)
3980 "Unsupported viewer object :" + jmolviewer.getClass());
3984 System.err.println("Can't use this object as a structure viewer:"
3985 + jmolviewer.getClass());
3988 SequenceI[] seqs = null;
3989 if (sequenceIds == null || sequenceIds.length == 0)
3991 seqs = viewport.getAlignment().getSequencesArray();
3995 Vector sqi = new Vector();
3996 AlignmentI al = viewport.getAlignment();
3997 for (int sid = 0; sid < sequenceIds.length; sid++)
3999 SequenceI sq = al.findName(sequenceIds[sid]);
4007 seqs = new SequenceI[sqi.size()];
4008 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
4010 seqs[sid] = (SequenceI) sqi.elementAt(sid);
4018 AAStructureBindingModel jmv = null;
4019 // TODO: search for a jmv that involves viewer
4021 { // create a new viewer/jalview binding.
4022 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] { seqs });
4029 * bind a pdb file to a sequence in the current view
4032 * - sequenceId within the dataset.
4033 * @param pdbEntryString
4034 * - the short name for the PDB file
4036 * - pdb file - either a URL or a valid PDB file.
4037 * @return true if binding was as success TODO: consider making an exception
4038 * structure for indicating when PDB parsing or sequenceId location
4041 public boolean addPdbFile(String sequenceId, String pdbEntryString,
4044 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
4045 boolean needtoadd = false;
4046 if (toaddpdb != null)
4048 Vector pdbe = toaddpdb.getAllPDBEntries();
4049 PDBEntry pdbentry = null;
4050 if (pdbe != null && pdbe.size() > 0)
4052 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
4054 pdbentry = (PDBEntry) pdbe.elementAt(pe);
4055 if (!pdbentry.getId().equals(pdbEntryString)
4056 && !pdbentry.getFile().equals(pdbFile))
4066 if (pdbentry == null)
4068 pdbentry = new PDBEntry();
4069 pdbentry.setId(pdbEntryString);
4070 pdbentry.setFile(pdbFile);
4071 needtoadd = true; // add this new entry to sequence.
4073 // resolve data source
4074 // TODO: this code should be a refactored to an io package
4075 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(pdbFile,
4077 if (protocol == null)
4083 pdbentry.setProperty("protocol", protocol);
4084 toaddpdb.addPDBId(pdbentry);
4085 alignPanel.getStructureSelectionManager()
4086 .registerPDBEntry(pdbentry);
4092 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
4096 Vector sequences = new Vector();
4097 for (int i = 0; i < seqs.length; i++)
4099 if (seqs[i] != null)
4102 .addElement(new Object[]
4103 { seqs[i], (chains != null) ? chains[i] : null });
4106 seqs = new SequenceI[sequences.size()];
4107 chains = new String[sequences.size()];
4108 for (int i = 0, isize = sequences.size(); i < isize; i++)
4110 Object[] oj = (Object[]) sequences.elementAt(i);
4112 seqs[i] = (SequenceI) oj[0];
4113 chains[i] = (String) oj[1];
4116 return new Object[] { seqs, chains };
4120 public void newStructureView(JalviewLite applet, PDBEntry pdb,
4121 SequenceI[] seqs, String[] chains, DataSourceType protocol)
4123 // Scrub any null sequences from the array
4124 Object[] sqch = cleanSeqChainArrays(seqs, chains);
4125 seqs = (SequenceI[]) sqch[0];
4126 chains = (String[]) sqch[1];
4127 if (seqs == null || seqs.length == 0)
4130 "JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
4132 if (protocol == null)
4134 String sourceType = (String) pdb.getProperty("protocol");
4137 protocol = DataSourceType.valueOf(sourceType);
4138 } catch (IllegalArgumentException e)
4142 if (protocol == null)
4144 System.err.println("Couldn't work out protocol to open structure: "
4149 if (applet.useXtrnalSviewer)
4151 // register the association(s) and quit, don't create any windows.
4152 if (StructureSelectionManager.getStructureSelectionManager(applet)
4153 .setMapping(seqs, chains, pdb.getFile(), protocol, null) == null)
4155 System.err.println("Failed to map " + pdb.getFile() + " ("
4156 + protocol + ") to any sequences");
4160 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
4162 // can only do alignments with Jmol
4163 // find the last jmol window assigned to this alignment
4164 AppletJmol ajm = null, tajm;
4165 Vector jmols = applet.getAppletWindow(AppletJmol.class);
4166 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
4168 tajm = (AppletJmol) jmols.elementAt(i);
4169 if (tajm.ap.alignFrame == this)
4178 "Incremental adding and aligning structure to existing Jmol view not yet implemented.");
4179 // try and add the pdb structure
4184 // otherwise, create a new window
4185 if (applet.jmolAvailable)
4187 new AppletJmol(pdb, seqs, chains, alignPanel, protocol);
4188 applet.lastFrameX += 40;
4189 applet.lastFrameY += 40;
4193 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
4198 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
4199 SequenceI[][] seqs, String[][] chains, String[] protocols)
4201 // TODO Auto-generated method stub
4202 System.err.println("Aligned Structure View: Not yet implemented.");
4206 * modify the current selection, providing the user has not made a selection
4210 * - sequences from this alignment
4212 * - columns to be selected on the alignment
4214 public void select(SequenceGroup sel, ColumnSelection csel,
4215 HiddenColumns hidden)
4217 alignPanel.seqPanel.selection(sel, csel, hidden, null);
4220 public void scrollTo(int row, int column)
4222 alignPanel.seqPanel.scrollTo(row, column);
4225 public void scrollToRow(int row)
4227 alignPanel.seqPanel.scrollToRow(row);
4230 public void scrollToColumn(int column)
4232 alignPanel.seqPanel.scrollToColumn(column);
4236 * @return the alignments unique ID.
4238 public String getSequenceSetId()
4240 return viewport.getSequenceSetId();
4244 * Load the (T-Coffee) score file from the specified url
4247 * File/URL/T-COFFEE score file contents
4248 * @throws IOException
4249 * @return true if alignment was annotated with data from source
4251 public boolean loadScoreFile(String source) throws IOException
4254 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
4255 AppletFormatAdapter.checkProtocol(source));
4256 if (!file.isValid())
4258 // TODO: raise dialog for gui
4259 System.err.println("Problems parsing T-Coffee scores: "
4260 + file.getWarningMessage());
4261 System.err.println("Origin was:\n" + source);
4266 * check that the score matrix matches the alignment dimensions
4269 if ((aln = viewport.getAlignment()) != null
4270 && (aln.getHeight() != file.getHeight()
4271 || aln.getWidth() != file.getWidth()))
4273 // TODO: raise a dialog box here rather than bomb out.
4275 "The scores matrix does not match the alignment dimensions");
4279 // TODO add parameter to indicate if matching should be done
4280 if (file.annotateAlignment(alignPanel.getAlignment(), false))
4282 alignPanel.fontChanged();
4283 tcoffeeColour.setEnabled(true);
4284 // switch to this color
4285 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4290 System.err.println("Problems resolving T-Coffee scores:");
4291 if (file.getWarningMessage() != null)
4293 System.err.println(file.getWarningMessage());
4299 public SplitFrame getSplitFrame()
4301 return this.splitFrame;
4304 public void setSplitFrame(SplitFrame sf)
4306 this.splitFrame = sf;
4309 // may not need this
4311 public void setShowSeqFeatures(boolean b)
4313 // showSeqFeatures.setSelected(b);
4314 viewport.setShowSequenceFeatures(b);
4319 public void setMenusForViewport()
4321 // setMenusFromViewport(viewport);
4326 public void refreshFeatureUI(boolean enableIfNecessary)
4328 if (enableIfNecessary)
4330 sequenceFeatures.setState(true);
4331 alignPanel.av.setShowSequenceFeatures(true);
4336 public FeatureSettingsControllerI getFeatureSettingsUI()
4338 return alignPanel.av.featureSettings;