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.commands.ChangeCaseCommand;
28 import jalview.commands.EditCommand;
29 import jalview.commands.EditCommand.Action;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.PDBEntry;
33 import jalview.datamodel.SequenceFeature;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.io.AppletFormatAdapter;
37 import jalview.io.SequenceAnnotationReport;
38 import jalview.schemes.Blosum62ColourScheme;
39 import jalview.schemes.BuriedColourScheme;
40 import jalview.schemes.ClustalxColourScheme;
41 import jalview.schemes.HelixColourScheme;
42 import jalview.schemes.HydrophobicColourScheme;
43 import jalview.schemes.NucleotideColourScheme;
44 import jalview.schemes.PIDColourScheme;
45 import jalview.schemes.StrandColourScheme;
46 import jalview.schemes.TaylorColourScheme;
47 import jalview.schemes.TurnColourScheme;
48 import jalview.schemes.ZappoColourScheme;
49 import jalview.util.MessageManager;
50 import jalview.util.UrlLink;
52 import java.awt.CheckboxMenuItem;
53 import java.awt.Frame;
55 import java.awt.MenuItem;
56 import java.awt.event.ActionEvent;
57 import java.awt.event.ActionListener;
58 import java.awt.event.ItemEvent;
59 import java.awt.event.ItemListener;
60 import java.util.Arrays;
61 import java.util.Collection;
62 import java.util.Collections;
63 import java.util.LinkedHashMap;
64 import java.util.List;
66 import java.util.TreeMap;
67 import java.util.Vector;
69 public class APopupMenu extends java.awt.PopupMenu implements
70 ActionListener, ItemListener
72 Menu groupMenu = new Menu();
74 MenuItem editGroupName = new MenuItem();
76 protected MenuItem clustalColour = new MenuItem();
78 protected MenuItem zappoColour = new MenuItem();
80 protected MenuItem taylorColour = new MenuItem();
82 protected MenuItem hydrophobicityColour = new MenuItem();
84 protected MenuItem helixColour = new MenuItem();
86 protected MenuItem strandColour = new MenuItem();
88 protected MenuItem turnColour = new MenuItem();
90 protected MenuItem buriedColour = new MenuItem();
92 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
94 protected MenuItem userDefinedColour = new MenuItem();
96 protected MenuItem PIDColour = new MenuItem();
98 protected MenuItem BLOSUM62Colour = new MenuItem();
100 MenuItem noColourmenuItem = new MenuItem();
102 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
104 final AlignmentPanel ap;
106 MenuItem unGroupMenuItem = new MenuItem();
108 MenuItem createGroupMenuItem = new MenuItem();
110 MenuItem nucleotideMenuItem = new MenuItem();
112 Menu colourMenu = new Menu();
114 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
116 CheckboxMenuItem showText = new CheckboxMenuItem();
118 CheckboxMenuItem showColourText = new CheckboxMenuItem();
120 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
122 Menu seqShowAnnotationsMenu = new Menu(
123 MessageManager.getString("label.show_annotations"));
125 Menu seqHideAnnotationsMenu = new Menu(
126 MessageManager.getString("label.hide_annotations"));
128 MenuItem seqAddReferenceAnnotations = new MenuItem(
129 MessageManager.getString("label.add_reference_annotations"));
131 Menu groupShowAnnotationsMenu = new Menu(
132 MessageManager.getString("label.show_annotations"));
134 Menu groupHideAnnotationsMenu = new Menu(
135 MessageManager.getString("label.hide_annotations"));
137 MenuItem groupAddReferenceAnnotations = new MenuItem(
138 MessageManager.getString("label.add_reference_annotations"));
140 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
142 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
144 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
146 MenuItem toUpper = new MenuItem(
147 MessageManager.getString("label.to_upper_case"));
149 MenuItem toLower = new MenuItem(
150 MessageManager.getString("label.to_lower_case"));
152 MenuItem toggleCase = new MenuItem(
153 MessageManager.getString("label.toggle_case"));
155 Menu outputmenu = new Menu();
157 Menu seqMenu = new Menu();
159 MenuItem pdb = new MenuItem();
161 MenuItem hideSeqs = new MenuItem();
163 MenuItem repGroup = new MenuItem();
165 MenuItem sequenceName = new MenuItem(
166 MessageManager.getString("label.edit_name_description"));
168 MenuItem sequenceFeature = new MenuItem(
169 MessageManager.getString("label.create_sequence_feature"));
171 MenuItem editSequence = new MenuItem(
172 MessageManager.getString("label.edit_sequence"));
174 MenuItem sequenceDetails = new MenuItem(
175 MessageManager.getString("label.sequence_details"));
177 MenuItem selSeqDetails = new MenuItem(
178 MessageManager.getString("label.sequence_details"));
180 MenuItem makeReferenceSeq = new MenuItem();
184 MenuItem revealAll = new MenuItem();
186 MenuItem revealSeq = new MenuItem();
189 * index of sequence to be revealed
191 int revealSeq_index = -1;
193 Menu menu1 = new Menu();
195 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
196 Vector<String> links)
198 // /////////////////////////////////////////////////////////
199 // If this is activated from the sequence panel, the user may want to
200 // edit or annotate a particular residue. Therefore display the residue menu
202 // If from the IDPanel, we must display the sequence menu
203 // ////////////////////////////////////////////////////////
211 } catch (Exception e)
216 for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
218 MenuItem item = new MenuItem(
219 jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
221 item.addActionListener(this);
222 outputmenu.add(item);
225 buildAnnotationSubmenus();
227 SequenceGroup sg = ap.av.getSelectionGroup();
228 if (sg != null && sg.getSize() > 0)
230 editGroupName.setLabel(MessageManager.formatMessage(
231 "label.name_param", new Object[] { sg.getName() }));
232 showText.setState(sg.getDisplayText());
233 showColourText.setState(sg.getColourText());
234 showBoxes.setState(sg.getDisplayBoxes());
235 displayNonconserved.setState(sg.getShowNonconserved());
236 if (!ap.av.getAlignment().getGroups().contains(sg))
238 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
239 groupMenu.remove(unGroupMenuItem);
243 menu1.setLabel(MessageManager.getString("action.edit_group"));
244 groupMenu.remove(createGroupMenuItem);
254 if (links != null && links.size() > 0)
256 addFeatureLinks(seq, links);
259 // TODO: add group link menu entry here
262 seqMenu.setLabel(seq.getName());
263 if (seq == ap.av.getAlignment().getSeqrep())
265 makeReferenceSeq.setLabel(MessageManager
266 .getString("action.unmark_as_reference"));// Unmark
271 makeReferenceSeq.setLabel(MessageManager
272 .getString("action.set_as_reference")); // );
274 repGroup.setLabel(MessageManager.formatMessage(
275 "label.represent_group_with", new Object[] { seq.getName() }));
282 if (!ap.av.hasHiddenRows())
289 final int index = ap.av.getAlignment().findIndex(seq);
291 if (ap.av.adjustForHiddenSeqs(index)
292 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
294 revealSeq_index = index;
304 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
309 void addFeatureLinks(final SequenceI seq, List<String> links)
311 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
312 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
314 for (String link : links)
316 UrlLink urlLink = null;
319 urlLink = new UrlLink(link);
320 } catch (Exception foo)
322 System.err.println("Exception for URLLink '" + link + "': "
327 if (!urlLink.isValid())
329 System.err.println(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 StringBuilder contents = new StringBuilder(128);
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(
816 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
817 .getMinMax() : null);
818 contents.append("</p>");
820 Frame frame = new Frame();
822 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
823 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
824 : "Selection"), 600, 500);
825 cap.setText(MessageManager.formatMessage("label.html_content",
826 new Object[] { contents.toString() }));
831 EditNameDialog dialog = new EditNameDialog(seq.getName(),
832 seq.getDescription(), " Sequence Name",
833 "Sequence Description", ap.alignFrame,
834 "Edit Sequence Name / Description", 500, 100, true);
838 seq.setName(dialog.getName());
839 seq.setDescription(dialog.getDescription());
840 ap.paintAlignment(false);
846 if (seq.getAllPDBEntries() != null)
848 PDBEntry entry = seq.getAllPDBEntries().firstElement();
850 if (ap.av.applet.jmolAvailable)
852 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
853 null, ap, AppletFormatAdapter.URL);
857 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
858 ap, AppletFormatAdapter.URL);
864 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
865 cap.setText(MessageManager.getString("label.paste_pdb_file"));
866 cap.setPDBImport(seq);
867 Frame frame = new Frame();
869 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
870 "label.paste_pdb_file_for_sequence",
871 new Object[] { seq.getName() }), 400, 300);
875 private void jbInit() throws Exception
877 groupMenu.setLabel(MessageManager.getString("label.selection"));
878 sequenceFeature.addActionListener(this);
880 editGroupName.addActionListener(this);
881 unGroupMenuItem.setLabel(MessageManager
882 .getString("action.remove_group"));
883 unGroupMenuItem.addActionListener(this);
885 createGroupMenuItem.setLabel(MessageManager
886 .getString("action.create_group"));
887 createGroupMenuItem.addActionListener(this);
889 nucleotideMenuItem.setLabel(MessageManager
890 .getString("label.nucleotide"));
891 nucleotideMenuItem.addActionListener(this);
892 conservationMenuItem.addItemListener(this);
893 abovePIDColour.addItemListener(this);
894 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
895 showBoxes.setLabel(MessageManager.getString("action.boxes"));
896 showBoxes.setState(true);
897 showBoxes.addItemListener(this);
898 sequenceName.addActionListener(this);
899 sequenceDetails.addActionListener(this);
900 selSeqDetails.addActionListener(this);
901 displayNonconserved.setLabel(MessageManager
902 .getString("label.show_non_conversed"));
903 displayNonconserved.setState(false);
904 displayNonconserved.addItemListener(this);
905 showText.setLabel(MessageManager.getString("action.text"));
906 showText.addItemListener(this);
907 showColourText.setLabel(MessageManager.getString("label.colour_text"));
908 showColourText.addItemListener(this);
909 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
910 seqMenu.setLabel(MessageManager.getString("label.sequence"));
911 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
912 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
913 repGroup.setLabel(MessageManager.formatMessage(
914 "label.represent_group_with", new Object[] { "" }));
915 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
916 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
917 menu1.setLabel(MessageManager.getString("label.group:"));
923 // groupMenu.add(selSeqDetails);
924 groupMenu.add(groupShowAnnotationsMenu);
925 groupMenu.add(groupHideAnnotationsMenu);
926 groupMenu.add(groupAddReferenceAnnotations);
927 groupMenu.add(editMenu);
928 groupMenu.add(outputmenu);
929 groupMenu.add(sequenceFeature);
930 groupMenu.add(createGroupMenuItem);
931 groupMenu.add(unGroupMenuItem);
932 groupMenu.add(menu1);
934 colourMenu.add(noColourmenuItem);
935 colourMenu.add(clustalColour);
936 colourMenu.add(BLOSUM62Colour);
937 colourMenu.add(PIDColour);
938 colourMenu.add(zappoColour);
939 colourMenu.add(taylorColour);
940 colourMenu.add(hydrophobicityColour);
941 colourMenu.add(helixColour);
942 colourMenu.add(strandColour);
943 colourMenu.add(turnColour);
944 colourMenu.add(buriedColour);
945 colourMenu.add(nucleotideMenuItem);
946 colourMenu.add(userDefinedColour);
947 colourMenu.addSeparator();
948 colourMenu.add(abovePIDColour);
949 colourMenu.add(conservationMenuItem);
951 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
952 noColourmenuItem.addActionListener(this);
954 clustalColour.setLabel(MessageManager
955 .getString("label.clustalx_colours"));
956 clustalColour.addActionListener(this);
957 zappoColour.setLabel(MessageManager.getString("label.zappo"));
958 zappoColour.addActionListener(this);
959 taylorColour.setLabel(MessageManager.getString("label.taylor"));
960 taylorColour.addActionListener(this);
961 hydrophobicityColour.setLabel(MessageManager
962 .getString("label.hydrophobicity"));
963 hydrophobicityColour.addActionListener(this);
965 .setLabel(MessageManager.getString("label.helix_propensity"));
966 helixColour.addActionListener(this);
967 strandColour.setLabel(MessageManager
968 .getString("label.strand_propensity"));
969 strandColour.addActionListener(this);
970 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
971 turnColour.addActionListener(this);
972 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
973 buriedColour.addActionListener(this);
974 abovePIDColour.setLabel(MessageManager
975 .getString("label.above_identity_percentage"));
977 userDefinedColour.setLabel(MessageManager
978 .getString("action.user_defined"));
979 userDefinedColour.addActionListener(this);
980 PIDColour.setLabel(MessageManager
981 .getString("label.percentage_identity"));
982 PIDColour.addActionListener(this);
983 BLOSUM62Colour.setLabel("BLOSUM62");
984 BLOSUM62Colour.addActionListener(this);
985 conservationMenuItem.setLabel(MessageManager
986 .getString("label.conservation"));
989 copy.addActionListener(this);
991 cut.addActionListener(this);
993 editMenu.add(editSequence);
994 editSequence.addActionListener(this);
996 editMenu.add(toUpper);
997 toUpper.addActionListener(this);
998 editMenu.add(toLower);
999 toLower.addActionListener(this);
1000 editMenu.add(toggleCase);
1001 seqMenu.add(seqShowAnnotationsMenu);
1002 seqMenu.add(seqHideAnnotationsMenu);
1003 seqMenu.add(seqAddReferenceAnnotations);
1004 seqMenu.add(sequenceName);
1005 seqMenu.add(makeReferenceSeq);
1006 // seqMenu.add(sequenceDetails);
1008 if (!ap.av.applet.useXtrnalSviewer)
1012 seqMenu.add(repGroup);
1013 menu1.add(editGroupName);
1014 menu1.add(colourMenu);
1015 menu1.add(showBoxes);
1016 menu1.add(showText);
1017 menu1.add(showColourText);
1018 menu1.add(displayNonconserved);
1019 toggleCase.addActionListener(this);
1020 pdb.addActionListener(this);
1021 hideSeqs.addActionListener(this);
1022 repGroup.addActionListener(this);
1023 revealAll.addActionListener(this);
1024 revealSeq.addActionListener(this);
1025 makeReferenceSeq.addActionListener(this);
1030 ap.paintAlignment(true);
1033 protected void clustalColour_actionPerformed()
1035 SequenceGroup sg = getGroup();
1036 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1040 protected void zappoColour_actionPerformed()
1042 getGroup().cs = new ZappoColourScheme();
1046 protected void taylorColour_actionPerformed()
1048 getGroup().cs = new TaylorColourScheme();
1052 protected void hydrophobicityColour_actionPerformed()
1054 getGroup().cs = new HydrophobicColourScheme();
1058 protected void helixColour_actionPerformed()
1060 getGroup().cs = new HelixColourScheme();
1064 protected void strandColour_actionPerformed()
1066 getGroup().cs = new StrandColourScheme();
1070 protected void turnColour_actionPerformed()
1072 getGroup().cs = new TurnColourScheme();
1076 protected void buriedColour_actionPerformed()
1078 getGroup().cs = new BuriedColourScheme();
1082 public void nucleotideMenuItem_actionPerformed()
1084 getGroup().cs = new NucleotideColourScheme();
1088 protected void abovePIDColour_itemStateChanged()
1090 SequenceGroup sg = getGroup();
1096 if (abovePIDColour.getState())
1098 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1099 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1100 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1103 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1105 SliderPanel.showPIDSlider();
1109 // remove PIDColouring
1111 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1118 protected void userDefinedColour_actionPerformed()
1120 new UserDefinedColours(ap, getGroup());
1123 protected void PIDColour_actionPerformed()
1125 SequenceGroup sg = getGroup();
1126 sg.cs = new PIDColourScheme();
1127 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1128 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1132 protected void BLOSUM62Colour_actionPerformed()
1134 SequenceGroup sg = getGroup();
1136 sg.cs = new Blosum62ColourScheme();
1138 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1139 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1144 protected void noColourmenuItem_actionPerformed()
1146 getGroup().cs = null;
1150 protected void conservationMenuItem_itemStateChanged()
1152 SequenceGroup sg = getGroup();
1158 if (conservationMenuItem.getState())
1160 sg.cs.setConservation(Conservation.calculateConservation("Group", sg
1161 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1162 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1164 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1165 SliderPanel.showConservationSlider();
1168 // remove ConservationColouring
1170 sg.cs.setConservation(null);
1176 SequenceGroup getGroup()
1178 SequenceGroup sg = ap.av.getSelectionGroup();
1180 // this method won't add a new group if it already exists
1183 ap.av.getAlignment().addGroup(sg);
1189 void unGroupMenuItem_actionPerformed()
1191 SequenceGroup sg = ap.av.getSelectionGroup();
1192 ap.av.getAlignment().deleteGroup(sg);
1193 ap.av.setSelectionGroup(null);
1194 ap.paintAlignment(true);
1197 void createGroupMenuItem_actionPerformed()
1199 getGroup(); // implicitly create group
1203 public void showColourText_itemStateChanged()
1205 getGroup().setColourText(showColourText.getState());
1209 public void showText_itemStateChanged()
1211 getGroup().setDisplayText(showText.getState());
1215 public void makeReferenceSeq_actionPerformed()
1217 if (!ap.av.getAlignment().hasSeqrep())
1219 // initialise the display flags so the user sees something happen
1220 ap.av.setDisplayReferenceSeq(true);
1221 ap.av.setColourByReferenceSeq(true);
1222 ap.av.getAlignment().setSeqrep(seq);
1226 if (ap.av.getAlignment().getSeqrep() == seq)
1228 ap.av.getAlignment().setSeqrep(null);
1232 ap.av.getAlignment().setSeqrep(seq);
1238 public void showNonconserved_itemStateChanged()
1240 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1244 public void showBoxes_itemStateChanged()
1246 getGroup().setDisplayBoxes(showBoxes.getState());
1250 void hideSequences(boolean representGroup)
1252 ap.av.hideSequences(seq, representGroup);
1256 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1257 * "All" is added first, followed by a separator. Then add any annotation
1258 * types associated with the current selection. Separate menus are built for
1259 * the selected sequence group (if any), and the selected sequence.
1261 * Some annotation rows are always rendered together - these can be identified
1262 * by a common graphGroup property > -1. Only one of each group will be marked
1263 * as visible (to avoid duplication of the display). For such groups we add a
1264 * composite type name, e.g.
1266 * IUPredWS (Long), IUPredWS (Short)
1270 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1271 List<SequenceI> forSequences)
1273 showMenu.removeAll();
1274 hideMenu.removeAll();
1276 final List<String> all = Arrays.asList(new String[] { MessageManager
1277 .getString("label.all") });
1278 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1279 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1281 showMenu.addSeparator();
1282 hideMenu.addSeparator();
1284 final AlignmentAnnotation[] annotations = ap.getAlignment()
1285 .getAlignmentAnnotation();
1288 * Find shown/hidden annotations types, distinguished by source (calcId),
1289 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1290 * the insertion order, which is the order of the annotations on the
1293 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1294 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1295 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1296 AlignmentAnnotationUtils.asList(annotations), forSequences);
1298 for (String calcId : hiddenTypes.keySet())
1300 for (List<String> type : hiddenTypes.get(calcId))
1302 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1306 // grey out 'show annotations' if none are hidden
1307 showMenu.setEnabled(!hiddenTypes.isEmpty());
1309 for (String calcId : shownTypes.keySet())
1311 for (List<String> type : shownTypes.get(calcId))
1313 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1317 // grey out 'hide annotations' if none are shown
1318 hideMenu.setEnabled(!shownTypes.isEmpty());
1322 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1325 * @param showOrHideMenu
1326 * the menu to add to
1327 * @param forSequences
1328 * the sequences whose annotations may be shown or hidden
1333 * if true this is a special label meaning 'All'
1334 * @param actionIsShow
1335 * if true, the select menu item action is to show the annotation
1338 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1339 final List<SequenceI> forSequences, String calcId,
1340 final List<String> types, final boolean allTypes,
1341 final boolean actionIsShow)
1343 String label = types.toString(); // [a, b, c]
1344 label = label.substring(1, label.length() - 1);
1345 final MenuItem item = new MenuItem(label);
1346 item.addActionListener(new java.awt.event.ActionListener()
1349 public void actionPerformed(ActionEvent e)
1351 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1352 types, forSequences, allTypes, actionIsShow);
1356 showOrHideMenu.add(item);