2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
25 import jalview.analysis.TreeBuilder;
26 import jalview.analysis.scoremodels.PIDModel;
27 import jalview.analysis.scoremodels.ScoreModels;
28 import jalview.api.AlignViewControllerGuiI;
29 import jalview.api.AlignViewControllerI;
30 import jalview.api.AlignViewportI;
31 import jalview.api.FeatureColourI;
32 import jalview.api.FeatureRenderer;
33 import jalview.api.FeatureSettingsControllerI;
34 import jalview.api.SequenceStructureBinding;
35 import jalview.bin.JalviewLite;
36 import jalview.commands.CommandI;
37 import jalview.commands.EditCommand;
38 import jalview.commands.EditCommand.Action;
39 import jalview.commands.OrderCommand;
40 import jalview.commands.RemoveGapColCommand;
41 import jalview.commands.RemoveGapsCommand;
42 import jalview.commands.SlideSequencesCommand;
43 import jalview.commands.TrimRegionCommand;
44 import jalview.datamodel.Alignment;
45 import jalview.datamodel.AlignmentAnnotation;
46 import jalview.datamodel.AlignmentI;
47 import jalview.datamodel.AlignmentOrder;
48 import jalview.datamodel.ColumnSelection;
49 import jalview.datamodel.HiddenColumns;
50 import jalview.datamodel.PDBEntry;
51 import jalview.datamodel.Sequence;
52 import jalview.datamodel.SequenceGroup;
53 import jalview.datamodel.SequenceI;
54 import jalview.io.AnnotationFile;
55 import jalview.io.AppletFormatAdapter;
56 import jalview.io.DataSourceType;
57 import jalview.io.FeaturesFile;
58 import jalview.io.FileFormat;
59 import jalview.io.FileFormatI;
60 import jalview.io.FileFormats;
61 import jalview.io.TCoffeeScoreFile;
62 import jalview.schemes.Blosum62ColourScheme;
63 import jalview.schemes.BuriedColourScheme;
64 import jalview.schemes.ClustalxColourScheme;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.HelixColourScheme;
67 import jalview.schemes.HydrophobicColourScheme;
68 import jalview.schemes.NucleotideColourScheme;
69 import jalview.schemes.PIDColourScheme;
70 import jalview.schemes.PurinePyrimidineColourScheme;
71 import jalview.schemes.RNAHelicesColour;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.ZappoColourScheme;
77 import jalview.structure.StructureSelectionManager;
78 import jalview.structures.models.AAStructureBindingModel;
79 import jalview.util.MappingUtils;
80 import jalview.util.MessageManager;
81 import jalview.viewmodel.AlignmentViewport;
82 import jalview.viewmodel.ViewportRanges;
84 import java.awt.BorderLayout;
85 import java.awt.Canvas;
86 import java.awt.CheckboxMenuItem;
87 import java.awt.Color;
88 import java.awt.FlowLayout;
90 import java.awt.FontMetrics;
91 import java.awt.Frame;
92 import java.awt.Graphics;
93 import java.awt.Label;
95 import java.awt.MenuBar;
96 import java.awt.MenuItem;
97 import java.awt.Panel;
98 import java.awt.event.ActionEvent;
99 import java.awt.event.ActionListener;
100 import java.awt.event.FocusEvent;
101 import java.awt.event.FocusListener;
102 import java.awt.event.ItemEvent;
103 import java.awt.event.ItemListener;
104 import java.awt.event.KeyEvent;
105 import java.awt.event.KeyListener;
106 import java.awt.event.WindowAdapter;
107 import java.awt.event.WindowEvent;
108 import java.io.IOException;
110 import java.net.URLEncoder;
111 import java.util.Arrays;
112 import java.util.Deque;
113 import java.util.HashMap;
114 import java.util.List;
115 import java.util.Map;
116 import java.util.StringTokenizer;
117 import java.util.Vector;
119 import org.jmol.viewer.Viewer;
121 public class AlignFrame extends EmbmenuFrame implements ActionListener,
122 ItemListener, KeyListener, AlignViewControllerGuiI
124 public AlignViewControllerI avc;
126 public AlignmentPanel alignPanel;
128 public AlignViewport viewport;
130 // width and height may be overridden by applet parameters
131 int frameWidth = 700;
133 int frameHeight = 500;
135 String jalviewServletURL;
138 * Flag for showing autocalculated consensus above or below other consensus
141 private boolean showAutoCalculatedAbove;
143 private SequenceAnnotationOrder annotationSortOrder;
146 * Constructor that creates the frame and adds it to the display.
153 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
156 this(al, applet, title, embedded, true);
160 * Constructor that optionally allows the frame to be displayed or only
167 * @param addToDisplay
169 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
170 boolean embedded, boolean addToDisplay)
172 this(al, null, null, applet, title, embedded, addToDisplay);
175 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
176 HiddenColumns hidden, JalviewLite applet,
177 String title, boolean embedded)
179 this(al, hiddenSeqs, hidden, applet, title, embedded, true);
182 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
183 HiddenColumns hidden, JalviewLite applet,
184 String title, boolean embedded, boolean addToDisplay)
188 jalviewServletURL = applet.getParameter("APPLICATION_URL");
194 } catch (Exception ex)
196 ex.printStackTrace();
198 // need to get window geometry before we calculate alignment layout
204 param = applet.getParameter("windowWidth");
207 int width = Integer.parseInt(param);
210 param = applet.getParameter("windowHeight");
213 int height = Integer.parseInt(param);
214 frameHeight = height;
216 } catch (Exception ex)
220 viewport = new AlignViewport(al, applet);
222 if (hiddenSeqs != null && hiddenSeqs.length > 0)
224 viewport.hideSequence(hiddenSeqs);
228 viewport.getAlignment().setHiddenColumns(hidden);
230 viewport.setScaleAboveWrapped(scaleAbove.getState());
232 alignPanel = new AlignmentPanel(this, viewport);
233 avc = new jalview.controller.AlignViewController(this, viewport,
235 viewport.updateConservation(alignPanel);
236 viewport.updateConsensus(alignPanel);
238 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
239 followMouseOverFlag.setState(viewport.isFollowHighlight());
240 showGroupConsensus.setState(viewport.isShowGroupConsensus());
241 showGroupConservation.setState(viewport.isShowGroupConservation());
242 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
243 showSequenceLogo.setState(viewport.isShowSequenceLogo());
244 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
245 applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
246 annotationPanelMenuItem.setState(viewport.isShowAnnotation());
247 showAlignmentAnnotations.setEnabled(annotationPanelMenuItem.getState());
248 showSequenceAnnotations.setEnabled(annotationPanelMenuItem.getState());
249 showAlignmentAnnotations.setState(true);
250 showSequenceAnnotations.setState(false);
252 seqLimits.setState(viewport.getShowJVSuffix());
256 String param = applet.getParameter("sortBy");
259 if (param.equalsIgnoreCase("Id"))
261 sortIDMenuItem_actionPerformed();
263 else if (param.equalsIgnoreCase("Pairwise Identity"))
265 sortPairwiseMenuItem_actionPerformed();
267 else if (param.equalsIgnoreCase("Length"))
269 sortLengthMenuItem_actionPerformed();
273 param = applet.getParameter("wrap");
276 if (param.equalsIgnoreCase("true"))
278 wrapMenuItem.setState(true);
279 wrapMenuItem_actionPerformed();
282 param = applet.getParameter("centrecolumnlabels");
285 centreColumnLabelFlag.setState(true);
286 centreColumnLabelFlag_stateChanged();
290 if (viewport.getAlignment().isNucleotide())
292 conservationMenuItem.setEnabled(false);
293 clustalColour.setEnabled(false);
294 BLOSUM62Colour.setEnabled(false);
295 zappoColour.setEnabled(false);
296 taylorColour.setEnabled(false);
297 hydrophobicityColour.setEnabled(false);
298 helixColour.setEnabled(false);
299 strandColour.setEnabled(false);
300 turnColour.setEnabled(false);
301 buriedColour.setEnabled(false);
302 viewport.updateStrucConsensus(alignPanel);
303 if (viewport.getAlignment().hasRNAStructure())
305 RNAHelixColour.setEnabled(true);
309 RNAHelixColour.setEnabled(false);
314 RNAHelixColour.setEnabled(false);
315 purinePyrimidineColour.setEnabled(false);
316 nucleotideColour.setEnabled(false);
318 // Some JVMS send keyevents to Top frame or lowest panel,
319 // Havent worked out why yet. So add to both this frame and seqCanvas for
321 this.addKeyListener(this);
322 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
323 alignPanel.idPanel.idCanvas.addKeyListener(this);
324 alignPanel.scalePanel.addKeyListener(this);
325 alignPanel.annotationPanel.addKeyListener(this);
326 alignPanel.annotationPanelHolder.addKeyListener(this);
327 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
328 alignPanel.alabels.addKeyListener(this);
330 setAnnotationsVisibility();
334 addToDisplay(embedded);
341 public void addToDisplay(boolean embedded)
343 createAlignFrameWindow(embedded);
345 alignPanel.adjustAnnotationHeight();
346 alignPanel.paintAlignment(true);
349 public AlignViewport getAlignViewport()
354 public SeqCanvas getSeqcanvas()
356 return alignPanel.seqPanel.seqCanvas;
360 * Load a features file onto the alignment
363 * file URL, content, or other resolvable path
365 * is protocol for accessing data referred to by file
368 public boolean parseFeaturesFile(String file, DataSourceType type)
370 return parseFeaturesFile(file, type, true);
374 * Load a features file onto the alignment
377 * file URL, content, or other resolvable path
379 * is protocol for accessing data referred to by file
380 * @param autoenabledisplay
381 * when true, display features flag will be automatically enabled if
382 * features are loaded
383 * @return true if data parsed as a features file
385 public boolean parseFeaturesFile(String file, DataSourceType sourceType,
386 boolean autoenabledisplay)
388 boolean featuresFile = false;
391 Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
392 .getFeatureRenderer().getFeatureColours();
393 boolean relaxedIdMatching = viewport.applet.getDefaultParameter(
394 "relaxedidmatch", false);
395 featuresFile = new FeaturesFile(file, sourceType).parse(
396 viewport.getAlignment(), colours, true, relaxedIdMatching);
397 } catch (Exception ex)
399 ex.printStackTrace();
404 if (autoenabledisplay)
406 viewport.setShowSequenceFeatures(true);
407 sequenceFeatures.setState(true);
409 if (alignPanel.seqPanel.seqCanvas.fr != null)
411 // update the min/max ranges where necessary
412 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
414 if (viewport.featureSettings != null)
416 viewport.featureSettings.refreshTable();
418 alignPanel.paintAlignment(true);
419 statusBar.setText(MessageManager
420 .getString("label.successfully_added_features_alignment"));
426 public void keyPressed(KeyEvent evt)
428 ViewportRanges ranges = viewport.getRanges();
430 if (viewport.cursorMode
431 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
432 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
433 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
434 && Character.isDigit(evt.getKeyChar()))
436 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
439 switch (evt.getKeyCode())
441 case 27: // escape key
442 deselectAllSequenceMenuItem_actionPerformed();
444 alignPanel.alabels.cancelDrag();
447 if (evt.isControlDown() || evt.isMetaDown())
449 cut_actionPerformed();
453 if (viewport.cursorMode && !evt.isControlDown())
455 alignPanel.seqPanel.setCursorColumn();
457 if (evt.isControlDown() || evt.isMetaDown())
459 copy_actionPerformed();
463 if (evt.isControlDown())
465 paste(evt.isShiftDown());
469 if (evt.isControlDown() || evt.isMetaDown())
471 selectAllSequenceMenuItem_actionPerformed();
474 case KeyEvent.VK_DOWN:
475 if (viewport.cursorMode)
477 alignPanel.seqPanel.moveCursor(0, 1);
481 moveSelectedSequences(false);
486 if (viewport.cursorMode)
488 alignPanel.seqPanel.moveCursor(0, -1);
492 moveSelectedSequences(true);
496 case KeyEvent.VK_LEFT:
497 if (evt.isAltDown() || !viewport.cursorMode)
499 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
503 alignPanel.seqPanel.moveCursor(-1, 0);
507 case KeyEvent.VK_RIGHT:
508 if (evt.isAltDown() || !viewport.cursorMode)
510 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
514 alignPanel.seqPanel.moveCursor(1, 0);
518 case KeyEvent.VK_SPACE:
519 if (viewport.cursorMode)
521 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
522 || evt.isShiftDown() || evt.isAltDown());
526 case KeyEvent.VK_DELETE:
527 case KeyEvent.VK_BACK_SPACE:
528 if (viewport.cursorMode)
530 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
531 || evt.isShiftDown() || evt.isAltDown());
535 cut_actionPerformed();
536 alignPanel.seqPanel.seqCanvas.repaint();
541 if (viewport.cursorMode)
543 alignPanel.seqPanel.setCursorRow();
547 if (viewport.cursorMode)
549 alignPanel.seqPanel.setCursorPosition();
553 case KeyEvent.VK_ENTER:
554 case KeyEvent.VK_COMMA:
555 if (viewport.cursorMode)
557 alignPanel.seqPanel.setCursorRowAndColumn();
562 if (viewport.cursorMode)
564 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
568 if (viewport.cursorMode)
570 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
575 viewport.cursorMode = !viewport.cursorMode;
576 statusBar.setText(MessageManager.formatMessage(
577 "label.keyboard_editing_mode",
578 new String[] { (viewport.cursorMode ? "on" : "off") }));
579 if (viewport.cursorMode)
581 alignPanel.seqPanel.seqCanvas.cursorX = ranges.getStartRes();
582 alignPanel.seqPanel.seqCanvas.cursorY = ranges.getStartSeq();
587 if (evt.isControlDown())
589 findMenuItem_actionPerformed();
595 boolean toggleSeqs = !evt.isControlDown();
596 boolean toggleCols = !evt.isShiftDown();
597 toggleHiddenRegions(toggleSeqs, toggleCols);
601 case KeyEvent.VK_PAGE_UP:
602 if (viewport.getWrapAlignment())
604 ranges.scrollUp(true);
612 case KeyEvent.VK_PAGE_DOWN:
613 if (viewport.getWrapAlignment())
615 ranges.scrollUp(false);
624 if (evt.isControlDown())
626 undoMenuItem_actionPerformed();
631 if (evt.isControlDown())
633 redoMenuItem_actionPerformed();
638 if (evt.isControlDown())
645 if (evt.isControlDown())
647 trimAlignment(false);
652 if (evt.isControlDown())
654 if (evt.isShiftDown())
656 this.removeAllGapsMenuItem_actionPerformed();
660 removeGappedColumnMenuItem_actionPerformed();
665 if (evt.isControlDown())
669 invertColSel_actionPerformed();
673 invertSequenceMenuItem_actionPerformed();
679 if (evt.isControlDown())
681 if (evt.isShiftDown())
683 this.unGroup_actionPerformed();
687 this.createGroup_actionPerformed();
693 if (evt.isControlDown())
695 this.deleteGroups_actionPerformed();
700 if (evt.isControlDown())
707 alignPanel.paintAlignment(true);
711 * called by key handler and the hide all/show all menu items
716 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
718 boolean hide = false;
719 SequenceGroup sg = viewport.getSelectionGroup();
720 if (!toggleSeqs && !toggleCols)
722 // Hide everything by the current selection - this is a hack - we do the
723 // invert and then hide
724 // first check that there will be visible columns after the invert.
725 if (viewport.hasSelectedColumns()
726 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
729 // now invert the sequence set, if required - empty selection implies
730 // that no hiding is required.
733 invertSequenceMenuItem_actionPerformed();
734 sg = viewport.getSelectionGroup();
738 viewport.expandColSelection(sg, true);
739 // finally invert the column selection and get the new sequence
740 // selection and indicate it should be hidden.
741 invertColSel_actionPerformed();
748 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
751 viewport.hideAllSelectedSeqs();
753 else if (!(toggleCols && viewport.hasSelectedColumns()))
755 viewport.showAllHiddenSeqs();
761 if (viewport.hasSelectedColumns())
763 viewport.hideSelectedColumns();
766 viewport.setSelectionGroup(sg);
771 viewport.showAllHiddenColumns();
773 viewport.sendSelection();
778 public void keyReleased(KeyEvent evt)
783 public void keyTyped(KeyEvent evt)
788 public void itemStateChanged(ItemEvent evt)
790 final Object source = evt.getSource();
791 if (source == displayNonconservedMenuItem)
793 displayNonconservedMenuItem_actionPerformed();
795 else if (source == colourTextMenuItem)
797 colourTextMenuItem_actionPerformed();
799 else if (source == wrapMenuItem)
801 wrapMenuItem_actionPerformed();
803 else if (source == scaleAbove)
805 viewport.setScaleAboveWrapped(scaleAbove.getState());
807 else if (source == scaleLeft)
809 viewport.setScaleLeftWrapped(scaleLeft.getState());
811 else if (source == scaleRight)
813 viewport.setScaleRightWrapped(scaleRight.getState());
815 else if (source == seqLimits)
817 seqLimits_itemStateChanged();
819 else if (source == viewBoxesMenuItem)
821 viewport.setShowBoxes(viewBoxesMenuItem.getState());
823 else if (source == viewTextMenuItem)
825 viewport.setShowText(viewTextMenuItem.getState());
827 else if (source == renderGapsMenuItem)
829 viewport.setRenderGaps(renderGapsMenuItem.getState());
831 else if (source == annotationPanelMenuItem)
833 boolean showAnnotations = annotationPanelMenuItem.getState();
834 showAlignmentAnnotations.setEnabled(showAnnotations);
835 showSequenceAnnotations.setEnabled(showAnnotations);
836 viewport.setShowAnnotation(showAnnotations);
837 alignPanel.setAnnotationVisible(showAnnotations);
839 else if (source == sequenceFeatures)
841 viewport.setShowSequenceFeatures(sequenceFeatures.getState());
842 alignPanel.seqPanel.seqCanvas.repaint();
844 else if (source == showAlignmentAnnotations)
846 setAnnotationsVisibility();
848 else if (source == showSequenceAnnotations)
850 setAnnotationsVisibility();
852 else if (source == sortAnnBySequence)
854 boolean newState = sortAnnBySequence.getState();
855 sortAnnByLabel.setState(false);
856 setAnnotationSortOrder(newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
857 : SequenceAnnotationOrder.NONE);
858 setViewportAnnotationOrder();
860 else if (source == sortAnnByLabel)
862 boolean newState = sortAnnByLabel.getState();
863 sortAnnBySequence.setState(false);
864 setAnnotationSortOrder(newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
865 : SequenceAnnotationOrder.NONE);
866 setViewportAnnotationOrder();
868 else if (source == showAutoFirst)
870 showAutoLast.setState(!showAutoFirst.getState());
871 setShowAutoCalculatedAbove(showAutoFirst.getState());
872 setViewportAnnotationOrder();
874 else if (source == showAutoLast)
876 showAutoFirst.setState(!showAutoLast.getState());
877 setShowAutoCalculatedAbove(showAutoFirst.getState());
878 setViewportAnnotationOrder();
880 else if (source == conservationMenuItem)
882 conservationMenuItem_actionPerformed();
884 else if (source == abovePIDThreshold)
886 abovePIDThreshold_actionPerformed();
888 else if (source == applyToAllGroups)
890 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
892 else if (source == autoCalculate)
894 viewport.autoCalculateConsensus = autoCalculate.getState();
896 else if (source == sortByTree)
898 viewport.sortByTree = sortByTree.getState();
900 else if (source == this.centreColumnLabelFlag)
902 centreColumnLabelFlag_stateChanged();
904 else if (source == this.followMouseOverFlag)
906 mouseOverFlag_stateChanged();
908 else if (source == showGroupConsensus)
910 showGroupConsensus_actionPerformed();
912 else if (source == showGroupConservation)
914 showGroupConservation_actionPerformed();
916 else if (source == showSequenceLogo)
918 showSequenceLogo_actionPerformed();
920 else if (source == normSequenceLogo)
922 normSequenceLogo_actionPerformed();
924 else if (source == showConsensusHistogram)
926 showConsensusHistogram_actionPerformed();
928 else if (source == applyAutoAnnotationSettings)
930 applyAutoAnnotationSettings_actionPerformed();
932 alignPanel.paintAlignment(true);
936 * Set the visibility state of sequence-related and/or alignment-related
937 * annotations depending on checkbox selections, and repaint.
941 private void setAnnotationsVisibility()
943 boolean showForAlignment = showAlignmentAnnotations.getState();
944 boolean showForSequences = showSequenceAnnotations.getState();
945 if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
947 for (AlignmentAnnotation aa : alignPanel.getAlignment()
948 .getAlignmentAnnotation())
950 boolean visible = (aa.sequenceRef == null ? showForAlignment
952 aa.visible = visible;
955 alignPanel.validateAnnotationDimensions(true);
960 private void setAnnotationSortOrder(SequenceAnnotationOrder order)
962 this.annotationSortOrder = order;
966 * Set flags on the viewport that control annotation ordering
968 private void setViewportAnnotationOrder()
970 this.alignPanel.av.setSortAnnotationsBy(this.annotationSortOrder);
972 .setShowAutocalculatedAbove(this.showAutoCalculatedAbove);
975 private void setShowAutoCalculatedAbove(boolean showAbove)
977 this.showAutoCalculatedAbove = showAbove;
980 private void mouseOverFlag_stateChanged()
982 viewport.setFollowHighlight(followMouseOverFlag.getState());
983 // TODO: could kick the scrollTo mechanism to reset view for current
987 private void centreColumnLabelFlag_stateChanged()
989 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
990 this.alignPanel.annotationPanel.repaint();
994 public void actionPerformed(ActionEvent evt)
996 viewport.applet.currentAlignFrame = this;
998 Object source = evt.getSource();
1000 if (source == inputText)
1002 inputText_actionPerformed();
1004 else if (source == loadTree)
1006 loadTree_actionPerformed();
1008 else if (source == loadApplication)
1010 launchFullApplication();
1012 else if (source == loadAnnotations)
1016 else if (source == outputAnnotations)
1018 outputAnnotations(true);
1020 else if (source == outputFeatures)
1022 outputFeatures(true, "Jalview");
1024 else if (source == closeMenuItem)
1026 closeMenuItem_actionPerformed();
1028 else if (source == copy)
1030 copy_actionPerformed();
1032 else if (source == undoMenuItem)
1034 undoMenuItem_actionPerformed();
1036 else if (source == redoMenuItem)
1038 redoMenuItem_actionPerformed();
1040 else if (source == inputText)
1042 inputText_actionPerformed();
1044 else if (source == closeMenuItem)
1046 closeMenuItem_actionPerformed();
1048 else if (source == undoMenuItem)
1050 undoMenuItem_actionPerformed();
1052 else if (source == redoMenuItem)
1054 redoMenuItem_actionPerformed();
1056 else if (source == copy)
1058 copy_actionPerformed();
1060 else if (source == pasteNew)
1062 pasteNew_actionPerformed();
1064 else if (source == pasteThis)
1066 pasteThis_actionPerformed();
1068 else if (source == cut)
1070 cut_actionPerformed();
1072 else if (source == delete)
1074 delete_actionPerformed();
1076 else if (source == createGroup)
1078 createGroup_actionPerformed();
1080 else if (source == unGroup)
1082 unGroup_actionPerformed();
1084 else if (source == grpsFromSelection)
1086 makeGrpsFromSelection_actionPerformed();
1088 else if (source == deleteGroups)
1090 deleteGroups_actionPerformed();
1092 else if (source == selectAllSequenceMenuItem)
1094 selectAllSequenceMenuItem_actionPerformed();
1096 else if (source == deselectAllSequenceMenuItem)
1098 deselectAllSequenceMenuItem_actionPerformed();
1100 else if (source == invertSequenceMenuItem)
1102 invertSequenceMenuItem_actionPerformed();
1103 // uncomment to slave sequence selections in split frame
1104 // viewport.sendSelection();
1106 else if (source == invertColSel)
1108 viewport.invertColumnSelection();
1109 alignPanel.paintAlignment(true);
1110 viewport.sendSelection();
1112 else if (source == remove2LeftMenuItem)
1114 trimAlignment(true);
1116 else if (source == remove2RightMenuItem)
1118 trimAlignment(false);
1120 else if (source == removeGappedColumnMenuItem)
1122 removeGappedColumnMenuItem_actionPerformed();
1124 else if (source == removeAllGapsMenuItem)
1126 removeAllGapsMenuItem_actionPerformed();
1128 else if (source == findMenuItem)
1130 findMenuItem_actionPerformed();
1132 else if (source == font)
1134 new FontChooser(alignPanel);
1136 else if (source == newView)
1140 else if (source == showColumns)
1142 viewport.showAllHiddenColumns();
1143 alignPanel.paintAlignment(true);
1144 viewport.sendSelection();
1146 else if (source == showSeqs)
1148 viewport.showAllHiddenSeqs();
1149 alignPanel.paintAlignment(true);
1150 // uncomment if we want to slave sequence selections in split frame
1151 // viewport.sendSelection();
1153 else if (source == hideColumns)
1155 viewport.hideSelectedColumns();
1156 alignPanel.paintAlignment(true);
1157 viewport.sendSelection();
1159 else if (source == hideSequences
1160 && viewport.getSelectionGroup() != null)
1162 viewport.hideAllSelectedSeqs();
1163 alignPanel.paintAlignment(true);
1164 // uncomment if we want to slave sequence selections in split frame
1165 // viewport.sendSelection();
1167 else if (source == hideAllButSelection)
1169 toggleHiddenRegions(false, false);
1170 alignPanel.paintAlignment(true);
1171 viewport.sendSelection();
1173 else if (source == hideAllSelection)
1175 SequenceGroup sg = viewport.getSelectionGroup();
1176 viewport.expandColSelection(sg, false);
1177 viewport.hideAllSelectedSeqs();
1178 viewport.hideSelectedColumns();
1179 alignPanel.paintAlignment(true);
1180 viewport.sendSelection();
1182 else if (source == showAllHidden)
1184 viewport.showAllHiddenColumns();
1185 viewport.showAllHiddenSeqs();
1186 alignPanel.paintAlignment(true);
1187 viewport.sendSelection();
1189 else if (source == showGroupConsensus)
1191 showGroupConsensus_actionPerformed();
1193 else if (source == showGroupConservation)
1195 showGroupConservation_actionPerformed();
1197 else if (source == showSequenceLogo)
1199 showSequenceLogo_actionPerformed();
1201 else if (source == normSequenceLogo)
1203 normSequenceLogo_actionPerformed();
1205 else if (source == showConsensusHistogram)
1207 showConsensusHistogram_actionPerformed();
1209 else if (source == applyAutoAnnotationSettings)
1211 applyAutoAnnotationSettings_actionPerformed();
1213 else if (source == featureSettings)
1215 new FeatureSettings(alignPanel);
1217 else if (source == alProperties)
1219 StringBuffer contents = new jalview.io.AlignmentProperties(
1220 viewport.getAlignment()).formatAsString();
1221 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1222 cap.setText(contents.toString());
1223 Frame frame = new Frame();
1225 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
1226 "label.alignment_properties", new String[] { getTitle() }),
1229 else if (source == overviewMenuItem)
1231 overviewMenuItem_actionPerformed();
1233 else if (source == noColourmenuItem)
1237 else if (source == clustalColour)
1239 abovePIDThreshold.setState(false);
1240 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1242 else if (source == zappoColour)
1244 changeColour(new ZappoColourScheme());
1246 else if (source == taylorColour)
1248 changeColour(new TaylorColourScheme());
1250 else if (source == hydrophobicityColour)
1252 changeColour(new HydrophobicColourScheme());
1254 else if (source == helixColour)
1256 changeColour(new HelixColourScheme());
1258 else if (source == strandColour)
1260 changeColour(new StrandColourScheme());
1262 else if (source == turnColour)
1264 changeColour(new TurnColourScheme());
1266 else if (source == buriedColour)
1268 changeColour(new BuriedColourScheme());
1270 else if (source == nucleotideColour)
1272 changeColour(new NucleotideColourScheme());
1274 else if (source == purinePyrimidineColour)
1276 changeColour(new PurinePyrimidineColourScheme());
1278 // else if (source == RNAInteractionColour)
1280 // changeColour(new RNAInteractionColourScheme());
1282 else if (source == RNAHelixColour)
1284 changeColour(new RNAHelicesColour(viewport.getAlignment()));
1285 // new RNAHelicesColourChooser(viewport, alignPanel);
1287 else if (source == modifyPID)
1289 modifyPID_actionPerformed();
1291 else if (source == modifyConservation)
1293 modifyConservation_actionPerformed();
1295 else if (source == userDefinedColour)
1297 new UserDefinedColours(alignPanel, null);
1299 else if (source == PIDColour)
1301 changeColour(new PIDColourScheme());
1303 else if (source == BLOSUM62Colour)
1305 changeColour(new Blosum62ColourScheme());
1307 else if (source == tcoffeeColour)
1309 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1311 else if (source == annotationColour)
1313 new AnnotationColourChooser(viewport, alignPanel);
1315 else if (source == annotationColumnSelection)
1317 new AnnotationColumnChooser(viewport, alignPanel);
1319 else if (source == sortPairwiseMenuItem)
1321 sortPairwiseMenuItem_actionPerformed();
1323 else if (source == sortIDMenuItem)
1325 sortIDMenuItem_actionPerformed();
1327 else if (source == sortLengthMenuItem)
1329 sortLengthMenuItem_actionPerformed();
1331 else if (source == sortGroupMenuItem)
1333 sortGroupMenuItem_actionPerformed();
1335 else if (source == removeRedundancyMenuItem)
1337 removeRedundancyMenuItem_actionPerformed();
1339 else if (source == pairwiseAlignmentMenuItem)
1341 pairwiseAlignmentMenuItem_actionPerformed();
1343 else if (source == PCAMenuItem)
1345 PCAMenuItem_actionPerformed();
1347 else if (source == averageDistanceTreeMenuItem)
1349 averageDistanceTreeMenuItem_actionPerformed();
1351 else if (source == neighbourTreeMenuItem)
1353 neighbourTreeMenuItem_actionPerformed();
1355 else if (source == njTreeBlosumMenuItem)
1357 njTreeBlosumMenuItem_actionPerformed();
1359 else if (source == avDistanceTreeBlosumMenuItem)
1361 avTreeBlosumMenuItem_actionPerformed();
1363 else if (source == documentation)
1365 documentation_actionPerformed();
1367 else if (source == about)
1369 about_actionPerformed();
1374 public void inputText_actionPerformed()
1376 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1377 Frame frame = new Frame();
1379 jalview.bin.JalviewLite.addFrame(frame,
1380 MessageManager.getString("label.input_cut_paste"), 500, 500);
1383 protected void outputText_actionPerformed(ActionEvent e)
1385 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1386 Frame frame = new Frame();
1388 JalviewLite.addFrame(frame, MessageManager.formatMessage(
1389 "label.alignment_output_command",
1390 new Object[] { e.getActionCommand() }), 600, 500);
1392 FileFormatI fileFormat = FileFormats.getInstance().forName(
1393 e.getActionCommand());
1394 cap.setText(new AppletFormatAdapter(alignPanel).formatSequences(
1395 fileFormat, viewport.getAlignment(),
1396 viewport.getShowJVSuffix()));
1399 public void loadAnnotations()
1401 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1402 cap.setText(MessageManager
1403 .getString("label.paste_features_annotations_Tcoffee_here"));
1404 cap.setAnnotationImport();
1405 Frame frame = new Frame();
1407 jalview.bin.JalviewLite.addFrame(frame,
1408 MessageManager.getString("action.paste_annotations"), 400, 300);
1412 public String outputAnnotations(boolean displayTextbox)
1414 String annotation = new AnnotationFile()
1415 .printAnnotationsForView(viewport);
1419 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1420 Frame frame = new Frame();
1422 jalview.bin.JalviewLite.addFrame(frame,
1423 MessageManager.getString("label.annotations"), 600, 500);
1424 cap.setText(annotation);
1430 private Map<String, FeatureColourI> getDisplayedFeatureCols()
1432 if (alignPanel.getFeatureRenderer() != null
1433 && viewport.getFeaturesDisplayed() != null)
1435 return alignPanel.getFeatureRenderer().getDisplayedFeatureCols();
1441 private List<String> getDisplayedFeatureGroups()
1443 if (alignPanel.getFeatureRenderer() != null
1444 && viewport.getFeaturesDisplayed() != null)
1446 return alignPanel.getFeatureRenderer().getDisplayedFeatureGroups();
1452 public String outputFeatures(boolean displayTextbox, String format)
1455 FeaturesFile formatter = new FeaturesFile();
1456 if (format.equalsIgnoreCase("Jalview"))
1458 features = formatter.printJalviewFormat(viewport.getAlignment()
1459 .getSequencesArray(), getDisplayedFeatureCols(),
1460 getDisplayedFeatureGroups(), true);
1464 features = formatter.printGffFormat(viewport.getAlignment()
1465 .getSequencesArray(), getDisplayedFeatureCols(),
1466 getDisplayedFeatureGroups(), true);
1471 boolean frimport = false;
1472 if (features == null || features.equals("No Features Visible"))
1474 features = "# No features visible - paste some and import them here.";
1478 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1481 cap.setAnnotationImport();
1483 Frame frame = new Frame();
1485 jalview.bin.JalviewLite.addFrame(frame,
1486 MessageManager.getString("label.features"), 600, 500);
1487 cap.setText(features);
1491 if (features == null)
1500 void launchFullApplication()
1502 StringBuffer url = new StringBuffer(jalviewServletURL);
1504 // allow servlet parameters to be passed in applet parameter
1505 String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
1507 url.append(firstSep);
1510 + appendProtocol(viewport.applet.getParameter("file")));
1512 if (viewport.applet.getParameter("features") != null)
1514 url.append("&features=");
1515 url.append(appendProtocol(viewport.applet.getParameter("features")));
1518 if (viewport.applet.getParameter("annotations") != null)
1520 url.append("&annotations=");
1521 url.append(appendProtocol(viewport.applet.getParameter("annotations")));
1524 if (viewport.applet.getParameter("jnetfile") != null
1525 || viewport.applet.getParameter("jpredfile") != null)
1527 url.append("&annotations=");
1528 url.append(appendProtocol(viewport.applet.getParameter("jnetfile") != null ? viewport.applet
1529 .getParameter("jnetfile") : viewport.applet
1530 .getParameter("jpredfile")));
1533 if (viewport.applet.getParameter("defaultColour") != null)
1535 url.append("&colour="
1536 + removeWhiteSpace(viewport.applet
1537 .getParameter("defaultColour")));
1540 if (viewport.applet.getParameter("userDefinedColour") != null)
1542 url.append("&colour="
1543 + removeWhiteSpace(viewport.applet
1544 .getParameter("userDefinedColour")));
1546 if (viewport.applet.getParameter("tree") != null)
1549 + appendProtocol(viewport.applet.getParameter("tree")));
1551 if (viewport.applet.getParameter("treeFile") != null)
1554 + appendProtocol(viewport.applet.getParameter("treeFile")));
1557 showURL(url.toString(), "FULL_APP");
1560 String removeWhiteSpace(String colour)
1562 StringBuffer sb = new StringBuffer();
1563 for (int i = 0; i < colour.length(); i++)
1565 if (Character.isWhitespace(colour.charAt(i)))
1571 sb.append(colour.charAt(i));
1575 return sb.toString();
1578 String appendProtocol(String url)
1583 url = URLEncoder.encode(url);
1586 * When we finally deprecate 1.1 compatibility, we can start to use
1587 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1588 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1589 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1590 * ex.printStackTrace(); }
1592 catch (java.net.MalformedURLException ex)
1594 url = viewport.applet.getCodeBase() + url;
1599 public void closeMenuItem_actionPerformed()
1601 PaintRefresher.RemoveComponent(alignPanel);
1602 if (alignPanel.seqPanel != null
1603 && alignPanel.seqPanel.seqCanvas != null)
1605 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1607 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1609 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1612 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1627 void updateEditMenuBar()
1630 if (viewport.getHistoryList().size() > 0)
1632 undoMenuItem.setEnabled(true);
1633 CommandI command = viewport.getHistoryList().peek();
1634 undoMenuItem.setLabel(MessageManager.formatMessage(
1635 "label.undo_command",
1636 new Object[] { command.getDescription() }));
1640 undoMenuItem.setEnabled(false);
1641 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1644 if (viewport.getRedoList().size() > 0)
1646 redoMenuItem.setEnabled(true);
1648 CommandI command = viewport.getRedoList().peek();
1649 redoMenuItem.setLabel(MessageManager.formatMessage(
1650 "label.redo_command",
1651 new Object[] { command.getDescription() }));
1655 redoMenuItem.setEnabled(false);
1656 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1664 public void addHistoryItem(CommandI command)
1666 if (command.getSize() > 0)
1668 viewport.addToHistoryList(command);
1669 viewport.clearRedoList();
1670 updateEditMenuBar();
1671 viewport.updateHiddenColumns();
1676 * TODO: JAL-1104 DOCUMENT ME!
1681 protected void undoMenuItem_actionPerformed()
1683 if (viewport.getHistoryList().isEmpty())
1688 CommandI command = viewport.getHistoryList().pop();
1689 viewport.addToRedoList(command);
1690 command.undoCommand(null);
1692 AlignmentViewport originalSource = getOriginatingSource(command);
1694 if (originalSource != viewport)
1697 .println("Warning: Viewport object mismatch whilst undoing");
1699 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1700 // viewport.getColumnSelection().getHiddenColumns()
1702 updateEditMenuBar();
1703 originalSource.firePropertyChange("alignment", null, originalSource
1704 .getAlignment().getSequences());
1708 * TODO: JAL-1104 DOCUMENT ME!
1713 protected void redoMenuItem_actionPerformed()
1715 if (viewport.getRedoList().isEmpty())
1720 CommandI command = viewport.getRedoList().pop();
1721 viewport.addToHistoryList(command);
1722 command.doCommand(null);
1724 AlignmentViewport originalSource = getOriginatingSource(command);
1726 if (originalSource != viewport)
1729 .println("Warning: Viewport object mismatch whilst re-doing");
1731 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1732 // viewport.getColumnSelection().getHiddenColumns()
1735 updateEditMenuBar();
1736 originalSource.firePropertyChange("alignment", null, originalSource
1737 .getAlignment().getSequences());
1740 AlignmentViewport getOriginatingSource(CommandI command)
1742 AlignmentViewport originalSource = null;
1743 // For sequence removal and addition, we need to fire
1744 // the property change event FROM the viewport where the
1745 // original alignment was altered
1746 AlignmentI al = null;
1747 if (command instanceof EditCommand)
1749 EditCommand editCommand = (EditCommand) command;
1750 al = editCommand.getAlignment();
1751 Vector comps = (Vector) PaintRefresher.components.get(viewport
1752 .getSequenceSetId());
1753 for (int i = 0; i < comps.size(); i++)
1755 if (comps.elementAt(i) instanceof AlignmentPanel)
1757 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1759 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1766 if (originalSource == null)
1768 // The original view is closed, we must validate
1769 // the current view against the closed view first
1772 PaintRefresher.validateSequences(al, viewport.getAlignment());
1775 originalSource = viewport;
1778 return originalSource;
1782 * Move the currently selected sequences up or down one position in the
1787 public void moveSelectedSequences(boolean up)
1789 SequenceGroup sg = viewport.getSelectionGroup();
1794 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1795 up ? null : viewport.getHiddenRepSequences(), up);
1796 alignPanel.paintAlignment(true);
1799 * Also move cDNA/protein complement sequences
1801 AlignViewportI complement = viewport.getCodingComplement();
1802 if (complement != null)
1804 SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
1805 viewport, complement);
1806 complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
1807 up ? null : complement.getHiddenRepSequences(), up);
1808 getSplitFrame().getComplement(this).alignPanel.paintAlignment(true);
1812 synchronized void slideSequences(boolean right, int size)
1814 List<SequenceI> sg = new Vector<SequenceI>();
1815 if (viewport.cursorMode)
1817 sg.add(viewport.getAlignment().getSequenceAt(
1818 alignPanel.seqPanel.seqCanvas.cursorY));
1820 else if (viewport.getSelectionGroup() != null
1821 && viewport.getSelectionGroup().getSize() != viewport
1822 .getAlignment().getHeight())
1824 sg = viewport.getSelectionGroup().getSequences(
1825 viewport.getHiddenRepSequences());
1833 Vector<SequenceI> invertGroup = new Vector();
1835 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1837 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1839 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1843 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1845 SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup
1847 for (int i = 0; i < invertGroup.size(); i++)
1849 seqs2[i] = invertGroup.elementAt(i);
1852 SlideSequencesCommand ssc;
1855 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1856 size, viewport.getGapCharacter());
1860 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1861 size, viewport.getGapCharacter());
1864 int groupAdjustment = 0;
1865 if (ssc.getGapsInsertedBegin() && right)
1867 if (viewport.cursorMode)
1869 alignPanel.seqPanel.moveCursor(size, 0);
1873 groupAdjustment = size;
1876 else if (!ssc.getGapsInsertedBegin() && !right)
1878 if (viewport.cursorMode)
1880 alignPanel.seqPanel.moveCursor(-size, 0);
1884 groupAdjustment = -size;
1888 if (groupAdjustment != 0)
1890 viewport.getSelectionGroup().setStartRes(
1891 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1892 viewport.getSelectionGroup().setEndRes(
1893 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1896 boolean appendHistoryItem = false;
1897 Deque<CommandI> historyList = viewport.getHistoryList();
1898 if (historyList != null && historyList.size() > 0
1899 && historyList.peek() instanceof SlideSequencesCommand)
1901 appendHistoryItem = ssc
1902 .appendSlideCommand((SlideSequencesCommand) historyList
1906 if (!appendHistoryItem)
1908 addHistoryItem(ssc);
1914 static StringBuffer copiedSequences;
1916 static Vector copiedHiddenColumns;
1918 protected void copy_actionPerformed()
1920 if (viewport.getSelectionGroup() == null)
1925 SequenceGroup sg = viewport.getSelectionGroup();
1926 copiedSequences = new StringBuffer();
1927 Map<Integer, SequenceI> orderedSeqs = new HashMap<Integer, SequenceI>();
1928 for (int i = 0; i < sg.getSize(); i++)
1930 SequenceI seq = sg.getSequenceAt(i);
1931 int index = viewport.getAlignment().findIndex(seq);
1932 orderedSeqs.put(index, seq);
1935 int index = 0, startRes, endRes;
1938 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1940 copiedHiddenColumns = new Vector();
1941 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1942 for (int[] region : viewport.getAlignment().getHiddenColumns()
1943 .getHiddenRegions())
1945 copiedHiddenColumns.addElement(new int[] {
1946 region[0] - hiddenOffset, region[1] - hiddenOffset });
1951 copiedHiddenColumns = null;
1954 for (int i = 0; i < sg.getSize(); i++)
1956 SequenceI seq = null;
1960 if (orderedSeqs.containsKey(index))
1962 seq = orderedSeqs.get(index);
1973 // Returns residue following index if gap
1974 startRes = seq.findPosition(sg.getStartRes());
1977 // Need to find the residue preceeding index if gap
1980 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1982 ch = seq.getCharAt(j);
1983 if (!jalview.util.Comparison.isGap((ch)))
1991 endRes += seq.getStart() - 1;
1994 copiedSequences.append(seq.getName()
2000 + seq.getSequenceAsString(sg.getStartRes(),
2001 sg.getEndRes() + 1) + "\n");
2006 protected void pasteNew_actionPerformed()
2011 protected void pasteThis_actionPerformed()
2016 void paste(boolean newAlignment)
2021 if (copiedSequences == null)
2026 StringTokenizer st = new StringTokenizer(copiedSequences.toString());
2027 Vector seqs = new Vector();
2028 while (st.hasMoreElements())
2030 String name = st.nextToken();
2031 int start = Integer.parseInt(st.nextToken());
2032 int end = Integer.parseInt(st.nextToken());
2033 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
2035 SequenceI[] newSeqs = new SequenceI[seqs.size()];
2036 for (int i = 0; i < seqs.size(); i++)
2038 newSeqs[i] = (SequenceI) seqs.elementAt(i);
2043 String newtitle = MessageManager
2044 .getString("label.copied_sequences");
2045 if (getTitle().startsWith(
2046 MessageManager.getString("label.copied_sequences")))
2048 newtitle = getTitle();
2052 newtitle = newtitle.concat(MessageManager.formatMessage(
2053 "label.from_msname", new String[] { getTitle() }));
2055 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
2056 viewport.applet, newtitle, false);
2057 if (copiedHiddenColumns != null)
2059 for (int i = 0; i < copiedHiddenColumns.size(); i++)
2061 int[] region = (int[]) copiedHiddenColumns.elementAt(i);
2062 af.viewport.hideColumns(region[0], region[1]);
2066 jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
2071 addSequences(newSeqs);
2074 } catch (Exception ex)
2076 } // could be anything being pasted in here
2080 void addSequences(SequenceI[] seqs)
2082 for (int i = 0; i < seqs.length; i++)
2084 viewport.getAlignment().addSequence(seqs[i]);
2088 addHistoryItem(new EditCommand(
2089 MessageManager.getString("label.add_sequences"), Action.PASTE,
2090 seqs, 0, viewport.getAlignment().getWidth(),
2091 viewport.getAlignment()));
2093 viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight());
2094 viewport.getAlignment().getWidth();
2095 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2100 protected void cut_actionPerformed()
2102 copy_actionPerformed();
2103 delete_actionPerformed();
2106 protected void delete_actionPerformed()
2109 SequenceGroup sg = viewport.getSelectionGroup();
2115 Vector seqs = new Vector();
2117 for (int i = 0; i < sg.getSize(); i++)
2119 seq = sg.getSequenceAt(i);
2120 seqs.addElement(seq);
2124 * If the cut affects all sequences, warn, remove highlighted columns
2126 if (sg.getSize() == viewport.getAlignment().getHeight())
2128 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2129 .getAlignment().getWidth()) ? true : false;
2130 if (isEntireAlignWidth)
2132 String title = MessageManager.getString("label.delete_all");
2133 Panel infoPanel = new Panel();
2134 infoPanel.setLayout(new FlowLayout());
2136 .add(new Label(MessageManager.getString("warn.delete_all")));
2138 final JVDialog dialog = new JVDialog(this, title, true, 400, 200);
2139 dialog.setMainPanel(infoPanel);
2140 dialog.ok.setLabel(MessageManager.getString("action.ok"));
2141 dialog.cancel.setLabel(MessageManager.getString("action.cancel"));
2142 dialog.setVisible(true);
2149 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2150 sg.getEndRes() + 1);
2153 SequenceI[] cut = new SequenceI[seqs.size()];
2154 for (int i = 0; i < seqs.size(); i++)
2156 cut[i] = (SequenceI) seqs.elementAt(i);
2160 * //ADD HISTORY ITEM
2162 addHistoryItem(new EditCommand(
2163 MessageManager.getString("label.cut_sequences"), Action.CUT,
2164 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2165 viewport.getAlignment()));
2167 viewport.setSelectionGroup(null);
2168 viewport.getAlignment().deleteGroup(sg);
2170 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2173 if (viewport.getAlignment().getHeight() < 1)
2175 this.setVisible(false);
2177 viewport.sendSelection();
2181 * group consensus toggled
2184 protected void showGroupConsensus_actionPerformed()
2186 viewport.setShowGroupConsensus(showGroupConsensus.getState());
2187 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2192 * group conservation toggled.
2194 protected void showGroupConservation_actionPerformed()
2196 viewport.setShowGroupConservation(showGroupConservation.getState());
2197 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2204 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
2205 * .event.ActionEvent)
2207 protected void showConsensusHistogram_actionPerformed()
2209 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
2210 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2217 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
2218 * .event.ActionEvent)
2220 protected void showSequenceLogo_actionPerformed()
2222 viewport.setShowSequenceLogo(showSequenceLogo.getState());
2223 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2226 protected void normSequenceLogo_actionPerformed()
2228 showSequenceLogo.setState(true);
2229 viewport.setShowSequenceLogo(true);
2230 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
2231 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2234 protected void applyAutoAnnotationSettings_actionPerformed()
2236 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2239 protected void makeGrpsFromSelection_actionPerformed()
2241 if (avc.makeGroupsFromSelection())
2243 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2244 alignPanel.updateAnnotation();
2245 alignPanel.paintAlignment(true);
2249 protected void createGroup_actionPerformed()
2254 protected void unGroup_actionPerformed()
2258 alignPanel.alignmentChanged();
2262 protected void deleteGroups_actionPerformed()
2264 if (avc.deleteGroups())
2266 alignPanel.alignmentChanged();
2270 public void selectAllSequenceMenuItem_actionPerformed()
2272 SequenceGroup sg = new SequenceGroup();
2273 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2275 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2277 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2278 viewport.setSelectionGroup(sg);
2279 // JAL-2034 - should delegate to
2280 // alignPanel to decide if overview needs
2282 alignPanel.paintAlignment(false);
2283 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2284 viewport.sendSelection();
2287 public void deselectAllSequenceMenuItem_actionPerformed()
2289 if (viewport.cursorMode)
2291 alignPanel.seqPanel.keyboardNo1 = null;
2292 alignPanel.seqPanel.keyboardNo2 = null;
2294 viewport.setSelectionGroup(null);
2295 viewport.getColumnSelection().clear();
2296 viewport.setSelectionGroup(null);
2297 alignPanel.idPanel.idCanvas.searchResults = null;
2298 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2299 // JAL-2034 - should delegate to
2300 // alignPanel to decide if overview needs
2302 alignPanel.paintAlignment(false);
2303 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2304 viewport.sendSelection();
2307 public void invertSequenceMenuItem_actionPerformed()
2309 SequenceGroup sg = viewport.getSelectionGroup();
2310 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2312 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2315 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2316 viewport.sendSelection();
2319 public void invertColSel_actionPerformed()
2321 viewport.invertColumnSelection();
2322 alignPanel.paintAlignment(true);
2323 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2324 viewport.sendSelection();
2327 void trimAlignment(boolean trimLeft)
2329 AlignmentI al = viewport.getAlignment();
2330 ViewportRanges ranges = viewport.getRanges();
2331 ColumnSelection colSel = viewport.getColumnSelection();
2334 if (!colSel.isEmpty())
2338 column = colSel.getMin();
2342 column = colSel.getMax();
2346 if (viewport.getSelectionGroup() != null)
2348 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2349 viewport.getHiddenRepSequences());
2353 seqs = al.getSequencesArray();
2356 TrimRegionCommand trimRegion;
2359 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2361 ranges.setStartRes(0);
2365 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2369 statusBar.setText(MessageManager.formatMessage(
2370 "label.removed_columns",
2371 new String[] { Integer.valueOf(trimRegion.getSize())
2373 addHistoryItem(trimRegion);
2375 for (SequenceGroup sg : al.getGroups())
2377 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2378 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2384 viewport.firePropertyChange("alignment", null, al.getSequences());
2388 public void removeGappedColumnMenuItem_actionPerformed()
2390 AlignmentI al = viewport.getAlignment();
2391 ViewportRanges ranges = viewport.getRanges();
2393 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2396 if (viewport.getSelectionGroup() != null)
2398 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2399 viewport.getHiddenRepSequences());
2400 start = viewport.getSelectionGroup().getStartRes();
2401 end = viewport.getSelectionGroup().getEndRes();
2405 seqs = viewport.getAlignment().getSequencesArray();
2408 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2409 "Remove Gapped Columns", seqs, start, end,
2410 viewport.getAlignment());
2412 addHistoryItem(removeGapCols);
2414 statusBar.setText(MessageManager.formatMessage(
2415 "label.removed_empty_columns",
2416 new String[] { Integer.valueOf(removeGapCols.getSize())
2419 // This is to maintain viewport position on first residue
2420 // of first sequence
2421 SequenceI seq = al.getSequenceAt(0);
2422 int startRes = seq.findPosition(ranges.getStartRes());
2423 // ShiftList shifts;
2424 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2425 // edit.alColumnChanges=shifts.getInverse();
2426 // if (viewport.hasHiddenColumns)
2427 // viewport.getColumnSelection().compensateForEdits(shifts);
2428 ranges.setStartRes(seq.findIndex(startRes) - 1);
2429 viewport.firePropertyChange("alignment", null, al.getSequences());
2433 public void removeAllGapsMenuItem_actionPerformed()
2435 AlignmentI al = viewport.getAlignment();
2436 ViewportRanges ranges = viewport.getRanges();
2438 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2441 if (viewport.getSelectionGroup() != null)
2443 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2444 viewport.getHiddenRepSequences());
2445 start = viewport.getSelectionGroup().getStartRes();
2446 end = viewport.getSelectionGroup().getEndRes();
2450 seqs = viewport.getAlignment().getSequencesArray();
2453 // This is to maintain viewport position on first residue
2454 // of first sequence
2455 SequenceI seq = al.getSequenceAt(0);
2456 int startRes = seq.findPosition(ranges.getStartRes());
2458 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2461 ranges.setStartRes(seq.findIndex(startRes) - 1);
2463 viewport.firePropertyChange("alignment", null, al.getSequences());
2467 public void findMenuItem_actionPerformed()
2469 new Finder(alignPanel);
2473 * create a new view derived from the current view
2476 * @return frame for the new view
2478 public AlignFrame newView(String viewtitle)
2481 if (viewport.hasHiddenRows())
2483 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2484 .getFullAlignment().getSequencesArray());
2488 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2491 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2493 for (int i = 0; i < viewport.getAlignment().getAlignmentAnnotation().length; i++)
2495 if (!viewport.getAlignment().getAlignmentAnnotation()[i].autoCalculated)
2497 newal.addAnnotation(viewport.getAlignment()
2498 .getAlignmentAnnotation()[i]);
2503 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2505 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2506 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2507 PaintRefresher.Register(newaf.alignPanel,
2508 newaf.alignPanel.av.getSequenceSetId());
2510 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2511 newaf.alignPanel.av.getSequenceSetId());
2512 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2513 newaf.alignPanel.av.getSequenceSetId());
2515 Vector comps = (Vector) PaintRefresher.components.get(viewport
2516 .getSequenceSetId());
2518 for (int i = 0; i < comps.size(); i++)
2520 if (comps.elementAt(i) instanceof AlignmentPanel)
2526 String title = new String(this.getTitle());
2527 if (viewtitle != null)
2529 title = viewtitle + " ( " + title + ")";
2533 if (title.indexOf("(View") > -1)
2535 title = title.substring(0, title.indexOf("(View"));
2537 title += "(View " + viewSize + ")";
2540 newaf.setTitle(title.toString());
2542 newaf.viewport.setHistoryList(viewport.getHistoryList());
2543 newaf.viewport.setRedoList(viewport.getRedoList());
2549 * @return list of feature groups on the view
2551 public String[] getFeatureGroups()
2553 FeatureRenderer fr = null;
2554 if (alignPanel != null
2555 && (fr = alignPanel.getFeatureRenderer()) != null)
2557 List<String> gps = fr.getFeatureGroups();
2558 String[] _gps = gps.toArray(new String[gps.size()]);
2565 * get sequence feature groups that are hidden or shown
2571 public String[] getFeatureGroupsOfState(boolean visible)
2573 FeatureRenderer fr = null;
2574 if (alignPanel != null
2575 && (fr = alignPanel.getFeatureRenderer()) != null)
2577 List<String> gps = fr.getGroups(visible);
2578 String[] _gps = gps.toArray(new String[gps.size()]);
2585 * Change the display state for the given feature groups
2588 * list of group strings
2590 * visible or invisible
2592 public void setFeatureGroupState(String[] groups, boolean state)
2594 FeatureRenderer fr = null;
2595 this.sequenceFeatures.setState(true);
2596 viewport.setShowSequenceFeatures(true);
2597 if (alignPanel != null
2598 && (fr = alignPanel.getFeatureRenderer()) != null)
2601 fr.setGroupVisibility(Arrays.asList(groups), state);
2602 alignPanel.seqPanel.seqCanvas.repaint();
2603 if (alignPanel.overviewPanel != null)
2605 alignPanel.overviewPanel.updateOverviewImage();
2610 public void seqLimits_itemStateChanged()
2612 viewport.setShowJVSuffix(seqLimits.getState());
2613 alignPanel.fontChanged();
2614 alignPanel.paintAlignment(true);
2617 protected void colourTextMenuItem_actionPerformed()
2619 viewport.setColourText(colourTextMenuItem.getState());
2620 alignPanel.paintAlignment(true);
2623 protected void displayNonconservedMenuItem_actionPerformed()
2625 viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
2626 alignPanel.paintAlignment(true);
2629 protected void wrapMenuItem_actionPerformed()
2631 viewport.setWrapAlignment(wrapMenuItem.getState());
2632 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2633 scaleAbove.setEnabled(wrapMenuItem.getState());
2634 scaleLeft.setEnabled(wrapMenuItem.getState());
2635 scaleRight.setEnabled(wrapMenuItem.getState());
2636 alignPanel.paintAlignment(true);
2639 public void overviewMenuItem_actionPerformed()
2641 if (alignPanel.overviewPanel != null)
2646 Frame frame = new Frame();
2647 OverviewPanel overview = new OverviewPanel(alignPanel);
2648 frame.add(overview);
2649 // +50 must allow for applet frame window
2650 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
2651 "label.overview_params", new String[] { this.getTitle() }),
2652 overview.getPreferredSize().width,
2653 overview.getPreferredSize().height + 50);
2656 final AlignmentPanel ap = alignPanel;
2657 frame.addWindowListener(new WindowAdapter()
2660 public void windowClosing(WindowEvent e)
2664 ap.setOverviewPanel(null);
2669 alignPanel.setOverviewPanel(overview);
2674 public void changeColour(ColourSchemeI cs)
2676 viewport.setGlobalColourScheme(cs);
2678 alignPanel.paintAlignment(true);
2681 protected void modifyPID_actionPerformed()
2683 if (viewport.getAbovePIDThreshold()
2684 && viewport.getGlobalColourScheme() != null)
2686 SliderPanel.setPIDSliderSource(alignPanel,
2687 viewport.getResidueShading(), alignPanel.getViewName());
2688 SliderPanel.showPIDSlider();
2692 protected void modifyConservation_actionPerformed()
2694 if (viewport.getConservationSelected()
2695 && viewport.getGlobalColourScheme() != null)
2697 SliderPanel.setConservationSlider(alignPanel,
2698 viewport.getResidueShading(), alignPanel.getViewName());
2699 SliderPanel.showConservationSlider();
2703 protected void conservationMenuItem_actionPerformed()
2705 boolean selected = conservationMenuItem.getState();
2706 modifyConservation.setEnabled(selected);
2707 viewport.setConservationSelected(selected);
2708 viewport.getResidueShading().setConservationApplied(selected);
2710 changeColour(viewport.getGlobalColourScheme());
2714 modifyConservation_actionPerformed();
2718 SliderPanel.hideConservationSlider();
2722 public void abovePIDThreshold_actionPerformed()
2724 boolean selected = abovePIDThreshold.getState();
2725 modifyPID.setEnabled(selected);
2726 viewport.setAbovePIDThreshold(selected);
2729 viewport.getResidueShading().setThreshold(0,
2730 viewport.isIgnoreGapsConsensus());
2733 changeColour(viewport.getGlobalColourScheme());
2737 modifyPID_actionPerformed();
2741 SliderPanel.hidePIDSlider();
2745 public void sortPairwiseMenuItem_actionPerformed()
2747 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2748 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
2749 .getAlignment().getSequenceAt(0));
2751 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2752 viewport.getAlignment()));
2753 alignPanel.paintAlignment(true);
2756 public void sortIDMenuItem_actionPerformed()
2758 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2759 AlignmentSorter.sortByID(viewport.getAlignment());
2760 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
2761 viewport.getAlignment()));
2762 alignPanel.paintAlignment(true);
2765 public void sortLengthMenuItem_actionPerformed()
2767 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2768 AlignmentSorter.sortByLength(viewport.getAlignment());
2769 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2770 viewport.getAlignment()));
2771 alignPanel.paintAlignment(true);
2774 public void sortGroupMenuItem_actionPerformed()
2776 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2777 AlignmentSorter.sortByGroup(viewport.getAlignment());
2778 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2779 viewport.getAlignment()));
2780 alignPanel.paintAlignment(true);
2784 public void removeRedundancyMenuItem_actionPerformed()
2786 new RedundancyPanel(alignPanel);
2789 public void pairwiseAlignmentMenuItem_actionPerformed()
2791 if (viewport.getSelectionGroup() != null
2792 && viewport.getSelectionGroup().getSize() > 1)
2794 Frame frame = new Frame();
2795 frame.add(new PairwiseAlignPanel(alignPanel));
2796 jalview.bin.JalviewLite.addFrame(frame,
2797 MessageManager.getString("action.pairwise_alignment"), 600,
2802 public void PCAMenuItem_actionPerformed()
2804 // are the sequences aligned?
2805 if (!viewport.getAlignment().isAligned(false))
2808 int Width = viewport.getAlignment().getWidth();
2810 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2812 current = viewport.getAlignment().getSequenceAt(i);
2814 if (current.getLength() < Width)
2816 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2819 alignPanel.paintAlignment(true);
2822 if ((viewport.getSelectionGroup() != null
2823 && viewport.getSelectionGroup().getSize() < 4 && viewport
2824 .getSelectionGroup().getSize() > 0)
2825 || viewport.getAlignment().getHeight() < 4)
2832 new PCAPanel(viewport);
2833 } catch (java.lang.OutOfMemoryError ex)
2839 public void averageDistanceTreeMenuItem_actionPerformed()
2841 newTreePanel(TreeBuilder.AVERAGE_DISTANCE, new PIDModel().getName(),
2842 "Average distance tree using PID");
2845 public void neighbourTreeMenuItem_actionPerformed()
2847 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING, new PIDModel().getName(),
2848 "Neighbour joining tree using PID");
2851 protected void njTreeBlosumMenuItem_actionPerformed()
2853 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING, ScoreModels.getInstance()
2854 .getBlosum62().getName(),
2855 "Neighbour joining tree using BLOSUM62");
2858 protected void avTreeBlosumMenuItem_actionPerformed()
2860 newTreePanel(TreeBuilder.AVERAGE_DISTANCE, ScoreModels.getInstance()
2861 .getBlosum62().getName(),
2862 "Average distance tree using BLOSUM62");
2865 void newTreePanel(String type, String pwType, String title)
2867 // are the sequences aligned?
2868 if (!viewport.getAlignment().isAligned(false))
2871 int Width = viewport.getAlignment().getWidth();
2873 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2875 current = viewport.getAlignment().getSequenceAt(i);
2877 if (current.getLength() < Width)
2879 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2882 alignPanel.paintAlignment(true);
2886 if ((viewport.getSelectionGroup() != null && viewport
2887 .getSelectionGroup().getSize() > 1)
2888 || (viewport.getAlignment().getHeight() > 1))
2890 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2892 addTreeMenuItem(tp, title);
2894 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2898 void loadTree_actionPerformed()
2900 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2901 cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2902 cap.setTreeImport();
2903 Frame frame = new Frame();
2905 jalview.bin.JalviewLite.addFrame(frame,
2906 MessageManager.getString("label.paste_newick_file"), 400, 300);
2909 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2911 TreePanel tp = new TreePanel(alignPanel, treeFile,
2912 MessageManager.getString("label.load_tree_from_file"), tree);
2913 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2914 addTreeMenuItem(tp, treeFile);
2918 * sort the alignment using the given treePanel
2921 * tree used to sort view
2923 * string used for undo event name
2925 public void sortByTree(TreePanel treePanel, String title)
2927 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2929 .sortByTree(viewport.getAlignment(), treePanel.getTree());
2930 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2931 // HistoryItem.SORT));
2932 addHistoryItem(new OrderCommand(MessageManager.formatMessage(
2933 "label.order_by_params", new String[] { title }), oldOrder,
2934 viewport.getAlignment()));
2935 alignPanel.paintAlignment(true);
2939 * Do any automatic reordering of the alignment and add the necessary bits to
2940 * the menu structure for the new tree
2945 protected void addTreeMenuItem(final TreePanel treePanel,
2948 final MenuItem item = new MenuItem(title);
2949 sortByTreeMenu.add(item);
2950 item.addActionListener(new java.awt.event.ActionListener()
2953 public void actionPerformed(ActionEvent evt)
2955 sortByTree(treePanel, title); // treePanel.getTitle());
2959 treePanel.addWindowListener(new WindowAdapter()
2962 public void windowOpened(WindowEvent e)
2964 if (viewport.sortByTree)
2966 sortByTree(treePanel, title);
2968 super.windowOpened(e);
2972 public void windowClosing(WindowEvent e)
2974 sortByTreeMenu.remove(item);
2979 public boolean sortBy(AlignmentOrder alorder, String undoname)
2981 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2982 if (viewport.applet.debug)
2984 System.err.println("Sorting " + alorder.getOrder().size()
2985 + " in alignment '" + getTitle() + "'");
2987 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2988 if (undoname != null)
2990 addHistoryItem(new OrderCommand(undoname, oldOrder,
2991 viewport.getAlignment()));
2993 alignPanel.paintAlignment(true);
2997 protected void documentation_actionPerformed()
2999 alignPanel.av.applet.openJalviewHelpUrl();
3002 protected void about_actionPerformed()
3005 class AboutPanel extends Canvas
3011 public AboutPanel(String version, String builddate)
3013 this.version = version;
3014 this.builddate = builddate;
3018 public void paint(Graphics g)
3020 g.setColor(Color.white);
3021 g.fillRect(0, 0, getSize().width, getSize().height);
3022 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3023 FontMetrics fm = g.getFontMetrics();
3024 int fh = fm.getHeight();
3026 g.setColor(Color.black);
3027 // TODO: update this text for each release or centrally store it for
3028 // lite and application
3029 g.setFont(new Font("Helvetica", Font.BOLD, 14));
3030 g.drawString(MessageManager.formatMessage(
3031 "label.jalviewLite_release", new String[] { version }), x,
3033 g.setFont(new Font("Helvetica", Font.BOLD, 12));
3034 g.drawString(MessageManager.formatMessage(
3035 "label.jaview_build_date", new String[] { builddate }), x,
3037 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3038 g.drawString(MessageManager.getString("label.jalview_authors_1"),
3040 g.drawString(MessageManager.getString("label.jalview_authors_2"),
3041 x + 50, y += fh + 8);
3043 MessageManager.getString("label.jalview_dev_managers"), x,
3045 g.drawString(MessageManager
3046 .getString("label.jalview_distribution_lists"), x, y += fh);
3047 g.drawString(MessageManager.getString("label.jalview_please_cite"),
3050 MessageManager.getString("label.jalview_cite_1_authors"),
3053 MessageManager.getString("label.jalview_cite_1_title"), x,
3055 g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
3060 Frame frame = new Frame();
3061 frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite
3063 jalview.bin.JalviewLite.addFrame(frame,
3064 MessageManager.getString("label.jalview"), 580, 220);
3068 public void showURL(String url, String target)
3070 if (viewport.applet == null)
3072 System.out.println("Not running as applet - no browser available.");
3076 viewport.applet.showURL(url, target);
3080 // ////////////////////////////////////////////////////////////////////////////////
3081 // JBuilder Graphics here
3083 MenuBar alignFrameMenuBar = new MenuBar();
3085 Menu fileMenu = new Menu(MessageManager.getString("action.file"));
3087 MenuItem loadApplication = new MenuItem(
3088 MessageManager.getString("label.view_full_application"));
3090 MenuItem loadTree = new MenuItem(
3091 MessageManager.getString("label.load_associated_tree"));
3093 MenuItem loadAnnotations = new MenuItem(
3094 MessageManager.getString("label.load_features_annotations"));
3096 MenuItem outputFeatures = new MenuItem(
3097 MessageManager.getString("label.export_features"));
3099 MenuItem outputAnnotations = new MenuItem(
3100 MessageManager.getString("label.export_annotations"));
3102 MenuItem closeMenuItem = new MenuItem(
3103 MessageManager.getString("action.close"));
3105 MenuItem selectAllSequenceMenuItem = new MenuItem(
3106 MessageManager.getString("action.select_all"));
3108 MenuItem deselectAllSequenceMenuItem = new MenuItem(
3109 MessageManager.getString("action.deselect_all"));
3111 MenuItem invertSequenceMenuItem = new MenuItem(
3112 MessageManager.getString("action.invert_selection"));
3114 MenuItem remove2LeftMenuItem = new MenuItem();
3116 MenuItem remove2RightMenuItem = new MenuItem();
3118 MenuItem removeGappedColumnMenuItem = new MenuItem();
3120 MenuItem removeAllGapsMenuItem = new MenuItem();
3122 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
3124 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
3126 MenuItem sortPairwiseMenuItem = new MenuItem();
3128 MenuItem sortIDMenuItem = new MenuItem();
3130 MenuItem sortLengthMenuItem = new MenuItem();
3132 MenuItem sortGroupMenuItem = new MenuItem();
3134 MenuItem removeRedundancyMenuItem = new MenuItem();
3136 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
3138 MenuItem PCAMenuItem = new MenuItem();
3140 MenuItem averageDistanceTreeMenuItem = new MenuItem();
3142 MenuItem neighbourTreeMenuItem = new MenuItem();
3144 BorderLayout borderLayout1 = new BorderLayout();
3146 public Label statusBar = new Label();
3148 MenuItem clustalColour = new MenuItem();
3150 MenuItem zappoColour = new MenuItem();
3152 MenuItem taylorColour = new MenuItem();
3154 MenuItem hydrophobicityColour = new MenuItem();
3156 MenuItem helixColour = new MenuItem();
3158 MenuItem strandColour = new MenuItem();
3160 MenuItem turnColour = new MenuItem();
3162 MenuItem buriedColour = new MenuItem();
3164 MenuItem purinePyrimidineColour = new MenuItem();
3166 // MenuItem RNAInteractionColour = new MenuItem();
3168 MenuItem RNAHelixColour = new MenuItem();
3170 MenuItem userDefinedColour = new MenuItem();
3172 MenuItem PIDColour = new MenuItem();
3174 MenuItem BLOSUM62Colour = new MenuItem();
3176 MenuItem tcoffeeColour = new MenuItem();
3178 MenuItem njTreeBlosumMenuItem = new MenuItem();
3180 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
3182 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
3184 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
3186 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
3188 MenuItem alProperties = new MenuItem(
3189 MessageManager.getString("label.alignment_props"));
3191 MenuItem overviewMenuItem = new MenuItem();
3193 MenuItem undoMenuItem = new MenuItem();
3195 MenuItem redoMenuItem = new MenuItem();
3197 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
3199 MenuItem noColourmenuItem = new MenuItem();
3201 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
3203 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
3205 MenuItem findMenuItem = new MenuItem();
3207 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
3209 MenuItem nucleotideColour = new MenuItem();
3211 MenuItem deleteGroups = new MenuItem();
3213 MenuItem grpsFromSelection = new MenuItem();
3215 MenuItem createGroup = new MenuItem();
3217 MenuItem unGroup = new MenuItem();
3219 MenuItem delete = new MenuItem();
3221 MenuItem copy = new MenuItem();
3223 MenuItem cut = new MenuItem();
3225 Menu pasteMenu = new Menu();
3227 MenuItem pasteNew = new MenuItem();
3229 MenuItem pasteThis = new MenuItem();
3231 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
3233 MenuItem font = new MenuItem();
3235 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
3237 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
3239 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
3241 MenuItem modifyPID = new MenuItem();
3243 MenuItem modifyConservation = new MenuItem();
3245 CheckboxMenuItem autoCalculate = null;
3247 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
3248 "Sort Alignment With New Tree", true);
3250 Menu sortByTreeMenu = new Menu();
3252 MenuItem inputText = new MenuItem();
3254 MenuItem documentation = new MenuItem();
3256 MenuItem about = new MenuItem();
3258 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
3260 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
3262 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
3264 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
3266 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
3268 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
3270 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
3272 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
3274 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
3277 * Initialise menus and other items
3281 private void jbInit() throws Exception
3283 setMenuBar(alignFrameMenuBar);
3286 * Configure File menu items and actions
3289 .setLabel(MessageManager.getString("label.input_from_textbox"));
3290 inputText.addActionListener(this);
3291 Menu outputTextboxMenu = new Menu(
3292 MessageManager.getString("label.out_to_textbox"));
3293 for (String ff : FileFormats.getInstance().getWritableFormats(true))
3295 MenuItem item = new MenuItem(ff);
3297 item.addActionListener(new java.awt.event.ActionListener()
3300 public void actionPerformed(ActionEvent e)
3302 outputText_actionPerformed(e);
3306 outputTextboxMenu.add(item);
3308 closeMenuItem.addActionListener(this);
3309 loadApplication.addActionListener(this);
3310 loadTree.addActionListener(this);
3311 loadAnnotations.addActionListener(this);
3312 outputFeatures.addActionListener(this);
3313 outputAnnotations.addActionListener(this);
3316 * Configure Edit menu items and actions
3318 undoMenuItem.setEnabled(false);
3319 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3320 undoMenuItem.addActionListener(this);
3321 redoMenuItem.setEnabled(false);
3322 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3323 redoMenuItem.addActionListener(this);
3324 copy.setLabel(MessageManager.getString("action.copy"));
3325 copy.addActionListener(this);
3326 cut.setLabel(MessageManager.getString("action.cut"));
3327 cut.addActionListener(this);
3328 delete.setLabel(MessageManager.getString("action.delete"));
3329 delete.addActionListener(this);
3330 pasteMenu.setLabel(MessageManager.getString("action.paste"));
3331 pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3332 pasteNew.addActionListener(this);
3333 pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3334 pasteThis.addActionListener(this);
3335 remove2LeftMenuItem.setLabel(MessageManager
3336 .getString("action.remove_left"));
3337 remove2LeftMenuItem.addActionListener(this);
3338 remove2RightMenuItem.setLabel(MessageManager
3339 .getString("action.remove_right"));
3340 remove2RightMenuItem.addActionListener(this);
3341 removeGappedColumnMenuItem.setLabel(MessageManager
3342 .getString("action.remove_empty_columns"));
3343 removeGappedColumnMenuItem.addActionListener(this);
3344 removeAllGapsMenuItem.setLabel(MessageManager
3345 .getString("action.remove_all_gaps"));
3346 removeAllGapsMenuItem.addActionListener(this);
3347 removeRedundancyMenuItem.setLabel(MessageManager
3348 .getString("action.remove_redundancy"));
3349 removeRedundancyMenuItem.addActionListener(this);
3352 * Configure Select menu items and actions
3354 findMenuItem.setLabel(MessageManager.getString("action.find"));
3355 findMenuItem.addActionListener(this);
3356 selectAllSequenceMenuItem.addActionListener(this);
3357 deselectAllSequenceMenuItem.addActionListener(this);
3358 invertSequenceMenuItem.setLabel(MessageManager
3359 .getString("action.invert_sequence_selection"));
3360 invertSequenceMenuItem.addActionListener(this);
3361 invertColSel.setLabel(MessageManager
3362 .getString("action.invert_column_selection"));
3363 invertColSel.addActionListener(this);
3364 deleteGroups.setLabel(MessageManager
3365 .getString("action.undefine_groups"));
3366 deleteGroups.addActionListener(this);
3367 grpsFromSelection.setLabel(MessageManager
3368 .getString("action.make_groups_selection"));
3369 grpsFromSelection.addActionListener(this);
3370 createGroup.setLabel(MessageManager.getString("action.create_group"));
3371 createGroup.addActionListener(this);
3372 unGroup.setLabel(MessageManager.getString("action.remove_group"));
3373 unGroup.addActionListener(this);
3375 annotationColumnSelection.setLabel(MessageManager
3376 .getString("action.select_by_annotation"));
3377 annotationColumnSelection.addActionListener(this);
3380 * Configure View menu items and actions
3382 newView.setLabel(MessageManager.getString("action.new_view"));
3383 newView.addActionListener(this);
3384 Menu showMenu = new Menu(MessageManager.getString("action.show"));
3385 showColumns.setLabel(MessageManager.getString("label.all_columns"));
3386 showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3387 Menu hideMenu = new Menu(MessageManager.getString("action.hide"));
3389 .setLabel(MessageManager.getString("label.selected_columns"));
3390 hideSequences.setLabel(MessageManager
3391 .getString("label.selected_sequences"));
3392 hideAllButSelection.setLabel(MessageManager
3393 .getString("label.all_but_selected_region"));
3394 hideAllSelection.setLabel(MessageManager
3395 .getString("label.selected_region"));
3396 showAllHidden.setLabel(MessageManager
3397 .getString("label.all_sequences_columns"));
3398 showColumns.addActionListener(this);
3399 showSeqs.addActionListener(this);
3400 hideColumns.addActionListener(this);
3401 hideSequences.addActionListener(this);
3402 hideAllButSelection.addActionListener(this);
3403 hideAllSelection.addActionListener(this);
3404 showAllHidden.addActionListener(this);
3405 featureSettings.setLabel(MessageManager
3406 .getString("action.feature_settings"));
3407 featureSettings.addActionListener(this);
3408 sequenceFeatures.setLabel(MessageManager
3409 .getString("label.show_sequence_features"));
3410 sequenceFeatures.addItemListener(this);
3411 sequenceFeatures.setState(false);
3412 followMouseOverFlag.setLabel(MessageManager
3413 .getString("label.automatic_scrolling"));
3414 followMouseOverFlag.addItemListener(this);
3415 alProperties.addActionListener(this);
3416 overviewMenuItem.setLabel(MessageManager
3417 .getString("label.overview_window"));
3418 overviewMenuItem.addActionListener(this);
3421 * Configure Annotations menu items and actions
3423 annotationPanelMenuItem.setLabel(MessageManager
3424 .getString("label.show_annotations"));
3425 annotationPanelMenuItem.addItemListener(this);
3426 showGroupConsensus.setLabel(MessageManager
3427 .getString("label.group_consensus"));
3428 showGroupConservation.setLabel(MessageManager
3429 .getString("label.group_conservation"));
3430 showConsensusHistogram.setLabel(MessageManager
3431 .getString("label.show_consensus_histogram"));
3432 showSequenceLogo.setLabel(MessageManager
3433 .getString("label.show_consensus_logo"));
3434 normSequenceLogo.setLabel(MessageManager
3435 .getString("label.norm_consensus_logo"));
3436 applyAutoAnnotationSettings.setLabel(MessageManager
3437 .getString("label.apply_all_groups"));
3438 applyAutoAnnotationSettings.setState(true);
3439 Menu autoAnnMenu = new Menu(
3440 MessageManager.getString("label.autocalculated_annotation"));
3441 showGroupConsensus.addItemListener(this);
3442 showGroupConservation.addItemListener(this);
3443 showConsensusHistogram.addItemListener(this);
3444 showSequenceLogo.addItemListener(this);
3445 normSequenceLogo.addItemListener(this);
3446 applyAutoAnnotationSettings.addItemListener(this);
3447 showAlignmentAnnotations = new CheckboxMenuItem(
3448 MessageManager.getString("label.show_all_al_annotations"));
3449 showSequenceAnnotations = new CheckboxMenuItem(
3450 MessageManager.getString("label.show_all_seq_annotations"));
3451 sortAnnBySequence = new CheckboxMenuItem(
3452 MessageManager.getString("label.sort_annotations_by_sequence"));
3453 sortAnnByLabel = new CheckboxMenuItem(
3454 MessageManager.getString("label.sort_annotations_by_label"));
3455 showAutoFirst = new CheckboxMenuItem(
3456 MessageManager.getString("label.show_first"));
3457 showAutoFirst.setState(false); // pending applet parameter
3458 setShowAutoCalculatedAbove(showAutoFirst.getState());
3459 showAutoLast = new CheckboxMenuItem(
3460 MessageManager.getString("label.show_last"));
3461 showAutoLast.setState(!showAutoFirst.getState());
3462 showAlignmentAnnotations.addItemListener(this);
3463 showSequenceAnnotations.addItemListener(this);
3464 sortAnnBySequence.addItemListener(this);
3465 sortAnnByLabel.addItemListener(this);
3466 showAutoFirst.addItemListener(this);
3467 showAutoLast.addItemListener(this);
3470 * Configure Format menu items and actions
3472 font.setLabel(MessageManager.getString("action.font"));
3473 font.addActionListener(this);
3474 scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3475 scaleAbove.setState(true);
3476 scaleAbove.setEnabled(false);
3477 scaleAbove.addItemListener(this);
3478 scaleLeft.setEnabled(false);
3479 scaleLeft.setState(true);
3480 scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3481 scaleLeft.addItemListener(this);
3482 scaleRight.setEnabled(false);
3483 scaleRight.setState(true);
3484 scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3485 scaleRight.addItemListener(this);
3486 viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
3487 viewBoxesMenuItem.setState(true);
3488 viewBoxesMenuItem.addItemListener(this);
3489 viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
3490 viewTextMenuItem.setState(true);
3491 viewTextMenuItem.addItemListener(this);
3492 colourTextMenuItem.setLabel(MessageManager
3493 .getString("label.colour_text"));
3494 colourTextMenuItem.addItemListener(this);
3495 displayNonconservedMenuItem.setLabel(MessageManager
3496 .getString("label.show_non_conserved"));
3497 displayNonconservedMenuItem.addItemListener(this);
3498 wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3499 wrapMenuItem.addItemListener(this);
3500 renderGapsMenuItem.setLabel(MessageManager
3501 .getString("action.show_gaps"));
3502 renderGapsMenuItem.setState(true);
3503 renderGapsMenuItem.addItemListener(this);
3504 centreColumnLabelFlag.setLabel(MessageManager
3505 .getString("label.centre_column_labels"));
3506 centreColumnLabelFlag.addItemListener(this);
3507 seqLimits.setState(true);
3508 seqLimits.setLabel(MessageManager
3509 .getString("label.show_sequence_limits"));
3510 seqLimits.addItemListener(this);
3513 * Configure Colour menu items and actions
3515 applyToAllGroups.setLabel(MessageManager
3516 .getString("label.apply_colour_to_all_groups"));
3517 applyToAllGroups.setState(true);
3518 applyToAllGroups.addItemListener(this);
3519 clustalColour.setLabel(MessageManager
3520 .getString("label.colourScheme_clustal"));
3521 clustalColour.addActionListener(this);
3522 zappoColour.setLabel(MessageManager
3523 .getString("label.colourScheme_zappo"));
3524 zappoColour.addActionListener(this);
3525 taylorColour.setLabel(MessageManager
3526 .getString("label.colourScheme_taylor"));
3527 taylorColour.addActionListener(this);
3528 hydrophobicityColour.setLabel(MessageManager
3529 .getString("label.colourScheme_hydrophobic"));
3530 hydrophobicityColour.addActionListener(this);
3531 helixColour.setLabel(MessageManager
3532 .getString("label.colourScheme_helix_propensity"));
3533 helixColour.addActionListener(this);
3534 strandColour.setLabel(MessageManager
3535 .getString("label.colourScheme_strand_propensity"));
3536 strandColour.addActionListener(this);
3537 turnColour.setLabel(MessageManager
3538 .getString("label.colourScheme_turn_propensity"));
3539 turnColour.addActionListener(this);
3540 buriedColour.setLabel(MessageManager
3541 .getString("label.colourScheme_buried_index"));
3542 buriedColour.addActionListener(this);
3543 purinePyrimidineColour.setLabel(MessageManager
3544 .getString("label.colourScheme_purine/pyrimidine"));
3545 purinePyrimidineColour.addActionListener(this);
3546 // RNAInteractionColour.setLabel(MessageManager
3547 // .getString("label.rna_interaction"));
3548 // RNAInteractionColour.addActionListener(this);
3549 RNAHelixColour.setLabel(MessageManager
3550 .getString("label.colourScheme_rna_helices"));
3551 RNAHelixColour.addActionListener(this);
3552 userDefinedColour.setLabel(MessageManager
3553 .getString("action.user_defined"));
3554 userDefinedColour.addActionListener(this);
3555 PIDColour.setLabel(MessageManager
3556 .getString("label.colourScheme_%_identity"));
3557 PIDColour.addActionListener(this);
3558 BLOSUM62Colour.setLabel(MessageManager
3559 .getString("label.colourScheme_blosum62"));
3560 BLOSUM62Colour.addActionListener(this);
3561 tcoffeeColour.setLabel(MessageManager
3562 .getString("label.colourScheme_t-coffee_scores"));
3563 // it will be enabled only if a score file is provided
3564 tcoffeeColour.setEnabled(false);
3565 tcoffeeColour.addActionListener(this);
3566 conservationMenuItem.setLabel(MessageManager
3567 .getString("action.by_conservation"));
3568 conservationMenuItem.addItemListener(this);
3569 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3570 noColourmenuItem.addActionListener(this);
3571 abovePIDThreshold.setLabel(MessageManager
3572 .getString("label.above_identity_threshold"));
3573 abovePIDThreshold.addItemListener(this);
3574 nucleotideColour.setLabel(MessageManager
3575 .getString("label.colourScheme_nucleotide"));
3576 nucleotideColour.addActionListener(this);
3577 modifyPID.setLabel(MessageManager
3578 .getString("label.modify_identity_threshold"));
3579 modifyPID.setEnabled(abovePIDThreshold.getState());
3580 modifyPID.addActionListener(this);
3581 modifyConservation.setLabel(MessageManager
3582 .getString("label.modify_conservation_threshold"));
3583 modifyConservation.setEnabled(conservationMenuItem.getState());
3584 modifyConservation.addActionListener(this);
3585 annotationColour.setLabel(MessageManager
3586 .getString("action.by_annotation"));
3587 annotationColour.addActionListener(this);
3590 * Configure Calculate menu items and actions
3592 sortPairwiseMenuItem.setLabel(MessageManager
3593 .getString("action.by_pairwise_id"));
3594 sortPairwiseMenuItem.addActionListener(this);
3595 sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
3596 sortIDMenuItem.addActionListener(this);
3597 sortLengthMenuItem.setLabel(MessageManager
3598 .getString("action.by_length"));
3599 sortLengthMenuItem.addActionListener(this);
3600 sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3601 sortGroupMenuItem.addActionListener(this);
3602 pairwiseAlignmentMenuItem.setLabel(MessageManager
3603 .getString("action.pairwise_alignment"));
3604 pairwiseAlignmentMenuItem.addActionListener(this);
3605 PCAMenuItem.setLabel(MessageManager
3606 .getString("label.principal_component_analysis"));
3607 PCAMenuItem.addActionListener(this);
3608 autoCalculate = new CheckboxMenuItem(
3609 MessageManager.getString("label.autocalculate_consensus"), true);
3610 averageDistanceTreeMenuItem.setLabel(MessageManager
3611 .getString("label.average_distance_identity"));
3612 averageDistanceTreeMenuItem.addActionListener(this);
3613 neighbourTreeMenuItem.setLabel(MessageManager
3614 .getString("label.neighbour_joining_identity"));
3615 neighbourTreeMenuItem.addActionListener(this);
3616 avDistanceTreeBlosumMenuItem.setLabel(MessageManager
3617 .getString("label.average_distance_blosum62"));
3618 avDistanceTreeBlosumMenuItem.addActionListener(this);
3619 njTreeBlosumMenuItem.setLabel(MessageManager
3620 .getString("label.neighbour_blosum62"));
3621 njTreeBlosumMenuItem.addActionListener(this);
3622 sortByTreeMenu.setLabel(MessageManager
3623 .getString("action.by_tree_order"));
3624 Menu sortMenu = new Menu(MessageManager.getString("action.sort"));
3625 Menu calculateTreeMenu = new Menu(
3626 MessageManager.getString("action.calculate_tree"));
3627 autoCalculate.addItemListener(this);
3628 sortByTree.addItemListener(this);
3631 * Configure Help menu items and actions
3633 Menu helpMenu = new Menu(MessageManager.getString("action.help"));
3634 documentation.setLabel(MessageManager.getString("label.documentation"));
3635 documentation.addActionListener(this);
3636 about.setLabel(MessageManager.getString("label.about"));
3637 about.addActionListener(this);
3640 * Add top level menus to frame
3642 alignFrameMenuBar.add(fileMenu);
3643 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
3644 alignFrameMenuBar.add(editMenu);
3645 Menu selectMenu = new Menu(MessageManager.getString("action.select"));
3646 alignFrameMenuBar.add(selectMenu);
3647 Menu viewMenu = new Menu(MessageManager.getString("action.view"));
3648 alignFrameMenuBar.add(viewMenu);
3649 Menu annotationsMenu = new Menu(
3650 MessageManager.getString("action.annotations"));
3651 alignFrameMenuBar.add(annotationsMenu);
3652 Menu formatMenu = new Menu(MessageManager.getString("action.format"));
3653 alignFrameMenuBar.add(formatMenu);
3654 Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
3655 alignFrameMenuBar.add(colourMenu);
3656 Menu calculateMenu = new Menu(
3657 MessageManager.getString("action.calculate"));
3658 alignFrameMenuBar.add(calculateMenu);
3659 alignFrameMenuBar.add(helpMenu);
3664 fileMenu.add(inputText);
3665 fileMenu.add(loadTree);
3666 fileMenu.add(loadAnnotations);
3667 fileMenu.addSeparator();
3668 fileMenu.add(outputTextboxMenu);
3669 fileMenu.add(outputFeatures);
3670 fileMenu.add(outputAnnotations);
3671 if (jalviewServletURL != null)
3673 fileMenu.add(loadApplication);
3675 fileMenu.addSeparator();
3676 fileMenu.add(closeMenuItem);
3681 editMenu.add(undoMenuItem);
3682 editMenu.add(redoMenuItem);
3685 pasteMenu.add(pasteNew);
3686 pasteMenu.add(pasteThis);
3687 editMenu.add(pasteMenu);
3688 editMenu.add(delete);
3689 editMenu.addSeparator();
3690 editMenu.add(remove2LeftMenuItem);
3691 editMenu.add(remove2RightMenuItem);
3692 editMenu.add(removeGappedColumnMenuItem);
3693 editMenu.add(removeAllGapsMenuItem);
3694 editMenu.add(removeRedundancyMenuItem);
3699 selectMenu.add(findMenuItem);
3700 selectMenu.addSeparator();
3701 selectMenu.add(selectAllSequenceMenuItem);
3702 selectMenu.add(deselectAllSequenceMenuItem);
3703 selectMenu.add(invertSequenceMenuItem);
3704 selectMenu.add(invertColSel);
3705 selectMenu.add(createGroup);
3706 selectMenu.add(unGroup);
3707 selectMenu.add(grpsFromSelection);
3708 selectMenu.add(deleteGroups);
3709 selectMenu.add(annotationColumnSelection);
3714 viewMenu.add(newView);
3715 viewMenu.addSeparator();
3716 showMenu.add(showColumns);
3717 showMenu.add(showSeqs);
3718 showMenu.add(showAllHidden);
3719 viewMenu.add(showMenu);
3720 hideMenu.add(hideColumns);
3721 hideMenu.add(hideSequences);
3722 hideMenu.add(hideAllSelection);
3723 hideMenu.add(hideAllButSelection);
3724 viewMenu.add(hideMenu);
3725 viewMenu.addSeparator();
3726 viewMenu.add(followMouseOverFlag);
3727 viewMenu.addSeparator();
3728 viewMenu.add(sequenceFeatures);
3729 viewMenu.add(featureSettings);
3730 viewMenu.addSeparator();
3731 viewMenu.add(alProperties);
3732 viewMenu.addSeparator();
3733 viewMenu.add(overviewMenuItem);
3738 annotationsMenu.add(annotationPanelMenuItem);
3739 annotationsMenu.addSeparator();
3740 annotationsMenu.add(showAlignmentAnnotations);
3741 annotationsMenu.add(showSequenceAnnotations);
3742 annotationsMenu.add(sortAnnBySequence);
3743 annotationsMenu.add(sortAnnByLabel);
3744 annotationsMenu.addSeparator();
3745 autoAnnMenu.add(showAutoFirst);
3746 autoAnnMenu.add(showAutoLast);
3747 autoAnnMenu.addSeparator();
3748 autoAnnMenu.add(applyAutoAnnotationSettings);
3749 autoAnnMenu.add(showConsensusHistogram);
3750 autoAnnMenu.add(showSequenceLogo);
3751 autoAnnMenu.add(normSequenceLogo);
3752 autoAnnMenu.addSeparator();
3753 autoAnnMenu.add(showGroupConservation);
3754 autoAnnMenu.add(showGroupConsensus);
3755 annotationsMenu.add(autoAnnMenu);
3760 formatMenu.add(font);
3761 formatMenu.add(seqLimits);
3762 formatMenu.add(wrapMenuItem);
3763 formatMenu.add(scaleAbove);
3764 formatMenu.add(scaleLeft);
3765 formatMenu.add(scaleRight);
3766 formatMenu.add(viewBoxesMenuItem);
3767 formatMenu.add(viewTextMenuItem);
3768 formatMenu.add(colourTextMenuItem);
3769 formatMenu.add(displayNonconservedMenuItem);
3770 formatMenu.add(renderGapsMenuItem);
3771 formatMenu.add(centreColumnLabelFlag);
3776 colourMenu.add(applyToAllGroups);
3777 colourMenu.addSeparator();
3778 colourMenu.add(noColourmenuItem);
3779 colourMenu.add(clustalColour);
3780 colourMenu.add(BLOSUM62Colour);
3781 colourMenu.add(PIDColour);
3782 colourMenu.add(zappoColour);
3783 colourMenu.add(taylorColour);
3784 colourMenu.add(hydrophobicityColour);
3785 colourMenu.add(helixColour);
3786 colourMenu.add(strandColour);
3787 colourMenu.add(turnColour);
3788 colourMenu.add(buriedColour);
3789 colourMenu.add(nucleotideColour);
3790 colourMenu.add(purinePyrimidineColour);
3791 // colourMenu.add(RNAInteractionColour);
3792 colourMenu.add(tcoffeeColour);
3793 colourMenu.add(userDefinedColour);
3794 colourMenu.addSeparator();
3795 colourMenu.add(conservationMenuItem);
3796 colourMenu.add(modifyConservation);
3797 colourMenu.add(abovePIDThreshold);
3798 colourMenu.add(modifyPID);
3799 colourMenu.add(annotationColour);
3800 colourMenu.add(RNAHelixColour);
3805 sortMenu.add(sortIDMenuItem);
3806 sortMenu.add(sortLengthMenuItem);
3807 sortMenu.add(sortByTreeMenu);
3808 sortMenu.add(sortGroupMenuItem);
3809 sortMenu.add(sortPairwiseMenuItem);
3810 calculateMenu.add(sortMenu);
3811 calculateTreeMenu.add(averageDistanceTreeMenuItem);
3812 calculateTreeMenu.add(neighbourTreeMenuItem);
3813 calculateTreeMenu.add(avDistanceTreeBlosumMenuItem);
3814 calculateTreeMenu.add(njTreeBlosumMenuItem);
3815 calculateMenu.add(calculateTreeMenu);
3816 calculateMenu.addSeparator();
3817 calculateMenu.add(pairwiseAlignmentMenuItem);
3818 calculateMenu.add(PCAMenuItem);
3819 calculateMenu.add(autoCalculate);
3820 calculateMenu.add(sortByTree);
3825 helpMenu.add(documentation);
3826 helpMenu.add(about);
3831 statusBar.setBackground(Color.white);
3832 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3833 statusBar.setText(MessageManager.getString("label.status_bar"));
3834 this.add(statusBar, BorderLayout.SOUTH);
3838 public void setStatus(String string)
3840 statusBar.setText(string);
3843 MenuItem featureSettings = new MenuItem();
3845 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3847 MenuItem annotationColour = new MenuItem();
3849 MenuItem annotationColumnSelection = new MenuItem();
3851 MenuItem invertColSel = new MenuItem();
3853 MenuItem showColumns = new MenuItem();
3855 MenuItem showSeqs = new MenuItem();
3857 MenuItem hideColumns = new MenuItem();
3859 MenuItem hideSequences = new MenuItem();
3861 MenuItem hideAllButSelection = new MenuItem();
3863 MenuItem hideAllSelection = new MenuItem();
3865 MenuItem showAllHidden = new MenuItem();
3867 MenuItem newView = new MenuItem();
3869 private CheckboxMenuItem showAlignmentAnnotations;
3871 private CheckboxMenuItem showSequenceAnnotations;
3873 private CheckboxMenuItem sortAnnBySequence;
3875 private CheckboxMenuItem sortAnnByLabel;
3877 private CheckboxMenuItem showAutoFirst;
3879 private CheckboxMenuItem showAutoLast;
3881 private SplitFrame splitFrame;
3884 * Attach the alignFrame panels after embedding menus, if necessary. This used
3885 * to be called setEmbedded, but is now creates the dropdown menus in a
3886 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3888 * @param reallyEmbedded
3889 * true to attach the view to the applet area on the page rather than
3892 public void createAlignFrameWindow(boolean reallyEmbedded)
3896 embedAlignFrameInApplet(viewport.applet);
3901 // test and embed menu bar if necessary.
3903 if (embedMenuIfNeeded(alignPanel))
3906 * adjust for status bar height too. ? pointless as overridden by layout
3909 alignPanel.setSize(getSize().width,
3910 getSize().height - statusBar.getHeight());
3912 add(statusBar, BorderLayout.SOUTH);
3913 add(alignPanel, BorderLayout.CENTER);
3914 // and register with the applet so it can pass external API calls to us
3915 jalview.bin.JalviewLite.addFrame(this, this.getTitle(), frameWidth,
3921 * Add the components of this AlignFrame to the applet container.
3925 public void embedAlignFrameInApplet(final JalviewLite theApplet)
3928 // Explicitly build the embedded menu panel for the on-page applet
3930 // view cannot be closed if its actually on the page
3931 fileMenu.remove(closeMenuItem);
3932 fileMenu.remove(3); // Remove Separator
3933 // construct embedded menu, using default font
3934 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
3935 // and actually add the components to the applet area
3936 theApplet.setLayout(new BorderLayout());
3937 theApplet.add(embeddedMenu, BorderLayout.NORTH);
3938 theApplet.add(statusBar, BorderLayout.SOUTH);
3939 // TODO should size be left to the layout manager?
3940 alignPanel.setSize(theApplet.getSize().width,
3941 theApplet.getSize().height - embeddedMenu.getHeight()
3942 - statusBar.getHeight());
3943 theApplet.add(alignPanel, BorderLayout.CENTER);
3944 final AlignFrame me = this;
3945 theApplet.addFocusListener(new FocusListener()
3949 public void focusLost(FocusEvent e)
3951 if (theApplet.currentAlignFrame == me)
3953 theApplet.currentAlignFrame = null;
3958 public void focusGained(FocusEvent e)
3960 theApplet.currentAlignFrame = me;
3963 theApplet.validate();
3967 * create a new binding between structures in an existing jmol viewer instance
3968 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3969 * this does not open a new Jmol window, or modify the display of the
3970 * structures in the original jmol window. Note This method doesn't work
3971 * without an additional javascript library to exchange messages between the
3972 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3975 * JmolViewer instance
3976 * @param sequenceIds
3977 * - sequence Ids to search for associations
3979 public SequenceStructureBinding addStructureViewInstance(
3980 Object jmolviewer, String[] sequenceIds)
3982 Viewer viewer = null;
3985 viewer = (Viewer) jmolviewer;
3986 } catch (ClassCastException ex)
3988 System.err.println("Unsupported viewer object :"
3989 + jmolviewer.getClass());
3993 System.err.println("Can't use this object as a structure viewer:"
3994 + jmolviewer.getClass());
3997 SequenceI[] seqs = null;
3998 if (sequenceIds == null || sequenceIds.length == 0)
4000 seqs = viewport.getAlignment().getSequencesArray();
4004 Vector sqi = new Vector();
4005 AlignmentI al = viewport.getAlignment();
4006 for (int sid = 0; sid < sequenceIds.length; sid++)
4008 SequenceI sq = al.findName(sequenceIds[sid]);
4016 seqs = new SequenceI[sqi.size()];
4017 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
4019 seqs[sid] = (SequenceI) sqi.elementAt(sid);
4027 AAStructureBindingModel jmv = null;
4028 // TODO: search for a jmv that involves viewer
4030 { // create a new viewer/jalview binding.
4031 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] { seqs });
4038 * bind a pdb file to a sequence in the current view
4041 * - sequenceId within the dataset.
4042 * @param pdbEntryString
4043 * - the short name for the PDB file
4045 * - pdb file - either a URL or a valid PDB file.
4046 * @return true if binding was as success TODO: consider making an exception
4047 * structure for indicating when PDB parsing or sequenceId location
4050 public boolean addPdbFile(String sequenceId, String pdbEntryString,
4053 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
4054 boolean needtoadd = false;
4055 if (toaddpdb != null)
4057 Vector pdbe = toaddpdb.getAllPDBEntries();
4058 PDBEntry pdbentry = null;
4059 if (pdbe != null && pdbe.size() > 0)
4061 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
4063 pdbentry = (PDBEntry) pdbe.elementAt(pe);
4064 if (!pdbentry.getId().equals(pdbEntryString)
4065 && !pdbentry.getFile().equals(pdbFile))
4075 if (pdbentry == null)
4077 pdbentry = new PDBEntry();
4078 pdbentry.setId(pdbEntryString);
4079 pdbentry.setFile(pdbFile);
4080 needtoadd = true; // add this new entry to sequence.
4082 // resolve data source
4083 // TODO: this code should be a refactored to an io package
4084 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(
4085 pdbFile, FileFormat.PDB);
4086 if (protocol == null)
4092 pdbentry.setProperty("protocol", protocol);
4093 toaddpdb.addPDBId(pdbentry);
4094 alignPanel.getStructureSelectionManager()
4095 .registerPDBEntry(pdbentry);
4101 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
4105 Vector sequences = new Vector();
4106 for (int i = 0; i < seqs.length; i++)
4108 if (seqs[i] != null)
4110 sequences.addElement(new Object[] { seqs[i],
4111 (chains != null) ? chains[i] : null });
4114 seqs = new SequenceI[sequences.size()];
4115 chains = new String[sequences.size()];
4116 for (int i = 0, isize = sequences.size(); i < isize; i++)
4118 Object[] oj = (Object[]) sequences.elementAt(i);
4120 seqs[i] = (SequenceI) oj[0];
4121 chains[i] = (String) oj[1];
4124 return new Object[] { seqs, chains };
4128 public void newStructureView(JalviewLite applet, PDBEntry pdb,
4129 SequenceI[] seqs, String[] chains, DataSourceType protocol)
4131 // Scrub any null sequences from the array
4132 Object[] sqch = cleanSeqChainArrays(seqs, chains);
4133 seqs = (SequenceI[]) sqch[0];
4134 chains = (String[]) sqch[1];
4135 if (seqs == null || seqs.length == 0)
4138 .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
4140 if (protocol == null)
4142 String sourceType = (String) pdb.getProperty("protocol");
4145 protocol = DataSourceType.valueOf(sourceType);
4146 } catch (IllegalArgumentException e)
4150 if (protocol == null)
4152 System.err.println("Couldn't work out protocol to open structure: "
4157 if (applet.useXtrnalSviewer)
4159 // register the association(s) and quit, don't create any windows.
4160 if (StructureSelectionManager.getStructureSelectionManager(applet)
4161 .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
4163 System.err.println("Failed to map " + pdb.getFile() + " ("
4164 + protocol + ") to any sequences");
4168 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
4170 // can only do alignments with Jmol
4171 // find the last jmol window assigned to this alignment
4172 AppletJmol ajm = null, tajm;
4173 Vector jmols = applet.getAppletWindow(AppletJmol.class);
4174 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
4176 tajm = (AppletJmol) jmols.elementAt(i);
4177 if (tajm.ap.alignFrame == this)
4186 .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
4187 // try and add the pdb structure
4192 // otherwise, create a new window
4193 if (applet.jmolAvailable)
4195 new AppletJmol(pdb, seqs, chains, alignPanel,
4197 applet.lastFrameX += 40;
4198 applet.lastFrameY += 40;
4202 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
4207 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
4208 SequenceI[][] seqs, String[][] chains, String[] protocols)
4210 // TODO Auto-generated method stub
4211 System.err.println("Aligned Structure View: Not yet implemented.");
4215 * modify the current selection, providing the user has not made a selection
4219 * - sequences from this alignment
4221 * - columns to be selected on the alignment
4223 public void select(SequenceGroup sel, ColumnSelection csel,
4224 HiddenColumns hidden)
4226 alignPanel.seqPanel.selection(sel, csel, hidden, null);
4229 public void scrollTo(int row, int column)
4231 alignPanel.seqPanel.scrollTo(row, column);
4234 public void scrollToRow(int row)
4236 alignPanel.seqPanel.scrollToRow(row);
4239 public void scrollToColumn(int column)
4241 alignPanel.seqPanel.scrollToColumn(column);
4245 * @return the alignments unique ID.
4247 public String getSequenceSetId()
4249 return viewport.getSequenceSetId();
4253 * Load the (T-Coffee) score file from the specified url
4256 * File/URL/T-COFFEE score file contents
4257 * @throws IOException
4258 * @return true if alignment was annotated with data from source
4260 public boolean loadScoreFile(String source) throws IOException
4263 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
4264 AppletFormatAdapter.checkProtocol(source));
4265 if (!file.isValid())
4267 // TODO: raise dialog for gui
4268 System.err.println("Problems parsing T-Coffee scores: "
4269 + file.getWarningMessage());
4270 System.err.println("Origin was:\n" + source);
4275 * check that the score matrix matches the alignment dimensions
4278 if ((aln = viewport.getAlignment()) != null
4279 && (aln.getHeight() != file.getHeight() || aln.getWidth() != file
4282 // TODO: raise a dialog box here rather than bomb out.
4284 .println("The scores matrix does not match the alignment dimensions");
4288 // TODO add parameter to indicate if matching should be done
4289 if (file.annotateAlignment(alignPanel.getAlignment(), false))
4291 alignPanel.fontChanged();
4292 tcoffeeColour.setEnabled(true);
4293 // switch to this color
4294 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4299 System.err.println("Problems resolving T-Coffee scores:");
4300 if (file.getWarningMessage() != null)
4302 System.err.println(file.getWarningMessage());
4308 public SplitFrame getSplitFrame()
4310 return this.splitFrame;
4313 public void setSplitFrame(SplitFrame sf)
4315 this.splitFrame = sf;
4318 // may not need this
4320 public void setShowSeqFeatures(boolean b)
4322 // showSeqFeatures.setSelected(b);
4323 viewport.setShowSequenceFeatures(b);
4328 public void setMenusForViewport()
4330 // setMenusFromViewport(viewport);
4335 public void refreshFeatureUI(boolean enableIfNecessary)
4337 if (enableIfNecessary)
4339 sequenceFeatures.setState(true);
4340 alignPanel.av.setShowSequenceFeatures(true);
4345 public FeatureSettingsControllerI getFeatureSettingsUI()
4347 return alignPanel.av.featureSettings;