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.NJTree;
26 import jalview.api.AlignViewControllerGuiI;
27 import jalview.api.AlignViewControllerI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.FeatureColourI;
30 import jalview.api.FeatureRenderer;
31 import jalview.api.FeatureSettingsControllerI;
32 import jalview.api.SequenceStructureBinding;
33 import jalview.bin.JalviewLite;
34 import jalview.commands.CommandI;
35 import jalview.commands.EditCommand;
36 import jalview.commands.EditCommand.Action;
37 import jalview.commands.OrderCommand;
38 import jalview.commands.RemoveGapColCommand;
39 import jalview.commands.RemoveGapsCommand;
40 import jalview.commands.SlideSequencesCommand;
41 import jalview.commands.TrimRegionCommand;
42 import jalview.datamodel.Alignment;
43 import jalview.datamodel.AlignmentAnnotation;
44 import jalview.datamodel.AlignmentI;
45 import jalview.datamodel.AlignmentOrder;
46 import jalview.datamodel.ColumnSelection;
47 import jalview.datamodel.PDBEntry;
48 import jalview.datamodel.Sequence;
49 import jalview.datamodel.SequenceGroup;
50 import jalview.datamodel.SequenceI;
51 import jalview.io.AnnotationFile;
52 import jalview.io.AppletFormatAdapter;
53 import jalview.io.DataSourceType;
54 import jalview.io.FeaturesFile;
55 import jalview.io.FileFormat;
56 import jalview.io.FileFormatI;
57 import jalview.io.FileFormats;
58 import jalview.io.TCoffeeScoreFile;
59 import jalview.schemes.Blosum62ColourScheme;
60 import jalview.schemes.BuriedColourScheme;
61 import jalview.schemes.ClustalxColourScheme;
62 import jalview.schemes.ColourSchemeI;
63 import jalview.schemes.HelixColourScheme;
64 import jalview.schemes.HydrophobicColourScheme;
65 import jalview.schemes.NucleotideColourScheme;
66 import jalview.schemes.PIDColourScheme;
67 import jalview.schemes.PurinePyrimidineColourScheme;
68 import jalview.schemes.RNAHelicesColour;
69 import jalview.schemes.StrandColourScheme;
70 import jalview.schemes.TCoffeeColourScheme;
71 import jalview.schemes.TaylorColourScheme;
72 import jalview.schemes.TurnColourScheme;
73 import jalview.schemes.ZappoColourScheme;
74 import jalview.structure.StructureSelectionManager;
75 import jalview.structures.models.AAStructureBindingModel;
76 import jalview.util.MappingUtils;
77 import jalview.util.MessageManager;
78 import jalview.viewmodel.AlignmentViewport;
80 import java.awt.BorderLayout;
81 import java.awt.Canvas;
82 import java.awt.CheckboxMenuItem;
83 import java.awt.Color;
84 import java.awt.FlowLayout;
86 import java.awt.FontMetrics;
87 import java.awt.Frame;
88 import java.awt.Graphics;
89 import java.awt.Label;
91 import java.awt.MenuBar;
92 import java.awt.MenuItem;
93 import java.awt.Panel;
94 import java.awt.event.ActionEvent;
95 import java.awt.event.ActionListener;
96 import java.awt.event.FocusEvent;
97 import java.awt.event.FocusListener;
98 import java.awt.event.ItemEvent;
99 import java.awt.event.ItemListener;
100 import java.awt.event.KeyEvent;
101 import java.awt.event.KeyListener;
102 import java.awt.event.WindowAdapter;
103 import java.awt.event.WindowEvent;
104 import java.io.IOException;
106 import java.net.URLEncoder;
107 import java.util.Arrays;
108 import java.util.Deque;
109 import java.util.HashMap;
110 import java.util.List;
111 import java.util.Map;
112 import java.util.StringTokenizer;
113 import java.util.Vector;
115 import org.jmol.viewer.Viewer;
117 public class AlignFrame extends EmbmenuFrame implements ActionListener,
118 ItemListener, KeyListener, AlignViewControllerGuiI
120 public AlignViewControllerI avc;
122 public AlignmentPanel alignPanel;
124 public AlignViewport viewport;
126 // width and height may be overridden by applet parameters
127 int frameWidth = 700;
129 int frameHeight = 500;
131 String jalviewServletURL;
134 * Flag for showing autocalculated consensus above or below other consensus
137 private boolean showAutoCalculatedAbove;
139 private SequenceAnnotationOrder annotationSortOrder;
142 * Constructor that creates the frame and adds it to the display.
149 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
152 this(al, applet, title, embedded, true);
156 * Constructor that optionally allows the frame to be displayed or only
163 * @param addToDisplay
165 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
166 boolean embedded, boolean addToDisplay)
168 this(al, null, null, applet, title, embedded, addToDisplay);
171 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
172 ColumnSelection columnSelection, JalviewLite applet,
173 String title, boolean embedded)
175 this(al, hiddenSeqs, columnSelection, applet, title, embedded, true);
178 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
179 ColumnSelection columnSelection, JalviewLite applet,
180 String title, boolean embedded, boolean addToDisplay)
184 jalviewServletURL = applet.getParameter("APPLICATION_URL");
190 } catch (Exception ex)
192 ex.printStackTrace();
194 // need to get window geometry before we calculate alignment layout
200 param = applet.getParameter("windowWidth");
203 int width = Integer.parseInt(param);
206 param = applet.getParameter("windowHeight");
209 int height = Integer.parseInt(param);
210 frameHeight = height;
212 } catch (Exception ex)
216 viewport = new AlignViewport(al, applet);
218 if (hiddenSeqs != null && hiddenSeqs.length > 0)
220 viewport.hideSequence(hiddenSeqs);
222 if (columnSelection != null)
224 viewport.setColumnSelection(columnSelection);
226 viewport.setScaleAboveWrapped(scaleAbove.getState());
228 alignPanel = new AlignmentPanel(this, viewport);
229 avc = new jalview.controller.AlignViewController(this, viewport,
231 viewport.updateConservation(alignPanel);
232 viewport.updateConsensus(alignPanel);
234 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
235 followMouseOverFlag.setState(viewport.isFollowHighlight());
236 showGroupConsensus.setState(viewport.isShowGroupConsensus());
237 showGroupConservation.setState(viewport.isShowGroupConservation());
238 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
239 showSequenceLogo.setState(viewport.isShowSequenceLogo());
240 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
241 applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
242 annotationPanelMenuItem.setState(viewport.isShowAnnotation());
243 showAlignmentAnnotations.setEnabled(annotationPanelMenuItem.getState());
244 showSequenceAnnotations.setEnabled(annotationPanelMenuItem.getState());
245 showAlignmentAnnotations.setState(true);
246 showSequenceAnnotations.setState(false);
248 seqLimits.setState(viewport.getShowJVSuffix());
252 String param = applet.getParameter("sortBy");
255 if (param.equalsIgnoreCase("Id"))
257 sortIDMenuItem_actionPerformed();
259 else if (param.equalsIgnoreCase("Pairwise Identity"))
261 sortPairwiseMenuItem_actionPerformed();
263 else if (param.equalsIgnoreCase("Length"))
265 sortLengthMenuItem_actionPerformed();
269 param = applet.getParameter("wrap");
272 if (param.equalsIgnoreCase("true"))
274 wrapMenuItem.setState(true);
275 wrapMenuItem_actionPerformed();
278 param = applet.getParameter("centrecolumnlabels");
281 centreColumnLabelFlag.setState(true);
282 centreColumnLabelFlag_stateChanged();
286 if (viewport.getAlignment().isNucleotide())
288 conservationMenuItem.setEnabled(false);
289 clustalColour.setEnabled(false);
290 BLOSUM62Colour.setEnabled(false);
291 zappoColour.setEnabled(false);
292 taylorColour.setEnabled(false);
293 hydrophobicityColour.setEnabled(false);
294 helixColour.setEnabled(false);
295 strandColour.setEnabled(false);
296 turnColour.setEnabled(false);
297 buriedColour.setEnabled(false);
298 viewport.updateStrucConsensus(alignPanel);
299 if (viewport.getAlignment().hasRNAStructure())
301 RNAHelixColour.setEnabled(true);
305 RNAHelixColour.setEnabled(false);
310 RNAHelixColour.setEnabled(false);
311 purinePyrimidineColour.setEnabled(false);
312 nucleotideColour.setEnabled(false);
314 // Some JVMS send keyevents to Top frame or lowest panel,
315 // Havent worked out why yet. So add to both this frame and seqCanvas for
317 this.addKeyListener(this);
318 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
319 alignPanel.idPanel.idCanvas.addKeyListener(this);
320 alignPanel.scalePanel.addKeyListener(this);
321 alignPanel.annotationPanel.addKeyListener(this);
322 alignPanel.annotationPanelHolder.addKeyListener(this);
323 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
324 alignPanel.alabels.addKeyListener(this);
326 setAnnotationsVisibility();
330 addToDisplay(embedded);
337 public void addToDisplay(boolean embedded)
339 createAlignFrameWindow(embedded);
341 alignPanel.adjustAnnotationHeight();
342 alignPanel.paintAlignment(true);
345 public AlignViewport getAlignViewport()
350 public SeqCanvas getSeqcanvas()
352 return alignPanel.seqPanel.seqCanvas;
356 * Load a features file onto the alignment
359 * file URL, content, or other resolvable path
361 * is protocol for accessing data referred to by file
364 public boolean parseFeaturesFile(String file, DataSourceType type)
366 return parseFeaturesFile(file, type, true);
370 * Load a features file onto the alignment
373 * file URL, content, or other resolvable path
375 * is protocol for accessing data referred to by file
376 * @param autoenabledisplay
377 * when true, display features flag will be automatically enabled if
378 * features are loaded
379 * @return true if data parsed as a features file
381 public boolean parseFeaturesFile(String file, DataSourceType sourceType,
382 boolean autoenabledisplay)
384 boolean featuresFile = false;
387 Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
388 .getFeatureRenderer().getFeatureColours();
389 boolean relaxedIdMatching = viewport.applet.getDefaultParameter(
390 "relaxedidmatch", false);
391 featuresFile = new FeaturesFile(file, sourceType).parse(
392 viewport.getAlignment(), colours, true, relaxedIdMatching);
393 } catch (Exception ex)
395 ex.printStackTrace();
400 if (autoenabledisplay)
402 viewport.setShowSequenceFeatures(true);
403 sequenceFeatures.setState(true);
405 if (alignPanel.seqPanel.seqCanvas.fr != null)
407 // update the min/max ranges where necessary
408 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
410 if (viewport.featureSettings != null)
412 viewport.featureSettings.refreshTable();
414 alignPanel.paintAlignment(true);
415 statusBar.setText(MessageManager
416 .getString("label.successfully_added_features_alignment"));
422 public void keyPressed(KeyEvent evt)
424 if (viewport.cursorMode
425 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
426 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
427 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
428 && Character.isDigit(evt.getKeyChar()))
430 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
433 switch (evt.getKeyCode())
435 case 27: // escape key
436 deselectAllSequenceMenuItem_actionPerformed();
438 alignPanel.alabels.cancelDrag();
441 if (evt.isControlDown() || evt.isMetaDown())
443 cut_actionPerformed();
447 if (viewport.cursorMode && !evt.isControlDown())
449 alignPanel.seqPanel.setCursorColumn();
451 if (evt.isControlDown() || evt.isMetaDown())
453 copy_actionPerformed();
457 if (evt.isControlDown())
459 paste(evt.isShiftDown());
463 if (evt.isControlDown() || evt.isMetaDown())
465 selectAllSequenceMenuItem_actionPerformed();
468 case KeyEvent.VK_DOWN:
469 if (viewport.cursorMode)
471 alignPanel.seqPanel.moveCursor(0, 1);
475 moveSelectedSequences(false);
480 if (viewport.cursorMode)
482 alignPanel.seqPanel.moveCursor(0, -1);
486 moveSelectedSequences(true);
490 case KeyEvent.VK_LEFT:
491 if (evt.isAltDown() || !viewport.cursorMode)
493 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
497 alignPanel.seqPanel.moveCursor(-1, 0);
501 case KeyEvent.VK_RIGHT:
502 if (evt.isAltDown() || !viewport.cursorMode)
504 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
508 alignPanel.seqPanel.moveCursor(1, 0);
512 case KeyEvent.VK_SPACE:
513 if (viewport.cursorMode)
515 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
516 || evt.isShiftDown() || evt.isAltDown());
520 case KeyEvent.VK_DELETE:
521 case KeyEvent.VK_BACK_SPACE:
522 if (viewport.cursorMode)
524 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
525 || evt.isShiftDown() || evt.isAltDown());
529 cut_actionPerformed();
530 alignPanel.seqPanel.seqCanvas.repaint();
535 if (viewport.cursorMode)
537 alignPanel.seqPanel.setCursorRow();
541 if (viewport.cursorMode)
543 alignPanel.seqPanel.setCursorPosition();
547 case KeyEvent.VK_ENTER:
548 case KeyEvent.VK_COMMA:
549 if (viewport.cursorMode)
551 alignPanel.seqPanel.setCursorRowAndColumn();
556 if (viewport.cursorMode)
558 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
562 if (viewport.cursorMode)
564 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
569 viewport.cursorMode = !viewport.cursorMode;
570 statusBar.setText(MessageManager.formatMessage(
571 "label.keyboard_editing_mode",
572 new String[] { (viewport.cursorMode ? "on" : "off") }));
573 if (viewport.cursorMode)
575 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
576 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
581 if (evt.isControlDown())
583 findMenuItem_actionPerformed();
589 boolean toggleSeqs = !evt.isControlDown();
590 boolean toggleCols = !evt.isShiftDown();
591 toggleHiddenRegions(toggleSeqs, toggleCols);
595 case KeyEvent.VK_PAGE_UP:
596 if (viewport.getWrapAlignment())
598 alignPanel.scrollUp(true);
602 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
603 - viewport.endSeq + viewport.startSeq);
607 case KeyEvent.VK_PAGE_DOWN:
608 if (viewport.getWrapAlignment())
610 alignPanel.scrollUp(false);
614 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
615 + viewport.endSeq - viewport.startSeq);
620 if (evt.isControlDown())
622 undoMenuItem_actionPerformed();
627 if (evt.isControlDown())
629 redoMenuItem_actionPerformed();
634 if (evt.isControlDown())
641 if (evt.isControlDown())
643 trimAlignment(false);
648 if (evt.isControlDown())
650 if (evt.isShiftDown())
652 this.removeAllGapsMenuItem_actionPerformed();
656 removeGappedColumnMenuItem_actionPerformed();
661 if (evt.isControlDown())
665 invertColSel_actionPerformed();
669 invertSequenceMenuItem_actionPerformed();
675 if (evt.isControlDown())
677 if (evt.isShiftDown())
679 this.unGroup_actionPerformed();
683 this.createGroup_actionPerformed();
689 if (evt.isControlDown())
691 this.deleteGroups_actionPerformed();
696 if (evt.isControlDown())
703 alignPanel.paintAlignment(true);
707 * called by key handler and the hide all/show all menu items
712 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
714 boolean hide = false;
715 SequenceGroup sg = viewport.getSelectionGroup();
716 if (!toggleSeqs && !toggleCols)
718 // Hide everything by the current selection - this is a hack - we do the
719 // invert and then hide
720 // first check that there will be visible columns after the invert.
721 if (viewport.hasSelectedColumns()
722 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
725 // now invert the sequence set, if required - empty selection implies
726 // that no hiding is required.
729 invertSequenceMenuItem_actionPerformed();
730 sg = viewport.getSelectionGroup();
734 viewport.expandColSelection(sg, true);
735 // finally invert the column selection and get the new sequence
736 // selection and indicate it should be hidden.
737 invertColSel_actionPerformed();
744 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
747 viewport.hideAllSelectedSeqs();
749 else if (!(toggleCols && viewport.hasSelectedColumns()))
751 viewport.showAllHiddenSeqs();
757 if (viewport.hasSelectedColumns())
759 viewport.hideSelectedColumns();
762 viewport.setSelectionGroup(sg);
767 viewport.showAllHiddenColumns();
769 viewport.sendSelection();
774 public void keyReleased(KeyEvent evt)
779 public void keyTyped(KeyEvent evt)
784 public void itemStateChanged(ItemEvent evt)
786 final Object source = evt.getSource();
787 if (source == displayNonconservedMenuItem)
789 displayNonconservedMenuItem_actionPerformed();
791 else if (source == colourTextMenuItem)
793 colourTextMenuItem_actionPerformed();
795 else if (source == wrapMenuItem)
797 wrapMenuItem_actionPerformed();
799 else if (source == scaleAbove)
801 viewport.setScaleAboveWrapped(scaleAbove.getState());
803 else if (source == scaleLeft)
805 viewport.setScaleLeftWrapped(scaleLeft.getState());
807 else if (source == scaleRight)
809 viewport.setScaleRightWrapped(scaleRight.getState());
811 else if (source == seqLimits)
813 seqLimits_itemStateChanged();
815 else if (source == viewBoxesMenuItem)
817 viewport.setShowBoxes(viewBoxesMenuItem.getState());
819 else if (source == viewTextMenuItem)
821 viewport.setShowText(viewTextMenuItem.getState());
823 else if (source == renderGapsMenuItem)
825 viewport.setRenderGaps(renderGapsMenuItem.getState());
827 else if (source == annotationPanelMenuItem)
829 boolean showAnnotations = annotationPanelMenuItem.getState();
830 showAlignmentAnnotations.setEnabled(showAnnotations);
831 showSequenceAnnotations.setEnabled(showAnnotations);
832 viewport.setShowAnnotation(showAnnotations);
833 alignPanel.setAnnotationVisible(showAnnotations);
835 else if (source == sequenceFeatures)
837 viewport.setShowSequenceFeatures(sequenceFeatures.getState());
838 alignPanel.seqPanel.seqCanvas.repaint();
840 else if (source == showAlignmentAnnotations)
842 setAnnotationsVisibility();
844 else if (source == showSequenceAnnotations)
846 setAnnotationsVisibility();
848 else if (source == sortAnnBySequence)
850 boolean newState = sortAnnBySequence.getState();
851 sortAnnByLabel.setState(false);
852 setAnnotationSortOrder(newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
853 : SequenceAnnotationOrder.NONE);
854 setViewportAnnotationOrder();
856 else if (source == sortAnnByLabel)
858 boolean newState = sortAnnByLabel.getState();
859 sortAnnBySequence.setState(false);
860 setAnnotationSortOrder(newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
861 : SequenceAnnotationOrder.NONE);
862 setViewportAnnotationOrder();
864 else if (source == showAutoFirst)
866 showAutoLast.setState(!showAutoFirst.getState());
867 setShowAutoCalculatedAbove(showAutoFirst.getState());
868 setViewportAnnotationOrder();
870 else if (source == showAutoLast)
872 showAutoFirst.setState(!showAutoLast.getState());
873 setShowAutoCalculatedAbove(showAutoFirst.getState());
874 setViewportAnnotationOrder();
876 else if (source == conservationMenuItem)
878 conservationMenuItem_actionPerformed();
880 else if (source == abovePIDThreshold)
882 abovePIDThreshold_actionPerformed();
884 else if (source == applyToAllGroups)
886 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
888 else if (source == autoCalculate)
890 viewport.autoCalculateConsensus = autoCalculate.getState();
892 else if (source == sortByTree)
894 viewport.sortByTree = sortByTree.getState();
896 else if (source == this.centreColumnLabelFlag)
898 centreColumnLabelFlag_stateChanged();
900 else if (source == this.followMouseOverFlag)
902 mouseOverFlag_stateChanged();
904 else if (source == showGroupConsensus)
906 showGroupConsensus_actionPerformed();
908 else if (source == showGroupConservation)
910 showGroupConservation_actionPerformed();
912 else if (source == showSequenceLogo)
914 showSequenceLogo_actionPerformed();
916 else if (source == normSequenceLogo)
918 normSequenceLogo_actionPerformed();
920 else if (source == showConsensusHistogram)
922 showConsensusHistogram_actionPerformed();
924 else if (source == applyAutoAnnotationSettings)
926 applyAutoAnnotationSettings_actionPerformed();
928 alignPanel.paintAlignment(true);
932 * Set the visibility state of sequence-related and/or alignment-related
933 * annotations depending on checkbox selections, and repaint.
937 private void setAnnotationsVisibility()
939 boolean showForAlignment = showAlignmentAnnotations.getState();
940 boolean showForSequences = showSequenceAnnotations.getState();
941 if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
943 for (AlignmentAnnotation aa : alignPanel.getAlignment()
944 .getAlignmentAnnotation())
946 boolean visible = (aa.sequenceRef == null ? showForAlignment
948 aa.visible = visible;
951 alignPanel.validateAnnotationDimensions(true);
956 private void setAnnotationSortOrder(SequenceAnnotationOrder order)
958 this.annotationSortOrder = order;
962 * Set flags on the viewport that control annotation ordering
964 private void setViewportAnnotationOrder()
966 this.alignPanel.av.setSortAnnotationsBy(this.annotationSortOrder);
968 .setShowAutocalculatedAbove(this.showAutoCalculatedAbove);
971 private void setShowAutoCalculatedAbove(boolean showAbove)
973 this.showAutoCalculatedAbove = showAbove;
976 private void mouseOverFlag_stateChanged()
978 viewport.setFollowHighlight(followMouseOverFlag.getState());
979 // TODO: could kick the scrollTo mechanism to reset view for current
983 private void centreColumnLabelFlag_stateChanged()
985 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
986 this.alignPanel.annotationPanel.repaint();
990 public void actionPerformed(ActionEvent evt)
992 viewport.applet.currentAlignFrame = this;
994 Object source = evt.getSource();
996 if (source == inputText)
998 inputText_actionPerformed();
1000 else if (source == loadTree)
1002 loadTree_actionPerformed();
1004 else if (source == loadApplication)
1006 launchFullApplication();
1008 else if (source == loadAnnotations)
1012 else if (source == outputAnnotations)
1014 outputAnnotations(true);
1016 else if (source == outputFeatures)
1018 outputFeatures(true, "Jalview");
1020 else if (source == closeMenuItem)
1022 closeMenuItem_actionPerformed();
1024 else if (source == copy)
1026 copy_actionPerformed();
1028 else if (source == undoMenuItem)
1030 undoMenuItem_actionPerformed();
1032 else if (source == redoMenuItem)
1034 redoMenuItem_actionPerformed();
1036 else if (source == inputText)
1038 inputText_actionPerformed();
1040 else if (source == closeMenuItem)
1042 closeMenuItem_actionPerformed();
1044 else if (source == undoMenuItem)
1046 undoMenuItem_actionPerformed();
1048 else if (source == redoMenuItem)
1050 redoMenuItem_actionPerformed();
1052 else if (source == copy)
1054 copy_actionPerformed();
1056 else if (source == pasteNew)
1058 pasteNew_actionPerformed();
1060 else if (source == pasteThis)
1062 pasteThis_actionPerformed();
1064 else if (source == cut)
1066 cut_actionPerformed();
1068 else if (source == delete)
1070 delete_actionPerformed();
1072 else if (source == grpsFromSelection)
1074 makeGrpsFromSelection_actionPerformed();
1076 else if (source == deleteGroups)
1078 deleteGroups_actionPerformed();
1080 else if (source == selectAllSequenceMenuItem)
1082 selectAllSequenceMenuItem_actionPerformed();
1084 else if (source == deselectAllSequenceMenuItem)
1086 deselectAllSequenceMenuItem_actionPerformed();
1088 else if (source == invertSequenceMenuItem)
1090 invertSequenceMenuItem_actionPerformed();
1091 // uncomment to slave sequence selections in split frame
1092 // viewport.sendSelection();
1094 else if (source == invertColSel)
1096 viewport.invertColumnSelection();
1097 alignPanel.paintAlignment(true);
1098 viewport.sendSelection();
1100 else if (source == remove2LeftMenuItem)
1102 trimAlignment(true);
1104 else if (source == remove2RightMenuItem)
1106 trimAlignment(false);
1108 else if (source == removeGappedColumnMenuItem)
1110 removeGappedColumnMenuItem_actionPerformed();
1112 else if (source == removeAllGapsMenuItem)
1114 removeAllGapsMenuItem_actionPerformed();
1116 else if (source == findMenuItem)
1118 findMenuItem_actionPerformed();
1120 else if (source == font)
1122 new FontChooser(alignPanel);
1124 else if (source == newView)
1128 else if (source == showColumns)
1130 viewport.showAllHiddenColumns();
1131 alignPanel.paintAlignment(true);
1132 viewport.sendSelection();
1134 else if (source == showSeqs)
1136 viewport.showAllHiddenSeqs();
1137 alignPanel.paintAlignment(true);
1138 // uncomment if we want to slave sequence selections in split frame
1139 // viewport.sendSelection();
1141 else if (source == hideColumns)
1143 viewport.hideSelectedColumns();
1144 alignPanel.paintAlignment(true);
1145 viewport.sendSelection();
1147 else if (source == hideSequences
1148 && viewport.getSelectionGroup() != null)
1150 viewport.hideAllSelectedSeqs();
1151 alignPanel.paintAlignment(true);
1152 // uncomment if we want to slave sequence selections in split frame
1153 // viewport.sendSelection();
1155 else if (source == hideAllButSelection)
1157 toggleHiddenRegions(false, false);
1158 alignPanel.paintAlignment(true);
1159 viewport.sendSelection();
1161 else if (source == hideAllSelection)
1163 SequenceGroup sg = viewport.getSelectionGroup();
1164 viewport.expandColSelection(sg, false);
1165 viewport.hideAllSelectedSeqs();
1166 viewport.hideSelectedColumns();
1167 alignPanel.paintAlignment(true);
1168 viewport.sendSelection();
1170 else if (source == showAllHidden)
1172 viewport.showAllHiddenColumns();
1173 viewport.showAllHiddenSeqs();
1174 alignPanel.paintAlignment(true);
1175 viewport.sendSelection();
1177 else if (source == showGroupConsensus)
1179 showGroupConsensus_actionPerformed();
1181 else if (source == showGroupConservation)
1183 showGroupConservation_actionPerformed();
1185 else if (source == showSequenceLogo)
1187 showSequenceLogo_actionPerformed();
1189 else if (source == normSequenceLogo)
1191 normSequenceLogo_actionPerformed();
1193 else if (source == showConsensusHistogram)
1195 showConsensusHistogram_actionPerformed();
1197 else if (source == applyAutoAnnotationSettings)
1199 applyAutoAnnotationSettings_actionPerformed();
1201 else if (source == featureSettings)
1203 new FeatureSettings(alignPanel);
1205 else if (source == alProperties)
1207 StringBuffer contents = new jalview.io.AlignmentProperties(
1208 viewport.getAlignment()).formatAsString();
1209 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1210 cap.setText(contents.toString());
1211 Frame frame = new Frame();
1213 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
1214 "label.alignment_properties", new String[] { getTitle() }),
1217 else if (source == overviewMenuItem)
1219 overviewMenuItem_actionPerformed();
1221 else if (source == noColourmenuItem)
1225 else if (source == clustalColour)
1227 abovePIDThreshold.setState(false);
1228 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1230 else if (source == zappoColour)
1232 changeColour(new ZappoColourScheme());
1234 else if (source == taylorColour)
1236 changeColour(new TaylorColourScheme());
1238 else if (source == hydrophobicityColour)
1240 changeColour(new HydrophobicColourScheme());
1242 else if (source == helixColour)
1244 changeColour(new HelixColourScheme());
1246 else if (source == strandColour)
1248 changeColour(new StrandColourScheme());
1250 else if (source == turnColour)
1252 changeColour(new TurnColourScheme());
1254 else if (source == buriedColour)
1256 changeColour(new BuriedColourScheme());
1258 else if (source == nucleotideColour)
1260 changeColour(new NucleotideColourScheme());
1262 else if (source == purinePyrimidineColour)
1264 changeColour(new PurinePyrimidineColourScheme());
1266 // else if (source == RNAInteractionColour)
1268 // changeColour(new RNAInteractionColourScheme());
1270 else if (source == RNAHelixColour)
1272 changeColour(new RNAHelicesColour(viewport.getAlignment()));
1273 // new RNAHelicesColourChooser(viewport, alignPanel);
1275 else if (source == modifyPID)
1277 modifyPID_actionPerformed();
1279 else if (source == modifyConservation)
1281 modifyConservation_actionPerformed();
1283 else if (source == userDefinedColour)
1285 new UserDefinedColours(alignPanel, null);
1287 else if (source == PIDColour)
1289 changeColour(new PIDColourScheme());
1291 else if (source == BLOSUM62Colour)
1293 changeColour(new Blosum62ColourScheme());
1295 else if (source == tcoffeeColour)
1297 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1299 else if (source == annotationColour)
1301 new AnnotationColourChooser(viewport, alignPanel);
1303 else if (source == annotationColumnSelection)
1305 new AnnotationColumnChooser(viewport, alignPanel);
1307 else if (source == sortPairwiseMenuItem)
1309 sortPairwiseMenuItem_actionPerformed();
1311 else if (source == sortIDMenuItem)
1313 sortIDMenuItem_actionPerformed();
1315 else if (source == sortLengthMenuItem)
1317 sortLengthMenuItem_actionPerformed();
1319 else if (source == sortGroupMenuItem)
1321 sortGroupMenuItem_actionPerformed();
1323 else if (source == removeRedundancyMenuItem)
1325 removeRedundancyMenuItem_actionPerformed();
1327 else if (source == pairwiseAlignmentMenuItem)
1329 pairwiseAlignmentMenuItem_actionPerformed();
1331 else if (source == PCAMenuItem)
1333 PCAMenuItem_actionPerformed();
1335 else if (source == averageDistanceTreeMenuItem)
1337 averageDistanceTreeMenuItem_actionPerformed();
1339 else if (source == neighbourTreeMenuItem)
1341 neighbourTreeMenuItem_actionPerformed();
1343 else if (source == njTreeBlosumMenuItem)
1345 njTreeBlosumMenuItem_actionPerformed();
1347 else if (source == avDistanceTreeBlosumMenuItem)
1349 avTreeBlosumMenuItem_actionPerformed();
1351 else if (source == documentation)
1353 documentation_actionPerformed();
1355 else if (source == about)
1357 about_actionPerformed();
1362 public void inputText_actionPerformed()
1364 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1365 Frame frame = new Frame();
1367 jalview.bin.JalviewLite.addFrame(frame,
1368 MessageManager.getString("label.input_cut_paste"), 500, 500);
1371 protected void outputText_actionPerformed(ActionEvent e)
1373 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1374 Frame frame = new Frame();
1376 JalviewLite.addFrame(frame, MessageManager.formatMessage(
1377 "label.alignment_output_command",
1378 new Object[] { e.getActionCommand() }), 600, 500);
1380 FileFormatI fileFormat = FileFormats.getInstance().forName(
1381 e.getActionCommand());
1382 cap.setText(new AppletFormatAdapter(alignPanel).formatSequences(
1383 fileFormat, viewport.getAlignment(),
1384 viewport.getShowJVSuffix()));
1387 public void loadAnnotations()
1389 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1390 cap.setText(MessageManager
1391 .getString("label.paste_features_annotations_Tcoffee_here"));
1392 cap.setAnnotationImport();
1393 Frame frame = new Frame();
1395 jalview.bin.JalviewLite.addFrame(frame,
1396 MessageManager.getString("action.paste_annotations"), 400, 300);
1400 public String outputAnnotations(boolean displayTextbox)
1402 String annotation = new AnnotationFile()
1403 .printAnnotationsForView(viewport);
1407 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1408 Frame frame = new Frame();
1410 jalview.bin.JalviewLite.addFrame(frame,
1411 MessageManager.getString("label.annotations"), 600, 500);
1412 cap.setText(annotation);
1418 private Map<String, FeatureColourI> getDisplayedFeatureCols()
1420 if (alignPanel.getFeatureRenderer() != null
1421 && viewport.getFeaturesDisplayed() != null)
1423 return alignPanel.getFeatureRenderer().getDisplayedFeatureCols();
1429 public String outputFeatures(boolean displayTextbox, String format)
1432 FeaturesFile formatter = new FeaturesFile();
1433 if (format.equalsIgnoreCase("Jalview"))
1435 features = formatter.printJalviewFormat(viewport.getAlignment()
1436 .getSequencesArray(), getDisplayedFeatureCols());
1440 features = formatter.printGffFormat(viewport.getAlignment()
1441 .getSequencesArray(), getDisplayedFeatureCols());
1446 boolean frimport = false;
1447 if (features == null || features.equals("No Features Visible"))
1449 features = "# No features visible - paste some and import them here.";
1453 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1456 cap.setAnnotationImport();
1458 Frame frame = new Frame();
1460 jalview.bin.JalviewLite.addFrame(frame,
1461 MessageManager.getString("label.features"), 600, 500);
1462 cap.setText(features);
1466 if (features == null)
1475 void launchFullApplication()
1477 StringBuffer url = new StringBuffer(jalviewServletURL);
1479 // allow servlet parameters to be passed in applet parameter
1480 String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
1482 url.append(firstSep);
1485 + appendProtocol(viewport.applet.getParameter("file")));
1487 if (viewport.applet.getParameter("features") != null)
1489 url.append("&features=");
1490 url.append(appendProtocol(viewport.applet.getParameter("features")));
1493 if (viewport.applet.getParameter("annotations") != null)
1495 url.append("&annotations=");
1496 url.append(appendProtocol(viewport.applet.getParameter("annotations")));
1499 if (viewport.applet.getParameter("jnetfile") != null
1500 || viewport.applet.getParameter("jpredfile") != null)
1502 url.append("&annotations=");
1503 url.append(appendProtocol(viewport.applet.getParameter("jnetfile") != null ? viewport.applet
1504 .getParameter("jnetfile") : viewport.applet
1505 .getParameter("jpredfile")));
1508 if (viewport.applet.getParameter("defaultColour") != null)
1510 url.append("&colour="
1511 + removeWhiteSpace(viewport.applet
1512 .getParameter("defaultColour")));
1515 if (viewport.applet.getParameter("userDefinedColour") != null)
1517 url.append("&colour="
1518 + removeWhiteSpace(viewport.applet
1519 .getParameter("userDefinedColour")));
1521 if (viewport.applet.getParameter("tree") != null)
1524 + appendProtocol(viewport.applet.getParameter("tree")));
1526 if (viewport.applet.getParameter("treeFile") != null)
1529 + appendProtocol(viewport.applet.getParameter("treeFile")));
1532 showURL(url.toString(), "FULL_APP");
1535 String removeWhiteSpace(String colour)
1537 StringBuffer sb = new StringBuffer();
1538 for (int i = 0; i < colour.length(); i++)
1540 if (Character.isWhitespace(colour.charAt(i)))
1546 sb.append(colour.charAt(i));
1550 return sb.toString();
1553 String appendProtocol(String url)
1558 url = URLEncoder.encode(url);
1561 * When we finally deprecate 1.1 compatibility, we can start to use
1562 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1563 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1564 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1565 * ex.printStackTrace(); }
1567 catch (java.net.MalformedURLException ex)
1569 url = viewport.applet.getCodeBase() + url;
1574 public void closeMenuItem_actionPerformed()
1576 PaintRefresher.RemoveComponent(alignPanel);
1577 if (alignPanel.seqPanel != null
1578 && alignPanel.seqPanel.seqCanvas != null)
1580 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1582 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1584 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1587 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1602 void updateEditMenuBar()
1605 if (viewport.getHistoryList().size() > 0)
1607 undoMenuItem.setEnabled(true);
1608 CommandI command = viewport.getHistoryList().peek();
1609 undoMenuItem.setLabel(MessageManager.formatMessage(
1610 "label.undo_command",
1611 new Object[] { command.getDescription() }));
1615 undoMenuItem.setEnabled(false);
1616 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1619 if (viewport.getRedoList().size() > 0)
1621 redoMenuItem.setEnabled(true);
1623 CommandI command = viewport.getRedoList().peek();
1624 redoMenuItem.setLabel(MessageManager.formatMessage(
1625 "label.redo_command",
1626 new Object[] { command.getDescription() }));
1630 redoMenuItem.setEnabled(false);
1631 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1639 public void addHistoryItem(CommandI command)
1641 if (command.getSize() > 0)
1643 viewport.addToHistoryList(command);
1644 viewport.clearRedoList();
1645 updateEditMenuBar();
1646 viewport.updateHiddenColumns();
1651 * TODO: JAL-1104 DOCUMENT ME!
1656 protected void undoMenuItem_actionPerformed()
1658 if (viewport.getHistoryList().isEmpty())
1663 CommandI command = viewport.getHistoryList().pop();
1664 viewport.addToRedoList(command);
1665 command.undoCommand(null);
1667 AlignmentViewport originalSource = getOriginatingSource(command);
1669 if (originalSource != viewport)
1672 .println("Warning: Viewport object mismatch whilst undoing");
1674 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1675 // viewport.getColumnSelection().getHiddenColumns()
1677 updateEditMenuBar();
1678 originalSource.firePropertyChange("alignment", null, originalSource
1679 .getAlignment().getSequences());
1683 * TODO: JAL-1104 DOCUMENT ME!
1688 protected void redoMenuItem_actionPerformed()
1690 if (viewport.getRedoList().isEmpty())
1695 CommandI command = viewport.getRedoList().pop();
1696 viewport.addToHistoryList(command);
1697 command.doCommand(null);
1699 AlignmentViewport originalSource = getOriginatingSource(command);
1701 if (originalSource != viewport)
1704 .println("Warning: Viewport object mismatch whilst re-doing");
1706 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1707 // viewport.getColumnSelection().getHiddenColumns()
1710 updateEditMenuBar();
1711 originalSource.firePropertyChange("alignment", null, originalSource
1712 .getAlignment().getSequences());
1715 AlignmentViewport getOriginatingSource(CommandI command)
1717 AlignmentViewport originalSource = null;
1718 // For sequence removal and addition, we need to fire
1719 // the property change event FROM the viewport where the
1720 // original alignment was altered
1721 AlignmentI al = null;
1722 if (command instanceof EditCommand)
1724 EditCommand editCommand = (EditCommand) command;
1725 al = editCommand.getAlignment();
1726 Vector comps = (Vector) PaintRefresher.components.get(viewport
1727 .getSequenceSetId());
1728 for (int i = 0; i < comps.size(); i++)
1730 if (comps.elementAt(i) instanceof AlignmentPanel)
1732 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1734 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1741 if (originalSource == null)
1743 // The original view is closed, we must validate
1744 // the current view against the closed view first
1747 PaintRefresher.validateSequences(al, viewport.getAlignment());
1750 originalSource = viewport;
1753 return originalSource;
1757 * Move the currently selected sequences up or down one position in the
1762 public void moveSelectedSequences(boolean up)
1764 SequenceGroup sg = viewport.getSelectionGroup();
1769 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1770 up ? null : viewport.getHiddenRepSequences(), up);
1771 alignPanel.paintAlignment(true);
1774 * Also move cDNA/protein complement sequences
1776 AlignViewportI complement = viewport.getCodingComplement();
1777 if (complement != null)
1779 SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
1780 viewport, complement);
1781 complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
1782 up ? null : complement.getHiddenRepSequences(), up);
1783 getSplitFrame().getComplement(this).alignPanel.paintAlignment(true);
1787 synchronized void slideSequences(boolean right, int size)
1789 List<SequenceI> sg = new Vector<SequenceI>();
1790 if (viewport.cursorMode)
1792 sg.add(viewport.getAlignment().getSequenceAt(
1793 alignPanel.seqPanel.seqCanvas.cursorY));
1795 else if (viewport.getSelectionGroup() != null
1796 && viewport.getSelectionGroup().getSize() != viewport
1797 .getAlignment().getHeight())
1799 sg = viewport.getSelectionGroup().getSequences(
1800 viewport.getHiddenRepSequences());
1808 Vector<SequenceI> invertGroup = new Vector();
1810 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1812 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1814 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1818 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1820 SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup
1822 for (int i = 0; i < invertGroup.size(); i++)
1824 seqs2[i] = invertGroup.elementAt(i);
1827 SlideSequencesCommand ssc;
1830 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1831 size, viewport.getGapCharacter());
1835 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1836 size, viewport.getGapCharacter());
1839 int groupAdjustment = 0;
1840 if (ssc.getGapsInsertedBegin() && right)
1842 if (viewport.cursorMode)
1844 alignPanel.seqPanel.moveCursor(size, 0);
1848 groupAdjustment = size;
1851 else if (!ssc.getGapsInsertedBegin() && !right)
1853 if (viewport.cursorMode)
1855 alignPanel.seqPanel.moveCursor(-size, 0);
1859 groupAdjustment = -size;
1863 if (groupAdjustment != 0)
1865 viewport.getSelectionGroup().setStartRes(
1866 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1867 viewport.getSelectionGroup().setEndRes(
1868 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1871 boolean appendHistoryItem = false;
1872 Deque<CommandI> historyList = viewport.getHistoryList();
1873 if (historyList != null && historyList.size() > 0
1874 && historyList.peek() instanceof SlideSequencesCommand)
1876 appendHistoryItem = ssc
1877 .appendSlideCommand((SlideSequencesCommand) historyList
1881 if (!appendHistoryItem)
1883 addHistoryItem(ssc);
1889 static StringBuffer copiedSequences;
1891 static Vector copiedHiddenColumns;
1893 protected void copy_actionPerformed()
1895 if (viewport.getSelectionGroup() == null)
1900 SequenceGroup sg = viewport.getSelectionGroup();
1901 copiedSequences = new StringBuffer();
1902 Map<Integer, SequenceI> orderedSeqs = new HashMap<Integer, SequenceI>();
1903 for (int i = 0; i < sg.getSize(); i++)
1905 SequenceI seq = sg.getSequenceAt(i);
1906 int index = viewport.getAlignment().findIndex(seq);
1907 orderedSeqs.put(index, seq);
1910 int index = 0, startRes, endRes;
1913 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1915 copiedHiddenColumns = new Vector();
1916 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1917 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1919 copiedHiddenColumns.addElement(new int[] {
1920 region[0] - hiddenOffset, region[1] - hiddenOffset });
1925 copiedHiddenColumns = null;
1928 for (int i = 0; i < sg.getSize(); i++)
1930 SequenceI seq = null;
1934 if (orderedSeqs.containsKey(index))
1936 seq = orderedSeqs.get(index);
1947 // Returns residue following index if gap
1948 startRes = seq.findPosition(sg.getStartRes());
1951 // Need to find the residue preceeding index if gap
1954 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1956 ch = seq.getCharAt(j);
1957 if (!jalview.util.Comparison.isGap((ch)))
1965 endRes += seq.getStart() - 1;
1968 copiedSequences.append(seq.getName()
1974 + seq.getSequenceAsString(sg.getStartRes(),
1975 sg.getEndRes() + 1) + "\n");
1980 protected void pasteNew_actionPerformed()
1985 protected void pasteThis_actionPerformed()
1990 void paste(boolean newAlignment)
1995 if (copiedSequences == null)
2000 StringTokenizer st = new StringTokenizer(copiedSequences.toString());
2001 Vector seqs = new Vector();
2002 while (st.hasMoreElements())
2004 String name = st.nextToken();
2005 int start = Integer.parseInt(st.nextToken());
2006 int end = Integer.parseInt(st.nextToken());
2007 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
2009 SequenceI[] newSeqs = new SequenceI[seqs.size()];
2010 for (int i = 0; i < seqs.size(); i++)
2012 newSeqs[i] = (SequenceI) seqs.elementAt(i);
2017 String newtitle = MessageManager
2018 .getString("label.copied_sequences");
2019 if (getTitle().startsWith(
2020 MessageManager.getString("label.copied_sequences")))
2022 newtitle = getTitle();
2026 newtitle = newtitle.concat(MessageManager.formatMessage(
2027 "label.from_msname", new String[] { getTitle() }));
2029 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
2030 viewport.applet, newtitle, false);
2031 if (copiedHiddenColumns != null)
2033 for (int i = 0; i < copiedHiddenColumns.size(); i++)
2035 int[] region = (int[]) copiedHiddenColumns.elementAt(i);
2036 af.viewport.hideColumns(region[0], region[1]);
2040 jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
2045 addSequences(newSeqs);
2048 } catch (Exception ex)
2050 } // could be anything being pasted in here
2054 void addSequences(SequenceI[] seqs)
2056 for (int i = 0; i < seqs.length; i++)
2058 viewport.getAlignment().addSequence(seqs[i]);
2062 addHistoryItem(new EditCommand(
2063 MessageManager.getString("label.add_sequences"), Action.PASTE,
2064 seqs, 0, viewport.getAlignment().getWidth(),
2065 viewport.getAlignment()));
2067 viewport.setEndSeq(viewport.getAlignment().getHeight());
2068 viewport.getAlignment().getWidth();
2069 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2074 protected void cut_actionPerformed()
2076 copy_actionPerformed();
2077 delete_actionPerformed();
2080 protected void delete_actionPerformed()
2083 SequenceGroup sg = viewport.getSelectionGroup();
2089 Vector seqs = new Vector();
2091 for (int i = 0; i < sg.getSize(); i++)
2093 seq = sg.getSequenceAt(i);
2094 seqs.addElement(seq);
2098 * If the cut affects all sequences, warn, remove highlighted columns
2100 if (sg.getSize() == viewport.getAlignment().getHeight())
2102 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2103 .getAlignment().getWidth()) ? true : false;
2104 if (isEntireAlignWidth)
2106 String title = MessageManager.getString("label.delete_all");
2107 Panel infoPanel = new Panel();
2108 infoPanel.setLayout(new FlowLayout());
2110 .add(new Label(MessageManager.getString("warn.delete_all")));
2112 final JVDialog dialog = new JVDialog(this, title, true, 400, 200);
2113 dialog.setMainPanel(infoPanel);
2114 dialog.ok.setLabel(MessageManager.getString("action.ok"));
2115 dialog.cancel.setLabel(MessageManager.getString("action.cancel"));
2116 dialog.setVisible(true);
2123 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2124 sg.getEndRes() + 1);
2127 SequenceI[] cut = new SequenceI[seqs.size()];
2128 for (int i = 0; i < seqs.size(); i++)
2130 cut[i] = (SequenceI) seqs.elementAt(i);
2134 * //ADD HISTORY ITEM
2136 addHistoryItem(new EditCommand(
2137 MessageManager.getString("label.cut_sequences"), Action.CUT,
2138 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2139 viewport.getAlignment()));
2141 viewport.setSelectionGroup(null);
2142 viewport.getAlignment().deleteGroup(sg);
2144 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2147 if (viewport.getAlignment().getHeight() < 1)
2149 this.setVisible(false);
2151 viewport.sendSelection();
2155 * group consensus toggled
2158 protected void showGroupConsensus_actionPerformed()
2160 viewport.setShowGroupConsensus(showGroupConsensus.getState());
2161 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2166 * group conservation toggled.
2168 protected void showGroupConservation_actionPerformed()
2170 viewport.setShowGroupConservation(showGroupConservation.getState());
2171 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2178 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
2179 * .event.ActionEvent)
2181 protected void showConsensusHistogram_actionPerformed()
2183 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
2184 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2191 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
2192 * .event.ActionEvent)
2194 protected void showSequenceLogo_actionPerformed()
2196 viewport.setShowSequenceLogo(showSequenceLogo.getState());
2197 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2200 protected void normSequenceLogo_actionPerformed()
2202 showSequenceLogo.setState(true);
2203 viewport.setShowSequenceLogo(true);
2204 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
2205 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2208 protected void applyAutoAnnotationSettings_actionPerformed()
2210 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2213 protected void makeGrpsFromSelection_actionPerformed()
2215 if (avc.makeGroupsFromSelection())
2217 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2218 alignPanel.updateAnnotation();
2219 alignPanel.paintAlignment(true);
2223 protected void createGroup_actionPerformed()
2228 protected void unGroup_actionPerformed()
2232 alignPanel.alignmentChanged();
2236 protected void deleteGroups_actionPerformed()
2238 if (avc.deleteGroups())
2240 alignPanel.alignmentChanged();
2244 public void selectAllSequenceMenuItem_actionPerformed()
2246 SequenceGroup sg = new SequenceGroup();
2247 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2249 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2251 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2252 viewport.setSelectionGroup(sg);
2253 // JAL-2034 - should delegate to
2254 // alignPanel to decide if overview needs
2256 alignPanel.paintAlignment(false);
2257 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2258 viewport.sendSelection();
2261 public void deselectAllSequenceMenuItem_actionPerformed()
2263 if (viewport.cursorMode)
2265 alignPanel.seqPanel.keyboardNo1 = null;
2266 alignPanel.seqPanel.keyboardNo2 = null;
2268 viewport.setSelectionGroup(null);
2269 viewport.getColumnSelection().clear();
2270 viewport.setSelectionGroup(null);
2271 alignPanel.idPanel.idCanvas.searchResults = null;
2272 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2273 // JAL-2034 - should delegate to
2274 // alignPanel to decide if overview needs
2276 alignPanel.paintAlignment(false);
2277 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2278 viewport.sendSelection();
2281 public void invertSequenceMenuItem_actionPerformed()
2283 SequenceGroup sg = viewport.getSelectionGroup();
2284 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2286 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2289 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2290 viewport.sendSelection();
2293 public void invertColSel_actionPerformed()
2295 viewport.invertColumnSelection();
2296 alignPanel.paintAlignment(true);
2297 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2298 viewport.sendSelection();
2301 void trimAlignment(boolean trimLeft)
2303 ColumnSelection colSel = viewport.getColumnSelection();
2306 if (!colSel.isEmpty())
2310 column = colSel.getMin();
2314 column = colSel.getMax();
2318 if (viewport.getSelectionGroup() != null)
2320 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2321 viewport.getHiddenRepSequences());
2325 seqs = viewport.getAlignment().getSequencesArray();
2328 TrimRegionCommand trimRegion;
2331 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2332 column, viewport.getAlignment());
2333 viewport.setStartRes(0);
2337 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2338 column, viewport.getAlignment());
2341 statusBar.setText(MessageManager.formatMessage(
2342 "label.removed_columns",
2343 new String[] { Integer.valueOf(trimRegion.getSize())
2345 addHistoryItem(trimRegion);
2347 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2349 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2350 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2352 viewport.getAlignment().deleteGroup(sg);
2356 viewport.firePropertyChange("alignment", null, viewport
2357 .getAlignment().getSequences());
2361 public void removeGappedColumnMenuItem_actionPerformed()
2363 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2366 if (viewport.getSelectionGroup() != null)
2368 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2369 viewport.getHiddenRepSequences());
2370 start = viewport.getSelectionGroup().getStartRes();
2371 end = viewport.getSelectionGroup().getEndRes();
2375 seqs = viewport.getAlignment().getSequencesArray();
2378 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2379 "Remove Gapped Columns", seqs, start, end,
2380 viewport.getAlignment());
2382 addHistoryItem(removeGapCols);
2384 statusBar.setText(MessageManager.formatMessage(
2385 "label.removed_empty_columns",
2386 new String[] { Integer.valueOf(removeGapCols.getSize())
2389 // This is to maintain viewport position on first residue
2390 // of first sequence
2391 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2392 int startRes = seq.findPosition(viewport.startRes);
2393 // ShiftList shifts;
2394 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2395 // edit.alColumnChanges=shifts.getInverse();
2396 // if (viewport.hasHiddenColumns)
2397 // viewport.getColumnSelection().compensateForEdits(shifts);
2398 viewport.setStartRes(seq.findIndex(startRes) - 1);
2399 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2404 public void removeAllGapsMenuItem_actionPerformed()
2406 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2409 if (viewport.getSelectionGroup() != null)
2411 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2412 viewport.getHiddenRepSequences());
2413 start = viewport.getSelectionGroup().getStartRes();
2414 end = viewport.getSelectionGroup().getEndRes();
2418 seqs = viewport.getAlignment().getSequencesArray();
2421 // This is to maintain viewport position on first residue
2422 // of first sequence
2423 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2424 int startRes = seq.findPosition(viewport.startRes);
2426 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2427 viewport.getAlignment()));
2429 viewport.setStartRes(seq.findIndex(startRes) - 1);
2431 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2436 public void findMenuItem_actionPerformed()
2438 new Finder(alignPanel);
2442 * create a new view derived from the current view
2445 * @return frame for the new view
2447 public AlignFrame newView(String viewtitle)
2450 if (viewport.hasHiddenRows())
2452 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2453 .getFullAlignment().getSequencesArray());
2457 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2460 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2462 for (int i = 0; i < viewport.getAlignment().getAlignmentAnnotation().length; i++)
2464 if (!viewport.getAlignment().getAlignmentAnnotation()[i].autoCalculated)
2466 newal.addAnnotation(viewport.getAlignment()
2467 .getAlignmentAnnotation()[i]);
2472 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2474 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2475 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2476 PaintRefresher.Register(newaf.alignPanel,
2477 newaf.alignPanel.av.getSequenceSetId());
2479 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2480 newaf.alignPanel.av.getSequenceSetId());
2481 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2482 newaf.alignPanel.av.getSequenceSetId());
2484 Vector comps = (Vector) PaintRefresher.components.get(viewport
2485 .getSequenceSetId());
2487 for (int i = 0; i < comps.size(); i++)
2489 if (comps.elementAt(i) instanceof AlignmentPanel)
2495 String title = new String(this.getTitle());
2496 if (viewtitle != null)
2498 title = viewtitle + " ( " + title + ")";
2502 if (title.indexOf("(View") > -1)
2504 title = title.substring(0, title.indexOf("(View"));
2506 title += "(View " + viewSize + ")";
2509 newaf.setTitle(title.toString());
2511 newaf.viewport.setHistoryList(viewport.getHistoryList());
2512 newaf.viewport.setRedoList(viewport.getRedoList());
2518 * @return list of feature groups on the view
2520 public String[] getFeatureGroups()
2522 FeatureRenderer fr = null;
2523 if (alignPanel != null
2524 && (fr = alignPanel.getFeatureRenderer()) != null)
2526 List<String> gps = fr.getFeatureGroups();
2527 String[] _gps = gps.toArray(new String[gps.size()]);
2534 * get sequence feature groups that are hidden or shown
2540 public String[] getFeatureGroupsOfState(boolean visible)
2542 FeatureRenderer fr = null;
2543 if (alignPanel != null
2544 && (fr = alignPanel.getFeatureRenderer()) != null)
2546 List<String> gps = fr.getGroups(visible);
2547 String[] _gps = gps.toArray(new String[gps.size()]);
2554 * Change the display state for the given feature groups
2557 * list of group strings
2559 * visible or invisible
2561 public void setFeatureGroupState(String[] groups, boolean state)
2563 FeatureRenderer fr = null;
2564 this.sequenceFeatures.setState(true);
2565 viewport.setShowSequenceFeatures(true);
2566 if (alignPanel != null
2567 && (fr = alignPanel.getFeatureRenderer()) != null)
2570 fr.setGroupVisibility(Arrays.asList(groups), state);
2571 alignPanel.seqPanel.seqCanvas.repaint();
2572 if (alignPanel.overviewPanel != null)
2574 alignPanel.overviewPanel.updateOverviewImage();
2579 public void seqLimits_itemStateChanged()
2581 viewport.setShowJVSuffix(seqLimits.getState());
2582 alignPanel.fontChanged();
2583 alignPanel.paintAlignment(true);
2586 protected void colourTextMenuItem_actionPerformed()
2588 viewport.setColourText(colourTextMenuItem.getState());
2589 alignPanel.paintAlignment(true);
2592 protected void displayNonconservedMenuItem_actionPerformed()
2594 viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
2595 alignPanel.paintAlignment(true);
2598 protected void wrapMenuItem_actionPerformed()
2600 viewport.setWrapAlignment(wrapMenuItem.getState());
2601 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2602 scaleAbove.setEnabled(wrapMenuItem.getState());
2603 scaleLeft.setEnabled(wrapMenuItem.getState());
2604 scaleRight.setEnabled(wrapMenuItem.getState());
2605 alignPanel.paintAlignment(true);
2608 public void overviewMenuItem_actionPerformed()
2610 if (alignPanel.overviewPanel != null)
2615 Frame frame = new Frame();
2616 OverviewPanel overview = new OverviewPanel(alignPanel);
2617 frame.add(overview);
2618 // +50 must allow for applet frame window
2619 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
2620 "label.overview_params", new String[] { this.getTitle() }),
2621 overview.getPreferredSize().width,
2622 overview.getPreferredSize().height + 50);
2625 final AlignmentPanel ap = alignPanel;
2626 frame.addWindowListener(new WindowAdapter()
2629 public void windowClosing(WindowEvent e)
2633 ap.setOverviewPanel(null);
2638 alignPanel.setOverviewPanel(overview);
2643 public void changeColour(ColourSchemeI cs)
2645 viewport.setGlobalColourScheme(cs);
2647 alignPanel.paintAlignment(true);
2650 protected void modifyPID_actionPerformed()
2652 if (viewport.getAbovePIDThreshold()
2653 && viewport.getGlobalColourScheme() != null)
2655 SliderPanel.setPIDSliderSource(alignPanel,
2656 viewport.getResidueShading(), alignPanel.getViewName());
2657 SliderPanel.showPIDSlider();
2661 protected void modifyConservation_actionPerformed()
2663 if (viewport.getConservationSelected()
2664 && viewport.getGlobalColourScheme() != null)
2666 SliderPanel.setConservationSlider(alignPanel,
2667 viewport.getResidueShading(), alignPanel.getViewName());
2668 SliderPanel.showConservationSlider();
2672 protected void conservationMenuItem_actionPerformed()
2674 boolean selected = conservationMenuItem.getState();
2675 modifyConservation.setEnabled(selected);
2676 viewport.setConservationSelected(selected);
2678 // viewport.setAbovePIDThreshold(false);
2679 // abovePIDThreshold.setState(false);
2681 changeColour(viewport.getGlobalColourScheme());
2685 modifyConservation_actionPerformed();
2689 SliderPanel.hideConservationSlider();
2693 public void abovePIDThreshold_actionPerformed()
2695 boolean selected = abovePIDThreshold.getState();
2696 modifyPID.setEnabled(selected);
2697 viewport.setAbovePIDThreshold(selected);
2698 // conservationMenuItem.setState(false);
2699 // viewport.setConservationSelected(false);
2701 changeColour(viewport.getGlobalColourScheme());
2705 modifyPID_actionPerformed();
2709 SliderPanel.hidePIDSlider();
2713 public void sortPairwiseMenuItem_actionPerformed()
2715 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2716 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
2717 .getAlignment().getSequenceAt(0), null);
2719 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2720 viewport.getAlignment()));
2721 alignPanel.paintAlignment(true);
2724 public void sortIDMenuItem_actionPerformed()
2726 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2727 AlignmentSorter.sortByID(viewport.getAlignment());
2728 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
2729 viewport.getAlignment()));
2730 alignPanel.paintAlignment(true);
2733 public void sortLengthMenuItem_actionPerformed()
2735 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2736 AlignmentSorter.sortByLength(viewport.getAlignment());
2737 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2738 viewport.getAlignment()));
2739 alignPanel.paintAlignment(true);
2742 public void sortGroupMenuItem_actionPerformed()
2744 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2745 AlignmentSorter.sortByGroup(viewport.getAlignment());
2746 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2747 viewport.getAlignment()));
2748 alignPanel.paintAlignment(true);
2752 public void removeRedundancyMenuItem_actionPerformed()
2754 new RedundancyPanel(alignPanel);
2757 public void pairwiseAlignmentMenuItem_actionPerformed()
2759 if (viewport.getSelectionGroup() != null
2760 && viewport.getSelectionGroup().getSize() > 1)
2762 Frame frame = new Frame();
2763 frame.add(new PairwiseAlignPanel(alignPanel));
2764 jalview.bin.JalviewLite.addFrame(frame,
2765 MessageManager.getString("action.pairwise_alignment"), 600,
2770 public void PCAMenuItem_actionPerformed()
2772 // are the sequences aligned?
2773 if (!viewport.getAlignment().isAligned(false))
2776 int Width = viewport.getAlignment().getWidth();
2778 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2780 current = viewport.getAlignment().getSequenceAt(i);
2782 if (current.getLength() < Width)
2784 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2787 alignPanel.paintAlignment(true);
2790 if ((viewport.getSelectionGroup() != null
2791 && viewport.getSelectionGroup().getSize() < 4 && viewport
2792 .getSelectionGroup().getSize() > 0)
2793 || viewport.getAlignment().getHeight() < 4)
2800 new PCAPanel(viewport);
2801 } catch (java.lang.OutOfMemoryError ex)
2807 public void averageDistanceTreeMenuItem_actionPerformed()
2809 NewTreePanel(NJTree.AVERAGE_DISTANCE, "PID",
2810 "Average distance tree using PID");
2813 public void neighbourTreeMenuItem_actionPerformed()
2815 NewTreePanel(NJTree.NEIGHBOUR_JOINING, "PID",
2816 "Neighbour joining tree using PID");
2819 protected void njTreeBlosumMenuItem_actionPerformed()
2821 NewTreePanel(NJTree.NEIGHBOUR_JOINING, "BL",
2822 "Neighbour joining tree using BLOSUM62");
2825 protected void avTreeBlosumMenuItem_actionPerformed()
2827 NewTreePanel(NJTree.AVERAGE_DISTANCE, "BL",
2828 "Average distance tree using BLOSUM62");
2831 void NewTreePanel(String type, String pwType, String title)
2833 // are the sequences aligned?
2834 if (!viewport.getAlignment().isAligned(false))
2837 int Width = viewport.getAlignment().getWidth();
2839 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2841 current = viewport.getAlignment().getSequenceAt(i);
2843 if (current.getLength() < Width)
2845 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2848 alignPanel.paintAlignment(true);
2852 if ((viewport.getSelectionGroup() != null && viewport
2853 .getSelectionGroup().getSize() > 1)
2854 || (viewport.getAlignment().getHeight() > 1))
2856 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2858 addTreeMenuItem(tp, title);
2860 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2864 void loadTree_actionPerformed()
2866 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2867 cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2868 cap.setTreeImport();
2869 Frame frame = new Frame();
2871 jalview.bin.JalviewLite.addFrame(frame,
2872 MessageManager.getString("label.paste_newick_file"), 400, 300);
2875 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2877 TreePanel tp = new TreePanel(alignPanel, treeFile,
2878 MessageManager.getString("label.load_tree_from_file"), tree);
2879 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2880 addTreeMenuItem(tp, treeFile);
2884 * sort the alignment using the given treePanel
2887 * tree used to sort view
2889 * string used for undo event name
2891 public void sortByTree(TreePanel treePanel, String title)
2893 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2895 .sortByTree(viewport.getAlignment(), treePanel.getTree());
2896 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2897 // HistoryItem.SORT));
2898 addHistoryItem(new OrderCommand(MessageManager.formatMessage(
2899 "label.order_by_params", new String[] { title }), oldOrder,
2900 viewport.getAlignment()));
2901 alignPanel.paintAlignment(true);
2905 * Do any automatic reordering of the alignment and add the necessary bits to
2906 * the menu structure for the new tree
2911 protected void addTreeMenuItem(final TreePanel treePanel,
2914 final MenuItem item = new MenuItem(title);
2915 sortByTreeMenu.add(item);
2916 item.addActionListener(new java.awt.event.ActionListener()
2919 public void actionPerformed(ActionEvent evt)
2921 sortByTree(treePanel, title); // treePanel.getTitle());
2925 treePanel.addWindowListener(new WindowAdapter()
2928 public void windowOpened(WindowEvent e)
2930 if (viewport.sortByTree)
2932 sortByTree(treePanel, title);
2934 super.windowOpened(e);
2938 public void windowClosing(WindowEvent e)
2940 sortByTreeMenu.remove(item);
2945 public boolean sortBy(AlignmentOrder alorder, String undoname)
2947 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2948 if (viewport.applet.debug)
2950 System.err.println("Sorting " + alorder.getOrder().size()
2951 + " in alignment '" + getTitle() + "'");
2953 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2954 if (undoname != null)
2956 addHistoryItem(new OrderCommand(undoname, oldOrder,
2957 viewport.getAlignment()));
2959 alignPanel.paintAlignment(true);
2963 protected void documentation_actionPerformed()
2965 alignPanel.av.applet.openJalviewHelpUrl();
2968 protected void about_actionPerformed()
2971 class AboutPanel extends Canvas
2977 public AboutPanel(String version, String builddate)
2979 this.version = version;
2980 this.builddate = builddate;
2984 public void paint(Graphics g)
2986 g.setColor(Color.white);
2987 g.fillRect(0, 0, getSize().width, getSize().height);
2988 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
2989 FontMetrics fm = g.getFontMetrics();
2990 int fh = fm.getHeight();
2992 g.setColor(Color.black);
2993 // TODO: update this text for each release or centrally store it for
2994 // lite and application
2995 g.setFont(new Font("Helvetica", Font.BOLD, 14));
2996 g.drawString(MessageManager.formatMessage(
2997 "label.jalviewLite_release", new String[] { version }), x,
2999 g.setFont(new Font("Helvetica", Font.BOLD, 12));
3000 g.drawString(MessageManager.formatMessage(
3001 "label.jaview_build_date", new String[] { builddate }), x,
3003 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3004 g.drawString(MessageManager.getString("label.jalview_authors_1"),
3006 g.drawString(MessageManager.getString("label.jalview_authors_2"),
3007 x + 50, y += fh + 8);
3009 MessageManager.getString("label.jalview_dev_managers"), x,
3011 g.drawString(MessageManager
3012 .getString("label.jalview_distribution_lists"), x, y += fh);
3013 g.drawString(MessageManager.getString("label.jalview_please_cite"),
3016 MessageManager.getString("label.jalview_cite_1_authors"),
3019 MessageManager.getString("label.jalview_cite_1_title"), x,
3021 g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
3026 Frame frame = new Frame();
3027 frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite
3029 jalview.bin.JalviewLite.addFrame(frame,
3030 MessageManager.getString("label.jalview"), 580, 220);
3034 public void showURL(String url, String target)
3036 if (viewport.applet == null)
3038 System.out.println("Not running as applet - no browser available.");
3042 viewport.applet.showURL(url, target);
3046 // ////////////////////////////////////////////////////////////////////////////////
3047 // JBuilder Graphics here
3049 MenuBar alignFrameMenuBar = new MenuBar();
3051 Menu fileMenu = new Menu(MessageManager.getString("action.file"));
3053 MenuItem loadApplication = new MenuItem(
3054 MessageManager.getString("label.view_full_application"));
3056 MenuItem loadTree = new MenuItem(
3057 MessageManager.getString("label.load_associated_tree"));
3059 MenuItem loadAnnotations = new MenuItem(
3060 MessageManager.getString("label.load_features_annotations"));
3062 MenuItem outputFeatures = new MenuItem(
3063 MessageManager.getString("label.export_features"));
3065 MenuItem outputAnnotations = new MenuItem(
3066 MessageManager.getString("label.export_annotations"));
3068 MenuItem closeMenuItem = new MenuItem(
3069 MessageManager.getString("action.close"));
3071 MenuItem selectAllSequenceMenuItem = new MenuItem(
3072 MessageManager.getString("action.select_all"));
3074 MenuItem deselectAllSequenceMenuItem = new MenuItem(
3075 MessageManager.getString("action.deselect_all"));
3077 MenuItem invertSequenceMenuItem = new MenuItem(
3078 MessageManager.getString("action.invert_selection"));
3080 MenuItem remove2LeftMenuItem = new MenuItem();
3082 MenuItem remove2RightMenuItem = new MenuItem();
3084 MenuItem removeGappedColumnMenuItem = new MenuItem();
3086 MenuItem removeAllGapsMenuItem = new MenuItem();
3088 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
3090 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
3092 MenuItem sortPairwiseMenuItem = new MenuItem();
3094 MenuItem sortIDMenuItem = new MenuItem();
3096 MenuItem sortLengthMenuItem = new MenuItem();
3098 MenuItem sortGroupMenuItem = new MenuItem();
3100 MenuItem removeRedundancyMenuItem = new MenuItem();
3102 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
3104 MenuItem PCAMenuItem = new MenuItem();
3106 MenuItem averageDistanceTreeMenuItem = new MenuItem();
3108 MenuItem neighbourTreeMenuItem = new MenuItem();
3110 BorderLayout borderLayout1 = new BorderLayout();
3112 public Label statusBar = new Label();
3114 MenuItem clustalColour = new MenuItem();
3116 MenuItem zappoColour = new MenuItem();
3118 MenuItem taylorColour = new MenuItem();
3120 MenuItem hydrophobicityColour = new MenuItem();
3122 MenuItem helixColour = new MenuItem();
3124 MenuItem strandColour = new MenuItem();
3126 MenuItem turnColour = new MenuItem();
3128 MenuItem buriedColour = new MenuItem();
3130 MenuItem purinePyrimidineColour = new MenuItem();
3132 // MenuItem RNAInteractionColour = new MenuItem();
3134 MenuItem RNAHelixColour = new MenuItem();
3136 MenuItem userDefinedColour = new MenuItem();
3138 MenuItem PIDColour = new MenuItem();
3140 MenuItem BLOSUM62Colour = new MenuItem();
3142 MenuItem tcoffeeColour = new MenuItem();
3144 MenuItem njTreeBlosumMenuItem = new MenuItem();
3146 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
3148 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
3150 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
3152 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
3154 MenuItem alProperties = new MenuItem(
3155 MessageManager.getString("label.alignment_props"));
3157 MenuItem overviewMenuItem = new MenuItem();
3159 MenuItem undoMenuItem = new MenuItem();
3161 MenuItem redoMenuItem = new MenuItem();
3163 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
3165 MenuItem noColourmenuItem = new MenuItem();
3167 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
3169 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
3171 MenuItem findMenuItem = new MenuItem();
3173 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
3175 MenuItem nucleotideColour = new MenuItem();
3177 MenuItem deleteGroups = new MenuItem();
3179 MenuItem grpsFromSelection = new MenuItem();
3181 MenuItem createGroup = new MenuItem();
3183 MenuItem unGroup = new MenuItem();
3185 MenuItem delete = new MenuItem();
3187 MenuItem copy = new MenuItem();
3189 MenuItem cut = new MenuItem();
3191 Menu pasteMenu = new Menu();
3193 MenuItem pasteNew = new MenuItem();
3195 MenuItem pasteThis = new MenuItem();
3197 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
3199 MenuItem font = new MenuItem();
3201 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
3203 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
3205 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
3207 MenuItem modifyPID = new MenuItem();
3209 MenuItem modifyConservation = new MenuItem();
3211 CheckboxMenuItem autoCalculate = null;
3213 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
3214 "Sort Alignment With New Tree", true);
3216 Menu sortByTreeMenu = new Menu();
3218 MenuItem inputText = new MenuItem();
3220 MenuItem documentation = new MenuItem();
3222 MenuItem about = new MenuItem();
3224 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
3226 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
3228 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
3230 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
3232 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
3234 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
3236 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
3238 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
3240 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
3243 * Initialise menus and other items
3247 private void jbInit() throws Exception
3249 setMenuBar(alignFrameMenuBar);
3252 * Configure File menu items and actions
3255 .setLabel(MessageManager.getString("label.input_from_textbox"));
3256 inputText.addActionListener(this);
3257 Menu outputTextboxMenu = new Menu(
3258 MessageManager.getString("label.out_to_textbox"));
3259 for (String ff : FileFormats.getInstance().getWritableFormats(true))
3261 MenuItem item = new MenuItem(ff);
3263 item.addActionListener(new java.awt.event.ActionListener()
3266 public void actionPerformed(ActionEvent e)
3268 outputText_actionPerformed(e);
3272 outputTextboxMenu.add(item);
3274 closeMenuItem.addActionListener(this);
3275 loadApplication.addActionListener(this);
3276 loadTree.addActionListener(this);
3277 loadAnnotations.addActionListener(this);
3278 outputFeatures.addActionListener(this);
3279 outputAnnotations.addActionListener(this);
3282 * Configure Edit menu items and actions
3284 undoMenuItem.setEnabled(false);
3285 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3286 undoMenuItem.addActionListener(this);
3287 redoMenuItem.setEnabled(false);
3288 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3289 redoMenuItem.addActionListener(this);
3290 copy.setLabel(MessageManager.getString("action.copy"));
3291 copy.addActionListener(this);
3292 cut.setLabel(MessageManager.getString("action.cut"));
3293 cut.addActionListener(this);
3294 delete.setLabel(MessageManager.getString("action.delete"));
3295 delete.addActionListener(this);
3296 pasteMenu.setLabel(MessageManager.getString("action.paste"));
3297 pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3298 pasteNew.addActionListener(this);
3299 pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3300 pasteThis.addActionListener(this);
3301 remove2LeftMenuItem.setLabel(MessageManager
3302 .getString("action.remove_left"));
3303 remove2LeftMenuItem.addActionListener(this);
3304 remove2RightMenuItem.setLabel(MessageManager
3305 .getString("action.remove_right"));
3306 remove2RightMenuItem.addActionListener(this);
3307 removeGappedColumnMenuItem.setLabel(MessageManager
3308 .getString("action.remove_empty_columns"));
3309 removeGappedColumnMenuItem.addActionListener(this);
3310 removeAllGapsMenuItem.setLabel(MessageManager
3311 .getString("action.remove_all_gaps"));
3312 removeAllGapsMenuItem.addActionListener(this);
3313 removeRedundancyMenuItem.setLabel(MessageManager
3314 .getString("action.remove_redundancy"));
3315 removeRedundancyMenuItem.addActionListener(this);
3318 * Configure Select menu items and actions
3320 findMenuItem.setLabel(MessageManager.getString("action.find"));
3321 findMenuItem.addActionListener(this);
3322 selectAllSequenceMenuItem.addActionListener(this);
3323 deselectAllSequenceMenuItem.addActionListener(this);
3324 invertSequenceMenuItem.setLabel(MessageManager
3325 .getString("action.invert_sequence_selection"));
3326 invertSequenceMenuItem.addActionListener(this);
3327 invertColSel.setLabel(MessageManager
3328 .getString("action.invert_column_selection"));
3329 invertColSel.addActionListener(this);
3330 deleteGroups.setLabel(MessageManager
3331 .getString("action.undefine_groups"));
3332 deleteGroups.addActionListener(this);
3333 grpsFromSelection.setLabel(MessageManager
3334 .getString("action.make_groups_selection"));
3335 grpsFromSelection.addActionListener(this);
3336 createGroup.setLabel(MessageManager.getString("action.create_group"));
3337 unGroup.setLabel(MessageManager.getString("action.remove_group"));
3338 annotationColumnSelection.setLabel(MessageManager
3339 .getString("action.select_by_annotation"));
3340 annotationColumnSelection.addActionListener(this);
3343 * Configure View menu items and actions
3345 newView.setLabel(MessageManager.getString("action.new_view"));
3346 newView.addActionListener(this);
3347 Menu showMenu = new Menu(MessageManager.getString("action.show"));
3348 showColumns.setLabel(MessageManager.getString("label.all_columns"));
3349 showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3350 Menu hideMenu = new Menu(MessageManager.getString("action.hide"));
3352 .setLabel(MessageManager.getString("label.selected_columns"));
3353 hideSequences.setLabel(MessageManager
3354 .getString("label.selected_sequences"));
3355 hideAllButSelection.setLabel(MessageManager
3356 .getString("label.all_but_selected_region"));
3357 hideAllSelection.setLabel(MessageManager
3358 .getString("label.selected_region"));
3359 showAllHidden.setLabel(MessageManager
3360 .getString("label.all_sequences_columns"));
3361 showColumns.addActionListener(this);
3362 showSeqs.addActionListener(this);
3363 hideColumns.addActionListener(this);
3364 hideSequences.addActionListener(this);
3365 hideAllButSelection.addActionListener(this);
3366 hideAllSelection.addActionListener(this);
3367 showAllHidden.addActionListener(this);
3368 featureSettings.setLabel(MessageManager
3369 .getString("action.feature_settings"));
3370 featureSettings.addActionListener(this);
3371 sequenceFeatures.setLabel(MessageManager
3372 .getString("label.show_sequence_features"));
3373 sequenceFeatures.addItemListener(this);
3374 sequenceFeatures.setState(false);
3375 followMouseOverFlag.setLabel(MessageManager
3376 .getString("label.automatic_scrolling"));
3377 followMouseOverFlag.addItemListener(this);
3378 alProperties.addActionListener(this);
3379 overviewMenuItem.setLabel(MessageManager
3380 .getString("label.overview_window"));
3381 overviewMenuItem.addActionListener(this);
3384 * Configure Annotations menu items and actions
3386 annotationPanelMenuItem.setLabel(MessageManager
3387 .getString("label.show_annotations"));
3388 annotationPanelMenuItem.addItemListener(this);
3389 showGroupConsensus.setLabel(MessageManager
3390 .getString("label.group_consensus"));
3391 showGroupConservation.setLabel(MessageManager
3392 .getString("label.group_conservation"));
3393 showConsensusHistogram.setLabel(MessageManager
3394 .getString("label.show_consensus_histogram"));
3395 showSequenceLogo.setLabel(MessageManager
3396 .getString("label.show_consensus_logo"));
3397 normSequenceLogo.setLabel(MessageManager
3398 .getString("label.norm_consensus_logo"));
3399 applyAutoAnnotationSettings.setLabel(MessageManager
3400 .getString("label.apply_all_groups"));
3401 applyAutoAnnotationSettings.setState(true);
3402 Menu autoAnnMenu = new Menu(
3403 MessageManager.getString("label.autocalculated_annotation"));
3404 showGroupConsensus.addItemListener(this);
3405 showGroupConservation.addItemListener(this);
3406 showConsensusHistogram.addItemListener(this);
3407 showSequenceLogo.addItemListener(this);
3408 normSequenceLogo.addItemListener(this);
3409 applyAutoAnnotationSettings.addItemListener(this);
3410 showAlignmentAnnotations = new CheckboxMenuItem(
3411 MessageManager.getString("label.show_all_al_annotations"));
3412 showSequenceAnnotations = new CheckboxMenuItem(
3413 MessageManager.getString("label.show_all_seq_annotations"));
3414 sortAnnBySequence = new CheckboxMenuItem(
3415 MessageManager.getString("label.sort_annotations_by_sequence"));
3416 sortAnnByLabel = new CheckboxMenuItem(
3417 MessageManager.getString("label.sort_annotations_by_label"));
3418 showAutoFirst = new CheckboxMenuItem(
3419 MessageManager.getString("label.show_first"));
3420 showAutoFirst.setState(false); // pending applet parameter
3421 setShowAutoCalculatedAbove(showAutoFirst.getState());
3422 showAutoLast = new CheckboxMenuItem(
3423 MessageManager.getString("label.show_last"));
3424 showAutoLast.setState(!showAutoFirst.getState());
3425 showAlignmentAnnotations.addItemListener(this);
3426 showSequenceAnnotations.addItemListener(this);
3427 sortAnnBySequence.addItemListener(this);
3428 sortAnnByLabel.addItemListener(this);
3429 showAutoFirst.addItemListener(this);
3430 showAutoLast.addItemListener(this);
3433 * Configure Format menu items and actions
3435 font.setLabel(MessageManager.getString("action.font"));
3436 font.addActionListener(this);
3437 scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3438 scaleAbove.setState(true);
3439 scaleAbove.setEnabled(false);
3440 scaleAbove.addItemListener(this);
3441 scaleLeft.setEnabled(false);
3442 scaleLeft.setState(true);
3443 scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3444 scaleLeft.addItemListener(this);
3445 scaleRight.setEnabled(false);
3446 scaleRight.setState(true);
3447 scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3448 scaleRight.addItemListener(this);
3449 viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
3450 viewBoxesMenuItem.setState(true);
3451 viewBoxesMenuItem.addItemListener(this);
3452 viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
3453 viewTextMenuItem.setState(true);
3454 viewTextMenuItem.addItemListener(this);
3455 colourTextMenuItem.setLabel(MessageManager
3456 .getString("label.colour_text"));
3457 colourTextMenuItem.addItemListener(this);
3458 displayNonconservedMenuItem.setLabel(MessageManager
3459 .getString("label.show_non_conserved"));
3460 displayNonconservedMenuItem.addItemListener(this);
3461 wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3462 wrapMenuItem.addItemListener(this);
3463 renderGapsMenuItem.setLabel(MessageManager
3464 .getString("action.show_gaps"));
3465 renderGapsMenuItem.setState(true);
3466 renderGapsMenuItem.addItemListener(this);
3467 centreColumnLabelFlag.setLabel(MessageManager
3468 .getString("label.centre_column_labels"));
3469 centreColumnLabelFlag.addItemListener(this);
3470 seqLimits.setState(true);
3471 seqLimits.setLabel(MessageManager
3472 .getString("label.show_sequence_limits"));
3473 seqLimits.addItemListener(this);
3476 * Configure Colour menu items and actions
3478 applyToAllGroups.setLabel(MessageManager
3479 .getString("label.apply_colour_to_all_groups"));
3480 applyToAllGroups.setState(true);
3481 applyToAllGroups.addItemListener(this);
3482 clustalColour.setLabel(MessageManager
3483 .getString("label.colourScheme_clustal"));
3484 clustalColour.addActionListener(this);
3485 zappoColour.setLabel(MessageManager
3486 .getString("label.colourScheme_zappo"));
3487 zappoColour.addActionListener(this);
3488 taylorColour.setLabel(MessageManager
3489 .getString("label.colourScheme_taylor"));
3490 taylorColour.addActionListener(this);
3491 hydrophobicityColour.setLabel(MessageManager
3492 .getString("label.colourScheme_hydrophobic"));
3493 hydrophobicityColour.addActionListener(this);
3494 helixColour.setLabel(MessageManager
3495 .getString("label.colourScheme_helix_propensity"));
3496 helixColour.addActionListener(this);
3497 strandColour.setLabel(MessageManager
3498 .getString("label.colourScheme_strand_propensity"));
3499 strandColour.addActionListener(this);
3500 turnColour.setLabel(MessageManager
3501 .getString("label.colourScheme_turn_propensity"));
3502 turnColour.addActionListener(this);
3503 buriedColour.setLabel(MessageManager
3504 .getString("label.colourScheme_buried_index"));
3505 buriedColour.addActionListener(this);
3506 purinePyrimidineColour.setLabel(MessageManager
3507 .getString("label.colourScheme_purine/pyrimidine"));
3508 purinePyrimidineColour.addActionListener(this);
3509 // RNAInteractionColour.setLabel(MessageManager
3510 // .getString("label.rna_interaction"));
3511 // RNAInteractionColour.addActionListener(this);
3512 RNAHelixColour.setLabel(MessageManager
3513 .getString("label.colourScheme_rna_helices"));
3514 RNAHelixColour.addActionListener(this);
3515 userDefinedColour.setLabel(MessageManager
3516 .getString("action.user_defined"));
3517 userDefinedColour.addActionListener(this);
3518 PIDColour.setLabel(MessageManager
3519 .getString("label.colourScheme_%_identity"));
3520 PIDColour.addActionListener(this);
3521 BLOSUM62Colour.setLabel(MessageManager
3522 .getString("label.colourScheme_blosum62"));
3523 BLOSUM62Colour.addActionListener(this);
3524 tcoffeeColour.setLabel(MessageManager
3525 .getString("label.colourScheme_t-coffee_scores"));
3526 // it will be enabled only if a score file is provided
3527 tcoffeeColour.setEnabled(false);
3528 tcoffeeColour.addActionListener(this);
3529 conservationMenuItem.setLabel(MessageManager
3530 .getString("action.by_conservation"));
3531 conservationMenuItem.addItemListener(this);
3532 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3533 noColourmenuItem.addActionListener(this);
3534 abovePIDThreshold.setLabel(MessageManager
3535 .getString("label.above_identity_threshold"));
3536 abovePIDThreshold.addItemListener(this);
3537 nucleotideColour.setLabel(MessageManager
3538 .getString("label.colourScheme_nucleotide"));
3539 nucleotideColour.addActionListener(this);
3540 modifyPID.setLabel(MessageManager
3541 .getString("label.modify_identity_threshold"));
3542 modifyPID.setEnabled(abovePIDThreshold.getState());
3543 modifyPID.addActionListener(this);
3544 modifyConservation.setLabel(MessageManager
3545 .getString("label.modify_conservation_threshold"));
3546 modifyConservation.setEnabled(conservationMenuItem.getState());
3547 modifyConservation.addActionListener(this);
3548 annotationColour.setLabel(MessageManager
3549 .getString("action.by_annotation"));
3550 annotationColour.addActionListener(this);
3553 * Configure Calculate menu items and actions
3555 sortPairwiseMenuItem.setLabel(MessageManager
3556 .getString("action.by_pairwise_id"));
3557 sortPairwiseMenuItem.addActionListener(this);
3558 sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
3559 sortIDMenuItem.addActionListener(this);
3560 sortLengthMenuItem.setLabel(MessageManager
3561 .getString("action.by_length"));
3562 sortLengthMenuItem.addActionListener(this);
3563 sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3564 sortGroupMenuItem.addActionListener(this);
3565 pairwiseAlignmentMenuItem.setLabel(MessageManager
3566 .getString("action.pairwise_alignment"));
3567 pairwiseAlignmentMenuItem.addActionListener(this);
3568 PCAMenuItem.setLabel(MessageManager
3569 .getString("label.principal_component_analysis"));
3570 PCAMenuItem.addActionListener(this);
3571 autoCalculate = new CheckboxMenuItem(
3572 MessageManager.getString("label.autocalculate_consensus"), true);
3573 averageDistanceTreeMenuItem.setLabel(MessageManager
3574 .getString("label.average_distance_identity"));
3575 averageDistanceTreeMenuItem.addActionListener(this);
3576 neighbourTreeMenuItem.setLabel(MessageManager
3577 .getString("label.neighbour_joining_identity"));
3578 neighbourTreeMenuItem.addActionListener(this);
3579 avDistanceTreeBlosumMenuItem.setLabel(MessageManager
3580 .getString("label.average_distance_blosum62"));
3581 avDistanceTreeBlosumMenuItem.addActionListener(this);
3582 njTreeBlosumMenuItem.setLabel(MessageManager
3583 .getString("label.neighbour_blosum62"));
3584 njTreeBlosumMenuItem.addActionListener(this);
3585 sortByTreeMenu.setLabel(MessageManager
3586 .getString("action.by_tree_order"));
3587 Menu sortMenu = new Menu(MessageManager.getString("action.sort"));
3588 Menu calculateTreeMenu = new Menu(
3589 MessageManager.getString("action.calculate_tree"));
3590 autoCalculate.addItemListener(this);
3591 sortByTree.addItemListener(this);
3594 * Configure Help menu items and actions
3596 Menu helpMenu = new Menu(MessageManager.getString("action.help"));
3597 documentation.setLabel(MessageManager.getString("label.documentation"));
3598 documentation.addActionListener(this);
3599 about.setLabel(MessageManager.getString("label.about"));
3600 about.addActionListener(this);
3603 * Add top level menus to frame
3605 alignFrameMenuBar.add(fileMenu);
3606 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
3607 alignFrameMenuBar.add(editMenu);
3608 Menu selectMenu = new Menu(MessageManager.getString("action.select"));
3609 alignFrameMenuBar.add(selectMenu);
3610 Menu viewMenu = new Menu(MessageManager.getString("action.view"));
3611 alignFrameMenuBar.add(viewMenu);
3612 Menu annotationsMenu = new Menu(
3613 MessageManager.getString("action.annotations"));
3614 alignFrameMenuBar.add(annotationsMenu);
3615 Menu formatMenu = new Menu(MessageManager.getString("action.format"));
3616 alignFrameMenuBar.add(formatMenu);
3617 Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
3618 alignFrameMenuBar.add(colourMenu);
3619 Menu calculateMenu = new Menu(
3620 MessageManager.getString("action.calculate"));
3621 alignFrameMenuBar.add(calculateMenu);
3622 alignFrameMenuBar.add(helpMenu);
3627 fileMenu.add(inputText);
3628 fileMenu.add(loadTree);
3629 fileMenu.add(loadAnnotations);
3630 fileMenu.addSeparator();
3631 fileMenu.add(outputTextboxMenu);
3632 fileMenu.add(outputFeatures);
3633 fileMenu.add(outputAnnotations);
3634 if (jalviewServletURL != null)
3636 fileMenu.add(loadApplication);
3638 fileMenu.addSeparator();
3639 fileMenu.add(closeMenuItem);
3644 editMenu.add(undoMenuItem);
3645 editMenu.add(redoMenuItem);
3648 pasteMenu.add(pasteNew);
3649 pasteMenu.add(pasteThis);
3650 editMenu.add(pasteMenu);
3651 editMenu.add(delete);
3652 editMenu.addSeparator();
3653 editMenu.add(remove2LeftMenuItem);
3654 editMenu.add(remove2RightMenuItem);
3655 editMenu.add(removeGappedColumnMenuItem);
3656 editMenu.add(removeAllGapsMenuItem);
3657 editMenu.add(removeRedundancyMenuItem);
3662 selectMenu.add(findMenuItem);
3663 selectMenu.addSeparator();
3664 selectMenu.add(selectAllSequenceMenuItem);
3665 selectMenu.add(deselectAllSequenceMenuItem);
3666 selectMenu.add(invertSequenceMenuItem);
3667 selectMenu.add(invertColSel);
3668 selectMenu.add(createGroup);
3669 selectMenu.add(unGroup);
3670 selectMenu.add(grpsFromSelection);
3671 selectMenu.add(deleteGroups);
3672 selectMenu.add(annotationColumnSelection);
3677 viewMenu.add(newView);
3678 viewMenu.addSeparator();
3679 showMenu.add(showColumns);
3680 showMenu.add(showSeqs);
3681 showMenu.add(showAllHidden);
3682 viewMenu.add(showMenu);
3683 hideMenu.add(hideColumns);
3684 hideMenu.add(hideSequences);
3685 hideMenu.add(hideAllSelection);
3686 hideMenu.add(hideAllButSelection);
3687 viewMenu.add(hideMenu);
3688 viewMenu.addSeparator();
3689 viewMenu.add(followMouseOverFlag);
3690 viewMenu.addSeparator();
3691 viewMenu.add(sequenceFeatures);
3692 viewMenu.add(featureSettings);
3693 viewMenu.addSeparator();
3694 viewMenu.add(alProperties);
3695 viewMenu.addSeparator();
3696 viewMenu.add(overviewMenuItem);
3701 annotationsMenu.add(annotationPanelMenuItem);
3702 annotationsMenu.addSeparator();
3703 annotationsMenu.add(showAlignmentAnnotations);
3704 annotationsMenu.add(showSequenceAnnotations);
3705 annotationsMenu.add(sortAnnBySequence);
3706 annotationsMenu.add(sortAnnByLabel);
3707 annotationsMenu.addSeparator();
3708 autoAnnMenu.add(showAutoFirst);
3709 autoAnnMenu.add(showAutoLast);
3710 autoAnnMenu.addSeparator();
3711 autoAnnMenu.add(applyAutoAnnotationSettings);
3712 autoAnnMenu.add(showConsensusHistogram);
3713 autoAnnMenu.add(showSequenceLogo);
3714 autoAnnMenu.add(normSequenceLogo);
3715 autoAnnMenu.addSeparator();
3716 autoAnnMenu.add(showGroupConservation);
3717 autoAnnMenu.add(showGroupConsensus);
3718 annotationsMenu.add(autoAnnMenu);
3723 formatMenu.add(font);
3724 formatMenu.add(seqLimits);
3725 formatMenu.add(wrapMenuItem);
3726 formatMenu.add(scaleAbove);
3727 formatMenu.add(scaleLeft);
3728 formatMenu.add(scaleRight);
3729 formatMenu.add(viewBoxesMenuItem);
3730 formatMenu.add(viewTextMenuItem);
3731 formatMenu.add(colourTextMenuItem);
3732 formatMenu.add(displayNonconservedMenuItem);
3733 formatMenu.add(renderGapsMenuItem);
3734 formatMenu.add(centreColumnLabelFlag);
3739 colourMenu.add(applyToAllGroups);
3740 colourMenu.addSeparator();
3741 colourMenu.add(noColourmenuItem);
3742 colourMenu.add(clustalColour);
3743 colourMenu.add(BLOSUM62Colour);
3744 colourMenu.add(PIDColour);
3745 colourMenu.add(zappoColour);
3746 colourMenu.add(taylorColour);
3747 colourMenu.add(hydrophobicityColour);
3748 colourMenu.add(helixColour);
3749 colourMenu.add(strandColour);
3750 colourMenu.add(turnColour);
3751 colourMenu.add(buriedColour);
3752 colourMenu.add(nucleotideColour);
3753 colourMenu.add(purinePyrimidineColour);
3754 // colourMenu.add(RNAInteractionColour);
3755 colourMenu.add(tcoffeeColour);
3756 colourMenu.add(userDefinedColour);
3757 colourMenu.addSeparator();
3758 colourMenu.add(conservationMenuItem);
3759 colourMenu.add(modifyConservation);
3760 colourMenu.add(abovePIDThreshold);
3761 colourMenu.add(modifyPID);
3762 colourMenu.add(annotationColour);
3763 colourMenu.add(RNAHelixColour);
3768 sortMenu.add(sortIDMenuItem);
3769 sortMenu.add(sortLengthMenuItem);
3770 sortMenu.add(sortByTreeMenu);
3771 sortMenu.add(sortGroupMenuItem);
3772 sortMenu.add(sortPairwiseMenuItem);
3773 calculateMenu.add(sortMenu);
3774 calculateTreeMenu.add(averageDistanceTreeMenuItem);
3775 calculateTreeMenu.add(neighbourTreeMenuItem);
3776 calculateTreeMenu.add(avDistanceTreeBlosumMenuItem);
3777 calculateTreeMenu.add(njTreeBlosumMenuItem);
3778 calculateMenu.add(calculateTreeMenu);
3779 calculateMenu.addSeparator();
3780 calculateMenu.add(pairwiseAlignmentMenuItem);
3781 calculateMenu.add(PCAMenuItem);
3782 calculateMenu.add(autoCalculate);
3783 calculateMenu.add(sortByTree);
3788 helpMenu.add(documentation);
3789 helpMenu.add(about);
3794 statusBar.setBackground(Color.white);
3795 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3796 statusBar.setText(MessageManager.getString("label.status_bar"));
3797 this.add(statusBar, BorderLayout.SOUTH);
3801 public void setStatus(String string)
3803 statusBar.setText(string);
3806 MenuItem featureSettings = new MenuItem();
3808 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3810 MenuItem annotationColour = new MenuItem();
3812 MenuItem annotationColumnSelection = new MenuItem();
3814 MenuItem invertColSel = new MenuItem();
3816 MenuItem showColumns = new MenuItem();
3818 MenuItem showSeqs = new MenuItem();
3820 MenuItem hideColumns = new MenuItem();
3822 MenuItem hideSequences = new MenuItem();
3824 MenuItem hideAllButSelection = new MenuItem();
3826 MenuItem hideAllSelection = new MenuItem();
3828 MenuItem showAllHidden = new MenuItem();
3830 MenuItem newView = new MenuItem();
3832 private CheckboxMenuItem showAlignmentAnnotations;
3834 private CheckboxMenuItem showSequenceAnnotations;
3836 private CheckboxMenuItem sortAnnBySequence;
3838 private CheckboxMenuItem sortAnnByLabel;
3840 private CheckboxMenuItem showAutoFirst;
3842 private CheckboxMenuItem showAutoLast;
3844 private SplitFrame splitFrame;
3847 * Attach the alignFrame panels after embedding menus, if necessary. This used
3848 * to be called setEmbedded, but is now creates the dropdown menus in a
3849 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3851 * @param reallyEmbedded
3852 * true to attach the view to the applet area on the page rather than
3855 public void createAlignFrameWindow(boolean reallyEmbedded)
3859 embedAlignFrameInApplet(viewport.applet);
3864 // test and embed menu bar if necessary.
3866 if (embedMenuIfNeeded(alignPanel))
3869 * adjust for status bar height too. ? pointless as overridden by layout
3872 alignPanel.setSize(getSize().width,
3873 getSize().height - statusBar.getHeight());
3875 add(statusBar, BorderLayout.SOUTH);
3876 add(alignPanel, BorderLayout.CENTER);
3877 // and register with the applet so it can pass external API calls to us
3878 jalview.bin.JalviewLite.addFrame(this, this.getTitle(), frameWidth,
3884 * Add the components of this AlignFrame to the applet container.
3888 public void embedAlignFrameInApplet(final JalviewLite theApplet)
3891 // Explicitly build the embedded menu panel for the on-page applet
3893 // view cannot be closed if its actually on the page
3894 fileMenu.remove(closeMenuItem);
3895 fileMenu.remove(3); // Remove Separator
3896 // construct embedded menu, using default font
3897 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
3898 // and actually add the components to the applet area
3899 theApplet.setLayout(new BorderLayout());
3900 theApplet.add(embeddedMenu, BorderLayout.NORTH);
3901 theApplet.add(statusBar, BorderLayout.SOUTH);
3902 // TODO should size be left to the layout manager?
3903 alignPanel.setSize(theApplet.getSize().width,
3904 theApplet.getSize().height - embeddedMenu.getHeight()
3905 - statusBar.getHeight());
3906 theApplet.add(alignPanel, BorderLayout.CENTER);
3907 final AlignFrame me = this;
3908 theApplet.addFocusListener(new FocusListener()
3912 public void focusLost(FocusEvent e)
3914 if (theApplet.currentAlignFrame == me)
3916 theApplet.currentAlignFrame = null;
3921 public void focusGained(FocusEvent e)
3923 theApplet.currentAlignFrame = me;
3926 theApplet.validate();
3930 * create a new binding between structures in an existing jmol viewer instance
3931 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3932 * this does not open a new Jmol window, or modify the display of the
3933 * structures in the original jmol window. Note This method doesn't work
3934 * without an additional javascript library to exchange messages between the
3935 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3938 * JmolViewer instance
3939 * @param sequenceIds
3940 * - sequence Ids to search for associations
3942 public SequenceStructureBinding addStructureViewInstance(
3943 Object jmolviewer, String[] sequenceIds)
3945 Viewer viewer = null;
3948 viewer = (Viewer) jmolviewer;
3949 } catch (ClassCastException ex)
3951 System.err.println("Unsupported viewer object :"
3952 + jmolviewer.getClass());
3956 System.err.println("Can't use this object as a structure viewer:"
3957 + jmolviewer.getClass());
3960 SequenceI[] seqs = null;
3961 if (sequenceIds == null || sequenceIds.length == 0)
3963 seqs = viewport.getAlignment().getSequencesArray();
3967 Vector sqi = new Vector();
3968 AlignmentI al = viewport.getAlignment();
3969 for (int sid = 0; sid < sequenceIds.length; sid++)
3971 SequenceI sq = al.findName(sequenceIds[sid]);
3979 seqs = new SequenceI[sqi.size()];
3980 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
3982 seqs[sid] = (SequenceI) sqi.elementAt(sid);
3990 AAStructureBindingModel jmv = null;
3991 // TODO: search for a jmv that involves viewer
3993 { // create a new viewer/jalview binding.
3994 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] { seqs });
4001 * bind a pdb file to a sequence in the current view
4004 * - sequenceId within the dataset.
4005 * @param pdbEntryString
4006 * - the short name for the PDB file
4008 * - pdb file - either a URL or a valid PDB file.
4009 * @return true if binding was as success TODO: consider making an exception
4010 * structure for indicating when PDB parsing or sequenceId location
4013 public boolean addPdbFile(String sequenceId, String pdbEntryString,
4016 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
4017 boolean needtoadd = false;
4018 if (toaddpdb != null)
4020 Vector pdbe = toaddpdb.getAllPDBEntries();
4021 PDBEntry pdbentry = null;
4022 if (pdbe != null && pdbe.size() > 0)
4024 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
4026 pdbentry = (PDBEntry) pdbe.elementAt(pe);
4027 if (!pdbentry.getId().equals(pdbEntryString)
4028 && !pdbentry.getFile().equals(pdbFile))
4038 if (pdbentry == null)
4040 pdbentry = new PDBEntry();
4041 pdbentry.setId(pdbEntryString);
4042 pdbentry.setFile(pdbFile);
4043 needtoadd = true; // add this new entry to sequence.
4045 // resolve data source
4046 // TODO: this code should be a refactored to an io package
4047 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(
4048 pdbFile, FileFormat.PDB);
4049 if (protocol == null)
4055 pdbentry.setProperty("protocol", protocol);
4056 toaddpdb.addPDBId(pdbentry);
4057 alignPanel.getStructureSelectionManager()
4058 .registerPDBEntry(pdbentry);
4064 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
4068 Vector sequences = new Vector();
4069 for (int i = 0; i < seqs.length; i++)
4071 if (seqs[i] != null)
4073 sequences.addElement(new Object[] { seqs[i],
4074 (chains != null) ? chains[i] : null });
4077 seqs = new SequenceI[sequences.size()];
4078 chains = new String[sequences.size()];
4079 for (int i = 0, isize = sequences.size(); i < isize; i++)
4081 Object[] oj = (Object[]) sequences.elementAt(i);
4083 seqs[i] = (SequenceI) oj[0];
4084 chains[i] = (String) oj[1];
4087 return new Object[] { seqs, chains };
4091 public void newStructureView(JalviewLite applet, PDBEntry pdb,
4092 SequenceI[] seqs, String[] chains, DataSourceType protocol)
4094 // Scrub any null sequences from the array
4095 Object[] sqch = cleanSeqChainArrays(seqs, chains);
4096 seqs = (SequenceI[]) sqch[0];
4097 chains = (String[]) sqch[1];
4098 if (seqs == null || seqs.length == 0)
4101 .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
4103 if (protocol == null)
4105 String sourceType = (String) pdb.getProperty("protocol");
4108 protocol = DataSourceType.valueOf(sourceType);
4109 } catch (IllegalArgumentException e)
4113 if (protocol == null)
4115 System.err.println("Couldn't work out protocol to open structure: "
4120 if (applet.useXtrnalSviewer)
4122 // register the association(s) and quit, don't create any windows.
4123 if (StructureSelectionManager.getStructureSelectionManager(applet)
4124 .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
4126 System.err.println("Failed to map " + pdb.getFile() + " ("
4127 + protocol + ") to any sequences");
4131 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
4133 // can only do alignments with Jmol
4134 // find the last jmol window assigned to this alignment
4135 AppletJmol ajm = null, tajm;
4136 Vector jmols = applet.getAppletWindow(AppletJmol.class);
4137 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
4139 tajm = (AppletJmol) jmols.elementAt(i);
4140 if (tajm.ap.alignFrame == this)
4149 .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
4150 // try and add the pdb structure
4155 // otherwise, create a new window
4156 if (applet.jmolAvailable)
4158 new AppletJmol(pdb, seqs, chains, alignPanel,
4160 applet.lastFrameX += 40;
4161 applet.lastFrameY += 40;
4165 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
4170 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
4171 SequenceI[][] seqs, String[][] chains, String[] protocols)
4173 // TODO Auto-generated method stub
4174 System.err.println("Aligned Structure View: Not yet implemented.");
4178 * modify the current selection, providing the user has not made a selection
4182 * - sequences from this alignment
4184 * - columns to be selected on the alignment
4186 public void select(SequenceGroup sel, ColumnSelection csel)
4188 alignPanel.seqPanel.selection(sel, csel, null);
4191 public void scrollTo(int row, int column)
4193 alignPanel.seqPanel.scrollTo(row, column);
4196 public void scrollToRow(int row)
4198 alignPanel.seqPanel.scrollToRow(row);
4201 public void scrollToColumn(int column)
4203 alignPanel.seqPanel.scrollToColumn(column);
4207 * @return the alignments unique ID.
4209 public String getSequenceSetId()
4211 return viewport.getSequenceSetId();
4215 * Load the (T-Coffee) score file from the specified url
4218 * File/URL/T-COFFEE score file contents
4219 * @throws IOException
4220 * @return true if alignment was annotated with data from source
4222 public boolean loadScoreFile(String source) throws IOException
4225 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
4226 AppletFormatAdapter.checkProtocol(source));
4227 if (!file.isValid())
4229 // TODO: raise dialog for gui
4230 System.err.println("Problems parsing T-Coffee scores: "
4231 + file.getWarningMessage());
4232 System.err.println("Origin was:\n" + source);
4237 * check that the score matrix matches the alignment dimensions
4240 if ((aln = viewport.getAlignment()) != null
4241 && (aln.getHeight() != file.getHeight() || aln.getWidth() != file
4244 // TODO: raise a dialog box here rather than bomb out.
4246 .println("The scores matrix does not match the alignment dimensions");
4250 // TODO add parameter to indicate if matching should be done
4251 if (file.annotateAlignment(alignPanel.getAlignment(), false))
4253 alignPanel.fontChanged();
4254 tcoffeeColour.setEnabled(true);
4255 // switch to this color
4256 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4261 System.err.println("Problems resolving T-Coffee scores:");
4262 if (file.getWarningMessage() != null)
4264 System.err.println(file.getWarningMessage());
4270 public SplitFrame getSplitFrame()
4272 return this.splitFrame;
4275 public void setSplitFrame(SplitFrame sf)
4277 this.splitFrame = sf;
4280 // may not need this
4282 public void setShowSeqFeatures(boolean b)
4284 // showSeqFeatures.setSelected(b);
4285 viewport.setShowSequenceFeatures(b);
4290 public void setMenusForViewport()
4292 // setMenusFromViewport(viewport);
4297 public void refreshFeatureUI(boolean enableIfNecessary)
4299 if (enableIfNecessary)
4301 sequenceFeatures.setState(true);
4302 alignPanel.av.setShowSequenceFeatures(true);
4307 public FeatureSettingsControllerI getFeatureSettingsUI()
4309 return alignPanel.av.featureSettings;