2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
25 import jalview.analysis.TreeBuilder;
26 import jalview.analysis.scoremodels.PIDModel;
27 import jalview.analysis.scoremodels.ScoreModels;
28 import jalview.api.AlignViewControllerGuiI;
29 import jalview.api.AlignViewControllerI;
30 import jalview.api.AlignViewportI;
31 import jalview.api.FeatureColourI;
32 import jalview.api.FeatureRenderer;
33 import jalview.api.FeatureSettingsControllerI;
34 import jalview.api.SequenceStructureBinding;
35 import jalview.bin.JalviewLite;
36 import jalview.commands.CommandI;
37 import jalview.commands.EditCommand;
38 import jalview.commands.EditCommand.Action;
39 import jalview.commands.OrderCommand;
40 import jalview.commands.RemoveGapColCommand;
41 import jalview.commands.RemoveGapsCommand;
42 import jalview.commands.SlideSequencesCommand;
43 import jalview.commands.TrimRegionCommand;
44 import jalview.datamodel.Alignment;
45 import jalview.datamodel.AlignmentAnnotation;
46 import jalview.datamodel.AlignmentI;
47 import jalview.datamodel.AlignmentOrder;
48 import jalview.datamodel.ColumnSelection;
49 import jalview.datamodel.HiddenColumns;
50 import jalview.datamodel.PDBEntry;
51 import jalview.datamodel.Sequence;
52 import jalview.datamodel.SequenceGroup;
53 import jalview.datamodel.SequenceI;
54 import jalview.io.AnnotationFile;
55 import jalview.io.AppletFormatAdapter;
56 import jalview.io.DataSourceType;
57 import jalview.io.FeaturesFile;
58 import jalview.io.FileFormat;
59 import jalview.io.FileFormatI;
60 import jalview.io.FileFormats;
61 import jalview.io.TCoffeeScoreFile;
62 import jalview.schemes.Blosum62ColourScheme;
63 import jalview.schemes.BuriedColourScheme;
64 import jalview.schemes.ClustalxColourScheme;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.HelixColourScheme;
67 import jalview.schemes.HydrophobicColourScheme;
68 import jalview.schemes.NucleotideColourScheme;
69 import jalview.schemes.PIDColourScheme;
70 import jalview.schemes.PurinePyrimidineColourScheme;
71 import jalview.schemes.RNAHelicesColour;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.ZappoColourScheme;
77 import jalview.structure.StructureSelectionManager;
78 import jalview.structures.models.AAStructureBindingModel;
79 import jalview.util.MappingUtils;
80 import jalview.util.MessageManager;
81 import jalview.viewmodel.AlignmentViewport;
82 import jalview.viewmodel.ViewportRanges;
84 import java.awt.BorderLayout;
85 import java.awt.Canvas;
86 import java.awt.CheckboxMenuItem;
87 import java.awt.Color;
88 import java.awt.FlowLayout;
90 import java.awt.FontMetrics;
91 import java.awt.Frame;
92 import java.awt.Graphics;
93 import java.awt.Label;
95 import java.awt.MenuBar;
96 import java.awt.MenuItem;
97 import java.awt.Panel;
98 import java.awt.event.ActionEvent;
99 import java.awt.event.ActionListener;
100 import java.awt.event.FocusEvent;
101 import java.awt.event.FocusListener;
102 import java.awt.event.ItemEvent;
103 import java.awt.event.ItemListener;
104 import java.awt.event.KeyEvent;
105 import java.awt.event.KeyListener;
106 import java.awt.event.WindowAdapter;
107 import java.awt.event.WindowEvent;
108 import java.io.IOException;
110 import java.net.URLEncoder;
111 import java.util.Arrays;
112 import java.util.Deque;
113 import java.util.HashMap;
114 import java.util.List;
115 import java.util.Map;
116 import java.util.StringTokenizer;
117 import java.util.Vector;
119 import org.jmol.viewer.Viewer;
121 public class AlignFrame extends EmbmenuFrame implements ActionListener,
122 ItemListener, KeyListener, AlignViewControllerGuiI
124 public AlignViewControllerI avc;
126 public AlignmentPanel alignPanel;
128 public AlignViewport viewport;
130 // width and height may be overridden by applet parameters
131 int frameWidth = 700;
133 int frameHeight = 500;
135 String jalviewServletURL;
138 * Flag for showing autocalculated consensus above or below other consensus
141 private boolean showAutoCalculatedAbove;
143 private SequenceAnnotationOrder annotationSortOrder;
146 * Constructor that creates the frame and adds it to the display.
153 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
156 this(al, applet, title, embedded, true);
160 * Constructor that optionally allows the frame to be displayed or only
167 * @param addToDisplay
169 public AlignFrame(AlignmentI al, JalviewLite applet, String title,
170 boolean embedded, boolean addToDisplay)
172 this(al, null, null, applet, title, embedded, addToDisplay);
175 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
176 HiddenColumns hidden, JalviewLite applet, String title,
179 this(al, hiddenSeqs, hidden, applet, title, embedded, true);
182 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
183 HiddenColumns hidden, JalviewLite applet, String title,
184 boolean embedded, boolean addToDisplay)
188 jalviewServletURL = applet.getParameter("APPLICATION_URL");
194 } catch (Exception ex)
196 ex.printStackTrace();
198 // need to get window geometry before we calculate alignment layout
204 param = applet.getParameter("windowWidth");
207 int width = Integer.parseInt(param);
210 param = applet.getParameter("windowHeight");
213 int height = Integer.parseInt(param);
214 frameHeight = height;
216 } catch (Exception ex)
220 viewport = new AlignViewport(al, applet);
222 if (hiddenSeqs != null && hiddenSeqs.length > 0)
224 viewport.hideSequence(hiddenSeqs);
228 viewport.getAlignment().setHiddenColumns(hidden);
230 viewport.setScaleAboveWrapped(scaleAbove.getState());
232 alignPanel = new AlignmentPanel(this, viewport);
233 avc = new jalview.controller.AlignViewController(this, viewport,
235 viewport.updateConservation(alignPanel);
236 viewport.updateConsensus(alignPanel);
238 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
239 followMouseOverFlag.setState(viewport.isFollowHighlight());
240 showGroupConsensus.setState(viewport.isShowGroupConsensus());
241 showGroupConservation.setState(viewport.isShowGroupConservation());
242 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
243 showSequenceLogo.setState(viewport.isShowSequenceLogo());
244 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
245 applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
246 annotationPanelMenuItem.setState(viewport.isShowAnnotation());
247 showAlignmentAnnotations.setEnabled(annotationPanelMenuItem.getState());
248 showSequenceAnnotations.setEnabled(annotationPanelMenuItem.getState());
249 showAlignmentAnnotations.setState(true);
250 showSequenceAnnotations.setState(false);
252 seqLimits.setState(viewport.getShowJVSuffix());
256 String param = applet.getParameter("sortBy");
259 if (param.equalsIgnoreCase("Id"))
261 sortIDMenuItem_actionPerformed();
263 else if (param.equalsIgnoreCase("Pairwise Identity"))
265 sortPairwiseMenuItem_actionPerformed();
267 else if (param.equalsIgnoreCase("Length"))
269 sortLengthMenuItem_actionPerformed();
273 param = applet.getParameter("wrap");
276 if (param.equalsIgnoreCase("true"))
278 wrapMenuItem.setState(true);
279 wrapMenuItem_actionPerformed();
282 param = applet.getParameter("centrecolumnlabels");
285 centreColumnLabelFlag.setState(true);
286 centreColumnLabelFlag_stateChanged();
290 if (viewport.getAlignment().isNucleotide())
292 conservationMenuItem.setEnabled(false);
293 clustalColour.setEnabled(false);
294 BLOSUM62Colour.setEnabled(false);
295 zappoColour.setEnabled(false);
296 taylorColour.setEnabled(false);
297 hydrophobicityColour.setEnabled(false);
298 helixColour.setEnabled(false);
299 strandColour.setEnabled(false);
300 turnColour.setEnabled(false);
301 buriedColour.setEnabled(false);
302 viewport.updateStrucConsensus(alignPanel);
303 if (viewport.getAlignment().hasRNAStructure())
305 RNAHelixColour.setEnabled(true);
309 RNAHelixColour.setEnabled(false);
314 RNAHelixColour.setEnabled(false);
315 purinePyrimidineColour.setEnabled(false);
316 nucleotideColour.setEnabled(false);
318 // Some JVMS send keyevents to Top frame or lowest panel,
319 // Havent worked out why yet. So add to both this frame and seqCanvas for
321 this.addKeyListener(this);
322 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
323 alignPanel.idPanel.idCanvas.addKeyListener(this);
324 alignPanel.scalePanel.addKeyListener(this);
325 alignPanel.annotationPanel.addKeyListener(this);
326 alignPanel.annotationPanelHolder.addKeyListener(this);
327 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
328 alignPanel.alabels.addKeyListener(this);
330 setAnnotationsVisibility();
334 addToDisplay(embedded);
341 public void addToDisplay(boolean embedded)
343 createAlignFrameWindow(embedded);
345 alignPanel.adjustAnnotationHeight();
346 alignPanel.paintAlignment(true, true);
349 public AlignViewport getAlignViewport()
354 public SeqCanvas getSeqcanvas()
356 return alignPanel.seqPanel.seqCanvas;
360 * Load a features file onto the alignment
363 * file URL, content, or other resolvable path
365 * is protocol for accessing data referred to by file
368 public boolean parseFeaturesFile(String file, DataSourceType type)
370 return parseFeaturesFile(file, type, true);
374 * Load a features file onto the alignment
377 * file URL, content, or other resolvable path
379 * is protocol for accessing data referred to by file
380 * @param autoenabledisplay
381 * when true, display features flag will be automatically enabled if
382 * features are loaded
383 * @return true if data parsed as a features file
385 public boolean parseFeaturesFile(String file, DataSourceType sourceType,
386 boolean autoenabledisplay)
388 boolean featuresFile = false;
391 Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
392 .getFeatureRenderer().getFeatureColours();
393 boolean relaxedIdMatching = viewport.applet
394 .getDefaultParameter("relaxedidmatch", false);
395 featuresFile = new FeaturesFile(file, sourceType).parse(
396 viewport.getAlignment(), colours, true, relaxedIdMatching);
397 } catch (Exception ex)
399 ex.printStackTrace();
404 if (autoenabledisplay)
406 viewport.setShowSequenceFeatures(true);
407 sequenceFeatures.setState(true);
409 if (alignPanel.seqPanel.seqCanvas.fr != null)
411 // update the min/max ranges where necessary
412 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
414 if (viewport.featureSettings != null)
416 viewport.featureSettings.refreshTable();
418 alignPanel.paintAlignment(true, true);
419 statusBar.setText(MessageManager
420 .getString("label.successfully_added_features_alignment"));
426 public void keyPressed(KeyEvent evt)
428 ViewportRanges ranges = viewport.getRanges();
430 if (viewport.cursorMode
431 && ((evt.getKeyCode() >= KeyEvent.VK_0
432 && evt.getKeyCode() <= KeyEvent.VK_9)
433 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
434 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
435 && Character.isDigit(evt.getKeyChar()))
437 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
440 switch (evt.getKeyCode())
442 case 27: // escape key
443 deselectAllSequenceMenuItem_actionPerformed();
445 alignPanel.alabels.cancelDrag();
448 if (evt.isControlDown() || evt.isMetaDown())
450 cut_actionPerformed();
454 if (viewport.cursorMode && !evt.isControlDown())
456 alignPanel.seqPanel.setCursorColumn();
458 if (evt.isControlDown() || evt.isMetaDown())
460 copy_actionPerformed();
464 if (evt.isControlDown())
466 paste(evt.isShiftDown());
470 if (evt.isControlDown() || evt.isMetaDown())
472 selectAllSequenceMenuItem_actionPerformed();
475 case KeyEvent.VK_DOWN:
476 if (viewport.cursorMode)
478 alignPanel.seqPanel.moveCursor(0, 1);
482 moveSelectedSequences(false);
487 if (viewport.cursorMode)
489 alignPanel.seqPanel.moveCursor(0, -1);
493 moveSelectedSequences(true);
497 case KeyEvent.VK_LEFT:
498 if (evt.isAltDown() || !viewport.cursorMode)
500 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
504 alignPanel.seqPanel.moveCursor(-1, 0);
508 case KeyEvent.VK_RIGHT:
509 if (evt.isAltDown() || !viewport.cursorMode)
511 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
515 alignPanel.seqPanel.moveCursor(1, 0);
519 case KeyEvent.VK_SPACE:
520 if (viewport.cursorMode)
522 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
523 || evt.isShiftDown() || evt.isAltDown());
527 case KeyEvent.VK_DELETE:
528 case KeyEvent.VK_BACK_SPACE:
529 if (viewport.cursorMode)
531 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
532 || evt.isShiftDown() || evt.isAltDown());
536 cut_actionPerformed();
537 alignPanel.seqPanel.seqCanvas.repaint();
542 if (viewport.cursorMode)
544 alignPanel.seqPanel.setCursorRow();
548 if (viewport.cursorMode)
550 alignPanel.seqPanel.setCursorPosition();
554 case KeyEvent.VK_ENTER:
555 case KeyEvent.VK_COMMA:
556 if (viewport.cursorMode)
558 alignPanel.seqPanel.setCursorRowAndColumn();
563 if (viewport.cursorMode)
565 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
569 if (viewport.cursorMode)
571 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
576 viewport.cursorMode = !viewport.cursorMode;
577 statusBar.setText(MessageManager
578 .formatMessage("label.keyboard_editing_mode", new String[]
579 { (viewport.cursorMode ? "on" : "off") }));
580 if (viewport.cursorMode)
582 alignPanel.seqPanel.seqCanvas.cursorX = ranges.getStartRes();
583 alignPanel.seqPanel.seqCanvas.cursorY = ranges.getStartSeq();
588 if (evt.isControlDown())
590 findMenuItem_actionPerformed();
596 boolean toggleSeqs = !evt.isControlDown();
597 boolean toggleCols = !evt.isShiftDown();
598 toggleHiddenRegions(toggleSeqs, toggleCols);
602 case KeyEvent.VK_PAGE_UP:
606 case KeyEvent.VK_PAGE_DOWN:
611 if (evt.isControlDown())
613 undoMenuItem_actionPerformed();
618 if (evt.isControlDown())
620 redoMenuItem_actionPerformed();
625 if (evt.isControlDown())
632 if (evt.isControlDown())
634 trimAlignment(false);
639 if (evt.isControlDown())
641 if (evt.isShiftDown())
643 this.removeAllGapsMenuItem_actionPerformed();
647 removeGappedColumnMenuItem_actionPerformed();
652 if (evt.isControlDown())
656 invertColSel_actionPerformed();
660 invertSequenceMenuItem_actionPerformed();
666 if (evt.isControlDown())
668 if (evt.isShiftDown())
670 this.unGroup_actionPerformed();
674 this.createGroup_actionPerformed();
680 if (evt.isControlDown())
682 this.deleteGroups_actionPerformed();
687 if (evt.isControlDown())
694 // TODO: repaint flags set only if the keystroke warrants it
695 alignPanel.paintAlignment(true, true);
699 * called by key handler and the hide all/show all menu items
704 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
706 boolean hide = false;
707 SequenceGroup sg = viewport.getSelectionGroup();
708 if (!toggleSeqs && !toggleCols)
710 // Hide everything by the current selection - this is a hack - we do the
711 // invert and then hide
712 // first check that there will be visible columns after the invert.
713 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
714 && sg.getStartRes() <= sg.getEndRes()))
716 // now invert the sequence set, if required - empty selection implies
717 // that no hiding is required.
720 invertSequenceMenuItem_actionPerformed();
721 sg = viewport.getSelectionGroup();
725 viewport.expandColSelection(sg, true);
726 // finally invert the column selection and get the new sequence
727 // selection and indicate it should be hidden.
728 invertColSel_actionPerformed();
735 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
738 viewport.hideAllSelectedSeqs();
740 else if (!(toggleCols && viewport.hasSelectedColumns()))
742 viewport.showAllHiddenSeqs();
748 if (viewport.hasSelectedColumns())
750 viewport.hideSelectedColumns();
753 viewport.setSelectionGroup(sg);
758 viewport.showAllHiddenColumns();
760 viewport.sendSelection();
765 public void keyReleased(KeyEvent evt)
770 public void keyTyped(KeyEvent evt)
775 public void itemStateChanged(ItemEvent evt)
777 final Object source = evt.getSource();
778 if (source == displayNonconservedMenuItem)
780 displayNonconservedMenuItem_actionPerformed();
782 else if (source == colourTextMenuItem)
784 colourTextMenuItem_actionPerformed();
786 else if (source == wrapMenuItem)
788 wrapMenuItem_actionPerformed();
790 else if (source == scaleAbove)
792 viewport.setScaleAboveWrapped(scaleAbove.getState());
794 else if (source == scaleLeft)
796 viewport.setScaleLeftWrapped(scaleLeft.getState());
798 else if (source == scaleRight)
800 viewport.setScaleRightWrapped(scaleRight.getState());
802 else if (source == seqLimits)
804 seqLimits_itemStateChanged();
806 else if (source == viewBoxesMenuItem)
808 viewport.setShowBoxes(viewBoxesMenuItem.getState());
810 else if (source == viewTextMenuItem)
812 viewport.setShowText(viewTextMenuItem.getState());
814 else if (source == renderGapsMenuItem)
816 viewport.setRenderGaps(renderGapsMenuItem.getState());
818 else if (source == annotationPanelMenuItem)
820 boolean showAnnotations = annotationPanelMenuItem.getState();
821 showAlignmentAnnotations.setEnabled(showAnnotations);
822 showSequenceAnnotations.setEnabled(showAnnotations);
823 viewport.setShowAnnotation(showAnnotations);
824 alignPanel.setAnnotationVisible(showAnnotations);
826 else if (source == sequenceFeatures)
828 viewport.setShowSequenceFeatures(sequenceFeatures.getState());
829 alignPanel.seqPanel.seqCanvas.repaint();
831 else if (source == showAlignmentAnnotations)
833 setAnnotationsVisibility();
835 else if (source == showSequenceAnnotations)
837 setAnnotationsVisibility();
839 else if (source == sortAnnBySequence)
841 boolean newState = sortAnnBySequence.getState();
842 sortAnnByLabel.setState(false);
843 setAnnotationSortOrder(
844 newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
845 : SequenceAnnotationOrder.NONE);
846 setViewportAnnotationOrder();
848 else if (source == sortAnnByLabel)
850 boolean newState = sortAnnByLabel.getState();
851 sortAnnBySequence.setState(false);
852 setAnnotationSortOrder(
853 newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
854 : SequenceAnnotationOrder.NONE);
855 setViewportAnnotationOrder();
857 else if (source == showAutoFirst)
859 showAutoLast.setState(!showAutoFirst.getState());
860 setShowAutoCalculatedAbove(showAutoFirst.getState());
861 setViewportAnnotationOrder();
863 else if (source == showAutoLast)
865 showAutoFirst.setState(!showAutoLast.getState());
866 setShowAutoCalculatedAbove(showAutoFirst.getState());
867 setViewportAnnotationOrder();
869 else if (source == conservationMenuItem)
871 conservationMenuItem_actionPerformed();
873 else if (source == abovePIDThreshold)
875 abovePIDThreshold_actionPerformed();
877 else if (source == applyToAllGroups)
879 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
881 else if (source == autoCalculate)
883 viewport.autoCalculateConsensus = autoCalculate.getState();
885 else if (source == sortByTree)
887 viewport.sortByTree = sortByTree.getState();
889 else if (source == this.centreColumnLabelFlag)
891 centreColumnLabelFlag_stateChanged();
893 else if (source == this.followMouseOverFlag)
895 mouseOverFlag_stateChanged();
897 else if (source == showGroupConsensus)
899 showGroupConsensus_actionPerformed();
901 else if (source == showGroupConservation)
903 showGroupConservation_actionPerformed();
905 else if (source == showSequenceLogo)
907 showSequenceLogo_actionPerformed();
909 else if (source == normSequenceLogo)
911 normSequenceLogo_actionPerformed();
913 else if (source == showConsensusHistogram)
915 showConsensusHistogram_actionPerformed();
917 else if (source == applyAutoAnnotationSettings)
919 applyAutoAnnotationSettings_actionPerformed();
921 // TODO: repaint flags set only if warranted
922 alignPanel.paintAlignment(true, true);
926 * Set the visibility state of sequence-related and/or alignment-related
927 * annotations depending on checkbox selections, and repaint.
931 private void setAnnotationsVisibility()
933 boolean showForAlignment = showAlignmentAnnotations.getState();
934 boolean showForSequences = showSequenceAnnotations.getState();
935 if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
937 for (AlignmentAnnotation aa : alignPanel.getAlignment()
938 .getAlignmentAnnotation())
940 boolean visible = (aa.sequenceRef == null ? showForAlignment
942 aa.visible = visible;
945 alignPanel.validateAnnotationDimensions(true);
950 private void setAnnotationSortOrder(SequenceAnnotationOrder order)
952 this.annotationSortOrder = order;
956 * Set flags on the viewport that control annotation ordering
958 private void setViewportAnnotationOrder()
960 this.alignPanel.av.setSortAnnotationsBy(this.annotationSortOrder);
962 .setShowAutocalculatedAbove(this.showAutoCalculatedAbove);
965 private void setShowAutoCalculatedAbove(boolean showAbove)
967 this.showAutoCalculatedAbove = showAbove;
970 private void mouseOverFlag_stateChanged()
972 viewport.setFollowHighlight(followMouseOverFlag.getState());
973 // TODO: could kick the scrollTo mechanism to reset view for current
977 private void centreColumnLabelFlag_stateChanged()
979 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
980 this.alignPanel.annotationPanel.repaint();
984 public void actionPerformed(ActionEvent evt)
986 viewport.applet.currentAlignFrame = this;
988 Object source = evt.getSource();
990 if (source == inputText)
992 inputText_actionPerformed();
994 else if (source == loadTree)
996 loadTree_actionPerformed();
998 else if (source == loadApplication)
1000 launchFullApplication();
1002 else if (source == loadAnnotations)
1006 else if (source == outputAnnotations)
1008 outputAnnotations(true);
1010 else if (source == outputFeatures)
1012 outputFeatures(true, "Jalview");
1014 else if (source == closeMenuItem)
1016 closeMenuItem_actionPerformed();
1018 else if (source == copy)
1020 copy_actionPerformed();
1022 else if (source == undoMenuItem)
1024 undoMenuItem_actionPerformed();
1026 else if (source == redoMenuItem)
1028 redoMenuItem_actionPerformed();
1030 else if (source == inputText)
1032 inputText_actionPerformed();
1034 else if (source == closeMenuItem)
1036 closeMenuItem_actionPerformed();
1038 else if (source == undoMenuItem)
1040 undoMenuItem_actionPerformed();
1042 else if (source == redoMenuItem)
1044 redoMenuItem_actionPerformed();
1046 else if (source == copy)
1048 copy_actionPerformed();
1050 else if (source == pasteNew)
1052 pasteNew_actionPerformed();
1054 else if (source == pasteThis)
1056 pasteThis_actionPerformed();
1058 else if (source == cut)
1060 cut_actionPerformed();
1062 else if (source == delete)
1064 delete_actionPerformed();
1066 else if (source == createGroup)
1068 createGroup_actionPerformed();
1070 else if (source == unGroup)
1072 unGroup_actionPerformed();
1074 else if (source == grpsFromSelection)
1076 makeGrpsFromSelection_actionPerformed();
1078 else if (source == deleteGroups)
1080 deleteGroups_actionPerformed();
1082 else if (source == selectAllSequenceMenuItem)
1084 selectAllSequenceMenuItem_actionPerformed();
1086 else if (source == deselectAllSequenceMenuItem)
1088 deselectAllSequenceMenuItem_actionPerformed();
1090 else if (source == invertSequenceMenuItem)
1092 invertSequenceMenuItem_actionPerformed();
1093 // uncomment to slave sequence selections in split frame
1094 // viewport.sendSelection();
1096 else if (source == invertColSel)
1098 viewport.invertColumnSelection();
1099 alignPanel.paintAlignment(false, false);
1100 viewport.sendSelection();
1102 else if (source == remove2LeftMenuItem)
1104 trimAlignment(true);
1106 else if (source == remove2RightMenuItem)
1108 trimAlignment(false);
1110 else if (source == removeGappedColumnMenuItem)
1112 removeGappedColumnMenuItem_actionPerformed();
1114 else if (source == removeAllGapsMenuItem)
1116 removeAllGapsMenuItem_actionPerformed();
1118 else if (source == findMenuItem)
1120 findMenuItem_actionPerformed();
1122 else if (source == font)
1124 new FontChooser(alignPanel);
1126 else if (source == newView)
1130 else if (source == showColumns)
1132 viewport.showAllHiddenColumns();
1133 alignPanel.paintAlignment(true, true);
1134 viewport.sendSelection();
1136 else if (source == showSeqs)
1138 viewport.showAllHiddenSeqs();
1139 alignPanel.paintAlignment(true, true);
1140 // uncomment if we want to slave sequence selections in split frame
1141 // viewport.sendSelection();
1143 else if (source == hideColumns)
1145 viewport.hideSelectedColumns();
1146 alignPanel.paintAlignment(true, true);
1147 viewport.sendSelection();
1149 else if (source == hideSequences
1150 && viewport.getSelectionGroup() != null)
1152 viewport.hideAllSelectedSeqs();
1153 alignPanel.paintAlignment(true, true);
1154 // uncomment if we want to slave sequence selections in split frame
1155 // viewport.sendSelection();
1157 else if (source == hideAllButSelection)
1159 toggleHiddenRegions(false, false);
1160 alignPanel.paintAlignment(true, true);
1161 viewport.sendSelection();
1163 else if (source == hideAllSelection)
1165 SequenceGroup sg = viewport.getSelectionGroup();
1166 viewport.expandColSelection(sg, false);
1167 viewport.hideAllSelectedSeqs();
1168 viewport.hideSelectedColumns();
1169 alignPanel.paintAlignment(true, true);
1170 viewport.sendSelection();
1172 else if (source == showAllHidden)
1174 viewport.showAllHiddenColumns();
1175 viewport.showAllHiddenSeqs();
1176 alignPanel.paintAlignment(true, true);
1177 viewport.sendSelection();
1179 else if (source == showGroupConsensus)
1181 showGroupConsensus_actionPerformed();
1183 else if (source == showGroupConservation)
1185 showGroupConservation_actionPerformed();
1187 else if (source == showSequenceLogo)
1189 showSequenceLogo_actionPerformed();
1191 else if (source == normSequenceLogo)
1193 normSequenceLogo_actionPerformed();
1195 else if (source == showConsensusHistogram)
1197 showConsensusHistogram_actionPerformed();
1199 else if (source == applyAutoAnnotationSettings)
1201 applyAutoAnnotationSettings_actionPerformed();
1203 else if (source == featureSettings)
1205 new FeatureSettings(alignPanel);
1207 else if (source == alProperties)
1209 StringBuffer contents = new jalview.io.AlignmentProperties(
1210 viewport.getAlignment()).formatAsString();
1211 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1212 cap.setText(contents.toString());
1213 Frame frame = new Frame();
1215 jalview.bin.JalviewLite.addFrame(frame, MessageManager
1216 .formatMessage("label.alignment_properties", new String[]
1217 { getTitle() }), 400, 250);
1219 else if (source == overviewMenuItem)
1221 overviewMenuItem_actionPerformed();
1223 else if (source == noColourmenuItem)
1227 else if (source == clustalColour)
1229 abovePIDThreshold.setState(false);
1230 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1232 else if (source == zappoColour)
1234 changeColour(new ZappoColourScheme());
1236 else if (source == taylorColour)
1238 changeColour(new TaylorColourScheme());
1240 else if (source == hydrophobicityColour)
1242 changeColour(new HydrophobicColourScheme());
1244 else if (source == helixColour)
1246 changeColour(new HelixColourScheme());
1248 else if (source == strandColour)
1250 changeColour(new StrandColourScheme());
1252 else if (source == turnColour)
1254 changeColour(new TurnColourScheme());
1256 else if (source == buriedColour)
1258 changeColour(new BuriedColourScheme());
1260 else if (source == nucleotideColour)
1262 changeColour(new NucleotideColourScheme());
1264 else if (source == purinePyrimidineColour)
1266 changeColour(new PurinePyrimidineColourScheme());
1268 // else if (source == RNAInteractionColour)
1270 // changeColour(new RNAInteractionColourScheme());
1272 else if (source == RNAHelixColour)
1274 changeColour(new RNAHelicesColour(viewport.getAlignment()));
1275 // new RNAHelicesColourChooser(viewport, alignPanel);
1277 else if (source == modifyPID)
1279 modifyPID_actionPerformed();
1281 else if (source == modifyConservation)
1283 modifyConservation_actionPerformed();
1285 else if (source == userDefinedColour)
1287 new UserDefinedColours(alignPanel, null);
1289 else if (source == PIDColour)
1291 changeColour(new PIDColourScheme());
1293 else if (source == BLOSUM62Colour)
1295 changeColour(new Blosum62ColourScheme());
1297 else if (source == tcoffeeColour)
1299 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1301 else if (source == annotationColour)
1303 new AnnotationColourChooser(viewport, alignPanel);
1305 else if (source == annotationColumnSelection)
1307 new AnnotationColumnChooser(viewport, alignPanel);
1309 else if (source == sortPairwiseMenuItem)
1311 sortPairwiseMenuItem_actionPerformed();
1313 else if (source == sortIDMenuItem)
1315 sortIDMenuItem_actionPerformed();
1317 else if (source == sortLengthMenuItem)
1319 sortLengthMenuItem_actionPerformed();
1321 else if (source == sortGroupMenuItem)
1323 sortGroupMenuItem_actionPerformed();
1325 else if (source == removeRedundancyMenuItem)
1327 removeRedundancyMenuItem_actionPerformed();
1329 else if (source == pairwiseAlignmentMenuItem)
1331 pairwiseAlignmentMenuItem_actionPerformed();
1333 else if (source == PCAMenuItem)
1335 PCAMenuItem_actionPerformed();
1337 else if (source == averageDistanceTreeMenuItem)
1339 averageDistanceTreeMenuItem_actionPerformed();
1341 else if (source == neighbourTreeMenuItem)
1343 neighbourTreeMenuItem_actionPerformed();
1345 else if (source == njTreeBlosumMenuItem)
1347 njTreeBlosumMenuItem_actionPerformed();
1349 else if (source == avDistanceTreeBlosumMenuItem)
1351 avTreeBlosumMenuItem_actionPerformed();
1353 else if (source == documentation)
1355 documentation_actionPerformed();
1357 else if (source == about)
1359 about_actionPerformed();
1364 public void inputText_actionPerformed()
1366 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1367 Frame frame = new Frame();
1369 jalview.bin.JalviewLite.addFrame(frame,
1370 MessageManager.getString("label.input_cut_paste"), 500, 500);
1373 protected void outputText_actionPerformed(ActionEvent e)
1375 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1376 Frame frame = new Frame();
1378 JalviewLite.addFrame(frame, MessageManager
1379 .formatMessage("label.alignment_output_command", new Object[]
1380 { e.getActionCommand() }), 600, 500);
1382 FileFormatI fileFormat = FileFormats.getInstance()
1383 .forName(e.getActionCommand());
1385 new AppletFormatAdapter(alignPanel).formatSequences(fileFormat,
1386 viewport.getAlignment(), viewport.getShowJVSuffix()));
1389 public void loadAnnotations()
1391 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1392 cap.setText(MessageManager
1393 .getString("label.paste_features_annotations_Tcoffee_here"));
1394 cap.setAnnotationImport();
1395 Frame frame = new Frame();
1397 jalview.bin.JalviewLite.addFrame(frame,
1398 MessageManager.getString("action.paste_annotations"), 400, 300);
1402 public String outputAnnotations(boolean displayTextbox)
1404 String annotation = new AnnotationFile()
1405 .printAnnotationsForView(viewport);
1409 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1410 Frame frame = new Frame();
1412 jalview.bin.JalviewLite.addFrame(frame,
1413 MessageManager.getString("label.annotations"), 600, 500);
1414 cap.setText(annotation);
1420 private Map<String, FeatureColourI> getDisplayedFeatureCols()
1422 if (alignPanel.getFeatureRenderer() != null
1423 && viewport.getFeaturesDisplayed() != null)
1425 return alignPanel.getFeatureRenderer().getDisplayedFeatureCols();
1431 private List<String> getDisplayedFeatureGroups()
1433 if (alignPanel.getFeatureRenderer() != null
1434 && viewport.getFeaturesDisplayed() != null)
1436 return alignPanel.getFeatureRenderer().getDisplayedFeatureGroups();
1442 public String outputFeatures(boolean displayTextbox, String format)
1445 FeaturesFile formatter = new FeaturesFile();
1446 if (format.equalsIgnoreCase("Jalview"))
1448 features = formatter.printJalviewFormat(
1449 viewport.getAlignment().getSequencesArray(),
1450 getDisplayedFeatureCols(), null, getDisplayedFeatureGroups(),
1455 features = formatter.printGffFormat(viewport.getAlignment()
1456 .getSequencesArray(), getDisplayedFeatureCols(),
1457 getDisplayedFeatureGroups(), true);
1462 boolean frimport = false;
1463 if (features == null || features.equals("No Features Visible"))
1465 features = "# No features visible - paste some and import them here.";
1469 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1472 cap.setAnnotationImport();
1474 Frame frame = new Frame();
1476 jalview.bin.JalviewLite.addFrame(frame,
1477 MessageManager.getString("label.features"), 600, 500);
1478 cap.setText(features);
1482 if (features == null)
1491 void launchFullApplication()
1493 StringBuffer url = new StringBuffer(jalviewServletURL);
1495 // allow servlet parameters to be passed in applet parameter
1496 String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
1498 url.append(firstSep);
1501 "open=" + appendProtocol(viewport.applet.getParameter("file")));
1503 if (viewport.applet.getParameter("features") != null)
1505 url.append("&features=");
1506 url.append(appendProtocol(viewport.applet.getParameter("features")));
1509 if (viewport.applet.getParameter("annotations") != null)
1511 url.append("&annotations=");
1513 appendProtocol(viewport.applet.getParameter("annotations")));
1516 if (viewport.applet.getParameter("jnetfile") != null
1517 || viewport.applet.getParameter("jpredfile") != null)
1519 url.append("&annotations=");
1520 url.append(appendProtocol(
1521 viewport.applet.getParameter("jnetfile") != null
1522 ? viewport.applet.getParameter("jnetfile")
1523 : viewport.applet.getParameter("jpredfile")));
1526 if (viewport.applet.getParameter("defaultColour") != null)
1528 url.append("&colour=" + removeWhiteSpace(
1529 viewport.applet.getParameter("defaultColour")));
1532 if (viewport.applet.getParameter("userDefinedColour") != null)
1534 url.append("&colour=" + removeWhiteSpace(
1535 viewport.applet.getParameter("userDefinedColour")));
1537 if (viewport.applet.getParameter("tree") != null)
1540 + appendProtocol(viewport.applet.getParameter("tree")));
1542 if (viewport.applet.getParameter("treeFile") != null)
1545 + appendProtocol(viewport.applet.getParameter("treeFile")));
1548 showURL(url.toString(), "FULL_APP");
1551 String removeWhiteSpace(String colour)
1553 StringBuffer sb = new StringBuffer();
1554 for (int i = 0; i < colour.length(); i++)
1556 if (Character.isWhitespace(colour.charAt(i)))
1562 sb.append(colour.charAt(i));
1566 return sb.toString();
1569 String appendProtocol(String url)
1574 url = URLEncoder.encode(url);
1577 * When we finally deprecate 1.1 compatibility, we can start to use
1578 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1579 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1580 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1581 * ex.printStackTrace(); }
1583 catch (java.net.MalformedURLException ex)
1585 url = viewport.applet.getCodeBase() + url;
1590 public void closeMenuItem_actionPerformed()
1592 PaintRefresher.RemoveComponent(alignPanel);
1593 if (alignPanel.seqPanel != null
1594 && alignPanel.seqPanel.seqCanvas != null)
1596 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1598 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1600 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1603 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1609 if (alignPanel != null && alignPanel.overviewPanel != null)
1611 alignPanel.overviewPanel.dispose();
1620 void updateEditMenuBar()
1623 if (viewport.getHistoryList().size() > 0)
1625 undoMenuItem.setEnabled(true);
1626 CommandI command = viewport.getHistoryList().peek();
1627 undoMenuItem.setLabel(MessageManager
1628 .formatMessage("label.undo_command", new Object[]
1629 { command.getDescription() }));
1633 undoMenuItem.setEnabled(false);
1634 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1637 if (viewport.getRedoList().size() > 0)
1639 redoMenuItem.setEnabled(true);
1641 CommandI command = viewport.getRedoList().peek();
1642 redoMenuItem.setLabel(MessageManager
1643 .formatMessage("label.redo_command", new Object[]
1644 { command.getDescription() }));
1648 redoMenuItem.setEnabled(false);
1649 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1657 public void addHistoryItem(CommandI command)
1659 if (command.getSize() > 0)
1661 viewport.addToHistoryList(command);
1662 viewport.clearRedoList();
1663 updateEditMenuBar();
1664 viewport.updateHiddenColumns();
1669 * TODO: JAL-1104 DOCUMENT ME!
1674 protected void undoMenuItem_actionPerformed()
1676 if (viewport.getHistoryList().isEmpty())
1681 CommandI command = viewport.getHistoryList().pop();
1682 viewport.addToRedoList(command);
1683 command.undoCommand(null);
1685 AlignmentViewport originalSource = getOriginatingSource(command);
1687 if (originalSource != viewport)
1690 .println("Warning: Viewport object mismatch whilst undoing");
1692 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1693 // viewport.getColumnSelection().getHiddenColumns()
1695 updateEditMenuBar();
1696 originalSource.firePropertyChange("alignment", null,
1697 originalSource.getAlignment().getSequences());
1701 * TODO: JAL-1104 DOCUMENT ME!
1706 protected void redoMenuItem_actionPerformed()
1708 if (viewport.getRedoList().isEmpty())
1713 CommandI command = viewport.getRedoList().pop();
1714 viewport.addToHistoryList(command);
1715 command.doCommand(null);
1717 AlignmentViewport originalSource = getOriginatingSource(command);
1719 if (originalSource != viewport)
1722 .println("Warning: Viewport object mismatch whilst re-doing");
1724 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1725 // viewport.getColumnSelection().getHiddenColumns()
1728 updateEditMenuBar();
1729 originalSource.firePropertyChange("alignment", null,
1730 originalSource.getAlignment().getSequences());
1733 AlignmentViewport getOriginatingSource(CommandI command)
1735 AlignmentViewport originalSource = null;
1736 // For sequence removal and addition, we need to fire
1737 // the property change event FROM the viewport where the
1738 // original alignment was altered
1739 AlignmentI al = null;
1740 if (command instanceof EditCommand)
1742 EditCommand editCommand = (EditCommand) command;
1743 al = editCommand.getAlignment();
1744 Vector comps = PaintRefresher.components
1745 .get(viewport.getSequenceSetId());
1746 for (int i = 0; i < comps.size(); i++)
1748 if (comps.elementAt(i) instanceof AlignmentPanel)
1750 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1752 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1759 if (originalSource == null)
1761 // The original view is closed, we must validate
1762 // the current view against the closed view first
1765 PaintRefresher.validateSequences(al, viewport.getAlignment());
1768 originalSource = viewport;
1771 return originalSource;
1775 * Move the currently selected sequences up or down one position in the
1780 public void moveSelectedSequences(boolean up)
1782 SequenceGroup sg = viewport.getSelectionGroup();
1787 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1788 up ? null : viewport.getHiddenRepSequences(), up);
1789 alignPanel.paintAlignment(true, false);
1792 * Also move cDNA/protein complement sequences
1794 AlignViewportI complement = viewport.getCodingComplement();
1795 if (complement != null)
1797 SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
1798 viewport, complement);
1799 complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
1800 up ? null : complement.getHiddenRepSequences(), up);
1801 getSplitFrame().getComplement(this).alignPanel.paintAlignment(true,
1806 synchronized void slideSequences(boolean right, int size)
1808 List<SequenceI> sg = new Vector<>();
1809 if (viewport.cursorMode)
1811 sg.add(viewport.getAlignment()
1812 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1814 else if (viewport.getSelectionGroup() != null
1815 && viewport.getSelectionGroup().getSize() != viewport
1816 .getAlignment().getHeight())
1818 sg = viewport.getSelectionGroup()
1819 .getSequences(viewport.getHiddenRepSequences());
1827 Vector<SequenceI> invertGroup = new Vector();
1829 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1831 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1833 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1837 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1839 SequenceI[] seqs2 = invertGroup
1840 .toArray(new SequenceI[invertGroup.size()]);
1841 for (int i = 0; i < invertGroup.size(); i++)
1843 seqs2[i] = invertGroup.elementAt(i);
1846 SlideSequencesCommand ssc;
1849 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1850 viewport.getGapCharacter());
1854 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1855 viewport.getGapCharacter());
1858 int groupAdjustment = 0;
1859 if (ssc.getGapsInsertedBegin() && right)
1861 if (viewport.cursorMode)
1863 alignPanel.seqPanel.moveCursor(size, 0);
1867 groupAdjustment = size;
1870 else if (!ssc.getGapsInsertedBegin() && !right)
1872 if (viewport.cursorMode)
1874 alignPanel.seqPanel.moveCursor(-size, 0);
1878 groupAdjustment = -size;
1882 if (groupAdjustment != 0)
1884 viewport.getSelectionGroup().setStartRes(
1885 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1886 viewport.getSelectionGroup().setEndRes(
1887 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1890 boolean appendHistoryItem = false;
1891 Deque<CommandI> historyList = viewport.getHistoryList();
1892 if (historyList != null && historyList.size() > 0
1893 && historyList.peek() instanceof SlideSequencesCommand)
1895 appendHistoryItem = ssc.appendSlideCommand(
1896 (SlideSequencesCommand) historyList.peek());
1899 if (!appendHistoryItem)
1901 addHistoryItem(ssc);
1907 static StringBuffer copiedSequences;
1909 static HiddenColumns copiedHiddenColumns;
1911 protected void copy_actionPerformed()
1913 if (viewport.getSelectionGroup() == null)
1918 SequenceGroup sg = viewport.getSelectionGroup();
1919 copiedSequences = new StringBuffer();
1920 Map<Integer, SequenceI> orderedSeqs = new HashMap<>();
1921 for (int i = 0; i < sg.getSize(); i++)
1923 SequenceI seq = sg.getSequenceAt(i);
1924 int index = viewport.getAlignment().findIndex(seq);
1925 orderedSeqs.put(index, seq);
1928 int index = 0, startRes, endRes;
1931 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1933 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1934 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
1936 // create new HiddenColumns object with copy of hidden regions
1937 // between startRes and endRes, offset by startRes
1938 copiedHiddenColumns = new HiddenColumns(
1939 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
1940 hiddenCutoff, hiddenOffset);
1944 copiedHiddenColumns = null;
1947 for (int i = 0; i < sg.getSize(); i++)
1949 SequenceI seq = null;
1953 if (orderedSeqs.containsKey(index))
1955 seq = orderedSeqs.get(index);
1966 // Returns residue following index if gap
1967 startRes = seq.findPosition(sg.getStartRes());
1970 // Need to find the residue preceeding index if gap
1973 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1975 ch = seq.getCharAt(j);
1976 if (!jalview.util.Comparison.isGap((ch)))
1984 endRes += seq.getStart() - 1;
1987 copiedSequences.append(seq.getName() + "\t" + startRes + "\t" + endRes
1988 + "\t" + seq.getSequenceAsString(sg.getStartRes(),
1995 protected void pasteNew_actionPerformed()
2000 protected void pasteThis_actionPerformed()
2005 void paste(boolean newAlignment)
2009 if (copiedSequences == null)
2014 StringTokenizer st = new StringTokenizer(copiedSequences.toString(),
2016 Vector seqs = new Vector();
2017 while (st.hasMoreElements())
2019 String name = st.nextToken();
2020 int start = Integer.parseInt(st.nextToken());
2021 int end = Integer.parseInt(st.nextToken());
2022 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
2024 SequenceI[] newSeqs = new SequenceI[seqs.size()];
2025 for (int i = 0; i < seqs.size(); i++)
2027 newSeqs[i] = (SequenceI) seqs.elementAt(i);
2032 String newtitle = MessageManager
2033 .getString("label.copied_sequences");
2034 if (getTitle().startsWith(
2035 MessageManager.getString("label.copied_sequences")))
2037 newtitle = getTitle();
2041 newtitle = newtitle.concat(MessageManager
2042 .formatMessage("label.from_msname", new String[]
2045 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
2046 viewport.applet, newtitle, false);
2047 af.viewport.setHiddenColumns(copiedHiddenColumns);
2049 jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
2054 addSequences(newSeqs);
2057 } catch (Exception ex)
2059 } // could be anything being pasted in here
2063 void addSequences(SequenceI[] seqs)
2065 for (int i = 0; i < seqs.length; i++)
2067 viewport.getAlignment().addSequence(seqs[i]);
2071 addHistoryItem(new EditCommand(
2072 MessageManager.getString("label.add_sequences"), Action.PASTE,
2073 seqs, 0, viewport.getAlignment().getWidth(),
2074 viewport.getAlignment()));
2076 viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight());
2077 viewport.getAlignment().getWidth();
2078 viewport.firePropertyChange("alignment", null,
2079 viewport.getAlignment().getSequences());
2083 protected void cut_actionPerformed()
2085 copy_actionPerformed();
2086 delete_actionPerformed();
2089 protected void delete_actionPerformed()
2092 SequenceGroup sg = viewport.getSelectionGroup();
2098 Vector seqs = new Vector();
2100 for (int i = 0; i < sg.getSize(); i++)
2102 seq = sg.getSequenceAt(i);
2103 seqs.addElement(seq);
2107 * If the cut affects all sequences, warn, remove highlighted columns
2109 if (sg.getSize() == viewport.getAlignment().getHeight())
2111 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
2112 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2113 if (isEntireAlignWidth)
2115 String title = MessageManager.getString("label.delete_all");
2116 Panel infoPanel = new Panel();
2117 infoPanel.setLayout(new FlowLayout());
2119 new Label(MessageManager.getString("warn.delete_all")));
2121 final JVDialog dialog = new JVDialog(this, title, true, 400, 200);
2122 dialog.setMainPanel(infoPanel);
2123 dialog.ok.setLabel(MessageManager.getString("action.ok"));
2124 dialog.cancel.setLabel(MessageManager.getString("action.cancel"));
2125 dialog.setVisible(true);
2132 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2133 sg.getEndRes() + 1);
2136 SequenceI[] cut = new SequenceI[seqs.size()];
2137 for (int i = 0; i < seqs.size(); i++)
2139 cut[i] = (SequenceI) seqs.elementAt(i);
2143 * //ADD HISTORY ITEM
2145 addHistoryItem(new EditCommand(
2146 MessageManager.getString("label.cut_sequences"), Action.CUT,
2147 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2148 viewport.getAlignment()));
2150 viewport.setSelectionGroup(null);
2151 viewport.getAlignment().deleteGroup(sg);
2153 viewport.firePropertyChange("alignment", null,
2154 viewport.getAlignment().getSequences());
2156 if (viewport.getAlignment().getHeight() < 1)
2158 this.setVisible(false);
2160 viewport.sendSelection();
2164 * group consensus toggled
2167 protected void showGroupConsensus_actionPerformed()
2169 viewport.setShowGroupConsensus(showGroupConsensus.getState());
2170 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2175 * group conservation toggled.
2177 protected void showGroupConservation_actionPerformed()
2179 viewport.setShowGroupConservation(showGroupConservation.getState());
2180 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2187 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
2188 * .event.ActionEvent)
2190 protected void showConsensusHistogram_actionPerformed()
2192 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
2193 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2200 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
2201 * .event.ActionEvent)
2203 protected void showSequenceLogo_actionPerformed()
2205 viewport.setShowSequenceLogo(showSequenceLogo.getState());
2206 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2209 protected void normSequenceLogo_actionPerformed()
2211 showSequenceLogo.setState(true);
2212 viewport.setShowSequenceLogo(true);
2213 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
2214 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2217 protected void applyAutoAnnotationSettings_actionPerformed()
2219 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2222 protected void makeGrpsFromSelection_actionPerformed()
2224 if (avc.makeGroupsFromSelection())
2226 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2227 alignPanel.updateAnnotation();
2228 alignPanel.paintAlignment(true, true);
2232 protected void createGroup_actionPerformed()
2237 protected void unGroup_actionPerformed()
2241 alignPanel.alignmentChanged();
2245 protected void deleteGroups_actionPerformed()
2247 if (avc.deleteGroups())
2249 alignPanel.alignmentChanged();
2253 public void selectAllSequenceMenuItem_actionPerformed()
2255 SequenceGroup sg = new SequenceGroup();
2256 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2258 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2260 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2261 viewport.setSelectionGroup(sg);
2262 // JAL-2034 - should delegate to
2263 // alignPanel to decide if overview needs
2265 alignPanel.paintAlignment(false, false);
2266 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2267 viewport.sendSelection();
2270 public void deselectAllSequenceMenuItem_actionPerformed()
2272 if (viewport.cursorMode)
2274 alignPanel.seqPanel.keyboardNo1 = null;
2275 alignPanel.seqPanel.keyboardNo2 = null;
2277 viewport.setSelectionGroup(null);
2278 viewport.getColumnSelection().clear();
2279 viewport.setSelectionGroup(null);
2280 alignPanel.idPanel.idCanvas.searchResults = null;
2281 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2282 // JAL-2034 - should delegate to
2283 // alignPanel to decide if overview needs
2285 alignPanel.paintAlignment(false, false);
2286 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2287 viewport.sendSelection();
2290 public void invertSequenceMenuItem_actionPerformed()
2292 SequenceGroup sg = viewport.getSelectionGroup();
2293 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2295 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2298 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2299 viewport.sendSelection();
2302 public void invertColSel_actionPerformed()
2304 viewport.invertColumnSelection();
2305 alignPanel.paintAlignment(true, false);
2306 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2307 viewport.sendSelection();
2310 void trimAlignment(boolean trimLeft)
2312 AlignmentI al = viewport.getAlignment();
2313 ViewportRanges ranges = viewport.getRanges();
2314 ColumnSelection colSel = viewport.getColumnSelection();
2317 if (!colSel.isEmpty())
2321 column = colSel.getMin();
2325 column = colSel.getMax();
2329 if (viewport.getSelectionGroup() != null)
2331 seqs = viewport.getSelectionGroup()
2332 .getSequencesAsArray(viewport.getHiddenRepSequences());
2336 seqs = al.getSequencesArray();
2339 TrimRegionCommand trimRegion;
2342 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2344 ranges.setStartRes(0);
2348 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2352 statusBar.setText(MessageManager
2353 .formatMessage("label.removed_columns", new String[]
2354 { Integer.valueOf(trimRegion.getSize()).toString() }));
2355 addHistoryItem(trimRegion);
2357 for (SequenceGroup sg : al.getGroups())
2359 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2360 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2366 viewport.firePropertyChange("alignment", null, al.getSequences());
2370 public void removeGappedColumnMenuItem_actionPerformed()
2372 AlignmentI al = viewport.getAlignment();
2373 ViewportRanges ranges = viewport.getRanges();
2375 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2378 if (viewport.getSelectionGroup() != null)
2380 seqs = viewport.getSelectionGroup()
2381 .getSequencesAsArray(viewport.getHiddenRepSequences());
2382 start = viewport.getSelectionGroup().getStartRes();
2383 end = viewport.getSelectionGroup().getEndRes();
2387 seqs = viewport.getAlignment().getSequencesArray();
2390 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2391 "Remove Gapped Columns", seqs, start, end,
2392 viewport.getAlignment());
2394 addHistoryItem(removeGapCols);
2396 statusBar.setText(MessageManager
2397 .formatMessage("label.removed_empty_columns", new String[]
2398 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2400 // This is to maintain viewport position on first residue
2401 // of first sequence
2402 SequenceI seq = al.getSequenceAt(0);
2403 int startRes = seq.findPosition(ranges.getStartRes());
2404 // ShiftList shifts;
2405 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2406 // edit.alColumnChanges=shifts.getInverse();
2407 // if (viewport.hasHiddenColumns)
2408 // viewport.getColumnSelection().compensateForEdits(shifts);
2409 ranges.setStartRes(seq.findIndex(startRes) - 1);
2410 viewport.firePropertyChange("alignment", null, al.getSequences());
2414 public void removeAllGapsMenuItem_actionPerformed()
2416 AlignmentI al = viewport.getAlignment();
2417 ViewportRanges ranges = viewport.getRanges();
2419 int end = ranges.getAbsoluteAlignmentWidth() - 1;
2422 if (viewport.getSelectionGroup() != null)
2424 seqs = viewport.getSelectionGroup()
2425 .getSequencesAsArray(viewport.getHiddenRepSequences());
2426 start = viewport.getSelectionGroup().getStartRes();
2427 end = viewport.getSelectionGroup().getEndRes();
2431 seqs = viewport.getAlignment().getSequencesArray();
2434 // This is to maintain viewport position on first residue
2435 // of first sequence
2436 SequenceI seq = al.getSequenceAt(0);
2437 int startRes = seq.findPosition(ranges.getStartRes());
2440 new RemoveGapsCommand("Remove Gaps", seqs, start, end, al));
2442 ranges.setStartRes(seq.findIndex(startRes) - 1);
2444 viewport.firePropertyChange("alignment", null, al.getSequences());
2448 public void findMenuItem_actionPerformed()
2450 new Finder(alignPanel);
2454 * create a new view derived from the current view
2457 * @return frame for the new view
2459 public AlignFrame newView(String viewtitle)
2462 if (viewport.hasHiddenRows())
2464 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2465 .getFullAlignment().getSequencesArray());
2469 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2472 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2474 for (int i = 0; i < viewport.getAlignment()
2475 .getAlignmentAnnotation().length; i++)
2477 if (!viewport.getAlignment()
2478 .getAlignmentAnnotation()[i].autoCalculated)
2480 newal.addAnnotation(
2481 viewport.getAlignment().getAlignmentAnnotation()[i]);
2486 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2488 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2489 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2490 PaintRefresher.Register(newaf.alignPanel,
2491 newaf.alignPanel.av.getSequenceSetId());
2493 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2494 newaf.alignPanel.av.getSequenceSetId());
2495 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2496 newaf.alignPanel.av.getSequenceSetId());
2498 Vector comps = PaintRefresher.components
2499 .get(viewport.getSequenceSetId());
2501 for (int i = 0; i < comps.size(); i++)
2503 if (comps.elementAt(i) instanceof AlignmentPanel)
2509 String title = new String(this.getTitle());
2510 if (viewtitle != null)
2512 title = viewtitle + " ( " + title + ")";
2516 if (title.indexOf("(View") > -1)
2518 title = title.substring(0, title.indexOf("(View"));
2520 title += "(View " + viewSize + ")";
2523 newaf.setTitle(title.toString());
2525 newaf.viewport.setHistoryList(viewport.getHistoryList());
2526 newaf.viewport.setRedoList(viewport.getRedoList());
2532 * @return list of feature groups on the view
2534 public String[] getFeatureGroups()
2536 FeatureRenderer fr = null;
2537 if (alignPanel != null
2538 && (fr = alignPanel.getFeatureRenderer()) != null)
2540 List<String> gps = fr.getFeatureGroups();
2541 String[] _gps = gps.toArray(new String[gps.size()]);
2548 * get sequence feature groups that are hidden or shown
2554 public String[] getFeatureGroupsOfState(boolean visible)
2556 FeatureRenderer fr = null;
2557 if (alignPanel != null
2558 && (fr = alignPanel.getFeatureRenderer()) != null)
2560 List<String> gps = fr.getGroups(visible);
2561 String[] _gps = gps.toArray(new String[gps.size()]);
2568 * Change the display state for the given feature groups
2571 * list of group strings
2573 * visible or invisible
2575 public void setFeatureGroupState(String[] groups, boolean state)
2577 FeatureRenderer fr = null;
2578 this.sequenceFeatures.setState(true);
2579 viewport.setShowSequenceFeatures(true);
2580 if (alignPanel != null
2581 && (fr = alignPanel.getFeatureRenderer()) != null)
2584 fr.setGroupVisibility(Arrays.asList(groups), state);
2585 alignPanel.seqPanel.seqCanvas.repaint();
2586 if (alignPanel.overviewPanel != null)
2588 alignPanel.overviewPanel.updateOverviewImage();
2593 public void seqLimits_itemStateChanged()
2595 viewport.setShowJVSuffix(seqLimits.getState());
2596 alignPanel.fontChanged();
2597 alignPanel.paintAlignment(true, false);
2600 protected void colourTextMenuItem_actionPerformed()
2602 viewport.setColourText(colourTextMenuItem.getState());
2603 alignPanel.paintAlignment(false, false);
2606 protected void displayNonconservedMenuItem_actionPerformed()
2608 viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
2609 alignPanel.paintAlignment(false, false);
2612 protected void wrapMenuItem_actionPerformed()
2614 viewport.setWrapAlignment(wrapMenuItem.getState());
2615 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2616 scaleAbove.setEnabled(wrapMenuItem.getState());
2617 scaleLeft.setEnabled(wrapMenuItem.getState());
2618 scaleRight.setEnabled(wrapMenuItem.getState());
2619 alignPanel.paintAlignment(true, false);
2622 public void overviewMenuItem_actionPerformed()
2624 if (alignPanel.overviewPanel != null)
2629 Frame frame = new Frame();
2630 final OverviewPanel overview = new OverviewPanel(alignPanel);
2631 frame.add(overview);
2632 // +50 must allow for applet frame window
2633 jalview.bin.JalviewLite.addFrame(frame, MessageManager
2634 .formatMessage("label.overview_params", new String[]
2635 { this.getTitle() }), overview.getPreferredSize().width,
2636 overview.getPreferredSize().height + 50);
2639 final AlignmentPanel ap = alignPanel;
2640 frame.addWindowListener(new WindowAdapter()
2643 public void windowClosing(WindowEvent e)
2648 ap.setOverviewPanel(null);
2653 alignPanel.setOverviewPanel(overview);
2658 public void changeColour(ColourSchemeI cs)
2660 viewport.setGlobalColourScheme(cs);
2662 alignPanel.paintAlignment(true, true);
2665 protected void modifyPID_actionPerformed()
2667 if (viewport.getAbovePIDThreshold()
2668 && viewport.getGlobalColourScheme() != null)
2670 SliderPanel.setPIDSliderSource(alignPanel,
2671 viewport.getResidueShading(), alignPanel.getViewName());
2672 SliderPanel.showPIDSlider();
2676 protected void modifyConservation_actionPerformed()
2678 if (viewport.getConservationSelected()
2679 && viewport.getGlobalColourScheme() != null)
2681 SliderPanel.setConservationSlider(alignPanel,
2682 viewport.getResidueShading(), alignPanel.getViewName());
2683 SliderPanel.showConservationSlider();
2687 protected void conservationMenuItem_actionPerformed()
2689 boolean selected = conservationMenuItem.getState();
2690 modifyConservation.setEnabled(selected);
2691 viewport.setConservationSelected(selected);
2692 viewport.getResidueShading().setConservationApplied(selected);
2694 changeColour(viewport.getGlobalColourScheme());
2698 modifyConservation_actionPerformed();
2702 SliderPanel.hideConservationSlider();
2706 public void abovePIDThreshold_actionPerformed()
2708 boolean selected = abovePIDThreshold.getState();
2709 modifyPID.setEnabled(selected);
2710 viewport.setAbovePIDThreshold(selected);
2713 viewport.getResidueShading().setThreshold(0,
2714 viewport.isIgnoreGapsConsensus());
2717 changeColour(viewport.getGlobalColourScheme());
2721 modifyPID_actionPerformed();
2725 SliderPanel.hidePIDSlider();
2729 public void sortPairwiseMenuItem_actionPerformed()
2731 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2732 AlignmentSorter.sortByPID(viewport.getAlignment(),
2733 viewport.getAlignment().getSequenceAt(0));
2735 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2736 viewport.getAlignment()));
2737 alignPanel.paintAlignment(true, false);
2740 public void sortIDMenuItem_actionPerformed()
2742 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2743 AlignmentSorter.sortByID(viewport.getAlignment());
2745 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
2746 alignPanel.paintAlignment(true, false);
2749 public void sortLengthMenuItem_actionPerformed()
2751 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2752 AlignmentSorter.sortByLength(viewport.getAlignment());
2753 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2754 viewport.getAlignment()));
2755 alignPanel.paintAlignment(true, false);
2758 public void sortGroupMenuItem_actionPerformed()
2760 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2761 AlignmentSorter.sortByGroup(viewport.getAlignment());
2762 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2763 viewport.getAlignment()));
2764 alignPanel.paintAlignment(true, false);
2768 public void removeRedundancyMenuItem_actionPerformed()
2770 new RedundancyPanel(alignPanel);
2773 public void pairwiseAlignmentMenuItem_actionPerformed()
2775 if (viewport.getSelectionGroup() != null
2776 && viewport.getSelectionGroup().getSize() > 1)
2778 Frame frame = new Frame();
2779 frame.add(new PairwiseAlignPanel(alignPanel));
2780 jalview.bin.JalviewLite.addFrame(frame,
2781 MessageManager.getString("action.pairwise_alignment"), 600,
2786 public void PCAMenuItem_actionPerformed()
2788 // are the sequences aligned?
2789 if (!viewport.getAlignment().isAligned(false))
2792 int Width = viewport.getAlignment().getWidth();
2794 for (int i = 0; i < viewport.getAlignment().getSequences()
2797 current = viewport.getAlignment().getSequenceAt(i);
2799 if (current.getLength() < Width)
2801 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2804 alignPanel.paintAlignment(false, false);
2807 if ((viewport.getSelectionGroup() != null
2808 && viewport.getSelectionGroup().getSize() < 4
2809 && viewport.getSelectionGroup().getSize() > 0)
2810 || viewport.getAlignment().getHeight() < 4)
2817 new PCAPanel(viewport);
2818 } catch (java.lang.OutOfMemoryError ex)
2824 public void averageDistanceTreeMenuItem_actionPerformed()
2826 newTreePanel(TreeBuilder.AVERAGE_DISTANCE, new PIDModel().getName(),
2827 "Average distance tree using PID");
2830 public void neighbourTreeMenuItem_actionPerformed()
2832 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING, new PIDModel().getName(),
2833 "Neighbour joining tree using PID");
2836 protected void njTreeBlosumMenuItem_actionPerformed()
2838 newTreePanel(TreeBuilder.NEIGHBOUR_JOINING,
2839 ScoreModels.getInstance().getBlosum62().getName(),
2840 "Neighbour joining tree using BLOSUM62");
2843 protected void avTreeBlosumMenuItem_actionPerformed()
2845 newTreePanel(TreeBuilder.AVERAGE_DISTANCE,
2846 ScoreModels.getInstance().getBlosum62().getName(),
2847 "Average distance tree using BLOSUM62");
2850 void newTreePanel(String type, String pwType, String title)
2852 // are the sequences aligned?
2853 if (!viewport.getAlignment().isAligned(false))
2856 int Width = viewport.getAlignment().getWidth();
2858 for (int i = 0; i < viewport.getAlignment().getSequences()
2861 current = viewport.getAlignment().getSequenceAt(i);
2863 if (current.getLength() < Width)
2865 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2868 alignPanel.paintAlignment(false, false);
2872 if ((viewport.getSelectionGroup() != null
2873 && viewport.getSelectionGroup().getSize() > 1)
2874 || (viewport.getAlignment().getHeight() > 1))
2876 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2878 addTreeMenuItem(tp, title);
2880 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2884 void loadTree_actionPerformed()
2886 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2887 cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2888 cap.setTreeImport();
2889 Frame frame = new Frame();
2891 jalview.bin.JalviewLite.addFrame(frame,
2892 MessageManager.getString("label.paste_newick_file"), 400, 300);
2895 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2897 TreePanel tp = new TreePanel(alignPanel, treeFile,
2898 MessageManager.getString("label.load_tree_from_file"), tree);
2899 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2900 addTreeMenuItem(tp, treeFile);
2904 * sort the alignment using the given treePanel
2907 * tree used to sort view
2909 * string used for undo event name
2911 public void sortByTree(TreePanel treePanel, String title)
2913 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2914 AlignmentSorter.sortByTree(viewport.getAlignment(),
2915 treePanel.getTree());
2916 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2917 // HistoryItem.SORT));
2918 addHistoryItem(new OrderCommand(MessageManager
2919 .formatMessage("label.order_by_params", new String[]
2920 { title }), oldOrder, viewport.getAlignment()));
2921 alignPanel.paintAlignment(true, false);
2925 * Do any automatic reordering of the alignment and add the necessary bits to
2926 * the menu structure for the new tree
2931 protected void addTreeMenuItem(final TreePanel treePanel,
2934 final MenuItem item = new MenuItem(title);
2935 sortByTreeMenu.add(item);
2936 item.addActionListener(new java.awt.event.ActionListener()
2939 public void actionPerformed(ActionEvent evt)
2941 sortByTree(treePanel, title); // treePanel.getTitle());
2945 treePanel.addWindowListener(new WindowAdapter()
2948 public void windowOpened(WindowEvent e)
2950 if (viewport.sortByTree)
2952 sortByTree(treePanel, title);
2954 super.windowOpened(e);
2958 public void windowClosing(WindowEvent e)
2960 sortByTreeMenu.remove(item);
2965 public boolean sortBy(AlignmentOrder alorder, String undoname)
2967 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2968 if (viewport.applet.debug)
2970 System.err.println("Sorting " + alorder.getOrder().size()
2971 + " in alignment '" + getTitle() + "'");
2973 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2974 if (undoname != null)
2976 addHistoryItem(new OrderCommand(undoname, oldOrder,
2977 viewport.getAlignment()));
2979 alignPanel.paintAlignment(true, false);
2983 protected void documentation_actionPerformed()
2985 alignPanel.av.applet.openJalviewHelpUrl();
2988 protected void about_actionPerformed()
2991 class AboutPanel extends Canvas
2997 public AboutPanel(String version, String builddate)
2999 this.version = version;
3000 this.builddate = builddate;
3004 public void paint(Graphics g)
3006 g.setColor(Color.white);
3007 g.fillRect(0, 0, getSize().width, getSize().height);
3008 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3009 FontMetrics fm = g.getFontMetrics();
3010 int fh = fm.getHeight();
3012 g.setColor(Color.black);
3013 // TODO: update this text for each release or centrally store it for
3014 // lite and application
3015 g.setFont(new Font("Helvetica", Font.BOLD, 14));
3016 g.drawString(MessageManager
3017 .formatMessage("label.jalviewLite_release", new String[]
3018 { version }), x, y += fh);
3019 g.setFont(new Font("Helvetica", Font.BOLD, 12));
3020 g.drawString(MessageManager.formatMessage("label.jaview_build_date",
3022 { builddate }), x, y += fh);
3023 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3024 g.drawString(MessageManager.getString("label.jalview_authors_1"), x,
3026 g.drawString(MessageManager.getString("label.jalview_authors_2"),
3027 x + 50, y += fh + 8);
3028 g.drawString(MessageManager.getString("label.jalview_dev_managers"),
3030 g.drawString(MessageManager
3031 .getString("label.jalview_distribution_lists"), x, y += fh);
3032 g.drawString(MessageManager.getString("label.jalview_please_cite"),
3035 MessageManager.getString("label.jalview_cite_1_authors"), x,
3037 g.drawString(MessageManager.getString("label.jalview_cite_1_title"),
3039 g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
3044 Frame frame = new Frame();
3045 frame.add(new AboutPanel(JalviewLite.getVersion(),
3046 JalviewLite.getBuildDate()));
3047 jalview.bin.JalviewLite.addFrame(frame,
3048 MessageManager.getString("label.jalview"), 580, 220);
3052 public void showURL(String url, String target)
3054 if (viewport.applet == null)
3056 System.out.println("Not running as applet - no browser available.");
3060 viewport.applet.showURL(url, target);
3064 // ////////////////////////////////////////////////////////////////////////////////
3065 // JBuilder Graphics here
3067 MenuBar alignFrameMenuBar = new MenuBar();
3069 Menu fileMenu = new Menu(MessageManager.getString("action.file"));
3071 MenuItem loadApplication = new MenuItem(
3072 MessageManager.getString("label.view_full_application"));
3074 MenuItem loadTree = new MenuItem(
3075 MessageManager.getString("label.load_associated_tree"));
3077 MenuItem loadAnnotations = new MenuItem(
3078 MessageManager.getString("label.load_features_annotations"));
3080 MenuItem outputFeatures = new MenuItem(
3081 MessageManager.getString("label.export_features"));
3083 MenuItem outputAnnotations = new MenuItem(
3084 MessageManager.getString("label.export_annotations"));
3086 MenuItem closeMenuItem = new MenuItem(
3087 MessageManager.getString("action.close"));
3089 MenuItem selectAllSequenceMenuItem = new MenuItem(
3090 MessageManager.getString("action.select_all"));
3092 MenuItem deselectAllSequenceMenuItem = new MenuItem(
3093 MessageManager.getString("action.deselect_all"));
3095 MenuItem invertSequenceMenuItem = new MenuItem(
3096 MessageManager.getString("action.invert_selection"));
3098 MenuItem remove2LeftMenuItem = new MenuItem();
3100 MenuItem remove2RightMenuItem = new MenuItem();
3102 MenuItem removeGappedColumnMenuItem = new MenuItem();
3104 MenuItem removeAllGapsMenuItem = new MenuItem();
3106 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
3108 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
3110 MenuItem sortPairwiseMenuItem = new MenuItem();
3112 MenuItem sortIDMenuItem = new MenuItem();
3114 MenuItem sortLengthMenuItem = new MenuItem();
3116 MenuItem sortGroupMenuItem = new MenuItem();
3118 MenuItem removeRedundancyMenuItem = new MenuItem();
3120 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
3122 MenuItem PCAMenuItem = new MenuItem();
3124 MenuItem averageDistanceTreeMenuItem = new MenuItem();
3126 MenuItem neighbourTreeMenuItem = new MenuItem();
3128 BorderLayout borderLayout1 = new BorderLayout();
3130 public Label statusBar = new Label();
3132 MenuItem clustalColour = new MenuItem();
3134 MenuItem zappoColour = new MenuItem();
3136 MenuItem taylorColour = new MenuItem();
3138 MenuItem hydrophobicityColour = new MenuItem();
3140 MenuItem helixColour = new MenuItem();
3142 MenuItem strandColour = new MenuItem();
3144 MenuItem turnColour = new MenuItem();
3146 MenuItem buriedColour = new MenuItem();
3148 MenuItem purinePyrimidineColour = new MenuItem();
3150 // MenuItem RNAInteractionColour = new MenuItem();
3152 MenuItem RNAHelixColour = new MenuItem();
3154 MenuItem userDefinedColour = new MenuItem();
3156 MenuItem PIDColour = new MenuItem();
3158 MenuItem BLOSUM62Colour = new MenuItem();
3160 MenuItem tcoffeeColour = new MenuItem();
3162 MenuItem njTreeBlosumMenuItem = new MenuItem();
3164 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
3166 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
3168 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
3170 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
3172 MenuItem alProperties = new MenuItem(
3173 MessageManager.getString("label.alignment_props"));
3175 MenuItem overviewMenuItem = new MenuItem();
3177 MenuItem undoMenuItem = new MenuItem();
3179 MenuItem redoMenuItem = new MenuItem();
3181 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
3183 MenuItem noColourmenuItem = new MenuItem();
3185 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
3187 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
3189 MenuItem findMenuItem = new MenuItem();
3191 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
3193 MenuItem nucleotideColour = new MenuItem();
3195 MenuItem deleteGroups = new MenuItem();
3197 MenuItem grpsFromSelection = new MenuItem();
3199 MenuItem createGroup = new MenuItem();
3201 MenuItem unGroup = new MenuItem();
3203 MenuItem delete = new MenuItem();
3205 MenuItem copy = new MenuItem();
3207 MenuItem cut = new MenuItem();
3209 Menu pasteMenu = new Menu();
3211 MenuItem pasteNew = new MenuItem();
3213 MenuItem pasteThis = new MenuItem();
3215 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
3217 MenuItem font = new MenuItem();
3219 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
3221 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
3223 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
3225 MenuItem modifyPID = new MenuItem();
3227 MenuItem modifyConservation = new MenuItem();
3229 CheckboxMenuItem autoCalculate = null;
3231 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
3232 "Sort Alignment With New Tree", true);
3234 Menu sortByTreeMenu = new Menu();
3236 MenuItem inputText = new MenuItem();
3238 MenuItem documentation = new MenuItem();
3240 MenuItem about = new MenuItem();
3242 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
3244 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
3246 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
3248 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
3250 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
3252 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
3254 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
3256 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
3258 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
3261 * Initialise menus and other items
3265 private void jbInit() throws Exception
3267 setMenuBar(alignFrameMenuBar);
3270 * Configure File menu items and actions
3273 .setLabel(MessageManager.getString("label.input_from_textbox"));
3274 inputText.addActionListener(this);
3275 Menu outputTextboxMenu = new Menu(
3276 MessageManager.getString("label.out_to_textbox"));
3277 for (String ff : FileFormats.getInstance().getWritableFormats(true))
3279 MenuItem item = new MenuItem(ff);
3281 item.addActionListener(new java.awt.event.ActionListener()
3284 public void actionPerformed(ActionEvent e)
3286 outputText_actionPerformed(e);
3290 outputTextboxMenu.add(item);
3292 closeMenuItem.addActionListener(this);
3293 loadApplication.addActionListener(this);
3294 loadTree.addActionListener(this);
3295 loadAnnotations.addActionListener(this);
3296 outputFeatures.addActionListener(this);
3297 outputAnnotations.addActionListener(this);
3300 * Configure Edit menu items and actions
3302 undoMenuItem.setEnabled(false);
3303 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3304 undoMenuItem.addActionListener(this);
3305 redoMenuItem.setEnabled(false);
3306 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3307 redoMenuItem.addActionListener(this);
3308 copy.setLabel(MessageManager.getString("action.copy"));
3309 copy.addActionListener(this);
3310 cut.setLabel(MessageManager.getString("action.cut"));
3311 cut.addActionListener(this);
3312 delete.setLabel(MessageManager.getString("action.delete"));
3313 delete.addActionListener(this);
3314 pasteMenu.setLabel(MessageManager.getString("action.paste"));
3315 pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3316 pasteNew.addActionListener(this);
3317 pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3318 pasteThis.addActionListener(this);
3320 .setLabel(MessageManager.getString("action.remove_left"));
3321 remove2LeftMenuItem.addActionListener(this);
3322 remove2RightMenuItem
3323 .setLabel(MessageManager.getString("action.remove_right"));
3324 remove2RightMenuItem.addActionListener(this);
3325 removeGappedColumnMenuItem.setLabel(
3326 MessageManager.getString("action.remove_empty_columns"));
3327 removeGappedColumnMenuItem.addActionListener(this);
3328 removeAllGapsMenuItem
3329 .setLabel(MessageManager.getString("action.remove_all_gaps"));
3330 removeAllGapsMenuItem.addActionListener(this);
3331 removeRedundancyMenuItem
3332 .setLabel(MessageManager.getString("action.remove_redundancy"));
3333 removeRedundancyMenuItem.addActionListener(this);
3336 * Configure Select menu items and actions
3338 findMenuItem.setLabel(MessageManager.getString("action.find"));
3339 findMenuItem.addActionListener(this);
3340 selectAllSequenceMenuItem.addActionListener(this);
3341 deselectAllSequenceMenuItem.addActionListener(this);
3342 invertSequenceMenuItem.setLabel(
3343 MessageManager.getString("action.invert_sequence_selection"));
3344 invertSequenceMenuItem.addActionListener(this);
3345 invertColSel.setLabel(
3346 MessageManager.getString("action.invert_column_selection"));
3347 invertColSel.addActionListener(this);
3349 .setLabel(MessageManager.getString("action.undefine_groups"));
3350 deleteGroups.addActionListener(this);
3351 grpsFromSelection.setLabel(
3352 MessageManager.getString("action.make_groups_selection"));
3353 grpsFromSelection.addActionListener(this);
3354 createGroup.setLabel(MessageManager.getString("action.create_group"));
3355 createGroup.addActionListener(this);
3356 unGroup.setLabel(MessageManager.getString("action.remove_group"));
3357 unGroup.addActionListener(this);
3359 annotationColumnSelection.setLabel(
3360 MessageManager.getString("action.select_by_annotation"));
3361 annotationColumnSelection.addActionListener(this);
3364 * Configure View menu items and actions
3366 newView.setLabel(MessageManager.getString("action.new_view"));
3367 newView.addActionListener(this);
3368 Menu showMenu = new Menu(MessageManager.getString("action.show"));
3369 showColumns.setLabel(MessageManager.getString("label.all_columns"));
3370 showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3371 Menu hideMenu = new Menu(MessageManager.getString("action.hide"));
3373 .setLabel(MessageManager.getString("label.selected_columns"));
3375 .setLabel(MessageManager.getString("label.selected_sequences"));
3376 hideAllButSelection.setLabel(
3377 MessageManager.getString("label.all_but_selected_region"));
3379 .setLabel(MessageManager.getString("label.selected_region"));
3380 showAllHidden.setLabel(
3381 MessageManager.getString("label.all_sequences_columns"));
3382 showColumns.addActionListener(this);
3383 showSeqs.addActionListener(this);
3384 hideColumns.addActionListener(this);
3385 hideSequences.addActionListener(this);
3386 hideAllButSelection.addActionListener(this);
3387 hideAllSelection.addActionListener(this);
3388 showAllHidden.addActionListener(this);
3390 .setLabel(MessageManager.getString("action.feature_settings"));
3391 featureSettings.addActionListener(this);
3392 sequenceFeatures.setLabel(
3393 MessageManager.getString("label.show_sequence_features"));
3394 sequenceFeatures.addItemListener(this);
3395 sequenceFeatures.setState(false);
3396 followMouseOverFlag.setLabel(
3397 MessageManager.getString("label.automatic_scrolling"));
3398 followMouseOverFlag.addItemListener(this);
3399 alProperties.addActionListener(this);
3401 .setLabel(MessageManager.getString("label.overview_window"));
3402 overviewMenuItem.addActionListener(this);
3405 * Configure Annotations menu items and actions
3407 annotationPanelMenuItem
3408 .setLabel(MessageManager.getString("label.show_annotations"));
3409 annotationPanelMenuItem.addItemListener(this);
3411 .setLabel(MessageManager.getString("label.group_consensus"));
3412 showGroupConservation
3413 .setLabel(MessageManager.getString("label.group_conservation"));
3414 showConsensusHistogram.setLabel(
3415 MessageManager.getString("label.show_consensus_histogram"));
3416 showSequenceLogo.setLabel(
3417 MessageManager.getString("label.show_consensus_logo"));
3418 normSequenceLogo.setLabel(
3419 MessageManager.getString("label.norm_consensus_logo"));
3420 applyAutoAnnotationSettings
3421 .setLabel(MessageManager.getString("label.apply_all_groups"));
3422 applyAutoAnnotationSettings.setState(true);
3423 Menu autoAnnMenu = new Menu(
3424 MessageManager.getString("label.autocalculated_annotation"));
3425 showGroupConsensus.addItemListener(this);
3426 showGroupConservation.addItemListener(this);
3427 showConsensusHistogram.addItemListener(this);
3428 showSequenceLogo.addItemListener(this);
3429 normSequenceLogo.addItemListener(this);
3430 applyAutoAnnotationSettings.addItemListener(this);
3431 showAlignmentAnnotations = new CheckboxMenuItem(
3432 MessageManager.getString("label.show_all_al_annotations"));
3433 showSequenceAnnotations = new CheckboxMenuItem(
3434 MessageManager.getString("label.show_all_seq_annotations"));
3435 sortAnnBySequence = new CheckboxMenuItem(
3436 MessageManager.getString("label.sort_annotations_by_sequence"));
3437 sortAnnByLabel = new CheckboxMenuItem(
3438 MessageManager.getString("label.sort_annotations_by_label"));
3439 showAutoFirst = new CheckboxMenuItem(
3440 MessageManager.getString("label.show_first"));
3441 showAutoFirst.setState(false); // pending applet parameter
3442 setShowAutoCalculatedAbove(showAutoFirst.getState());
3443 showAutoLast = new CheckboxMenuItem(
3444 MessageManager.getString("label.show_last"));
3445 showAutoLast.setState(!showAutoFirst.getState());
3446 showAlignmentAnnotations.addItemListener(this);
3447 showSequenceAnnotations.addItemListener(this);
3448 sortAnnBySequence.addItemListener(this);
3449 sortAnnByLabel.addItemListener(this);
3450 showAutoFirst.addItemListener(this);
3451 showAutoLast.addItemListener(this);
3454 * Configure Format menu items and actions
3456 font.setLabel(MessageManager.getString("action.font"));
3457 font.addActionListener(this);
3458 scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3459 scaleAbove.setState(true);
3460 scaleAbove.setEnabled(false);
3461 scaleAbove.addItemListener(this);
3462 scaleLeft.setEnabled(false);
3463 scaleLeft.setState(true);
3464 scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3465 scaleLeft.addItemListener(this);
3466 scaleRight.setEnabled(false);
3467 scaleRight.setState(true);
3468 scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3469 scaleRight.addItemListener(this);
3470 viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
3471 viewBoxesMenuItem.setState(true);
3472 viewBoxesMenuItem.addItemListener(this);
3473 viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
3474 viewTextMenuItem.setState(true);
3475 viewTextMenuItem.addItemListener(this);
3477 .setLabel(MessageManager.getString("label.colour_text"));
3478 colourTextMenuItem.addItemListener(this);
3479 displayNonconservedMenuItem
3480 .setLabel(MessageManager.getString("label.show_non_conserved"));
3481 displayNonconservedMenuItem.addItemListener(this);
3482 wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3483 wrapMenuItem.addItemListener(this);
3485 .setLabel(MessageManager.getString("action.show_gaps"));
3486 renderGapsMenuItem.setState(true);
3487 renderGapsMenuItem.addItemListener(this);
3488 centreColumnLabelFlag.setLabel(
3489 MessageManager.getString("label.centre_column_labels"));
3490 centreColumnLabelFlag.addItemListener(this);
3491 seqLimits.setState(true);
3493 MessageManager.getString("label.show_sequence_limits"));
3494 seqLimits.addItemListener(this);
3497 * Configure Colour menu items and actions
3499 applyToAllGroups.setLabel(
3500 MessageManager.getString("label.apply_colour_to_all_groups"));
3501 applyToAllGroups.setState(true);
3502 applyToAllGroups.addItemListener(this);
3503 clustalColour.setLabel(
3504 MessageManager.getString("label.colourScheme_clustal"));
3505 clustalColour.addActionListener(this);
3507 .setLabel(MessageManager.getString("label.colourScheme_zappo"));
3508 zappoColour.addActionListener(this);
3509 taylorColour.setLabel(
3510 MessageManager.getString("label.colourScheme_taylor"));
3511 taylorColour.addActionListener(this);
3512 hydrophobicityColour.setLabel(
3513 MessageManager.getString("label.colourScheme_hydrophobic"));
3514 hydrophobicityColour.addActionListener(this);
3515 helixColour.setLabel(MessageManager
3516 .getString("label.colourScheme_helix_propensity"));
3517 helixColour.addActionListener(this);
3518 strandColour.setLabel(MessageManager
3519 .getString("label.colourScheme_strand_propensity"));
3520 strandColour.addActionListener(this);
3521 turnColour.setLabel(
3522 MessageManager.getString("label.colourScheme_turn_propensity"));
3523 turnColour.addActionListener(this);
3524 buriedColour.setLabel(
3525 MessageManager.getString("label.colourScheme_buried_index"));
3526 buriedColour.addActionListener(this);
3527 purinePyrimidineColour.setLabel(MessageManager
3528 .getString("label.colourScheme_purine/pyrimidine"));
3529 purinePyrimidineColour.addActionListener(this);
3530 // RNAInteractionColour.setLabel(MessageManager
3531 // .getString("label.rna_interaction"));
3532 // RNAInteractionColour.addActionListener(this);
3533 RNAHelixColour.setLabel(
3534 MessageManager.getString("label.colourScheme_rna_helices"));
3535 RNAHelixColour.addActionListener(this);
3537 .setLabel(MessageManager.getString("action.user_defined"));
3538 userDefinedColour.addActionListener(this);
3540 MessageManager.getString("label.colourScheme_%_identity"));
3541 PIDColour.addActionListener(this);
3542 BLOSUM62Colour.setLabel(
3543 MessageManager.getString("label.colourScheme_blosum62"));
3544 BLOSUM62Colour.addActionListener(this);
3545 tcoffeeColour.setLabel(
3546 MessageManager.getString("label.colourScheme_t-coffee_scores"));
3547 // it will be enabled only if a score file is provided
3548 tcoffeeColour.setEnabled(false);
3549 tcoffeeColour.addActionListener(this);
3550 conservationMenuItem
3551 .setLabel(MessageManager.getString("action.by_conservation"));
3552 conservationMenuItem.addItemListener(this);
3553 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3554 noColourmenuItem.addActionListener(this);
3555 abovePIDThreshold.setLabel(
3556 MessageManager.getString("label.above_identity_threshold"));
3557 abovePIDThreshold.addItemListener(this);
3558 nucleotideColour.setLabel(
3559 MessageManager.getString("label.colourScheme_nucleotide"));
3560 nucleotideColour.addActionListener(this);
3562 MessageManager.getString("label.modify_identity_threshold"));
3563 modifyPID.setEnabled(abovePIDThreshold.getState());
3564 modifyPID.addActionListener(this);
3565 modifyConservation.setLabel(MessageManager
3566 .getString("label.modify_conservation_threshold"));
3567 modifyConservation.setEnabled(conservationMenuItem.getState());
3568 modifyConservation.addActionListener(this);
3570 .setLabel(MessageManager.getString("action.by_annotation"));
3571 annotationColour.addActionListener(this);
3574 * Configure Calculate menu items and actions
3576 sortPairwiseMenuItem
3577 .setLabel(MessageManager.getString("action.by_pairwise_id"));
3578 sortPairwiseMenuItem.addActionListener(this);
3579 sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
3580 sortIDMenuItem.addActionListener(this);
3582 .setLabel(MessageManager.getString("action.by_length"));
3583 sortLengthMenuItem.addActionListener(this);
3584 sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3585 sortGroupMenuItem.addActionListener(this);
3586 pairwiseAlignmentMenuItem.setLabel(
3587 MessageManager.getString("action.pairwise_alignment"));
3588 pairwiseAlignmentMenuItem.addActionListener(this);
3589 PCAMenuItem.setLabel(
3590 MessageManager.getString("label.principal_component_analysis"));
3591 PCAMenuItem.addActionListener(this);
3592 autoCalculate = new CheckboxMenuItem(
3593 MessageManager.getString("label.autocalculate_consensus"),
3595 averageDistanceTreeMenuItem.setLabel(
3596 MessageManager.getString("label.average_distance_identity"));
3597 averageDistanceTreeMenuItem.addActionListener(this);
3598 neighbourTreeMenuItem.setLabel(
3599 MessageManager.getString("label.neighbour_joining_identity"));
3600 neighbourTreeMenuItem.addActionListener(this);
3601 avDistanceTreeBlosumMenuItem.setLabel(
3602 MessageManager.getString("label.average_distance_blosum62"));
3603 avDistanceTreeBlosumMenuItem.addActionListener(this);
3604 njTreeBlosumMenuItem
3605 .setLabel(MessageManager.getString("label.neighbour_blosum62"));
3606 njTreeBlosumMenuItem.addActionListener(this);
3608 .setLabel(MessageManager.getString("action.by_tree_order"));
3609 Menu sortMenu = new Menu(MessageManager.getString("action.sort"));
3610 Menu calculateTreeMenu = new Menu(
3611 MessageManager.getString("action.calculate_tree"));
3612 autoCalculate.addItemListener(this);
3613 sortByTree.addItemListener(this);
3616 * Configure Help menu items and actions
3618 Menu helpMenu = new Menu(MessageManager.getString("action.help"));
3619 documentation.setLabel(MessageManager.getString("label.documentation"));
3620 documentation.addActionListener(this);
3621 about.setLabel(MessageManager.getString("label.about"));
3622 about.addActionListener(this);
3625 * Add top level menus to frame
3627 alignFrameMenuBar.add(fileMenu);
3628 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
3629 alignFrameMenuBar.add(editMenu);
3630 Menu selectMenu = new Menu(MessageManager.getString("action.select"));
3631 alignFrameMenuBar.add(selectMenu);
3632 Menu viewMenu = new Menu(MessageManager.getString("action.view"));
3633 alignFrameMenuBar.add(viewMenu);
3634 Menu annotationsMenu = new Menu(
3635 MessageManager.getString("action.annotations"));
3636 alignFrameMenuBar.add(annotationsMenu);
3637 Menu formatMenu = new Menu(MessageManager.getString("action.format"));
3638 alignFrameMenuBar.add(formatMenu);
3639 Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
3640 alignFrameMenuBar.add(colourMenu);
3641 Menu calculateMenu = new Menu(
3642 MessageManager.getString("action.calculate"));
3643 alignFrameMenuBar.add(calculateMenu);
3644 alignFrameMenuBar.add(helpMenu);
3649 fileMenu.add(inputText);
3650 fileMenu.add(loadTree);
3651 fileMenu.add(loadAnnotations);
3652 fileMenu.addSeparator();
3653 fileMenu.add(outputTextboxMenu);
3654 fileMenu.add(outputFeatures);
3655 fileMenu.add(outputAnnotations);
3656 if (jalviewServletURL != null)
3658 fileMenu.add(loadApplication);
3660 fileMenu.addSeparator();
3661 fileMenu.add(closeMenuItem);
3666 editMenu.add(undoMenuItem);
3667 editMenu.add(redoMenuItem);
3670 pasteMenu.add(pasteNew);
3671 pasteMenu.add(pasteThis);
3672 editMenu.add(pasteMenu);
3673 editMenu.add(delete);
3674 editMenu.addSeparator();
3675 editMenu.add(remove2LeftMenuItem);
3676 editMenu.add(remove2RightMenuItem);
3677 editMenu.add(removeGappedColumnMenuItem);
3678 editMenu.add(removeAllGapsMenuItem);
3679 editMenu.add(removeRedundancyMenuItem);
3684 selectMenu.add(findMenuItem);
3685 selectMenu.addSeparator();
3686 selectMenu.add(selectAllSequenceMenuItem);
3687 selectMenu.add(deselectAllSequenceMenuItem);
3688 selectMenu.add(invertSequenceMenuItem);
3689 selectMenu.add(invertColSel);
3690 selectMenu.add(createGroup);
3691 selectMenu.add(unGroup);
3692 selectMenu.add(grpsFromSelection);
3693 selectMenu.add(deleteGroups);
3694 selectMenu.add(annotationColumnSelection);
3699 viewMenu.add(newView);
3700 viewMenu.addSeparator();
3701 showMenu.add(showColumns);
3702 showMenu.add(showSeqs);
3703 showMenu.add(showAllHidden);
3704 viewMenu.add(showMenu);
3705 hideMenu.add(hideColumns);
3706 hideMenu.add(hideSequences);
3707 hideMenu.add(hideAllSelection);
3708 hideMenu.add(hideAllButSelection);
3709 viewMenu.add(hideMenu);
3710 viewMenu.addSeparator();
3711 viewMenu.add(followMouseOverFlag);
3712 viewMenu.addSeparator();
3713 viewMenu.add(sequenceFeatures);
3714 viewMenu.add(featureSettings);
3715 viewMenu.addSeparator();
3716 viewMenu.add(alProperties);
3717 viewMenu.addSeparator();
3718 viewMenu.add(overviewMenuItem);
3723 annotationsMenu.add(annotationPanelMenuItem);
3724 annotationsMenu.addSeparator();
3725 annotationsMenu.add(showAlignmentAnnotations);
3726 annotationsMenu.add(showSequenceAnnotations);
3727 annotationsMenu.add(sortAnnBySequence);
3728 annotationsMenu.add(sortAnnByLabel);
3729 annotationsMenu.addSeparator();
3730 autoAnnMenu.add(showAutoFirst);
3731 autoAnnMenu.add(showAutoLast);
3732 autoAnnMenu.addSeparator();
3733 autoAnnMenu.add(applyAutoAnnotationSettings);
3734 autoAnnMenu.add(showConsensusHistogram);
3735 autoAnnMenu.add(showSequenceLogo);
3736 autoAnnMenu.add(normSequenceLogo);
3737 autoAnnMenu.addSeparator();
3738 autoAnnMenu.add(showGroupConservation);
3739 autoAnnMenu.add(showGroupConsensus);
3740 annotationsMenu.add(autoAnnMenu);
3745 formatMenu.add(font);
3746 formatMenu.add(seqLimits);
3747 formatMenu.add(wrapMenuItem);
3748 formatMenu.add(scaleAbove);
3749 formatMenu.add(scaleLeft);
3750 formatMenu.add(scaleRight);
3751 formatMenu.add(viewBoxesMenuItem);
3752 formatMenu.add(viewTextMenuItem);
3753 formatMenu.add(colourTextMenuItem);
3754 formatMenu.add(displayNonconservedMenuItem);
3755 formatMenu.add(renderGapsMenuItem);
3756 formatMenu.add(centreColumnLabelFlag);
3761 colourMenu.add(applyToAllGroups);
3762 colourMenu.addSeparator();
3763 colourMenu.add(noColourmenuItem);
3764 colourMenu.add(clustalColour);
3765 colourMenu.add(BLOSUM62Colour);
3766 colourMenu.add(PIDColour);
3767 colourMenu.add(zappoColour);
3768 colourMenu.add(taylorColour);
3769 colourMenu.add(hydrophobicityColour);
3770 colourMenu.add(helixColour);
3771 colourMenu.add(strandColour);
3772 colourMenu.add(turnColour);
3773 colourMenu.add(buriedColour);
3774 colourMenu.add(nucleotideColour);
3775 colourMenu.add(purinePyrimidineColour);
3776 // colourMenu.add(RNAInteractionColour);
3777 colourMenu.add(tcoffeeColour);
3778 colourMenu.add(userDefinedColour);
3779 colourMenu.addSeparator();
3780 colourMenu.add(conservationMenuItem);
3781 colourMenu.add(modifyConservation);
3782 colourMenu.add(abovePIDThreshold);
3783 colourMenu.add(modifyPID);
3784 colourMenu.add(annotationColour);
3785 colourMenu.add(RNAHelixColour);
3790 sortMenu.add(sortIDMenuItem);
3791 sortMenu.add(sortLengthMenuItem);
3792 sortMenu.add(sortByTreeMenu);
3793 sortMenu.add(sortGroupMenuItem);
3794 sortMenu.add(sortPairwiseMenuItem);
3795 calculateMenu.add(sortMenu);
3796 calculateTreeMenu.add(averageDistanceTreeMenuItem);
3797 calculateTreeMenu.add(neighbourTreeMenuItem);
3798 calculateTreeMenu.add(avDistanceTreeBlosumMenuItem);
3799 calculateTreeMenu.add(njTreeBlosumMenuItem);
3800 calculateMenu.add(calculateTreeMenu);
3801 calculateMenu.addSeparator();
3802 calculateMenu.add(pairwiseAlignmentMenuItem);
3803 calculateMenu.add(PCAMenuItem);
3804 calculateMenu.add(autoCalculate);
3805 calculateMenu.add(sortByTree);
3810 helpMenu.add(documentation);
3811 helpMenu.add(about);
3816 statusBar.setBackground(Color.white);
3817 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3818 statusBar.setText(MessageManager.getString("label.status_bar"));
3819 this.add(statusBar, BorderLayout.SOUTH);
3823 public void setStatus(String string)
3825 statusBar.setText(string);
3828 MenuItem featureSettings = new MenuItem();
3830 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3832 MenuItem annotationColour = new MenuItem();
3834 MenuItem annotationColumnSelection = new MenuItem();
3836 MenuItem invertColSel = new MenuItem();
3838 MenuItem showColumns = new MenuItem();
3840 MenuItem showSeqs = new MenuItem();
3842 MenuItem hideColumns = new MenuItem();
3844 MenuItem hideSequences = new MenuItem();
3846 MenuItem hideAllButSelection = new MenuItem();
3848 MenuItem hideAllSelection = new MenuItem();
3850 MenuItem showAllHidden = new MenuItem();
3852 MenuItem newView = new MenuItem();
3854 private CheckboxMenuItem showAlignmentAnnotations;
3856 private CheckboxMenuItem showSequenceAnnotations;
3858 private CheckboxMenuItem sortAnnBySequence;
3860 private CheckboxMenuItem sortAnnByLabel;
3862 private CheckboxMenuItem showAutoFirst;
3864 private CheckboxMenuItem showAutoLast;
3866 private SplitFrame splitFrame;
3869 * Attach the alignFrame panels after embedding menus, if necessary. This used
3870 * to be called setEmbedded, but is now creates the dropdown menus in a
3871 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3873 * @param reallyEmbedded
3874 * true to attach the view to the applet area on the page rather than
3877 public void createAlignFrameWindow(boolean reallyEmbedded)
3881 embedAlignFrameInApplet(viewport.applet);
3886 // test and embed menu bar if necessary.
3888 if (embedMenuIfNeeded(alignPanel))
3891 * adjust for status bar height too. ? pointless as overridden by layout
3894 alignPanel.setSize(getSize().width,
3895 getSize().height - statusBar.getHeight());
3897 add(statusBar, BorderLayout.SOUTH);
3898 add(alignPanel, BorderLayout.CENTER);
3899 // and register with the applet so it can pass external API calls to us
3900 jalview.bin.JalviewLite.addFrame(this, this.getTitle(), frameWidth,
3906 * Add the components of this AlignFrame to the applet container.
3910 public void embedAlignFrameInApplet(final JalviewLite theApplet)
3913 // Explicitly build the embedded menu panel for the on-page applet
3915 // view cannot be closed if its actually on the page
3916 fileMenu.remove(closeMenuItem);
3917 fileMenu.remove(3); // Remove Separator
3918 // construct embedded menu, using default font
3919 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
3920 // and actually add the components to the applet area
3921 theApplet.setLayout(new BorderLayout());
3922 theApplet.add(embeddedMenu, BorderLayout.NORTH);
3923 theApplet.add(statusBar, BorderLayout.SOUTH);
3924 // TODO should size be left to the layout manager?
3925 alignPanel.setSize(theApplet.getSize().width, theApplet.getSize().height
3926 - embeddedMenu.getHeight() - statusBar.getHeight());
3927 theApplet.add(alignPanel, BorderLayout.CENTER);
3928 final AlignFrame me = this;
3929 theApplet.addFocusListener(new FocusListener()
3933 public void focusLost(FocusEvent e)
3935 if (theApplet.currentAlignFrame == me)
3937 theApplet.currentAlignFrame = null;
3942 public void focusGained(FocusEvent e)
3944 theApplet.currentAlignFrame = me;
3947 theApplet.validate();
3951 * create a new binding between structures in an existing jmol viewer instance
3952 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3953 * this does not open a new Jmol window, or modify the display of the
3954 * structures in the original jmol window. Note This method doesn't work
3955 * without an additional javascript library to exchange messages between the
3956 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3959 * JmolViewer instance
3960 * @param sequenceIds
3961 * - sequence Ids to search for associations
3963 public SequenceStructureBinding addStructureViewInstance(
3964 Object jmolviewer, String[] sequenceIds)
3966 Viewer viewer = null;
3969 viewer = (Viewer) jmolviewer;
3970 } catch (ClassCastException ex)
3973 "Unsupported viewer object :" + jmolviewer.getClass());
3977 System.err.println("Can't use this object as a structure viewer:"
3978 + jmolviewer.getClass());
3981 SequenceI[] seqs = null;
3982 if (sequenceIds == null || sequenceIds.length == 0)
3984 seqs = viewport.getAlignment().getSequencesArray();
3988 Vector sqi = new Vector();
3989 AlignmentI al = viewport.getAlignment();
3990 for (int sid = 0; sid < sequenceIds.length; sid++)
3992 SequenceI sq = al.findName(sequenceIds[sid]);
4000 seqs = new SequenceI[sqi.size()];
4001 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
4003 seqs[sid] = (SequenceI) sqi.elementAt(sid);
4011 AAStructureBindingModel jmv = null;
4012 // TODO: search for a jmv that involves viewer
4014 { // create a new viewer/jalview binding.
4015 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] { seqs });
4022 * bind a pdb file to a sequence in the current view
4025 * - sequenceId within the dataset.
4026 * @param pdbEntryString
4027 * - the short name for the PDB file
4029 * - pdb file - either a URL or a valid PDB file.
4030 * @return true if binding was as success TODO: consider making an exception
4031 * structure for indicating when PDB parsing or sequenceId location
4034 public boolean addPdbFile(String sequenceId, String pdbEntryString,
4037 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
4038 boolean needtoadd = false;
4039 if (toaddpdb != null)
4041 Vector pdbe = toaddpdb.getAllPDBEntries();
4042 PDBEntry pdbentry = null;
4043 if (pdbe != null && pdbe.size() > 0)
4045 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
4047 pdbentry = (PDBEntry) pdbe.elementAt(pe);
4048 if (!pdbentry.getId().equals(pdbEntryString)
4049 && !pdbentry.getFile().equals(pdbFile))
4059 if (pdbentry == null)
4061 pdbentry = new PDBEntry();
4062 pdbentry.setId(pdbEntryString);
4063 pdbentry.setFile(pdbFile);
4064 needtoadd = true; // add this new entry to sequence.
4066 // resolve data source
4067 // TODO: this code should be a refactored to an io package
4068 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(pdbFile,
4070 if (protocol == null)
4076 pdbentry.setProperty("protocol", protocol);
4077 toaddpdb.addPDBId(pdbentry);
4078 alignPanel.getStructureSelectionManager()
4079 .registerPDBEntry(pdbentry);
4085 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
4089 Vector sequences = new Vector();
4090 for (int i = 0; i < seqs.length; i++)
4092 if (seqs[i] != null)
4095 .addElement(new Object[]
4096 { seqs[i], (chains != null) ? chains[i] : null });
4099 seqs = new SequenceI[sequences.size()];
4100 chains = new String[sequences.size()];
4101 for (int i = 0, isize = sequences.size(); i < isize; i++)
4103 Object[] oj = (Object[]) sequences.elementAt(i);
4105 seqs[i] = (SequenceI) oj[0];
4106 chains[i] = (String) oj[1];
4109 return new Object[] { seqs, chains };
4113 public void newStructureView(JalviewLite applet, PDBEntry pdb,
4114 SequenceI[] seqs, String[] chains, DataSourceType protocol)
4116 // Scrub any null sequences from the array
4117 Object[] sqch = cleanSeqChainArrays(seqs, chains);
4118 seqs = (SequenceI[]) sqch[0];
4119 chains = (String[]) sqch[1];
4120 if (seqs == null || seqs.length == 0)
4123 "JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
4125 if (protocol == null)
4127 String sourceType = (String) pdb.getProperty("protocol");
4130 protocol = DataSourceType.valueOf(sourceType);
4131 } catch (IllegalArgumentException e)
4135 if (protocol == null)
4137 System.err.println("Couldn't work out protocol to open structure: "
4142 if (applet.useXtrnalSviewer)
4144 // register the association(s) and quit, don't create any windows.
4145 if (StructureSelectionManager.getStructureSelectionManager(applet)
4146 .setMapping(seqs, chains, pdb.getFile(), protocol, null) == null)
4148 System.err.println("Failed to map " + pdb.getFile() + " ("
4149 + protocol + ") to any sequences");
4153 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
4155 // can only do alignments with Jmol
4156 // find the last jmol window assigned to this alignment
4157 AppletJmol ajm = null, tajm;
4158 Vector jmols = applet.getAppletWindow(AppletJmol.class);
4159 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
4161 tajm = (AppletJmol) jmols.elementAt(i);
4162 if (tajm.ap.alignFrame == this)
4171 "Incremental adding and aligning structure to existing Jmol view not yet implemented.");
4172 // try and add the pdb structure
4177 // otherwise, create a new window
4178 if (applet.jmolAvailable)
4180 new AppletJmol(pdb, seqs, chains, alignPanel, protocol);
4181 applet.lastFrameX += 40;
4182 applet.lastFrameY += 40;
4186 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
4191 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
4192 SequenceI[][] seqs, String[][] chains, String[] protocols)
4194 // TODO Auto-generated method stub
4195 System.err.println("Aligned Structure View: Not yet implemented.");
4199 * modify the current selection, providing the user has not made a selection
4203 * - sequences from this alignment
4205 * - columns to be selected on the alignment
4207 public void select(SequenceGroup sel, ColumnSelection csel,
4208 HiddenColumns hidden)
4210 alignPanel.seqPanel.selection(sel, csel, hidden, null);
4213 public void scrollTo(int row, int column)
4215 alignPanel.seqPanel.scrollTo(row, column);
4218 public void scrollToRow(int row)
4220 alignPanel.seqPanel.scrollToRow(row);
4223 public void scrollToColumn(int column)
4225 alignPanel.seqPanel.scrollToColumn(column);
4229 * @return the alignments unique ID.
4231 public String getSequenceSetId()
4233 return viewport.getSequenceSetId();
4237 * Load the (T-Coffee) score file from the specified url
4240 * File/URL/T-COFFEE score file contents
4241 * @throws IOException
4242 * @return true if alignment was annotated with data from source
4244 public boolean loadScoreFile(String source) throws IOException
4247 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
4248 AppletFormatAdapter.checkProtocol(source));
4249 if (!file.isValid())
4251 // TODO: raise dialog for gui
4252 System.err.println("Problems parsing T-Coffee scores: "
4253 + file.getWarningMessage());
4254 System.err.println("Origin was:\n" + source);
4259 * check that the score matrix matches the alignment dimensions
4262 if ((aln = viewport.getAlignment()) != null
4263 && (aln.getHeight() != file.getHeight()
4264 || aln.getWidth() != file.getWidth()))
4266 // TODO: raise a dialog box here rather than bomb out.
4268 "The scores matrix does not match the alignment dimensions");
4272 // TODO add parameter to indicate if matching should be done
4273 if (file.annotateAlignment(alignPanel.getAlignment(), false))
4275 alignPanel.fontChanged();
4276 tcoffeeColour.setEnabled(true);
4277 // switch to this color
4278 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4283 System.err.println("Problems resolving T-Coffee scores:");
4284 if (file.getWarningMessage() != null)
4286 System.err.println(file.getWarningMessage());
4292 public SplitFrame getSplitFrame()
4294 return this.splitFrame;
4297 public void setSplitFrame(SplitFrame sf)
4299 this.splitFrame = sf;
4302 // may not need this
4304 public void setShowSeqFeatures(boolean b)
4306 // showSeqFeatures.setSelected(b);
4307 viewport.setShowSequenceFeatures(b);
4312 public void setMenusForViewport()
4314 // setMenusFromViewport(viewport);
4319 public void refreshFeatureUI(boolean enableIfNecessary)
4321 if (enableIfNecessary)
4323 sequenceFeatures.setState(true);
4324 alignPanel.av.setShowSequenceFeatures(true);
4329 public FeatureSettingsControllerI getFeatureSettingsUI()
4331 return alignPanel.av.featureSettings;