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 private static final String ALL_ANNOTATIONS = "All";
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 (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
221 MenuItem item = new MenuItem(
222 jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
224 item.addActionListener(this);
225 outputmenu.add(item);
228 buildAnnotationSubmenus();
230 SequenceGroup sg = ap.av.getSelectionGroup();
231 if (sg != null && sg.getSize() > 0)
233 editGroupName.setLabel(MessageManager.formatMessage(
234 "label.name_param", new Object[] { sg.getName() }));
235 showText.setState(sg.getDisplayText());
236 showColourText.setState(sg.getColourText());
237 showBoxes.setState(sg.getDisplayBoxes());
238 displayNonconserved.setState(sg.getShowNonconserved());
239 if (!ap.av.getAlignment().getGroups().contains(sg))
241 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
242 groupMenu.remove(unGroupMenuItem);
246 menu1.setLabel(MessageManager.getString("action.edit_group"));
247 groupMenu.remove(createGroupMenuItem);
257 if (links != null && links.size() > 0)
259 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
260 for (int i = 0; i < links.size(); i++)
262 String link = links.elementAt(i);
263 UrlLink urlLink = new UrlLink(link);
264 if (!urlLink.isValid())
266 System.err.println(urlLink.getInvalidMessage());
269 final String target = urlLink.getTarget(); // link.substring(0,
270 // link.indexOf("|"));
271 final String label = urlLink.getLabel();
272 if (seq != null && urlLink.isDynamic())
275 // collect matching db-refs
276 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
277 seq.getDBRef(), new String[] { target });
278 // collect id string too
279 String id = seq.getName();
280 String descr = seq.getDescription();
281 if (descr != null && descr.length() < 1)
287 for (int r = 0; r < dbr.length; r++)
289 if (id != null && dbr[r].getAccessionId().equals(id))
291 // suppress duplicate link creation for the bare sequence ID
292 // string with this link
295 // create Bare ID link for this RUL
296 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
300 for (int u = 0; u < urls.length; u += 2)
302 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
309 // create Bare ID link for this RUL
310 String[] urls = urlLink.makeUrls(id, true);
313 for (int u = 0; u < urls.length; u += 2)
315 addshowLink(linkMenu, label, urls[u + 1]);
318 // addshowLink(linkMenu, target, url_pref + id + url_suff);
320 // Now construct URLs from description but only try to do it for regex
322 if (descr != null && urlLink.getRegexReplace() != null)
324 // create link for this URL from description only if regex matches
325 String[] urls = urlLink.makeUrls(descr, true);
328 for (int u = 0; u < urls.length; u += 2)
330 addshowLink(linkMenu, label, urls[u + 1]);
337 addshowLink(linkMenu, target, urlLink.getUrl_prefix()); // link.substring(link.lastIndexOf("|")+1));
342 * if (link.indexOf("$SEQUENCE_ID$") > -1) { // Substitute SEQUENCE_ID
343 * string and any matching database reference accessions String url_pref
344 * = link.substring(link.indexOf("|") + 1,
345 * link.indexOf("$SEQUENCE_ID$"));
347 * String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
348 * // collect matching db-refs DBRefEntry[] dbr =
349 * jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new
350 * String[]{target}); // collect id string too String id =
351 * seq.getName(); if (id.indexOf("|") > -1) { id =
352 * id.substring(id.lastIndexOf("|") + 1); } if (dbr!=null) { for (int
353 * r=0;r<dbr.length; r++) { if (dbr[r].getAccessionId().equals(id)) { //
354 * suppress duplicate link creation for the bare sequence ID string with
355 * this link id = null; } addshowLink(linkMenu,
356 * dbr[r].getSource()+"|"+dbr[r].getAccessionId(), target,
357 * url_pref+dbr[r].getAccessionId()+url_suff); } } if (id!=null) { //
358 * create Bare ID link for this RUL addshowLink(linkMenu, target,
359 * url_pref + id + url_suff); } } else { addshowLink(linkMenu, target,
360 * link.substring(link.lastIndexOf("|")+1)); }
363 if (linkMenu.getItemCount() > 0)
367 seqMenu.add(linkMenu);
375 // TODO: add group link menu entry here
378 seqMenu.setLabel(seq.getName());
379 if (seq == ap.av.getAlignment().getSeqrep())
381 makeReferenceSeq.setLabel(MessageManager
382 .getString("action.unmark_as_reference"));// Unmark
387 makeReferenceSeq.setLabel(MessageManager
388 .getString("action.set_as_reference")); // );
390 repGroup.setLabel(MessageManager.formatMessage(
391 "label.represent_group_with", new Object[] { seq.getName() }));
398 if (!ap.av.hasHiddenRows())
405 final int index = ap.av.getAlignment().findIndex(seq);
407 if (ap.av.adjustForHiddenSeqs(index)
408 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
410 revealSeq_index = index;
420 * Build menus for annotation types that may be shown or hidden, and for
421 * 'reference annotations' that may be added to the alignment.
423 private void buildAnnotationSubmenus()
426 * First for the currently selected sequence (if there is one):
428 final List<SequenceI> selectedSequence = (seq == null ? Collections
429 .<SequenceI> emptyList() : Arrays.asList(seq));
430 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
431 seqHideAnnotationsMenu, selectedSequence);
432 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
436 * and repeat for the current selection group (if there is one):
438 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
439 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
441 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
442 groupHideAnnotationsMenu, selectedGroup);
443 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
448 * Determine whether or not to enable 'add reference annotations' menu item.
449 * It is enable if there are any annotations, on any of the selected
450 * sequences, which are not yet on the alignment (visible or not).
453 * @param forSequences
455 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
456 List<SequenceI> forSequences)
458 menuItem.setEnabled(false);
461 * Temporary store to hold distinct calcId / type pairs for the tooltip.
462 * Using TreeMap means calcIds are shown in alphabetical order.
464 Map<String, String> tipEntries = new TreeMap<String, String>();
465 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
466 AlignmentI al = this.ap.av.getAlignment();
467 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
468 tipEntries, candidates, al);
469 if (!candidates.isEmpty())
471 StringBuilder tooltip = new StringBuilder(64);
472 tooltip.append(MessageManager.getString("label.add_annotations_for"));
475 * Found annotations that could be added. Enable the menu item, and
476 * configure its action.
478 menuItem.setEnabled(true);
480 menuItem.addActionListener(new ActionListener()
483 public void actionPerformed(ActionEvent e)
485 addReferenceAnnotations_actionPerformed(candidates);
492 * Add annotations to the sequences and to the alignment.
495 * a map whose keys are sequences on the alignment, and values a list
496 * of annotations to add to each sequence
498 protected void addReferenceAnnotations_actionPerformed(
499 Map<SequenceI, List<AlignmentAnnotation>> candidates)
501 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
502 final AlignmentI alignment = this.ap.getAlignment();
503 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
509 * add a show URL menu item to the given linkMenu
513 * - menu label string
517 private void addshowLink(Menu linkMenu, final String target,
520 addshowLink(linkMenu, target, target, url);
524 * add a show URL menu item to the given linkMenu
528 * - URL target window
530 * - menu label string
534 private void addshowLink(Menu linkMenu, final String target,
535 final String label, final String url)
537 MenuItem item = new MenuItem(label);
538 item.addActionListener(new java.awt.event.ActionListener()
540 public void actionPerformed(ActionEvent e)
542 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();
572 public void actionPerformed(ActionEvent evt)
574 Object source = evt.getSource();
575 if (source == clustalColour)
577 clustalColour_actionPerformed();
579 else if (source == zappoColour)
581 zappoColour_actionPerformed();
583 else if (source == taylorColour)
585 taylorColour_actionPerformed();
587 else if (source == hydrophobicityColour)
589 hydrophobicityColour_actionPerformed();
591 else if (source == helixColour)
593 helixColour_actionPerformed();
595 else if (source == strandColour)
597 strandColour_actionPerformed();
599 else if (source == turnColour)
601 turnColour_actionPerformed();
603 else if (source == buriedColour)
605 buriedColour_actionPerformed();
607 else if (source == nucleotideMenuItem)
609 nucleotideMenuItem_actionPerformed();
612 else if (source == userDefinedColour)
614 userDefinedColour_actionPerformed();
616 else if (source == PIDColour)
618 PIDColour_actionPerformed();
620 else if (source == BLOSUM62Colour)
622 BLOSUM62Colour_actionPerformed();
624 else if (source == noColourmenuItem)
626 noColourmenuItem_actionPerformed();
628 else if (source == conservationMenuItem)
630 conservationMenuItem_itemStateChanged();
632 else if (source == unGroupMenuItem)
634 unGroupMenuItem_actionPerformed();
637 else if (source == createGroupMenuItem)
639 createGroupMenuItem_actionPerformed();
642 else if (source == sequenceName)
646 else if (source == makeReferenceSeq)
648 makeReferenceSeq_actionPerformed();
650 else if (source == sequenceDetails)
652 showSequenceDetails();
654 else if (source == selSeqDetails)
656 showSequenceSelectionDetails();
658 else if (source == pdb)
662 else if (source == hideSeqs)
664 hideSequences(false);
666 else if (source == repGroup)
670 else if (source == revealSeq)
672 ap.av.showSequence(revealSeq_index);
674 else if (source == revealAll)
676 ap.av.showAllHiddenSeqs();
679 else if (source == editGroupName)
681 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
682 getGroup().getDescription(), " Group Name",
683 "Group Description", ap.alignFrame,
684 "Edit Group Name / Description", 500, 100, true);
688 getGroup().setName(dialog.getName().replace(' ', '_'));
689 getGroup().setDescription(dialog.getDescription());
693 else if (source == copy)
695 ap.alignFrame.copy_actionPerformed();
697 else if (source == cut)
699 ap.alignFrame.cut_actionPerformed();
701 else if (source == editSequence)
703 SequenceGroup sg = ap.av.getSelectionGroup();
709 seq = sg.getSequenceAt(0);
712 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
713 sg.getStartRes(), sg.getEndRes() + 1), null,
714 "Edit Sequence ", null,
716 ap.alignFrame, "Edit Sequence", 500, 100, true);
720 EditCommand editCommand = new EditCommand(
721 MessageManager.getString("label.edit_sequences"),
722 Action.REPLACE, dialog.getName().replace(' ',
723 ap.av.getGapCharacter()),
724 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
725 sg.getStartRes(), sg.getEndRes() + 1,
726 ap.av.getAlignment());
728 ap.alignFrame.addHistoryItem(editCommand);
730 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
735 else if (source == toUpper || source == toLower || source == toggleCase)
737 SequenceGroup sg = ap.av.getSelectionGroup();
740 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
741 sg.getStartRes(), sg.getEndRes() + 1);
746 if (source == toggleCase)
748 description = "Toggle Case";
749 caseChange = ChangeCaseCommand.TOGGLE_CASE;
751 else if (source == toUpper)
753 description = "To Upper Case";
754 caseChange = ChangeCaseCommand.TO_UPPER;
758 description = "To Lower Case";
759 caseChange = ChangeCaseCommand.TO_LOWER;
762 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
763 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
764 startEnd, caseChange);
766 ap.alignFrame.addHistoryItem(caseCommand);
768 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
773 else if (source == sequenceFeature)
775 SequenceGroup sg = ap.av.getSelectionGroup();
781 int rsize = 0, gSize = sg.getSize();
782 SequenceI[] rseqs, seqs = new SequenceI[gSize];
783 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
785 for (int i = 0; i < gSize; i++)
787 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
788 int end = sg.findEndRes(sg.getSequenceAt(i));
791 seqs[rsize] = sg.getSequenceAt(i);
792 features[rsize] = new SequenceFeature(null, null, null, start,
797 rseqs = new SequenceI[rsize];
798 tfeatures = new SequenceFeature[rsize];
799 System.arraycopy(seqs, 0, rseqs, 0, rsize);
800 System.arraycopy(features, 0, tfeatures, 0, rsize);
801 features = tfeatures;
804 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
807 ap.alignFrame.sequenceFeatures.setState(true);
808 ap.av.setShowSequenceFeatures(true);
810 ap.highlightSearchResults(null);
820 void outputText(ActionEvent e)
822 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
824 Frame frame = new Frame();
826 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
827 "label.selection_output_command",
828 new Object[] { e.getActionCommand() }), 600, 500);
829 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
830 // now returns a full copy of sequence data
831 // TODO consider using getSequenceSelection instead here
833 cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
834 e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true));
838 protected void showSequenceSelectionDetails()
840 createSequenceDetailsReport(ap.av.getSequenceSelection());
843 protected void showSequenceDetails()
845 createSequenceDetailsReport(new SequenceI[] { seq });
848 public void createSequenceDetailsReport(SequenceI[] sequences)
851 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
853 StringBuffer contents = new StringBuffer();
854 for (SequenceI seq : sequences)
856 contents.append(MessageManager.formatMessage(
857 "label.annotation_for_displayid",
858 new Object[] { seq.getDisplayId(true) }));
859 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
865 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
866 .getMinMax() : null);
867 contents.append("</p>");
869 Frame frame = new Frame();
871 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
872 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
873 : "Selection"), 600, 500);
874 cap.setText(MessageManager.formatMessage("label.html_content",
875 new Object[] { contents.toString() }));
880 EditNameDialog dialog = new EditNameDialog(seq.getName(),
881 seq.getDescription(), " Sequence Name",
882 "Sequence Description", ap.alignFrame,
883 "Edit Sequence Name / Description", 500, 100, true);
887 seq.setName(dialog.getName());
888 seq.setDescription(dialog.getDescription());
889 ap.paintAlignment(false);
895 if (seq.getAllPDBEntries() != null)
897 PDBEntry entry = seq.getAllPDBEntries().firstElement();
899 if (ap.av.applet.jmolAvailable)
901 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
902 null, ap, AppletFormatAdapter.URL);
906 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
907 ap, AppletFormatAdapter.URL);
913 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
914 cap.setText(MessageManager.getString("label.paste_pdb_file"));
915 cap.setPDBImport(seq);
916 Frame frame = new Frame();
918 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
919 "label.paste_pdb_file_for_sequence",
920 new Object[] { seq.getName() }), 400, 300);
924 private void jbInit() throws Exception
926 groupMenu.setLabel(MessageManager.getString("label.selection"));
927 sequenceFeature.addActionListener(this);
929 editGroupName.addActionListener(this);
930 unGroupMenuItem.setLabel(MessageManager
931 .getString("action.remove_group"));
932 unGroupMenuItem.addActionListener(this);
934 createGroupMenuItem.setLabel(MessageManager
935 .getString("action.create_group"));
936 createGroupMenuItem.addActionListener(this);
938 nucleotideMenuItem.setLabel(MessageManager
939 .getString("label.nucleotide"));
940 nucleotideMenuItem.addActionListener(this);
941 conservationMenuItem.addItemListener(this);
942 abovePIDColour.addItemListener(this);
943 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
944 showBoxes.setLabel(MessageManager.getString("action.boxes"));
945 showBoxes.setState(true);
946 showBoxes.addItemListener(this);
947 sequenceName.addActionListener(this);
948 sequenceDetails.addActionListener(this);
949 selSeqDetails.addActionListener(this);
950 displayNonconserved.setLabel(MessageManager
951 .getString("label.show_non_conversed"));
952 displayNonconserved.setState(false);
953 displayNonconserved.addItemListener(this);
954 showText.setLabel(MessageManager.getString("action.text"));
955 showText.addItemListener(this);
956 showColourText.setLabel(MessageManager.getString("label.colour_text"));
957 showColourText.addItemListener(this);
958 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
959 seqMenu.setLabel(MessageManager.getString("label.sequence"));
960 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
961 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
962 repGroup.setLabel(MessageManager.formatMessage(
963 "label.represent_group_with", new Object[] { "" }));
964 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
965 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
966 menu1.setLabel(MessageManager.getString("label.group") + ":");
972 // groupMenu.add(selSeqDetails);
973 groupMenu.add(groupShowAnnotationsMenu);
974 groupMenu.add(groupHideAnnotationsMenu);
975 groupMenu.add(groupAddReferenceAnnotations);
976 groupMenu.add(editMenu);
977 groupMenu.add(outputmenu);
978 groupMenu.add(sequenceFeature);
979 groupMenu.add(createGroupMenuItem);
980 groupMenu.add(unGroupMenuItem);
981 groupMenu.add(menu1);
983 colourMenu.add(noColourmenuItem);
984 colourMenu.add(clustalColour);
985 colourMenu.add(BLOSUM62Colour);
986 colourMenu.add(PIDColour);
987 colourMenu.add(zappoColour);
988 colourMenu.add(taylorColour);
989 colourMenu.add(hydrophobicityColour);
990 colourMenu.add(helixColour);
991 colourMenu.add(strandColour);
992 colourMenu.add(turnColour);
993 colourMenu.add(buriedColour);
994 colourMenu.add(nucleotideMenuItem);
995 colourMenu.add(userDefinedColour);
996 colourMenu.addSeparator();
997 colourMenu.add(abovePIDColour);
998 colourMenu.add(conservationMenuItem);
1000 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
1001 noColourmenuItem.addActionListener(this);
1003 clustalColour.setLabel(MessageManager
1004 .getString("label.clustalx_colours"));
1005 clustalColour.addActionListener(this);
1006 zappoColour.setLabel(MessageManager.getString("label.zappo"));
1007 zappoColour.addActionListener(this);
1008 taylorColour.setLabel(MessageManager.getString("label.taylor"));
1009 taylorColour.addActionListener(this);
1010 hydrophobicityColour.setLabel(MessageManager
1011 .getString("label.hydrophobicity"));
1012 hydrophobicityColour.addActionListener(this);
1014 .setLabel(MessageManager.getString("label.helix_propensity"));
1015 helixColour.addActionListener(this);
1016 strandColour.setLabel(MessageManager
1017 .getString("label.strand_propensity"));
1018 strandColour.addActionListener(this);
1019 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
1020 turnColour.addActionListener(this);
1021 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
1022 buriedColour.addActionListener(this);
1023 abovePIDColour.setLabel(MessageManager
1024 .getString("label.above_identity_percentage"));
1026 userDefinedColour.setLabel(MessageManager
1027 .getString("action.user_defined"));
1028 userDefinedColour.addActionListener(this);
1029 PIDColour.setLabel(MessageManager
1030 .getString("label.percentage_identity"));
1031 PIDColour.addActionListener(this);
1032 BLOSUM62Colour.setLabel("BLOSUM62");
1033 BLOSUM62Colour.addActionListener(this);
1034 conservationMenuItem.setLabel(MessageManager
1035 .getString("label.conservation"));
1038 copy.addActionListener(this);
1040 cut.addActionListener(this);
1042 editMenu.add(editSequence);
1043 editSequence.addActionListener(this);
1045 editMenu.add(toUpper);
1046 toUpper.addActionListener(this);
1047 editMenu.add(toLower);
1048 toLower.addActionListener(this);
1049 editMenu.add(toggleCase);
1050 seqMenu.add(seqShowAnnotationsMenu);
1051 seqMenu.add(seqHideAnnotationsMenu);
1052 seqMenu.add(seqAddReferenceAnnotations);
1053 seqMenu.add(sequenceName);
1054 seqMenu.add(makeReferenceSeq);
1055 // seqMenu.add(sequenceDetails);
1057 if (!ap.av.applet.useXtrnalSviewer)
1061 seqMenu.add(repGroup);
1062 menu1.add(editGroupName);
1063 menu1.add(colourMenu);
1064 menu1.add(showBoxes);
1065 menu1.add(showText);
1066 menu1.add(showColourText);
1067 menu1.add(displayNonconserved);
1068 toggleCase.addActionListener(this);
1069 pdb.addActionListener(this);
1070 hideSeqs.addActionListener(this);
1071 repGroup.addActionListener(this);
1072 revealAll.addActionListener(this);
1073 revealSeq.addActionListener(this);
1074 makeReferenceSeq.addActionListener(this);
1079 ap.paintAlignment(true);
1082 protected void clustalColour_actionPerformed()
1084 SequenceGroup sg = getGroup();
1085 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1089 protected void zappoColour_actionPerformed()
1091 getGroup().cs = new ZappoColourScheme();
1095 protected void taylorColour_actionPerformed()
1097 getGroup().cs = new TaylorColourScheme();
1101 protected void hydrophobicityColour_actionPerformed()
1103 getGroup().cs = new HydrophobicColourScheme();
1107 protected void helixColour_actionPerformed()
1109 getGroup().cs = new HelixColourScheme();
1113 protected void strandColour_actionPerformed()
1115 getGroup().cs = new StrandColourScheme();
1119 protected void turnColour_actionPerformed()
1121 getGroup().cs = new TurnColourScheme();
1125 protected void buriedColour_actionPerformed()
1127 getGroup().cs = new BuriedColourScheme();
1131 public void nucleotideMenuItem_actionPerformed()
1133 getGroup().cs = new NucleotideColourScheme();
1137 protected void abovePIDColour_itemStateChanged()
1139 SequenceGroup sg = getGroup();
1145 if (abovePIDColour.getState())
1147 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1148 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1149 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1152 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1154 SliderPanel.showPIDSlider();
1158 // remove PIDColouring
1160 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1167 protected void userDefinedColour_actionPerformed()
1169 new UserDefinedColours(ap, getGroup());
1172 protected void PIDColour_actionPerformed()
1174 SequenceGroup sg = getGroup();
1175 sg.cs = new PIDColourScheme();
1176 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1177 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1181 protected void BLOSUM62Colour_actionPerformed()
1183 SequenceGroup sg = getGroup();
1185 sg.cs = new Blosum62ColourScheme();
1187 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1188 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1193 protected void noColourmenuItem_actionPerformed()
1195 getGroup().cs = null;
1199 protected void conservationMenuItem_itemStateChanged()
1201 SequenceGroup sg = getGroup();
1207 if (conservationMenuItem.getState())
1210 sg.cs.setConservation(Conservation.calculateConservation("Group",
1211 ResidueProperties.propHash, 3, sg.getSequences(ap.av
1212 .getHiddenRepSequences()), 0, ap.av.getAlignment()
1213 .getWidth(), false, ap.av.getConsPercGaps(), false));
1214 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1215 SliderPanel.showConservationSlider();
1218 // remove ConservationColouring
1220 sg.cs.setConservation(null);
1226 SequenceGroup getGroup()
1228 SequenceGroup sg = ap.av.getSelectionGroup();
1230 // this method won't add a new group if it already exists
1233 ap.av.getAlignment().addGroup(sg);
1239 void unGroupMenuItem_actionPerformed()
1241 SequenceGroup sg = ap.av.getSelectionGroup();
1242 ap.av.getAlignment().deleteGroup(sg);
1243 ap.av.setSelectionGroup(null);
1244 ap.paintAlignment(true);
1247 void createGroupMenuItem_actionPerformed()
1249 getGroup(); // implicitly create group
1253 public void showColourText_itemStateChanged()
1255 getGroup().setColourText(showColourText.getState());
1259 public void showText_itemStateChanged()
1261 getGroup().setDisplayText(showText.getState());
1265 public void makeReferenceSeq_actionPerformed()
1267 if (!ap.av.getAlignment().hasSeqrep())
1269 // initialise the display flags so the user sees something happen
1270 ap.av.setDisplayReferenceSeq(true);
1271 ap.av.setColourByReferenceSeq(true);
1272 ap.av.getAlignment().setSeqrep(seq);
1276 if (ap.av.getAlignment().getSeqrep() == seq)
1278 ap.av.getAlignment().setSeqrep(null);
1282 ap.av.getAlignment().setSeqrep(seq);
1288 public void showNonconserved_itemStateChanged()
1290 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1294 public void showBoxes_itemStateChanged()
1296 getGroup().setDisplayBoxes(showBoxes.getState());
1300 void hideSequences(boolean representGroup)
1302 SequenceGroup sg = ap.av.getSelectionGroup();
1303 if (sg == null || sg.getSize() < 1)
1305 ap.av.hideSequence(new SequenceI[] { seq });
1309 ap.av.setSelectionGroup(null);
1313 ap.av.hideRepSequences(seq, sg);
1318 int gsize = sg.getSize();
1321 hseqs = new SequenceI[gsize];
1324 for (int i = 0; i < gsize; i++)
1326 hseqs[index++] = sg.getSequenceAt(i);
1329 ap.av.hideSequence(hseqs);
1330 ap.av.sendSelection();
1334 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1335 * "All" is added first, followed by a separator. Then add any annotation
1336 * types associated with the current selection. Separate menus are built for
1337 * the selected sequence group (if any), and the selected sequence.
1339 * Some annotation rows are always rendered together - these can be identified
1340 * by a common graphGroup property > -1. Only one of each group will be marked
1341 * as visible (to avoid duplication of the display). For such groups we add a
1342 * composite type name, e.g.
1344 * IUPredWS (Long), IUPredWS (Short)
1348 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1349 List<SequenceI> forSequences)
1351 showMenu.removeAll();
1352 hideMenu.removeAll();
1354 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
1355 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1356 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1358 showMenu.addSeparator();
1359 hideMenu.addSeparator();
1361 final AlignmentAnnotation[] annotations = ap.getAlignment()
1362 .getAlignmentAnnotation();
1365 * Find shown/hidden annotations types, distinguished by source (calcId),
1366 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1367 * the insertion order, which is the order of the annotations on the
1370 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1371 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1372 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1373 AlignmentAnnotationUtils.asList(annotations), forSequences);
1375 for (String calcId : hiddenTypes.keySet())
1377 for (List<String> type : hiddenTypes.get(calcId))
1379 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1383 // grey out 'show annotations' if none are hidden
1384 showMenu.setEnabled(!hiddenTypes.isEmpty());
1386 for (String calcId : shownTypes.keySet())
1388 for (List<String> type : shownTypes.get(calcId))
1390 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1394 // grey out 'hide annotations' if none are shown
1395 hideMenu.setEnabled(!shownTypes.isEmpty());
1399 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1402 * @param showOrHideMenu
1403 * the menu to add to
1404 * @param forSequences
1405 * the sequences whose annotations may be shown or hidden
1410 * if true this is a special label meaning 'All'
1411 * @param actionIsShow
1412 * if true, the select menu item action is to show the annotation
1415 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1416 final List<SequenceI> forSequences, String calcId,
1417 final List<String> types, final boolean allTypes,
1418 final boolean actionIsShow)
1420 String label = types.toString(); // [a, b, c]
1421 label = label.substring(1, label.length() - 1);
1422 final MenuItem item = new MenuItem(label);
1423 item.addActionListener(new java.awt.event.ActionListener()
1426 public void actionPerformed(ActionEvent e)
1428 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1429 types, forSequences, allTypes, actionIsShow);
1433 showOrHideMenu.add(item);