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.PDBEntry;
50 import jalview.datamodel.Sequence;
51 import jalview.datamodel.SequenceGroup;
52 import jalview.datamodel.SequenceI;
53 import jalview.io.AnnotationFile;
54 import jalview.io.AppletFormatAdapter;
55 import jalview.io.DataSourceType;
56 import jalview.io.FeaturesFile;
57 import jalview.io.FileFormat;
58 import jalview.io.FileFormatI;
59 import jalview.io.FileFormats;
60 import jalview.io.TCoffeeScoreFile;
61 import jalview.schemes.Blosum62ColourScheme;
62 import jalview.schemes.BuriedColourScheme;
63 import jalview.schemes.ClustalxColourScheme;
64 import jalview.schemes.ColourSchemeI;
65 import jalview.schemes.HelixColourScheme;
66 import jalview.schemes.HydrophobicColourScheme;
67 import jalview.schemes.NucleotideColourScheme;
68 import jalview.schemes.PIDColourScheme;
69 import jalview.schemes.PurinePyrimidineColourScheme;
70 import jalview.schemes.RNAHelicesColour;
71 import jalview.schemes.StrandColourScheme;
72 import jalview.schemes.TCoffeeColourScheme;
73 import jalview.schemes.TaylorColourScheme;
74 import jalview.schemes.TurnColourScheme;
75 import jalview.schemes.ZappoColourScheme;
76 import jalview.structure.StructureSelectionManager;
77 import jalview.structures.models.AAStructureBindingModel;
78 import jalview.util.MappingUtils;
79 import jalview.util.MessageManager;
80 import jalview.viewmodel.AlignmentViewport;
81 import jalview.viewmodel.ViewportRanges;
83 import java.awt.BorderLayout;
84 import java.awt.Canvas;
85 import java.awt.CheckboxMenuItem;
86 import java.awt.Color;
87 import java.awt.FlowLayout;
89 import java.awt.FontMetrics;
90 import java.awt.Frame;
91 import java.awt.Graphics;
92 import java.awt.Label;
94 import java.awt.MenuBar;
95 import java.awt.MenuItem;
96 import java.awt.Panel;
97 import java.awt.event.ActionEvent;
98 import java.awt.event.ActionListener;
99 import java.awt.event.FocusEvent;
100 import java.awt.event.FocusListener;
101 import java.awt.event.ItemEvent;
102 import java.awt.event.ItemListener;
103 import java.awt.event.KeyEvent;
104 import java.awt.event.KeyListener;
105 import java.awt.event.WindowAdapter;
106 import java.awt.event.WindowEvent;
107 import java.io.IOException;
109 import java.net.URLEncoder;
110 import java.util.Arrays;
111 import java.util.Deque;
112 import java.util.HashMap;
113 import java.util.List;
114 import java.util.Map;
115 import java.util.StringTokenizer;
116 import java.util.Vector;
118 import org.jmol.viewer.Viewer;
120 public class AlignFrame extends EmbmenuFrame implements ActionListener,
121 ItemListener, KeyListener, AlignViewControllerGuiI
123 public AlignViewControllerI avc;
125 public AlignmentPanel alignPanel;
127 public AlignViewport viewport;
129 // width and height may be overridden by applet parameters
130 int frameWidth = 700;
132 int frameHeight = 500;
134 String jalviewServletURL;
137 * Flag for showing autocalculated consensus above or below other consensus
140 private boolean showAutoCalculatedAbove;
142 private SequenceAnnotationOrder annotationSortOrder;
145 * Constructor that creates the frame and adds it to the display.
152 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
155 this(al, applet, title, embedded, true);
159 * Constructor that optionally allows the frame to be displayed or only
166 * @param addToDisplay
168 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
169 boolean embedded, boolean addToDisplay)
171 this(al, null, null, applet, title, embedded, addToDisplay);
174 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
175 ColumnSelection columnSelection, JalviewLite applet,
176 String title, boolean embedded)
178 this(al, hiddenSeqs, columnSelection, applet, title, embedded, true);
181 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
182 ColumnSelection columnSelection, JalviewLite applet,
183 String title, boolean embedded, boolean addToDisplay)
187 jalviewServletURL = applet.getParameter("APPLICATION_URL");
193 } catch (Exception ex)
195 ex.printStackTrace();
197 // need to get window geometry before we calculate alignment layout
203 param = applet.getParameter("windowWidth");
206 int width = Integer.parseInt(param);
209 param = applet.getParameter("windowHeight");
212 int height = Integer.parseInt(param);
213 frameHeight = height;
215 } catch (Exception ex)
219 viewport = new AlignViewport(al, applet);
221 if (hiddenSeqs != null && hiddenSeqs.length > 0)
223 viewport.hideSequence(hiddenSeqs);
225 if (columnSelection != null)
227 viewport.setColumnSelection(columnSelection);
229 viewport.setScaleAboveWrapped(scaleAbove.getState());
231 alignPanel = new AlignmentPanel(this, viewport);
232 avc = new jalview.controller.AlignViewController(this, viewport,
234 viewport.updateConservation(alignPanel);
235 viewport.updateConsensus(alignPanel);
237 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
238 followMouseOverFlag.setState(viewport.isFollowHighlight());
239 showGroupConsensus.setState(viewport.isShowGroupConsensus());
240 showGroupConservation.setState(viewport.isShowGroupConservation());
241 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
242 showSequenceLogo.setState(viewport.isShowSequenceLogo());
243 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
244 applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
245 annotationPanelMenuItem.setState(viewport.isShowAnnotation());
246 showAlignmentAnnotations.setEnabled(annotationPanelMenuItem.getState());
247 showSequenceAnnotations.setEnabled(annotationPanelMenuItem.getState());
248 showAlignmentAnnotations.setState(true);
249 showSequenceAnnotations.setState(false);
251 seqLimits.setState(viewport.getShowJVSuffix());
255 String param = applet.getParameter("sortBy");
258 if (param.equalsIgnoreCase("Id"))
260 sortIDMenuItem_actionPerformed();
262 else if (param.equalsIgnoreCase("Pairwise Identity"))
264 sortPairwiseMenuItem_actionPerformed();
266 else if (param.equalsIgnoreCase("Length"))
268 sortLengthMenuItem_actionPerformed();
272 param = applet.getParameter("wrap");
275 if (param.equalsIgnoreCase("true"))
277 wrapMenuItem.setState(true);
278 wrapMenuItem_actionPerformed();
281 param = applet.getParameter("centrecolumnlabels");
284 centreColumnLabelFlag.setState(true);
285 centreColumnLabelFlag_stateChanged();
289 if (viewport.getAlignment().isNucleotide())
291 conservationMenuItem.setEnabled(false);
292 clustalColour.setEnabled(false);
293 BLOSUM62Colour.setEnabled(false);
294 zappoColour.setEnabled(false);
295 taylorColour.setEnabled(false);
296 hydrophobicityColour.setEnabled(false);
297 helixColour.setEnabled(false);
298 strandColour.setEnabled(false);
299 turnColour.setEnabled(false);
300 buriedColour.setEnabled(false);
301 viewport.updateStrucConsensus(alignPanel);
302 if (viewport.getAlignment().hasRNAStructure())
304 RNAHelixColour.setEnabled(true);
308 RNAHelixColour.setEnabled(false);
313 RNAHelixColour.setEnabled(false);
314 purinePyrimidineColour.setEnabled(false);
315 nucleotideColour.setEnabled(false);
317 // Some JVMS send keyevents to Top frame or lowest panel,
318 // Havent worked out why yet. So add to both this frame and seqCanvas for
320 this.addKeyListener(this);
321 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
322 alignPanel.idPanel.idCanvas.addKeyListener(this);
323 alignPanel.scalePanel.addKeyListener(this);
324 alignPanel.annotationPanel.addKeyListener(this);
325 alignPanel.annotationPanelHolder.addKeyListener(this);
326 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
327 alignPanel.alabels.addKeyListener(this);
329 setAnnotationsVisibility();
333 addToDisplay(embedded);
340 public void addToDisplay(boolean embedded)
342 createAlignFrameWindow(embedded);
344 alignPanel.adjustAnnotationHeight();
345 alignPanel.paintAlignment(true);
348 public AlignViewport getAlignViewport()
353 public SeqCanvas getSeqcanvas()
355 return alignPanel.seqPanel.seqCanvas;
359 * Load a features file onto the alignment
362 * file URL, content, or other resolvable path
364 * is protocol for accessing data referred to by file
367 public boolean parseFeaturesFile(String file, DataSourceType type)
369 return parseFeaturesFile(file, type, true);
373 * Load a features file onto the alignment
376 * file URL, content, or other resolvable path
378 * is protocol for accessing data referred to by file
379 * @param autoenabledisplay
380 * when true, display features flag will be automatically enabled if
381 * features are loaded
382 * @return true if data parsed as a features file
384 public boolean parseFeaturesFile(String file, DataSourceType sourceType,
385 boolean autoenabledisplay)
387 boolean featuresFile = false;
390 Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
391 .getFeatureRenderer().getFeatureColours();
392 boolean relaxedIdMatching = viewport.applet.getDefaultParameter(
393 "relaxedidmatch", false);
394 featuresFile = new FeaturesFile(file, sourceType).parse(
395 viewport.getAlignment(), colours, true, relaxedIdMatching);
396 } catch (Exception ex)
398 ex.printStackTrace();
403 if (autoenabledisplay)
405 viewport.setShowSequenceFeatures(true);
406 sequenceFeatures.setState(true);
408 if (alignPanel.seqPanel.seqCanvas.fr != null)
410 // update the min/max ranges where necessary
411 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
413 if (viewport.featureSettings != null)
415 viewport.featureSettings.refreshTable();
417 alignPanel.paintAlignment(true);
418 statusBar.setText(MessageManager
419 .getString("label.successfully_added_features_alignment"));
425 public void keyPressed(KeyEvent evt)
427 ViewportRanges ranges = viewport.getRanges();
429 if (viewport.cursorMode
430 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
431 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
432 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
433 && Character.isDigit(evt.getKeyChar()))
435 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
438 switch (evt.getKeyCode())
440 case 27: // escape key
441 deselectAllSequenceMenuItem_actionPerformed();
443 alignPanel.alabels.cancelDrag();
446 if (evt.isControlDown() || evt.isMetaDown())
448 cut_actionPerformed();
452 if (viewport.cursorMode && !evt.isControlDown())
454 alignPanel.seqPanel.setCursorColumn();
456 if (evt.isControlDown() || evt.isMetaDown())
458 copy_actionPerformed();
462 if (evt.isControlDown())
464 paste(evt.isShiftDown());
468 if (evt.isControlDown() || evt.isMetaDown())
470 selectAllSequenceMenuItem_actionPerformed();
473 case KeyEvent.VK_DOWN:
474 if (viewport.cursorMode)
476 alignPanel.seqPanel.moveCursor(0, 1);
480 moveSelectedSequences(false);
485 if (viewport.cursorMode)
487 alignPanel.seqPanel.moveCursor(0, -1);
491 moveSelectedSequences(true);
495 case KeyEvent.VK_LEFT:
496 if (evt.isAltDown() || !viewport.cursorMode)
498 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
502 alignPanel.seqPanel.moveCursor(-1, 0);
506 case KeyEvent.VK_RIGHT:
507 if (evt.isAltDown() || !viewport.cursorMode)
509 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
513 alignPanel.seqPanel.moveCursor(1, 0);
517 case KeyEvent.VK_SPACE:
518 if (viewport.cursorMode)
520 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
521 || evt.isShiftDown() || evt.isAltDown());
525 case KeyEvent.VK_DELETE:
526 case KeyEvent.VK_BACK_SPACE:
527 if (viewport.cursorMode)
529 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
530 || evt.isShiftDown() || evt.isAltDown());
534 cut_actionPerformed();
535 alignPanel.seqPanel.seqCanvas.repaint();
540 if (viewport.cursorMode)
542 alignPanel.seqPanel.setCursorRow();
546 if (viewport.cursorMode)
548 alignPanel.seqPanel.setCursorPosition();
552 case KeyEvent.VK_ENTER:
553 case KeyEvent.VK_COMMA:
554 if (viewport.cursorMode)
556 alignPanel.seqPanel.setCursorRowAndColumn();
561 if (viewport.cursorMode)
563 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
567 if (viewport.cursorMode)
569 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
574 viewport.cursorMode = !viewport.cursorMode;
575 statusBar.setText(MessageManager.formatMessage(
576 "label.keyboard_editing_mode",
577 new String[] { (viewport.cursorMode ? "on" : "off") }));
578 if (viewport.cursorMode)
580 alignPanel.seqPanel.seqCanvas.cursorX = ranges.getStartRes();
581 alignPanel.seqPanel.seqCanvas.cursorY = ranges.getStartSeq();
586 if (evt.isControlDown())
588 findMenuItem_actionPerformed();
594 boolean toggleSeqs = !evt.isControlDown();
595 boolean toggleCols = !evt.isShiftDown();
596 toggleHiddenRegions(toggleSeqs, toggleCols);
600 case KeyEvent.VK_PAGE_UP:
601 if (viewport.getWrapAlignment())
603 alignPanel.scrollUp(true);
607 alignPanel.setScrollValues(ranges.getStartRes(),
608 2 * ranges.getStartSeq() - ranges.getEndSeq());
612 case KeyEvent.VK_PAGE_DOWN:
613 if (viewport.getWrapAlignment())
615 alignPanel.scrollUp(false);
620 .setScrollValues(ranges.getStartRes(), ranges.getEndSeq());
625 if (evt.isControlDown())
627 undoMenuItem_actionPerformed();
632 if (evt.isControlDown())
634 redoMenuItem_actionPerformed();
639 if (evt.isControlDown())
646 if (evt.isControlDown())
648 trimAlignment(false);
653 if (evt.isControlDown())
655 if (evt.isShiftDown())
657 this.removeAllGapsMenuItem_actionPerformed();
661 removeGappedColumnMenuItem_actionPerformed();
666 if (evt.isControlDown())
670 invertColSel_actionPerformed();
674 invertSequenceMenuItem_actionPerformed();
680 if (evt.isControlDown())
682 if (evt.isShiftDown())
684 this.unGroup_actionPerformed();
688 this.createGroup_actionPerformed();
694 if (evt.isControlDown())
696 this.deleteGroups_actionPerformed();
701 if (evt.isControlDown())
708 alignPanel.paintAlignment(true);
712 * called by key handler and the hide all/show all menu items
717 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
719 boolean hide = false;
720 SequenceGroup sg = viewport.getSelectionGroup();
721 if (!toggleSeqs && !toggleCols)
723 // Hide everything by the current selection - this is a hack - we do the
724 // invert and then hide
725 // first check that there will be visible columns after the invert.
726 if (viewport.hasSelectedColumns()
727 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
730 // now invert the sequence set, if required - empty selection implies
731 // that no hiding is required.
734 invertSequenceMenuItem_actionPerformed();
735 sg = viewport.getSelectionGroup();
739 viewport.expandColSelection(sg, true);
740 // finally invert the column selection and get the new sequence
741 // selection and indicate it should be hidden.
742 invertColSel_actionPerformed();
749 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
752 viewport.hideAllSelectedSeqs();
754 else if (!(toggleCols && viewport.hasSelectedColumns()))
756 viewport.showAllHiddenSeqs();
762 if (viewport.hasSelectedColumns())
764 viewport.hideSelectedColumns();
767 viewport.setSelectionGroup(sg);
772 viewport.showAllHiddenColumns();
774 viewport.sendSelection();
779 public void keyReleased(KeyEvent evt)
784 public void keyTyped(KeyEvent evt)
789 public void itemStateChanged(ItemEvent evt)
791 final Object source = evt.getSource();
792 if (source == displayNonconservedMenuItem)
794 displayNonconservedMenuItem_actionPerformed();
796 else if (source == colourTextMenuItem)
798 colourTextMenuItem_actionPerformed();
800 else if (source == wrapMenuItem)
802 wrapMenuItem_actionPerformed();
804 else if (source == scaleAbove)
806 viewport.setScaleAboveWrapped(scaleAbove.getState());
808 else if (source == scaleLeft)
810 viewport.setScaleLeftWrapped(scaleLeft.getState());
812 else if (source == scaleRight)
814 viewport.setScaleRightWrapped(scaleRight.getState());
816 else if (source == seqLimits)
818 seqLimits_itemStateChanged();
820 else if (source == viewBoxesMenuItem)
822 viewport.setShowBoxes(viewBoxesMenuItem.getState());
824 else if (source == viewTextMenuItem)
826 viewport.setShowText(viewTextMenuItem.getState());
828 else if (source == renderGapsMenuItem)
830 viewport.setRenderGaps(renderGapsMenuItem.getState());
832 else if (source == annotationPanelMenuItem)
834 boolean showAnnotations = annotationPanelMenuItem.getState();
835 showAlignmentAnnotations.setEnabled(showAnnotations);
836 showSequenceAnnotations.setEnabled(showAnnotations);
837 viewport.setShowAnnotation(showAnnotations);
838 alignPanel.setAnnotationVisible(showAnnotations);
840 else if (source == sequenceFeatures)
842 viewport.setShowSequenceFeatures(sequenceFeatures.getState());
843 alignPanel.seqPanel.seqCanvas.repaint();
845 else if (source == showAlignmentAnnotations)
847 setAnnotationsVisibility();
849 else if (source == showSequenceAnnotations)
851 setAnnotationsVisibility();
853 else if (source == sortAnnBySequence)
855 boolean newState = sortAnnBySequence.getState();
856 sortAnnByLabel.setState(false);
857 setAnnotationSortOrder(newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
858 : SequenceAnnotationOrder.NONE);
859 setViewportAnnotationOrder();
861 else if (source == sortAnnByLabel)
863 boolean newState = sortAnnByLabel.getState();
864 sortAnnBySequence.setState(false);
865 setAnnotationSortOrder(newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
866 : SequenceAnnotationOrder.NONE);
867 setViewportAnnotationOrder();
869 else if (source == showAutoFirst)
871 showAutoLast.setState(!showAutoFirst.getState());
872 setShowAutoCalculatedAbove(showAutoFirst.getState());
873 setViewportAnnotationOrder();
875 else if (source == showAutoLast)
877 showAutoFirst.setState(!showAutoLast.getState());
878 setShowAutoCalculatedAbove(showAutoFirst.getState());
879 setViewportAnnotationOrder();
881 else if (source == conservationMenuItem)
883 conservationMenuItem_actionPerformed();
885 else if (source == abovePIDThreshold)
887 abovePIDThreshold_actionPerformed();
889 else if (source == applyToAllGroups)
891 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
893 else if (source == autoCalculate)
895 viewport.autoCalculateConsensus = autoCalculate.getState();
897 else if (source == sortByTree)
899 viewport.sortByTree = sortByTree.getState();
901 else if (source == this.centreColumnLabelFlag)
903 centreColumnLabelFlag_stateChanged();
905 else if (source == this.followMouseOverFlag)
907 mouseOverFlag_stateChanged();
909 else if (source == showGroupConsensus)
911 showGroupConsensus_actionPerformed();
913 else if (source == showGroupConservation)
915 showGroupConservation_actionPerformed();
917 else if (source == showSequenceLogo)
919 showSequenceLogo_actionPerformed();
921 else if (source == normSequenceLogo)
923 normSequenceLogo_actionPerformed();
925 else if (source == showConsensusHistogram)
927 showConsensusHistogram_actionPerformed();
929 else if (source == applyAutoAnnotationSettings)
931 applyAutoAnnotationSettings_actionPerformed();
933 alignPanel.paintAlignment(true);
937 * Set the visibility state of sequence-related and/or alignment-related
938 * annotations depending on checkbox selections, and repaint.
942 private void setAnnotationsVisibility()
944 boolean showForAlignment = showAlignmentAnnotations.getState();
945 boolean showForSequences = showSequenceAnnotations.getState();
946 if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
948 for (AlignmentAnnotation aa : alignPanel.getAlignment()
949 .getAlignmentAnnotation())
951 boolean visible = (aa.sequenceRef == null ? showForAlignment
953 aa.visible = visible;
956 alignPanel.validateAnnotationDimensions(true);
961 private void setAnnotationSortOrder(SequenceAnnotationOrder order)
963 this.annotationSortOrder = order;
967 * Set flags on the viewport that control annotation ordering
969 private void setViewportAnnotationOrder()
971 this.alignPanel.av.setSortAnnotationsBy(this.annotationSortOrder);
973 .setShowAutocalculatedAbove(this.showAutoCalculatedAbove);
976 private void setShowAutoCalculatedAbove(boolean showAbove)
978 this.showAutoCalculatedAbove = showAbove;
981 private void mouseOverFlag_stateChanged()
983 viewport.setFollowHighlight(followMouseOverFlag.getState());
984 // TODO: could kick the scrollTo mechanism to reset view for current
988 private void centreColumnLabelFlag_stateChanged()
990 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
991 this.alignPanel.annotationPanel.repaint();
995 public void actionPerformed(ActionEvent evt)
997 viewport.applet.currentAlignFrame = this;
999 Object source = evt.getSource();
1001 if (source == inputText)
1003 inputText_actionPerformed();
1005 else if (source == loadTree)
1007 loadTree_actionPerformed();
1009 else if (source == loadApplication)
1011 launchFullApplication();
1013 else if (source == loadAnnotations)
1017 else if (source == outputAnnotations)
1019 outputAnnotations(true);
1021 else if (source == outputFeatures)
1023 outputFeatures(true, "Jalview");
1025 else if (source == closeMenuItem)
1027 closeMenuItem_actionPerformed();
1029 else if (source == copy)
1031 copy_actionPerformed();
1033 else if (source == undoMenuItem)
1035 undoMenuItem_actionPerformed();
1037 else if (source == redoMenuItem)
1039 redoMenuItem_actionPerformed();
1041 else if (source == inputText)
1043 inputText_actionPerformed();
1045 else if (source == closeMenuItem)
1047 closeMenuItem_actionPerformed();
1049 else if (source == undoMenuItem)
1051 undoMenuItem_actionPerformed();
1053 else if (source == redoMenuItem)
1055 redoMenuItem_actionPerformed();
1057 else if (source == copy)
1059 copy_actionPerformed();
1061 else if (source == pasteNew)
1063 pasteNew_actionPerformed();
1065 else if (source == pasteThis)
1067 pasteThis_actionPerformed();
1069 else if (source == cut)
1071 cut_actionPerformed();
1073 else if (source == delete)
1075 delete_actionPerformed();
1077 else if (source == grpsFromSelection)
1079 makeGrpsFromSelection_actionPerformed();
1081 else if (source == deleteGroups)
1083 deleteGroups_actionPerformed();
1085 else if (source == selectAllSequenceMenuItem)
1087 selectAllSequenceMenuItem_actionPerformed();
1089 else if (source == deselectAllSequenceMenuItem)
1091 deselectAllSequenceMenuItem_actionPerformed();
1093 else if (source == invertSequenceMenuItem)
1095 invertSequenceMenuItem_actionPerformed();
1096 // uncomment to slave sequence selections in split frame
1097 // viewport.sendSelection();
1099 else if (source == invertColSel)
1101 viewport.invertColumnSelection();
1102 alignPanel.paintAlignment(true);
1103 viewport.sendSelection();
1105 else if (source == remove2LeftMenuItem)
1107 trimAlignment(true);
1109 else if (source == remove2RightMenuItem)
1111 trimAlignment(false);
1113 else if (source == removeGappedColumnMenuItem)
1115 removeGappedColumnMenuItem_actionPerformed();
1117 else if (source == removeAllGapsMenuItem)
1119 removeAllGapsMenuItem_actionPerformed();
1121 else if (source == findMenuItem)
1123 findMenuItem_actionPerformed();
1125 else if (source == font)
1127 new FontChooser(alignPanel);
1129 else if (source == newView)
1133 else if (source == showColumns)
1135 viewport.showAllHiddenColumns();
1136 alignPanel.paintAlignment(true);
1137 viewport.sendSelection();
1139 else if (source == showSeqs)
1141 viewport.showAllHiddenSeqs();
1142 alignPanel.paintAlignment(true);
1143 // uncomment if we want to slave sequence selections in split frame
1144 // viewport.sendSelection();
1146 else if (source == hideColumns)
1148 viewport.hideSelectedColumns();
1149 alignPanel.paintAlignment(true);
1150 viewport.sendSelection();
1152 else if (source == hideSequences
1153 && viewport.getSelectionGroup() != null)
1155 viewport.hideAllSelectedSeqs();
1156 alignPanel.paintAlignment(true);
1157 // uncomment if we want to slave sequence selections in split frame
1158 // viewport.sendSelection();
1160 else if (source == hideAllButSelection)
1162 toggleHiddenRegions(false, false);
1163 alignPanel.paintAlignment(true);
1164 viewport.sendSelection();
1166 else if (source == hideAllSelection)
1168 SequenceGroup sg = viewport.getSelectionGroup();
1169 viewport.expandColSelection(sg, false);
1170 viewport.hideAllSelectedSeqs();
1171 viewport.hideSelectedColumns();
1172 alignPanel.paintAlignment(true);
1173 viewport.sendSelection();
1175 else if (source == showAllHidden)
1177 viewport.showAllHiddenColumns();
1178 viewport.showAllHiddenSeqs();
1179 alignPanel.paintAlignment(true);
1180 viewport.sendSelection();
1182 else if (source == showGroupConsensus)
1184 showGroupConsensus_actionPerformed();
1186 else if (source == showGroupConservation)
1188 showGroupConservation_actionPerformed();
1190 else if (source == showSequenceLogo)
1192 showSequenceLogo_actionPerformed();
1194 else if (source == normSequenceLogo)
1196 normSequenceLogo_actionPerformed();
1198 else if (source == showConsensusHistogram)
1200 showConsensusHistogram_actionPerformed();
1202 else if (source == applyAutoAnnotationSettings)
1204 applyAutoAnnotationSettings_actionPerformed();
1206 else if (source == featureSettings)
1208 new FeatureSettings(alignPanel);
1210 else if (source == alProperties)
1212 StringBuffer contents = new jalview.io.AlignmentProperties(
1213 viewport.getAlignment()).formatAsString();
1214 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1215 cap.setText(contents.toString());
1216 Frame frame = new Frame();
1218 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
1219 "label.alignment_properties", new String[] { getTitle() }),
1222 else if (source == overviewMenuItem)
1224 overviewMenuItem_actionPerformed();
1226 else if (source == noColourmenuItem)
1230 else if (source == clustalColour)
1232 abovePIDThreshold.setState(false);
1233 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1235 else if (source == zappoColour)
1237 changeColour(new ZappoColourScheme());
1239 else if (source == taylorColour)
1241 changeColour(new TaylorColourScheme());
1243 else if (source == hydrophobicityColour)
1245 changeColour(new HydrophobicColourScheme());
1247 else if (source == helixColour)
1249 changeColour(new HelixColourScheme());
1251 else if (source == strandColour)
1253 changeColour(new StrandColourScheme());
1255 else if (source == turnColour)
1257 changeColour(new TurnColourScheme());
1259 else if (source == buriedColour)
1261 changeColour(new BuriedColourScheme());
1263 else if (source == nucleotideColour)
1265 changeColour(new NucleotideColourScheme());
1267 else if (source == purinePyrimidineColour)
1269 changeColour(new PurinePyrimidineColourScheme());
1271 // else if (source == RNAInteractionColour)
1273 // changeColour(new RNAInteractionColourScheme());
1275 else if (source == RNAHelixColour)
1277 changeColour(new RNAHelicesColour(viewport.getAlignment()));
1278 // new RNAHelicesColourChooser(viewport, alignPanel);
1280 else if (source == modifyPID)
1282 modifyPID_actionPerformed();
1284 else if (source == modifyConservation)
1286 modifyConservation_actionPerformed();
1288 else if (source == userDefinedColour)
1290 new UserDefinedColours(alignPanel, null);
1292 else if (source == PIDColour)
1294 changeColour(new PIDColourScheme());
1296 else if (source == BLOSUM62Colour)
1298 changeColour(new Blosum62ColourScheme());
1300 else if (source == tcoffeeColour)
1302 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1304 else if (source == annotationColour)
1306 new AnnotationColourChooser(viewport, alignPanel);
1308 else if (source == annotationColumnSelection)
1310 new AnnotationColumnChooser(viewport, alignPanel);
1312 else if (source == sortPairwiseMenuItem)
1314 sortPairwiseMenuItem_actionPerformed();
1316 else if (source == sortIDMenuItem)
1318 sortIDMenuItem_actionPerformed();
1320 else if (source == sortLengthMenuItem)
1322 sortLengthMenuItem_actionPerformed();
1324 else if (source == sortGroupMenuItem)
1326 sortGroupMenuItem_actionPerformed();
1328 else if (source == removeRedundancyMenuItem)
1330 removeRedundancyMenuItem_actionPerformed();
1332 else if (source == pairwiseAlignmentMenuItem)
1334 pairwiseAlignmentMenuItem_actionPerformed();
1336 else if (source == PCAMenuItem)
1338 PCAMenuItem_actionPerformed();
1340 else if (source == averageDistanceTreeMenuItem)
1342 averageDistanceTreeMenuItem_actionPerformed();
1344 else if (source == neighbourTreeMenuItem)
1346 neighbourTreeMenuItem_actionPerformed();
1348 else if (source == njTreeBlosumMenuItem)
1350 njTreeBlosumMenuItem_actionPerformed();
1352 else if (source == avDistanceTreeBlosumMenuItem)
1354 avTreeBlosumMenuItem_actionPerformed();
1356 else if (source == documentation)
1358 documentation_actionPerformed();
1360 else if (source == about)
1362 about_actionPerformed();
1367 public void inputText_actionPerformed()
1369 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1370 Frame frame = new Frame();
1372 jalview.bin.JalviewLite.addFrame(frame,
1373 MessageManager.getString("label.input_cut_paste"), 500, 500);
1376 protected void outputText_actionPerformed(ActionEvent e)
1378 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1379 Frame frame = new Frame();
1381 JalviewLite.addFrame(frame, MessageManager.formatMessage(
1382 "label.alignment_output_command",
1383 new Object[] { e.getActionCommand() }), 600, 500);
1385 FileFormatI fileFormat = FileFormats.getInstance().forName(
1386 e.getActionCommand());
1387 cap.setText(new AppletFormatAdapter(alignPanel).formatSequences(
1388 fileFormat, viewport.getAlignment(),
1389 viewport.getShowJVSuffix()));
1392 public void loadAnnotations()
1394 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1395 cap.setText(MessageManager
1396 .getString("label.paste_features_annotations_Tcoffee_here"));
1397 cap.setAnnotationImport();
1398 Frame frame = new Frame();
1400 jalview.bin.JalviewLite.addFrame(frame,
1401 MessageManager.getString("action.paste_annotations"), 400, 300);
1405 public String outputAnnotations(boolean displayTextbox)
1407 String annotation = new AnnotationFile()
1408 .printAnnotationsForView(viewport);
1412 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1413 Frame frame = new Frame();
1415 jalview.bin.JalviewLite.addFrame(frame,
1416 MessageManager.getString("label.annotations"), 600, 500);
1417 cap.setText(annotation);
1423 private Map<String, FeatureColourI> getDisplayedFeatureCols()
1425 if (alignPanel.getFeatureRenderer() != null
1426 && viewport.getFeaturesDisplayed() != null)
1428 return alignPanel.getFeatureRenderer().getDisplayedFeatureCols();
1434 public String outputFeatures(boolean displayTextbox, String format)
1437 FeaturesFile formatter = new FeaturesFile();
1438 if (format.equalsIgnoreCase("Jalview"))
1440 features = formatter.printJalviewFormat(viewport.getAlignment()
1441 .getSequencesArray(), getDisplayedFeatureCols());
1445 features = formatter.printGffFormat(viewport.getAlignment()
1446 .getSequencesArray(), getDisplayedFeatureCols());
1451 boolean frimport = false;
1452 if (features == null || features.equals("No Features Visible"))
1454 features = "# No features visible - paste some and import them here.";
1458 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1461 cap.setAnnotationImport();
1463 Frame frame = new Frame();
1465 jalview.bin.JalviewLite.addFrame(frame,
1466 MessageManager.getString("label.features"), 600, 500);
1467 cap.setText(features);
1471 if (features == null)
1480 void launchFullApplication()
1482 StringBuffer url = new StringBuffer(jalviewServletURL);
1484 // allow servlet parameters to be passed in applet parameter
1485 String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
1487 url.append(firstSep);
1490 + appendProtocol(viewport.applet.getParameter("file")));
1492 if (viewport.applet.getParameter("features") != null)
1494 url.append("&features=");
1495 url.append(appendProtocol(viewport.applet.getParameter("features")));
1498 if (viewport.applet.getParameter("annotations") != null)
1500 url.append("&annotations=");
1501 url.append(appendProtocol(viewport.applet.getParameter("annotations")));
1504 if (viewport.applet.getParameter("jnetfile") != null
1505 || viewport.applet.getParameter("jpredfile") != null)
1507 url.append("&annotations=");
1508 url.append(appendProtocol(viewport.applet.getParameter("jnetfile") != null ? viewport.applet
1509 .getParameter("jnetfile") : viewport.applet
1510 .getParameter("jpredfile")));
1513 if (viewport.applet.getParameter("defaultColour") != null)
1515 url.append("&colour="
1516 + removeWhiteSpace(viewport.applet
1517 .getParameter("defaultColour")));
1520 if (viewport.applet.getParameter("userDefinedColour") != null)
1522 url.append("&colour="
1523 + removeWhiteSpace(viewport.applet
1524 .getParameter("userDefinedColour")));
1526 if (viewport.applet.getParameter("tree") != null)
1529 + appendProtocol(viewport.applet.getParameter("tree")));
1531 if (viewport.applet.getParameter("treeFile") != null)
1534 + appendProtocol(viewport.applet.getParameter("treeFile")));
1537 showURL(url.toString(), "FULL_APP");
1540 String removeWhiteSpace(String colour)
1542 StringBuffer sb = new StringBuffer();
1543 for (int i = 0; i < colour.length(); i++)
1545 if (Character.isWhitespace(colour.charAt(i)))
1551 sb.append(colour.charAt(i));
1555 return sb.toString();
1558 String appendProtocol(String url)
1563 url = URLEncoder.encode(url);
1566 * When we finally deprecate 1.1 compatibility, we can start to use
1567 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1568 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1569 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1570 * ex.printStackTrace(); }
1572 catch (java.net.MalformedURLException ex)
1574 url = viewport.applet.getCodeBase() + url;
1579 public void closeMenuItem_actionPerformed()
1581 PaintRefresher.RemoveComponent(alignPanel);
1582 if (alignPanel.seqPanel != null
1583 && alignPanel.seqPanel.seqCanvas != null)
1585 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1587 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1589 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1592 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1607 void updateEditMenuBar()
1610 if (viewport.getHistoryList().size() > 0)
1612 undoMenuItem.setEnabled(true);
1613 CommandI command = viewport.getHistoryList().peek();
1614 undoMenuItem.setLabel(MessageManager.formatMessage(
1615 "label.undo_command",
1616 new Object[] { command.getDescription() }));
1620 undoMenuItem.setEnabled(false);
1621 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1624 if (viewport.getRedoList().size() > 0)
1626 redoMenuItem.setEnabled(true);
1628 CommandI command = viewport.getRedoList().peek();
1629 redoMenuItem.setLabel(MessageManager.formatMessage(
1630 "label.redo_command",
1631 new Object[] { command.getDescription() }));
1635 redoMenuItem.setEnabled(false);
1636 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1644 public void addHistoryItem(CommandI command)
1646 if (command.getSize() > 0)
1648 viewport.addToHistoryList(command);
1649 viewport.clearRedoList();
1650 updateEditMenuBar();
1651 viewport.updateHiddenColumns();
1656 * TODO: JAL-1104 DOCUMENT ME!
1661 protected void undoMenuItem_actionPerformed()
1663 if (viewport.getHistoryList().isEmpty())
1668 CommandI command = viewport.getHistoryList().pop();
1669 viewport.addToRedoList(command);
1670 command.undoCommand(null);
1672 AlignmentViewport originalSource = getOriginatingSource(command);
1674 if (originalSource != viewport)
1677 .println("Warning: Viewport object mismatch whilst undoing");
1679 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1680 // viewport.getColumnSelection().getHiddenColumns()
1682 updateEditMenuBar();
1683 originalSource.firePropertyChange("alignment", null, originalSource
1684 .getAlignment().getSequences());
1688 * TODO: JAL-1104 DOCUMENT ME!
1693 protected void redoMenuItem_actionPerformed()
1695 if (viewport.getRedoList().isEmpty())
1700 CommandI command = viewport.getRedoList().pop();
1701 viewport.addToHistoryList(command);
1702 command.doCommand(null);
1704 AlignmentViewport originalSource = getOriginatingSource(command);
1706 if (originalSource != viewport)
1709 .println("Warning: Viewport object mismatch whilst re-doing");
1711 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1712 // viewport.getColumnSelection().getHiddenColumns()
1715 updateEditMenuBar();
1716 originalSource.firePropertyChange("alignment", null, originalSource
1717 .getAlignment().getSequences());
1720 AlignmentViewport getOriginatingSource(CommandI command)
1722 AlignmentViewport originalSource = null;
1723 // For sequence removal and addition, we need to fire
1724 // the property change event FROM the viewport where the
1725 // original alignment was altered
1726 AlignmentI al = null;
1727 if (command instanceof EditCommand)
1729 EditCommand editCommand = (EditCommand) command;
1730 al = editCommand.getAlignment();
1731 Vector comps = (Vector) PaintRefresher.components.get(viewport
1732 .getSequenceSetId());
1733 for (int i = 0; i < comps.size(); i++)
1735 if (comps.elementAt(i) instanceof AlignmentPanel)
1737 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1739 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1746 if (originalSource == null)
1748 // The original view is closed, we must validate
1749 // the current view against the closed view first
1752 PaintRefresher.validateSequences(al, viewport.getAlignment());
1755 originalSource = viewport;
1758 return originalSource;
1762 * Move the currently selected sequences up or down one position in the
1767 public void moveSelectedSequences(boolean up)
1769 SequenceGroup sg = viewport.getSelectionGroup();
1774 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1775 up ? null : viewport.getHiddenRepSequences(), up);
1776 alignPanel.paintAlignment(true);
1779 * Also move cDNA/protein complement sequences
1781 AlignViewportI complement = viewport.getCodingComplement();
1782 if (complement != null)
1784 SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
1785 viewport, complement);
1786 complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
1787 up ? null : complement.getHiddenRepSequences(), up);
1788 getSplitFrame().getComplement(this).alignPanel.paintAlignment(true);
1792 synchronized void slideSequences(boolean right, int size)
1794 List<SequenceI> sg = new Vector<SequenceI>();
1795 if (viewport.cursorMode)
1797 sg.add(viewport.getAlignment().getSequenceAt(
1798 alignPanel.seqPanel.seqCanvas.cursorY));
1800 else if (viewport.getSelectionGroup() != null
1801 && viewport.getSelectionGroup().getSize() != viewport
1802 .getAlignment().getHeight())
1804 sg = viewport.getSelectionGroup().getSequences(
1805 viewport.getHiddenRepSequences());
1813 Vector<SequenceI> invertGroup = new Vector();
1815 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1817 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1819 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1823 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1825 SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup
1827 for (int i = 0; i < invertGroup.size(); i++)
1829 seqs2[i] = invertGroup.elementAt(i);
1832 SlideSequencesCommand ssc;
1835 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1836 size, viewport.getGapCharacter());
1840 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1841 size, viewport.getGapCharacter());
1844 int groupAdjustment = 0;
1845 if (ssc.getGapsInsertedBegin() && right)
1847 if (viewport.cursorMode)
1849 alignPanel.seqPanel.moveCursor(size, 0);
1853 groupAdjustment = size;
1856 else if (!ssc.getGapsInsertedBegin() && !right)
1858 if (viewport.cursorMode)
1860 alignPanel.seqPanel.moveCursor(-size, 0);
1864 groupAdjustment = -size;
1868 if (groupAdjustment != 0)
1870 viewport.getSelectionGroup().setStartRes(
1871 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1872 viewport.getSelectionGroup().setEndRes(
1873 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1876 boolean appendHistoryItem = false;
1877 Deque<CommandI> historyList = viewport.getHistoryList();
1878 if (historyList != null && historyList.size() > 0
1879 && historyList.peek() instanceof SlideSequencesCommand)
1881 appendHistoryItem = ssc
1882 .appendSlideCommand((SlideSequencesCommand) historyList
1886 if (!appendHistoryItem)
1888 addHistoryItem(ssc);
1894 static StringBuffer copiedSequences;
1896 static Vector copiedHiddenColumns;
1898 protected void copy_actionPerformed()
1900 if (viewport.getSelectionGroup() == null)
1905 SequenceGroup sg = viewport.getSelectionGroup();
1906 copiedSequences = new StringBuffer();
1907 Map<Integer, SequenceI> orderedSeqs = new HashMap<Integer, SequenceI>();
1908 for (int i = 0; i < sg.getSize(); i++)
1910 SequenceI seq = sg.getSequenceAt(i);
1911 int index = viewport.getAlignment().findIndex(seq);
1912 orderedSeqs.put(index, seq);
1915 int index = 0, startRes, endRes;
1918 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1920 copiedHiddenColumns = new Vector();
1921 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1922 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1924 copiedHiddenColumns.addElement(new int[] {
1925 region[0] - hiddenOffset, region[1] - hiddenOffset });
1930 copiedHiddenColumns = null;
1933 for (int i = 0; i < sg.getSize(); i++)
1935 SequenceI seq = null;
1939 if (orderedSeqs.containsKey(index))
1941 seq = orderedSeqs.get(index);
1952 // Returns residue following index if gap
1953 startRes = seq.findPosition(sg.getStartRes());
1956 // Need to find the residue preceeding index if gap
1959 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1961 ch = seq.getCharAt(j);
1962 if (!jalview.util.Comparison.isGap((ch)))
1970 endRes += seq.getStart() - 1;
1973 copiedSequences.append(seq.getName()
1979 + seq.getSequenceAsString(sg.getStartRes(),
1980 sg.getEndRes() + 1) + "\n");
1985 protected void pasteNew_actionPerformed()
1990 protected void pasteThis_actionPerformed()
1995 void paste(boolean newAlignment)
2000 if (copiedSequences == null)
2005 StringTokenizer st = new StringTokenizer(copiedSequences.toString());
2006 Vector seqs = new Vector();
2007 while (st.hasMoreElements())
2009 String name = st.nextToken();
2010 int start = Integer.parseInt(st.nextToken());
2011 int end = Integer.parseInt(st.nextToken());
2012 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
2014 SequenceI[] newSeqs = new SequenceI[seqs.size()];
2015 for (int i = 0; i < seqs.size(); i++)
2017 newSeqs[i] = (SequenceI) seqs.elementAt(i);
2022 String newtitle = MessageManager
2023 .getString("label.copied_sequences");
2024 if (getTitle().startsWith(
2025 MessageManager.getString("label.copied_sequences")))
2027 newtitle = getTitle();
2031 newtitle = newtitle.concat(MessageManager.formatMessage(
2032 "label.from_msname", new String[] { getTitle() }));
2034 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
2035 viewport.applet, newtitle, false);
2036 if (copiedHiddenColumns != null)
2038 for (int i = 0; i < copiedHiddenColumns.size(); i++)
2040 int[] region = (int[]) copiedHiddenColumns.elementAt(i);
2041 af.viewport.hideColumns(region[0], region[1]);
2045 jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
2050 addSequences(newSeqs);
2053 } catch (Exception ex)
2055 } // could be anything being pasted in here
2059 void addSequences(SequenceI[] seqs)
2061 for (int i = 0; i < seqs.length; i++)
2063 viewport.getAlignment().addSequence(seqs[i]);
2067 addHistoryItem(new EditCommand(
2068 MessageManager.getString("label.add_sequences"), Action.PASTE,
2069 seqs, 0, viewport.getAlignment().getWidth(),
2070 viewport.getAlignment()));
2072 viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight());
2073 viewport.getAlignment().getWidth();
2074 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2079 protected void cut_actionPerformed()
2081 copy_actionPerformed();
2082 delete_actionPerformed();
2085 protected void delete_actionPerformed()
2088 SequenceGroup sg = viewport.getSelectionGroup();
2094 Vector seqs = new Vector();
2096 for (int i = 0; i < sg.getSize(); i++)
2098 seq = sg.getSequenceAt(i);
2099 seqs.addElement(seq);
2103 * If the cut affects all sequences, warn, remove highlighted columns
2105 if (sg.getSize() == viewport.getAlignment().getHeight())
2107 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2108 .getAlignment().getWidth()) ? true : false;
2109 if (isEntireAlignWidth)
2111 String title = MessageManager.getString("label.delete_all");
2112 Panel infoPanel = new Panel();
2113 infoPanel.setLayout(new FlowLayout());
2115 .add(new Label(MessageManager.getString("warn.delete_all")));
2117 final JVDialog dialog = new JVDialog(this, title, true, 400, 200);
2118 dialog.setMainPanel(infoPanel);
2119 dialog.ok.setLabel(MessageManager.getString("action.ok"));
2120 dialog.cancel.setLabel(MessageManager.getString("action.cancel"));
2121 dialog.setVisible(true);
2128 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2129 sg.getEndRes() + 1);
2132 SequenceI[] cut = new SequenceI[seqs.size()];
2133 for (int i = 0; i < seqs.size(); i++)
2135 cut[i] = (SequenceI) seqs.elementAt(i);
2139 * //ADD HISTORY ITEM
2141 addHistoryItem(new EditCommand(
2142 MessageManager.getString("label.cut_sequences"), Action.CUT,
2143 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2144 viewport.getAlignment()));
2146 viewport.setSelectionGroup(null);
2147 viewport.getAlignment().deleteGroup(sg);
2149 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2152 if (viewport.getAlignment().getHeight() < 1)
2154 this.setVisible(false);
2156 viewport.sendSelection();
2160 * group consensus toggled
2163 protected void showGroupConsensus_actionPerformed()
2165 viewport.setShowGroupConsensus(showGroupConsensus.getState());
2166 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2171 * group conservation toggled.
2173 protected void showGroupConservation_actionPerformed()
2175 viewport.setShowGroupConservation(showGroupConservation.getState());
2176 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2183 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
2184 * .event.ActionEvent)
2186 protected void showConsensusHistogram_actionPerformed()
2188 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
2189 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2196 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
2197 * .event.ActionEvent)
2199 protected void showSequenceLogo_actionPerformed()
2201 viewport.setShowSequenceLogo(showSequenceLogo.getState());
2202 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2205 protected void normSequenceLogo_actionPerformed()
2207 showSequenceLogo.setState(true);
2208 viewport.setShowSequenceLogo(true);
2209 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
2210 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2213 protected void applyAutoAnnotationSettings_actionPerformed()
2215 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2218 protected void makeGrpsFromSelection_actionPerformed()
2220 if (avc.makeGroupsFromSelection())
2222 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2223 alignPanel.updateAnnotation();
2224 alignPanel.paintAlignment(true);
2228 protected void createGroup_actionPerformed()
2233 protected void unGroup_actionPerformed()
2237 alignPanel.alignmentChanged();
2241 protected void deleteGroups_actionPerformed()
2243 if (avc.deleteGroups())
2245 alignPanel.alignmentChanged();
2249 public void selectAllSequenceMenuItem_actionPerformed()
2251 SequenceGroup sg = new SequenceGroup();
2252 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2254 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2256 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2257 viewport.setSelectionGroup(sg);
2258 // JAL-2034 - should delegate to
2259 // alignPanel to decide if overview needs
2261 alignPanel.paintAlignment(false);
2262 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2263 viewport.sendSelection();
2266 public void deselectAllSequenceMenuItem_actionPerformed()
2268 if (viewport.cursorMode)
2270 alignPanel.seqPanel.keyboardNo1 = null;
2271 alignPanel.seqPanel.keyboardNo2 = null;
2273 viewport.setSelectionGroup(null);
2274 viewport.getColumnSelection().clear();
2275 viewport.setSelectionGroup(null);
2276 alignPanel.idPanel.idCanvas.searchResults = null;
2277 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2278 // JAL-2034 - should delegate to
2279 // alignPanel to decide if overview needs
2281 alignPanel.paintAlignment(false);
2282 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2283 viewport.sendSelection();
2286 public void invertSequenceMenuItem_actionPerformed()
2288 SequenceGroup sg = viewport.getSelectionGroup();
2289 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2291 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2294 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2295 viewport.sendSelection();
2298 public void invertColSel_actionPerformed()
2300 viewport.invertColumnSelection();
2301 alignPanel.paintAlignment(true);
2302 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2303 viewport.sendSelection();
2306 void trimAlignment(boolean trimLeft)
2308 AlignmentI al = viewport.getAlignment();
2309 ViewportRanges ranges = viewport.getRanges();
2310 ColumnSelection colSel = viewport.getColumnSelection();
2313 if (!colSel.isEmpty())
2317 column = colSel.getMin();
2321 column = colSel.getMax();
2325 if (viewport.getSelectionGroup() != null)
2327 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2328 viewport.getHiddenRepSequences());
2332 seqs = al.getSequencesArray();
2335 TrimRegionCommand trimRegion;
2338 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2340 ranges.setStartRes(0);
2344 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2348 statusBar.setText(MessageManager.formatMessage(
2349 "label.removed_columns",
2350 new String[] { Integer.valueOf(trimRegion.getSize())
2352 addHistoryItem(trimRegion);
2354 for (SequenceGroup sg : al.getGroups())
2356 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2357 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2363 viewport.firePropertyChange("alignment", null, al.getSequences());
2367 public void removeGappedColumnMenuItem_actionPerformed()
2369 AlignmentI al = viewport.getAlignment();
2370 ViewportRanges ranges = viewport.getRanges();
2372 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2375 if (viewport.getSelectionGroup() != null)
2377 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2378 viewport.getHiddenRepSequences());
2379 start = viewport.getSelectionGroup().getStartRes();
2380 end = viewport.getSelectionGroup().getEndRes();
2384 seqs = viewport.getAlignment().getSequencesArray();
2387 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2388 "Remove Gapped Columns", seqs, start, end,
2389 viewport.getAlignment());
2391 addHistoryItem(removeGapCols);
2393 statusBar.setText(MessageManager.formatMessage(
2394 "label.removed_empty_columns",
2395 new String[] { Integer.valueOf(removeGapCols.getSize())
2398 // This is to maintain viewport position on first residue
2399 // of first sequence
2400 SequenceI seq = al.getSequenceAt(0);
2401 int startRes = seq.findPosition(ranges.getStartRes());
2402 // ShiftList shifts;
2403 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2404 // edit.alColumnChanges=shifts.getInverse();
2405 // if (viewport.hasHiddenColumns)
2406 // viewport.getColumnSelection().compensateForEdits(shifts);
2407 ranges.setStartRes(seq.findIndex(startRes) - 1);
2408 viewport.firePropertyChange("alignment", null, al.getSequences());
2412 public void removeAllGapsMenuItem_actionPerformed()
2414 AlignmentI al = viewport.getAlignment();
2415 ViewportRanges ranges = viewport.getRanges();
2417 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2420 if (viewport.getSelectionGroup() != null)
2422 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2423 viewport.getHiddenRepSequences());
2424 start = viewport.getSelectionGroup().getStartRes();
2425 end = viewport.getSelectionGroup().getEndRes();
2429 seqs = viewport.getAlignment().getSequencesArray();
2432 // This is to maintain viewport position on first residue
2433 // of first sequence
2434 SequenceI seq = al.getSequenceAt(0);
2435 int startRes = seq.findPosition(ranges.getStartRes());
2437 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2440 ranges.setStartRes(seq.findIndex(startRes) - 1);
2442 viewport.firePropertyChange("alignment", null, al.getSequences());
2446 public void findMenuItem_actionPerformed()
2448 new Finder(alignPanel);
2452 * create a new view derived from the current view
2455 * @return frame for the new view
2457 public AlignFrame newView(String viewtitle)
2460 if (viewport.hasHiddenRows())
2462 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2463 .getFullAlignment().getSequencesArray());
2467 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2470 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2472 for (int i = 0; i < viewport.getAlignment().getAlignmentAnnotation().length; i++)
2474 if (!viewport.getAlignment().getAlignmentAnnotation()[i].autoCalculated)
2476 newal.addAnnotation(viewport.getAlignment()
2477 .getAlignmentAnnotation()[i]);
2482 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2484 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2485 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2486 PaintRefresher.Register(newaf.alignPanel,
2487 newaf.alignPanel.av.getSequenceSetId());
2489 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2490 newaf.alignPanel.av.getSequenceSetId());
2491 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2492 newaf.alignPanel.av.getSequenceSetId());
2494 Vector comps = (Vector) PaintRefresher.components.get(viewport
2495 .getSequenceSetId());
2497 for (int i = 0; i < comps.size(); i++)
2499 if (comps.elementAt(i) instanceof AlignmentPanel)
2505 String title = new String(this.getTitle());
2506 if (viewtitle != null)
2508 title = viewtitle + " ( " + title + ")";
2512 if (title.indexOf("(View") > -1)
2514 title = title.substring(0, title.indexOf("(View"));
2516 title += "(View " + viewSize + ")";
2519 newaf.setTitle(title.toString());
2521 newaf.viewport.setHistoryList(viewport.getHistoryList());
2522 newaf.viewport.setRedoList(viewport.getRedoList());
2528 * @return list of feature groups on the view
2530 public String[] getFeatureGroups()
2532 FeatureRenderer fr = null;
2533 if (alignPanel != null
2534 && (fr = alignPanel.getFeatureRenderer()) != null)
2536 List<String> gps = fr.getFeatureGroups();
2537 String[] _gps = gps.toArray(new String[gps.size()]);
2544 * get sequence feature groups that are hidden or shown
2550 public String[] getFeatureGroupsOfState(boolean visible)
2552 FeatureRenderer fr = null;
2553 if (alignPanel != null
2554 && (fr = alignPanel.getFeatureRenderer()) != null)
2556 List<String> gps = fr.getGroups(visible);
2557 String[] _gps = gps.toArray(new String[gps.size()]);
2564 * Change the display state for the given feature groups
2567 * list of group strings
2569 * visible or invisible
2571 public void setFeatureGroupState(String[] groups, boolean state)
2573 FeatureRenderer fr = null;
2574 this.sequenceFeatures.setState(true);
2575 viewport.setShowSequenceFeatures(true);
2576 if (alignPanel != null
2577 && (fr = alignPanel.getFeatureRenderer()) != null)
2580 fr.setGroupVisibility(Arrays.asList(groups), state);
2581 alignPanel.seqPanel.seqCanvas.repaint();
2582 if (alignPanel.overviewPanel != null)
2584 alignPanel.overviewPanel.updateOverviewImage();
2589 public void seqLimits_itemStateChanged()
2591 viewport.setShowJVSuffix(seqLimits.getState());
2592 alignPanel.fontChanged();
2593 alignPanel.paintAlignment(true);
2596 protected void colourTextMenuItem_actionPerformed()
2598 viewport.setColourText(colourTextMenuItem.getState());
2599 alignPanel.paintAlignment(true);
2602 protected void displayNonconservedMenuItem_actionPerformed()
2604 viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
2605 alignPanel.paintAlignment(true);
2608 protected void wrapMenuItem_actionPerformed()
2610 viewport.setWrapAlignment(wrapMenuItem.getState());
2611 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2612 scaleAbove.setEnabled(wrapMenuItem.getState());
2613 scaleLeft.setEnabled(wrapMenuItem.getState());
2614 scaleRight.setEnabled(wrapMenuItem.getState());
2615 alignPanel.paintAlignment(true);
2618 public void overviewMenuItem_actionPerformed()
2620 if (alignPanel.overviewPanel != null)
2625 Frame frame = new Frame();
2626 OverviewPanel overview = new OverviewPanel(alignPanel);
2627 frame.add(overview);
2628 // +50 must allow for applet frame window
2629 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
2630 "label.overview_params", new String[] { this.getTitle() }),
2631 overview.getPreferredSize().width,
2632 overview.getPreferredSize().height + 50);
2635 final AlignmentPanel ap = alignPanel;
2636 frame.addWindowListener(new WindowAdapter()
2639 public void windowClosing(WindowEvent e)
2643 ap.setOverviewPanel(null);
2648 alignPanel.setOverviewPanel(overview);
2653 public void changeColour(ColourSchemeI cs)
2655 viewport.setGlobalColourScheme(cs);
2657 alignPanel.paintAlignment(true);
2660 protected void modifyPID_actionPerformed()
2662 if (viewport.getAbovePIDThreshold()
2663 && viewport.getGlobalColourScheme() != null)
2665 SliderPanel.setPIDSliderSource(alignPanel,
2666 viewport.getResidueShading(), alignPanel.getViewName());
2667 SliderPanel.showPIDSlider();
2671 protected void modifyConservation_actionPerformed()
2673 if (viewport.getConservationSelected()
2674 && viewport.getGlobalColourScheme() != null)
2676 SliderPanel.setConservationSlider(alignPanel,
2677 viewport.getResidueShading(), alignPanel.getViewName());
2678 SliderPanel.showConservationSlider();
2682 protected void conservationMenuItem_actionPerformed()
2684 boolean selected = conservationMenuItem.getState();
2685 modifyConservation.setEnabled(selected);
2686 viewport.setConservationSelected(selected);
2688 // viewport.setAbovePIDThreshold(false);
2689 // abovePIDThreshold.setState(false);
2691 changeColour(viewport.getGlobalColourScheme());
2695 modifyConservation_actionPerformed();
2699 SliderPanel.hideConservationSlider();
2703 public void abovePIDThreshold_actionPerformed()
2705 boolean selected = abovePIDThreshold.getState();
2706 modifyPID.setEnabled(selected);
2707 viewport.setAbovePIDThreshold(selected);
2708 // conservationMenuItem.setState(false);
2709 // viewport.setConservationSelected(false);
2711 changeColour(viewport.getGlobalColourScheme());
2715 modifyPID_actionPerformed();
2719 SliderPanel.hidePIDSlider();
2723 public void sortPairwiseMenuItem_actionPerformed()
2725 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2726 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
2727 .getAlignment().getSequenceAt(0));
2729 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2730 viewport.getAlignment()));
2731 alignPanel.paintAlignment(true);
2734 public void sortIDMenuItem_actionPerformed()
2736 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2737 AlignmentSorter.sortByID(viewport.getAlignment());
2738 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
2739 viewport.getAlignment()));
2740 alignPanel.paintAlignment(true);
2743 public void sortLengthMenuItem_actionPerformed()
2745 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2746 AlignmentSorter.sortByLength(viewport.getAlignment());
2747 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2748 viewport.getAlignment()));
2749 alignPanel.paintAlignment(true);
2752 public void sortGroupMenuItem_actionPerformed()
2754 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2755 AlignmentSorter.sortByGroup(viewport.getAlignment());
2756 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2757 viewport.getAlignment()));
2758 alignPanel.paintAlignment(true);
2762 public void removeRedundancyMenuItem_actionPerformed()
2764 new RedundancyPanel(alignPanel);
2767 public void pairwiseAlignmentMenuItem_actionPerformed()
2769 if (viewport.getSelectionGroup() != null
2770 && viewport.getSelectionGroup().getSize() > 1)
2772 Frame frame = new Frame();
2773 frame.add(new PairwiseAlignPanel(alignPanel));
2774 jalview.bin.JalviewLite.addFrame(frame,
2775 MessageManager.getString("action.pairwise_alignment"), 600,
2780 public void PCAMenuItem_actionPerformed()
2782 // are the sequences aligned?
2783 if (!viewport.getAlignment().isAligned(false))
2786 int Width = viewport.getAlignment().getWidth();
2788 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2790 current = viewport.getAlignment().getSequenceAt(i);
2792 if (current.getLength() < Width)
2794 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2797 alignPanel.paintAlignment(true);
2800 if ((viewport.getSelectionGroup() != null
2801 && viewport.getSelectionGroup().getSize() < 4 && viewport
2802 .getSelectionGroup().getSize() > 0)
2803 || viewport.getAlignment().getHeight() < 4)
2810 new PCAPanel(viewport);
2811 } catch (java.lang.OutOfMemoryError ex)
2817 public void averageDistanceTreeMenuItem_actionPerformed()
2819 newTreePanel(TreeBuilder.AVERAGE_DISTANCE, new PIDModel().getName(),
2820 "Average distance tree using PID");
2823 public void neighbourTreeMenuItem_actionPerformed()
2825 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING, new PIDModel().getName(),
2826 "Neighbour joining tree using PID");
2829 protected void njTreeBlosumMenuItem_actionPerformed()
2831 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING, ScoreModels.getInstance()
2832 .getBlosum62().getName(),
2833 "Neighbour joining tree using BLOSUM62");
2836 protected void avTreeBlosumMenuItem_actionPerformed()
2838 newTreePanel(TreeBuilder.AVERAGE_DISTANCE, ScoreModels.getInstance()
2839 .getBlosum62().getName(),
2840 "Average distance tree using BLOSUM62");
2843 void newTreePanel(String type, String pwType, String title)
2845 // are the sequences aligned?
2846 if (!viewport.getAlignment().isAligned(false))
2849 int Width = viewport.getAlignment().getWidth();
2851 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2853 current = viewport.getAlignment().getSequenceAt(i);
2855 if (current.getLength() < Width)
2857 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2860 alignPanel.paintAlignment(true);
2864 if ((viewport.getSelectionGroup() != null && viewport
2865 .getSelectionGroup().getSize() > 1)
2866 || (viewport.getAlignment().getHeight() > 1))
2868 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2870 addTreeMenuItem(tp, title);
2872 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2876 void loadTree_actionPerformed()
2878 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2879 cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2880 cap.setTreeImport();
2881 Frame frame = new Frame();
2883 jalview.bin.JalviewLite.addFrame(frame,
2884 MessageManager.getString("label.paste_newick_file"), 400, 300);
2887 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2889 TreePanel tp = new TreePanel(alignPanel, treeFile,
2890 MessageManager.getString("label.load_tree_from_file"), tree);
2891 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2892 addTreeMenuItem(tp, treeFile);
2896 * sort the alignment using the given treePanel
2899 * tree used to sort view
2901 * string used for undo event name
2903 public void sortByTree(TreePanel treePanel, String title)
2905 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2907 .sortByTree(viewport.getAlignment(), treePanel.getTree());
2908 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2909 // HistoryItem.SORT));
2910 addHistoryItem(new OrderCommand(MessageManager.formatMessage(
2911 "label.order_by_params", new String[] { title }), oldOrder,
2912 viewport.getAlignment()));
2913 alignPanel.paintAlignment(true);
2917 * Do any automatic reordering of the alignment and add the necessary bits to
2918 * the menu structure for the new tree
2923 protected void addTreeMenuItem(final TreePanel treePanel,
2926 final MenuItem item = new MenuItem(title);
2927 sortByTreeMenu.add(item);
2928 item.addActionListener(new java.awt.event.ActionListener()
2931 public void actionPerformed(ActionEvent evt)
2933 sortByTree(treePanel, title); // treePanel.getTitle());
2937 treePanel.addWindowListener(new WindowAdapter()
2940 public void windowOpened(WindowEvent e)
2942 if (viewport.sortByTree)
2944 sortByTree(treePanel, title);
2946 super.windowOpened(e);
2950 public void windowClosing(WindowEvent e)
2952 sortByTreeMenu.remove(item);
2957 public boolean sortBy(AlignmentOrder alorder, String undoname)
2959 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2960 if (viewport.applet.debug)
2962 System.err.println("Sorting " + alorder.getOrder().size()
2963 + " in alignment '" + getTitle() + "'");
2965 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2966 if (undoname != null)
2968 addHistoryItem(new OrderCommand(undoname, oldOrder,
2969 viewport.getAlignment()));
2971 alignPanel.paintAlignment(true);
2975 protected void documentation_actionPerformed()
2977 alignPanel.av.applet.openJalviewHelpUrl();
2980 protected void about_actionPerformed()
2983 class AboutPanel extends Canvas
2989 public AboutPanel(String version, String builddate)
2991 this.version = version;
2992 this.builddate = builddate;
2996 public void paint(Graphics g)
2998 g.setColor(Color.white);
2999 g.fillRect(0, 0, getSize().width, getSize().height);
3000 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3001 FontMetrics fm = g.getFontMetrics();
3002 int fh = fm.getHeight();
3004 g.setColor(Color.black);
3005 // TODO: update this text for each release or centrally store it for
3006 // lite and application
3007 g.setFont(new Font("Helvetica", Font.BOLD, 14));
3008 g.drawString(MessageManager.formatMessage(
3009 "label.jalviewLite_release", new String[] { version }), x,
3011 g.setFont(new Font("Helvetica", Font.BOLD, 12));
3012 g.drawString(MessageManager.formatMessage(
3013 "label.jaview_build_date", new String[] { builddate }), x,
3015 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3016 g.drawString(MessageManager.getString("label.jalview_authors_1"),
3018 g.drawString(MessageManager.getString("label.jalview_authors_2"),
3019 x + 50, y += fh + 8);
3021 MessageManager.getString("label.jalview_dev_managers"), x,
3023 g.drawString(MessageManager
3024 .getString("label.jalview_distribution_lists"), x, y += fh);
3025 g.drawString(MessageManager.getString("label.jalview_please_cite"),
3028 MessageManager.getString("label.jalview_cite_1_authors"),
3031 MessageManager.getString("label.jalview_cite_1_title"), x,
3033 g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
3038 Frame frame = new Frame();
3039 frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite
3041 jalview.bin.JalviewLite.addFrame(frame,
3042 MessageManager.getString("label.jalview"), 580, 220);
3046 public void showURL(String url, String target)
3048 if (viewport.applet == null)
3050 System.out.println("Not running as applet - no browser available.");
3054 viewport.applet.showURL(url, target);
3058 // ////////////////////////////////////////////////////////////////////////////////
3059 // JBuilder Graphics here
3061 MenuBar alignFrameMenuBar = new MenuBar();
3063 Menu fileMenu = new Menu(MessageManager.getString("action.file"));
3065 MenuItem loadApplication = new MenuItem(
3066 MessageManager.getString("label.view_full_application"));
3068 MenuItem loadTree = new MenuItem(
3069 MessageManager.getString("label.load_associated_tree"));
3071 MenuItem loadAnnotations = new MenuItem(
3072 MessageManager.getString("label.load_features_annotations"));
3074 MenuItem outputFeatures = new MenuItem(
3075 MessageManager.getString("label.export_features"));
3077 MenuItem outputAnnotations = new MenuItem(
3078 MessageManager.getString("label.export_annotations"));
3080 MenuItem closeMenuItem = new MenuItem(
3081 MessageManager.getString("action.close"));
3083 MenuItem selectAllSequenceMenuItem = new MenuItem(
3084 MessageManager.getString("action.select_all"));
3086 MenuItem deselectAllSequenceMenuItem = new MenuItem(
3087 MessageManager.getString("action.deselect_all"));
3089 MenuItem invertSequenceMenuItem = new MenuItem(
3090 MessageManager.getString("action.invert_selection"));
3092 MenuItem remove2LeftMenuItem = new MenuItem();
3094 MenuItem remove2RightMenuItem = new MenuItem();
3096 MenuItem removeGappedColumnMenuItem = new MenuItem();
3098 MenuItem removeAllGapsMenuItem = new MenuItem();
3100 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
3102 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
3104 MenuItem sortPairwiseMenuItem = new MenuItem();
3106 MenuItem sortIDMenuItem = new MenuItem();
3108 MenuItem sortLengthMenuItem = new MenuItem();
3110 MenuItem sortGroupMenuItem = new MenuItem();
3112 MenuItem removeRedundancyMenuItem = new MenuItem();
3114 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
3116 MenuItem PCAMenuItem = new MenuItem();
3118 MenuItem averageDistanceTreeMenuItem = new MenuItem();
3120 MenuItem neighbourTreeMenuItem = new MenuItem();
3122 BorderLayout borderLayout1 = new BorderLayout();
3124 public Label statusBar = new Label();
3126 MenuItem clustalColour = new MenuItem();
3128 MenuItem zappoColour = new MenuItem();
3130 MenuItem taylorColour = new MenuItem();
3132 MenuItem hydrophobicityColour = new MenuItem();
3134 MenuItem helixColour = new MenuItem();
3136 MenuItem strandColour = new MenuItem();
3138 MenuItem turnColour = new MenuItem();
3140 MenuItem buriedColour = new MenuItem();
3142 MenuItem purinePyrimidineColour = new MenuItem();
3144 // MenuItem RNAInteractionColour = new MenuItem();
3146 MenuItem RNAHelixColour = new MenuItem();
3148 MenuItem userDefinedColour = new MenuItem();
3150 MenuItem PIDColour = new MenuItem();
3152 MenuItem BLOSUM62Colour = new MenuItem();
3154 MenuItem tcoffeeColour = new MenuItem();
3156 MenuItem njTreeBlosumMenuItem = new MenuItem();
3158 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
3160 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
3162 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
3164 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
3166 MenuItem alProperties = new MenuItem(
3167 MessageManager.getString("label.alignment_props"));
3169 MenuItem overviewMenuItem = new MenuItem();
3171 MenuItem undoMenuItem = new MenuItem();
3173 MenuItem redoMenuItem = new MenuItem();
3175 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
3177 MenuItem noColourmenuItem = new MenuItem();
3179 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
3181 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
3183 MenuItem findMenuItem = new MenuItem();
3185 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
3187 MenuItem nucleotideColour = new MenuItem();
3189 MenuItem deleteGroups = new MenuItem();
3191 MenuItem grpsFromSelection = new MenuItem();
3193 MenuItem createGroup = new MenuItem();
3195 MenuItem unGroup = new MenuItem();
3197 MenuItem delete = new MenuItem();
3199 MenuItem copy = new MenuItem();
3201 MenuItem cut = new MenuItem();
3203 Menu pasteMenu = new Menu();
3205 MenuItem pasteNew = new MenuItem();
3207 MenuItem pasteThis = new MenuItem();
3209 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
3211 MenuItem font = new MenuItem();
3213 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
3215 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
3217 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
3219 MenuItem modifyPID = new MenuItem();
3221 MenuItem modifyConservation = new MenuItem();
3223 CheckboxMenuItem autoCalculate = null;
3225 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
3226 "Sort Alignment With New Tree", true);
3228 Menu sortByTreeMenu = new Menu();
3230 MenuItem inputText = new MenuItem();
3232 MenuItem documentation = new MenuItem();
3234 MenuItem about = new MenuItem();
3236 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
3238 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
3240 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
3242 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
3244 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
3246 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
3248 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
3250 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
3252 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
3255 * Initialise menus and other items
3259 private void jbInit() throws Exception
3261 setMenuBar(alignFrameMenuBar);
3264 * Configure File menu items and actions
3267 .setLabel(MessageManager.getString("label.input_from_textbox"));
3268 inputText.addActionListener(this);
3269 Menu outputTextboxMenu = new Menu(
3270 MessageManager.getString("label.out_to_textbox"));
3271 for (String ff : FileFormats.getInstance().getWritableFormats(true))
3273 MenuItem item = new MenuItem(ff);
3275 item.addActionListener(new java.awt.event.ActionListener()
3278 public void actionPerformed(ActionEvent e)
3280 outputText_actionPerformed(e);
3284 outputTextboxMenu.add(item);
3286 closeMenuItem.addActionListener(this);
3287 loadApplication.addActionListener(this);
3288 loadTree.addActionListener(this);
3289 loadAnnotations.addActionListener(this);
3290 outputFeatures.addActionListener(this);
3291 outputAnnotations.addActionListener(this);
3294 * Configure Edit menu items and actions
3296 undoMenuItem.setEnabled(false);
3297 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3298 undoMenuItem.addActionListener(this);
3299 redoMenuItem.setEnabled(false);
3300 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3301 redoMenuItem.addActionListener(this);
3302 copy.setLabel(MessageManager.getString("action.copy"));
3303 copy.addActionListener(this);
3304 cut.setLabel(MessageManager.getString("action.cut"));
3305 cut.addActionListener(this);
3306 delete.setLabel(MessageManager.getString("action.delete"));
3307 delete.addActionListener(this);
3308 pasteMenu.setLabel(MessageManager.getString("action.paste"));
3309 pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3310 pasteNew.addActionListener(this);
3311 pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3312 pasteThis.addActionListener(this);
3313 remove2LeftMenuItem.setLabel(MessageManager
3314 .getString("action.remove_left"));
3315 remove2LeftMenuItem.addActionListener(this);
3316 remove2RightMenuItem.setLabel(MessageManager
3317 .getString("action.remove_right"));
3318 remove2RightMenuItem.addActionListener(this);
3319 removeGappedColumnMenuItem.setLabel(MessageManager
3320 .getString("action.remove_empty_columns"));
3321 removeGappedColumnMenuItem.addActionListener(this);
3322 removeAllGapsMenuItem.setLabel(MessageManager
3323 .getString("action.remove_all_gaps"));
3324 removeAllGapsMenuItem.addActionListener(this);
3325 removeRedundancyMenuItem.setLabel(MessageManager
3326 .getString("action.remove_redundancy"));
3327 removeRedundancyMenuItem.addActionListener(this);
3330 * Configure Select menu items and actions
3332 findMenuItem.setLabel(MessageManager.getString("action.find"));
3333 findMenuItem.addActionListener(this);
3334 selectAllSequenceMenuItem.addActionListener(this);
3335 deselectAllSequenceMenuItem.addActionListener(this);
3336 invertSequenceMenuItem.setLabel(MessageManager
3337 .getString("action.invert_sequence_selection"));
3338 invertSequenceMenuItem.addActionListener(this);
3339 invertColSel.setLabel(MessageManager
3340 .getString("action.invert_column_selection"));
3341 invertColSel.addActionListener(this);
3342 deleteGroups.setLabel(MessageManager
3343 .getString("action.undefine_groups"));
3344 deleteGroups.addActionListener(this);
3345 grpsFromSelection.setLabel(MessageManager
3346 .getString("action.make_groups_selection"));
3347 grpsFromSelection.addActionListener(this);
3348 createGroup.setLabel(MessageManager.getString("action.create_group"));
3349 unGroup.setLabel(MessageManager.getString("action.remove_group"));
3350 annotationColumnSelection.setLabel(MessageManager
3351 .getString("action.select_by_annotation"));
3352 annotationColumnSelection.addActionListener(this);
3355 * Configure View menu items and actions
3357 newView.setLabel(MessageManager.getString("action.new_view"));
3358 newView.addActionListener(this);
3359 Menu showMenu = new Menu(MessageManager.getString("action.show"));
3360 showColumns.setLabel(MessageManager.getString("label.all_columns"));
3361 showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3362 Menu hideMenu = new Menu(MessageManager.getString("action.hide"));
3364 .setLabel(MessageManager.getString("label.selected_columns"));
3365 hideSequences.setLabel(MessageManager
3366 .getString("label.selected_sequences"));
3367 hideAllButSelection.setLabel(MessageManager
3368 .getString("label.all_but_selected_region"));
3369 hideAllSelection.setLabel(MessageManager
3370 .getString("label.selected_region"));
3371 showAllHidden.setLabel(MessageManager
3372 .getString("label.all_sequences_columns"));
3373 showColumns.addActionListener(this);
3374 showSeqs.addActionListener(this);
3375 hideColumns.addActionListener(this);
3376 hideSequences.addActionListener(this);
3377 hideAllButSelection.addActionListener(this);
3378 hideAllSelection.addActionListener(this);
3379 showAllHidden.addActionListener(this);
3380 featureSettings.setLabel(MessageManager
3381 .getString("action.feature_settings"));
3382 featureSettings.addActionListener(this);
3383 sequenceFeatures.setLabel(MessageManager
3384 .getString("label.show_sequence_features"));
3385 sequenceFeatures.addItemListener(this);
3386 sequenceFeatures.setState(false);
3387 followMouseOverFlag.setLabel(MessageManager
3388 .getString("label.automatic_scrolling"));
3389 followMouseOverFlag.addItemListener(this);
3390 alProperties.addActionListener(this);
3391 overviewMenuItem.setLabel(MessageManager
3392 .getString("label.overview_window"));
3393 overviewMenuItem.addActionListener(this);
3396 * Configure Annotations menu items and actions
3398 annotationPanelMenuItem.setLabel(MessageManager
3399 .getString("label.show_annotations"));
3400 annotationPanelMenuItem.addItemListener(this);
3401 showGroupConsensus.setLabel(MessageManager
3402 .getString("label.group_consensus"));
3403 showGroupConservation.setLabel(MessageManager
3404 .getString("label.group_conservation"));
3405 showConsensusHistogram.setLabel(MessageManager
3406 .getString("label.show_consensus_histogram"));
3407 showSequenceLogo.setLabel(MessageManager
3408 .getString("label.show_consensus_logo"));
3409 normSequenceLogo.setLabel(MessageManager
3410 .getString("label.norm_consensus_logo"));
3411 applyAutoAnnotationSettings.setLabel(MessageManager
3412 .getString("label.apply_all_groups"));
3413 applyAutoAnnotationSettings.setState(true);
3414 Menu autoAnnMenu = new Menu(
3415 MessageManager.getString("label.autocalculated_annotation"));
3416 showGroupConsensus.addItemListener(this);
3417 showGroupConservation.addItemListener(this);
3418 showConsensusHistogram.addItemListener(this);
3419 showSequenceLogo.addItemListener(this);
3420 normSequenceLogo.addItemListener(this);
3421 applyAutoAnnotationSettings.addItemListener(this);
3422 showAlignmentAnnotations = new CheckboxMenuItem(
3423 MessageManager.getString("label.show_all_al_annotations"));
3424 showSequenceAnnotations = new CheckboxMenuItem(
3425 MessageManager.getString("label.show_all_seq_annotations"));
3426 sortAnnBySequence = new CheckboxMenuItem(
3427 MessageManager.getString("label.sort_annotations_by_sequence"));
3428 sortAnnByLabel = new CheckboxMenuItem(
3429 MessageManager.getString("label.sort_annotations_by_label"));
3430 showAutoFirst = new CheckboxMenuItem(
3431 MessageManager.getString("label.show_first"));
3432 showAutoFirst.setState(false); // pending applet parameter
3433 setShowAutoCalculatedAbove(showAutoFirst.getState());
3434 showAutoLast = new CheckboxMenuItem(
3435 MessageManager.getString("label.show_last"));
3436 showAutoLast.setState(!showAutoFirst.getState());
3437 showAlignmentAnnotations.addItemListener(this);
3438 showSequenceAnnotations.addItemListener(this);
3439 sortAnnBySequence.addItemListener(this);
3440 sortAnnByLabel.addItemListener(this);
3441 showAutoFirst.addItemListener(this);
3442 showAutoLast.addItemListener(this);
3445 * Configure Format menu items and actions
3447 font.setLabel(MessageManager.getString("action.font"));
3448 font.addActionListener(this);
3449 scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3450 scaleAbove.setState(true);
3451 scaleAbove.setEnabled(false);
3452 scaleAbove.addItemListener(this);
3453 scaleLeft.setEnabled(false);
3454 scaleLeft.setState(true);
3455 scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3456 scaleLeft.addItemListener(this);
3457 scaleRight.setEnabled(false);
3458 scaleRight.setState(true);
3459 scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3460 scaleRight.addItemListener(this);
3461 viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
3462 viewBoxesMenuItem.setState(true);
3463 viewBoxesMenuItem.addItemListener(this);
3464 viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
3465 viewTextMenuItem.setState(true);
3466 viewTextMenuItem.addItemListener(this);
3467 colourTextMenuItem.setLabel(MessageManager
3468 .getString("label.colour_text"));
3469 colourTextMenuItem.addItemListener(this);
3470 displayNonconservedMenuItem.setLabel(MessageManager
3471 .getString("label.show_non_conserved"));
3472 displayNonconservedMenuItem.addItemListener(this);
3473 wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3474 wrapMenuItem.addItemListener(this);
3475 renderGapsMenuItem.setLabel(MessageManager
3476 .getString("action.show_gaps"));
3477 renderGapsMenuItem.setState(true);
3478 renderGapsMenuItem.addItemListener(this);
3479 centreColumnLabelFlag.setLabel(MessageManager
3480 .getString("label.centre_column_labels"));
3481 centreColumnLabelFlag.addItemListener(this);
3482 seqLimits.setState(true);
3483 seqLimits.setLabel(MessageManager
3484 .getString("label.show_sequence_limits"));
3485 seqLimits.addItemListener(this);
3488 * Configure Colour menu items and actions
3490 applyToAllGroups.setLabel(MessageManager
3491 .getString("label.apply_colour_to_all_groups"));
3492 applyToAllGroups.setState(true);
3493 applyToAllGroups.addItemListener(this);
3494 clustalColour.setLabel(MessageManager
3495 .getString("label.colourScheme_clustal"));
3496 clustalColour.addActionListener(this);
3497 zappoColour.setLabel(MessageManager
3498 .getString("label.colourScheme_zappo"));
3499 zappoColour.addActionListener(this);
3500 taylorColour.setLabel(MessageManager
3501 .getString("label.colourScheme_taylor"));
3502 taylorColour.addActionListener(this);
3503 hydrophobicityColour.setLabel(MessageManager
3504 .getString("label.colourScheme_hydrophobic"));
3505 hydrophobicityColour.addActionListener(this);
3506 helixColour.setLabel(MessageManager
3507 .getString("label.colourScheme_helix_propensity"));
3508 helixColour.addActionListener(this);
3509 strandColour.setLabel(MessageManager
3510 .getString("label.colourScheme_strand_propensity"));
3511 strandColour.addActionListener(this);
3512 turnColour.setLabel(MessageManager
3513 .getString("label.colourScheme_turn_propensity"));
3514 turnColour.addActionListener(this);
3515 buriedColour.setLabel(MessageManager
3516 .getString("label.colourScheme_buried_index"));
3517 buriedColour.addActionListener(this);
3518 purinePyrimidineColour.setLabel(MessageManager
3519 .getString("label.colourScheme_purine/pyrimidine"));
3520 purinePyrimidineColour.addActionListener(this);
3521 // RNAInteractionColour.setLabel(MessageManager
3522 // .getString("label.rna_interaction"));
3523 // RNAInteractionColour.addActionListener(this);
3524 RNAHelixColour.setLabel(MessageManager
3525 .getString("label.colourScheme_rna_helices"));
3526 RNAHelixColour.addActionListener(this);
3527 userDefinedColour.setLabel(MessageManager
3528 .getString("action.user_defined"));
3529 userDefinedColour.addActionListener(this);
3530 PIDColour.setLabel(MessageManager
3531 .getString("label.colourScheme_%_identity"));
3532 PIDColour.addActionListener(this);
3533 BLOSUM62Colour.setLabel(MessageManager
3534 .getString("label.colourScheme_blosum62"));
3535 BLOSUM62Colour.addActionListener(this);
3536 tcoffeeColour.setLabel(MessageManager
3537 .getString("label.colourScheme_t-coffee_scores"));
3538 // it will be enabled only if a score file is provided
3539 tcoffeeColour.setEnabled(false);
3540 tcoffeeColour.addActionListener(this);
3541 conservationMenuItem.setLabel(MessageManager
3542 .getString("action.by_conservation"));
3543 conservationMenuItem.addItemListener(this);
3544 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3545 noColourmenuItem.addActionListener(this);
3546 abovePIDThreshold.setLabel(MessageManager
3547 .getString("label.above_identity_threshold"));
3548 abovePIDThreshold.addItemListener(this);
3549 nucleotideColour.setLabel(MessageManager
3550 .getString("label.colourScheme_nucleotide"));
3551 nucleotideColour.addActionListener(this);
3552 modifyPID.setLabel(MessageManager
3553 .getString("label.modify_identity_threshold"));
3554 modifyPID.setEnabled(abovePIDThreshold.getState());
3555 modifyPID.addActionListener(this);
3556 modifyConservation.setLabel(MessageManager
3557 .getString("label.modify_conservation_threshold"));
3558 modifyConservation.setEnabled(conservationMenuItem.getState());
3559 modifyConservation.addActionListener(this);
3560 annotationColour.setLabel(MessageManager
3561 .getString("action.by_annotation"));
3562 annotationColour.addActionListener(this);
3565 * Configure Calculate menu items and actions
3567 sortPairwiseMenuItem.setLabel(MessageManager
3568 .getString("action.by_pairwise_id"));
3569 sortPairwiseMenuItem.addActionListener(this);
3570 sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
3571 sortIDMenuItem.addActionListener(this);
3572 sortLengthMenuItem.setLabel(MessageManager
3573 .getString("action.by_length"));
3574 sortLengthMenuItem.addActionListener(this);
3575 sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3576 sortGroupMenuItem.addActionListener(this);
3577 pairwiseAlignmentMenuItem.setLabel(MessageManager
3578 .getString("action.pairwise_alignment"));
3579 pairwiseAlignmentMenuItem.addActionListener(this);
3580 PCAMenuItem.setLabel(MessageManager
3581 .getString("label.principal_component_analysis"));
3582 PCAMenuItem.addActionListener(this);
3583 autoCalculate = new CheckboxMenuItem(
3584 MessageManager.getString("label.autocalculate_consensus"), true);
3585 averageDistanceTreeMenuItem.setLabel(MessageManager
3586 .getString("label.average_distance_identity"));
3587 averageDistanceTreeMenuItem.addActionListener(this);
3588 neighbourTreeMenuItem.setLabel(MessageManager
3589 .getString("label.neighbour_joining_identity"));
3590 neighbourTreeMenuItem.addActionListener(this);
3591 avDistanceTreeBlosumMenuItem.setLabel(MessageManager
3592 .getString("label.average_distance_blosum62"));
3593 avDistanceTreeBlosumMenuItem.addActionListener(this);
3594 njTreeBlosumMenuItem.setLabel(MessageManager
3595 .getString("label.neighbour_blosum62"));
3596 njTreeBlosumMenuItem.addActionListener(this);
3597 sortByTreeMenu.setLabel(MessageManager
3598 .getString("action.by_tree_order"));
3599 Menu sortMenu = new Menu(MessageManager.getString("action.sort"));
3600 Menu calculateTreeMenu = new Menu(
3601 MessageManager.getString("action.calculate_tree"));
3602 autoCalculate.addItemListener(this);
3603 sortByTree.addItemListener(this);
3606 * Configure Help menu items and actions
3608 Menu helpMenu = new Menu(MessageManager.getString("action.help"));
3609 documentation.setLabel(MessageManager.getString("label.documentation"));
3610 documentation.addActionListener(this);
3611 about.setLabel(MessageManager.getString("label.about"));
3612 about.addActionListener(this);
3615 * Add top level menus to frame
3617 alignFrameMenuBar.add(fileMenu);
3618 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
3619 alignFrameMenuBar.add(editMenu);
3620 Menu selectMenu = new Menu(MessageManager.getString("action.select"));
3621 alignFrameMenuBar.add(selectMenu);
3622 Menu viewMenu = new Menu(MessageManager.getString("action.view"));
3623 alignFrameMenuBar.add(viewMenu);
3624 Menu annotationsMenu = new Menu(
3625 MessageManager.getString("action.annotations"));
3626 alignFrameMenuBar.add(annotationsMenu);
3627 Menu formatMenu = new Menu(MessageManager.getString("action.format"));
3628 alignFrameMenuBar.add(formatMenu);
3629 Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
3630 alignFrameMenuBar.add(colourMenu);
3631 Menu calculateMenu = new Menu(
3632 MessageManager.getString("action.calculate"));
3633 alignFrameMenuBar.add(calculateMenu);
3634 alignFrameMenuBar.add(helpMenu);
3639 fileMenu.add(inputText);
3640 fileMenu.add(loadTree);
3641 fileMenu.add(loadAnnotations);
3642 fileMenu.addSeparator();
3643 fileMenu.add(outputTextboxMenu);
3644 fileMenu.add(outputFeatures);
3645 fileMenu.add(outputAnnotations);
3646 if (jalviewServletURL != null)
3648 fileMenu.add(loadApplication);
3650 fileMenu.addSeparator();
3651 fileMenu.add(closeMenuItem);
3656 editMenu.add(undoMenuItem);
3657 editMenu.add(redoMenuItem);
3660 pasteMenu.add(pasteNew);
3661 pasteMenu.add(pasteThis);
3662 editMenu.add(pasteMenu);
3663 editMenu.add(delete);
3664 editMenu.addSeparator();
3665 editMenu.add(remove2LeftMenuItem);
3666 editMenu.add(remove2RightMenuItem);
3667 editMenu.add(removeGappedColumnMenuItem);
3668 editMenu.add(removeAllGapsMenuItem);
3669 editMenu.add(removeRedundancyMenuItem);
3674 selectMenu.add(findMenuItem);
3675 selectMenu.addSeparator();
3676 selectMenu.add(selectAllSequenceMenuItem);
3677 selectMenu.add(deselectAllSequenceMenuItem);
3678 selectMenu.add(invertSequenceMenuItem);
3679 selectMenu.add(invertColSel);
3680 selectMenu.add(createGroup);
3681 selectMenu.add(unGroup);
3682 selectMenu.add(grpsFromSelection);
3683 selectMenu.add(deleteGroups);
3684 selectMenu.add(annotationColumnSelection);
3689 viewMenu.add(newView);
3690 viewMenu.addSeparator();
3691 showMenu.add(showColumns);
3692 showMenu.add(showSeqs);
3693 showMenu.add(showAllHidden);
3694 viewMenu.add(showMenu);
3695 hideMenu.add(hideColumns);
3696 hideMenu.add(hideSequences);
3697 hideMenu.add(hideAllSelection);
3698 hideMenu.add(hideAllButSelection);
3699 viewMenu.add(hideMenu);
3700 viewMenu.addSeparator();
3701 viewMenu.add(followMouseOverFlag);
3702 viewMenu.addSeparator();
3703 viewMenu.add(sequenceFeatures);
3704 viewMenu.add(featureSettings);
3705 viewMenu.addSeparator();
3706 viewMenu.add(alProperties);
3707 viewMenu.addSeparator();
3708 viewMenu.add(overviewMenuItem);
3713 annotationsMenu.add(annotationPanelMenuItem);
3714 annotationsMenu.addSeparator();
3715 annotationsMenu.add(showAlignmentAnnotations);
3716 annotationsMenu.add(showSequenceAnnotations);
3717 annotationsMenu.add(sortAnnBySequence);
3718 annotationsMenu.add(sortAnnByLabel);
3719 annotationsMenu.addSeparator();
3720 autoAnnMenu.add(showAutoFirst);
3721 autoAnnMenu.add(showAutoLast);
3722 autoAnnMenu.addSeparator();
3723 autoAnnMenu.add(applyAutoAnnotationSettings);
3724 autoAnnMenu.add(showConsensusHistogram);
3725 autoAnnMenu.add(showSequenceLogo);
3726 autoAnnMenu.add(normSequenceLogo);
3727 autoAnnMenu.addSeparator();
3728 autoAnnMenu.add(showGroupConservation);
3729 autoAnnMenu.add(showGroupConsensus);
3730 annotationsMenu.add(autoAnnMenu);
3735 formatMenu.add(font);
3736 formatMenu.add(seqLimits);
3737 formatMenu.add(wrapMenuItem);
3738 formatMenu.add(scaleAbove);
3739 formatMenu.add(scaleLeft);
3740 formatMenu.add(scaleRight);
3741 formatMenu.add(viewBoxesMenuItem);
3742 formatMenu.add(viewTextMenuItem);
3743 formatMenu.add(colourTextMenuItem);
3744 formatMenu.add(displayNonconservedMenuItem);
3745 formatMenu.add(renderGapsMenuItem);
3746 formatMenu.add(centreColumnLabelFlag);
3751 colourMenu.add(applyToAllGroups);
3752 colourMenu.addSeparator();
3753 colourMenu.add(noColourmenuItem);
3754 colourMenu.add(clustalColour);
3755 colourMenu.add(BLOSUM62Colour);
3756 colourMenu.add(PIDColour);
3757 colourMenu.add(zappoColour);
3758 colourMenu.add(taylorColour);
3759 colourMenu.add(hydrophobicityColour);
3760 colourMenu.add(helixColour);
3761 colourMenu.add(strandColour);
3762 colourMenu.add(turnColour);
3763 colourMenu.add(buriedColour);
3764 colourMenu.add(nucleotideColour);
3765 colourMenu.add(purinePyrimidineColour);
3766 // colourMenu.add(RNAInteractionColour);
3767 colourMenu.add(tcoffeeColour);
3768 colourMenu.add(userDefinedColour);
3769 colourMenu.addSeparator();
3770 colourMenu.add(conservationMenuItem);
3771 colourMenu.add(modifyConservation);
3772 colourMenu.add(abovePIDThreshold);
3773 colourMenu.add(modifyPID);
3774 colourMenu.add(annotationColour);
3775 colourMenu.add(RNAHelixColour);
3780 sortMenu.add(sortIDMenuItem);
3781 sortMenu.add(sortLengthMenuItem);
3782 sortMenu.add(sortByTreeMenu);
3783 sortMenu.add(sortGroupMenuItem);
3784 sortMenu.add(sortPairwiseMenuItem);
3785 calculateMenu.add(sortMenu);
3786 calculateTreeMenu.add(averageDistanceTreeMenuItem);
3787 calculateTreeMenu.add(neighbourTreeMenuItem);
3788 calculateTreeMenu.add(avDistanceTreeBlosumMenuItem);
3789 calculateTreeMenu.add(njTreeBlosumMenuItem);
3790 calculateMenu.add(calculateTreeMenu);
3791 calculateMenu.addSeparator();
3792 calculateMenu.add(pairwiseAlignmentMenuItem);
3793 calculateMenu.add(PCAMenuItem);
3794 calculateMenu.add(autoCalculate);
3795 calculateMenu.add(sortByTree);
3800 helpMenu.add(documentation);
3801 helpMenu.add(about);
3806 statusBar.setBackground(Color.white);
3807 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3808 statusBar.setText(MessageManager.getString("label.status_bar"));
3809 this.add(statusBar, BorderLayout.SOUTH);
3813 public void setStatus(String string)
3815 statusBar.setText(string);
3818 MenuItem featureSettings = new MenuItem();
3820 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3822 MenuItem annotationColour = new MenuItem();
3824 MenuItem annotationColumnSelection = new MenuItem();
3826 MenuItem invertColSel = new MenuItem();
3828 MenuItem showColumns = new MenuItem();
3830 MenuItem showSeqs = new MenuItem();
3832 MenuItem hideColumns = new MenuItem();
3834 MenuItem hideSequences = new MenuItem();
3836 MenuItem hideAllButSelection = new MenuItem();
3838 MenuItem hideAllSelection = new MenuItem();
3840 MenuItem showAllHidden = new MenuItem();
3842 MenuItem newView = new MenuItem();
3844 private CheckboxMenuItem showAlignmentAnnotations;
3846 private CheckboxMenuItem showSequenceAnnotations;
3848 private CheckboxMenuItem sortAnnBySequence;
3850 private CheckboxMenuItem sortAnnByLabel;
3852 private CheckboxMenuItem showAutoFirst;
3854 private CheckboxMenuItem showAutoLast;
3856 private SplitFrame splitFrame;
3859 * Attach the alignFrame panels after embedding menus, if necessary. This used
3860 * to be called setEmbedded, but is now creates the dropdown menus in a
3861 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3863 * @param reallyEmbedded
3864 * true to attach the view to the applet area on the page rather than
3867 public void createAlignFrameWindow(boolean reallyEmbedded)
3871 embedAlignFrameInApplet(viewport.applet);
3876 // test and embed menu bar if necessary.
3878 if (embedMenuIfNeeded(alignPanel))
3881 * adjust for status bar height too. ? pointless as overridden by layout
3884 alignPanel.setSize(getSize().width,
3885 getSize().height - statusBar.getHeight());
3887 add(statusBar, BorderLayout.SOUTH);
3888 add(alignPanel, BorderLayout.CENTER);
3889 // and register with the applet so it can pass external API calls to us
3890 jalview.bin.JalviewLite.addFrame(this, this.getTitle(), frameWidth,
3896 * Add the components of this AlignFrame to the applet container.
3900 public void embedAlignFrameInApplet(final JalviewLite theApplet)
3903 // Explicitly build the embedded menu panel for the on-page applet
3905 // view cannot be closed if its actually on the page
3906 fileMenu.remove(closeMenuItem);
3907 fileMenu.remove(3); // Remove Separator
3908 // construct embedded menu, using default font
3909 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
3910 // and actually add the components to the applet area
3911 theApplet.setLayout(new BorderLayout());
3912 theApplet.add(embeddedMenu, BorderLayout.NORTH);
3913 theApplet.add(statusBar, BorderLayout.SOUTH);
3914 // TODO should size be left to the layout manager?
3915 alignPanel.setSize(theApplet.getSize().width,
3916 theApplet.getSize().height - embeddedMenu.getHeight()
3917 - statusBar.getHeight());
3918 theApplet.add(alignPanel, BorderLayout.CENTER);
3919 final AlignFrame me = this;
3920 theApplet.addFocusListener(new FocusListener()
3924 public void focusLost(FocusEvent e)
3926 if (theApplet.currentAlignFrame == me)
3928 theApplet.currentAlignFrame = null;
3933 public void focusGained(FocusEvent e)
3935 theApplet.currentAlignFrame = me;
3938 theApplet.validate();
3942 * create a new binding between structures in an existing jmol viewer instance
3943 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3944 * this does not open a new Jmol window, or modify the display of the
3945 * structures in the original jmol window. Note This method doesn't work
3946 * without an additional javascript library to exchange messages between the
3947 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3950 * JmolViewer instance
3951 * @param sequenceIds
3952 * - sequence Ids to search for associations
3954 public SequenceStructureBinding addStructureViewInstance(
3955 Object jmolviewer, String[] sequenceIds)
3957 Viewer viewer = null;
3960 viewer = (Viewer) jmolviewer;
3961 } catch (ClassCastException ex)
3963 System.err.println("Unsupported viewer object :"
3964 + jmolviewer.getClass());
3968 System.err.println("Can't use this object as a structure viewer:"
3969 + jmolviewer.getClass());
3972 SequenceI[] seqs = null;
3973 if (sequenceIds == null || sequenceIds.length == 0)
3975 seqs = viewport.getAlignment().getSequencesArray();
3979 Vector sqi = new Vector();
3980 AlignmentI al = viewport.getAlignment();
3981 for (int sid = 0; sid < sequenceIds.length; sid++)
3983 SequenceI sq = al.findName(sequenceIds[sid]);
3991 seqs = new SequenceI[sqi.size()];
3992 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
3994 seqs[sid] = (SequenceI) sqi.elementAt(sid);
4002 AAStructureBindingModel jmv = null;
4003 // TODO: search for a jmv that involves viewer
4005 { // create a new viewer/jalview binding.
4006 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] { seqs });
4013 * bind a pdb file to a sequence in the current view
4016 * - sequenceId within the dataset.
4017 * @param pdbEntryString
4018 * - the short name for the PDB file
4020 * - pdb file - either a URL or a valid PDB file.
4021 * @return true if binding was as success TODO: consider making an exception
4022 * structure for indicating when PDB parsing or sequenceId location
4025 public boolean addPdbFile(String sequenceId, String pdbEntryString,
4028 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
4029 boolean needtoadd = false;
4030 if (toaddpdb != null)
4032 Vector pdbe = toaddpdb.getAllPDBEntries();
4033 PDBEntry pdbentry = null;
4034 if (pdbe != null && pdbe.size() > 0)
4036 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
4038 pdbentry = (PDBEntry) pdbe.elementAt(pe);
4039 if (!pdbentry.getId().equals(pdbEntryString)
4040 && !pdbentry.getFile().equals(pdbFile))
4050 if (pdbentry == null)
4052 pdbentry = new PDBEntry();
4053 pdbentry.setId(pdbEntryString);
4054 pdbentry.setFile(pdbFile);
4055 needtoadd = true; // add this new entry to sequence.
4057 // resolve data source
4058 // TODO: this code should be a refactored to an io package
4059 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(
4060 pdbFile, FileFormat.PDB);
4061 if (protocol == null)
4067 pdbentry.setProperty("protocol", protocol);
4068 toaddpdb.addPDBId(pdbentry);
4069 alignPanel.getStructureSelectionManager()
4070 .registerPDBEntry(pdbentry);
4076 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
4080 Vector sequences = new Vector();
4081 for (int i = 0; i < seqs.length; i++)
4083 if (seqs[i] != null)
4085 sequences.addElement(new Object[] { seqs[i],
4086 (chains != null) ? chains[i] : null });
4089 seqs = new SequenceI[sequences.size()];
4090 chains = new String[sequences.size()];
4091 for (int i = 0, isize = sequences.size(); i < isize; i++)
4093 Object[] oj = (Object[]) sequences.elementAt(i);
4095 seqs[i] = (SequenceI) oj[0];
4096 chains[i] = (String) oj[1];
4099 return new Object[] { seqs, chains };
4103 public void newStructureView(JalviewLite applet, PDBEntry pdb,
4104 SequenceI[] seqs, String[] chains, DataSourceType protocol)
4106 // Scrub any null sequences from the array
4107 Object[] sqch = cleanSeqChainArrays(seqs, chains);
4108 seqs = (SequenceI[]) sqch[0];
4109 chains = (String[]) sqch[1];
4110 if (seqs == null || seqs.length == 0)
4113 .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
4115 if (protocol == null)
4117 String sourceType = (String) pdb.getProperty("protocol");
4120 protocol = DataSourceType.valueOf(sourceType);
4121 } catch (IllegalArgumentException e)
4125 if (protocol == null)
4127 System.err.println("Couldn't work out protocol to open structure: "
4132 if (applet.useXtrnalSviewer)
4134 // register the association(s) and quit, don't create any windows.
4135 if (StructureSelectionManager.getStructureSelectionManager(applet)
4136 .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
4138 System.err.println("Failed to map " + pdb.getFile() + " ("
4139 + protocol + ") to any sequences");
4143 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
4145 // can only do alignments with Jmol
4146 // find the last jmol window assigned to this alignment
4147 AppletJmol ajm = null, tajm;
4148 Vector jmols = applet.getAppletWindow(AppletJmol.class);
4149 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
4151 tajm = (AppletJmol) jmols.elementAt(i);
4152 if (tajm.ap.alignFrame == this)
4161 .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
4162 // try and add the pdb structure
4167 // otherwise, create a new window
4168 if (applet.jmolAvailable)
4170 new AppletJmol(pdb, seqs, chains, alignPanel,
4172 applet.lastFrameX += 40;
4173 applet.lastFrameY += 40;
4177 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
4182 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
4183 SequenceI[][] seqs, String[][] chains, String[] protocols)
4185 // TODO Auto-generated method stub
4186 System.err.println("Aligned Structure View: Not yet implemented.");
4190 * modify the current selection, providing the user has not made a selection
4194 * - sequences from this alignment
4196 * - columns to be selected on the alignment
4198 public void select(SequenceGroup sel, ColumnSelection csel)
4200 alignPanel.seqPanel.selection(sel, csel, null);
4203 public void scrollTo(int row, int column)
4205 alignPanel.seqPanel.scrollTo(row, column);
4208 public void scrollToRow(int row)
4210 alignPanel.seqPanel.scrollToRow(row);
4213 public void scrollToColumn(int column)
4215 alignPanel.seqPanel.scrollToColumn(column);
4219 * @return the alignments unique ID.
4221 public String getSequenceSetId()
4223 return viewport.getSequenceSetId();
4227 * Load the (T-Coffee) score file from the specified url
4230 * File/URL/T-COFFEE score file contents
4231 * @throws IOException
4232 * @return true if alignment was annotated with data from source
4234 public boolean loadScoreFile(String source) throws IOException
4237 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
4238 AppletFormatAdapter.checkProtocol(source));
4239 if (!file.isValid())
4241 // TODO: raise dialog for gui
4242 System.err.println("Problems parsing T-Coffee scores: "
4243 + file.getWarningMessage());
4244 System.err.println("Origin was:\n" + source);
4249 * check that the score matrix matches the alignment dimensions
4252 if ((aln = viewport.getAlignment()) != null
4253 && (aln.getHeight() != file.getHeight() || aln.getWidth() != file
4256 // TODO: raise a dialog box here rather than bomb out.
4258 .println("The scores matrix does not match the alignment dimensions");
4262 // TODO add parameter to indicate if matching should be done
4263 if (file.annotateAlignment(alignPanel.getAlignment(), false))
4265 alignPanel.fontChanged();
4266 tcoffeeColour.setEnabled(true);
4267 // switch to this color
4268 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4273 System.err.println("Problems resolving T-Coffee scores:");
4274 if (file.getWarningMessage() != null)
4276 System.err.println(file.getWarningMessage());
4282 public SplitFrame getSplitFrame()
4284 return this.splitFrame;
4287 public void setSplitFrame(SplitFrame sf)
4289 this.splitFrame = sf;
4292 // may not need this
4294 public void setShowSeqFeatures(boolean b)
4296 // showSeqFeatures.setSelected(b);
4297 viewport.setShowSequenceFeatures(b);
4302 public void setMenusForViewport()
4304 // setMenusFromViewport(viewport);
4309 public void refreshFeatureUI(boolean enableIfNecessary)
4311 if (enableIfNecessary)
4313 sequenceFeatures.setState(true);
4314 alignPanel.av.setShowSequenceFeatures(true);
4319 public FeatureSettingsControllerI getFeatureSettingsUI()
4321 return alignPanel.av.featureSettings;