2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.JalviewLite;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.DataSourceType;
39 import jalview.io.FileFormatI;
40 import jalview.io.FileFormats;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.renderer.ResidueShader;
43 import jalview.renderer.ResidueShaderI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.JalviewColourScheme;
50 import jalview.schemes.NucleotideColourScheme;
51 import jalview.schemes.PIDColourScheme;
52 import jalview.schemes.PurinePyrimidineColourScheme;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.MessageManager;
58 import jalview.util.UrlLink;
60 import java.awt.CheckboxMenuItem;
61 import java.awt.Frame;
63 import java.awt.MenuItem;
64 import java.awt.event.ActionEvent;
65 import java.awt.event.ActionListener;
66 import java.awt.event.ItemEvent;
67 import java.awt.event.ItemListener;
68 import java.util.Arrays;
69 import java.util.Collection;
70 import java.util.Collections;
71 import java.util.LinkedHashMap;
72 import java.util.List;
74 import java.util.SortedMap;
75 import java.util.TreeMap;
76 import java.util.Vector;
78 public class APopupMenu extends java.awt.PopupMenu implements
79 ActionListener, ItemListener
81 Menu groupMenu = new Menu();
83 MenuItem editGroupName = new MenuItem();
85 CheckboxMenuItem noColour = new CheckboxMenuItem();
87 protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
89 protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
91 protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
93 protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
95 protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
97 protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
99 protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
101 protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
103 protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
105 protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
107 CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
109 CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
111 protected MenuItem userDefinedColour = new MenuItem();
113 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
115 MenuItem modifyPID = new MenuItem();
117 protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
119 MenuItem modifyConservation = new MenuItem();
121 MenuItem noColourmenuItem = new MenuItem();
123 final AlignmentPanel ap;
125 MenuItem unGroupMenuItem = new MenuItem();
127 MenuItem createGroupMenuItem = new MenuItem();
129 Menu colourMenu = new Menu();
131 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
133 CheckboxMenuItem showText = new CheckboxMenuItem();
135 CheckboxMenuItem showColourText = new CheckboxMenuItem();
137 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
139 Menu seqShowAnnotationsMenu = new Menu(
140 MessageManager.getString("label.show_annotations"));
142 Menu seqHideAnnotationsMenu = new Menu(
143 MessageManager.getString("label.hide_annotations"));
145 MenuItem seqAddReferenceAnnotations = new MenuItem(
146 MessageManager.getString("label.add_reference_annotations"));
148 Menu groupShowAnnotationsMenu = new Menu(
149 MessageManager.getString("label.show_annotations"));
151 Menu groupHideAnnotationsMenu = new Menu(
152 MessageManager.getString("label.hide_annotations"));
154 MenuItem groupAddReferenceAnnotations = new MenuItem(
155 MessageManager.getString("label.add_reference_annotations"));
157 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
159 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
161 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
163 MenuItem toUpper = new MenuItem(
164 MessageManager.getString("label.to_upper_case"));
166 MenuItem toLower = new MenuItem(
167 MessageManager.getString("label.to_lower_case"));
169 MenuItem toggleCase = new MenuItem(
170 MessageManager.getString("label.toggle_case"));
172 Menu outputmenu = new Menu();
174 Menu seqMenu = new Menu();
176 MenuItem pdb = new MenuItem();
178 MenuItem hideSeqs = new MenuItem();
180 MenuItem repGroup = new MenuItem();
182 MenuItem sequenceName = new MenuItem(
183 MessageManager.getString("label.edit_name_description"));
185 MenuItem sequenceFeature = new MenuItem(
186 MessageManager.getString("label.create_sequence_feature"));
188 MenuItem editSequence = new MenuItem(
189 MessageManager.getString("label.edit_sequence"));
191 MenuItem sequenceDetails = new MenuItem(
192 MessageManager.getString("label.sequence_details"));
194 MenuItem selSeqDetails = new MenuItem(
195 MessageManager.getString("label.sequence_details"));
197 MenuItem makeReferenceSeq = new MenuItem();
201 MenuItem revealAll = new MenuItem();
203 MenuItem revealSeq = new MenuItem();
206 * index of sequence to be revealed
208 int revealSeq_index = -1;
210 Menu menu1 = new Menu();
212 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
213 Vector<String> links)
215 // /////////////////////////////////////////////////////////
216 // If this is activated from the sequence panel, the user may want to
217 // edit or annotate a particular residue. Therefore display the residue menu
219 // If from the IDPanel, we must display the sequence menu
220 // ////////////////////////////////////////////////////////
228 } catch (Exception e)
233 for (String ff : FileFormats.getInstance().getWritableFormats(true))
235 MenuItem item = new MenuItem(ff);
237 item.addActionListener(this);
238 outputmenu.add(item);
241 buildAnnotationSubmenus();
243 SequenceGroup sg = ap.av.getSelectionGroup();
244 if (sg != null && sg.getSize() > 0)
246 conservationColour.setEnabled(!sg.isNucleotide());
247 editGroupName.setLabel(MessageManager.formatMessage(
248 "label.name_param", new Object[] { sg.getName() }));
249 showText.setState(sg.getDisplayText());
250 showColourText.setState(sg.getColourText());
251 showBoxes.setState(sg.getDisplayBoxes());
252 displayNonconserved.setState(sg.getShowNonconserved());
253 if (!ap.av.getAlignment().getGroups().contains(sg))
255 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
256 groupMenu.remove(unGroupMenuItem);
260 menu1.setLabel(MessageManager.getString("action.edit_group"));
261 groupMenu.remove(createGroupMenuItem);
264 abovePIDColour.setState(sg.cs.getThreshold() > 0);
265 conservationColour.setState(sg.cs.conservationApplied());
266 modifyPID.setEnabled(abovePIDColour.getState());
267 modifyConservation.setEnabled(conservationColour.getState());
270 setSelectedColour(sg.cs);
278 if (links != null && links.size() > 0)
280 addFeatureLinks(seq, links);
283 // TODO: add group link menu entry here
286 seqMenu.setLabel(seq.getName());
287 if (seq == ap.av.getAlignment().getSeqrep())
289 makeReferenceSeq.setLabel(MessageManager
290 .getString("action.unmark_as_reference"));// Unmark
295 makeReferenceSeq.setLabel(MessageManager
296 .getString("action.set_as_reference")); // );
298 repGroup.setLabel(MessageManager.formatMessage(
299 "label.represent_group_with", new Object[] { seq.getName() }));
306 if (!ap.av.hasHiddenRows())
313 final int index = ap.av.getAlignment().findIndex(seq);
315 if (ap.av.adjustForHiddenSeqs(index)
316 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
318 revealSeq_index = index;
328 * Select the menu item (if any) matching the current colour scheme. This
329 * works by matching the menu item name (not display text) to the canonical
330 * name of the colour scheme.
334 protected void setSelectedColour(ResidueShaderI cs)
336 if (cs == null || cs.getColourScheme() == null)
338 noColour.setState(true);
342 String name = cs.getColourScheme().getSchemeName();
343 for (int i = 0; i < colourMenu.getItemCount(); i++)
345 MenuItem item = colourMenu.getItem(i);
346 if (item instanceof CheckboxMenuItem)
348 if (name.equals(item.getName()))
350 ((CheckboxMenuItem) item).setState(true);
358 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
363 void addFeatureLinks(final SequenceI seq, List<String> links)
365 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
366 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
368 for (String link : links)
370 UrlLink urlLink = null;
373 urlLink = new UrlLink(link);
374 } catch (Exception foo)
376 System.err.println("Exception for URLLink '" + link + "': "
381 if (!urlLink.isValid())
383 System.err.println(urlLink.getInvalidMessage());
387 urlLink.createLinksFromSeq(seq, linkset);
390 addshowLinks(linkMenu, linkset.values());
392 // disable link menu if there are no valid entries
393 if (linkMenu.getItemCount() > 0)
395 linkMenu.setEnabled(true);
399 linkMenu.setEnabled(false);
404 seqMenu.add(linkMenu);
413 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
415 for (List<String> linkstrset : linkset)
417 // split linkstr into label and url
418 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
423 * Build menus for annotation types that may be shown or hidden, and for
424 * 'reference annotations' that may be added to the alignment.
426 private void buildAnnotationSubmenus()
429 * First for the currently selected sequence (if there is one):
431 final List<SequenceI> selectedSequence = (seq == null ? Collections
432 .<SequenceI> emptyList() : Arrays.asList(seq));
433 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
434 seqHideAnnotationsMenu, selectedSequence);
435 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
439 * and repeat for the current selection group (if there is one):
441 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
442 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
444 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
445 groupHideAnnotationsMenu, selectedGroup);
446 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
451 * Determine whether or not to enable 'add reference annotations' menu item.
452 * It is enable if there are any annotations, on any of the selected
453 * sequences, which are not yet on the alignment (visible or not).
456 * @param forSequences
458 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
459 List<SequenceI> forSequences)
461 menuItem.setEnabled(false);
464 * Temporary store to hold distinct calcId / type pairs for the tooltip.
465 * Using TreeMap means calcIds are shown in alphabetical order.
467 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
468 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
469 AlignmentI al = this.ap.av.getAlignment();
470 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
471 tipEntries, candidates, al);
472 if (!candidates.isEmpty())
474 StringBuilder tooltip = new StringBuilder(64);
475 tooltip.append(MessageManager.getString("label.add_annotations_for"));
478 * Found annotations that could be added. Enable the menu item, and
479 * configure its action.
481 menuItem.setEnabled(true);
483 menuItem.addActionListener(new ActionListener()
486 public void actionPerformed(ActionEvent e)
488 addReferenceAnnotations_actionPerformed(candidates);
495 * Add annotations to the sequences and to the alignment.
498 * a map whose keys are sequences on the alignment, and values a list
499 * of annotations to add to each sequence
501 protected void addReferenceAnnotations_actionPerformed(
502 Map<SequenceI, List<AlignmentAnnotation>> candidates)
504 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
505 final AlignmentI alignment = this.ap.getAlignment();
506 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
512 * add a show URL menu item to the given linkMenu
516 * - menu label string
520 private void addshowLink(Menu linkMenu, final String target,
523 addshowLink(linkMenu, target, target, url);
527 * add a show URL menu item to the given linkMenu
531 * - URL target window
533 * - menu label string
537 private void addshowLink(Menu linkMenu, final String target,
538 final String label, final String url)
540 MenuItem item = new MenuItem(label);
541 item.addActionListener(new java.awt.event.ActionListener()
544 public void actionPerformed(ActionEvent e)
546 ap.alignFrame.showURL(url, target);
553 * Actions on selecting / unselecting a checkbox menu item
556 public void itemStateChanged(ItemEvent evt)
558 Object source = evt.getSource();
559 if (source == noColour)
561 noColourmenuItem_actionPerformed();
563 else if (source == clustalColour)
565 clustalColour_actionPerformed();
567 else if (source == BLOSUM62Colour)
569 BLOSUM62Colour_actionPerformed();
571 else if (evt.getSource() == PIDColour)
573 PIDColour_actionPerformed();
575 else if (source == zappoColour)
577 zappoColour_actionPerformed();
579 else if (source == taylorColour)
581 taylorColour_actionPerformed();
583 else if (source == hydrophobicityColour)
585 hydrophobicityColour_actionPerformed();
587 else if (source == helixColour)
589 helixColour_actionPerformed();
591 else if (source == strandColour)
593 strandColour_actionPerformed();
595 else if (source == turnColour)
597 turnColour_actionPerformed();
599 else if (source == buriedColour)
601 buriedColour_actionPerformed();
603 else if (source == nucleotideColour)
605 nucleotideMenuItem_actionPerformed();
607 else if (source == purinePyrimidineColour)
609 purinePyrimidineColour_actionPerformed();
611 else if (source == abovePIDColour)
613 abovePIDColour_itemStateChanged();
615 else if (source == conservationColour)
617 conservationMenuItem_itemStateChanged();
619 else if (source == showColourText)
621 showColourText_itemStateChanged();
623 else if (source == showText)
625 showText_itemStateChanged();
627 else if (source == showBoxes)
629 showBoxes_itemStateChanged();
631 else if (source == displayNonconserved)
633 this.showNonconserved_itemStateChanged();
638 * Actions on clicking a menu item
641 public void actionPerformed(ActionEvent evt)
643 Object source = evt.getSource();
644 if (source == userDefinedColour)
646 userDefinedColour_actionPerformed();
648 else if (source == modifyConservation)
650 conservationMenuItem_itemStateChanged();
652 else if (source == modifyPID)
654 abovePIDColour_itemStateChanged();
656 else if (source == unGroupMenuItem)
658 unGroupMenuItem_actionPerformed();
661 else if (source == createGroupMenuItem)
663 createGroupMenuItem_actionPerformed();
666 else if (source == sequenceName)
670 else if (source == makeReferenceSeq)
672 makeReferenceSeq_actionPerformed();
674 else if (source == sequenceDetails)
676 showSequenceDetails();
678 else if (source == selSeqDetails)
680 showSequenceSelectionDetails();
682 else if (source == pdb)
686 else if (source == hideSeqs)
688 hideSequences(false);
690 else if (source == repGroup)
694 else if (source == revealSeq)
696 ap.av.showSequence(revealSeq_index);
698 else if (source == revealAll)
700 ap.av.showAllHiddenSeqs();
703 else if (source == editGroupName)
705 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
706 getGroup().getDescription(), " Group Name",
707 "Group Description", ap.alignFrame,
708 "Edit Group Name / Description", 500, 100, true);
712 getGroup().setName(dialog.getName().replace(' ', '_'));
713 getGroup().setDescription(dialog.getDescription());
717 else if (source == copy)
719 ap.alignFrame.copy_actionPerformed();
721 else if (source == cut)
723 ap.alignFrame.cut_actionPerformed();
725 else if (source == editSequence)
727 SequenceGroup sg = ap.av.getSelectionGroup();
733 seq = sg.getSequenceAt(0);
736 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
737 sg.getStartRes(), sg.getEndRes() + 1), null,
738 "Edit Sequence ", null,
740 ap.alignFrame, "Edit Sequence", 500, 100, true);
744 EditCommand editCommand = new EditCommand(
745 MessageManager.getString("label.edit_sequences"),
746 Action.REPLACE, dialog.getName().replace(' ',
747 ap.av.getGapCharacter()),
748 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
749 sg.getStartRes(), sg.getEndRes() + 1,
750 ap.av.getAlignment());
752 ap.alignFrame.addHistoryItem(editCommand);
754 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
759 else if (source == toUpper || source == toLower || source == toggleCase)
761 SequenceGroup sg = ap.av.getSelectionGroup();
764 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
765 sg.getStartRes(), sg.getEndRes() + 1);
770 if (source == toggleCase)
772 description = "Toggle Case";
773 caseChange = ChangeCaseCommand.TOGGLE_CASE;
775 else if (source == toUpper)
777 description = "To Upper Case";
778 caseChange = ChangeCaseCommand.TO_UPPER;
782 description = "To Lower Case";
783 caseChange = ChangeCaseCommand.TO_LOWER;
786 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
787 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
788 startEnd, caseChange);
790 ap.alignFrame.addHistoryItem(caseCommand);
792 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
797 else if (source == sequenceFeature)
799 SequenceGroup sg = ap.av.getSelectionGroup();
805 int rsize = 0, gSize = sg.getSize();
806 SequenceI[] rseqs, seqs = new SequenceI[gSize];
807 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
809 for (int i = 0; i < gSize; i++)
811 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
812 int end = sg.findEndRes(sg.getSequenceAt(i));
815 seqs[rsize] = sg.getSequenceAt(i);
816 features[rsize] = new SequenceFeature(null, null, null, start,
821 rseqs = new SequenceI[rsize];
822 tfeatures = new SequenceFeature[rsize];
823 System.arraycopy(seqs, 0, rseqs, 0, rsize);
824 System.arraycopy(features, 0, tfeatures, 0, rsize);
825 features = tfeatures;
828 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
831 ap.alignFrame.sequenceFeatures.setState(true);
832 ap.av.setShowSequenceFeatures(true);
834 ap.highlightSearchResults(null);
844 void outputText(ActionEvent e)
846 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
848 Frame frame = new Frame();
850 JalviewLite.addFrame(frame, MessageManager.formatMessage(
851 "label.selection_output_command",
852 new Object[] { e.getActionCommand() }), 600, 500);
853 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
854 // now returns a full copy of sequence data
855 // TODO consider using getSequenceSelection instead here
857 FileFormatI fileFormat = FileFormats.getInstance().forName(
858 e.getActionCommand());
859 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
860 ap.av.getShowJVSuffix(), ap, true));
864 protected void showSequenceSelectionDetails()
866 createSequenceDetailsReport(ap.av.getSequenceSelection());
869 protected void showSequenceDetails()
871 createSequenceDetailsReport(new SequenceI[] { seq });
874 public void createSequenceDetailsReport(SequenceI[] sequences)
877 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
879 StringBuilder contents = new StringBuilder(128);
880 for (SequenceI seq : sequences)
882 contents.append(MessageManager.formatMessage(
883 "label.annotation_for_displayid",
884 new Object[] { seq.getDisplayId(true) }));
885 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
890 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
891 .getMinMax() : null);
892 contents.append("</p>");
894 Frame frame = new Frame();
896 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
897 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
898 : "Selection"), 600, 500);
899 cap.setText(MessageManager.formatMessage("label.html_content",
900 new Object[] { contents.toString() }));
905 EditNameDialog dialog = new EditNameDialog(seq.getName(),
906 seq.getDescription(), " Sequence Name",
907 "Sequence Description", ap.alignFrame,
908 "Edit Sequence Name / Description", 500, 100, true);
912 seq.setName(dialog.getName());
913 seq.setDescription(dialog.getDescription());
914 ap.paintAlignment(false);
920 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
921 if (pdbs != null && !pdbs.isEmpty())
923 PDBEntry entry = pdbs.firstElement();
925 if (ap.av.applet.jmolAvailable)
927 new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
932 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
933 ap, DataSourceType.URL);
939 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
940 cap.setText(MessageManager.getString("label.paste_pdb_file"));
941 cap.setPDBImport(seq);
942 Frame frame = new Frame();
944 JalviewLite.addFrame(frame, MessageManager.formatMessage(
945 "label.paste_pdb_file_for_sequence",
946 new Object[] { seq.getName() }), 400, 300);
950 private void jbInit() throws Exception
952 groupMenu.setLabel(MessageManager.getString("label.selection"));
953 sequenceFeature.addActionListener(this);
955 editGroupName.addActionListener(this);
956 unGroupMenuItem.setLabel(MessageManager
957 .getString("action.remove_group"));
958 unGroupMenuItem.addActionListener(this);
960 createGroupMenuItem.setLabel(MessageManager
961 .getString("action.create_group"));
962 createGroupMenuItem.addActionListener(this);
964 modifyPID.setEnabled(abovePIDColour.getState());
965 modifyConservation.setEnabled(conservationColour.getState());
966 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
967 showBoxes.setLabel(MessageManager.getString("action.boxes"));
968 showBoxes.setState(true);
969 showBoxes.addItemListener(this);
970 sequenceName.addActionListener(this);
971 sequenceDetails.addActionListener(this);
972 selSeqDetails.addActionListener(this);
973 displayNonconserved.setLabel(MessageManager
974 .getString("label.show_non_conserved"));
975 displayNonconserved.setState(false);
976 displayNonconserved.addItemListener(this);
977 showText.setLabel(MessageManager.getString("action.text"));
978 showText.addItemListener(this);
979 showColourText.setLabel(MessageManager.getString("label.colour_text"));
980 showColourText.addItemListener(this);
981 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
982 seqMenu.setLabel(MessageManager.getString("label.sequence"));
983 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
984 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
985 repGroup.setLabel(MessageManager.formatMessage(
986 "label.represent_group_with", new Object[] { "" }));
987 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
988 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
989 menu1.setLabel(MessageManager.getString("label.group:"));
995 // groupMenu.add(selSeqDetails);
996 groupMenu.add(groupShowAnnotationsMenu);
997 groupMenu.add(groupHideAnnotationsMenu);
998 groupMenu.add(groupAddReferenceAnnotations);
999 groupMenu.add(editMenu);
1000 groupMenu.add(outputmenu);
1001 groupMenu.add(sequenceFeature);
1002 groupMenu.add(createGroupMenuItem);
1003 groupMenu.add(unGroupMenuItem);
1004 groupMenu.add(menu1);
1006 colourMenu.add(noColour);
1007 colourMenu.add(clustalColour);
1008 colourMenu.add(BLOSUM62Colour);
1009 colourMenu.add(PIDColour);
1010 colourMenu.add(zappoColour);
1011 colourMenu.add(taylorColour);
1012 colourMenu.add(hydrophobicityColour);
1013 colourMenu.add(helixColour);
1014 colourMenu.add(strandColour);
1015 colourMenu.add(turnColour);
1016 colourMenu.add(buriedColour);
1017 colourMenu.add(nucleotideColour);
1018 colourMenu.add(purinePyrimidineColour);
1019 colourMenu.add(userDefinedColour);
1020 colourMenu.addSeparator();
1021 colourMenu.add(conservationColour);
1022 colourMenu.add(modifyConservation);
1023 colourMenu.add(abovePIDColour);
1024 colourMenu.add(modifyPID);
1026 noColour.setLabel(MessageManager.getString("label.none"));
1027 noColour.addItemListener(this);
1030 * setName allows setSelectedColour to do its thing
1032 clustalColour.setLabel(MessageManager
1033 .getString("label.colourScheme_clustal"));
1034 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1035 clustalColour.addItemListener(this);
1036 BLOSUM62Colour.setLabel(MessageManager
1037 .getString("label.colourScheme_blosum62"));
1038 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1039 BLOSUM62Colour.addItemListener(this);
1040 PIDColour.setLabel(MessageManager
1041 .getString("label.colourScheme_%_identity"));
1042 PIDColour.setName(JalviewColourScheme.PID.toString());
1043 PIDColour.addItemListener(this);
1044 zappoColour.setLabel(MessageManager
1045 .getString("label.colourScheme_zappo"));
1046 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1047 zappoColour.addItemListener(this);
1048 taylorColour.setLabel(MessageManager
1049 .getString("label.colourScheme_taylor"));
1050 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1051 taylorColour.addItemListener(this);
1052 hydrophobicityColour.setLabel(MessageManager
1053 .getString("label.colourScheme_hydrophobic"));
1054 hydrophobicityColour
1055 .setName(JalviewColourScheme.Hydrophobic.toString());
1056 hydrophobicityColour.addItemListener(this);
1057 helixColour.setLabel(MessageManager
1058 .getString("label.colourScheme_helix_propensity"));
1059 helixColour.setName(JalviewColourScheme.Helix.toString());
1060 helixColour.addItemListener(this);
1061 strandColour.setLabel(MessageManager
1062 .getString("label.colourScheme_strand_propensity"));
1063 strandColour.setName(JalviewColourScheme.Strand.toString());
1064 strandColour.addItemListener(this);
1065 turnColour.setLabel(MessageManager
1066 .getString("label.colourScheme_turn_propensity"));
1067 turnColour.setName(JalviewColourScheme.Turn.toString());
1068 turnColour.addItemListener(this);
1069 buriedColour.setLabel(MessageManager
1070 .getString("label.colourScheme_buried_index"));
1071 buriedColour.setName(JalviewColourScheme.Buried.toString());
1072 buriedColour.addItemListener(this);
1073 nucleotideColour.setLabel(MessageManager
1074 .getString("label.colourScheme_nucleotide"));
1075 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1076 nucleotideColour.addItemListener(this);
1077 purinePyrimidineColour.setLabel(MessageManager
1078 .getString("label.colourScheme_purine/pyrimidine"));
1079 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1081 purinePyrimidineColour.addItemListener(this);
1083 userDefinedColour.setLabel(MessageManager
1084 .getString("action.user_defined"));
1085 userDefinedColour.addActionListener(this);
1087 abovePIDColour.setLabel(MessageManager
1088 .getString("label.above_identity_threshold"));
1089 abovePIDColour.addItemListener(this);
1090 modifyPID.setLabel(MessageManager
1091 .getString("label.modify_identity_threshold"));
1092 modifyPID.addActionListener(this);
1093 conservationColour.setLabel(MessageManager
1094 .getString("action.by_conservation"));
1095 conservationColour.addItemListener(this);
1096 modifyConservation.setLabel(MessageManager
1097 .getString("label.modify_conservation_threshold"));
1098 modifyConservation.addActionListener(this);
1100 PIDColour.addActionListener(this);
1101 BLOSUM62Colour.addActionListener(this);
1104 copy.addActionListener(this);
1106 cut.addActionListener(this);
1108 editMenu.add(editSequence);
1109 editSequence.addActionListener(this);
1111 editMenu.add(toUpper);
1112 toUpper.addActionListener(this);
1113 editMenu.add(toLower);
1114 toLower.addActionListener(this);
1115 editMenu.add(toggleCase);
1116 seqMenu.add(seqShowAnnotationsMenu);
1117 seqMenu.add(seqHideAnnotationsMenu);
1118 seqMenu.add(seqAddReferenceAnnotations);
1119 seqMenu.add(sequenceName);
1120 seqMenu.add(makeReferenceSeq);
1121 // seqMenu.add(sequenceDetails);
1123 if (!ap.av.applet.useXtrnalSviewer)
1127 seqMenu.add(repGroup);
1128 menu1.add(editGroupName);
1129 menu1.add(colourMenu);
1130 menu1.add(showBoxes);
1131 menu1.add(showText);
1132 menu1.add(showColourText);
1133 menu1.add(displayNonconserved);
1134 toggleCase.addActionListener(this);
1135 pdb.addActionListener(this);
1136 hideSeqs.addActionListener(this);
1137 repGroup.addActionListener(this);
1138 revealAll.addActionListener(this);
1139 revealSeq.addActionListener(this);
1140 makeReferenceSeq.addActionListener(this);
1145 ap.paintAlignment(true);
1148 protected void clustalColour_actionPerformed()
1150 SequenceGroup sg = getGroup();
1151 sg.cs = new ResidueShader(new ClustalxColourScheme(sg,
1152 ap.av.getHiddenRepSequences()));
1156 protected void zappoColour_actionPerformed()
1158 getGroup().cs = new ResidueShader(new ZappoColourScheme());
1162 protected void taylorColour_actionPerformed()
1164 getGroup().cs = new ResidueShader(new TaylorColourScheme());
1168 protected void hydrophobicityColour_actionPerformed()
1170 getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
1174 protected void helixColour_actionPerformed()
1176 getGroup().cs = new ResidueShader(new HelixColourScheme());
1180 protected void strandColour_actionPerformed()
1182 getGroup().cs = new ResidueShader(new StrandColourScheme());
1186 protected void turnColour_actionPerformed()
1188 getGroup().cs = new ResidueShader(new TurnColourScheme());
1192 protected void buriedColour_actionPerformed()
1194 getGroup().cs = new ResidueShader(new BuriedColourScheme());
1198 public void nucleotideMenuItem_actionPerformed()
1200 getGroup().cs = new ResidueShader(new NucleotideColourScheme());
1204 public void purinePyrimidineColour_actionPerformed()
1206 getGroup().cs = new ResidueShader(
1207 new PurinePyrimidineColourScheme());
1211 protected void abovePIDColour_itemStateChanged()
1213 SequenceGroup sg = getGroup();
1219 if (abovePIDColour.getState())
1221 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1222 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1223 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1226 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1228 SliderPanel.showPIDSlider();
1232 // remove PIDColouring
1234 SliderPanel.hidePIDSlider();
1235 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1237 modifyPID.setEnabled(abovePIDColour.getState());
1241 protected void userDefinedColour_actionPerformed()
1243 new UserDefinedColours(ap, getGroup());
1246 protected void PIDColour_actionPerformed()
1248 SequenceGroup sg = getGroup();
1249 sg.cs = new ResidueShader(new PIDColourScheme());
1250 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1251 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1255 protected void BLOSUM62Colour_actionPerformed()
1257 SequenceGroup sg = getGroup();
1259 sg.cs = new ResidueShader(new Blosum62ColourScheme());
1261 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1262 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1267 protected void noColourmenuItem_actionPerformed()
1269 getGroup().cs = null;
1273 protected void conservationMenuItem_itemStateChanged()
1275 SequenceGroup sg = getGroup();
1281 if (conservationColour.getState())
1283 Conservation conservation = Conservation.calculateConservation(
1285 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1286 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1288 sg.getGroupColourScheme().setConservation(conservation);
1289 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1290 SliderPanel.showConservationSlider();
1293 // remove ConservationColouring
1295 SliderPanel.hideConservationSlider();
1296 sg.cs.setConservation(null);
1298 modifyConservation.setEnabled(conservationColour.getState());
1302 SequenceGroup getGroup()
1304 SequenceGroup sg = ap.av.getSelectionGroup();
1306 // this method won't add a new group if it already exists
1309 ap.av.getAlignment().addGroup(sg);
1315 void unGroupMenuItem_actionPerformed()
1317 SequenceGroup sg = ap.av.getSelectionGroup();
1318 ap.av.getAlignment().deleteGroup(sg);
1319 ap.av.setSelectionGroup(null);
1320 ap.paintAlignment(true);
1323 void createGroupMenuItem_actionPerformed()
1325 getGroup(); // implicitly create group
1329 public void showColourText_itemStateChanged()
1331 getGroup().setColourText(showColourText.getState());
1335 public void showText_itemStateChanged()
1337 getGroup().setDisplayText(showText.getState());
1341 public void makeReferenceSeq_actionPerformed()
1343 if (!ap.av.getAlignment().hasSeqrep())
1345 // initialise the display flags so the user sees something happen
1346 ap.av.setDisplayReferenceSeq(true);
1347 ap.av.setColourByReferenceSeq(true);
1348 ap.av.getAlignment().setSeqrep(seq);
1352 if (ap.av.getAlignment().getSeqrep() == seq)
1354 ap.av.getAlignment().setSeqrep(null);
1358 ap.av.getAlignment().setSeqrep(seq);
1364 public void showNonconserved_itemStateChanged()
1366 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1370 public void showBoxes_itemStateChanged()
1372 getGroup().setDisplayBoxes(showBoxes.getState());
1376 void hideSequences(boolean representGroup)
1378 ap.av.hideSequences(seq, representGroup);
1382 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1383 * "All" is added first, followed by a separator. Then add any annotation
1384 * types associated with the current selection. Separate menus are built for
1385 * the selected sequence group (if any), and the selected sequence.
1387 * Some annotation rows are always rendered together - these can be identified
1388 * by a common graphGroup property > -1. Only one of each group will be marked
1389 * as visible (to avoid duplication of the display). For such groups we add a
1390 * composite type name, e.g.
1392 * IUPredWS (Long), IUPredWS (Short)
1396 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1397 List<SequenceI> forSequences)
1399 showMenu.removeAll();
1400 hideMenu.removeAll();
1402 final List<String> all = Arrays.asList(new String[] { MessageManager
1403 .getString("label.all") });
1404 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1405 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1407 showMenu.addSeparator();
1408 hideMenu.addSeparator();
1410 final AlignmentAnnotation[] annotations = ap.getAlignment()
1411 .getAlignmentAnnotation();
1414 * Find shown/hidden annotations types, distinguished by source (calcId),
1415 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1416 * the insertion order, which is the order of the annotations on the
1419 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1420 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1421 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1422 AlignmentAnnotationUtils.asList(annotations), forSequences);
1424 for (String calcId : hiddenTypes.keySet())
1426 for (List<String> type : hiddenTypes.get(calcId))
1428 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1432 // grey out 'show annotations' if none are hidden
1433 showMenu.setEnabled(!hiddenTypes.isEmpty());
1435 for (String calcId : shownTypes.keySet())
1437 for (List<String> type : shownTypes.get(calcId))
1439 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1443 // grey out 'hide annotations' if none are shown
1444 hideMenu.setEnabled(!shownTypes.isEmpty());
1448 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1451 * @param showOrHideMenu
1452 * the menu to add to
1453 * @param forSequences
1454 * the sequences whose annotations may be shown or hidden
1459 * if true this is a special label meaning 'All'
1460 * @param actionIsShow
1461 * if true, the select menu item action is to show the annotation
1464 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1465 final List<SequenceI> forSequences, String calcId,
1466 final List<String> types, final boolean allTypes,
1467 final boolean actionIsShow)
1469 String label = types.toString(); // [a, b, c]
1470 label = label.substring(1, label.length() - 1);
1471 final MenuItem item = new MenuItem(label);
1472 item.addActionListener(new java.awt.event.ActionListener()
1475 public void actionPerformed(ActionEvent e)
1477 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1478 types, forSequences, allTypes, actionIsShow);
1482 showOrHideMenu.add(item);