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.DBRefEntry;
34 import jalview.datamodel.PDBEntry;
35 import jalview.datamodel.SequenceFeature;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.io.AppletFormatAdapter;
39 import jalview.io.DataSourceType;
40 import jalview.io.FileFormat;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.schemes.Blosum62ColourScheme;
43 import jalview.schemes.BuriedColourScheme;
44 import jalview.schemes.ClustalxColourScheme;
45 import jalview.schemes.HelixColourScheme;
46 import jalview.schemes.HydrophobicColourScheme;
47 import jalview.schemes.NucleotideColourScheme;
48 import jalview.schemes.PIDColourScheme;
49 import jalview.schemes.ResidueProperties;
50 import jalview.schemes.StrandColourScheme;
51 import jalview.schemes.TaylorColourScheme;
52 import jalview.schemes.TurnColourScheme;
53 import jalview.schemes.ZappoColourScheme;
54 import jalview.util.MessageManager;
55 import jalview.util.UrlLink;
57 import java.awt.CheckboxMenuItem;
58 import java.awt.Frame;
60 import java.awt.MenuItem;
61 import java.awt.event.ActionEvent;
62 import java.awt.event.ActionListener;
63 import java.awt.event.ItemEvent;
64 import java.awt.event.ItemListener;
65 import java.util.Arrays;
66 import java.util.Collections;
67 import java.util.LinkedHashMap;
68 import java.util.List;
70 import java.util.TreeMap;
71 import java.util.Vector;
73 public class APopupMenu extends java.awt.PopupMenu implements
74 ActionListener, ItemListener
76 Menu groupMenu = new Menu();
78 MenuItem editGroupName = new MenuItem();
80 protected MenuItem clustalColour = new MenuItem();
82 protected MenuItem zappoColour = new MenuItem();
84 protected MenuItem taylorColour = new MenuItem();
86 protected MenuItem hydrophobicityColour = new MenuItem();
88 protected MenuItem helixColour = new MenuItem();
90 protected MenuItem strandColour = new MenuItem();
92 protected MenuItem turnColour = new MenuItem();
94 protected MenuItem buriedColour = new MenuItem();
96 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
98 protected MenuItem userDefinedColour = new MenuItem();
100 protected MenuItem PIDColour = new MenuItem();
102 protected MenuItem BLOSUM62Colour = new MenuItem();
104 MenuItem noColourmenuItem = new MenuItem();
106 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
108 final AlignmentPanel ap;
110 MenuItem unGroupMenuItem = new MenuItem();
112 MenuItem createGroupMenuItem = new MenuItem();
114 MenuItem nucleotideMenuItem = new MenuItem();
116 Menu colourMenu = new Menu();
118 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
120 CheckboxMenuItem showText = new CheckboxMenuItem();
122 CheckboxMenuItem showColourText = new CheckboxMenuItem();
124 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
126 Menu seqShowAnnotationsMenu = new Menu(
127 MessageManager.getString("label.show_annotations"));
129 Menu seqHideAnnotationsMenu = new Menu(
130 MessageManager.getString("label.hide_annotations"));
132 MenuItem seqAddReferenceAnnotations = new MenuItem(
133 MessageManager.getString("label.add_reference_annotations"));
135 Menu groupShowAnnotationsMenu = new Menu(
136 MessageManager.getString("label.show_annotations"));
138 Menu groupHideAnnotationsMenu = new Menu(
139 MessageManager.getString("label.hide_annotations"));
141 MenuItem groupAddReferenceAnnotations = new MenuItem(
142 MessageManager.getString("label.add_reference_annotations"));
144 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
146 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
148 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
150 MenuItem toUpper = new MenuItem(
151 MessageManager.getString("label.to_upper_case"));
153 MenuItem toLower = new MenuItem(
154 MessageManager.getString("label.to_lower_case"));
156 MenuItem toggleCase = new MenuItem(
157 MessageManager.getString("label.toggle_case"));
159 Menu outputmenu = new Menu();
161 Menu seqMenu = new Menu();
163 MenuItem pdb = new MenuItem();
165 MenuItem hideSeqs = new MenuItem();
167 MenuItem repGroup = new MenuItem();
169 MenuItem sequenceName = new MenuItem(
170 MessageManager.getString("label.edit_name_description"));
172 MenuItem sequenceFeature = new MenuItem(
173 MessageManager.getString("label.create_sequence_feature"));
175 MenuItem editSequence = new MenuItem(
176 MessageManager.getString("label.edit_sequence"));
178 MenuItem sequenceDetails = new MenuItem(
179 MessageManager.getString("label.sequence_details"));
181 MenuItem selSeqDetails = new MenuItem(
182 MessageManager.getString("label.sequence_details"));
184 MenuItem makeReferenceSeq = new MenuItem();
188 MenuItem revealAll = new MenuItem();
190 MenuItem revealSeq = new MenuItem();
193 * index of sequence to be revealed
195 int revealSeq_index = -1;
197 Menu menu1 = new Menu();
199 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
200 Vector<String> links)
202 // /////////////////////////////////////////////////////////
203 // If this is activated from the sequence panel, the user may want to
204 // edit or annotate a particular residue. Therefore display the residue menu
206 // If from the IDPanel, we must display the sequence menu
207 // ////////////////////////////////////////////////////////
215 } catch (Exception e)
220 for (String ff : FileFormat.getWritableFormats())
222 MenuItem item = new MenuItem(ff);
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.getDBRefs(), 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()
541 public void actionPerformed(ActionEvent e)
543 ap.alignFrame.showURL(url, target);
550 public void itemStateChanged(ItemEvent evt)
552 if (evt.getSource() == abovePIDColour)
554 abovePIDColour_itemStateChanged();
556 else if (evt.getSource() == showColourText)
558 showColourText_itemStateChanged();
560 else if (evt.getSource() == showText)
562 showText_itemStateChanged();
564 else if (evt.getSource() == showBoxes)
566 showBoxes_itemStateChanged();
568 else if (evt.getSource() == displayNonconserved)
570 this.showNonconserved_itemStateChanged();
575 public void actionPerformed(ActionEvent evt)
577 Object source = evt.getSource();
578 if (source == clustalColour)
580 clustalColour_actionPerformed();
582 else if (source == zappoColour)
584 zappoColour_actionPerformed();
586 else if (source == taylorColour)
588 taylorColour_actionPerformed();
590 else if (source == hydrophobicityColour)
592 hydrophobicityColour_actionPerformed();
594 else if (source == helixColour)
596 helixColour_actionPerformed();
598 else if (source == strandColour)
600 strandColour_actionPerformed();
602 else if (source == turnColour)
604 turnColour_actionPerformed();
606 else if (source == buriedColour)
608 buriedColour_actionPerformed();
610 else if (source == nucleotideMenuItem)
612 nucleotideMenuItem_actionPerformed();
615 else if (source == userDefinedColour)
617 userDefinedColour_actionPerformed();
619 else if (source == PIDColour)
621 PIDColour_actionPerformed();
623 else if (source == BLOSUM62Colour)
625 BLOSUM62Colour_actionPerformed();
627 else if (source == noColourmenuItem)
629 noColourmenuItem_actionPerformed();
631 else if (source == conservationMenuItem)
633 conservationMenuItem_itemStateChanged();
635 else if (source == unGroupMenuItem)
637 unGroupMenuItem_actionPerformed();
640 else if (source == createGroupMenuItem)
642 createGroupMenuItem_actionPerformed();
645 else if (source == sequenceName)
649 else if (source == makeReferenceSeq)
651 makeReferenceSeq_actionPerformed();
653 else if (source == sequenceDetails)
655 showSequenceDetails();
657 else if (source == selSeqDetails)
659 showSequenceSelectionDetails();
661 else if (source == pdb)
665 else if (source == hideSeqs)
667 hideSequences(false);
669 else if (source == repGroup)
673 else if (source == revealSeq)
675 ap.av.showSequence(revealSeq_index);
677 else if (source == revealAll)
679 ap.av.showAllHiddenSeqs();
682 else if (source == editGroupName)
684 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
685 getGroup().getDescription(), " Group Name",
686 "Group Description", ap.alignFrame,
687 "Edit Group Name / Description", 500, 100, true);
691 getGroup().setName(dialog.getName().replace(' ', '_'));
692 getGroup().setDescription(dialog.getDescription());
696 else if (source == copy)
698 ap.alignFrame.copy_actionPerformed();
700 else if (source == cut)
702 ap.alignFrame.cut_actionPerformed();
704 else if (source == editSequence)
706 SequenceGroup sg = ap.av.getSelectionGroup();
712 seq = sg.getSequenceAt(0);
715 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
716 sg.getStartRes(), sg.getEndRes() + 1), null,
717 "Edit Sequence ", null,
719 ap.alignFrame, "Edit Sequence", 500, 100, true);
723 EditCommand editCommand = new EditCommand(
724 MessageManager.getString("label.edit_sequences"),
725 Action.REPLACE, dialog.getName().replace(' ',
726 ap.av.getGapCharacter()),
727 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
728 sg.getStartRes(), sg.getEndRes() + 1,
729 ap.av.getAlignment());
731 ap.alignFrame.addHistoryItem(editCommand);
733 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
738 else if (source == toUpper || source == toLower || source == toggleCase)
740 SequenceGroup sg = ap.av.getSelectionGroup();
743 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
744 sg.getStartRes(), sg.getEndRes() + 1);
749 if (source == toggleCase)
751 description = "Toggle Case";
752 caseChange = ChangeCaseCommand.TOGGLE_CASE;
754 else if (source == toUpper)
756 description = "To Upper Case";
757 caseChange = ChangeCaseCommand.TO_UPPER;
761 description = "To Lower Case";
762 caseChange = ChangeCaseCommand.TO_LOWER;
765 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
766 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
767 startEnd, caseChange);
769 ap.alignFrame.addHistoryItem(caseCommand);
771 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
776 else if (source == sequenceFeature)
778 SequenceGroup sg = ap.av.getSelectionGroup();
784 int rsize = 0, gSize = sg.getSize();
785 SequenceI[] rseqs, seqs = new SequenceI[gSize];
786 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
788 for (int i = 0; i < gSize; i++)
790 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
791 int end = sg.findEndRes(sg.getSequenceAt(i));
794 seqs[rsize] = sg.getSequenceAt(i);
795 features[rsize] = new SequenceFeature(null, null, null, start,
800 rseqs = new SequenceI[rsize];
801 tfeatures = new SequenceFeature[rsize];
802 System.arraycopy(seqs, 0, rseqs, 0, rsize);
803 System.arraycopy(features, 0, tfeatures, 0, rsize);
804 features = tfeatures;
807 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
810 ap.alignFrame.sequenceFeatures.setState(true);
811 ap.av.setShowSequenceFeatures(true);
813 ap.highlightSearchResults(null);
823 void outputText(ActionEvent e)
825 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
827 Frame frame = new Frame();
829 JalviewLite.addFrame(frame, MessageManager.formatMessage(
830 "label.selection_output_command",
831 new Object[] { e.getActionCommand() }), 600, 500);
832 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
833 // now returns a full copy of sequence data
834 // TODO consider using getSequenceSelection instead here
836 FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
837 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
838 ap.av.getShowJVSuffix(), ap, true));
842 protected void showSequenceSelectionDetails()
844 createSequenceDetailsReport(ap.av.getSequenceSelection());
847 protected void showSequenceDetails()
849 createSequenceDetailsReport(new SequenceI[] { seq });
852 public void createSequenceDetailsReport(SequenceI[] sequences)
855 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
857 StringBuffer contents = new StringBuffer();
858 for (SequenceI seq : sequences)
860 contents.append(MessageManager.formatMessage(
861 "label.annotation_for_displayid",
862 new Object[] { seq.getDisplayId(true) }));
863 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
869 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
870 .getMinMax() : null);
871 contents.append("</p>");
873 Frame frame = new Frame();
875 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
876 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
877 : "Selection"), 600, 500);
878 cap.setText(MessageManager.formatMessage("label.html_content",
879 new Object[] { contents.toString() }));
884 EditNameDialog dialog = new EditNameDialog(seq.getName(),
885 seq.getDescription(), " Sequence Name",
886 "Sequence Description", ap.alignFrame,
887 "Edit Sequence Name / Description", 500, 100, true);
891 seq.setName(dialog.getName());
892 seq.setDescription(dialog.getDescription());
893 ap.paintAlignment(false);
899 if (seq.getAllPDBEntries() != null)
901 PDBEntry entry = seq.getAllPDBEntries().firstElement();
903 if (ap.av.applet.jmolAvailable)
905 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
906 null, ap, DataSourceType.URL);
910 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
911 ap, DataSourceType.URL);
917 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
918 cap.setText(MessageManager.getString("label.paste_pdb_file"));
919 cap.setPDBImport(seq);
920 Frame frame = new Frame();
922 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
923 "label.paste_pdb_file_for_sequence",
924 new Object[] { seq.getName() }), 400, 300);
928 private void jbInit() throws Exception
930 groupMenu.setLabel(MessageManager.getString("label.selection"));
931 sequenceFeature.addActionListener(this);
933 editGroupName.addActionListener(this);
934 unGroupMenuItem.setLabel(MessageManager
935 .getString("action.remove_group"));
936 unGroupMenuItem.addActionListener(this);
938 createGroupMenuItem.setLabel(MessageManager
939 .getString("action.create_group"));
940 createGroupMenuItem.addActionListener(this);
942 nucleotideMenuItem.setLabel(MessageManager
943 .getString("label.nucleotide"));
944 nucleotideMenuItem.addActionListener(this);
945 conservationMenuItem.addItemListener(this);
946 abovePIDColour.addItemListener(this);
947 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
948 showBoxes.setLabel(MessageManager.getString("action.boxes"));
949 showBoxes.setState(true);
950 showBoxes.addItemListener(this);
951 sequenceName.addActionListener(this);
952 sequenceDetails.addActionListener(this);
953 selSeqDetails.addActionListener(this);
954 displayNonconserved.setLabel(MessageManager
955 .getString("label.show_non_conversed"));
956 displayNonconserved.setState(false);
957 displayNonconserved.addItemListener(this);
958 showText.setLabel(MessageManager.getString("action.text"));
959 showText.addItemListener(this);
960 showColourText.setLabel(MessageManager.getString("label.colour_text"));
961 showColourText.addItemListener(this);
962 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
963 seqMenu.setLabel(MessageManager.getString("label.sequence"));
964 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
965 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
966 repGroup.setLabel(MessageManager.formatMessage(
967 "label.represent_group_with", new Object[] { "" }));
968 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
969 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
970 menu1.setLabel(MessageManager.getString("label.group:"));
976 // groupMenu.add(selSeqDetails);
977 groupMenu.add(groupShowAnnotationsMenu);
978 groupMenu.add(groupHideAnnotationsMenu);
979 groupMenu.add(groupAddReferenceAnnotations);
980 groupMenu.add(editMenu);
981 groupMenu.add(outputmenu);
982 groupMenu.add(sequenceFeature);
983 groupMenu.add(createGroupMenuItem);
984 groupMenu.add(unGroupMenuItem);
985 groupMenu.add(menu1);
987 colourMenu.add(noColourmenuItem);
988 colourMenu.add(clustalColour);
989 colourMenu.add(BLOSUM62Colour);
990 colourMenu.add(PIDColour);
991 colourMenu.add(zappoColour);
992 colourMenu.add(taylorColour);
993 colourMenu.add(hydrophobicityColour);
994 colourMenu.add(helixColour);
995 colourMenu.add(strandColour);
996 colourMenu.add(turnColour);
997 colourMenu.add(buriedColour);
998 colourMenu.add(nucleotideMenuItem);
999 colourMenu.add(userDefinedColour);
1000 colourMenu.addSeparator();
1001 colourMenu.add(abovePIDColour);
1002 colourMenu.add(conservationMenuItem);
1004 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
1005 noColourmenuItem.addActionListener(this);
1007 clustalColour.setLabel(MessageManager
1008 .getString("label.clustalx_colours"));
1009 clustalColour.addActionListener(this);
1010 zappoColour.setLabel(MessageManager.getString("label.zappo"));
1011 zappoColour.addActionListener(this);
1012 taylorColour.setLabel(MessageManager.getString("label.taylor"));
1013 taylorColour.addActionListener(this);
1014 hydrophobicityColour.setLabel(MessageManager
1015 .getString("label.hydrophobicity"));
1016 hydrophobicityColour.addActionListener(this);
1018 .setLabel(MessageManager.getString("label.helix_propensity"));
1019 helixColour.addActionListener(this);
1020 strandColour.setLabel(MessageManager
1021 .getString("label.strand_propensity"));
1022 strandColour.addActionListener(this);
1023 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
1024 turnColour.addActionListener(this);
1025 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
1026 buriedColour.addActionListener(this);
1027 abovePIDColour.setLabel(MessageManager
1028 .getString("label.above_identity_percentage"));
1030 userDefinedColour.setLabel(MessageManager
1031 .getString("action.user_defined"));
1032 userDefinedColour.addActionListener(this);
1033 PIDColour.setLabel(MessageManager
1034 .getString("label.percentage_identity"));
1035 PIDColour.addActionListener(this);
1036 BLOSUM62Colour.setLabel("BLOSUM62");
1037 BLOSUM62Colour.addActionListener(this);
1038 conservationMenuItem.setLabel(MessageManager
1039 .getString("label.conservation"));
1042 copy.addActionListener(this);
1044 cut.addActionListener(this);
1046 editMenu.add(editSequence);
1047 editSequence.addActionListener(this);
1049 editMenu.add(toUpper);
1050 toUpper.addActionListener(this);
1051 editMenu.add(toLower);
1052 toLower.addActionListener(this);
1053 editMenu.add(toggleCase);
1054 seqMenu.add(seqShowAnnotationsMenu);
1055 seqMenu.add(seqHideAnnotationsMenu);
1056 seqMenu.add(seqAddReferenceAnnotations);
1057 seqMenu.add(sequenceName);
1058 seqMenu.add(makeReferenceSeq);
1059 // seqMenu.add(sequenceDetails);
1061 if (!ap.av.applet.useXtrnalSviewer)
1065 seqMenu.add(repGroup);
1066 menu1.add(editGroupName);
1067 menu1.add(colourMenu);
1068 menu1.add(showBoxes);
1069 menu1.add(showText);
1070 menu1.add(showColourText);
1071 menu1.add(displayNonconserved);
1072 toggleCase.addActionListener(this);
1073 pdb.addActionListener(this);
1074 hideSeqs.addActionListener(this);
1075 repGroup.addActionListener(this);
1076 revealAll.addActionListener(this);
1077 revealSeq.addActionListener(this);
1078 makeReferenceSeq.addActionListener(this);
1083 ap.paintAlignment(true);
1086 protected void clustalColour_actionPerformed()
1088 SequenceGroup sg = getGroup();
1089 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1093 protected void zappoColour_actionPerformed()
1095 getGroup().cs = new ZappoColourScheme();
1099 protected void taylorColour_actionPerformed()
1101 getGroup().cs = new TaylorColourScheme();
1105 protected void hydrophobicityColour_actionPerformed()
1107 getGroup().cs = new HydrophobicColourScheme();
1111 protected void helixColour_actionPerformed()
1113 getGroup().cs = new HelixColourScheme();
1117 protected void strandColour_actionPerformed()
1119 getGroup().cs = new StrandColourScheme();
1123 protected void turnColour_actionPerformed()
1125 getGroup().cs = new TurnColourScheme();
1129 protected void buriedColour_actionPerformed()
1131 getGroup().cs = new BuriedColourScheme();
1135 public void nucleotideMenuItem_actionPerformed()
1137 getGroup().cs = new NucleotideColourScheme();
1141 protected void abovePIDColour_itemStateChanged()
1143 SequenceGroup sg = getGroup();
1149 if (abovePIDColour.getState())
1151 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1152 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1153 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1156 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1158 SliderPanel.showPIDSlider();
1162 // remove PIDColouring
1164 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1171 protected void userDefinedColour_actionPerformed()
1173 new UserDefinedColours(ap, getGroup());
1176 protected void PIDColour_actionPerformed()
1178 SequenceGroup sg = getGroup();
1179 sg.cs = new PIDColourScheme();
1180 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1181 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1185 protected void BLOSUM62Colour_actionPerformed()
1187 SequenceGroup sg = getGroup();
1189 sg.cs = new Blosum62ColourScheme();
1191 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1192 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1197 protected void noColourmenuItem_actionPerformed()
1199 getGroup().cs = null;
1203 protected void conservationMenuItem_itemStateChanged()
1205 SequenceGroup sg = getGroup();
1211 if (conservationMenuItem.getState())
1214 sg.cs.setConservation(Conservation.calculateConservation("Group",
1215 ResidueProperties.propHash, 3, sg.getSequences(ap.av
1216 .getHiddenRepSequences()), 0, ap.av.getAlignment()
1217 .getWidth(), false, ap.av.getConsPercGaps(), false));
1218 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1219 SliderPanel.showConservationSlider();
1222 // remove ConservationColouring
1224 sg.cs.setConservation(null);
1230 SequenceGroup getGroup()
1232 SequenceGroup sg = ap.av.getSelectionGroup();
1234 // this method won't add a new group if it already exists
1237 ap.av.getAlignment().addGroup(sg);
1243 void unGroupMenuItem_actionPerformed()
1245 SequenceGroup sg = ap.av.getSelectionGroup();
1246 ap.av.getAlignment().deleteGroup(sg);
1247 ap.av.setSelectionGroup(null);
1248 ap.paintAlignment(true);
1251 void createGroupMenuItem_actionPerformed()
1253 getGroup(); // implicitly create group
1257 public void showColourText_itemStateChanged()
1259 getGroup().setColourText(showColourText.getState());
1263 public void showText_itemStateChanged()
1265 getGroup().setDisplayText(showText.getState());
1269 public void makeReferenceSeq_actionPerformed()
1271 if (!ap.av.getAlignment().hasSeqrep())
1273 // initialise the display flags so the user sees something happen
1274 ap.av.setDisplayReferenceSeq(true);
1275 ap.av.setColourByReferenceSeq(true);
1276 ap.av.getAlignment().setSeqrep(seq);
1280 if (ap.av.getAlignment().getSeqrep() == seq)
1282 ap.av.getAlignment().setSeqrep(null);
1286 ap.av.getAlignment().setSeqrep(seq);
1292 public void showNonconserved_itemStateChanged()
1294 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1298 public void showBoxes_itemStateChanged()
1300 getGroup().setDisplayBoxes(showBoxes.getState());
1304 void hideSequences(boolean representGroup)
1306 ap.av.hideSequences(seq, representGroup);
1310 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1311 * "All" is added first, followed by a separator. Then add any annotation
1312 * types associated with the current selection. Separate menus are built for
1313 * the selected sequence group (if any), and the selected sequence.
1315 * Some annotation rows are always rendered together - these can be identified
1316 * by a common graphGroup property > -1. Only one of each group will be marked
1317 * as visible (to avoid duplication of the display). For such groups we add a
1318 * composite type name, e.g.
1320 * IUPredWS (Long), IUPredWS (Short)
1324 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1325 List<SequenceI> forSequences)
1327 showMenu.removeAll();
1328 hideMenu.removeAll();
1330 final List<String> all = Arrays.asList(new String[] { MessageManager
1331 .getString("label.all") });
1332 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1333 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1335 showMenu.addSeparator();
1336 hideMenu.addSeparator();
1338 final AlignmentAnnotation[] annotations = ap.getAlignment()
1339 .getAlignmentAnnotation();
1342 * Find shown/hidden annotations types, distinguished by source (calcId),
1343 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1344 * the insertion order, which is the order of the annotations on the
1347 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1348 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1349 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1350 AlignmentAnnotationUtils.asList(annotations), forSequences);
1352 for (String calcId : hiddenTypes.keySet())
1354 for (List<String> type : hiddenTypes.get(calcId))
1356 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1360 // grey out 'show annotations' if none are hidden
1361 showMenu.setEnabled(!hiddenTypes.isEmpty());
1363 for (String calcId : shownTypes.keySet())
1365 for (List<String> type : shownTypes.get(calcId))
1367 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1371 // grey out 'hide annotations' if none are shown
1372 hideMenu.setEnabled(!shownTypes.isEmpty());
1376 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1379 * @param showOrHideMenu
1380 * the menu to add to
1381 * @param forSequences
1382 * the sequences whose annotations may be shown or hidden
1387 * if true this is a special label meaning 'All'
1388 * @param actionIsShow
1389 * if true, the select menu item action is to show the annotation
1392 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1393 final List<SequenceI> forSequences, String calcId,
1394 final List<String> types, final boolean allTypes,
1395 final boolean actionIsShow)
1397 String label = types.toString(); // [a, b, c]
1398 label = label.substring(1, label.length() - 1);
1399 final MenuItem item = new MenuItem(label);
1400 item.addActionListener(new java.awt.event.ActionListener()
1403 public void actionPerformed(ActionEvent e)
1405 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1406 types, forSequences, allTypes, actionIsShow);
1410 showOrHideMenu.add(item);