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 // disable link menu if there are no valid entries
339 if (linkMenu.getItemCount() > 0)
341 linkMenu.setEnabled(true);
345 linkMenu.setEnabled(false);
350 seqMenu.add(linkMenu);
359 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
361 for (List<String> linkstrset : linkset)
363 // split linkstr into label and url
364 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
369 * Build menus for annotation types that may be shown or hidden, and for
370 * 'reference annotations' that may be added to the alignment.
372 private void buildAnnotationSubmenus()
375 * First for the currently selected sequence (if there is one):
377 final List<SequenceI> selectedSequence = (seq == null ? Collections
378 .<SequenceI> emptyList() : Arrays.asList(seq));
379 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
380 seqHideAnnotationsMenu, selectedSequence);
381 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
385 * and repeat for the current selection group (if there is one):
387 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
388 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
390 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
391 groupHideAnnotationsMenu, selectedGroup);
392 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
397 * Determine whether or not to enable 'add reference annotations' menu item.
398 * It is enable if there are any annotations, on any of the selected
399 * sequences, which are not yet on the alignment (visible or not).
402 * @param forSequences
404 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
405 List<SequenceI> forSequences)
407 menuItem.setEnabled(false);
410 * Temporary store to hold distinct calcId / type pairs for the tooltip.
411 * Using TreeMap means calcIds are shown in alphabetical order.
413 Map<String, String> tipEntries = new TreeMap<String, String>();
414 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
415 AlignmentI al = this.ap.av.getAlignment();
416 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
417 tipEntries, candidates, al);
418 if (!candidates.isEmpty())
420 StringBuilder tooltip = new StringBuilder(64);
421 tooltip.append(MessageManager.getString("label.add_annotations_for"));
424 * Found annotations that could be added. Enable the menu item, and
425 * configure its action.
427 menuItem.setEnabled(true);
429 menuItem.addActionListener(new ActionListener()
432 public void actionPerformed(ActionEvent e)
434 addReferenceAnnotations_actionPerformed(candidates);
441 * Add annotations to the sequences and to the alignment.
444 * a map whose keys are sequences on the alignment, and values a list
445 * of annotations to add to each sequence
447 protected void addReferenceAnnotations_actionPerformed(
448 Map<SequenceI, List<AlignmentAnnotation>> candidates)
450 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
451 final AlignmentI alignment = this.ap.getAlignment();
452 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
458 * add a show URL menu item to the given linkMenu
462 * - menu label string
466 private void addshowLink(Menu linkMenu, final String target,
469 addshowLink(linkMenu, target, target, url);
473 * add a show URL menu item to the given linkMenu
477 * - URL target window
479 * - menu label string
483 private void addshowLink(Menu linkMenu, final String target,
484 final String label, final String url)
486 MenuItem item = new MenuItem(label);
487 item.addActionListener(new java.awt.event.ActionListener()
490 public void actionPerformed(ActionEvent e)
492 ap.alignFrame.showURL(url, target);
499 public void itemStateChanged(ItemEvent evt)
501 if (evt.getSource() == abovePIDColour)
503 abovePIDColour_itemStateChanged();
505 else if (evt.getSource() == showColourText)
507 showColourText_itemStateChanged();
509 else if (evt.getSource() == showText)
511 showText_itemStateChanged();
513 else if (evt.getSource() == showBoxes)
515 showBoxes_itemStateChanged();
517 else if (evt.getSource() == displayNonconserved)
519 this.showNonconserved_itemStateChanged();
524 public void actionPerformed(ActionEvent evt)
526 Object source = evt.getSource();
527 if (source == clustalColour)
529 clustalColour_actionPerformed();
531 else if (source == zappoColour)
533 zappoColour_actionPerformed();
535 else if (source == taylorColour)
537 taylorColour_actionPerformed();
539 else if (source == hydrophobicityColour)
541 hydrophobicityColour_actionPerformed();
543 else if (source == helixColour)
545 helixColour_actionPerformed();
547 else if (source == strandColour)
549 strandColour_actionPerformed();
551 else if (source == turnColour)
553 turnColour_actionPerformed();
555 else if (source == buriedColour)
557 buriedColour_actionPerformed();
559 else if (source == nucleotideMenuItem)
561 nucleotideMenuItem_actionPerformed();
564 else if (source == userDefinedColour)
566 userDefinedColour_actionPerformed();
568 else if (source == PIDColour)
570 PIDColour_actionPerformed();
572 else if (source == BLOSUM62Colour)
574 BLOSUM62Colour_actionPerformed();
576 else if (source == noColourmenuItem)
578 noColourmenuItem_actionPerformed();
580 else if (source == conservationMenuItem)
582 conservationMenuItem_itemStateChanged();
584 else if (source == unGroupMenuItem)
586 unGroupMenuItem_actionPerformed();
589 else if (source == createGroupMenuItem)
591 createGroupMenuItem_actionPerformed();
594 else if (source == sequenceName)
598 else if (source == makeReferenceSeq)
600 makeReferenceSeq_actionPerformed();
602 else if (source == sequenceDetails)
604 showSequenceDetails();
606 else if (source == selSeqDetails)
608 showSequenceSelectionDetails();
610 else if (source == pdb)
614 else if (source == hideSeqs)
616 hideSequences(false);
618 else if (source == repGroup)
622 else if (source == revealSeq)
624 ap.av.showSequence(revealSeq_index);
626 else if (source == revealAll)
628 ap.av.showAllHiddenSeqs();
631 else if (source == editGroupName)
633 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
634 getGroup().getDescription(), " Group Name",
635 "Group Description", ap.alignFrame,
636 "Edit Group Name / Description", 500, 100, true);
640 getGroup().setName(dialog.getName().replace(' ', '_'));
641 getGroup().setDescription(dialog.getDescription());
645 else if (source == copy)
647 ap.alignFrame.copy_actionPerformed();
649 else if (source == cut)
651 ap.alignFrame.cut_actionPerformed();
653 else if (source == editSequence)
655 SequenceGroup sg = ap.av.getSelectionGroup();
661 seq = sg.getSequenceAt(0);
664 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
665 sg.getStartRes(), sg.getEndRes() + 1), null,
666 "Edit Sequence ", null,
668 ap.alignFrame, "Edit Sequence", 500, 100, true);
672 EditCommand editCommand = new EditCommand(
673 MessageManager.getString("label.edit_sequences"),
674 Action.REPLACE, dialog.getName().replace(' ',
675 ap.av.getGapCharacter()),
676 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
677 sg.getStartRes(), sg.getEndRes() + 1,
678 ap.av.getAlignment());
680 ap.alignFrame.addHistoryItem(editCommand);
682 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
687 else if (source == toUpper || source == toLower || source == toggleCase)
689 SequenceGroup sg = ap.av.getSelectionGroup();
692 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
693 sg.getStartRes(), sg.getEndRes() + 1);
698 if (source == toggleCase)
700 description = "Toggle Case";
701 caseChange = ChangeCaseCommand.TOGGLE_CASE;
703 else if (source == toUpper)
705 description = "To Upper Case";
706 caseChange = ChangeCaseCommand.TO_UPPER;
710 description = "To Lower Case";
711 caseChange = ChangeCaseCommand.TO_LOWER;
714 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
715 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
716 startEnd, caseChange);
718 ap.alignFrame.addHistoryItem(caseCommand);
720 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
725 else if (source == sequenceFeature)
727 SequenceGroup sg = ap.av.getSelectionGroup();
733 int rsize = 0, gSize = sg.getSize();
734 SequenceI[] rseqs, seqs = new SequenceI[gSize];
735 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
737 for (int i = 0; i < gSize; i++)
739 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
740 int end = sg.findEndRes(sg.getSequenceAt(i));
743 seqs[rsize] = sg.getSequenceAt(i);
744 features[rsize] = new SequenceFeature(null, null, null, start,
749 rseqs = new SequenceI[rsize];
750 tfeatures = new SequenceFeature[rsize];
751 System.arraycopy(seqs, 0, rseqs, 0, rsize);
752 System.arraycopy(features, 0, tfeatures, 0, rsize);
753 features = tfeatures;
756 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
759 ap.alignFrame.sequenceFeatures.setState(true);
760 ap.av.setShowSequenceFeatures(true);
762 ap.highlightSearchResults(null);
772 void outputText(ActionEvent e)
774 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
776 Frame frame = new Frame();
778 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
779 "label.selection_output_command",
780 new Object[] { e.getActionCommand() }), 600, 500);
781 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
782 // now returns a full copy of sequence data
783 // TODO consider using getSequenceSelection instead here
785 cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
786 e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true));
790 protected void showSequenceSelectionDetails()
792 createSequenceDetailsReport(ap.av.getSequenceSelection());
795 protected void showSequenceDetails()
797 createSequenceDetailsReport(new SequenceI[] { seq });
800 public void createSequenceDetailsReport(SequenceI[] sequences)
803 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
805 StringBuffer contents = new StringBuffer();
806 for (SequenceI seq : sequences)
808 contents.append(MessageManager.formatMessage(
809 "label.annotation_for_displayid",
810 new Object[] { seq.getDisplayId(true) }));
811 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
817 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
818 .getMinMax() : null);
819 contents.append("</p>");
821 Frame frame = new Frame();
823 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
824 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
825 : "Selection"), 600, 500);
826 cap.setText(MessageManager.formatMessage("label.html_content",
827 new Object[] { contents.toString() }));
832 EditNameDialog dialog = new EditNameDialog(seq.getName(),
833 seq.getDescription(), " Sequence Name",
834 "Sequence Description", ap.alignFrame,
835 "Edit Sequence Name / Description", 500, 100, true);
839 seq.setName(dialog.getName());
840 seq.setDescription(dialog.getDescription());
841 ap.paintAlignment(false);
847 if (seq.getAllPDBEntries() != null)
849 PDBEntry entry = seq.getAllPDBEntries().firstElement();
851 if (ap.av.applet.jmolAvailable)
853 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
854 null, ap, AppletFormatAdapter.URL);
858 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
859 ap, AppletFormatAdapter.URL);
865 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
866 cap.setText(MessageManager.getString("label.paste_pdb_file"));
867 cap.setPDBImport(seq);
868 Frame frame = new Frame();
870 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
871 "label.paste_pdb_file_for_sequence",
872 new Object[] { seq.getName() }), 400, 300);
876 private void jbInit() throws Exception
878 groupMenu.setLabel(MessageManager.getString("label.selection"));
879 sequenceFeature.addActionListener(this);
881 editGroupName.addActionListener(this);
882 unGroupMenuItem.setLabel(MessageManager
883 .getString("action.remove_group"));
884 unGroupMenuItem.addActionListener(this);
886 createGroupMenuItem.setLabel(MessageManager
887 .getString("action.create_group"));
888 createGroupMenuItem.addActionListener(this);
890 nucleotideMenuItem.setLabel(MessageManager
891 .getString("label.nucleotide"));
892 nucleotideMenuItem.addActionListener(this);
893 conservationMenuItem.addItemListener(this);
894 abovePIDColour.addItemListener(this);
895 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
896 showBoxes.setLabel(MessageManager.getString("action.boxes"));
897 showBoxes.setState(true);
898 showBoxes.addItemListener(this);
899 sequenceName.addActionListener(this);
900 sequenceDetails.addActionListener(this);
901 selSeqDetails.addActionListener(this);
902 displayNonconserved.setLabel(MessageManager
903 .getString("label.show_non_conversed"));
904 displayNonconserved.setState(false);
905 displayNonconserved.addItemListener(this);
906 showText.setLabel(MessageManager.getString("action.text"));
907 showText.addItemListener(this);
908 showColourText.setLabel(MessageManager.getString("label.colour_text"));
909 showColourText.addItemListener(this);
910 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
911 seqMenu.setLabel(MessageManager.getString("label.sequence"));
912 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
913 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
914 repGroup.setLabel(MessageManager.formatMessage(
915 "label.represent_group_with", new Object[] { "" }));
916 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
917 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
918 menu1.setLabel(MessageManager.getString("label.group:"));
924 // groupMenu.add(selSeqDetails);
925 groupMenu.add(groupShowAnnotationsMenu);
926 groupMenu.add(groupHideAnnotationsMenu);
927 groupMenu.add(groupAddReferenceAnnotations);
928 groupMenu.add(editMenu);
929 groupMenu.add(outputmenu);
930 groupMenu.add(sequenceFeature);
931 groupMenu.add(createGroupMenuItem);
932 groupMenu.add(unGroupMenuItem);
933 groupMenu.add(menu1);
935 colourMenu.add(noColourmenuItem);
936 colourMenu.add(clustalColour);
937 colourMenu.add(BLOSUM62Colour);
938 colourMenu.add(PIDColour);
939 colourMenu.add(zappoColour);
940 colourMenu.add(taylorColour);
941 colourMenu.add(hydrophobicityColour);
942 colourMenu.add(helixColour);
943 colourMenu.add(strandColour);
944 colourMenu.add(turnColour);
945 colourMenu.add(buriedColour);
946 colourMenu.add(nucleotideMenuItem);
947 colourMenu.add(userDefinedColour);
948 colourMenu.addSeparator();
949 colourMenu.add(abovePIDColour);
950 colourMenu.add(conservationMenuItem);
952 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
953 noColourmenuItem.addActionListener(this);
955 clustalColour.setLabel(MessageManager
956 .getString("label.clustalx_colours"));
957 clustalColour.addActionListener(this);
958 zappoColour.setLabel(MessageManager.getString("label.zappo"));
959 zappoColour.addActionListener(this);
960 taylorColour.setLabel(MessageManager.getString("label.taylor"));
961 taylorColour.addActionListener(this);
962 hydrophobicityColour.setLabel(MessageManager
963 .getString("label.hydrophobicity"));
964 hydrophobicityColour.addActionListener(this);
966 .setLabel(MessageManager.getString("label.helix_propensity"));
967 helixColour.addActionListener(this);
968 strandColour.setLabel(MessageManager
969 .getString("label.strand_propensity"));
970 strandColour.addActionListener(this);
971 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
972 turnColour.addActionListener(this);
973 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
974 buriedColour.addActionListener(this);
975 abovePIDColour.setLabel(MessageManager
976 .getString("label.above_identity_percentage"));
978 userDefinedColour.setLabel(MessageManager
979 .getString("action.user_defined"));
980 userDefinedColour.addActionListener(this);
981 PIDColour.setLabel(MessageManager
982 .getString("label.percentage_identity"));
983 PIDColour.addActionListener(this);
984 BLOSUM62Colour.setLabel("BLOSUM62");
985 BLOSUM62Colour.addActionListener(this);
986 conservationMenuItem.setLabel(MessageManager
987 .getString("label.conservation"));
990 copy.addActionListener(this);
992 cut.addActionListener(this);
994 editMenu.add(editSequence);
995 editSequence.addActionListener(this);
997 editMenu.add(toUpper);
998 toUpper.addActionListener(this);
999 editMenu.add(toLower);
1000 toLower.addActionListener(this);
1001 editMenu.add(toggleCase);
1002 seqMenu.add(seqShowAnnotationsMenu);
1003 seqMenu.add(seqHideAnnotationsMenu);
1004 seqMenu.add(seqAddReferenceAnnotations);
1005 seqMenu.add(sequenceName);
1006 seqMenu.add(makeReferenceSeq);
1007 // seqMenu.add(sequenceDetails);
1009 if (!ap.av.applet.useXtrnalSviewer)
1013 seqMenu.add(repGroup);
1014 menu1.add(editGroupName);
1015 menu1.add(colourMenu);
1016 menu1.add(showBoxes);
1017 menu1.add(showText);
1018 menu1.add(showColourText);
1019 menu1.add(displayNonconserved);
1020 toggleCase.addActionListener(this);
1021 pdb.addActionListener(this);
1022 hideSeqs.addActionListener(this);
1023 repGroup.addActionListener(this);
1024 revealAll.addActionListener(this);
1025 revealSeq.addActionListener(this);
1026 makeReferenceSeq.addActionListener(this);
1031 ap.paintAlignment(true);
1034 protected void clustalColour_actionPerformed()
1036 SequenceGroup sg = getGroup();
1037 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1041 protected void zappoColour_actionPerformed()
1043 getGroup().cs = new ZappoColourScheme();
1047 protected void taylorColour_actionPerformed()
1049 getGroup().cs = new TaylorColourScheme();
1053 protected void hydrophobicityColour_actionPerformed()
1055 getGroup().cs = new HydrophobicColourScheme();
1059 protected void helixColour_actionPerformed()
1061 getGroup().cs = new HelixColourScheme();
1065 protected void strandColour_actionPerformed()
1067 getGroup().cs = new StrandColourScheme();
1071 protected void turnColour_actionPerformed()
1073 getGroup().cs = new TurnColourScheme();
1077 protected void buriedColour_actionPerformed()
1079 getGroup().cs = new BuriedColourScheme();
1083 public void nucleotideMenuItem_actionPerformed()
1085 getGroup().cs = new NucleotideColourScheme();
1089 protected void abovePIDColour_itemStateChanged()
1091 SequenceGroup sg = getGroup();
1097 if (abovePIDColour.getState())
1099 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1100 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1101 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1104 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1106 SliderPanel.showPIDSlider();
1110 // remove PIDColouring
1112 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1119 protected void userDefinedColour_actionPerformed()
1121 new UserDefinedColours(ap, getGroup());
1124 protected void PIDColour_actionPerformed()
1126 SequenceGroup sg = getGroup();
1127 sg.cs = new PIDColourScheme();
1128 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1129 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1133 protected void BLOSUM62Colour_actionPerformed()
1135 SequenceGroup sg = getGroup();
1137 sg.cs = new Blosum62ColourScheme();
1139 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1140 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1145 protected void noColourmenuItem_actionPerformed()
1147 getGroup().cs = null;
1151 protected void conservationMenuItem_itemStateChanged()
1153 SequenceGroup sg = getGroup();
1159 if (conservationMenuItem.getState())
1161 sg.cs.setConservation(Conservation.calculateConservation("Group", sg
1162 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1163 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1165 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1166 SliderPanel.showConservationSlider();
1169 // remove ConservationColouring
1171 sg.cs.setConservation(null);
1177 SequenceGroup getGroup()
1179 SequenceGroup sg = ap.av.getSelectionGroup();
1181 // this method won't add a new group if it already exists
1184 ap.av.getAlignment().addGroup(sg);
1190 void unGroupMenuItem_actionPerformed()
1192 SequenceGroup sg = ap.av.getSelectionGroup();
1193 ap.av.getAlignment().deleteGroup(sg);
1194 ap.av.setSelectionGroup(null);
1195 ap.paintAlignment(true);
1198 void createGroupMenuItem_actionPerformed()
1200 getGroup(); // implicitly create group
1204 public void showColourText_itemStateChanged()
1206 getGroup().setColourText(showColourText.getState());
1210 public void showText_itemStateChanged()
1212 getGroup().setDisplayText(showText.getState());
1216 public void makeReferenceSeq_actionPerformed()
1218 if (!ap.av.getAlignment().hasSeqrep())
1220 // initialise the display flags so the user sees something happen
1221 ap.av.setDisplayReferenceSeq(true);
1222 ap.av.setColourByReferenceSeq(true);
1223 ap.av.getAlignment().setSeqrep(seq);
1227 if (ap.av.getAlignment().getSeqrep() == seq)
1229 ap.av.getAlignment().setSeqrep(null);
1233 ap.av.getAlignment().setSeqrep(seq);
1239 public void showNonconserved_itemStateChanged()
1241 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1245 public void showBoxes_itemStateChanged()
1247 getGroup().setDisplayBoxes(showBoxes.getState());
1251 void hideSequences(boolean representGroup)
1253 ap.av.hideSequences(seq, representGroup);
1257 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1258 * "All" is added first, followed by a separator. Then add any annotation
1259 * types associated with the current selection. Separate menus are built for
1260 * the selected sequence group (if any), and the selected sequence.
1262 * Some annotation rows are always rendered together - these can be identified
1263 * by a common graphGroup property > -1. Only one of each group will be marked
1264 * as visible (to avoid duplication of the display). For such groups we add a
1265 * composite type name, e.g.
1267 * IUPredWS (Long), IUPredWS (Short)
1271 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1272 List<SequenceI> forSequences)
1274 showMenu.removeAll();
1275 hideMenu.removeAll();
1277 final List<String> all = Arrays.asList(new String[] { MessageManager
1278 .getString("label.all") });
1279 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1280 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1282 showMenu.addSeparator();
1283 hideMenu.addSeparator();
1285 final AlignmentAnnotation[] annotations = ap.getAlignment()
1286 .getAlignmentAnnotation();
1289 * Find shown/hidden annotations types, distinguished by source (calcId),
1290 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1291 * the insertion order, which is the order of the annotations on the
1294 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1295 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1296 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1297 AlignmentAnnotationUtils.asList(annotations), forSequences);
1299 for (String calcId : hiddenTypes.keySet())
1301 for (List<String> type : hiddenTypes.get(calcId))
1303 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1307 // grey out 'show annotations' if none are hidden
1308 showMenu.setEnabled(!hiddenTypes.isEmpty());
1310 for (String calcId : shownTypes.keySet())
1312 for (List<String> type : shownTypes.get(calcId))
1314 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1318 // grey out 'hide annotations' if none are shown
1319 hideMenu.setEnabled(!shownTypes.isEmpty());
1323 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1326 * @param showOrHideMenu
1327 * the menu to add to
1328 * @param forSequences
1329 * the sequences whose annotations may be shown or hidden
1334 * if true this is a special label meaning 'All'
1335 * @param actionIsShow
1336 * if true, the select menu item action is to show the annotation
1339 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1340 final List<SequenceI> forSequences, String calcId,
1341 final List<String> types, final boolean allTypes,
1342 final boolean actionIsShow)
1344 String label = types.toString(); // [a, b, c]
1345 label = label.substring(1, label.length() - 1);
1346 final MenuItem item = new MenuItem(label);
1347 item.addActionListener(new java.awt.event.ActionListener()
1350 public void actionPerformed(ActionEvent e)
1352 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1353 types, forSequences, allTypes, actionIsShow);
1357 showOrHideMenu.add(item);