2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.JalviewLite;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.DataSourceType;
39 import jalview.io.FileFormat;
40 import jalview.io.SequenceAnnotationReport;
41 import jalview.schemes.Blosum62ColourScheme;
42 import jalview.schemes.BuriedColourScheme;
43 import jalview.schemes.ClustalxColourScheme;
44 import jalview.schemes.HelixColourScheme;
45 import jalview.schemes.HydrophobicColourScheme;
46 import jalview.schemes.NucleotideColourScheme;
47 import jalview.schemes.PIDColourScheme;
48 import jalview.schemes.StrandColourScheme;
49 import jalview.schemes.TaylorColourScheme;
50 import jalview.schemes.TurnColourScheme;
51 import jalview.schemes.ZappoColourScheme;
52 import jalview.util.MessageManager;
53 import jalview.util.UrlLink;
55 import java.awt.CheckboxMenuItem;
56 import java.awt.Frame;
58 import java.awt.MenuItem;
59 import java.awt.event.ActionEvent;
60 import java.awt.event.ActionListener;
61 import java.awt.event.ItemEvent;
62 import java.awt.event.ItemListener;
63 import java.util.Arrays;
64 import java.util.Collection;
65 import java.util.Collections;
66 import java.util.LinkedHashMap;
67 import java.util.List;
69 import java.util.TreeMap;
70 import java.util.Vector;
72 public class APopupMenu extends java.awt.PopupMenu implements
73 ActionListener, ItemListener
75 Menu groupMenu = new Menu();
77 MenuItem editGroupName = new MenuItem();
79 protected MenuItem clustalColour = new MenuItem();
81 protected MenuItem zappoColour = new MenuItem();
83 protected MenuItem taylorColour = new MenuItem();
85 protected MenuItem hydrophobicityColour = new MenuItem();
87 protected MenuItem helixColour = new MenuItem();
89 protected MenuItem strandColour = new MenuItem();
91 protected MenuItem turnColour = new MenuItem();
93 protected MenuItem buriedColour = new MenuItem();
95 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
97 protected MenuItem userDefinedColour = new MenuItem();
99 protected MenuItem PIDColour = new MenuItem();
101 protected MenuItem BLOSUM62Colour = new MenuItem();
103 MenuItem noColourmenuItem = new MenuItem();
105 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
107 final AlignmentPanel ap;
109 MenuItem unGroupMenuItem = new MenuItem();
111 MenuItem createGroupMenuItem = new MenuItem();
113 MenuItem nucleotideMenuItem = new MenuItem();
115 Menu colourMenu = new Menu();
117 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
119 CheckboxMenuItem showText = new CheckboxMenuItem();
121 CheckboxMenuItem showColourText = new CheckboxMenuItem();
123 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
125 Menu seqShowAnnotationsMenu = new Menu(
126 MessageManager.getString("label.show_annotations"));
128 Menu seqHideAnnotationsMenu = new Menu(
129 MessageManager.getString("label.hide_annotations"));
131 MenuItem seqAddReferenceAnnotations = new MenuItem(
132 MessageManager.getString("label.add_reference_annotations"));
134 Menu groupShowAnnotationsMenu = new Menu(
135 MessageManager.getString("label.show_annotations"));
137 Menu groupHideAnnotationsMenu = new Menu(
138 MessageManager.getString("label.hide_annotations"));
140 MenuItem groupAddReferenceAnnotations = new MenuItem(
141 MessageManager.getString("label.add_reference_annotations"));
143 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
145 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
147 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
149 MenuItem toUpper = new MenuItem(
150 MessageManager.getString("label.to_upper_case"));
152 MenuItem toLower = new MenuItem(
153 MessageManager.getString("label.to_lower_case"));
155 MenuItem toggleCase = new MenuItem(
156 MessageManager.getString("label.toggle_case"));
158 Menu outputmenu = new Menu();
160 Menu seqMenu = new Menu();
162 MenuItem pdb = new MenuItem();
164 MenuItem hideSeqs = new MenuItem();
166 MenuItem repGroup = new MenuItem();
168 MenuItem sequenceName = new MenuItem(
169 MessageManager.getString("label.edit_name_description"));
171 MenuItem sequenceFeature = new MenuItem(
172 MessageManager.getString("label.create_sequence_feature"));
174 MenuItem editSequence = new MenuItem(
175 MessageManager.getString("label.edit_sequence"));
177 MenuItem sequenceDetails = new MenuItem(
178 MessageManager.getString("label.sequence_details"));
180 MenuItem selSeqDetails = new MenuItem(
181 MessageManager.getString("label.sequence_details"));
183 MenuItem makeReferenceSeq = new MenuItem();
187 MenuItem revealAll = new MenuItem();
189 MenuItem revealSeq = new MenuItem();
192 * index of sequence to be revealed
194 int revealSeq_index = -1;
196 Menu menu1 = new Menu();
198 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
199 Vector<String> links)
201 // /////////////////////////////////////////////////////////
202 // If this is activated from the sequence panel, the user may want to
203 // edit or annotate a particular residue. Therefore display the residue menu
205 // If from the IDPanel, we must display the sequence menu
206 // ////////////////////////////////////////////////////////
214 } catch (Exception e)
219 for (String ff : FileFormat.getWritableFormats(true))
221 MenuItem item = new MenuItem(ff);
223 item.addActionListener(this);
224 outputmenu.add(item);
227 buildAnnotationSubmenus();
229 SequenceGroup sg = ap.av.getSelectionGroup();
230 if (sg != null && sg.getSize() > 0)
232 editGroupName.setLabel(MessageManager.formatMessage(
233 "label.name_param", new Object[] { sg.getName() }));
234 showText.setState(sg.getDisplayText());
235 showColourText.setState(sg.getColourText());
236 showBoxes.setState(sg.getDisplayBoxes());
237 displayNonconserved.setState(sg.getShowNonconserved());
238 if (!ap.av.getAlignment().getGroups().contains(sg))
240 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
241 groupMenu.remove(unGroupMenuItem);
245 menu1.setLabel(MessageManager.getString("action.edit_group"));
246 groupMenu.remove(createGroupMenuItem);
256 if (links != null && links.size() > 0)
258 addFeatureLinks(seq, links);
261 // TODO: add group link menu entry here
264 seqMenu.setLabel(seq.getName());
265 if (seq == ap.av.getAlignment().getSeqrep())
267 makeReferenceSeq.setLabel(MessageManager
268 .getString("action.unmark_as_reference"));// Unmark
273 makeReferenceSeq.setLabel(MessageManager
274 .getString("action.set_as_reference")); // );
276 repGroup.setLabel(MessageManager.formatMessage(
277 "label.represent_group_with", new Object[] { seq.getName() }));
284 if (!ap.av.hasHiddenRows())
291 final int index = ap.av.getAlignment().findIndex(seq);
293 if (ap.av.adjustForHiddenSeqs(index)
294 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
296 revealSeq_index = index;
306 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
311 void addFeatureLinks(final SequenceI seq, List<String> links)
313 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
314 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
316 for (String link : links)
318 UrlLink urlLink = null;
321 urlLink = new UrlLink(link);
322 } catch (Exception foo)
324 System.err.println("Exception for URLLink '" + link + "': "
329 if (!urlLink.isValid())
331 System.err.println(urlLink.getInvalidMessage());
335 urlLink.createLinksFromSeq(seq, linkset);
338 addshowLinks(linkMenu, linkset.values());
340 // disable link menu if there are no valid entries
341 if (linkMenu.getItemCount() > 0)
343 linkMenu.setEnabled(true);
347 linkMenu.setEnabled(false);
352 seqMenu.add(linkMenu);
361 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
363 for (List<String> linkstrset : linkset)
365 // split linkstr into label and url
366 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
371 * Build menus for annotation types that may be shown or hidden, and for
372 * 'reference annotations' that may be added to the alignment.
374 private void buildAnnotationSubmenus()
377 * First for the currently selected sequence (if there is one):
379 final List<SequenceI> selectedSequence = (seq == null ? Collections
380 .<SequenceI> emptyList() : Arrays.asList(seq));
381 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
382 seqHideAnnotationsMenu, selectedSequence);
383 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
387 * and repeat for the current selection group (if there is one):
389 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
390 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
392 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
393 groupHideAnnotationsMenu, selectedGroup);
394 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
399 * Determine whether or not to enable 'add reference annotations' menu item.
400 * It is enable if there are any annotations, on any of the selected
401 * sequences, which are not yet on the alignment (visible or not).
404 * @param forSequences
406 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
407 List<SequenceI> forSequences)
409 menuItem.setEnabled(false);
412 * Temporary store to hold distinct calcId / type pairs for the tooltip.
413 * Using TreeMap means calcIds are shown in alphabetical order.
415 Map<String, String> tipEntries = new TreeMap<String, String>();
416 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
417 AlignmentI al = this.ap.av.getAlignment();
418 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
419 tipEntries, candidates, al);
420 if (!candidates.isEmpty())
422 StringBuilder tooltip = new StringBuilder(64);
423 tooltip.append(MessageManager.getString("label.add_annotations_for"));
426 * Found annotations that could be added. Enable the menu item, and
427 * configure its action.
429 menuItem.setEnabled(true);
431 menuItem.addActionListener(new ActionListener()
434 public void actionPerformed(ActionEvent e)
436 addReferenceAnnotations_actionPerformed(candidates);
443 * Add annotations to the sequences and to the alignment.
446 * a map whose keys are sequences on the alignment, and values a list
447 * of annotations to add to each sequence
449 protected void addReferenceAnnotations_actionPerformed(
450 Map<SequenceI, List<AlignmentAnnotation>> candidates)
452 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
453 final AlignmentI alignment = this.ap.getAlignment();
454 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
460 * add a show URL menu item to the given linkMenu
464 * - menu label string
468 private void addshowLink(Menu linkMenu, final String target,
471 addshowLink(linkMenu, target, target, url);
475 * add a show URL menu item to the given linkMenu
479 * - URL target window
481 * - menu label string
485 private void addshowLink(Menu linkMenu, final String target,
486 final String label, final String url)
488 MenuItem item = new MenuItem(label);
489 item.addActionListener(new java.awt.event.ActionListener()
492 public void actionPerformed(ActionEvent e)
494 ap.alignFrame.showURL(url, target);
501 public void itemStateChanged(ItemEvent evt)
503 if (evt.getSource() == abovePIDColour)
505 abovePIDColour_itemStateChanged();
507 else if (evt.getSource() == showColourText)
509 showColourText_itemStateChanged();
511 else if (evt.getSource() == showText)
513 showText_itemStateChanged();
515 else if (evt.getSource() == showBoxes)
517 showBoxes_itemStateChanged();
519 else if (evt.getSource() == displayNonconserved)
521 this.showNonconserved_itemStateChanged();
526 public void actionPerformed(ActionEvent evt)
528 Object source = evt.getSource();
529 if (source == clustalColour)
531 clustalColour_actionPerformed();
533 else if (source == zappoColour)
535 zappoColour_actionPerformed();
537 else if (source == taylorColour)
539 taylorColour_actionPerformed();
541 else if (source == hydrophobicityColour)
543 hydrophobicityColour_actionPerformed();
545 else if (source == helixColour)
547 helixColour_actionPerformed();
549 else if (source == strandColour)
551 strandColour_actionPerformed();
553 else if (source == turnColour)
555 turnColour_actionPerformed();
557 else if (source == buriedColour)
559 buriedColour_actionPerformed();
561 else if (source == nucleotideMenuItem)
563 nucleotideMenuItem_actionPerformed();
566 else if (source == userDefinedColour)
568 userDefinedColour_actionPerformed();
570 else if (source == PIDColour)
572 PIDColour_actionPerformed();
574 else if (source == BLOSUM62Colour)
576 BLOSUM62Colour_actionPerformed();
578 else if (source == noColourmenuItem)
580 noColourmenuItem_actionPerformed();
582 else if (source == conservationMenuItem)
584 conservationMenuItem_itemStateChanged();
586 else if (source == unGroupMenuItem)
588 unGroupMenuItem_actionPerformed();
591 else if (source == createGroupMenuItem)
593 createGroupMenuItem_actionPerformed();
596 else if (source == sequenceName)
600 else if (source == makeReferenceSeq)
602 makeReferenceSeq_actionPerformed();
604 else if (source == sequenceDetails)
606 showSequenceDetails();
608 else if (source == selSeqDetails)
610 showSequenceSelectionDetails();
612 else if (source == pdb)
616 else if (source == hideSeqs)
618 hideSequences(false);
620 else if (source == repGroup)
624 else if (source == revealSeq)
626 ap.av.showSequence(revealSeq_index);
628 else if (source == revealAll)
630 ap.av.showAllHiddenSeqs();
633 else if (source == editGroupName)
635 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
636 getGroup().getDescription(), " Group Name",
637 "Group Description", ap.alignFrame,
638 "Edit Group Name / Description", 500, 100, true);
642 getGroup().setName(dialog.getName().replace(' ', '_'));
643 getGroup().setDescription(dialog.getDescription());
647 else if (source == copy)
649 ap.alignFrame.copy_actionPerformed();
651 else if (source == cut)
653 ap.alignFrame.cut_actionPerformed();
655 else if (source == editSequence)
657 SequenceGroup sg = ap.av.getSelectionGroup();
663 seq = sg.getSequenceAt(0);
666 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
667 sg.getStartRes(), sg.getEndRes() + 1), null,
668 "Edit Sequence ", null,
670 ap.alignFrame, "Edit Sequence", 500, 100, true);
674 EditCommand editCommand = new EditCommand(
675 MessageManager.getString("label.edit_sequences"),
676 Action.REPLACE, dialog.getName().replace(' ',
677 ap.av.getGapCharacter()),
678 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
679 sg.getStartRes(), sg.getEndRes() + 1,
680 ap.av.getAlignment());
682 ap.alignFrame.addHistoryItem(editCommand);
684 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
689 else if (source == toUpper || source == toLower || source == toggleCase)
691 SequenceGroup sg = ap.av.getSelectionGroup();
694 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
695 sg.getStartRes(), sg.getEndRes() + 1);
700 if (source == toggleCase)
702 description = "Toggle Case";
703 caseChange = ChangeCaseCommand.TOGGLE_CASE;
705 else if (source == toUpper)
707 description = "To Upper Case";
708 caseChange = ChangeCaseCommand.TO_UPPER;
712 description = "To Lower Case";
713 caseChange = ChangeCaseCommand.TO_LOWER;
716 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
717 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
718 startEnd, caseChange);
720 ap.alignFrame.addHistoryItem(caseCommand);
722 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
727 else if (source == sequenceFeature)
729 SequenceGroup sg = ap.av.getSelectionGroup();
735 int rsize = 0, gSize = sg.getSize();
736 SequenceI[] rseqs, seqs = new SequenceI[gSize];
737 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
739 for (int i = 0; i < gSize; i++)
741 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
742 int end = sg.findEndRes(sg.getSequenceAt(i));
745 seqs[rsize] = sg.getSequenceAt(i);
746 features[rsize] = new SequenceFeature(null, null, null, start,
751 rseqs = new SequenceI[rsize];
752 tfeatures = new SequenceFeature[rsize];
753 System.arraycopy(seqs, 0, rseqs, 0, rsize);
754 System.arraycopy(features, 0, tfeatures, 0, rsize);
755 features = tfeatures;
758 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
761 ap.alignFrame.sequenceFeatures.setState(true);
762 ap.av.setShowSequenceFeatures(true);
764 ap.highlightSearchResults(null);
774 void outputText(ActionEvent e)
776 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
778 Frame frame = new Frame();
780 JalviewLite.addFrame(frame, MessageManager.formatMessage(
781 "label.selection_output_command",
782 new Object[] { e.getActionCommand() }), 600, 500);
783 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
784 // now returns a full copy of sequence data
785 // TODO consider using getSequenceSelection instead here
787 FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
788 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
789 ap.av.getShowJVSuffix(), ap, true));
793 protected void showSequenceSelectionDetails()
795 createSequenceDetailsReport(ap.av.getSequenceSelection());
798 protected void showSequenceDetails()
800 createSequenceDetailsReport(new SequenceI[] { seq });
803 public void createSequenceDetailsReport(SequenceI[] sequences)
806 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
808 StringBuilder contents = new StringBuilder(128);
809 for (SequenceI seq : sequences)
811 contents.append(MessageManager.formatMessage(
812 "label.annotation_for_displayid",
813 new Object[] { seq.getDisplayId(true) }));
814 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
819 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
820 .getMinMax() : null);
821 contents.append("</p>");
823 Frame frame = new Frame();
825 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
826 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
827 : "Selection"), 600, 500);
828 cap.setText(MessageManager.formatMessage("label.html_content",
829 new Object[] { contents.toString() }));
834 EditNameDialog dialog = new EditNameDialog(seq.getName(),
835 seq.getDescription(), " Sequence Name",
836 "Sequence Description", ap.alignFrame,
837 "Edit Sequence Name / Description", 500, 100, true);
841 seq.setName(dialog.getName());
842 seq.setDescription(dialog.getDescription());
843 ap.paintAlignment(false);
849 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
850 if (pdbs != null&& !pdbs.isEmpty())
852 PDBEntry entry = pdbs.firstElement();
854 if (ap.av.applet.jmolAvailable)
856 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
857 null, ap, DataSourceType.URL);
861 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
862 ap, DataSourceType.URL);
868 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
869 cap.setText(MessageManager.getString("label.paste_pdb_file"));
870 cap.setPDBImport(seq);
871 Frame frame = new Frame();
873 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
874 "label.paste_pdb_file_for_sequence",
875 new Object[] { seq.getName() }), 400, 300);
879 private void jbInit() throws Exception
881 groupMenu.setLabel(MessageManager.getString("label.selection"));
882 sequenceFeature.addActionListener(this);
884 editGroupName.addActionListener(this);
885 unGroupMenuItem.setLabel(MessageManager
886 .getString("action.remove_group"));
887 unGroupMenuItem.addActionListener(this);
889 createGroupMenuItem.setLabel(MessageManager
890 .getString("action.create_group"));
891 createGroupMenuItem.addActionListener(this);
893 nucleotideMenuItem.setLabel(MessageManager
894 .getString("label.nucleotide"));
895 nucleotideMenuItem.addActionListener(this);
896 conservationMenuItem.addItemListener(this);
897 abovePIDColour.addItemListener(this);
898 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
899 showBoxes.setLabel(MessageManager.getString("action.boxes"));
900 showBoxes.setState(true);
901 showBoxes.addItemListener(this);
902 sequenceName.addActionListener(this);
903 sequenceDetails.addActionListener(this);
904 selSeqDetails.addActionListener(this);
905 displayNonconserved.setLabel(MessageManager
906 .getString("label.show_non_conversed"));
907 displayNonconserved.setState(false);
908 displayNonconserved.addItemListener(this);
909 showText.setLabel(MessageManager.getString("action.text"));
910 showText.addItemListener(this);
911 showColourText.setLabel(MessageManager.getString("label.colour_text"));
912 showColourText.addItemListener(this);
913 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
914 seqMenu.setLabel(MessageManager.getString("label.sequence"));
915 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
916 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
917 repGroup.setLabel(MessageManager.formatMessage(
918 "label.represent_group_with", new Object[] { "" }));
919 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
920 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
921 menu1.setLabel(MessageManager.getString("label.group:"));
927 // groupMenu.add(selSeqDetails);
928 groupMenu.add(groupShowAnnotationsMenu);
929 groupMenu.add(groupHideAnnotationsMenu);
930 groupMenu.add(groupAddReferenceAnnotations);
931 groupMenu.add(editMenu);
932 groupMenu.add(outputmenu);
933 groupMenu.add(sequenceFeature);
934 groupMenu.add(createGroupMenuItem);
935 groupMenu.add(unGroupMenuItem);
936 groupMenu.add(menu1);
938 colourMenu.add(noColourmenuItem);
939 colourMenu.add(clustalColour);
940 colourMenu.add(BLOSUM62Colour);
941 colourMenu.add(PIDColour);
942 colourMenu.add(zappoColour);
943 colourMenu.add(taylorColour);
944 colourMenu.add(hydrophobicityColour);
945 colourMenu.add(helixColour);
946 colourMenu.add(strandColour);
947 colourMenu.add(turnColour);
948 colourMenu.add(buriedColour);
949 colourMenu.add(nucleotideMenuItem);
950 colourMenu.add(userDefinedColour);
951 colourMenu.addSeparator();
952 colourMenu.add(abovePIDColour);
953 colourMenu.add(conservationMenuItem);
955 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
956 noColourmenuItem.addActionListener(this);
958 clustalColour.setLabel(MessageManager
959 .getString("label.clustalx_colours"));
960 clustalColour.addActionListener(this);
961 zappoColour.setLabel(MessageManager.getString("label.zappo"));
962 zappoColour.addActionListener(this);
963 taylorColour.setLabel(MessageManager.getString("label.taylor"));
964 taylorColour.addActionListener(this);
965 hydrophobicityColour.setLabel(MessageManager
966 .getString("label.hydrophobicity"));
967 hydrophobicityColour.addActionListener(this);
969 .setLabel(MessageManager.getString("label.helix_propensity"));
970 helixColour.addActionListener(this);
971 strandColour.setLabel(MessageManager
972 .getString("label.strand_propensity"));
973 strandColour.addActionListener(this);
974 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
975 turnColour.addActionListener(this);
976 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
977 buriedColour.addActionListener(this);
978 abovePIDColour.setLabel(MessageManager
979 .getString("label.above_identity_percentage"));
981 userDefinedColour.setLabel(MessageManager
982 .getString("action.user_defined"));
983 userDefinedColour.addActionListener(this);
984 PIDColour.setLabel(MessageManager
985 .getString("label.percentage_identity"));
986 PIDColour.addActionListener(this);
987 BLOSUM62Colour.setLabel("BLOSUM62");
988 BLOSUM62Colour.addActionListener(this);
989 conservationMenuItem.setLabel(MessageManager
990 .getString("label.conservation"));
993 copy.addActionListener(this);
995 cut.addActionListener(this);
997 editMenu.add(editSequence);
998 editSequence.addActionListener(this);
1000 editMenu.add(toUpper);
1001 toUpper.addActionListener(this);
1002 editMenu.add(toLower);
1003 toLower.addActionListener(this);
1004 editMenu.add(toggleCase);
1005 seqMenu.add(seqShowAnnotationsMenu);
1006 seqMenu.add(seqHideAnnotationsMenu);
1007 seqMenu.add(seqAddReferenceAnnotations);
1008 seqMenu.add(sequenceName);
1009 seqMenu.add(makeReferenceSeq);
1010 // seqMenu.add(sequenceDetails);
1012 if (!ap.av.applet.useXtrnalSviewer)
1016 seqMenu.add(repGroup);
1017 menu1.add(editGroupName);
1018 menu1.add(colourMenu);
1019 menu1.add(showBoxes);
1020 menu1.add(showText);
1021 menu1.add(showColourText);
1022 menu1.add(displayNonconserved);
1023 toggleCase.addActionListener(this);
1024 pdb.addActionListener(this);
1025 hideSeqs.addActionListener(this);
1026 repGroup.addActionListener(this);
1027 revealAll.addActionListener(this);
1028 revealSeq.addActionListener(this);
1029 makeReferenceSeq.addActionListener(this);
1034 ap.paintAlignment(true);
1037 protected void clustalColour_actionPerformed()
1039 SequenceGroup sg = getGroup();
1040 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1044 protected void zappoColour_actionPerformed()
1046 getGroup().cs = new ZappoColourScheme();
1050 protected void taylorColour_actionPerformed()
1052 getGroup().cs = new TaylorColourScheme();
1056 protected void hydrophobicityColour_actionPerformed()
1058 getGroup().cs = new HydrophobicColourScheme();
1062 protected void helixColour_actionPerformed()
1064 getGroup().cs = new HelixColourScheme();
1068 protected void strandColour_actionPerformed()
1070 getGroup().cs = new StrandColourScheme();
1074 protected void turnColour_actionPerformed()
1076 getGroup().cs = new TurnColourScheme();
1080 protected void buriedColour_actionPerformed()
1082 getGroup().cs = new BuriedColourScheme();
1086 public void nucleotideMenuItem_actionPerformed()
1088 getGroup().cs = new NucleotideColourScheme();
1092 protected void abovePIDColour_itemStateChanged()
1094 SequenceGroup sg = getGroup();
1100 if (abovePIDColour.getState())
1102 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1103 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1104 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1107 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1109 SliderPanel.showPIDSlider();
1113 // remove PIDColouring
1115 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1122 protected void userDefinedColour_actionPerformed()
1124 new UserDefinedColours(ap, getGroup());
1127 protected void PIDColour_actionPerformed()
1129 SequenceGroup sg = getGroup();
1130 sg.cs = new PIDColourScheme();
1131 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1132 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1136 protected void BLOSUM62Colour_actionPerformed()
1138 SequenceGroup sg = getGroup();
1140 sg.cs = new Blosum62ColourScheme();
1142 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1143 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1148 protected void noColourmenuItem_actionPerformed()
1150 getGroup().cs = null;
1154 protected void conservationMenuItem_itemStateChanged()
1156 SequenceGroup sg = getGroup();
1162 if (conservationMenuItem.getState())
1164 sg.cs.setConservation(Conservation.calculateConservation("Group", sg
1165 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1166 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1168 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1169 SliderPanel.showConservationSlider();
1172 // remove ConservationColouring
1174 sg.cs.setConservation(null);
1180 SequenceGroup getGroup()
1182 SequenceGroup sg = ap.av.getSelectionGroup();
1184 // this method won't add a new group if it already exists
1187 ap.av.getAlignment().addGroup(sg);
1193 void unGroupMenuItem_actionPerformed()
1195 SequenceGroup sg = ap.av.getSelectionGroup();
1196 ap.av.getAlignment().deleteGroup(sg);
1197 ap.av.setSelectionGroup(null);
1198 ap.paintAlignment(true);
1201 void createGroupMenuItem_actionPerformed()
1203 getGroup(); // implicitly create group
1207 public void showColourText_itemStateChanged()
1209 getGroup().setColourText(showColourText.getState());
1213 public void showText_itemStateChanged()
1215 getGroup().setDisplayText(showText.getState());
1219 public void makeReferenceSeq_actionPerformed()
1221 if (!ap.av.getAlignment().hasSeqrep())
1223 // initialise the display flags so the user sees something happen
1224 ap.av.setDisplayReferenceSeq(true);
1225 ap.av.setColourByReferenceSeq(true);
1226 ap.av.getAlignment().setSeqrep(seq);
1230 if (ap.av.getAlignment().getSeqrep() == seq)
1232 ap.av.getAlignment().setSeqrep(null);
1236 ap.av.getAlignment().setSeqrep(seq);
1242 public void showNonconserved_itemStateChanged()
1244 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1248 public void showBoxes_itemStateChanged()
1250 getGroup().setDisplayBoxes(showBoxes.getState());
1254 void hideSequences(boolean representGroup)
1256 ap.av.hideSequences(seq, representGroup);
1260 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1261 * "All" is added first, followed by a separator. Then add any annotation
1262 * types associated with the current selection. Separate menus are built for
1263 * the selected sequence group (if any), and the selected sequence.
1265 * Some annotation rows are always rendered together - these can be identified
1266 * by a common graphGroup property > -1. Only one of each group will be marked
1267 * as visible (to avoid duplication of the display). For such groups we add a
1268 * composite type name, e.g.
1270 * IUPredWS (Long), IUPredWS (Short)
1274 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1275 List<SequenceI> forSequences)
1277 showMenu.removeAll();
1278 hideMenu.removeAll();
1280 final List<String> all = Arrays.asList(new String[] { MessageManager
1281 .getString("label.all") });
1282 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1283 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1285 showMenu.addSeparator();
1286 hideMenu.addSeparator();
1288 final AlignmentAnnotation[] annotations = ap.getAlignment()
1289 .getAlignmentAnnotation();
1292 * Find shown/hidden annotations types, distinguished by source (calcId),
1293 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1294 * the insertion order, which is the order of the annotations on the
1297 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1298 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1299 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1300 AlignmentAnnotationUtils.asList(annotations), forSequences);
1302 for (String calcId : hiddenTypes.keySet())
1304 for (List<String> type : hiddenTypes.get(calcId))
1306 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1310 // grey out 'show annotations' if none are hidden
1311 showMenu.setEnabled(!hiddenTypes.isEmpty());
1313 for (String calcId : shownTypes.keySet())
1315 for (List<String> type : shownTypes.get(calcId))
1317 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1321 // grey out 'hide annotations' if none are shown
1322 hideMenu.setEnabled(!shownTypes.isEmpty());
1326 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1329 * @param showOrHideMenu
1330 * the menu to add to
1331 * @param forSequences
1332 * the sequences whose annotations may be shown or hidden
1337 * if true this is a special label meaning 'All'
1338 * @param actionIsShow
1339 * if true, the select menu item action is to show the annotation
1342 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1343 final List<SequenceI> forSequences, String calcId,
1344 final List<String> types, final boolean allTypes,
1345 final boolean actionIsShow)
1347 String label = types.toString(); // [a, b, c]
1348 label = label.substring(1, label.length() - 1);
1349 final MenuItem item = new MenuItem(label);
1350 item.addActionListener(new java.awt.event.ActionListener()
1353 public void actionPerformed(ActionEvent e)
1355 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1356 types, forSequences, allTypes, actionIsShow);
1360 showOrHideMenu.add(item);