2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
20 import jalview.analysis.AlignmentSorter;
21 import jalview.analysis.Conservation;
22 import jalview.api.SequenceStructureBinding;
23 import jalview.bin.JalviewLite;
24 import jalview.commands.CommandI;
25 import jalview.commands.EditCommand;
26 import jalview.commands.OrderCommand;
27 import jalview.commands.RemoveGapColCommand;
28 import jalview.commands.RemoveGapsCommand;
29 import jalview.commands.SlideSequencesCommand;
30 import jalview.commands.TrimRegionCommand;
31 import jalview.datamodel.Alignment;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.AlignmentOrder;
34 import jalview.datamodel.ColumnSelection;
35 import jalview.datamodel.PDBEntry;
36 import jalview.datamodel.Sequence;
37 import jalview.datamodel.SequenceGroup;
38 import jalview.datamodel.SequenceI;
39 import jalview.io.AnnotationFile;
40 import jalview.io.AppletFormatAdapter;
41 import jalview.io.FeaturesFile;
42 import jalview.io.TCoffeeScoreFile;
43 import jalview.schemes.Blosum62ColourScheme;
44 import jalview.schemes.BuriedColourScheme;
45 import jalview.schemes.ClustalxColourScheme;
46 import jalview.schemes.ColourSchemeI;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.NucleotideColourScheme;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.PurinePyrimidineColourScheme;
52 import jalview.schemes.RNAHelicesColourChooser;
53 import jalview.schemes.ResidueProperties;
54 import jalview.schemes.StrandColourScheme;
55 import jalview.schemes.TCoffeeColourScheme;
56 import jalview.schemes.TaylorColourScheme;
57 import jalview.schemes.TurnColourScheme;
58 import jalview.schemes.ZappoColourScheme;
59 import jalview.structure.StructureSelectionManager;
61 import java.awt.BorderLayout;
62 import java.awt.Canvas;
63 import java.awt.CheckboxMenuItem;
64 import java.awt.Color;
66 import java.awt.FontMetrics;
67 import java.awt.Frame;
68 import java.awt.Graphics;
69 import java.awt.Label;
71 import java.awt.MenuBar;
72 import java.awt.MenuItem;
73 import java.awt.event.ActionEvent;
74 import java.awt.event.ActionListener;
75 import java.awt.event.FocusEvent;
76 import java.awt.event.FocusListener;
77 import java.awt.event.ItemEvent;
78 import java.awt.event.ItemListener;
79 import java.awt.event.KeyEvent;
80 import java.awt.event.KeyListener;
81 import java.awt.event.WindowAdapter;
82 import java.awt.event.WindowEvent;
83 import java.io.IOException;
85 import java.net.URLEncoder;
86 import java.util.Enumeration;
87 import java.util.Hashtable;
88 import java.util.List;
89 import java.util.StringTokenizer;
90 import java.util.Vector;
92 public class AlignFrame extends EmbmenuFrame implements ActionListener,
93 ItemListener, KeyListener
95 public AlignmentPanel alignPanel;
97 public AlignViewport viewport;
99 int DEFAULT_WIDTH = 700;
101 int DEFAULT_HEIGHT = 500;
103 String jalviewServletURL;
105 public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet,
106 String title, boolean embedded)
110 jalviewServletURL = applet.getParameter("APPLICATION_URL");
116 } catch (Exception ex)
118 ex.printStackTrace();
121 viewport = new AlignViewport(al, applet);
122 alignPanel = new AlignmentPanel(this, viewport);
124 viewport.updateConservation(alignPanel);
125 viewport.updateConsensus(alignPanel);
127 annotationPanelMenuItem.setState(viewport.showAnnotation);
128 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
129 followMouseOverFlag.setState(viewport.getFollowHighlight());
130 showGroupConsensus.setState(viewport.isShowGroupConsensus());
131 showGroupConservation.setState(viewport.isShowGroupConservation());
132 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
133 showSequenceLogo.setState(viewport.isShowSequenceLogo());
134 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
136 seqLimits.setState(viewport.showJVSuffix);
140 String param = applet.getParameter("sortBy");
143 if (param.equalsIgnoreCase("Id"))
145 sortIDMenuItem_actionPerformed();
147 else if (param.equalsIgnoreCase("Pairwise Identity"))
149 sortPairwiseMenuItem_actionPerformed();
151 else if (param.equalsIgnoreCase("Length"))
153 sortLengthMenuItem_actionPerformed();
157 param = applet.getParameter("wrap");
160 if (param.equalsIgnoreCase("true"))
162 wrapMenuItem.setState(true);
163 wrapMenuItem_actionPerformed();
166 param = applet.getParameter("centrecolumnlabels");
169 centreColumnLabelFlag.setState(true);
170 centreColumnLabelFlag_stateChanged();
174 param = applet.getParameter("windowWidth");
177 int width = Integer.parseInt(param);
178 DEFAULT_WIDTH = width;
180 param = applet.getParameter("windowHeight");
183 int height = Integer.parseInt(param);
184 DEFAULT_HEIGHT = height;
186 } catch (Exception ex)
191 if (viewport.getAlignment().isNucleotide())
193 viewport.updateStrucConsensus(alignPanel);
194 if (viewport.getAlignment().hasRNAStructure())
196 RNAHelixColour.setEnabled(true);
200 RNAHelixColour.setEnabled(false);
205 RNAHelixColour.setEnabled(false);
206 purinePyrimidineColour.setEnabled(false);
208 // Some JVMS send keyevents to Top frame or lowest panel,
209 // Havent worked out why yet. So add to both this frame and seqCanvas for
211 this.addKeyListener(this);
212 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
213 alignPanel.idPanel.idCanvas.addKeyListener(this);
214 alignPanel.scalePanel.addKeyListener(this);
215 alignPanel.annotationPanel.addKeyListener(this);
216 alignPanel.annotationPanelHolder.addKeyListener(this);
217 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
218 alignPanel.alabels.addKeyListener(this);
219 createAlignFrameWindow(embedded, title);
222 alignPanel.adjustAnnotationHeight();
223 alignPanel.paintAlignment(true);
226 public AlignViewport getAlignViewport()
231 public SeqCanvas getSeqcanvas()
233 return alignPanel.seqPanel.seqCanvas;
237 * Load a features file onto the alignment
240 * file URL, content, or other resolvable path
242 * is protocol for accessing data referred to by file
245 public boolean parseFeaturesFile(String file, String type)
247 return parseFeaturesFile(file, type, true);
251 * Load a features file onto the alignment
254 * file URL, content, or other resolvable path
256 * is protocol for accessing data referred to by file
257 * @param autoenabledisplay
258 * when true, display features flag will be automatically enabled if
259 * features are loaded
260 * @return true if data parsed as a features file
262 public boolean parseFeaturesFile(String file, String type,
263 boolean autoenabledisplay)
265 // TODO: test if importing a features file onto an alignment which already
266 // has features with links overwrites the original links.
268 Hashtable featureLinks = new Hashtable();
269 boolean featuresFile = false;
272 featuresFile = new jalview.io.FeaturesFile(file, type)
273 .parse(viewport.getAlignment(), alignPanel.seqPanel.seqCanvas
274 .getFeatureRenderer().featureColours, featureLinks,
275 true, viewport.applet.getDefaultParameter(
276 "relaxedidmatch", false));
277 } catch (Exception ex)
279 ex.printStackTrace();
284 if (featureLinks.size() > 0)
286 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureLinks = featureLinks;
288 if (autoenabledisplay)
290 viewport.showSequenceFeatures = true;
291 sequenceFeatures.setState(true);
293 if (viewport.featureSettings != null)
295 viewport.featureSettings.refreshTable();
297 alignPanel.paintAlignment(true);
298 statusBar.setText("Successfully added features to alignment.");
304 public void keyPressed(KeyEvent evt)
306 if (viewport.cursorMode
307 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
308 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
309 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
310 && Character.isDigit(evt.getKeyChar()))
311 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
313 switch (evt.getKeyCode())
315 case 27: // escape key
316 deselectAllSequenceMenuItem_actionPerformed();
318 alignPanel.alabels.cancelDrag();
321 if (evt.isControlDown() || evt.isMetaDown())
323 cut_actionPerformed();
327 if (viewport.cursorMode && !evt.isControlDown())
329 alignPanel.seqPanel.setCursorColumn();
331 if (evt.isControlDown() || evt.isMetaDown())
333 copy_actionPerformed();
337 if (evt.isControlDown())
339 paste(evt.isShiftDown());
343 if (evt.isControlDown() || evt.isMetaDown())
345 selectAllSequenceMenuItem_actionPerformed();
348 case KeyEvent.VK_DOWN:
349 if (viewport.cursorMode)
351 alignPanel.seqPanel.moveCursor(0, 1);
355 moveSelectedSequences(false);
360 if (viewport.cursorMode)
362 alignPanel.seqPanel.moveCursor(0, -1);
366 moveSelectedSequences(true);
370 case KeyEvent.VK_LEFT:
371 if (evt.isAltDown() || !viewport.cursorMode)
372 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
374 alignPanel.seqPanel.moveCursor(-1, 0);
377 case KeyEvent.VK_RIGHT:
378 if (evt.isAltDown() || !viewport.cursorMode)
379 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
381 alignPanel.seqPanel.moveCursor(1, 0);
384 case KeyEvent.VK_SPACE:
385 if (viewport.cursorMode)
387 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
388 || evt.isShiftDown() || evt.isAltDown());
392 case KeyEvent.VK_DELETE:
393 case KeyEvent.VK_BACK_SPACE:
394 if (viewport.cursorMode)
396 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
397 || evt.isShiftDown() || evt.isAltDown());
401 cut_actionPerformed();
402 alignPanel.seqPanel.seqCanvas.repaint();
407 if (viewport.cursorMode)
409 alignPanel.seqPanel.setCursorRow();
413 if (viewport.cursorMode)
415 alignPanel.seqPanel.setCursorPosition();
419 case KeyEvent.VK_ENTER:
420 case KeyEvent.VK_COMMA:
421 if (viewport.cursorMode)
423 alignPanel.seqPanel.setCursorRowAndColumn();
428 if (viewport.cursorMode)
430 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
434 if (viewport.cursorMode)
436 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
441 viewport.cursorMode = !viewport.cursorMode;
442 statusBar.setText("Keyboard editing mode is "
443 + (viewport.cursorMode ? "on" : "off"));
444 if (viewport.cursorMode)
446 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
447 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
452 if (evt.isControlDown())
454 findMenuItem_actionPerformed();
460 boolean toggleSeqs = !evt.isControlDown();
461 boolean toggleCols = !evt.isShiftDown();
462 toggleHiddenRegions(toggleSeqs, toggleCols);
466 case KeyEvent.VK_PAGE_UP:
467 if (viewport.wrapAlignment)
469 alignPanel.scrollUp(true);
473 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
474 - viewport.endSeq + viewport.startSeq);
478 case KeyEvent.VK_PAGE_DOWN:
479 if (viewport.wrapAlignment)
481 alignPanel.scrollUp(false);
485 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
486 + viewport.endSeq - viewport.startSeq);
491 if (evt.isControlDown())
493 undoMenuItem_actionPerformed();
498 if (evt.isControlDown())
500 redoMenuItem_actionPerformed();
505 if (evt.isControlDown())
512 if (evt.isControlDown())
514 trimAlignment(false);
519 if (evt.isControlDown())
521 if (evt.isShiftDown())
523 this.removeAllGapsMenuItem_actionPerformed();
527 removeGappedColumnMenuItem_actionPerformed();
532 if (evt.isControlDown())
536 invertColSel_actionPerformed();
540 invertSequenceMenuItem_actionPerformed();
546 if (evt.isControlDown())
548 this.deleteGroups_actionPerformed();
553 if (evt.isControlDown())
560 alignPanel.paintAlignment(true);
564 * called by key handler and the hide all/show all menu items
569 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
571 boolean hide = false;
572 SequenceGroup sg = viewport.getSelectionGroup();
573 if (!toggleSeqs && !toggleCols)
575 // Hide everything by the current selection - this is a hack - we do the
576 // invert and then hide
577 // first check that there will be visible columns after the invert.
578 if ((viewport.getColumnSelection() != null
579 && viewport.getColumnSelection().getSelected() != null && viewport
580 .getColumnSelection().getSelected().size() > 0)
581 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
584 // now invert the sequence set, if required - empty selection implies
585 // that no hiding is required.
588 invertSequenceMenuItem_actionPerformed();
589 sg = viewport.getSelectionGroup();
593 viewport.expandColSelection(sg, true);
594 // finally invert the column selection and get the new sequence
595 // selection and indicate it should be hidden.
596 invertColSel_actionPerformed();
603 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
606 viewport.hideAllSelectedSeqs();
608 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
611 viewport.showAllHiddenSeqs();
617 if (viewport.getColumnSelection().getSelected().size() > 0)
619 viewport.hideSelectedColumns();
622 viewport.setSelectionGroup(sg);
627 viewport.showAllHiddenColumns();
633 public void keyReleased(KeyEvent evt)
638 public void keyTyped(KeyEvent evt)
643 public void itemStateChanged(ItemEvent evt)
645 if (evt.getSource() == displayNonconservedMenuItem)
647 displayNonconservedMenuItem_actionPerformed();
649 else if (evt.getSource() == colourTextMenuItem)
651 colourTextMenuItem_actionPerformed();
653 else if (evt.getSource() == wrapMenuItem)
655 wrapMenuItem_actionPerformed();
657 else if (evt.getSource() == scaleAbove)
659 viewport.setScaleAboveWrapped(scaleAbove.getState());
661 else if (evt.getSource() == scaleLeft)
663 viewport.setScaleLeftWrapped(scaleLeft.getState());
665 else if (evt.getSource() == scaleRight)
667 viewport.setScaleRightWrapped(scaleRight.getState());
669 else if (evt.getSource() == seqLimits)
671 seqLimits_itemStateChanged();
673 else if (evt.getSource() == viewBoxesMenuItem)
675 viewport.setShowBoxes(viewBoxesMenuItem.getState());
677 else if (evt.getSource() == viewTextMenuItem)
679 viewport.setShowText(viewTextMenuItem.getState());
681 else if (evt.getSource() == renderGapsMenuItem)
683 viewport.setRenderGaps(renderGapsMenuItem.getState());
685 else if (evt.getSource() == annotationPanelMenuItem)
687 viewport.setShowAnnotation(annotationPanelMenuItem.getState());
688 alignPanel.setAnnotationVisible(annotationPanelMenuItem.getState());
690 else if (evt.getSource() == sequenceFeatures)
692 viewport.showSequenceFeatures(sequenceFeatures.getState());
693 alignPanel.seqPanel.seqCanvas.repaint();
695 else if (evt.getSource() == conservationMenuItem)
697 conservationMenuItem_actionPerformed();
699 else if (evt.getSource() == abovePIDThreshold)
701 abovePIDThreshold_actionPerformed();
703 else if (evt.getSource() == applyToAllGroups)
705 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
707 else if (evt.getSource() == autoCalculate)
709 viewport.autoCalculateConsensus = autoCalculate.getState();
711 else if (evt.getSource() == sortByTree)
713 viewport.sortByTree = sortByTree.getState();
715 else if (evt.getSource() == this.centreColumnLabelFlag)
717 centreColumnLabelFlag_stateChanged();
719 else if (evt.getSource() == this.followMouseOverFlag)
721 mouseOverFlag_stateChanged();
723 else if (evt.getSource() == showGroupConsensus)
725 showGroupConsensus_actionPerformed();
727 else if (evt.getSource() == showGroupConservation)
729 showGroupConservation_actionPerformed();
731 else if (evt.getSource() == showSequenceLogo)
733 showSequenceLogo_actionPerformed();
735 else if (evt.getSource() == normSequenceLogo)
737 normSequenceLogo_actionPerformed();
739 else if (evt.getSource() == showConsensusHistogram)
741 showConsensusHistogram_actionPerformed();
743 else if (evt.getSource() == applyAutoAnnotationSettings)
745 applyAutoAnnotationSettings_actionPerformed();
747 alignPanel.paintAlignment(true);
750 private void mouseOverFlag_stateChanged()
752 viewport.followHighlight = followMouseOverFlag.getState();
753 // TODO: could kick the scrollTo mechanism to reset view for current
757 private void centreColumnLabelFlag_stateChanged()
759 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
760 this.alignPanel.annotationPanel.repaint();
764 public void actionPerformed(ActionEvent evt)
766 Object source = evt.getSource();
768 if (source == inputText)
770 inputText_actionPerformed();
772 else if (source == loadTree)
774 loadTree_actionPerformed();
776 else if (source == loadApplication)
778 launchFullApplication();
780 else if (source == loadAnnotations)
784 else if (source == outputAnnotations)
786 outputAnnotations(true);
788 else if (source == outputFeatures)
790 outputFeatures(true, "Jalview");
792 else if (source == closeMenuItem)
794 closeMenuItem_actionPerformed();
796 else if (source == copy)
798 copy_actionPerformed();
800 else if (source == undoMenuItem)
802 undoMenuItem_actionPerformed();
804 else if (source == redoMenuItem)
806 redoMenuItem_actionPerformed();
808 else if (source == inputText)
810 inputText_actionPerformed();
812 else if (source == closeMenuItem)
814 closeMenuItem_actionPerformed();
816 else if (source == undoMenuItem)
818 undoMenuItem_actionPerformed();
820 else if (source == redoMenuItem)
822 redoMenuItem_actionPerformed();
824 else if (source == copy)
826 copy_actionPerformed();
828 else if (source == pasteNew)
830 pasteNew_actionPerformed();
832 else if (source == pasteThis)
834 pasteThis_actionPerformed();
836 else if (source == cut)
838 cut_actionPerformed();
840 else if (source == delete)
842 delete_actionPerformed();
844 else if (source == grpsFromSelection)
846 makeGrpsFromSelection_actionPerformed();
848 else if (source == deleteGroups)
850 deleteGroups_actionPerformed();
852 else if (source == selectAllSequenceMenuItem)
854 selectAllSequenceMenuItem_actionPerformed();
856 else if (source == deselectAllSequenceMenuItem)
858 deselectAllSequenceMenuItem_actionPerformed();
860 else if (source == invertSequenceMenuItem)
862 invertSequenceMenuItem_actionPerformed();
864 else if (source == invertColSel)
866 viewport.invertColumnSelection();
867 alignPanel.paintAlignment(true);
869 else if (source == remove2LeftMenuItem)
873 else if (source == remove2RightMenuItem)
875 trimAlignment(false);
877 else if (source == removeGappedColumnMenuItem)
879 removeGappedColumnMenuItem_actionPerformed();
881 else if (source == removeAllGapsMenuItem)
883 removeAllGapsMenuItem_actionPerformed();
885 else if (source == findMenuItem)
887 findMenuItem_actionPerformed();
889 else if (source == font)
891 new FontChooser(alignPanel);
893 else if (source == newView)
897 else if (source == showColumns)
899 viewport.showAllHiddenColumns();
900 alignPanel.paintAlignment(true);
902 else if (source == showSeqs)
904 viewport.showAllHiddenSeqs();
905 alignPanel.paintAlignment(true);
907 else if (source == hideColumns)
909 viewport.hideSelectedColumns();
910 alignPanel.paintAlignment(true);
912 else if (source == hideSequences
913 && viewport.getSelectionGroup() != null)
915 viewport.hideAllSelectedSeqs();
916 alignPanel.paintAlignment(true);
918 else if (source == hideAllButSelection)
920 toggleHiddenRegions(false, false);
921 alignPanel.paintAlignment(true);
923 else if (source == hideAllSelection)
925 SequenceGroup sg = viewport.getSelectionGroup();
926 viewport.expandColSelection(sg, false);
927 viewport.hideAllSelectedSeqs();
928 viewport.hideSelectedColumns();
929 alignPanel.paintAlignment(true);
931 else if (source == showAllHidden)
933 viewport.showAllHiddenColumns();
934 viewport.showAllHiddenSeqs();
935 alignPanel.paintAlignment(true);
937 else if (source == showGroupConsensus)
939 showGroupConsensus_actionPerformed();
941 else if (source == showGroupConservation)
943 showGroupConservation_actionPerformed();
945 else if (source == showSequenceLogo)
947 showSequenceLogo_actionPerformed();
949 else if (source == normSequenceLogo)
951 normSequenceLogo_actionPerformed();
953 else if (source == showConsensusHistogram)
955 showConsensusHistogram_actionPerformed();
957 else if (source == applyAutoAnnotationSettings)
959 applyAutoAnnotationSettings_actionPerformed();
961 else if (source == featureSettings)
963 new FeatureSettings(alignPanel);
965 else if (source == alProperties)
967 StringBuffer contents = new jalview.io.AlignmentProperties(
968 viewport.getAlignment()).formatAsString();
969 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
970 cap.setText(contents.toString());
971 Frame frame = new Frame();
973 jalview.bin.JalviewLite.addFrame(frame, "Alignment Properties: "
974 + getTitle(), 400, 250);
976 else if (source == overviewMenuItem)
978 overviewMenuItem_actionPerformed();
980 else if (source == noColourmenuItem)
984 else if (source == clustalColour)
986 abovePIDThreshold.setState(false);
987 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
989 else if (source == zappoColour)
991 changeColour(new ZappoColourScheme());
993 else if (source == taylorColour)
995 changeColour(new TaylorColourScheme());
997 else if (source == hydrophobicityColour)
999 changeColour(new HydrophobicColourScheme());
1001 else if (source == helixColour)
1003 changeColour(new HelixColourScheme());
1005 else if (source == strandColour)
1007 changeColour(new StrandColourScheme());
1009 else if (source == turnColour)
1011 changeColour(new TurnColourScheme());
1013 else if (source == buriedColour)
1015 changeColour(new BuriedColourScheme());
1017 else if (source == nucleotideColour)
1019 changeColour(new NucleotideColourScheme());
1021 else if (source == purinePyrimidineColour)
1023 changeColour(new PurinePyrimidineColourScheme());
1025 else if (source == RNAHelixColour)
1027 new RNAHelicesColourChooser(viewport, alignPanel);
1029 else if (source == modifyPID)
1031 modifyPID_actionPerformed();
1033 else if (source == modifyConservation)
1035 modifyConservation_actionPerformed();
1037 else if (source == userDefinedColour)
1039 new UserDefinedColours(alignPanel, null);
1041 else if (source == PIDColour)
1043 changeColour(new PIDColourScheme());
1045 else if (source == BLOSUM62Colour)
1047 changeColour(new Blosum62ColourScheme());
1049 else if (source == tcoffeeColour)
1051 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1053 else if (source == annotationColour)
1055 new AnnotationColourChooser(viewport, alignPanel);
1057 else if (source == sortPairwiseMenuItem)
1059 sortPairwiseMenuItem_actionPerformed();
1061 else if (source == sortIDMenuItem)
1063 sortIDMenuItem_actionPerformed();
1065 else if (source == sortLengthMenuItem)
1067 sortLengthMenuItem_actionPerformed();
1069 else if (source == sortGroupMenuItem)
1071 sortGroupMenuItem_actionPerformed();
1073 else if (source == removeRedundancyMenuItem)
1075 removeRedundancyMenuItem_actionPerformed();
1077 else if (source == pairwiseAlignmentMenuItem)
1079 pairwiseAlignmentMenuItem_actionPerformed();
1081 else if (source == PCAMenuItem)
1083 PCAMenuItem_actionPerformed();
1085 else if (source == averageDistanceTreeMenuItem)
1087 averageDistanceTreeMenuItem_actionPerformed();
1089 else if (source == neighbourTreeMenuItem)
1091 neighbourTreeMenuItem_actionPerformed();
1093 else if (source == njTreeBlosumMenuItem)
1095 njTreeBlosumMenuItem_actionPerformed();
1097 else if (source == avDistanceTreeBlosumMenuItem)
1099 avTreeBlosumMenuItem_actionPerformed();
1101 else if (source == documentation)
1103 documentation_actionPerformed();
1105 else if (source == about)
1107 about_actionPerformed();
1112 public void inputText_actionPerformed()
1114 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1115 Frame frame = new Frame();
1117 jalview.bin.JalviewLite.addFrame(frame, "Cut & Paste Input", 500, 500);
1120 protected void outputText_actionPerformed(ActionEvent e)
1122 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1123 Frame frame = new Frame();
1125 jalview.bin.JalviewLite.addFrame(frame,
1126 "Alignment output - " + e.getActionCommand(), 600, 500);
1127 cap.setText(new AppletFormatAdapter().formatSequences(
1128 e.getActionCommand(), viewport.getAlignment(),
1129 viewport.showJVSuffix));
1132 public void loadAnnotations()
1134 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1135 cap.setText("Paste your features / annotations / T-coffee score file here.");
1136 cap.setAnnotationImport();
1137 Frame frame = new Frame();
1139 jalview.bin.JalviewLite.addFrame(frame, "Paste Annotations ", 400, 300);
1143 public String outputAnnotations(boolean displayTextbox)
1145 String annotation = new AnnotationFile().printAnnotations(
1146 viewport.showAnnotation ? viewport.getAlignment()
1147 .getAlignmentAnnotation() : null, viewport
1148 .getAlignment().getGroups(), ((Alignment) viewport
1149 .getAlignment()).alignmentProperties);
1153 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1154 Frame frame = new Frame();
1156 jalview.bin.JalviewLite.addFrame(frame, "Annotations", 600, 500);
1157 cap.setText(annotation);
1163 private Hashtable getDisplayedFeatureCols()
1165 if (alignPanel.getFeatureRenderer() != null
1166 && viewport.featuresDisplayed != null)
1168 FeatureRenderer fr = alignPanel.getFeatureRenderer();
1169 Hashtable fcols = new Hashtable();
1170 Enumeration en = viewport.featuresDisplayed.keys();
1171 while (en.hasMoreElements())
1173 Object col = en.nextElement();
1174 fcols.put(col, fr.featureColours.get(col));
1181 public String outputFeatures(boolean displayTextbox, String format)
1184 if (format.equalsIgnoreCase("Jalview"))
1186 features = new FeaturesFile().printJalviewFormat(viewport
1187 .getAlignment().getSequencesArray(),
1188 getDisplayedFeatureCols());
1192 features = new FeaturesFile().printGFFFormat(viewport.getAlignment()
1193 .getSequencesArray(), getDisplayedFeatureCols());
1198 boolean frimport = false;
1199 if (features == null || features.equals("No Features Visible"))
1201 features = "# No features visible - paste some and import them here.";
1205 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1208 cap.setAnnotationImport();
1210 Frame frame = new Frame();
1212 jalview.bin.JalviewLite.addFrame(frame, "Features", 600, 500);
1213 cap.setText(features);
1217 if (features == null)
1224 void launchFullApplication()
1226 StringBuffer url = new StringBuffer(jalviewServletURL);
1229 + appendProtocol(viewport.applet.getParameter("file")));
1231 if (viewport.applet.getParameter("features") != null)
1233 url.append("&features=");
1234 url.append(appendProtocol(viewport.applet.getParameter("features")));
1237 if (viewport.applet.getParameter("annotations") != null)
1239 url.append("&annotations=");
1240 url.append(appendProtocol(viewport.applet.getParameter("annotations")));
1243 if (viewport.applet.getParameter("jnetfile") != null)
1245 url.append("&annotations=");
1246 url.append(appendProtocol(viewport.applet.getParameter("jnetfile")));
1249 if (viewport.applet.getParameter("defaultColour") != null)
1251 url.append("&colour="
1252 + removeWhiteSpace(viewport.applet
1253 .getParameter("defaultColour")));
1256 if (viewport.applet.getParameter("userDefinedColour") != null)
1258 url.append("&colour="
1259 + removeWhiteSpace(viewport.applet
1260 .getParameter("userDefinedColour")));
1262 if (viewport.applet.getParameter("tree") != null)
1265 + appendProtocol(viewport.applet.getParameter("tree")));
1267 if (viewport.applet.getParameter("treeFile") != null)
1270 + appendProtocol(viewport.applet.getParameter("treeFile")));
1273 showURL(url.toString(), "FULL_APP");
1276 String removeWhiteSpace(String colour)
1278 StringBuffer sb = new StringBuffer();
1279 for (int i = 0; i < colour.length(); i++)
1281 if (Character.isWhitespace(colour.charAt(i)))
1287 sb.append(colour.charAt(i));
1291 return sb.toString();
1294 String appendProtocol(String url)
1299 url = URLEncoder.encode(url);
1302 * When we finally deprecate 1.1 compatibility, we can start to use
1303 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1304 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1305 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1306 * ex.printStackTrace(); }
1308 catch (java.net.MalformedURLException ex)
1310 url = viewport.applet.getCodeBase() + url;
1315 public void closeMenuItem_actionPerformed()
1317 PaintRefresher.RemoveComponent(alignPanel);
1318 if (alignPanel.seqPanel != null
1319 && alignPanel.seqPanel.seqCanvas != null)
1321 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1323 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1325 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1328 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1343 void updateEditMenuBar()
1346 if (viewport.historyList.size() > 0)
1348 undoMenuItem.setEnabled(true);
1349 CommandI command = (CommandI) viewport.historyList.peek();
1350 undoMenuItem.setLabel("Undo " + command.getDescription());
1354 undoMenuItem.setEnabled(false);
1355 undoMenuItem.setLabel("Undo");
1358 if (viewport.redoList.size() > 0)
1360 redoMenuItem.setEnabled(true);
1362 CommandI command = (CommandI) viewport.redoList.peek();
1363 redoMenuItem.setLabel("Redo " + command.getDescription());
1367 redoMenuItem.setEnabled(false);
1368 redoMenuItem.setLabel("Redo");
1375 public void addHistoryItem(CommandI command)
1377 if (command.getSize() > 0)
1379 viewport.historyList.push(command);
1380 viewport.redoList.removeAllElements();
1381 updateEditMenuBar();
1382 viewport.updateHiddenColumns();
1387 * TODO: JAL-1104 DOCUMENT ME!
1392 protected void undoMenuItem_actionPerformed()
1394 if (viewport.historyList.size() < 1)
1399 CommandI command = (CommandI) viewport.historyList.pop();
1400 viewport.redoList.push(command);
1401 command.undoCommand(null);
1403 AlignViewport originalSource = getOriginatingSource(command);
1405 if (originalSource != viewport)
1408 .println("Warning: Viewport object mismatch whilst undoing");
1410 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1411 // viewport.getColumnSelection().getHiddenColumns()
1413 updateEditMenuBar();
1414 originalSource.firePropertyChange("alignment", null, originalSource
1415 .getAlignment().getSequences());
1419 * TODO: JAL-1104 DOCUMENT ME!
1424 protected void redoMenuItem_actionPerformed()
1426 if (viewport.redoList.size() < 1)
1431 CommandI command = (CommandI) viewport.redoList.pop();
1432 viewport.historyList.push(command);
1433 command.doCommand(null);
1435 AlignViewport originalSource = getOriginatingSource(command);
1437 if (originalSource != viewport)
1440 .println("Warning: Viewport object mismatch whilst re-doing");
1442 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1443 // viewport.getColumnSelection().getHiddenColumns()
1446 updateEditMenuBar();
1447 originalSource.firePropertyChange("alignment", null, originalSource
1448 .getAlignment().getSequences());
1451 AlignViewport getOriginatingSource(CommandI command)
1453 AlignViewport originalSource = null;
1454 // For sequence removal and addition, we need to fire
1455 // the property change event FROM the viewport where the
1456 // original alignment was altered
1457 AlignmentI al = null;
1458 if (command instanceof EditCommand)
1460 EditCommand editCommand = (EditCommand) command;
1461 al = editCommand.getAlignment();
1462 Vector comps = (Vector) PaintRefresher.components.get(viewport
1463 .getSequenceSetId());
1464 for (int i = 0; i < comps.size(); i++)
1466 if (comps.elementAt(i) instanceof AlignmentPanel)
1468 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1470 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1477 if (originalSource == null)
1479 // The original view is closed, we must validate
1480 // the current view against the closed view first
1483 PaintRefresher.validateSequences(al, viewport.getAlignment());
1486 originalSource = viewport;
1489 return originalSource;
1492 public void moveSelectedSequences(boolean up)
1494 SequenceGroup sg = viewport.getSelectionGroup();
1499 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1500 up ? null : viewport.getHiddenRepSequences(), up);
1501 alignPanel.paintAlignment(true);
1504 synchronized void slideSequences(boolean right, int size)
1506 List<SequenceI> sg = new Vector<SequenceI>();
1507 if (viewport.cursorMode)
1509 sg.add(viewport.getAlignment().getSequenceAt(
1510 alignPanel.seqPanel.seqCanvas.cursorY));
1512 else if (viewport.getSelectionGroup() != null
1513 && viewport.getSelectionGroup().getSize() != viewport
1514 .getAlignment().getHeight())
1516 sg = viewport.getSelectionGroup().getSequences(
1517 viewport.getHiddenRepSequences());
1525 Vector<SequenceI> invertGroup = new Vector();
1527 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1529 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1530 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1533 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1535 SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup
1537 for (int i = 0; i < invertGroup.size(); i++)
1538 seqs2[i] = invertGroup.elementAt(i);
1540 SlideSequencesCommand ssc;
1542 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1543 size, viewport.getGapCharacter());
1545 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1546 size, viewport.getGapCharacter());
1548 int groupAdjustment = 0;
1549 if (ssc.getGapsInsertedBegin() && right)
1551 if (viewport.cursorMode)
1552 alignPanel.seqPanel.moveCursor(size, 0);
1554 groupAdjustment = size;
1556 else if (!ssc.getGapsInsertedBegin() && !right)
1558 if (viewport.cursorMode)
1559 alignPanel.seqPanel.moveCursor(-size, 0);
1561 groupAdjustment = -size;
1564 if (groupAdjustment != 0)
1566 viewport.getSelectionGroup().setStartRes(
1567 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1568 viewport.getSelectionGroup().setEndRes(
1569 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1572 boolean appendHistoryItem = false;
1573 if (viewport.historyList != null && viewport.historyList.size() > 0
1574 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1576 appendHistoryItem = ssc
1577 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1581 if (!appendHistoryItem)
1582 addHistoryItem(ssc);
1587 static StringBuffer copiedSequences;
1589 static Vector copiedHiddenColumns;
1591 protected void copy_actionPerformed()
1593 if (viewport.getSelectionGroup() == null)
1598 SequenceGroup sg = viewport.getSelectionGroup();
1599 copiedSequences = new StringBuffer();
1600 Hashtable orderedSeqs = new Hashtable();
1601 for (int i = 0; i < sg.getSize(); i++)
1603 SequenceI seq = sg.getSequenceAt(i);
1604 int index = viewport.getAlignment().findIndex(seq);
1605 orderedSeqs.put(index + "", seq);
1608 int index = 0, startRes, endRes;
1611 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1613 copiedHiddenColumns = new Vector();
1614 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1615 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1618 int[] region = (int[]) viewport.getColumnSelection()
1619 .getHiddenColumns().elementAt(i);
1621 copiedHiddenColumns.addElement(new int[]
1622 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1627 copiedHiddenColumns = null;
1630 for (int i = 0; i < sg.getSize(); i++)
1632 SequenceI seq = null;
1636 if (orderedSeqs.containsKey(index + ""))
1638 seq = (SequenceI) orderedSeqs.get(index + "");
1650 // Returns residue following index if gap
1651 startRes = seq.findPosition(sg.getStartRes());
1654 // Need to find the residue preceeding index if gap
1657 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1659 ch = seq.getCharAt(j);
1660 if (!jalview.util.Comparison.isGap((ch)))
1668 endRes += seq.getStart() - 1;
1671 copiedSequences.append(seq.getName()
1677 + seq.getSequenceAsString(sg.getStartRes(),
1678 sg.getEndRes() + 1) + "\n");
1683 protected void pasteNew_actionPerformed()
1688 protected void pasteThis_actionPerformed()
1693 void paste(boolean newAlignment)
1698 if (copiedSequences == null)
1703 StringTokenizer st = new StringTokenizer(copiedSequences.toString());
1704 Vector seqs = new Vector();
1705 while (st.hasMoreElements())
1707 String name = st.nextToken();
1708 int start = Integer.parseInt(st.nextToken());
1709 int end = Integer.parseInt(st.nextToken());
1710 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
1712 SequenceI[] newSeqs = new SequenceI[seqs.size()];
1713 for (int i = 0; i < seqs.size(); i++)
1715 newSeqs[i] = (SequenceI) seqs.elementAt(i);
1720 String newtitle = new String("Copied sequences");
1721 if (getTitle().startsWith("Copied sequences"))
1723 newtitle = getTitle();
1727 newtitle = newtitle.concat("- from " + getTitle());
1729 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
1730 viewport.applet, newtitle, false);
1731 if (copiedHiddenColumns != null)
1733 for (int i = 0; i < copiedHiddenColumns.size(); i++)
1735 int[] region = (int[]) copiedHiddenColumns.elementAt(i);
1736 af.viewport.hideColumns(region[0], region[1]);
1740 jalview.bin.JalviewLite.addFrame(af, newtitle, DEFAULT_WIDTH,
1745 addSequences(newSeqs);
1748 } catch (Exception ex)
1750 } // could be anything being pasted in here
1754 void addSequences(SequenceI[] seqs)
1756 for (int i = 0; i < seqs.length; i++)
1758 viewport.getAlignment().addSequence(seqs[i]);
1762 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1763 seqs, 0, viewport.getAlignment().getWidth(),
1764 viewport.getAlignment()));
1766 viewport.setEndSeq(viewport.getAlignment().getHeight());
1767 viewport.getAlignment().getWidth();
1768 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1773 protected void cut_actionPerformed()
1775 copy_actionPerformed();
1776 delete_actionPerformed();
1779 protected void delete_actionPerformed()
1782 SequenceGroup sg = viewport.getSelectionGroup();
1788 Vector seqs = new Vector();
1790 for (int i = 0; i < sg.getSize(); i++)
1792 seq = sg.getSequenceAt(i);
1793 seqs.addElement(seq);
1796 // If the cut affects all sequences, remove highlighted columns
1797 if (sg.getSize() == viewport.getAlignment().getHeight())
1799 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1800 sg.getEndRes() + 1);
1803 SequenceI[] cut = new SequenceI[seqs.size()];
1804 for (int i = 0; i < seqs.size(); i++)
1806 cut[i] = (SequenceI) seqs.elementAt(i);
1810 * //ADD HISTORY ITEM
1812 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
1813 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
1814 viewport.getAlignment()));
1816 viewport.setSelectionGroup(null);
1817 viewport.getAlignment().deleteGroup(sg);
1819 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1822 if (viewport.getAlignment().getHeight() < 1)
1824 this.setVisible(false);
1826 viewport.sendSelection();
1830 * group consensus toggled
1833 protected void showGroupConsensus_actionPerformed()
1835 viewport.setShowGroupConsensus(showGroupConsensus.getState());
1836 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1841 * group conservation toggled.
1843 protected void showGroupConservation_actionPerformed()
1845 viewport.setShowGroupConservation(showGroupConservation.getState());
1846 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1853 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
1854 * .event.ActionEvent)
1856 protected void showConsensusHistogram_actionPerformed()
1858 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
1859 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1866 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
1867 * .event.ActionEvent)
1869 protected void showSequenceLogo_actionPerformed()
1871 viewport.setShowSequenceLogo(showSequenceLogo.getState());
1872 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1875 protected void normSequenceLogo_actionPerformed()
1877 showSequenceLogo.setState(true);
1878 viewport.setShowSequenceLogo(true);
1879 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
1880 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1883 protected void applyAutoAnnotationSettings_actionPerformed()
1885 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1888 protected void makeGrpsFromSelection_actionPerformed()
1890 if (viewport.getSelectionGroup() != null)
1892 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
1893 viewport.getSequenceSelection(),
1894 viewport.getAlignmentView(true).getSequenceStrings(
1895 viewport.getGapCharacter()), viewport.getAlignment()
1897 viewport.getAlignment().deleteAllGroups();
1898 viewport.sequenceColours = null;
1899 viewport.setSelectionGroup(null);
1900 // set view properties for each group
1901 for (int g = 0; g < gps.length; g++)
1903 // gps[g].setShowunconserved(viewport.getShowUnconserved());
1904 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
1905 viewport.getAlignment().addGroup(gps[g]);
1906 Color col = new Color((int) (Math.random() * 255),
1907 (int) (Math.random() * 255), (int) (Math.random() * 255));
1908 col = col.brighter();
1909 for (SequenceI sq : gps[g].getSequences(null))
1910 viewport.setSequenceColour(sq, col);
1912 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1913 alignPanel.updateAnnotation();
1914 alignPanel.paintAlignment(true);
1918 protected void deleteGroups_actionPerformed()
1920 viewport.getAlignment().deleteAllGroups();
1921 viewport.sequenceColours = null;
1922 viewport.setSelectionGroup(null);
1924 alignPanel.paintAlignment(true);
1927 public void selectAllSequenceMenuItem_actionPerformed()
1929 SequenceGroup sg = new SequenceGroup();
1930 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1932 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1934 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
1935 viewport.setSelectionGroup(sg);
1936 alignPanel.paintAlignment(true);
1937 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1938 viewport.sendSelection();
1941 public void deselectAllSequenceMenuItem_actionPerformed()
1943 if (viewport.cursorMode)
1945 alignPanel.seqPanel.keyboardNo1 = null;
1946 alignPanel.seqPanel.keyboardNo2 = null;
1948 viewport.setSelectionGroup(null);
1949 viewport.getColumnSelection().clear();
1950 viewport.setSelectionGroup(null);
1951 alignPanel.idPanel.idCanvas.searchResults = null;
1952 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1953 alignPanel.paintAlignment(true);
1954 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1955 viewport.sendSelection();
1958 public void invertSequenceMenuItem_actionPerformed()
1960 SequenceGroup sg = viewport.getSelectionGroup();
1961 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1963 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1966 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1967 viewport.sendSelection();
1970 public void invertColSel_actionPerformed()
1972 viewport.invertColumnSelection();
1973 alignPanel.paintAlignment(true);
1974 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1975 viewport.sendSelection();
1978 void trimAlignment(boolean trimLeft)
1980 ColumnSelection colSel = viewport.getColumnSelection();
1983 if (colSel.size() > 0)
1987 column = colSel.getMin();
1991 column = colSel.getMax();
1995 if (viewport.getSelectionGroup() != null)
1997 seqs = viewport.getSelectionGroup().getSequencesAsArray(
1998 viewport.getHiddenRepSequences());
2002 seqs = viewport.getAlignment().getSequencesArray();
2005 TrimRegionCommand trimRegion;
2008 trimRegion = new TrimRegionCommand("Remove Left",
2009 TrimRegionCommand.TRIM_LEFT, seqs, column,
2010 viewport.getAlignment(), viewport.getColumnSelection(),
2011 viewport.getSelectionGroup());
2012 viewport.setStartRes(0);
2016 trimRegion = new TrimRegionCommand("Remove Right",
2017 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2018 viewport.getAlignment(), viewport.getColumnSelection(),
2019 viewport.getSelectionGroup());
2022 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2024 addHistoryItem(trimRegion);
2026 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2028 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2029 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2031 viewport.getAlignment().deleteGroup(sg);
2035 viewport.firePropertyChange("alignment", null, viewport
2036 .getAlignment().getSequences());
2040 public void removeGappedColumnMenuItem_actionPerformed()
2042 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2045 if (viewport.getSelectionGroup() != null)
2047 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2048 viewport.getHiddenRepSequences());
2049 start = viewport.getSelectionGroup().getStartRes();
2050 end = viewport.getSelectionGroup().getEndRes();
2054 seqs = viewport.getAlignment().getSequencesArray();
2057 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2058 "Remove Gapped Columns", seqs, start, end,
2059 viewport.getAlignment());
2061 addHistoryItem(removeGapCols);
2063 statusBar.setText("Removed " + removeGapCols.getSize()
2064 + " empty columns.");
2066 // This is to maintain viewport position on first residue
2067 // of first sequence
2068 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2069 int startRes = seq.findPosition(viewport.startRes);
2070 // ShiftList shifts;
2071 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2072 // edit.alColumnChanges=shifts.getInverse();
2073 // if (viewport.hasHiddenColumns)
2074 // viewport.getColumnSelection().compensateForEdits(shifts);
2075 viewport.setStartRes(seq.findIndex(startRes) - 1);
2076 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2081 public void removeAllGapsMenuItem_actionPerformed()
2083 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2086 if (viewport.getSelectionGroup() != null)
2088 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2089 viewport.getHiddenRepSequences());
2090 start = viewport.getSelectionGroup().getStartRes();
2091 end = viewport.getSelectionGroup().getEndRes();
2095 seqs = viewport.getAlignment().getSequencesArray();
2098 // This is to maintain viewport position on first residue
2099 // of first sequence
2100 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2101 int startRes = seq.findPosition(viewport.startRes);
2103 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2104 viewport.getAlignment()));
2106 viewport.setStartRes(seq.findIndex(startRes) - 1);
2108 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2113 public void findMenuItem_actionPerformed()
2115 new Finder(alignPanel);
2119 * create a new view derived from the current view
2122 * @return frame for the new view
2124 public AlignFrame newView(String viewtitle)
2127 if (viewport.hasHiddenRows())
2129 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2130 .getFullAlignment().getSequencesArray());
2134 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2137 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2139 for (int i = 0; i < viewport.getAlignment().getAlignmentAnnotation().length; i++)
2141 if (!viewport.getAlignment().getAlignmentAnnotation()[i].autoCalculated)
2143 newal.addAnnotation(viewport.getAlignment()
2144 .getAlignmentAnnotation()[i]);
2149 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2151 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2152 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2153 PaintRefresher.Register(newaf.alignPanel,
2154 newaf.alignPanel.av.getSequenceSetId());
2156 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2157 newaf.alignPanel.av.getSequenceSetId());
2158 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2159 newaf.alignPanel.av.getSequenceSetId());
2161 Vector comps = (Vector) PaintRefresher.components.get(viewport
2162 .getSequenceSetId());
2164 for (int i = 0; i < comps.size(); i++)
2166 if (comps.elementAt(i) instanceof AlignmentPanel)
2172 String title = new String(this.getTitle());
2173 if (viewtitle != null)
2175 title = viewtitle + " ( " + title + ")";
2179 if (title.indexOf("(View") > -1)
2181 title = title.substring(0, title.indexOf("(View"));
2183 title += "(View " + viewSize + ")";
2186 newaf.setTitle(title.toString());
2188 newaf.viewport.historyList = viewport.historyList;
2189 newaf.viewport.redoList = viewport.redoList;
2195 * @return list of feature groups on the view
2197 public String[] getFeatureGroups()
2199 FeatureRenderer fr = null;
2200 if (alignPanel != null
2201 && (fr = alignPanel.getFeatureRenderer()) != null)
2203 return fr.getGroups();
2209 * get sequence feature groups that are hidden or shown
2215 public String[] getFeatureGroupsOfState(boolean visible)
2217 FeatureRenderer fr = null;
2218 if (alignPanel != null
2219 && (fr = alignPanel.getFeatureRenderer()) != null)
2221 return fr.getGroups(visible);
2227 * Change the display state for the given feature groups
2230 * list of group strings
2232 * visible or invisible
2234 public void setFeatureGroupState(String[] groups, boolean state)
2236 FeatureRenderer fr = null;
2237 this.sequenceFeatures.setState(true);
2238 viewport.showSequenceFeatures(true);
2239 if (alignPanel != null
2240 && (fr = alignPanel.getFeatureRenderer()) != null)
2242 fr.setGroupState(groups, state);
2243 alignPanel.seqPanel.seqCanvas.repaint();
2244 if (alignPanel.overviewPanel != null)
2246 alignPanel.overviewPanel.updateOverviewImage();
2251 public void seqLimits_itemStateChanged()
2253 viewport.setShowJVSuffix(seqLimits.getState());
2254 alignPanel.fontChanged();
2255 alignPanel.paintAlignment(true);
2258 protected void colourTextMenuItem_actionPerformed()
2260 viewport.setColourText(colourTextMenuItem.getState());
2261 alignPanel.paintAlignment(true);
2264 protected void displayNonconservedMenuItem_actionPerformed()
2266 viewport.setShowunconserved(displayNonconservedMenuItem.getState());
2267 alignPanel.paintAlignment(true);
2270 protected void wrapMenuItem_actionPerformed()
2272 viewport.setWrapAlignment(wrapMenuItem.getState());
2273 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2274 scaleAbove.setEnabled(wrapMenuItem.getState());
2275 scaleLeft.setEnabled(wrapMenuItem.getState());
2276 scaleRight.setEnabled(wrapMenuItem.getState());
2277 alignPanel.paintAlignment(true);
2280 public void overviewMenuItem_actionPerformed()
2282 if (alignPanel.overviewPanel != null)
2287 Frame frame = new Frame();
2288 OverviewPanel overview = new OverviewPanel(alignPanel);
2289 frame.add(overview);
2290 // +50 must allow for applet frame window
2291 jalview.bin.JalviewLite.addFrame(frame, "Overview " + this.getTitle(),
2292 overview.getPreferredSize().width,
2293 overview.getPreferredSize().height + 50);
2296 final AlignmentPanel ap = alignPanel;
2297 frame.addWindowListener(new WindowAdapter()
2300 public void windowClosing(WindowEvent e)
2304 ap.setOverviewPanel(null);
2309 alignPanel.setOverviewPanel(overview);
2313 void changeColour(ColourSchemeI cs)
2319 if (viewport.getAbovePIDThreshold())
2321 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2324 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2326 viewport.setGlobalColourScheme(cs);
2330 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2333 if (viewport.getConservationSelected())
2336 Alignment al = (Alignment) viewport.getAlignment();
2337 Conservation c = new Conservation("All",
2338 ResidueProperties.propHash, 3, al.getSequences(), 0,
2342 c.verdict(false, viewport.getConsPercGaps());
2344 cs.setConservation(c);
2346 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
2352 cs.setConservation(null);
2355 cs.setConsensus(viewport.getSequenceConsensusHash());
2358 viewport.setGlobalColourScheme(cs);
2360 if (alignPanel.getOverviewPanel() != null)
2362 alignPanel.getOverviewPanel().updateOverviewImage();
2365 jalview.structure.StructureSelectionManager
2366 .getStructureSelectionManager(viewport.applet)
2367 .sequenceColoursChanged(alignPanel);
2369 alignPanel.paintAlignment(true);
2372 protected void modifyPID_actionPerformed()
2374 if (viewport.getAbovePIDThreshold()
2375 && viewport.getGlobalColourScheme() != null)
2377 SliderPanel.setPIDSliderSource(alignPanel,
2378 viewport.getGlobalColourScheme(), "Background");
2379 SliderPanel.showPIDSlider();
2383 protected void modifyConservation_actionPerformed()
2385 if (viewport.getConservationSelected()
2386 && viewport.getGlobalColourScheme() != null)
2388 SliderPanel.setConservationSlider(alignPanel,
2389 viewport.getGlobalColourScheme(), "Background");
2390 SliderPanel.showConservationSlider();
2394 protected void conservationMenuItem_actionPerformed()
2396 viewport.setConservationSelected(conservationMenuItem.getState());
2398 viewport.setAbovePIDThreshold(false);
2399 abovePIDThreshold.setState(false);
2401 changeColour(viewport.getGlobalColourScheme());
2403 modifyConservation_actionPerformed();
2406 public void abovePIDThreshold_actionPerformed()
2408 viewport.setAbovePIDThreshold(abovePIDThreshold.getState());
2410 conservationMenuItem.setState(false);
2411 viewport.setConservationSelected(false);
2413 changeColour(viewport.getGlobalColourScheme());
2415 modifyPID_actionPerformed();
2418 public void sortPairwiseMenuItem_actionPerformed()
2420 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2421 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
2422 .getAlignment().getSequenceAt(0), null);
2424 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2425 viewport.getAlignment()));
2426 alignPanel.paintAlignment(true);
2429 public void sortIDMenuItem_actionPerformed()
2431 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2432 AlignmentSorter.sortByID(viewport.getAlignment());
2433 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
2434 viewport.getAlignment()));
2435 alignPanel.paintAlignment(true);
2438 public void sortLengthMenuItem_actionPerformed()
2440 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2441 AlignmentSorter.sortByLength(viewport.getAlignment());
2442 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2443 viewport.getAlignment()));
2444 alignPanel.paintAlignment(true);
2447 public void sortGroupMenuItem_actionPerformed()
2449 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2450 AlignmentSorter.sortByGroup(viewport.getAlignment());
2451 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2452 viewport.getAlignment()));
2453 alignPanel.paintAlignment(true);
2457 public void removeRedundancyMenuItem_actionPerformed()
2459 new RedundancyPanel(alignPanel);
2462 public void pairwiseAlignmentMenuItem_actionPerformed()
2464 if (viewport.getSelectionGroup() != null
2465 && viewport.getSelectionGroup().getSize() > 1)
2467 Frame frame = new Frame();
2468 frame.add(new PairwiseAlignPanel(alignPanel));
2469 jalview.bin.JalviewLite.addFrame(frame, "Pairwise Alignment", 600,
2474 public void PCAMenuItem_actionPerformed()
2476 // are the sequences aligned?
2477 if (!viewport.getAlignment().isAligned(false))
2480 int Width = viewport.getAlignment().getWidth();
2482 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2484 current = viewport.getAlignment().getSequenceAt(i);
2486 if (current.getLength() < Width)
2488 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2491 alignPanel.paintAlignment(true);
2494 if ((viewport.getSelectionGroup() != null
2495 && viewport.getSelectionGroup().getSize() < 4 && viewport
2496 .getSelectionGroup().getSize() > 0)
2497 || viewport.getAlignment().getHeight() < 4)
2504 new PCAPanel(viewport);
2505 } catch (java.lang.OutOfMemoryError ex)
2511 public void averageDistanceTreeMenuItem_actionPerformed()
2513 NewTreePanel("AV", "PID", "Average distance tree using PID");
2516 public void neighbourTreeMenuItem_actionPerformed()
2518 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2521 protected void njTreeBlosumMenuItem_actionPerformed()
2523 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2526 protected void avTreeBlosumMenuItem_actionPerformed()
2528 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2531 void NewTreePanel(String type, String pwType, String title)
2533 // are the sequences aligned?
2534 if (!viewport.getAlignment().isAligned(false))
2537 int Width = viewport.getAlignment().getWidth();
2539 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2541 current = viewport.getAlignment().getSequenceAt(i);
2543 if (current.getLength() < Width)
2545 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2548 alignPanel.paintAlignment(true);
2552 if ((viewport.getSelectionGroup() != null && viewport
2553 .getSelectionGroup().getSize() > 1)
2554 || (viewport.getAlignment().getHeight() > 1))
2556 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2558 addTreeMenuItem(tp, title);
2560 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2564 void loadTree_actionPerformed()
2566 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2567 cap.setText("Paste your Newick tree file here.");
2568 cap.setTreeImport();
2569 Frame frame = new Frame();
2571 jalview.bin.JalviewLite.addFrame(frame, "Paste Newick file ", 400, 300);
2574 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2576 TreePanel tp = new TreePanel(alignPanel, treeFile, "From File - ", tree);
2577 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2578 addTreeMenuItem(tp, treeFile);
2582 * sort the alignment using the given treePanel
2585 * tree used to sort view
2587 * string used for undo event name
2589 public void sortByTree(TreePanel treePanel, String title)
2591 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2593 .sortByTree(viewport.getAlignment(), treePanel.getTree());
2594 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2595 // HistoryItem.SORT));
2596 addHistoryItem(new OrderCommand("Order by " + title, oldOrder,
2597 viewport.getAlignment()));
2598 alignPanel.paintAlignment(true);
2602 * Do any automatic reordering of the alignment and add the necessary bits to
2603 * the menu structure for the new tree
2608 protected void addTreeMenuItem(final TreePanel treePanel,
2611 final MenuItem item = new MenuItem(title);
2612 sortByTreeMenu.add(item);
2613 item.addActionListener(new java.awt.event.ActionListener()
2616 public void actionPerformed(ActionEvent evt)
2618 sortByTree(treePanel, title); // treePanel.getTitle());
2622 treePanel.addWindowListener(new WindowAdapter()
2625 public void windowOpened(WindowEvent e)
2627 if (viewport.sortByTree)
2629 sortByTree(treePanel, title);
2631 super.windowOpened(e);
2635 public void windowClosing(WindowEvent e)
2637 sortByTreeMenu.remove(item);
2642 public boolean sortBy(AlignmentOrder alorder, String undoname)
2644 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2645 if (viewport.applet.debug)
2647 System.err.println("Sorting " + alorder.getOrder().size()
2648 + " in alignment '" + getTitle() + "'");
2650 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2651 if (undoname != null)
2653 addHistoryItem(new OrderCommand(undoname, oldOrder,
2654 viewport.getAlignment()));
2656 alignPanel.paintAlignment(true);
2660 protected void documentation_actionPerformed()
2662 alignPanel.av.applet.openJalviewHelpUrl();
2665 protected void about_actionPerformed()
2668 class AboutPanel extends Canvas
2674 public AboutPanel(String version, String builddate)
2676 this.version = version;
2677 this.builddate = builddate;
2681 public void paint(Graphics g)
2683 g.setColor(Color.white);
2684 g.fillRect(0, 0, getSize().width, getSize().height);
2685 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
2686 FontMetrics fm = g.getFontMetrics();
2687 int fh = fm.getHeight();
2689 g.setColor(Color.black);
2690 // TODO: update this text for each release or centrally store it for
2691 // lite and application
2692 g.setFont(new Font("Helvetica", Font.BOLD, 14));
2693 g.drawString("JalviewLite - Release " + version, x, y += fh);
2694 g.setFont(new Font("Helvetica", Font.BOLD, 12));
2695 g.drawString("Build date: " + builddate, x, y += fh);
2696 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
2698 "Authors: Jim Procter, Andrew Waterhouse, Jan Engelhardt, Lauren Lui,",
2700 g.drawString("Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton.", x + 50, y += fh+8);
2702 "Development managed by The Barton Group, University of Dundee, Scotland, UK.",
2705 "For help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list",
2707 g.drawString("If you use Jalview, please cite:", x, y += fh + 8);
2709 "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)",
2712 "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench",
2714 g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033",
2719 Frame frame = new Frame();
2720 frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite
2722 jalview.bin.JalviewLite.addFrame(frame, "Jalview", 580, 220);
2726 public void showURL(String url, String target)
2728 if (viewport.applet == null)
2730 System.out.println("Not running as applet - no browser available.");
2734 viewport.applet.showURL(url, target);
2738 // ////////////////////////////////////////////////////////////////////////////////
2739 // JBuilder Graphics here
2741 MenuBar alignFrameMenuBar = new MenuBar();
2743 Menu fileMenu = new Menu("File");
2745 MenuItem loadApplication = new MenuItem("View in Full Application");
2747 MenuItem loadTree = new MenuItem("Load Associated Tree ...");
2749 MenuItem loadAnnotations = new MenuItem("Load Features/Annotations ...");
2751 MenuItem outputFeatures = new MenuItem("Export Features ...");
2753 MenuItem outputAnnotations = new MenuItem("Export Annotations ...");
2755 MenuItem closeMenuItem = new MenuItem("Close");
2757 Menu editMenu = new Menu("Edit");
2759 Menu viewMenu = new Menu("View");
2761 Menu colourMenu = new Menu("Colour");
2763 Menu calculateMenu = new Menu("Calculate");
2765 MenuItem selectAllSequenceMenuItem = new MenuItem("Select all");
2767 MenuItem deselectAllSequenceMenuItem = new MenuItem("Deselect All");
2769 MenuItem invertSequenceMenuItem = new MenuItem("Invert Selection");
2771 MenuItem remove2LeftMenuItem = new MenuItem();
2773 MenuItem remove2RightMenuItem = new MenuItem();
2775 MenuItem removeGappedColumnMenuItem = new MenuItem();
2777 MenuItem removeAllGapsMenuItem = new MenuItem();
2779 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
2781 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
2783 MenuItem sortPairwiseMenuItem = new MenuItem();
2785 MenuItem sortIDMenuItem = new MenuItem();
2787 MenuItem sortLengthMenuItem = new MenuItem();
2789 MenuItem sortGroupMenuItem = new MenuItem();
2791 MenuItem removeRedundancyMenuItem = new MenuItem();
2793 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
2795 MenuItem PCAMenuItem = new MenuItem();
2797 MenuItem averageDistanceTreeMenuItem = new MenuItem();
2799 MenuItem neighbourTreeMenuItem = new MenuItem();
2801 BorderLayout borderLayout1 = new BorderLayout();
2803 public Label statusBar = new Label();
2805 Menu outputTextboxMenu = new Menu();
2807 MenuItem clustalColour = new MenuItem();
2809 MenuItem zappoColour = new MenuItem();
2811 MenuItem taylorColour = new MenuItem();
2813 MenuItem hydrophobicityColour = new MenuItem();
2815 MenuItem helixColour = new MenuItem();
2817 MenuItem strandColour = new MenuItem();
2819 MenuItem turnColour = new MenuItem();
2821 MenuItem buriedColour = new MenuItem();
2823 MenuItem purinePyrimidineColour = new MenuItem();
2825 MenuItem RNAHelixColour = new MenuItem();
2827 MenuItem userDefinedColour = new MenuItem();
2829 MenuItem PIDColour = new MenuItem();
2831 MenuItem BLOSUM62Colour = new MenuItem();
2833 MenuItem tcoffeeColour = new MenuItem();
2835 MenuItem njTreeBlosumMenuItem = new MenuItem();
2837 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
2839 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
2841 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
2843 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
2845 MenuItem alProperties = new MenuItem("Alignment Properties...");
2847 MenuItem overviewMenuItem = new MenuItem();
2849 MenuItem undoMenuItem = new MenuItem();
2851 MenuItem redoMenuItem = new MenuItem();
2853 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
2855 MenuItem noColourmenuItem = new MenuItem();
2857 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
2859 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
2861 MenuItem findMenuItem = new MenuItem();
2863 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
2865 MenuItem nucleotideColour = new MenuItem();
2867 MenuItem deleteGroups = new MenuItem();
2869 MenuItem grpsFromSelection = new MenuItem();
2871 MenuItem delete = new MenuItem();
2873 MenuItem copy = new MenuItem();
2875 MenuItem cut = new MenuItem();
2877 Menu pasteMenu = new Menu();
2879 MenuItem pasteNew = new MenuItem();
2881 MenuItem pasteThis = new MenuItem();
2883 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
2885 MenuItem font = new MenuItem();
2887 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
2889 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
2891 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
2893 MenuItem modifyPID = new MenuItem();
2895 MenuItem modifyConservation = new MenuItem();
2897 CheckboxMenuItem autoCalculate = new CheckboxMenuItem(
2898 "Autocalculate Consensus", true);
2900 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
2901 "Sort Alignment With New Tree", true);
2903 Menu sortByTreeMenu = new Menu();
2905 Menu sort = new Menu();
2907 Menu calculate = new Menu();
2909 MenuItem inputText = new MenuItem();
2911 Menu helpMenu = new Menu();
2913 MenuItem documentation = new MenuItem();
2915 MenuItem about = new MenuItem();
2917 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
2919 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
2921 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
2923 Menu autoAnnMenu = new Menu();
2925 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
2927 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
2929 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
2931 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
2933 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
2935 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
2937 private void jbInit() throws Exception
2940 setMenuBar(alignFrameMenuBar);
2944 // dynamically fill save as menu with available formats
2945 for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
2948 item = new MenuItem(
2949 jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
2951 item.addActionListener(new java.awt.event.ActionListener()
2954 public void actionPerformed(ActionEvent e)
2956 outputText_actionPerformed(e);
2960 outputTextboxMenu.add(item);
2962 closeMenuItem.addActionListener(this);
2963 loadApplication.addActionListener(this);
2965 loadTree.addActionListener(this);
2966 loadAnnotations.addActionListener(this);
2967 outputFeatures.addActionListener(this);
2968 outputAnnotations.addActionListener(this);
2969 selectAllSequenceMenuItem.addActionListener(this);
2970 deselectAllSequenceMenuItem.addActionListener(this);
2971 invertSequenceMenuItem.addActionListener(this);
2972 remove2LeftMenuItem.setLabel("Remove Left");
2973 remove2LeftMenuItem.addActionListener(this);
2974 remove2RightMenuItem.setLabel("Remove Right");
2975 remove2RightMenuItem.addActionListener(this);
2976 removeGappedColumnMenuItem.setLabel("Remove Empty Columns");
2977 removeGappedColumnMenuItem.addActionListener(this);
2978 removeAllGapsMenuItem.setLabel("Remove All Gaps");
2979 removeAllGapsMenuItem.addActionListener(this);
2980 viewBoxesMenuItem.setLabel("Boxes");
2981 viewBoxesMenuItem.setState(true);
2982 viewBoxesMenuItem.addItemListener(this);
2983 viewTextMenuItem.setLabel("Text");
2984 viewTextMenuItem.setState(true);
2985 viewTextMenuItem.addItemListener(this);
2986 sortPairwiseMenuItem.setLabel("by Pairwise Identity");
2987 sortPairwiseMenuItem.addActionListener(this);
2988 sortIDMenuItem.setLabel("by ID");
2989 sortIDMenuItem.addActionListener(this);
2990 sortLengthMenuItem.setLabel("by Length");
2991 sortLengthMenuItem.addActionListener(this);
2992 sortGroupMenuItem.setLabel("by Group");
2993 sortGroupMenuItem.addActionListener(this);
2994 removeRedundancyMenuItem.setLabel("Remove Redundancy...");
2995 removeRedundancyMenuItem.addActionListener(this);
2996 pairwiseAlignmentMenuItem.setLabel("Pairwise Alignments...");
2997 pairwiseAlignmentMenuItem.addActionListener(this);
2998 PCAMenuItem.setLabel("Principal Component Analysis");
2999 PCAMenuItem.addActionListener(this);
3000 averageDistanceTreeMenuItem
3001 .setLabel("Average Distance Using % Identity");
3002 averageDistanceTreeMenuItem.addActionListener(this);
3003 neighbourTreeMenuItem.setLabel("Neighbour Joining Using % Identity");
3004 neighbourTreeMenuItem.addActionListener(this);
3005 statusBar.setBackground(Color.white);
3006 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3007 statusBar.setText("Status bar");
3008 outputTextboxMenu.setLabel("Output to Textbox");
3009 clustalColour.setLabel("Clustalx");
3011 clustalColour.addActionListener(this);
3012 zappoColour.setLabel("Zappo");
3013 zappoColour.addActionListener(this);
3014 taylorColour.setLabel("Taylor");
3015 taylorColour.addActionListener(this);
3016 hydrophobicityColour.setLabel("Hydrophobicity");
3017 hydrophobicityColour.addActionListener(this);
3018 helixColour.setLabel("Helix Propensity");
3019 helixColour.addActionListener(this);
3020 strandColour.setLabel("Strand Propensity");
3021 strandColour.addActionListener(this);
3022 turnColour.setLabel("Turn Propensity");
3023 turnColour.addActionListener(this);
3024 buriedColour.setLabel("Buried Index");
3025 buriedColour.addActionListener(this);
3026 purinePyrimidineColour.setLabel("Purine/Pyrimidine");
3027 purinePyrimidineColour.addActionListener(this);
3028 RNAHelixColour.setLabel("by RNA Helices");
3029 RNAHelixColour.addActionListener(this);
3030 userDefinedColour.setLabel("User Defined...");
3031 userDefinedColour.addActionListener(this);
3032 PIDColour.setLabel("Percentage Identity");
3033 PIDColour.addActionListener(this);
3034 BLOSUM62Colour.setLabel("BLOSUM62 Score");
3035 BLOSUM62Colour.addActionListener(this);
3036 tcoffeeColour.setLabel("T-Coffee Scores");
3037 tcoffeeColour.setEnabled(false); // it will enabled only if a score file is
3039 tcoffeeColour.addActionListener(this);
3040 avDistanceTreeBlosumMenuItem
3041 .setLabel("Average Distance Using BLOSUM62");
3042 avDistanceTreeBlosumMenuItem.addActionListener(this);
3043 njTreeBlosumMenuItem.setLabel("Neighbour Joining Using BLOSUM62");
3044 njTreeBlosumMenuItem.addActionListener(this);
3045 annotationPanelMenuItem.setLabel("Show Annotations");
3046 annotationPanelMenuItem.addItemListener(this);
3047 colourTextMenuItem.setLabel("Colour Text");
3048 colourTextMenuItem.addItemListener(this);
3049 displayNonconservedMenuItem.setLabel("Show nonconserved");
3050 displayNonconservedMenuItem.addItemListener(this);
3051 alProperties.addActionListener(this);
3052 overviewMenuItem.setLabel("Overview Window");
3053 overviewMenuItem.addActionListener(this);
3054 undoMenuItem.setEnabled(false);
3055 undoMenuItem.setLabel("Undo");
3056 undoMenuItem.addActionListener(this);
3057 redoMenuItem.setEnabled(false);
3058 redoMenuItem.setLabel("Redo");
3059 redoMenuItem.addActionListener(this);
3060 conservationMenuItem.setLabel("by Conservation");
3061 conservationMenuItem.addItemListener(this);
3062 noColourmenuItem.setLabel("None");
3063 noColourmenuItem.addActionListener(this);
3064 wrapMenuItem.setLabel("Wrap");
3065 wrapMenuItem.addItemListener(this);
3066 renderGapsMenuItem.setLabel("Show Gaps");
3067 renderGapsMenuItem.setState(true);
3068 renderGapsMenuItem.addItemListener(this);
3069 findMenuItem.setLabel("Find...");
3070 findMenuItem.addActionListener(this);
3071 abovePIDThreshold.setLabel("Above Identity Threshold");
3072 abovePIDThreshold.addItemListener(this);
3073 nucleotideColour.setLabel("Nucleotide");
3074 nucleotideColour.addActionListener(this);
3075 deleteGroups.setLabel("Undefine Groups");
3076 deleteGroups.addActionListener(this);
3077 grpsFromSelection.setLabel("Make Groups for selection");
3078 grpsFromSelection.addActionListener(this);
3079 copy.setLabel("Copy");
3080 copy.addActionListener(this);
3081 cut.setLabel("Cut");
3082 cut.addActionListener(this);
3083 delete.setLabel("Delete");
3084 delete.addActionListener(this);
3085 pasteMenu.setLabel("Paste");
3086 pasteNew.setLabel("To New Alignment");
3087 pasteNew.addActionListener(this);
3088 pasteThis.setLabel("Add To This Alignment");
3089 pasteThis.addActionListener(this);
3090 applyToAllGroups.setLabel("Apply Colour To All Groups");
3091 applyToAllGroups.setState(true);
3092 applyToAllGroups.addItemListener(this);
3093 font.setLabel("Font...");
3094 font.addActionListener(this);
3095 scaleAbove.setLabel("Scale Above");
3096 scaleAbove.setState(true);
3097 scaleAbove.setEnabled(false);
3098 scaleAbove.addItemListener(this);
3099 scaleLeft.setEnabled(false);
3100 scaleLeft.setState(true);
3101 scaleLeft.setLabel("Scale Left");
3102 scaleLeft.addItemListener(this);
3103 scaleRight.setEnabled(false);
3104 scaleRight.setState(true);
3105 scaleRight.setLabel("Scale Right");
3106 scaleRight.addItemListener(this);
3107 modifyPID.setLabel("Modify Identity Threshold...");
3108 modifyPID.addActionListener(this);
3109 modifyConservation.setLabel("Modify Conservation Threshold...");
3110 modifyConservation.addActionListener(this);
3111 sortByTreeMenu.setLabel("By Tree Order");
3112 sort.setLabel("Sort");
3113 calculate.setLabel("Calculate Tree");
3114 autoCalculate.addItemListener(this);
3115 sortByTree.addItemListener(this);
3116 inputText.setLabel("Input from textbox");
3117 inputText.addActionListener(this);
3118 centreColumnLabelFlag.setLabel("Centre column labels");
3119 centreColumnLabelFlag.addItemListener(this);
3120 followMouseOverFlag.setLabel("Automatic Scrolling");
3121 followMouseOverFlag.addItemListener(this);
3122 helpMenu.setLabel("Help");
3123 documentation.setLabel("Documentation");
3124 documentation.addActionListener(this);
3126 about.setLabel("About...");
3127 about.addActionListener(this);
3128 seqLimits.setState(true);
3129 seqLimits.setLabel("Show Sequence Limits");
3130 seqLimits.addItemListener(this);
3131 featureSettings.setLabel("Feature Settings...");
3132 featureSettings.addActionListener(this);
3133 sequenceFeatures.setLabel("Sequence Features");
3134 sequenceFeatures.addItemListener(this);
3135 sequenceFeatures.setState(false);
3136 annotationColour.setLabel("by Annotation...");
3137 annotationColour.addActionListener(this);
3138 invertSequenceMenuItem.setLabel("Invert Sequence Selection");
3139 invertColSel.setLabel("Invert Column Selection");
3140 menu1.setLabel("Show");
3141 showColumns.setLabel("All Columns ");
3142 showSeqs.setLabel("All Sequences");
3143 menu2.setLabel("Hide");
3144 hideColumns.setLabel("Selected Columns");
3145 hideSequences.setLabel("Selected Sequences");
3146 hideAllButSelection.setLabel("All but Selected Region (Shift+Ctrl+H)");
3147 hideAllSelection.setLabel("Selected Region");
3148 showAllHidden.setLabel("All Sequences and Columns");
3149 showGroupConsensus.setLabel("Group Consensus");
3150 showGroupConservation.setLabel("Group Conservation");
3151 showConsensusHistogram.setLabel("Show Consensus Histogram");
3152 showSequenceLogo.setLabel("Show Consensus Logo");
3153 normSequenceLogo.setLabel("Normalise Consensus Logo");
3154 applyAutoAnnotationSettings.setLabel("Apply to all groups");
3155 applyAutoAnnotationSettings.setState(true);
3156 autoAnnMenu.setLabel("Autocalculated Annotation");
3158 invertColSel.addActionListener(this);
3159 showColumns.addActionListener(this);
3160 showSeqs.addActionListener(this);
3161 hideColumns.addActionListener(this);
3162 hideSequences.addActionListener(this);
3163 hideAllButSelection.addActionListener(this);
3164 hideAllSelection.addActionListener(this);
3165 showAllHidden.addActionListener(this);
3166 showGroupConsensus.addItemListener(this);
3167 showGroupConservation.addItemListener(this);
3168 showConsensusHistogram.addItemListener(this);
3169 showSequenceLogo.addItemListener(this);
3170 normSequenceLogo.addItemListener(this);
3172 applyAutoAnnotationSettings.addItemListener(this);
3173 formatMenu.setLabel("Format");
3174 selectMenu.setLabel("Select");
3175 newView.setLabel("New View");
3176 newView.addActionListener(this);
3177 alignFrameMenuBar.add(fileMenu);
3178 alignFrameMenuBar.add(editMenu);
3179 alignFrameMenuBar.add(selectMenu);
3180 alignFrameMenuBar.add(viewMenu);
3181 alignFrameMenuBar.add(formatMenu);
3182 alignFrameMenuBar.add(colourMenu);
3183 alignFrameMenuBar.add(calculateMenu);
3184 alignFrameMenuBar.add(helpMenu);
3186 fileMenu.add(inputText);
3187 fileMenu.add(loadTree);
3188 fileMenu.add(loadAnnotations);
3190 fileMenu.addSeparator();
3191 fileMenu.add(outputTextboxMenu);
3192 fileMenu.add(outputFeatures);
3193 fileMenu.add(outputAnnotations);
3195 if (jalviewServletURL != null)
3197 fileMenu.add(loadApplication);
3200 fileMenu.addSeparator();
3201 fileMenu.add(closeMenuItem);
3203 editMenu.add(undoMenuItem);
3204 editMenu.add(redoMenuItem);
3207 editMenu.add(pasteMenu);
3208 editMenu.add(delete);
3209 editMenu.addSeparator();
3210 editMenu.add(remove2LeftMenuItem);
3211 editMenu.add(remove2RightMenuItem);
3212 editMenu.add(removeGappedColumnMenuItem);
3213 editMenu.add(removeAllGapsMenuItem);
3214 editMenu.add(removeRedundancyMenuItem);
3215 viewMenu.add(newView);
3216 viewMenu.addSeparator();
3217 viewMenu.add(menu1);
3218 viewMenu.add(menu2);
3219 viewMenu.addSeparator();
3220 viewMenu.add(followMouseOverFlag);
3221 viewMenu.add(annotationPanelMenuItem);
3222 autoAnnMenu.add(applyAutoAnnotationSettings);
3223 autoAnnMenu.add(showConsensusHistogram);
3224 autoAnnMenu.add(showSequenceLogo);
3225 autoAnnMenu.add(normSequenceLogo);
3226 autoAnnMenu.addSeparator();
3227 autoAnnMenu.add(showGroupConservation);
3228 autoAnnMenu.add(showGroupConsensus);
3229 viewMenu.add(autoAnnMenu);
3230 viewMenu.addSeparator();
3231 viewMenu.add(sequenceFeatures);
3232 viewMenu.add(featureSettings);
3233 viewMenu.addSeparator();
3234 viewMenu.add(alProperties);
3235 viewMenu.addSeparator();
3236 viewMenu.add(overviewMenuItem);
3237 colourMenu.add(applyToAllGroups);
3238 colourMenu.addSeparator();
3239 colourMenu.add(noColourmenuItem);
3240 colourMenu.add(clustalColour);
3241 colourMenu.add(BLOSUM62Colour);
3242 colourMenu.add(PIDColour);
3243 colourMenu.add(zappoColour);
3244 colourMenu.add(taylorColour);
3245 colourMenu.add(hydrophobicityColour);
3246 colourMenu.add(helixColour);
3247 colourMenu.add(strandColour);
3248 colourMenu.add(turnColour);
3249 colourMenu.add(buriedColour);
3250 colourMenu.add(nucleotideColour);
3251 colourMenu.add(purinePyrimidineColour);
3252 colourMenu.add(tcoffeeColour);
3253 colourMenu.add(userDefinedColour);
3254 colourMenu.addSeparator();
3255 colourMenu.add(conservationMenuItem);
3256 colourMenu.add(modifyConservation);
3257 colourMenu.add(abovePIDThreshold);
3258 colourMenu.add(modifyPID);
3259 colourMenu.add(annotationColour);
3260 colourMenu.add(RNAHelixColour);
3261 calculateMenu.add(sort);
3262 calculateMenu.add(calculate);
3263 calculateMenu.addSeparator();
3264 calculateMenu.add(pairwiseAlignmentMenuItem);
3265 calculateMenu.add(PCAMenuItem);
3266 calculateMenu.add(autoCalculate);
3267 calculateMenu.add(sortByTree);
3268 this.add(statusBar, BorderLayout.SOUTH);
3269 pasteMenu.add(pasteNew);
3270 pasteMenu.add(pasteThis);
3271 sort.add(sortIDMenuItem);
3272 sort.add(sortLengthMenuItem);
3273 sort.add(sortByTreeMenu);
3274 sort.add(sortGroupMenuItem);
3275 sort.add(sortPairwiseMenuItem);
3276 calculate.add(averageDistanceTreeMenuItem);
3277 calculate.add(neighbourTreeMenuItem);
3278 calculate.add(avDistanceTreeBlosumMenuItem);
3279 calculate.add(njTreeBlosumMenuItem);
3280 helpMenu.add(documentation);
3281 helpMenu.add(about);
3282 menu1.add(showColumns);
3283 menu1.add(showSeqs);
3284 menu1.add(showAllHidden);
3285 menu2.add(hideColumns);
3286 menu2.add(hideSequences);
3287 menu2.add(hideAllSelection);
3288 menu2.add(hideAllButSelection);
3289 formatMenu.add(font);
3290 formatMenu.add(seqLimits);
3291 formatMenu.add(wrapMenuItem);
3292 formatMenu.add(scaleAbove);
3293 formatMenu.add(scaleLeft);
3294 formatMenu.add(scaleRight);
3295 formatMenu.add(viewBoxesMenuItem);
3296 formatMenu.add(viewTextMenuItem);
3297 formatMenu.add(colourTextMenuItem);
3298 formatMenu.add(displayNonconservedMenuItem);
3299 formatMenu.add(renderGapsMenuItem);
3300 formatMenu.add(centreColumnLabelFlag);
3301 selectMenu.add(findMenuItem);
3302 selectMenu.addSeparator();
3303 selectMenu.add(selectAllSequenceMenuItem);
3304 selectMenu.add(deselectAllSequenceMenuItem);
3305 selectMenu.add(invertSequenceMenuItem);
3306 selectMenu.add(invertColSel);
3307 selectMenu.add(grpsFromSelection);
3308 selectMenu.add(deleteGroups);
3312 MenuItem featureSettings = new MenuItem();
3314 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3316 MenuItem annotationColour = new MenuItem();
3318 MenuItem invertColSel = new MenuItem();
3320 Menu menu1 = new Menu();
3322 MenuItem showColumns = new MenuItem();
3324 MenuItem showSeqs = new MenuItem();
3326 Menu menu2 = new Menu();
3328 MenuItem hideColumns = new MenuItem();
3330 MenuItem hideSequences = new MenuItem();
3332 MenuItem hideAllButSelection = new MenuItem();
3334 MenuItem hideAllSelection = new MenuItem();
3336 MenuItem showAllHidden = new MenuItem();
3338 Menu formatMenu = new Menu();
3340 Menu selectMenu = new Menu();
3342 MenuItem newView = new MenuItem();
3345 * Attach the alignFrame panels after embedding menus, if necessary. This used
3346 * to be called setEmbedded, but is now creates the dropdown menus in a
3347 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3349 * @param reallyEmbedded
3350 * true to attach the view to the applet area on the page rather than
3353 public void createAlignFrameWindow(boolean reallyEmbedded, String title)
3358 // Explicly build the embedded menu panel for the on-page applet
3360 // view cannot be closed if its actually on the page
3361 fileMenu.remove(closeMenuItem);
3362 fileMenu.remove(3); // Remove Seperator
3363 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, "Arial",
3364 Font.PLAIN, 10, false); // use our own fonts.
3365 // and actually add the components to the applet area
3366 viewport.applet.setLayout(new BorderLayout());
3367 viewport.applet.add(embeddedMenu, BorderLayout.NORTH);
3368 viewport.applet.add(statusBar, BorderLayout.SOUTH);
3369 alignPanel.setSize(viewport.applet.getSize().width,
3370 viewport.applet.getSize().height - embeddedMenu.HEIGHT
3371 - statusBar.HEIGHT);
3372 viewport.applet.add(alignPanel, BorderLayout.CENTER);
3373 final AlignFrame me = this;
3374 viewport.applet.addFocusListener(new FocusListener()
3378 public void focusLost(FocusEvent e)
3380 if (me.viewport.applet.currentAlignFrame == me)
3382 me.viewport.applet.currentAlignFrame = null;
3387 public void focusGained(FocusEvent e)
3389 me.viewport.applet.currentAlignFrame = me;
3392 viewport.applet.validate();
3397 // test and embed menu bar if necessary.
3399 if (embedMenuIfNeeded(alignPanel))
3401 // adjust for status bar height too
3402 alignPanel.setSize(getSize().width, getSize().height
3403 - statusBar.HEIGHT);
3405 add(statusBar, BorderLayout.SOUTH);
3406 add(alignPanel, BorderLayout.CENTER);
3407 // and register with the applet so it can pass external API calls to us
3408 jalview.bin.JalviewLite.addFrame(this, title, DEFAULT_WIDTH,
3414 * create a new binding between structures in an existing jmol viewer instance
3415 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3416 * this does not open a new Jmol window, or modify the display of the
3417 * structures in the original jmol window. Note This method doesn't work
3418 * without an additional javascript library to exchange messages between the
3419 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3422 * JmolViewer instance
3423 * @param sequenceIds
3424 * - sequence Ids to search for associations
3426 public SequenceStructureBinding addStructureViewInstance(
3427 Object jmolviewer, String[] sequenceIds)
3429 org.jmol.api.JmolViewer viewer = null;
3432 viewer = (org.jmol.api.JmolViewer) jmolviewer;
3433 } catch (ClassCastException ex)
3435 System.err.println("Unsupported viewer object :"
3436 + jmolviewer.getClass());
3440 System.err.println("Can't use this object as a structure viewer:"
3441 + jmolviewer.getClass());
3444 SequenceI[] seqs = null;
3445 if (sequenceIds == null || sequenceIds.length == 0)
3447 seqs = viewport.getAlignment().getSequencesArray();
3451 Vector sqi = new Vector();
3452 AlignmentI al = viewport.getAlignment();
3453 for (int sid = 0; sid < sequenceIds.length; sid++)
3455 SequenceI sq = al.findName(sequenceIds[sid]);
3463 seqs = new SequenceI[sqi.size()];
3464 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
3466 seqs[sid] = (SequenceI) sqi.elementAt(sid);
3475 // TODO: search for a jmv that involves viewer
3477 { // create a new viewer/jalview binding.
3478 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][]
3486 * bind a pdb file to a sequence in the current view
3489 * - sequenceId within the dataset.
3490 * @param pdbEntryString
3491 * - the short name for the PDB file
3493 * - pdb file - either a URL or a valid PDB file.
3494 * @return true if binding was as success TODO: consider making an exception
3495 * structure for indicating when PDB parsing or sequenceId location
3498 public boolean addPdbFile(String sequenceId, String pdbEntryString,
3501 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
3502 boolean needtoadd = false;
3503 if (toaddpdb != null)
3505 Vector pdbe = toaddpdb.getPDBId();
3506 PDBEntry pdbentry = null;
3507 if (pdbe != null && pdbe.size() > 0)
3509 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
3511 pdbentry = (PDBEntry) pdbe.elementAt(pe);
3512 if (!pdbentry.getId().equals(pdbEntryString)
3513 && !pdbentry.getFile().equals(pdbFile))
3523 if (pdbentry == null)
3525 pdbentry = new PDBEntry();
3526 pdbentry.setId(pdbEntryString);
3527 pdbentry.setFile(pdbFile);
3528 needtoadd = true; // add this new entry to sequence.
3530 // resolve data source
3531 // TODO: this code should be a refactored to an io package
3532 String protocol = AppletFormatAdapter.resolveProtocol(pdbFile, "PDB");
3533 if (protocol == null)
3539 // make a note of the access mode and add
3540 if (pdbentry.getProperty() == null)
3542 pdbentry.setProperty(new Hashtable());
3544 pdbentry.getProperty().put("protocol", protocol);
3545 toaddpdb.addPDBId(pdbentry);
3551 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
3555 Vector sequences = new Vector();
3556 for (int i = 0; i < seqs.length; i++)
3558 if (seqs[i] != null)
3560 sequences.addElement(new Object[]
3561 { seqs[i], (chains != null) ? chains[i] : null });
3564 seqs = new SequenceI[sequences.size()];
3565 chains = new String[sequences.size()];
3566 for (int i = 0, isize = sequences.size(); i < isize; i++)
3568 Object[] oj = (Object[]) sequences.elementAt(i);
3570 seqs[i] = (SequenceI) oj[0];
3571 chains[i] = (String) oj[1];
3579 public void newStructureView(JalviewLite applet, PDBEntry pdb,
3580 SequenceI[] seqs, String[] chains, String protocol)
3582 // Scrub any null sequences from the array
3583 Object[] sqch = cleanSeqChainArrays(seqs, chains);
3584 seqs = (SequenceI[]) sqch[0];
3585 chains = (String[]) sqch[1];
3586 if (seqs == null || seqs.length == 0)
3589 .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
3591 if (protocol == null || protocol.trim().length() == 0
3592 || protocol.equals("null"))
3594 protocol = (String) pdb.getProperty().get("protocol");
3595 if (protocol == null)
3597 System.err.println("Couldn't work out protocol to open structure: "
3602 if (applet.useXtrnalSviewer)
3604 // register the association(s) and quit, don't create any windows.
3605 if (StructureSelectionManager.getStructureSelectionManager(applet)
3606 .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
3608 System.err.println("Failed to map " + pdb.getFile() + " ("
3609 + protocol + ") to any sequences");
3613 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
3615 // can only do alignments with Jmol
3616 // find the last jmol window assigned to this alignment
3617 jalview.appletgui.AppletJmol ajm = null, tajm;
3618 Vector jmols = applet
3619 .getAppletWindow(jalview.appletgui.AppletJmol.class);
3620 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
3622 tajm = (jalview.appletgui.AppletJmol) jmols.elementAt(i);
3623 if (tajm.ap.alignFrame == this)
3632 .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
3633 // try and add the pdb structure
3638 // otherwise, create a new window
3639 if (applet.jmolAvailable)
3641 new jalview.appletgui.AppletJmol(pdb, seqs, chains, alignPanel,
3643 applet.lastFrameX += 40;
3644 applet.lastFrameY += 40;
3648 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
3653 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
3654 SequenceI[][] seqs, String[][] chains, String[] protocols)
3656 // TODO Auto-generated method stub
3657 System.err.println("Aligned Structure View: Not yet implemented.");
3661 * modify the current selection, providing the user has not made a selection
3665 * - sequences from this alignment
3667 * - columns to be selected on the alignment
3669 public void select(SequenceGroup sel, ColumnSelection csel)
3671 alignPanel.seqPanel.selection(sel, csel, null);
3674 public void scrollTo(int row, int column)
3676 alignPanel.seqPanel.scrollTo(row, column);
3679 public void scrollToRow(int row)
3681 alignPanel.seqPanel.scrollToRow(row);
3684 public void scrollToColumn(int column)
3686 alignPanel.seqPanel.scrollToColumn(column);
3690 * @return the alignments unique ID.
3692 public String getSequenceSetId()
3694 return viewport.getSequenceSetId();
3698 * Load the (T-Coffee) score file from the specified url
3701 * File/URL/T-COFFEE score file contents
3702 * @throws IOException
3703 * @return true if alignment was annotated with data from source
3705 public boolean loadScoreFile(String source) throws IOException
3708 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
3709 AppletFormatAdapter.checkProtocol(source));
3710 if (!file.isValid())
3712 // TODO: raise dialog for gui
3713 System.err.println("Problems parsing T-Coffee scores: "
3714 + file.getWarningMessage());
3715 System.err.println("Origin was:\n" + source);
3720 * check that the score matrix matches the alignment dimensions
3723 if ((aln = viewport.getAlignment()) != null
3724 && (aln.getHeight() != file.getHeight() || aln.getWidth() != file
3727 // TODO: raise a dialog box here rather than bomb out.
3729 .println("The scores matrix does not match the alignment dimensions");
3733 // TODO add parameter to indicate if matching should be done
3734 if (file.annotateAlignment(alignPanel.getAlignment(), false))
3736 alignPanel.fontChanged();
3737 tcoffeeColour.setEnabled(true);
3738 // switch to this color
3739 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
3744 System.err.println("Problems resolving T-Coffee scores:");
3745 if (file.getWarningMessage() != null)
3747 System.err.println(file.getWarningMessage());