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, start, end,
839 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
842 ap.alignFrame.sequenceFeatures.setState(true);
843 ap.av.setShowSequenceFeatures(true);
844 ap.highlightSearchResults(null);
854 void outputText(ActionEvent e)
856 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
858 Frame frame = new Frame();
860 JalviewLite.addFrame(frame, MessageManager.formatMessage(
861 "label.selection_output_command",
862 new Object[] { e.getActionCommand() }), 600, 500);
863 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
864 // now returns a full copy of sequence data
865 // TODO consider using getSequenceSelection instead here
867 FileFormatI fileFormat = FileFormats.getInstance().forName(
868 e.getActionCommand());
869 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
870 ap.av.getShowJVSuffix(), ap, true));
874 protected void showSequenceSelectionDetails()
876 createSequenceDetailsReport(ap.av.getSequenceSelection());
879 protected void showSequenceDetails()
881 createSequenceDetailsReport(new SequenceI[] { seq });
884 public void createSequenceDetailsReport(SequenceI[] sequences)
887 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
889 StringBuilder contents = new StringBuilder(128);
890 for (SequenceI seq : sequences)
892 contents.append(MessageManager.formatMessage(
893 "label.annotation_for_displayid",
894 new Object[] { seq.getDisplayId(true) }));
895 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
900 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
901 .getMinMax() : null);
902 contents.append("</p>");
904 Frame frame = new Frame();
906 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
907 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
908 : "Selection"), 600, 500);
909 cap.setText(MessageManager.formatMessage("label.html_content",
910 new Object[] { contents.toString() }));
915 EditNameDialog dialog = new EditNameDialog(seq.getName(),
916 seq.getDescription(), " Sequence Name",
917 "Sequence Description", ap.alignFrame,
918 "Edit Sequence Name / Description", 500, 100, true);
922 seq.setName(dialog.getName());
923 seq.setDescription(dialog.getDescription());
924 ap.paintAlignment(false);
930 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
931 if (pdbs != null && !pdbs.isEmpty())
933 PDBEntry entry = pdbs.firstElement();
935 if (ap.av.applet.jmolAvailable)
937 new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
942 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
943 ap, DataSourceType.URL);
949 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
950 cap.setText(MessageManager.getString("label.paste_pdb_file"));
951 cap.setPDBImport(seq);
952 Frame frame = new Frame();
954 JalviewLite.addFrame(frame, MessageManager.formatMessage(
955 "label.paste_pdb_file_for_sequence",
956 new Object[] { seq.getName() }), 400, 300);
960 private void jbInit() throws Exception
962 groupMenu.setLabel(MessageManager.getString("label.selection"));
963 sequenceFeature.addActionListener(this);
965 editGroupName.addActionListener(this);
966 unGroupMenuItem.setLabel(MessageManager
967 .getString("action.remove_group"));
968 unGroupMenuItem.addActionListener(this);
970 createGroupMenuItem.setLabel(MessageManager
971 .getString("action.create_group"));
972 createGroupMenuItem.addActionListener(this);
974 modifyPID.setEnabled(abovePIDColour.getState());
975 modifyConservation.setEnabled(conservationColour.getState());
976 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
977 showBoxes.setLabel(MessageManager.getString("action.boxes"));
978 showBoxes.setState(true);
979 showBoxes.addItemListener(this);
980 sequenceName.addActionListener(this);
981 sequenceDetails.addActionListener(this);
982 selSeqDetails.addActionListener(this);
983 displayNonconserved.setLabel(MessageManager
984 .getString("label.show_non_conserved"));
985 displayNonconserved.setState(false);
986 displayNonconserved.addItemListener(this);
987 showText.setLabel(MessageManager.getString("action.text"));
988 showText.addItemListener(this);
989 showColourText.setLabel(MessageManager.getString("label.colour_text"));
990 showColourText.addItemListener(this);
991 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
992 seqMenu.setLabel(MessageManager.getString("label.sequence"));
993 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
994 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
995 repGroup.setLabel(MessageManager.formatMessage(
996 "label.represent_group_with", new Object[] { "" }));
997 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
998 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
999 menu1.setLabel(MessageManager.getString("label.group:"));
1003 this.add(revealSeq);
1004 this.add(revealAll);
1005 // groupMenu.add(selSeqDetails);
1006 groupMenu.add(groupShowAnnotationsMenu);
1007 groupMenu.add(groupHideAnnotationsMenu);
1008 groupMenu.add(groupAddReferenceAnnotations);
1009 groupMenu.add(editMenu);
1010 groupMenu.add(outputmenu);
1011 groupMenu.add(sequenceFeature);
1012 groupMenu.add(createGroupMenuItem);
1013 groupMenu.add(unGroupMenuItem);
1014 groupMenu.add(menu1);
1016 colourMenu.add(noColour);
1017 colourMenu.add(clustalColour);
1018 colourMenu.add(BLOSUM62Colour);
1019 colourMenu.add(PIDColour);
1020 colourMenu.add(zappoColour);
1021 colourMenu.add(taylorColour);
1022 colourMenu.add(hydrophobicityColour);
1023 colourMenu.add(helixColour);
1024 colourMenu.add(strandColour);
1025 colourMenu.add(turnColour);
1026 colourMenu.add(buriedColour);
1027 colourMenu.add(nucleotideColour);
1028 colourMenu.add(purinePyrimidineColour);
1029 colourMenu.add(userDefinedColour);
1030 colourMenu.addSeparator();
1031 colourMenu.add(conservationColour);
1032 colourMenu.add(modifyConservation);
1033 colourMenu.add(abovePIDColour);
1034 colourMenu.add(modifyPID);
1036 noColour.setLabel(MessageManager.getString("label.none"));
1037 noColour.addItemListener(this);
1040 * setName allows setSelectedColour to do its thing
1042 clustalColour.setLabel(MessageManager
1043 .getString("label.colourScheme_clustal"));
1044 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1045 clustalColour.addItemListener(this);
1046 BLOSUM62Colour.setLabel(MessageManager
1047 .getString("label.colourScheme_blosum62"));
1048 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1049 BLOSUM62Colour.addItemListener(this);
1050 PIDColour.setLabel(MessageManager
1051 .getString("label.colourScheme_%_identity"));
1052 PIDColour.setName(JalviewColourScheme.PID.toString());
1053 PIDColour.addItemListener(this);
1054 zappoColour.setLabel(MessageManager
1055 .getString("label.colourScheme_zappo"));
1056 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1057 zappoColour.addItemListener(this);
1058 taylorColour.setLabel(MessageManager
1059 .getString("label.colourScheme_taylor"));
1060 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1061 taylorColour.addItemListener(this);
1062 hydrophobicityColour.setLabel(MessageManager
1063 .getString("label.colourScheme_hydrophobic"));
1064 hydrophobicityColour
1065 .setName(JalviewColourScheme.Hydrophobic.toString());
1066 hydrophobicityColour.addItemListener(this);
1067 helixColour.setLabel(MessageManager
1068 .getString("label.colourScheme_helix_propensity"));
1069 helixColour.setName(JalviewColourScheme.Helix.toString());
1070 helixColour.addItemListener(this);
1071 strandColour.setLabel(MessageManager
1072 .getString("label.colourScheme_strand_propensity"));
1073 strandColour.setName(JalviewColourScheme.Strand.toString());
1074 strandColour.addItemListener(this);
1075 turnColour.setLabel(MessageManager
1076 .getString("label.colourScheme_turn_propensity"));
1077 turnColour.setName(JalviewColourScheme.Turn.toString());
1078 turnColour.addItemListener(this);
1079 buriedColour.setLabel(MessageManager
1080 .getString("label.colourScheme_buried_index"));
1081 buriedColour.setName(JalviewColourScheme.Buried.toString());
1082 buriedColour.addItemListener(this);
1083 nucleotideColour.setLabel(MessageManager
1084 .getString("label.colourScheme_nucleotide"));
1085 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1086 nucleotideColour.addItemListener(this);
1087 purinePyrimidineColour.setLabel(MessageManager
1088 .getString("label.colourScheme_purine/pyrimidine"));
1089 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1091 purinePyrimidineColour.addItemListener(this);
1093 userDefinedColour.setLabel(MessageManager
1094 .getString("action.user_defined"));
1095 userDefinedColour.addActionListener(this);
1097 abovePIDColour.setLabel(MessageManager
1098 .getString("label.above_identity_threshold"));
1099 abovePIDColour.addItemListener(this);
1100 modifyPID.setLabel(MessageManager
1101 .getString("label.modify_identity_threshold"));
1102 modifyPID.addActionListener(this);
1103 conservationColour.setLabel(MessageManager
1104 .getString("action.by_conservation"));
1105 conservationColour.addItemListener(this);
1106 modifyConservation.setLabel(MessageManager
1107 .getString("label.modify_conservation_threshold"));
1108 modifyConservation.addActionListener(this);
1110 PIDColour.addActionListener(this);
1111 BLOSUM62Colour.addActionListener(this);
1114 copy.addActionListener(this);
1116 cut.addActionListener(this);
1118 editMenu.add(editSequence);
1119 editSequence.addActionListener(this);
1121 editMenu.add(toUpper);
1122 toUpper.addActionListener(this);
1123 editMenu.add(toLower);
1124 toLower.addActionListener(this);
1125 editMenu.add(toggleCase);
1126 seqMenu.add(seqShowAnnotationsMenu);
1127 seqMenu.add(seqHideAnnotationsMenu);
1128 seqMenu.add(seqAddReferenceAnnotations);
1129 seqMenu.add(sequenceName);
1130 seqMenu.add(makeReferenceSeq);
1131 // seqMenu.add(sequenceDetails);
1133 if (!ap.av.applet.useXtrnalSviewer)
1137 seqMenu.add(repGroup);
1138 menu1.add(editGroupName);
1139 menu1.add(colourMenu);
1140 menu1.add(showBoxes);
1141 menu1.add(showText);
1142 menu1.add(showColourText);
1143 menu1.add(displayNonconserved);
1144 toggleCase.addActionListener(this);
1145 pdb.addActionListener(this);
1146 hideSeqs.addActionListener(this);
1147 repGroup.addActionListener(this);
1148 revealAll.addActionListener(this);
1149 revealSeq.addActionListener(this);
1150 makeReferenceSeq.addActionListener(this);
1155 ap.paintAlignment(true);
1158 protected void clustalColour_actionPerformed()
1160 SequenceGroup sg = getGroup();
1161 sg.cs = new ResidueShader(new ClustalxColourScheme(sg,
1162 ap.av.getHiddenRepSequences()));
1166 protected void zappoColour_actionPerformed()
1168 getGroup().cs = new ResidueShader(new ZappoColourScheme());
1172 protected void taylorColour_actionPerformed()
1174 getGroup().cs = new ResidueShader(new TaylorColourScheme());
1178 protected void hydrophobicityColour_actionPerformed()
1180 getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
1184 protected void helixColour_actionPerformed()
1186 getGroup().cs = new ResidueShader(new HelixColourScheme());
1190 protected void strandColour_actionPerformed()
1192 getGroup().cs = new ResidueShader(new StrandColourScheme());
1196 protected void turnColour_actionPerformed()
1198 getGroup().cs = new ResidueShader(new TurnColourScheme());
1202 protected void buriedColour_actionPerformed()
1204 getGroup().cs = new ResidueShader(new BuriedColourScheme());
1208 public void nucleotideMenuItem_actionPerformed()
1210 getGroup().cs = new ResidueShader(new NucleotideColourScheme());
1214 public void purinePyrimidineColour_actionPerformed()
1216 getGroup().cs = new ResidueShader(
1217 new PurinePyrimidineColourScheme());
1221 protected void abovePIDColour_itemStateChanged()
1223 SequenceGroup sg = getGroup();
1229 if (abovePIDColour.getState())
1231 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1232 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1233 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1236 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1238 SliderPanel.showPIDSlider();
1242 // remove PIDColouring
1244 SliderPanel.hidePIDSlider();
1245 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1247 modifyPID.setEnabled(abovePIDColour.getState());
1251 protected void userDefinedColour_actionPerformed()
1253 new UserDefinedColours(ap, getGroup());
1256 protected void PIDColour_actionPerformed()
1258 SequenceGroup sg = getGroup();
1259 sg.cs = new ResidueShader(new PIDColourScheme());
1260 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1261 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1265 protected void BLOSUM62Colour_actionPerformed()
1267 SequenceGroup sg = getGroup();
1269 sg.cs = new ResidueShader(new Blosum62ColourScheme());
1271 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1272 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1277 protected void noColourmenuItem_actionPerformed()
1279 getGroup().cs = null;
1283 protected void conservationMenuItem_itemStateChanged()
1285 SequenceGroup sg = getGroup();
1291 if (conservationColour.getState())
1293 Conservation conservation = Conservation.calculateConservation(
1295 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1296 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1298 sg.getGroupColourScheme().setConservation(conservation);
1299 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1300 SliderPanel.showConservationSlider();
1303 // remove ConservationColouring
1305 SliderPanel.hideConservationSlider();
1306 sg.cs.setConservation(null);
1308 modifyConservation.setEnabled(conservationColour.getState());
1312 SequenceGroup getGroup()
1314 SequenceGroup sg = ap.av.getSelectionGroup();
1316 // this method won't add a new group if it already exists
1319 ap.av.getAlignment().addGroup(sg);
1325 void unGroupMenuItem_actionPerformed()
1327 SequenceGroup sg = ap.av.getSelectionGroup();
1328 ap.av.getAlignment().deleteGroup(sg);
1329 ap.av.setSelectionGroup(null);
1330 ap.paintAlignment(true);
1333 void createGroupMenuItem_actionPerformed()
1335 getGroup(); // implicitly create group
1339 public void showColourText_itemStateChanged()
1341 getGroup().setColourText(showColourText.getState());
1345 public void showText_itemStateChanged()
1347 getGroup().setDisplayText(showText.getState());
1351 public void makeReferenceSeq_actionPerformed()
1353 if (!ap.av.getAlignment().hasSeqrep())
1355 // initialise the display flags so the user sees something happen
1356 ap.av.setDisplayReferenceSeq(true);
1357 ap.av.setColourByReferenceSeq(true);
1358 ap.av.getAlignment().setSeqrep(seq);
1362 if (ap.av.getAlignment().getSeqrep() == seq)
1364 ap.av.getAlignment().setSeqrep(null);
1368 ap.av.getAlignment().setSeqrep(seq);
1374 public void showNonconserved_itemStateChanged()
1376 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1380 public void showBoxes_itemStateChanged()
1382 getGroup().setDisplayBoxes(showBoxes.getState());
1386 void hideSequences(boolean representGroup)
1388 ap.av.hideSequences(seq, representGroup);
1392 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1393 * "All" is added first, followed by a separator. Then add any annotation
1394 * types associated with the current selection. Separate menus are built for
1395 * the selected sequence group (if any), and the selected sequence.
1397 * Some annotation rows are always rendered together - these can be identified
1398 * by a common graphGroup property > -1. Only one of each group will be marked
1399 * as visible (to avoid duplication of the display). For such groups we add a
1400 * composite type name, e.g.
1402 * IUPredWS (Long), IUPredWS (Short)
1406 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1407 List<SequenceI> forSequences)
1409 showMenu.removeAll();
1410 hideMenu.removeAll();
1412 final List<String> all = Arrays.asList(new String[] { MessageManager
1413 .getString("label.all") });
1414 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1415 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1417 showMenu.addSeparator();
1418 hideMenu.addSeparator();
1420 final AlignmentAnnotation[] annotations = ap.getAlignment()
1421 .getAlignmentAnnotation();
1424 * Find shown/hidden annotations types, distinguished by source (calcId),
1425 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1426 * the insertion order, which is the order of the annotations on the
1429 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1430 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1431 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1432 AlignmentAnnotationUtils.asList(annotations), forSequences);
1434 for (String calcId : hiddenTypes.keySet())
1436 for (List<String> type : hiddenTypes.get(calcId))
1438 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1442 // grey out 'show annotations' if none are hidden
1443 showMenu.setEnabled(!hiddenTypes.isEmpty());
1445 for (String calcId : shownTypes.keySet())
1447 for (List<String> type : shownTypes.get(calcId))
1449 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1453 // grey out 'hide annotations' if none are shown
1454 hideMenu.setEnabled(!shownTypes.isEmpty());
1458 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1461 * @param showOrHideMenu
1462 * the menu to add to
1463 * @param forSequences
1464 * the sequences whose annotations may be shown or hidden
1469 * if true this is a special label meaning 'All'
1470 * @param actionIsShow
1471 * if true, the select menu item action is to show the annotation
1474 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1475 final List<SequenceI> forSequences, String calcId,
1476 final List<String> types, final boolean allTypes,
1477 final boolean actionIsShow)
1479 String label = types.toString(); // [a, b, c]
1480 label = label.substring(1, label.length() - 1);
1481 final MenuItem item = new MenuItem(label);
1482 item.addActionListener(new java.awt.event.ActionListener()
1485 public void actionPerformed(ActionEvent e)
1487 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1488 types, forSequences, allTypes, actionIsShow);
1492 showOrHideMenu.add(item);