2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.JalviewLite;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.DataSourceType;
39 import jalview.io.FileFormatI;
40 import jalview.io.FileFormats;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.renderer.ResidueShader;
43 import jalview.renderer.ResidueShaderI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.JalviewColourScheme;
50 import jalview.schemes.NucleotideColourScheme;
51 import jalview.schemes.PIDColourScheme;
52 import jalview.schemes.PurinePyrimidineColourScheme;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.MessageManager;
58 import jalview.util.UrlLink;
60 import java.awt.CheckboxMenuItem;
61 import java.awt.Frame;
63 import java.awt.MenuItem;
64 import java.awt.event.ActionEvent;
65 import java.awt.event.ActionListener;
66 import java.awt.event.ItemEvent;
67 import java.awt.event.ItemListener;
68 import java.util.ArrayList;
69 import java.util.Arrays;
70 import java.util.Collection;
71 import java.util.Collections;
72 import java.util.LinkedHashMap;
73 import java.util.List;
75 import java.util.SortedMap;
76 import java.util.TreeMap;
77 import java.util.Vector;
79 public class APopupMenu extends java.awt.PopupMenu implements
80 ActionListener, ItemListener
82 Menu groupMenu = new Menu();
84 MenuItem editGroupName = new MenuItem();
86 CheckboxMenuItem noColour = new CheckboxMenuItem();
88 protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
90 protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
92 protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
94 protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
96 protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
98 protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
100 protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
102 protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
104 protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
106 protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
108 CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
110 CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
112 protected MenuItem userDefinedColour = new MenuItem();
114 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
116 MenuItem modifyPID = new MenuItem();
118 protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
120 MenuItem modifyConservation = new MenuItem();
122 MenuItem noColourmenuItem = new MenuItem();
124 final AlignmentPanel ap;
126 MenuItem unGroupMenuItem = new MenuItem();
128 MenuItem createGroupMenuItem = new MenuItem();
130 Menu colourMenu = new Menu();
132 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
134 CheckboxMenuItem showText = new CheckboxMenuItem();
136 CheckboxMenuItem showColourText = new CheckboxMenuItem();
138 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
140 Menu seqShowAnnotationsMenu = new Menu(
141 MessageManager.getString("label.show_annotations"));
143 Menu seqHideAnnotationsMenu = new Menu(
144 MessageManager.getString("label.hide_annotations"));
146 MenuItem seqAddReferenceAnnotations = new MenuItem(
147 MessageManager.getString("label.add_reference_annotations"));
149 Menu groupShowAnnotationsMenu = new Menu(
150 MessageManager.getString("label.show_annotations"));
152 Menu groupHideAnnotationsMenu = new Menu(
153 MessageManager.getString("label.hide_annotations"));
155 MenuItem groupAddReferenceAnnotations = new MenuItem(
156 MessageManager.getString("label.add_reference_annotations"));
158 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
160 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
162 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
164 MenuItem toUpper = new MenuItem(
165 MessageManager.getString("label.to_upper_case"));
167 MenuItem toLower = new MenuItem(
168 MessageManager.getString("label.to_lower_case"));
170 MenuItem toggleCase = new MenuItem(
171 MessageManager.getString("label.toggle_case"));
173 Menu outputmenu = new Menu();
175 Menu seqMenu = new Menu();
177 MenuItem pdb = new MenuItem();
179 MenuItem hideSeqs = new MenuItem();
181 MenuItem repGroup = new MenuItem();
183 MenuItem sequenceName = new MenuItem(
184 MessageManager.getString("label.edit_name_description"));
186 MenuItem sequenceFeature = new MenuItem(
187 MessageManager.getString("label.create_sequence_feature"));
189 MenuItem editSequence = new MenuItem(
190 MessageManager.getString("label.edit_sequence"));
192 MenuItem sequenceDetails = new MenuItem(
193 MessageManager.getString("label.sequence_details"));
195 MenuItem selSeqDetails = new MenuItem(
196 MessageManager.getString("label.sequence_details"));
198 MenuItem makeReferenceSeq = new MenuItem();
202 MenuItem revealAll = new MenuItem();
204 MenuItem revealSeq = new MenuItem();
207 * index of sequence to be revealed
209 int revealSeq_index = -1;
211 Menu menu1 = new Menu();
213 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
216 // /////////////////////////////////////////////////////////
217 // If this is activated from the sequence panel, the user may want to
218 // edit or annotate a particular residue. Therefore display the residue menu
220 // If from the IDPanel, we must display the sequence menu
221 // ////////////////////////////////////////////////////////
229 } catch (Exception e)
234 for (String ff : FileFormats.getInstance().getWritableFormats(true))
236 MenuItem item = new MenuItem(ff);
238 item.addActionListener(this);
239 outputmenu.add(item);
242 buildAnnotationSubmenus();
244 SequenceGroup sg = ap.av.getSelectionGroup();
245 if (sg != null && sg.getSize() > 0)
247 if (sg.isNucleotide())
249 conservationColour.setEnabled(false);
250 clustalColour.setEnabled(false);
251 BLOSUM62Colour.setEnabled(false);
252 zappoColour.setEnabled(false);
253 taylorColour.setEnabled(false);
254 hydrophobicityColour.setEnabled(false);
255 helixColour.setEnabled(false);
256 strandColour.setEnabled(false);
257 turnColour.setEnabled(false);
258 buriedColour.setEnabled(false);
262 purinePyrimidineColour.setEnabled(false);
263 nucleotideColour.setEnabled(false);
265 editGroupName.setLabel(MessageManager.formatMessage(
266 "label.name_param", new Object[] { sg.getName() }));
267 showText.setState(sg.getDisplayText());
268 showColourText.setState(sg.getColourText());
269 showBoxes.setState(sg.getDisplayBoxes());
270 displayNonconserved.setState(sg.getShowNonconserved());
271 if (!ap.av.getAlignment().getGroups().contains(sg))
273 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
274 groupMenu.remove(unGroupMenuItem);
278 menu1.setLabel(MessageManager.getString("action.edit_group"));
279 groupMenu.remove(createGroupMenuItem);
282 abovePIDColour.setState(sg.cs.getThreshold() > 0);
283 conservationColour.setState(sg.cs.conservationApplied());
284 modifyPID.setEnabled(abovePIDColour.getState());
285 modifyConservation.setEnabled(conservationColour.getState());
288 setSelectedColour(sg.cs);
296 if (links != null && links.size() > 0)
298 addFeatureLinks(seq, links);
301 // TODO: add group link menu entry here
304 seqMenu.setLabel(seq.getName());
305 if (seq == ap.av.getAlignment().getSeqrep())
307 makeReferenceSeq.setLabel(MessageManager
308 .getString("action.unmark_as_reference"));// Unmark
313 makeReferenceSeq.setLabel(MessageManager
314 .getString("action.set_as_reference")); // );
316 repGroup.setLabel(MessageManager.formatMessage(
317 "label.represent_group_with", new Object[] { seq.getName() }));
324 if (!ap.av.hasHiddenRows())
331 final int index = ap.av.getAlignment().findIndex(seq);
333 if (ap.av.adjustForHiddenSeqs(index)
334 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
336 revealSeq_index = index;
346 * Select the menu item (if any) matching the current colour scheme. This
347 * works by matching the menu item name (not display text) to the canonical
348 * name of the colour scheme.
352 protected void setSelectedColour(ResidueShaderI cs)
354 if (cs == null || cs.getColourScheme() == null)
356 noColour.setState(true);
360 String name = cs.getColourScheme().getSchemeName();
361 for (int i = 0; i < colourMenu.getItemCount(); i++)
363 MenuItem item = colourMenu.getItem(i);
364 if (item instanceof CheckboxMenuItem)
366 if (name.equals(item.getName()))
368 ((CheckboxMenuItem) item).setState(true);
376 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
381 void addFeatureLinks(final SequenceI seq, List<String> links)
383 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
384 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
386 for (String link : links)
388 UrlLink urlLink = null;
391 urlLink = new UrlLink(link);
392 } catch (Exception foo)
394 System.err.println("Exception for URLLink '" + link + "': "
399 if (!urlLink.isValid())
401 System.err.println(urlLink.getInvalidMessage());
405 urlLink.createLinksFromSeq(seq, linkset);
408 addshowLinks(linkMenu, linkset.values());
410 // disable link menu if there are no valid entries
411 if (linkMenu.getItemCount() > 0)
413 linkMenu.setEnabled(true);
417 linkMenu.setEnabled(false);
422 seqMenu.add(linkMenu);
431 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
433 for (List<String> linkstrset : linkset)
435 // split linkstr into label and url
436 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
441 * Build menus for annotation types that may be shown or hidden, and for
442 * 'reference annotations' that may be added to the alignment.
444 private void buildAnnotationSubmenus()
447 * First for the currently selected sequence (if there is one):
449 final List<SequenceI> selectedSequence = (seq == null ? Collections
450 .<SequenceI> emptyList() : Arrays.asList(seq));
451 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
452 seqHideAnnotationsMenu, selectedSequence);
453 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
457 * and repeat for the current selection group (if there is one):
459 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
460 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
462 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
463 groupHideAnnotationsMenu, selectedGroup);
464 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
469 * Determine whether or not to enable 'add reference annotations' menu item.
470 * It is enable if there are any annotations, on any of the selected
471 * sequences, which are not yet on the alignment (visible or not).
474 * @param forSequences
476 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
477 List<SequenceI> forSequences)
479 menuItem.setEnabled(false);
482 * Temporary store to hold distinct calcId / type pairs for the tooltip.
483 * Using TreeMap means calcIds are shown in alphabetical order.
485 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
486 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
487 AlignmentI al = this.ap.av.getAlignment();
488 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
489 tipEntries, candidates, al);
490 if (!candidates.isEmpty())
492 StringBuilder tooltip = new StringBuilder(64);
493 tooltip.append(MessageManager.getString("label.add_annotations_for"));
496 * Found annotations that could be added. Enable the menu item, and
497 * configure its action.
499 menuItem.setEnabled(true);
501 menuItem.addActionListener(new ActionListener()
504 public void actionPerformed(ActionEvent e)
506 addReferenceAnnotations_actionPerformed(candidates);
513 * Add annotations to the sequences and to the alignment.
516 * a map whose keys are sequences on the alignment, and values a list
517 * of annotations to add to each sequence
519 protected void addReferenceAnnotations_actionPerformed(
520 Map<SequenceI, List<AlignmentAnnotation>> candidates)
522 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
523 final AlignmentI alignment = this.ap.getAlignment();
524 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
530 * add a show URL menu item to the given linkMenu
534 * - menu label string
538 private void addshowLink(Menu linkMenu, final String target,
541 addshowLink(linkMenu, target, target, url);
545 * add a show URL menu item to the given linkMenu
549 * - URL target window
551 * - menu label string
555 private void addshowLink(Menu linkMenu, final String target,
556 final String label, final String url)
558 MenuItem item = new MenuItem(label);
559 item.addActionListener(new java.awt.event.ActionListener()
562 public void actionPerformed(ActionEvent e)
564 ap.alignFrame.showURL(url, target);
571 * Actions on selecting / unselecting a checkbox menu item
574 public void itemStateChanged(ItemEvent evt)
576 Object source = evt.getSource();
577 if (source == noColour)
579 noColourmenuItem_actionPerformed();
581 else if (source == clustalColour)
583 clustalColour_actionPerformed();
585 else if (source == BLOSUM62Colour)
587 BLOSUM62Colour_actionPerformed();
589 else if (evt.getSource() == PIDColour)
591 PIDColour_actionPerformed();
593 else if (source == zappoColour)
595 zappoColour_actionPerformed();
597 else if (source == taylorColour)
599 taylorColour_actionPerformed();
601 else if (source == hydrophobicityColour)
603 hydrophobicityColour_actionPerformed();
605 else if (source == helixColour)
607 helixColour_actionPerformed();
609 else if (source == strandColour)
611 strandColour_actionPerformed();
613 else if (source == turnColour)
615 turnColour_actionPerformed();
617 else if (source == buriedColour)
619 buriedColour_actionPerformed();
621 else if (source == nucleotideColour)
623 nucleotideMenuItem_actionPerformed();
625 else if (source == purinePyrimidineColour)
627 purinePyrimidineColour_actionPerformed();
629 else if (source == abovePIDColour)
631 abovePIDColour_itemStateChanged();
633 else if (source == conservationColour)
635 conservationMenuItem_itemStateChanged();
637 else if (source == showColourText)
639 showColourText_itemStateChanged();
641 else if (source == showText)
643 showText_itemStateChanged();
645 else if (source == showBoxes)
647 showBoxes_itemStateChanged();
649 else if (source == displayNonconserved)
651 this.showNonconserved_itemStateChanged();
656 * Actions on clicking a menu item
659 public void actionPerformed(ActionEvent evt)
661 Object source = evt.getSource();
662 if (source == userDefinedColour)
664 userDefinedColour_actionPerformed();
666 else if (source == modifyConservation)
668 conservationMenuItem_itemStateChanged();
670 else if (source == modifyPID)
672 abovePIDColour_itemStateChanged();
674 else if (source == unGroupMenuItem)
676 unGroupMenuItem_actionPerformed();
679 else if (source == createGroupMenuItem)
681 createGroupMenuItem_actionPerformed();
684 else if (source == sequenceName)
688 else if (source == makeReferenceSeq)
690 makeReferenceSeq_actionPerformed();
692 else if (source == sequenceDetails)
694 showSequenceDetails();
696 else if (source == selSeqDetails)
698 showSequenceSelectionDetails();
700 else if (source == pdb)
704 else if (source == hideSeqs)
706 hideSequences(false);
708 else if (source == repGroup)
712 else if (source == revealSeq)
714 ap.av.showSequence(revealSeq_index);
716 else if (source == revealAll)
718 ap.av.showAllHiddenSeqs();
721 else if (source == editGroupName)
723 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
724 getGroup().getDescription(), " Group Name",
725 "Group Description", ap.alignFrame,
726 "Edit Group Name / Description", 500, 100, true);
730 getGroup().setName(dialog.getName().replace(' ', '_'));
731 getGroup().setDescription(dialog.getDescription());
735 else if (source == copy)
737 ap.alignFrame.copy_actionPerformed();
739 else if (source == cut)
741 ap.alignFrame.cut_actionPerformed();
743 else if (source == editSequence)
745 SequenceGroup sg = ap.av.getSelectionGroup();
751 seq = sg.getSequenceAt(0);
754 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
755 sg.getStartRes(), sg.getEndRes() + 1), null,
756 "Edit Sequence ", null,
758 ap.alignFrame, "Edit Sequence", 500, 100, true);
762 EditCommand editCommand = new EditCommand(
763 MessageManager.getString("label.edit_sequences"),
764 Action.REPLACE, dialog.getName().replace(' ',
765 ap.av.getGapCharacter()),
766 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
767 sg.getStartRes(), sg.getEndRes() + 1,
768 ap.av.getAlignment());
770 ap.alignFrame.addHistoryItem(editCommand);
772 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
777 else if (source == toUpper || source == toLower || source == toggleCase)
779 SequenceGroup sg = ap.av.getSelectionGroup();
782 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
783 sg.getStartRes(), sg.getEndRes() + 1);
788 if (source == toggleCase)
790 description = "Toggle Case";
791 caseChange = ChangeCaseCommand.TOGGLE_CASE;
793 else if (source == toUpper)
795 description = "To Upper Case";
796 caseChange = ChangeCaseCommand.TO_UPPER;
800 description = "To Lower Case";
801 caseChange = ChangeCaseCommand.TO_LOWER;
804 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
805 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
806 startEnd, caseChange);
808 ap.alignFrame.addHistoryItem(caseCommand);
810 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
815 else if (source == sequenceFeature)
817 SequenceGroup sg = ap.av.getSelectionGroup();
823 int gSize = sg.getSize();
824 List<SequenceI> seqs = new ArrayList<SequenceI>();
825 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
827 for (int i = 0; i < gSize; i++)
829 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
830 int end = sg.findEndRes(sg.getSequenceAt(i));
833 seqs.add(sg.getSequenceAt(i));
834 features.add(new SequenceFeature(null, null, null, start, end,
841 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
844 ap.alignFrame.sequenceFeatures.setState(true);
845 ap.av.setShowSequenceFeatures(true);
846 ap.highlightSearchResults(null);
857 void outputText(ActionEvent e)
859 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
861 Frame frame = new Frame();
863 JalviewLite.addFrame(frame, MessageManager.formatMessage(
864 "label.selection_output_command",
865 new Object[] { e.getActionCommand() }), 600, 500);
866 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
867 // now returns a full copy of sequence data
868 // TODO consider using getSequenceSelection instead here
870 FileFormatI fileFormat = FileFormats.getInstance().forName(
871 e.getActionCommand());
872 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
873 ap.av.getShowJVSuffix(), ap, true));
877 protected void showSequenceSelectionDetails()
879 createSequenceDetailsReport(ap.av.getSequenceSelection());
882 protected void showSequenceDetails()
884 createSequenceDetailsReport(new SequenceI[] { seq });
887 public void createSequenceDetailsReport(SequenceI[] sequences)
890 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
892 StringBuilder contents = new StringBuilder(128);
893 for (SequenceI seq : sequences)
895 contents.append(MessageManager.formatMessage(
896 "label.annotation_for_displayid",
897 new Object[] { seq.getDisplayId(true) }));
898 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
903 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
904 .getMinMax() : null);
905 contents.append("</p>");
907 Frame frame = new Frame();
909 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
910 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
911 : "Selection"), 600, 500);
912 cap.setText(MessageManager.formatMessage("label.html_content",
913 new Object[] { contents.toString() }));
918 EditNameDialog dialog = new EditNameDialog(seq.getName(),
919 seq.getDescription(), " Sequence Name",
920 "Sequence Description", ap.alignFrame,
921 "Edit Sequence Name / Description", 500, 100, true);
925 seq.setName(dialog.getName());
926 seq.setDescription(dialog.getDescription());
927 ap.paintAlignment(false);
933 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
934 if (pdbs != null && !pdbs.isEmpty())
936 PDBEntry entry = pdbs.firstElement();
938 if (ap.av.applet.jmolAvailable)
940 new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
945 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
946 ap, DataSourceType.URL);
952 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
953 cap.setText(MessageManager.getString("label.paste_pdb_file"));
954 cap.setPDBImport(seq);
955 Frame frame = new Frame();
957 JalviewLite.addFrame(frame, MessageManager.formatMessage(
958 "label.paste_pdb_file_for_sequence",
959 new Object[] { seq.getName() }), 400, 300);
963 private void jbInit() throws Exception
965 groupMenu.setLabel(MessageManager.getString("label.selection"));
966 sequenceFeature.addActionListener(this);
968 editGroupName.addActionListener(this);
969 unGroupMenuItem.setLabel(MessageManager
970 .getString("action.remove_group"));
971 unGroupMenuItem.addActionListener(this);
973 createGroupMenuItem.setLabel(MessageManager
974 .getString("action.create_group"));
975 createGroupMenuItem.addActionListener(this);
977 modifyPID.setEnabled(abovePIDColour.getState());
978 modifyConservation.setEnabled(conservationColour.getState());
979 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
980 showBoxes.setLabel(MessageManager.getString("action.boxes"));
981 showBoxes.setState(true);
982 showBoxes.addItemListener(this);
983 sequenceName.addActionListener(this);
984 sequenceDetails.addActionListener(this);
985 selSeqDetails.addActionListener(this);
986 displayNonconserved.setLabel(MessageManager
987 .getString("label.show_non_conserved"));
988 displayNonconserved.setState(false);
989 displayNonconserved.addItemListener(this);
990 showText.setLabel(MessageManager.getString("action.text"));
991 showText.addItemListener(this);
992 showColourText.setLabel(MessageManager.getString("label.colour_text"));
993 showColourText.addItemListener(this);
994 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
995 seqMenu.setLabel(MessageManager.getString("label.sequence"));
996 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
997 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
998 repGroup.setLabel(MessageManager.formatMessage(
999 "label.represent_group_with", new Object[] { "" }));
1000 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
1001 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
1002 menu1.setLabel(MessageManager.getString("label.group:"));
1006 this.add(revealSeq);
1007 this.add(revealAll);
1008 // groupMenu.add(selSeqDetails);
1009 groupMenu.add(groupShowAnnotationsMenu);
1010 groupMenu.add(groupHideAnnotationsMenu);
1011 groupMenu.add(groupAddReferenceAnnotations);
1012 groupMenu.add(editMenu);
1013 groupMenu.add(outputmenu);
1014 groupMenu.add(sequenceFeature);
1015 groupMenu.add(createGroupMenuItem);
1016 groupMenu.add(unGroupMenuItem);
1017 groupMenu.add(menu1);
1019 colourMenu.add(noColour);
1020 colourMenu.add(clustalColour);
1021 colourMenu.add(BLOSUM62Colour);
1022 colourMenu.add(PIDColour);
1023 colourMenu.add(zappoColour);
1024 colourMenu.add(taylorColour);
1025 colourMenu.add(hydrophobicityColour);
1026 colourMenu.add(helixColour);
1027 colourMenu.add(strandColour);
1028 colourMenu.add(turnColour);
1029 colourMenu.add(buriedColour);
1030 colourMenu.add(nucleotideColour);
1031 colourMenu.add(purinePyrimidineColour);
1032 colourMenu.add(userDefinedColour);
1033 colourMenu.addSeparator();
1034 colourMenu.add(conservationColour);
1035 colourMenu.add(modifyConservation);
1036 colourMenu.add(abovePIDColour);
1037 colourMenu.add(modifyPID);
1039 noColour.setLabel(MessageManager.getString("label.none"));
1040 noColour.addItemListener(this);
1043 * setName allows setSelectedColour to do its thing
1045 clustalColour.setLabel(MessageManager
1046 .getString("label.colourScheme_clustal"));
1047 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1048 clustalColour.addItemListener(this);
1049 BLOSUM62Colour.setLabel(MessageManager
1050 .getString("label.colourScheme_blosum62"));
1051 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1052 BLOSUM62Colour.addItemListener(this);
1053 PIDColour.setLabel(MessageManager
1054 .getString("label.colourScheme_%_identity"));
1055 PIDColour.setName(JalviewColourScheme.PID.toString());
1056 PIDColour.addItemListener(this);
1057 zappoColour.setLabel(MessageManager
1058 .getString("label.colourScheme_zappo"));
1059 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1060 zappoColour.addItemListener(this);
1061 taylorColour.setLabel(MessageManager
1062 .getString("label.colourScheme_taylor"));
1063 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1064 taylorColour.addItemListener(this);
1065 hydrophobicityColour.setLabel(MessageManager
1066 .getString("label.colourScheme_hydrophobic"));
1067 hydrophobicityColour
1068 .setName(JalviewColourScheme.Hydrophobic.toString());
1069 hydrophobicityColour.addItemListener(this);
1070 helixColour.setLabel(MessageManager
1071 .getString("label.colourScheme_helix_propensity"));
1072 helixColour.setName(JalviewColourScheme.Helix.toString());
1073 helixColour.addItemListener(this);
1074 strandColour.setLabel(MessageManager
1075 .getString("label.colourScheme_strand_propensity"));
1076 strandColour.setName(JalviewColourScheme.Strand.toString());
1077 strandColour.addItemListener(this);
1078 turnColour.setLabel(MessageManager
1079 .getString("label.colourScheme_turn_propensity"));
1080 turnColour.setName(JalviewColourScheme.Turn.toString());
1081 turnColour.addItemListener(this);
1082 buriedColour.setLabel(MessageManager
1083 .getString("label.colourScheme_buried_index"));
1084 buriedColour.setName(JalviewColourScheme.Buried.toString());
1085 buriedColour.addItemListener(this);
1086 nucleotideColour.setLabel(MessageManager
1087 .getString("label.colourScheme_nucleotide"));
1088 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1089 nucleotideColour.addItemListener(this);
1090 purinePyrimidineColour.setLabel(MessageManager
1091 .getString("label.colourScheme_purine/pyrimidine"));
1092 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1094 purinePyrimidineColour.addItemListener(this);
1096 userDefinedColour.setLabel(MessageManager
1097 .getString("action.user_defined"));
1098 userDefinedColour.addActionListener(this);
1100 abovePIDColour.setLabel(MessageManager
1101 .getString("label.above_identity_threshold"));
1102 abovePIDColour.addItemListener(this);
1103 modifyPID.setLabel(MessageManager
1104 .getString("label.modify_identity_threshold"));
1105 modifyPID.addActionListener(this);
1106 conservationColour.setLabel(MessageManager
1107 .getString("action.by_conservation"));
1108 conservationColour.addItemListener(this);
1109 modifyConservation.setLabel(MessageManager
1110 .getString("label.modify_conservation_threshold"));
1111 modifyConservation.addActionListener(this);
1113 PIDColour.addActionListener(this);
1114 BLOSUM62Colour.addActionListener(this);
1117 copy.addActionListener(this);
1119 cut.addActionListener(this);
1121 editMenu.add(editSequence);
1122 editSequence.addActionListener(this);
1124 editMenu.add(toUpper);
1125 toUpper.addActionListener(this);
1126 editMenu.add(toLower);
1127 toLower.addActionListener(this);
1128 editMenu.add(toggleCase);
1129 seqMenu.add(seqShowAnnotationsMenu);
1130 seqMenu.add(seqHideAnnotationsMenu);
1131 seqMenu.add(seqAddReferenceAnnotations);
1132 seqMenu.add(sequenceName);
1133 seqMenu.add(makeReferenceSeq);
1134 // seqMenu.add(sequenceDetails);
1136 if (!ap.av.applet.useXtrnalSviewer)
1140 seqMenu.add(repGroup);
1141 menu1.add(editGroupName);
1142 menu1.add(colourMenu);
1143 menu1.add(showBoxes);
1144 menu1.add(showText);
1145 menu1.add(showColourText);
1146 menu1.add(displayNonconserved);
1147 toggleCase.addActionListener(this);
1148 pdb.addActionListener(this);
1149 hideSeqs.addActionListener(this);
1150 repGroup.addActionListener(this);
1151 revealAll.addActionListener(this);
1152 revealSeq.addActionListener(this);
1153 makeReferenceSeq.addActionListener(this);
1158 ap.paintAlignment(true);
1161 protected void clustalColour_actionPerformed()
1163 SequenceGroup sg = getGroup();
1164 sg.cs = new ResidueShader(new ClustalxColourScheme(sg,
1165 ap.av.getHiddenRepSequences()));
1169 protected void zappoColour_actionPerformed()
1171 getGroup().cs = new ResidueShader(new ZappoColourScheme());
1175 protected void taylorColour_actionPerformed()
1177 getGroup().cs = new ResidueShader(new TaylorColourScheme());
1181 protected void hydrophobicityColour_actionPerformed()
1183 getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
1187 protected void helixColour_actionPerformed()
1189 getGroup().cs = new ResidueShader(new HelixColourScheme());
1193 protected void strandColour_actionPerformed()
1195 getGroup().cs = new ResidueShader(new StrandColourScheme());
1199 protected void turnColour_actionPerformed()
1201 getGroup().cs = new ResidueShader(new TurnColourScheme());
1205 protected void buriedColour_actionPerformed()
1207 getGroup().cs = new ResidueShader(new BuriedColourScheme());
1211 public void nucleotideMenuItem_actionPerformed()
1213 getGroup().cs = new ResidueShader(new NucleotideColourScheme());
1217 public void purinePyrimidineColour_actionPerformed()
1219 getGroup().cs = new ResidueShader(
1220 new PurinePyrimidineColourScheme());
1224 protected void abovePIDColour_itemStateChanged()
1226 SequenceGroup sg = getGroup();
1232 if (abovePIDColour.getState())
1234 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1235 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1236 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1239 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1241 SliderPanel.showPIDSlider();
1245 // remove PIDColouring
1247 SliderPanel.hidePIDSlider();
1248 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1250 modifyPID.setEnabled(abovePIDColour.getState());
1254 protected void userDefinedColour_actionPerformed()
1256 new UserDefinedColours(ap, getGroup());
1259 protected void PIDColour_actionPerformed()
1261 SequenceGroup sg = getGroup();
1262 sg.cs = new ResidueShader(new PIDColourScheme());
1263 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1264 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1268 protected void BLOSUM62Colour_actionPerformed()
1270 SequenceGroup sg = getGroup();
1272 sg.cs = new ResidueShader(new Blosum62ColourScheme());
1274 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1275 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1280 protected void noColourmenuItem_actionPerformed()
1282 getGroup().cs = null;
1286 protected void conservationMenuItem_itemStateChanged()
1288 SequenceGroup sg = getGroup();
1294 if (conservationColour.getState())
1296 Conservation conservation = Conservation.calculateConservation(
1298 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1299 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1301 sg.getGroupColourScheme().setConservation(conservation);
1302 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1303 SliderPanel.showConservationSlider();
1306 // remove ConservationColouring
1308 SliderPanel.hideConservationSlider();
1309 sg.cs.setConservation(null);
1311 modifyConservation.setEnabled(conservationColour.getState());
1315 SequenceGroup getGroup()
1317 SequenceGroup sg = ap.av.getSelectionGroup();
1319 // this method won't add a new group if it already exists
1322 ap.av.getAlignment().addGroup(sg);
1328 void unGroupMenuItem_actionPerformed()
1330 SequenceGroup sg = ap.av.getSelectionGroup();
1331 ap.av.getAlignment().deleteGroup(sg);
1332 ap.av.setSelectionGroup(null);
1333 ap.paintAlignment(true);
1336 void createGroupMenuItem_actionPerformed()
1338 getGroup(); // implicitly create group
1342 public void showColourText_itemStateChanged()
1344 getGroup().setColourText(showColourText.getState());
1348 public void showText_itemStateChanged()
1350 getGroup().setDisplayText(showText.getState());
1354 public void makeReferenceSeq_actionPerformed()
1356 if (!ap.av.getAlignment().hasSeqrep())
1358 // initialise the display flags so the user sees something happen
1359 ap.av.setDisplayReferenceSeq(true);
1360 ap.av.setColourByReferenceSeq(true);
1361 ap.av.getAlignment().setSeqrep(seq);
1365 if (ap.av.getAlignment().getSeqrep() == seq)
1367 ap.av.getAlignment().setSeqrep(null);
1371 ap.av.getAlignment().setSeqrep(seq);
1377 public void showNonconserved_itemStateChanged()
1379 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1383 public void showBoxes_itemStateChanged()
1385 getGroup().setDisplayBoxes(showBoxes.getState());
1389 void hideSequences(boolean representGroup)
1391 ap.av.hideSequences(seq, representGroup);
1395 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1396 * "All" is added first, followed by a separator. Then add any annotation
1397 * types associated with the current selection. Separate menus are built for
1398 * the selected sequence group (if any), and the selected sequence.
1400 * Some annotation rows are always rendered together - these can be identified
1401 * by a common graphGroup property > -1. Only one of each group will be marked
1402 * as visible (to avoid duplication of the display). For such groups we add a
1403 * composite type name, e.g.
1405 * IUPredWS (Long), IUPredWS (Short)
1409 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1410 List<SequenceI> forSequences)
1412 showMenu.removeAll();
1413 hideMenu.removeAll();
1415 final List<String> all = Arrays.asList(new String[] { MessageManager
1416 .getString("label.all") });
1417 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1418 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1420 showMenu.addSeparator();
1421 hideMenu.addSeparator();
1423 final AlignmentAnnotation[] annotations = ap.getAlignment()
1424 .getAlignmentAnnotation();
1427 * Find shown/hidden annotations types, distinguished by source (calcId),
1428 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1429 * the insertion order, which is the order of the annotations on the
1432 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1433 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1434 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1435 AlignmentAnnotationUtils.asList(annotations), forSequences);
1437 for (String calcId : hiddenTypes.keySet())
1439 for (List<String> type : hiddenTypes.get(calcId))
1441 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1445 // grey out 'show annotations' if none are hidden
1446 showMenu.setEnabled(!hiddenTypes.isEmpty());
1448 for (String calcId : shownTypes.keySet())
1450 for (List<String> type : shownTypes.get(calcId))
1452 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1456 // grey out 'hide annotations' if none are shown
1457 hideMenu.setEnabled(!shownTypes.isEmpty());
1461 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1464 * @param showOrHideMenu
1465 * the menu to add to
1466 * @param forSequences
1467 * the sequences whose annotations may be shown or hidden
1472 * if true this is a special label meaning 'All'
1473 * @param actionIsShow
1474 * if true, the select menu item action is to show the annotation
1477 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1478 final List<SequenceI> forSequences, String calcId,
1479 final List<String> types, final boolean allTypes,
1480 final boolean actionIsShow)
1482 String label = types.toString(); // [a, b, c]
1483 label = label.substring(1, label.length() - 1);
1484 final MenuItem item = new MenuItem(label);
1485 item.addActionListener(new java.awt.event.ActionListener()
1488 public void actionPerformed(ActionEvent e)
1490 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1491 types, forSequences, allTypes, actionIsShow);
1495 showOrHideMenu.add(item);