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.DBRefEntry;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.SequenceAnnotationReport;
39 import jalview.schemes.Blosum62ColourScheme;
40 import jalview.schemes.BuriedColourScheme;
41 import jalview.schemes.ClustalxColourScheme;
42 import jalview.schemes.HelixColourScheme;
43 import jalview.schemes.HydrophobicColourScheme;
44 import jalview.schemes.NucleotideColourScheme;
45 import jalview.schemes.PIDColourScheme;
46 import jalview.schemes.ResidueProperties;
47 import jalview.schemes.StrandColourScheme;
48 import jalview.schemes.TaylorColourScheme;
49 import jalview.schemes.TurnColourScheme;
50 import jalview.schemes.ZappoColourScheme;
51 import jalview.util.MessageManager;
52 import jalview.util.UrlLink;
54 import java.awt.CheckboxMenuItem;
55 import java.awt.Frame;
57 import java.awt.MenuItem;
58 import java.awt.event.ActionEvent;
59 import java.awt.event.ActionListener;
60 import java.awt.event.ItemEvent;
61 import java.awt.event.ItemListener;
62 import java.util.Arrays;
63 import java.util.Collections;
64 import java.util.LinkedHashMap;
65 import java.util.List;
67 import java.util.TreeMap;
68 import java.util.Vector;
70 public class APopupMenu extends java.awt.PopupMenu implements
71 ActionListener, ItemListener
73 Menu groupMenu = new Menu();
75 MenuItem editGroupName = new MenuItem();
77 protected MenuItem clustalColour = new MenuItem();
79 protected MenuItem zappoColour = new MenuItem();
81 protected MenuItem taylorColour = new MenuItem();
83 protected MenuItem hydrophobicityColour = new MenuItem();
85 protected MenuItem helixColour = new MenuItem();
87 protected MenuItem strandColour = new MenuItem();
89 protected MenuItem turnColour = new MenuItem();
91 protected MenuItem buriedColour = new MenuItem();
93 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
95 protected MenuItem userDefinedColour = new MenuItem();
97 protected MenuItem PIDColour = new MenuItem();
99 protected MenuItem BLOSUM62Colour = new MenuItem();
101 MenuItem noColourmenuItem = new MenuItem();
103 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
105 final AlignmentPanel ap;
107 MenuItem unGroupMenuItem = new MenuItem();
109 MenuItem createGroupMenuItem = new MenuItem();
111 MenuItem nucleotideMenuItem = new MenuItem();
113 Menu colourMenu = new Menu();
115 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
117 CheckboxMenuItem showText = new CheckboxMenuItem();
119 CheckboxMenuItem showColourText = new CheckboxMenuItem();
121 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
123 Menu seqShowAnnotationsMenu = new Menu(
124 MessageManager.getString("label.show_annotations"));
126 Menu seqHideAnnotationsMenu = new Menu(
127 MessageManager.getString("label.hide_annotations"));
129 MenuItem seqAddReferenceAnnotations = new MenuItem(
130 MessageManager.getString("label.add_reference_annotations"));
132 Menu groupShowAnnotationsMenu = new Menu(
133 MessageManager.getString("label.show_annotations"));
135 Menu groupHideAnnotationsMenu = new Menu(
136 MessageManager.getString("label.hide_annotations"));
138 MenuItem groupAddReferenceAnnotations = new MenuItem(
139 MessageManager.getString("label.add_reference_annotations"));
141 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
143 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
145 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
147 MenuItem toUpper = new MenuItem(
148 MessageManager.getString("label.to_upper_case"));
150 MenuItem toLower = new MenuItem(
151 MessageManager.getString("label.to_lower_case"));
153 MenuItem toggleCase = new MenuItem(
154 MessageManager.getString("label.toggle_case"));
156 Menu outputmenu = new Menu();
158 Menu seqMenu = new Menu();
160 MenuItem pdb = new MenuItem();
162 MenuItem hideSeqs = new MenuItem();
164 MenuItem repGroup = new MenuItem();
166 MenuItem sequenceName = new MenuItem(
167 MessageManager.getString("label.edit_name_description"));
169 MenuItem sequenceFeature = new MenuItem(
170 MessageManager.getString("label.create_sequence_feature"));
172 MenuItem editSequence = new MenuItem(
173 MessageManager.getString("label.edit_sequence"));
175 MenuItem sequenceDetails = new MenuItem(
176 MessageManager.getString("label.sequence_details"));
178 MenuItem selSeqDetails = new MenuItem(
179 MessageManager.getString("label.sequence_details"));
181 MenuItem makeReferenceSeq = new MenuItem();
185 MenuItem revealAll = new MenuItem();
187 MenuItem revealSeq = new MenuItem();
190 * index of sequence to be revealed
192 int revealSeq_index = -1;
194 Menu menu1 = new Menu();
196 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
197 Vector<String> links)
199 // /////////////////////////////////////////////////////////
200 // If this is activated from the sequence panel, the user may want to
201 // edit or annotate a particular residue. Therefore display the residue menu
203 // If from the IDPanel, we must display the sequence menu
204 // ////////////////////////////////////////////////////////
212 } catch (Exception e)
217 for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
219 MenuItem item = new MenuItem(
220 jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
222 item.addActionListener(this);
223 outputmenu.add(item);
226 buildAnnotationSubmenus();
228 SequenceGroup sg = ap.av.getSelectionGroup();
229 if (sg != null && sg.getSize() > 0)
231 editGroupName.setLabel(MessageManager.formatMessage(
232 "label.name_param", new Object[] { sg.getName() }));
233 showText.setState(sg.getDisplayText());
234 showColourText.setState(sg.getColourText());
235 showBoxes.setState(sg.getDisplayBoxes());
236 displayNonconserved.setState(sg.getShowNonconserved());
237 if (!ap.av.getAlignment().getGroups().contains(sg))
239 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
240 groupMenu.remove(unGroupMenuItem);
244 menu1.setLabel(MessageManager.getString("action.edit_group"));
245 groupMenu.remove(createGroupMenuItem);
255 if (links != null && links.size() > 0)
257 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
258 for (int i = 0; i < links.size(); i++)
260 String link = links.elementAt(i);
261 UrlLink urlLink = new UrlLink(link);
262 if (!urlLink.isValid())
264 System.err.println(urlLink.getInvalidMessage());
267 final String target = urlLink.getTarget(); // link.substring(0,
268 // link.indexOf("|"));
269 final String label = urlLink.getLabel();
270 if (seq != null && urlLink.isDynamic())
273 // collect matching db-refs
274 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
275 seq.getDBRefs(), new String[] { target });
276 // collect id string too
277 String id = seq.getName();
278 String descr = seq.getDescription();
279 if (descr != null && descr.length() < 1)
285 for (int r = 0; r < dbr.length; r++)
287 if (id != null && dbr[r].getAccessionId().equals(id))
289 // suppress duplicate link creation for the bare sequence ID
290 // string with this link
293 // create Bare ID link for this RUL
294 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
298 for (int u = 0; u < urls.length; u += 2)
300 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
307 // create Bare ID link for this RUL
308 String[] urls = urlLink.makeUrls(id, true);
311 for (int u = 0; u < urls.length; u += 2)
313 addshowLink(linkMenu, label, urls[u + 1]);
316 // addshowLink(linkMenu, target, url_pref + id + url_suff);
318 // Now construct URLs from description but only try to do it for regex
320 if (descr != null && urlLink.getRegexReplace() != null)
322 // create link for this URL from description only if regex matches
323 String[] urls = urlLink.makeUrls(descr, true);
326 for (int u = 0; u < urls.length; u += 2)
328 addshowLink(linkMenu, label, urls[u + 1]);
335 addshowLink(linkMenu, target, urlLink.getUrl_prefix()); // link.substring(link.lastIndexOf("|")+1));
340 * if (link.indexOf("$SEQUENCE_ID$") > -1) { // Substitute SEQUENCE_ID
341 * string and any matching database reference accessions String url_pref
342 * = link.substring(link.indexOf("|") + 1,
343 * link.indexOf("$SEQUENCE_ID$"));
345 * String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
346 * // collect matching db-refs DBRefEntry[] dbr =
347 * jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new
348 * String[]{target}); // collect id string too String id =
349 * seq.getName(); if (id.indexOf("|") > -1) { id =
350 * id.substring(id.lastIndexOf("|") + 1); } if (dbr!=null) { for (int
351 * r=0;r<dbr.length; r++) { if (dbr[r].getAccessionId().equals(id)) { //
352 * suppress duplicate link creation for the bare sequence ID string with
353 * this link id = null; } addshowLink(linkMenu,
354 * dbr[r].getSource()+"|"+dbr[r].getAccessionId(), target,
355 * url_pref+dbr[r].getAccessionId()+url_suff); } } if (id!=null) { //
356 * create Bare ID link for this RUL addshowLink(linkMenu, target,
357 * url_pref + id + url_suff); } } else { addshowLink(linkMenu, target,
358 * link.substring(link.lastIndexOf("|")+1)); }
361 if (linkMenu.getItemCount() > 0)
365 seqMenu.add(linkMenu);
373 // TODO: add group link menu entry here
376 seqMenu.setLabel(seq.getName());
377 if (seq == ap.av.getAlignment().getSeqrep())
379 makeReferenceSeq.setLabel(MessageManager
380 .getString("action.unmark_as_reference"));// Unmark
385 makeReferenceSeq.setLabel(MessageManager
386 .getString("action.set_as_reference")); // );
388 repGroup.setLabel(MessageManager.formatMessage(
389 "label.represent_group_with", new Object[] { seq.getName() }));
396 if (!ap.av.hasHiddenRows())
403 final int index = ap.av.getAlignment().findIndex(seq);
405 if (ap.av.adjustForHiddenSeqs(index)
406 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
408 revealSeq_index = index;
418 * Build menus for annotation types that may be shown or hidden, and for
419 * 'reference annotations' that may be added to the alignment.
421 private void buildAnnotationSubmenus()
424 * First for the currently selected sequence (if there is one):
426 final List<SequenceI> selectedSequence = (seq == null ? Collections
427 .<SequenceI> emptyList() : Arrays.asList(seq));
428 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
429 seqHideAnnotationsMenu, selectedSequence);
430 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
434 * and repeat for the current selection group (if there is one):
436 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
437 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
439 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
440 groupHideAnnotationsMenu, selectedGroup);
441 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
446 * Determine whether or not to enable 'add reference annotations' menu item.
447 * It is enable if there are any annotations, on any of the selected
448 * sequences, which are not yet on the alignment (visible or not).
451 * @param forSequences
453 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
454 List<SequenceI> forSequences)
456 menuItem.setEnabled(false);
459 * Temporary store to hold distinct calcId / type pairs for the tooltip.
460 * Using TreeMap means calcIds are shown in alphabetical order.
462 Map<String, String> tipEntries = new TreeMap<String, String>();
463 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
464 AlignmentI al = this.ap.av.getAlignment();
465 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
466 tipEntries, candidates, al);
467 if (!candidates.isEmpty())
469 StringBuilder tooltip = new StringBuilder(64);
470 tooltip.append(MessageManager.getString("label.add_annotations_for"));
473 * Found annotations that could be added. Enable the menu item, and
474 * configure its action.
476 menuItem.setEnabled(true);
478 menuItem.addActionListener(new ActionListener()
481 public void actionPerformed(ActionEvent e)
483 addReferenceAnnotations_actionPerformed(candidates);
490 * Add annotations to the sequences and to the alignment.
493 * a map whose keys are sequences on the alignment, and values a list
494 * of annotations to add to each sequence
496 protected void addReferenceAnnotations_actionPerformed(
497 Map<SequenceI, List<AlignmentAnnotation>> candidates)
499 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
500 final AlignmentI alignment = this.ap.getAlignment();
501 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
507 * add a show URL menu item to the given linkMenu
511 * - menu label string
515 private void addshowLink(Menu linkMenu, final String target,
518 addshowLink(linkMenu, target, target, url);
522 * add a show URL menu item to the given linkMenu
526 * - URL target window
528 * - menu label string
532 private void addshowLink(Menu linkMenu, final String target,
533 final String label, final String url)
535 MenuItem item = new MenuItem(label);
536 item.addActionListener(new java.awt.event.ActionListener()
539 public void actionPerformed(ActionEvent e)
541 ap.alignFrame.showURL(url, target);
548 public void itemStateChanged(ItemEvent evt)
550 if (evt.getSource() == abovePIDColour)
552 abovePIDColour_itemStateChanged();
554 else if (evt.getSource() == showColourText)
556 showColourText_itemStateChanged();
558 else if (evt.getSource() == showText)
560 showText_itemStateChanged();
562 else if (evt.getSource() == showBoxes)
564 showBoxes_itemStateChanged();
566 else if (evt.getSource() == displayNonconserved)
568 this.showNonconserved_itemStateChanged();
573 public void actionPerformed(ActionEvent evt)
575 Object source = evt.getSource();
576 if (source == clustalColour)
578 clustalColour_actionPerformed();
580 else if (source == zappoColour)
582 zappoColour_actionPerformed();
584 else if (source == taylorColour)
586 taylorColour_actionPerformed();
588 else if (source == hydrophobicityColour)
590 hydrophobicityColour_actionPerformed();
592 else if (source == helixColour)
594 helixColour_actionPerformed();
596 else if (source == strandColour)
598 strandColour_actionPerformed();
600 else if (source == turnColour)
602 turnColour_actionPerformed();
604 else if (source == buriedColour)
606 buriedColour_actionPerformed();
608 else if (source == nucleotideMenuItem)
610 nucleotideMenuItem_actionPerformed();
613 else if (source == userDefinedColour)
615 userDefinedColour_actionPerformed();
617 else if (source == PIDColour)
619 PIDColour_actionPerformed();
621 else if (source == BLOSUM62Colour)
623 BLOSUM62Colour_actionPerformed();
625 else if (source == noColourmenuItem)
627 noColourmenuItem_actionPerformed();
629 else if (source == conservationMenuItem)
631 conservationMenuItem_itemStateChanged();
633 else if (source == unGroupMenuItem)
635 unGroupMenuItem_actionPerformed();
638 else if (source == createGroupMenuItem)
640 createGroupMenuItem_actionPerformed();
643 else if (source == sequenceName)
647 else if (source == makeReferenceSeq)
649 makeReferenceSeq_actionPerformed();
651 else if (source == sequenceDetails)
653 showSequenceDetails();
655 else if (source == selSeqDetails)
657 showSequenceSelectionDetails();
659 else if (source == pdb)
663 else if (source == hideSeqs)
665 hideSequences(false);
667 else if (source == repGroup)
671 else if (source == revealSeq)
673 ap.av.showSequence(revealSeq_index);
675 else if (source == revealAll)
677 ap.av.showAllHiddenSeqs();
680 else if (source == editGroupName)
682 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
683 getGroup().getDescription(), " Group Name",
684 "Group Description", ap.alignFrame,
685 "Edit Group Name / Description", 500, 100, true);
689 getGroup().setName(dialog.getName().replace(' ', '_'));
690 getGroup().setDescription(dialog.getDescription());
694 else if (source == copy)
696 ap.alignFrame.copy_actionPerformed();
698 else if (source == cut)
700 ap.alignFrame.cut_actionPerformed();
702 else if (source == editSequence)
704 SequenceGroup sg = ap.av.getSelectionGroup();
710 seq = sg.getSequenceAt(0);
713 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
714 sg.getStartRes(), sg.getEndRes() + 1), null,
715 "Edit Sequence ", null,
717 ap.alignFrame, "Edit Sequence", 500, 100, true);
721 EditCommand editCommand = new EditCommand(
722 MessageManager.getString("label.edit_sequences"),
723 Action.REPLACE, dialog.getName().replace(' ',
724 ap.av.getGapCharacter()),
725 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
726 sg.getStartRes(), sg.getEndRes() + 1,
727 ap.av.getAlignment());
729 ap.alignFrame.addHistoryItem(editCommand);
731 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
736 else if (source == toUpper || source == toLower || source == toggleCase)
738 SequenceGroup sg = ap.av.getSelectionGroup();
741 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
742 sg.getStartRes(), sg.getEndRes() + 1);
747 if (source == toggleCase)
749 description = "Toggle Case";
750 caseChange = ChangeCaseCommand.TOGGLE_CASE;
752 else if (source == toUpper)
754 description = "To Upper Case";
755 caseChange = ChangeCaseCommand.TO_UPPER;
759 description = "To Lower Case";
760 caseChange = ChangeCaseCommand.TO_LOWER;
763 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
764 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
765 startEnd, caseChange);
767 ap.alignFrame.addHistoryItem(caseCommand);
769 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
774 else if (source == sequenceFeature)
776 SequenceGroup sg = ap.av.getSelectionGroup();
782 int rsize = 0, gSize = sg.getSize();
783 SequenceI[] rseqs, seqs = new SequenceI[gSize];
784 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
786 for (int i = 0; i < gSize; i++)
788 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
789 int end = sg.findEndRes(sg.getSequenceAt(i));
792 seqs[rsize] = sg.getSequenceAt(i);
793 features[rsize] = new SequenceFeature(null, null, null, start,
798 rseqs = new SequenceI[rsize];
799 tfeatures = new SequenceFeature[rsize];
800 System.arraycopy(seqs, 0, rseqs, 0, rsize);
801 System.arraycopy(features, 0, tfeatures, 0, rsize);
802 features = tfeatures;
805 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
808 ap.alignFrame.sequenceFeatures.setState(true);
809 ap.av.setShowSequenceFeatures(true);
811 ap.highlightSearchResults(null);
821 void outputText(ActionEvent e)
823 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
825 Frame frame = new Frame();
827 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
828 "label.selection_output_command",
829 new Object[] { e.getActionCommand() }), 600, 500);
830 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
831 // now returns a full copy of sequence data
832 // TODO consider using getSequenceSelection instead here
834 cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
835 e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true));
839 protected void showSequenceSelectionDetails()
841 createSequenceDetailsReport(ap.av.getSequenceSelection());
844 protected void showSequenceDetails()
846 createSequenceDetailsReport(new SequenceI[] { seq });
849 public void createSequenceDetailsReport(SequenceI[] sequences)
852 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
854 StringBuffer contents = new StringBuffer();
855 for (SequenceI seq : sequences)
857 contents.append(MessageManager.formatMessage(
858 "label.annotation_for_displayid",
859 new Object[] { seq.getDisplayId(true) }));
860 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
866 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
867 .getMinMax() : null);
868 contents.append("</p>");
870 Frame frame = new Frame();
872 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
873 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
874 : "Selection"), 600, 500);
875 cap.setText(MessageManager.formatMessage("label.html_content",
876 new Object[] { contents.toString() }));
881 EditNameDialog dialog = new EditNameDialog(seq.getName(),
882 seq.getDescription(), " Sequence Name",
883 "Sequence Description", ap.alignFrame,
884 "Edit Sequence Name / Description", 500, 100, true);
888 seq.setName(dialog.getName());
889 seq.setDescription(dialog.getDescription());
890 ap.paintAlignment(false);
896 if (seq.getAllPDBEntries() != null)
898 PDBEntry entry = seq.getAllPDBEntries().firstElement();
900 if (ap.av.applet.jmolAvailable)
902 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
903 null, ap, AppletFormatAdapter.URL);
907 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
908 ap, AppletFormatAdapter.URL);
914 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
915 cap.setText(MessageManager.getString("label.paste_pdb_file"));
916 cap.setPDBImport(seq);
917 Frame frame = new Frame();
919 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
920 "label.paste_pdb_file_for_sequence",
921 new Object[] { seq.getName() }), 400, 300);
925 private void jbInit() throws Exception
927 groupMenu.setLabel(MessageManager.getString("label.selection"));
928 sequenceFeature.addActionListener(this);
930 editGroupName.addActionListener(this);
931 unGroupMenuItem.setLabel(MessageManager
932 .getString("action.remove_group"));
933 unGroupMenuItem.addActionListener(this);
935 createGroupMenuItem.setLabel(MessageManager
936 .getString("action.create_group"));
937 createGroupMenuItem.addActionListener(this);
939 nucleotideMenuItem.setLabel(MessageManager
940 .getString("label.nucleotide"));
941 nucleotideMenuItem.addActionListener(this);
942 conservationMenuItem.addItemListener(this);
943 abovePIDColour.addItemListener(this);
944 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
945 showBoxes.setLabel(MessageManager.getString("action.boxes"));
946 showBoxes.setState(true);
947 showBoxes.addItemListener(this);
948 sequenceName.addActionListener(this);
949 sequenceDetails.addActionListener(this);
950 selSeqDetails.addActionListener(this);
951 displayNonconserved.setLabel(MessageManager
952 .getString("label.show_non_conversed"));
953 displayNonconserved.setState(false);
954 displayNonconserved.addItemListener(this);
955 showText.setLabel(MessageManager.getString("action.text"));
956 showText.addItemListener(this);
957 showColourText.setLabel(MessageManager.getString("label.colour_text"));
958 showColourText.addItemListener(this);
959 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
960 seqMenu.setLabel(MessageManager.getString("label.sequence"));
961 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
962 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
963 repGroup.setLabel(MessageManager.formatMessage(
964 "label.represent_group_with", new Object[] { "" }));
965 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
966 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
967 menu1.setLabel(MessageManager.getString("label.group") + ":");
973 // groupMenu.add(selSeqDetails);
974 groupMenu.add(groupShowAnnotationsMenu);
975 groupMenu.add(groupHideAnnotationsMenu);
976 groupMenu.add(groupAddReferenceAnnotations);
977 groupMenu.add(editMenu);
978 groupMenu.add(outputmenu);
979 groupMenu.add(sequenceFeature);
980 groupMenu.add(createGroupMenuItem);
981 groupMenu.add(unGroupMenuItem);
982 groupMenu.add(menu1);
984 colourMenu.add(noColourmenuItem);
985 colourMenu.add(clustalColour);
986 colourMenu.add(BLOSUM62Colour);
987 colourMenu.add(PIDColour);
988 colourMenu.add(zappoColour);
989 colourMenu.add(taylorColour);
990 colourMenu.add(hydrophobicityColour);
991 colourMenu.add(helixColour);
992 colourMenu.add(strandColour);
993 colourMenu.add(turnColour);
994 colourMenu.add(buriedColour);
995 colourMenu.add(nucleotideMenuItem);
996 colourMenu.add(userDefinedColour);
997 colourMenu.addSeparator();
998 colourMenu.add(abovePIDColour);
999 colourMenu.add(conservationMenuItem);
1001 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
1002 noColourmenuItem.addActionListener(this);
1004 clustalColour.setLabel(MessageManager
1005 .getString("label.clustalx_colours"));
1006 clustalColour.addActionListener(this);
1007 zappoColour.setLabel(MessageManager.getString("label.zappo"));
1008 zappoColour.addActionListener(this);
1009 taylorColour.setLabel(MessageManager.getString("label.taylor"));
1010 taylorColour.addActionListener(this);
1011 hydrophobicityColour.setLabel(MessageManager
1012 .getString("label.hydrophobicity"));
1013 hydrophobicityColour.addActionListener(this);
1015 .setLabel(MessageManager.getString("label.helix_propensity"));
1016 helixColour.addActionListener(this);
1017 strandColour.setLabel(MessageManager
1018 .getString("label.strand_propensity"));
1019 strandColour.addActionListener(this);
1020 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
1021 turnColour.addActionListener(this);
1022 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
1023 buriedColour.addActionListener(this);
1024 abovePIDColour.setLabel(MessageManager
1025 .getString("label.above_identity_percentage"));
1027 userDefinedColour.setLabel(MessageManager
1028 .getString("action.user_defined"));
1029 userDefinedColour.addActionListener(this);
1030 PIDColour.setLabel(MessageManager
1031 .getString("label.percentage_identity"));
1032 PIDColour.addActionListener(this);
1033 BLOSUM62Colour.setLabel("BLOSUM62");
1034 BLOSUM62Colour.addActionListener(this);
1035 conservationMenuItem.setLabel(MessageManager
1036 .getString("label.conservation"));
1039 copy.addActionListener(this);
1041 cut.addActionListener(this);
1043 editMenu.add(editSequence);
1044 editSequence.addActionListener(this);
1046 editMenu.add(toUpper);
1047 toUpper.addActionListener(this);
1048 editMenu.add(toLower);
1049 toLower.addActionListener(this);
1050 editMenu.add(toggleCase);
1051 seqMenu.add(seqShowAnnotationsMenu);
1052 seqMenu.add(seqHideAnnotationsMenu);
1053 seqMenu.add(seqAddReferenceAnnotations);
1054 seqMenu.add(sequenceName);
1055 seqMenu.add(makeReferenceSeq);
1056 // seqMenu.add(sequenceDetails);
1058 if (!ap.av.applet.useXtrnalSviewer)
1062 seqMenu.add(repGroup);
1063 menu1.add(editGroupName);
1064 menu1.add(colourMenu);
1065 menu1.add(showBoxes);
1066 menu1.add(showText);
1067 menu1.add(showColourText);
1068 menu1.add(displayNonconserved);
1069 toggleCase.addActionListener(this);
1070 pdb.addActionListener(this);
1071 hideSeqs.addActionListener(this);
1072 repGroup.addActionListener(this);
1073 revealAll.addActionListener(this);
1074 revealSeq.addActionListener(this);
1075 makeReferenceSeq.addActionListener(this);
1080 ap.paintAlignment(true);
1083 protected void clustalColour_actionPerformed()
1085 SequenceGroup sg = getGroup();
1086 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1090 protected void zappoColour_actionPerformed()
1092 getGroup().cs = new ZappoColourScheme();
1096 protected void taylorColour_actionPerformed()
1098 getGroup().cs = new TaylorColourScheme();
1102 protected void hydrophobicityColour_actionPerformed()
1104 getGroup().cs = new HydrophobicColourScheme();
1108 protected void helixColour_actionPerformed()
1110 getGroup().cs = new HelixColourScheme();
1114 protected void strandColour_actionPerformed()
1116 getGroup().cs = new StrandColourScheme();
1120 protected void turnColour_actionPerformed()
1122 getGroup().cs = new TurnColourScheme();
1126 protected void buriedColour_actionPerformed()
1128 getGroup().cs = new BuriedColourScheme();
1132 public void nucleotideMenuItem_actionPerformed()
1134 getGroup().cs = new NucleotideColourScheme();
1138 protected void abovePIDColour_itemStateChanged()
1140 SequenceGroup sg = getGroup();
1146 if (abovePIDColour.getState())
1148 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1149 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1150 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1153 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1155 SliderPanel.showPIDSlider();
1159 // remove PIDColouring
1161 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1168 protected void userDefinedColour_actionPerformed()
1170 new UserDefinedColours(ap, getGroup());
1173 protected void PIDColour_actionPerformed()
1175 SequenceGroup sg = getGroup();
1176 sg.cs = new PIDColourScheme();
1177 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1178 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1182 protected void BLOSUM62Colour_actionPerformed()
1184 SequenceGroup sg = getGroup();
1186 sg.cs = new Blosum62ColourScheme();
1188 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1189 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1194 protected void noColourmenuItem_actionPerformed()
1196 getGroup().cs = null;
1200 protected void conservationMenuItem_itemStateChanged()
1202 SequenceGroup sg = getGroup();
1208 if (conservationMenuItem.getState())
1211 sg.cs.setConservation(Conservation.calculateConservation("Group",
1212 ResidueProperties.propHash, 3, sg.getSequences(ap.av
1213 .getHiddenRepSequences()), 0, ap.av.getAlignment()
1214 .getWidth(), false, ap.av.getConsPercGaps(), false));
1215 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1216 SliderPanel.showConservationSlider();
1219 // remove ConservationColouring
1221 sg.cs.setConservation(null);
1227 SequenceGroup getGroup()
1229 SequenceGroup sg = ap.av.getSelectionGroup();
1231 // this method won't add a new group if it already exists
1234 ap.av.getAlignment().addGroup(sg);
1240 void unGroupMenuItem_actionPerformed()
1242 SequenceGroup sg = ap.av.getSelectionGroup();
1243 ap.av.getAlignment().deleteGroup(sg);
1244 ap.av.setSelectionGroup(null);
1245 ap.paintAlignment(true);
1248 void createGroupMenuItem_actionPerformed()
1250 getGroup(); // implicitly create group
1254 public void showColourText_itemStateChanged()
1256 getGroup().setColourText(showColourText.getState());
1260 public void showText_itemStateChanged()
1262 getGroup().setDisplayText(showText.getState());
1266 public void makeReferenceSeq_actionPerformed()
1268 if (!ap.av.getAlignment().hasSeqrep())
1270 // initialise the display flags so the user sees something happen
1271 ap.av.setDisplayReferenceSeq(true);
1272 ap.av.setColourByReferenceSeq(true);
1273 ap.av.getAlignment().setSeqrep(seq);
1277 if (ap.av.getAlignment().getSeqrep() == seq)
1279 ap.av.getAlignment().setSeqrep(null);
1283 ap.av.getAlignment().setSeqrep(seq);
1289 public void showNonconserved_itemStateChanged()
1291 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1295 public void showBoxes_itemStateChanged()
1297 getGroup().setDisplayBoxes(showBoxes.getState());
1301 void hideSequences(boolean representGroup)
1303 ap.av.hideSequences(seq, representGroup);
1307 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1308 * "All" is added first, followed by a separator. Then add any annotation
1309 * types associated with the current selection. Separate menus are built for
1310 * the selected sequence group (if any), and the selected sequence.
1312 * Some annotation rows are always rendered together - these can be identified
1313 * by a common graphGroup property > -1. Only one of each group will be marked
1314 * as visible (to avoid duplication of the display). For such groups we add a
1315 * composite type name, e.g.
1317 * IUPredWS (Long), IUPredWS (Short)
1321 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1322 List<SequenceI> forSequences)
1324 showMenu.removeAll();
1325 hideMenu.removeAll();
1327 final List<String> all = Arrays.asList(new String[] { MessageManager
1328 .getString("label.all") });
1329 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1330 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1332 showMenu.addSeparator();
1333 hideMenu.addSeparator();
1335 final AlignmentAnnotation[] annotations = ap.getAlignment()
1336 .getAlignmentAnnotation();
1339 * Find shown/hidden annotations types, distinguished by source (calcId),
1340 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1341 * the insertion order, which is the order of the annotations on the
1344 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1345 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1346 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1347 AlignmentAnnotationUtils.asList(annotations), forSequences);
1349 for (String calcId : hiddenTypes.keySet())
1351 for (List<String> type : hiddenTypes.get(calcId))
1353 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1357 // grey out 'show annotations' if none are hidden
1358 showMenu.setEnabled(!hiddenTypes.isEmpty());
1360 for (String calcId : shownTypes.keySet())
1362 for (List<String> type : shownTypes.get(calcId))
1364 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1368 // grey out 'hide annotations' if none are shown
1369 hideMenu.setEnabled(!shownTypes.isEmpty());
1373 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1376 * @param showOrHideMenu
1377 * the menu to add to
1378 * @param forSequences
1379 * the sequences whose annotations may be shown or hidden
1384 * if true this is a special label meaning 'All'
1385 * @param actionIsShow
1386 * if true, the select menu item action is to show the annotation
1389 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1390 final List<SequenceI> forSequences, String calcId,
1391 final List<String> types, final boolean allTypes,
1392 final boolean actionIsShow)
1394 String label = types.toString(); // [a, b, c]
1395 label = label.substring(1, label.length() - 1);
1396 final MenuItem item = new MenuItem(label);
1397 item.addActionListener(new java.awt.event.ActionListener()
1400 public void actionPerformed(ActionEvent e)
1402 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1403 types, forSequences, allTypes, actionIsShow);
1407 showOrHideMenu.add(item);