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.Cache;
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.SequenceAnnotationReport;
39 import jalview.schemes.Blosum62ColourScheme;
40 import jalview.schemes.BuriedColourScheme;
41 import jalview.schemes.ClustalxColourScheme;
42 import jalview.schemes.HelixColourScheme;
43 import jalview.schemes.HydrophobicColourScheme;
44 import jalview.schemes.NucleotideColourScheme;
45 import jalview.schemes.PIDColourScheme;
46 import jalview.schemes.StrandColourScheme;
47 import jalview.schemes.TaylorColourScheme;
48 import jalview.schemes.TurnColourScheme;
49 import jalview.schemes.ZappoColourScheme;
50 import jalview.util.MessageManager;
51 import jalview.util.UrlLink;
53 import java.awt.CheckboxMenuItem;
54 import java.awt.Frame;
56 import java.awt.MenuItem;
57 import java.awt.event.ActionEvent;
58 import java.awt.event.ActionListener;
59 import java.awt.event.ItemEvent;
60 import java.awt.event.ItemListener;
61 import java.util.Arrays;
62 import java.util.Collection;
63 import java.util.Collections;
64 import java.util.LinkedHashMap;
65 import java.util.List;
67 import java.util.TreeMap;
68 import java.util.Vector;
70 public class APopupMenu extends java.awt.PopupMenu implements
71 ActionListener, ItemListener
73 Menu groupMenu = new Menu();
75 MenuItem editGroupName = new MenuItem();
77 protected MenuItem clustalColour = new MenuItem();
79 protected MenuItem zappoColour = new MenuItem();
81 protected MenuItem taylorColour = new MenuItem();
83 protected MenuItem hydrophobicityColour = new MenuItem();
85 protected MenuItem helixColour = new MenuItem();
87 protected MenuItem strandColour = new MenuItem();
89 protected MenuItem turnColour = new MenuItem();
91 protected MenuItem buriedColour = new MenuItem();
93 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
95 protected MenuItem userDefinedColour = new MenuItem();
97 protected MenuItem PIDColour = new MenuItem();
99 protected MenuItem BLOSUM62Colour = new MenuItem();
101 MenuItem noColourmenuItem = new MenuItem();
103 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
105 final AlignmentPanel ap;
107 MenuItem unGroupMenuItem = new MenuItem();
109 MenuItem createGroupMenuItem = new MenuItem();
111 MenuItem nucleotideMenuItem = new MenuItem();
113 Menu colourMenu = new Menu();
115 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
117 CheckboxMenuItem showText = new CheckboxMenuItem();
119 CheckboxMenuItem showColourText = new CheckboxMenuItem();
121 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
123 Menu seqShowAnnotationsMenu = new Menu(
124 MessageManager.getString("label.show_annotations"));
126 Menu seqHideAnnotationsMenu = new Menu(
127 MessageManager.getString("label.hide_annotations"));
129 MenuItem seqAddReferenceAnnotations = new MenuItem(
130 MessageManager.getString("label.add_reference_annotations"));
132 Menu groupShowAnnotationsMenu = new Menu(
133 MessageManager.getString("label.show_annotations"));
135 Menu groupHideAnnotationsMenu = new Menu(
136 MessageManager.getString("label.hide_annotations"));
138 MenuItem groupAddReferenceAnnotations = new MenuItem(
139 MessageManager.getString("label.add_reference_annotations"));
141 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
143 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
145 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
147 MenuItem toUpper = new MenuItem(
148 MessageManager.getString("label.to_upper_case"));
150 MenuItem toLower = new MenuItem(
151 MessageManager.getString("label.to_lower_case"));
153 MenuItem toggleCase = new MenuItem(
154 MessageManager.getString("label.toggle_case"));
156 Menu outputmenu = new Menu();
158 Menu seqMenu = new Menu();
160 MenuItem pdb = new MenuItem();
162 MenuItem hideSeqs = new MenuItem();
164 MenuItem repGroup = new MenuItem();
166 MenuItem sequenceName = new MenuItem(
167 MessageManager.getString("label.edit_name_description"));
169 MenuItem sequenceFeature = new MenuItem(
170 MessageManager.getString("label.create_sequence_feature"));
172 MenuItem editSequence = new MenuItem(
173 MessageManager.getString("label.edit_sequence"));
175 MenuItem sequenceDetails = new MenuItem(
176 MessageManager.getString("label.sequence_details"));
178 MenuItem selSeqDetails = new MenuItem(
179 MessageManager.getString("label.sequence_details"));
181 MenuItem makeReferenceSeq = new MenuItem();
185 MenuItem revealAll = new MenuItem();
187 MenuItem revealSeq = new MenuItem();
190 * index of sequence to be revealed
192 int revealSeq_index = -1;
194 Menu menu1 = new Menu();
196 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
197 Vector<String> links)
199 // /////////////////////////////////////////////////////////
200 // If this is activated from the sequence panel, the user may want to
201 // edit or annotate a particular residue. Therefore display the residue menu
203 // If from the IDPanel, we must display the sequence menu
204 // ////////////////////////////////////////////////////////
212 } catch (Exception e)
217 for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
219 MenuItem item = new MenuItem(
220 jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
222 item.addActionListener(this);
223 outputmenu.add(item);
226 buildAnnotationSubmenus();
228 SequenceGroup sg = ap.av.getSelectionGroup();
229 if (sg != null && sg.getSize() > 0)
231 editGroupName.setLabel(MessageManager.formatMessage(
232 "label.name_param", new Object[] { sg.getName() }));
233 showText.setState(sg.getDisplayText());
234 showColourText.setState(sg.getColourText());
235 showBoxes.setState(sg.getDisplayBoxes());
236 displayNonconserved.setState(sg.getShowNonconserved());
237 if (!ap.av.getAlignment().getGroups().contains(sg))
239 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
240 groupMenu.remove(unGroupMenuItem);
244 menu1.setLabel(MessageManager.getString("action.edit_group"));
245 groupMenu.remove(createGroupMenuItem);
255 if (links != null && links.size() > 0)
257 addFeatureLinks(seq, links);
260 // TODO: add group link menu entry here
263 seqMenu.setLabel(seq.getName());
264 if (seq == ap.av.getAlignment().getSeqrep())
266 makeReferenceSeq.setLabel(MessageManager
267 .getString("action.unmark_as_reference"));// Unmark
272 makeReferenceSeq.setLabel(MessageManager
273 .getString("action.set_as_reference")); // );
275 repGroup.setLabel(MessageManager.formatMessage(
276 "label.represent_group_with", new Object[] { seq.getName() }));
283 if (!ap.av.hasHiddenRows())
290 final int index = ap.av.getAlignment().findIndex(seq);
292 if (ap.av.adjustForHiddenSeqs(index)
293 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
295 revealSeq_index = index;
305 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
310 void addFeatureLinks(final SequenceI seq, List<String> links)
312 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
313 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
315 for (String link : links)
317 UrlLink urlLink = null;
320 urlLink = new UrlLink(link);
321 } catch (Exception foo)
323 Cache.log.error("Exception for URLLink '" + link + "'", foo);
327 if (!urlLink.isValid())
329 Cache.log.error(urlLink.getInvalidMessage());
333 urlLink.createLinksFromSeq(seq, linkset);
336 addshowLinks(linkMenu, linkset.values());
338 if (linkMenu.getItemCount() > 0)
342 seqMenu.add(linkMenu);
351 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
353 for (List<String> linkstrset : linkset)
355 // split linkstr into label and url
356 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
361 * Build menus for annotation types that may be shown or hidden, and for
362 * 'reference annotations' that may be added to the alignment.
364 private void buildAnnotationSubmenus()
367 * First for the currently selected sequence (if there is one):
369 final List<SequenceI> selectedSequence = (seq == null ? Collections
370 .<SequenceI> emptyList() : Arrays.asList(seq));
371 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
372 seqHideAnnotationsMenu, selectedSequence);
373 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
377 * and repeat for the current selection group (if there is one):
379 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
380 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
382 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
383 groupHideAnnotationsMenu, selectedGroup);
384 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
389 * Determine whether or not to enable 'add reference annotations' menu item.
390 * It is enable if there are any annotations, on any of the selected
391 * sequences, which are not yet on the alignment (visible or not).
394 * @param forSequences
396 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
397 List<SequenceI> forSequences)
399 menuItem.setEnabled(false);
402 * Temporary store to hold distinct calcId / type pairs for the tooltip.
403 * Using TreeMap means calcIds are shown in alphabetical order.
405 Map<String, String> tipEntries = new TreeMap<String, String>();
406 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
407 AlignmentI al = this.ap.av.getAlignment();
408 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
409 tipEntries, candidates, al);
410 if (!candidates.isEmpty())
412 StringBuilder tooltip = new StringBuilder(64);
413 tooltip.append(MessageManager.getString("label.add_annotations_for"));
416 * Found annotations that could be added. Enable the menu item, and
417 * configure its action.
419 menuItem.setEnabled(true);
421 menuItem.addActionListener(new ActionListener()
424 public void actionPerformed(ActionEvent e)
426 addReferenceAnnotations_actionPerformed(candidates);
433 * Add annotations to the sequences and to the alignment.
436 * a map whose keys are sequences on the alignment, and values a list
437 * of annotations to add to each sequence
439 protected void addReferenceAnnotations_actionPerformed(
440 Map<SequenceI, List<AlignmentAnnotation>> candidates)
442 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
443 final AlignmentI alignment = this.ap.getAlignment();
444 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
450 * add a show URL menu item to the given linkMenu
454 * - menu label string
458 private void addshowLink(Menu linkMenu, final String target,
461 addshowLink(linkMenu, target, target, url);
465 * add a show URL menu item to the given linkMenu
469 * - URL target window
471 * - menu label string
475 private void addshowLink(Menu linkMenu, final String target,
476 final String label, final String url)
478 MenuItem item = new MenuItem(label);
479 item.addActionListener(new java.awt.event.ActionListener()
482 public void actionPerformed(ActionEvent e)
484 ap.alignFrame.showURL(url, target);
491 public void itemStateChanged(ItemEvent evt)
493 if (evt.getSource() == abovePIDColour)
495 abovePIDColour_itemStateChanged();
497 else if (evt.getSource() == showColourText)
499 showColourText_itemStateChanged();
501 else if (evt.getSource() == showText)
503 showText_itemStateChanged();
505 else if (evt.getSource() == showBoxes)
507 showBoxes_itemStateChanged();
509 else if (evt.getSource() == displayNonconserved)
511 this.showNonconserved_itemStateChanged();
516 public void actionPerformed(ActionEvent evt)
518 Object source = evt.getSource();
519 if (source == clustalColour)
521 clustalColour_actionPerformed();
523 else if (source == zappoColour)
525 zappoColour_actionPerformed();
527 else if (source == taylorColour)
529 taylorColour_actionPerformed();
531 else if (source == hydrophobicityColour)
533 hydrophobicityColour_actionPerformed();
535 else if (source == helixColour)
537 helixColour_actionPerformed();
539 else if (source == strandColour)
541 strandColour_actionPerformed();
543 else if (source == turnColour)
545 turnColour_actionPerformed();
547 else if (source == buriedColour)
549 buriedColour_actionPerformed();
551 else if (source == nucleotideMenuItem)
553 nucleotideMenuItem_actionPerformed();
556 else if (source == userDefinedColour)
558 userDefinedColour_actionPerformed();
560 else if (source == PIDColour)
562 PIDColour_actionPerformed();
564 else if (source == BLOSUM62Colour)
566 BLOSUM62Colour_actionPerformed();
568 else if (source == noColourmenuItem)
570 noColourmenuItem_actionPerformed();
572 else if (source == conservationMenuItem)
574 conservationMenuItem_itemStateChanged();
576 else if (source == unGroupMenuItem)
578 unGroupMenuItem_actionPerformed();
581 else if (source == createGroupMenuItem)
583 createGroupMenuItem_actionPerformed();
586 else if (source == sequenceName)
590 else if (source == makeReferenceSeq)
592 makeReferenceSeq_actionPerformed();
594 else if (source == sequenceDetails)
596 showSequenceDetails();
598 else if (source == selSeqDetails)
600 showSequenceSelectionDetails();
602 else if (source == pdb)
606 else if (source == hideSeqs)
608 hideSequences(false);
610 else if (source == repGroup)
614 else if (source == revealSeq)
616 ap.av.showSequence(revealSeq_index);
618 else if (source == revealAll)
620 ap.av.showAllHiddenSeqs();
623 else if (source == editGroupName)
625 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
626 getGroup().getDescription(), " Group Name",
627 "Group Description", ap.alignFrame,
628 "Edit Group Name / Description", 500, 100, true);
632 getGroup().setName(dialog.getName().replace(' ', '_'));
633 getGroup().setDescription(dialog.getDescription());
637 else if (source == copy)
639 ap.alignFrame.copy_actionPerformed();
641 else if (source == cut)
643 ap.alignFrame.cut_actionPerformed();
645 else if (source == editSequence)
647 SequenceGroup sg = ap.av.getSelectionGroup();
653 seq = sg.getSequenceAt(0);
656 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
657 sg.getStartRes(), sg.getEndRes() + 1), null,
658 "Edit Sequence ", null,
660 ap.alignFrame, "Edit Sequence", 500, 100, true);
664 EditCommand editCommand = new EditCommand(
665 MessageManager.getString("label.edit_sequences"),
666 Action.REPLACE, dialog.getName().replace(' ',
667 ap.av.getGapCharacter()),
668 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
669 sg.getStartRes(), sg.getEndRes() + 1,
670 ap.av.getAlignment());
672 ap.alignFrame.addHistoryItem(editCommand);
674 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
679 else if (source == toUpper || source == toLower || source == toggleCase)
681 SequenceGroup sg = ap.av.getSelectionGroup();
684 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
685 sg.getStartRes(), sg.getEndRes() + 1);
690 if (source == toggleCase)
692 description = "Toggle Case";
693 caseChange = ChangeCaseCommand.TOGGLE_CASE;
695 else if (source == toUpper)
697 description = "To Upper Case";
698 caseChange = ChangeCaseCommand.TO_UPPER;
702 description = "To Lower Case";
703 caseChange = ChangeCaseCommand.TO_LOWER;
706 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
707 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
708 startEnd, caseChange);
710 ap.alignFrame.addHistoryItem(caseCommand);
712 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
717 else if (source == sequenceFeature)
719 SequenceGroup sg = ap.av.getSelectionGroup();
725 int rsize = 0, gSize = sg.getSize();
726 SequenceI[] rseqs, seqs = new SequenceI[gSize];
727 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
729 for (int i = 0; i < gSize; i++)
731 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
732 int end = sg.findEndRes(sg.getSequenceAt(i));
735 seqs[rsize] = sg.getSequenceAt(i);
736 features[rsize] = new SequenceFeature(null, null, null, start,
741 rseqs = new SequenceI[rsize];
742 tfeatures = new SequenceFeature[rsize];
743 System.arraycopy(seqs, 0, rseqs, 0, rsize);
744 System.arraycopy(features, 0, tfeatures, 0, rsize);
745 features = tfeatures;
748 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
751 ap.alignFrame.sequenceFeatures.setState(true);
752 ap.av.setShowSequenceFeatures(true);
754 ap.highlightSearchResults(null);
764 void outputText(ActionEvent e)
766 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
768 Frame frame = new Frame();
770 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
771 "label.selection_output_command",
772 new Object[] { e.getActionCommand() }), 600, 500);
773 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
774 // now returns a full copy of sequence data
775 // TODO consider using getSequenceSelection instead here
777 cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
778 e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true));
782 protected void showSequenceSelectionDetails()
784 createSequenceDetailsReport(ap.av.getSequenceSelection());
787 protected void showSequenceDetails()
789 createSequenceDetailsReport(new SequenceI[] { seq });
792 public void createSequenceDetailsReport(SequenceI[] sequences)
795 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
797 StringBuffer contents = new StringBuffer();
798 for (SequenceI seq : sequences)
800 contents.append(MessageManager.formatMessage(
801 "label.annotation_for_displayid",
802 new Object[] { seq.getDisplayId(true) }));
803 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
809 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
810 .getMinMax() : null);
811 contents.append("</p>");
813 Frame frame = new Frame();
815 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
816 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
817 : "Selection"), 600, 500);
818 cap.setText(MessageManager.formatMessage("label.html_content",
819 new Object[] { contents.toString() }));
824 EditNameDialog dialog = new EditNameDialog(seq.getName(),
825 seq.getDescription(), " Sequence Name",
826 "Sequence Description", ap.alignFrame,
827 "Edit Sequence Name / Description", 500, 100, true);
831 seq.setName(dialog.getName());
832 seq.setDescription(dialog.getDescription());
833 ap.paintAlignment(false);
839 if (seq.getAllPDBEntries() != null)
841 PDBEntry entry = seq.getAllPDBEntries().firstElement();
843 if (ap.av.applet.jmolAvailable)
845 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
846 null, ap, AppletFormatAdapter.URL);
850 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
851 ap, AppletFormatAdapter.URL);
857 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
858 cap.setText(MessageManager.getString("label.paste_pdb_file"));
859 cap.setPDBImport(seq);
860 Frame frame = new Frame();
862 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
863 "label.paste_pdb_file_for_sequence",
864 new Object[] { seq.getName() }), 400, 300);
868 private void jbInit() throws Exception
870 groupMenu.setLabel(MessageManager.getString("label.selection"));
871 sequenceFeature.addActionListener(this);
873 editGroupName.addActionListener(this);
874 unGroupMenuItem.setLabel(MessageManager
875 .getString("action.remove_group"));
876 unGroupMenuItem.addActionListener(this);
878 createGroupMenuItem.setLabel(MessageManager
879 .getString("action.create_group"));
880 createGroupMenuItem.addActionListener(this);
882 nucleotideMenuItem.setLabel(MessageManager
883 .getString("label.nucleotide"));
884 nucleotideMenuItem.addActionListener(this);
885 conservationMenuItem.addItemListener(this);
886 abovePIDColour.addItemListener(this);
887 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
888 showBoxes.setLabel(MessageManager.getString("action.boxes"));
889 showBoxes.setState(true);
890 showBoxes.addItemListener(this);
891 sequenceName.addActionListener(this);
892 sequenceDetails.addActionListener(this);
893 selSeqDetails.addActionListener(this);
894 displayNonconserved.setLabel(MessageManager
895 .getString("label.show_non_conversed"));
896 displayNonconserved.setState(false);
897 displayNonconserved.addItemListener(this);
898 showText.setLabel(MessageManager.getString("action.text"));
899 showText.addItemListener(this);
900 showColourText.setLabel(MessageManager.getString("label.colour_text"));
901 showColourText.addItemListener(this);
902 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
903 seqMenu.setLabel(MessageManager.getString("label.sequence"));
904 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
905 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
906 repGroup.setLabel(MessageManager.formatMessage(
907 "label.represent_group_with", new Object[] { "" }));
908 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
909 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
910 menu1.setLabel(MessageManager.getString("label.group:"));
916 // groupMenu.add(selSeqDetails);
917 groupMenu.add(groupShowAnnotationsMenu);
918 groupMenu.add(groupHideAnnotationsMenu);
919 groupMenu.add(groupAddReferenceAnnotations);
920 groupMenu.add(editMenu);
921 groupMenu.add(outputmenu);
922 groupMenu.add(sequenceFeature);
923 groupMenu.add(createGroupMenuItem);
924 groupMenu.add(unGroupMenuItem);
925 groupMenu.add(menu1);
927 colourMenu.add(noColourmenuItem);
928 colourMenu.add(clustalColour);
929 colourMenu.add(BLOSUM62Colour);
930 colourMenu.add(PIDColour);
931 colourMenu.add(zappoColour);
932 colourMenu.add(taylorColour);
933 colourMenu.add(hydrophobicityColour);
934 colourMenu.add(helixColour);
935 colourMenu.add(strandColour);
936 colourMenu.add(turnColour);
937 colourMenu.add(buriedColour);
938 colourMenu.add(nucleotideMenuItem);
939 colourMenu.add(userDefinedColour);
940 colourMenu.addSeparator();
941 colourMenu.add(abovePIDColour);
942 colourMenu.add(conservationMenuItem);
944 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
945 noColourmenuItem.addActionListener(this);
947 clustalColour.setLabel(MessageManager
948 .getString("label.clustalx_colours"));
949 clustalColour.addActionListener(this);
950 zappoColour.setLabel(MessageManager.getString("label.zappo"));
951 zappoColour.addActionListener(this);
952 taylorColour.setLabel(MessageManager.getString("label.taylor"));
953 taylorColour.addActionListener(this);
954 hydrophobicityColour.setLabel(MessageManager
955 .getString("label.hydrophobicity"));
956 hydrophobicityColour.addActionListener(this);
958 .setLabel(MessageManager.getString("label.helix_propensity"));
959 helixColour.addActionListener(this);
960 strandColour.setLabel(MessageManager
961 .getString("label.strand_propensity"));
962 strandColour.addActionListener(this);
963 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
964 turnColour.addActionListener(this);
965 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
966 buriedColour.addActionListener(this);
967 abovePIDColour.setLabel(MessageManager
968 .getString("label.above_identity_percentage"));
970 userDefinedColour.setLabel(MessageManager
971 .getString("action.user_defined"));
972 userDefinedColour.addActionListener(this);
973 PIDColour.setLabel(MessageManager
974 .getString("label.percentage_identity"));
975 PIDColour.addActionListener(this);
976 BLOSUM62Colour.setLabel("BLOSUM62");
977 BLOSUM62Colour.addActionListener(this);
978 conservationMenuItem.setLabel(MessageManager
979 .getString("label.conservation"));
982 copy.addActionListener(this);
984 cut.addActionListener(this);
986 editMenu.add(editSequence);
987 editSequence.addActionListener(this);
989 editMenu.add(toUpper);
990 toUpper.addActionListener(this);
991 editMenu.add(toLower);
992 toLower.addActionListener(this);
993 editMenu.add(toggleCase);
994 seqMenu.add(seqShowAnnotationsMenu);
995 seqMenu.add(seqHideAnnotationsMenu);
996 seqMenu.add(seqAddReferenceAnnotations);
997 seqMenu.add(sequenceName);
998 seqMenu.add(makeReferenceSeq);
999 // seqMenu.add(sequenceDetails);
1001 if (!ap.av.applet.useXtrnalSviewer)
1005 seqMenu.add(repGroup);
1006 menu1.add(editGroupName);
1007 menu1.add(colourMenu);
1008 menu1.add(showBoxes);
1009 menu1.add(showText);
1010 menu1.add(showColourText);
1011 menu1.add(displayNonconserved);
1012 toggleCase.addActionListener(this);
1013 pdb.addActionListener(this);
1014 hideSeqs.addActionListener(this);
1015 repGroup.addActionListener(this);
1016 revealAll.addActionListener(this);
1017 revealSeq.addActionListener(this);
1018 makeReferenceSeq.addActionListener(this);
1023 ap.paintAlignment(true);
1026 protected void clustalColour_actionPerformed()
1028 SequenceGroup sg = getGroup();
1029 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1033 protected void zappoColour_actionPerformed()
1035 getGroup().cs = new ZappoColourScheme();
1039 protected void taylorColour_actionPerformed()
1041 getGroup().cs = new TaylorColourScheme();
1045 protected void hydrophobicityColour_actionPerformed()
1047 getGroup().cs = new HydrophobicColourScheme();
1051 protected void helixColour_actionPerformed()
1053 getGroup().cs = new HelixColourScheme();
1057 protected void strandColour_actionPerformed()
1059 getGroup().cs = new StrandColourScheme();
1063 protected void turnColour_actionPerformed()
1065 getGroup().cs = new TurnColourScheme();
1069 protected void buriedColour_actionPerformed()
1071 getGroup().cs = new BuriedColourScheme();
1075 public void nucleotideMenuItem_actionPerformed()
1077 getGroup().cs = new NucleotideColourScheme();
1081 protected void abovePIDColour_itemStateChanged()
1083 SequenceGroup sg = getGroup();
1089 if (abovePIDColour.getState())
1091 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1092 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1093 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1096 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1098 SliderPanel.showPIDSlider();
1102 // remove PIDColouring
1104 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1111 protected void userDefinedColour_actionPerformed()
1113 new UserDefinedColours(ap, getGroup());
1116 protected void PIDColour_actionPerformed()
1118 SequenceGroup sg = getGroup();
1119 sg.cs = new PIDColourScheme();
1120 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1121 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1125 protected void BLOSUM62Colour_actionPerformed()
1127 SequenceGroup sg = getGroup();
1129 sg.cs = new Blosum62ColourScheme();
1131 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1132 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1137 protected void noColourmenuItem_actionPerformed()
1139 getGroup().cs = null;
1143 protected void conservationMenuItem_itemStateChanged()
1145 SequenceGroup sg = getGroup();
1151 if (conservationMenuItem.getState())
1154 sg.cs.setConservation(Conservation.calculateConservation("Group", 3,
1155 sg.getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1156 .getAlignment().getWidth(), false, ap.av
1157 .getConsPercGaps(), false));
1158 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1159 SliderPanel.showConservationSlider();
1162 // remove ConservationColouring
1164 sg.cs.setConservation(null);
1170 SequenceGroup getGroup()
1172 SequenceGroup sg = ap.av.getSelectionGroup();
1174 // this method won't add a new group if it already exists
1177 ap.av.getAlignment().addGroup(sg);
1183 void unGroupMenuItem_actionPerformed()
1185 SequenceGroup sg = ap.av.getSelectionGroup();
1186 ap.av.getAlignment().deleteGroup(sg);
1187 ap.av.setSelectionGroup(null);
1188 ap.paintAlignment(true);
1191 void createGroupMenuItem_actionPerformed()
1193 getGroup(); // implicitly create group
1197 public void showColourText_itemStateChanged()
1199 getGroup().setColourText(showColourText.getState());
1203 public void showText_itemStateChanged()
1205 getGroup().setDisplayText(showText.getState());
1209 public void makeReferenceSeq_actionPerformed()
1211 if (!ap.av.getAlignment().hasSeqrep())
1213 // initialise the display flags so the user sees something happen
1214 ap.av.setDisplayReferenceSeq(true);
1215 ap.av.setColourByReferenceSeq(true);
1216 ap.av.getAlignment().setSeqrep(seq);
1220 if (ap.av.getAlignment().getSeqrep() == seq)
1222 ap.av.getAlignment().setSeqrep(null);
1226 ap.av.getAlignment().setSeqrep(seq);
1232 public void showNonconserved_itemStateChanged()
1234 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1238 public void showBoxes_itemStateChanged()
1240 getGroup().setDisplayBoxes(showBoxes.getState());
1244 void hideSequences(boolean representGroup)
1246 ap.av.hideSequences(seq, representGroup);
1250 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1251 * "All" is added first, followed by a separator. Then add any annotation
1252 * types associated with the current selection. Separate menus are built for
1253 * the selected sequence group (if any), and the selected sequence.
1255 * Some annotation rows are always rendered together - these can be identified
1256 * by a common graphGroup property > -1. Only one of each group will be marked
1257 * as visible (to avoid duplication of the display). For such groups we add a
1258 * composite type name, e.g.
1260 * IUPredWS (Long), IUPredWS (Short)
1264 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1265 List<SequenceI> forSequences)
1267 showMenu.removeAll();
1268 hideMenu.removeAll();
1270 final List<String> all = Arrays.asList(new String[] { MessageManager
1271 .getString("label.all") });
1272 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1273 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1275 showMenu.addSeparator();
1276 hideMenu.addSeparator();
1278 final AlignmentAnnotation[] annotations = ap.getAlignment()
1279 .getAlignmentAnnotation();
1282 * Find shown/hidden annotations types, distinguished by source (calcId),
1283 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1284 * the insertion order, which is the order of the annotations on the
1287 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1288 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1289 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1290 AlignmentAnnotationUtils.asList(annotations), forSequences);
1292 for (String calcId : hiddenTypes.keySet())
1294 for (List<String> type : hiddenTypes.get(calcId))
1296 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1300 // grey out 'show annotations' if none are hidden
1301 showMenu.setEnabled(!hiddenTypes.isEmpty());
1303 for (String calcId : shownTypes.keySet())
1305 for (List<String> type : shownTypes.get(calcId))
1307 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1311 // grey out 'hide annotations' if none are shown
1312 hideMenu.setEnabled(!shownTypes.isEmpty());
1316 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1319 * @param showOrHideMenu
1320 * the menu to add to
1321 * @param forSequences
1322 * the sequences whose annotations may be shown or hidden
1327 * if true this is a special label meaning 'All'
1328 * @param actionIsShow
1329 * if true, the select menu item action is to show the annotation
1332 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1333 final List<SequenceI> forSequences, String calcId,
1334 final List<String> types, final boolean allTypes,
1335 final boolean actionIsShow)
1337 String label = types.toString(); // [a, b, c]
1338 label = label.substring(1, label.length() - 1);
1339 final MenuItem item = new MenuItem(label);
1340 item.addActionListener(new java.awt.event.ActionListener()
1343 public void actionPerformed(ActionEvent e)
1345 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1346 types, forSequences, allTypes, actionIsShow);
1350 showOrHideMenu.add(item);