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 (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
222 MenuItem item = new MenuItem(
223 jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
225 item.addActionListener(this);
226 outputmenu.add(item);
229 buildAnnotationSubmenus();
231 SequenceGroup sg = ap.av.getSelectionGroup();
232 if (sg != null && sg.getSize() > 0)
234 editGroupName.setLabel(MessageManager.formatMessage(
235 "label.name_param", new Object[] { sg.getName() }));
236 showText.setState(sg.getDisplayText());
237 showColourText.setState(sg.getColourText());
238 showBoxes.setState(sg.getDisplayBoxes());
239 displayNonconserved.setState(sg.getShowNonconserved());
240 if (!ap.av.getAlignment().getGroups().contains(sg))
242 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
243 groupMenu.remove(unGroupMenuItem);
247 menu1.setLabel(MessageManager.getString("action.edit_group"));
248 groupMenu.remove(createGroupMenuItem);
258 if (links != null && links.size() > 0)
260 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
261 for (int i = 0; i < links.size(); i++)
263 String link = links.elementAt(i);
264 UrlLink urlLink = new UrlLink(link);
265 if (!urlLink.isValid())
267 System.err.println(urlLink.getInvalidMessage());
270 final String target = urlLink.getTarget(); // link.substring(0,
271 // link.indexOf("|"));
272 final String label = urlLink.getLabel();
273 if (seq != null && urlLink.isDynamic())
276 // collect matching db-refs
277 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
278 seq.getDBRefs(), new String[] { target });
279 // collect id string too
280 String id = seq.getName();
281 String descr = seq.getDescription();
282 if (descr != null && descr.length() < 1)
288 for (int r = 0; r < dbr.length; r++)
290 if (id != null && dbr[r].getAccessionId().equals(id))
292 // suppress duplicate link creation for the bare sequence ID
293 // string with this link
296 // create Bare ID link for this RUL
297 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
301 for (int u = 0; u < urls.length; u += 2)
303 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
310 // create Bare ID link for this RUL
311 String[] urls = urlLink.makeUrls(id, true);
314 for (int u = 0; u < urls.length; u += 2)
316 addshowLink(linkMenu, label, urls[u + 1]);
319 // addshowLink(linkMenu, target, url_pref + id + url_suff);
321 // Now construct URLs from description but only try to do it for regex
323 if (descr != null && urlLink.getRegexReplace() != null)
325 // create link for this URL from description only if regex matches
326 String[] urls = urlLink.makeUrls(descr, true);
329 for (int u = 0; u < urls.length; u += 2)
331 addshowLink(linkMenu, label, urls[u + 1]);
338 addshowLink(linkMenu, target, urlLink.getUrl_prefix()); // link.substring(link.lastIndexOf("|")+1));
343 * if (link.indexOf("$SEQUENCE_ID$") > -1) { // Substitute SEQUENCE_ID
344 * string and any matching database reference accessions String url_pref
345 * = link.substring(link.indexOf("|") + 1,
346 * link.indexOf("$SEQUENCE_ID$"));
348 * String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
349 * // collect matching db-refs DBRefEntry[] dbr =
350 * jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new
351 * String[]{target}); // collect id string too String id =
352 * seq.getName(); if (id.indexOf("|") > -1) { id =
353 * id.substring(id.lastIndexOf("|") + 1); } if (dbr!=null) { for (int
354 * r=0;r<dbr.length; r++) { if (dbr[r].getAccessionId().equals(id)) { //
355 * suppress duplicate link creation for the bare sequence ID string with
356 * this link id = null; } addshowLink(linkMenu,
357 * dbr[r].getSource()+"|"+dbr[r].getAccessionId(), target,
358 * url_pref+dbr[r].getAccessionId()+url_suff); } } if (id!=null) { //
359 * create Bare ID link for this RUL addshowLink(linkMenu, target,
360 * url_pref + id + url_suff); } } else { addshowLink(linkMenu, target,
361 * link.substring(link.lastIndexOf("|")+1)); }
364 if (linkMenu.getItemCount() > 0)
368 seqMenu.add(linkMenu);
376 // TODO: add group link menu entry here
379 seqMenu.setLabel(seq.getName());
380 if (seq == ap.av.getAlignment().getSeqrep())
382 makeReferenceSeq.setLabel(MessageManager
383 .getString("action.unmark_as_reference"));// Unmark
388 makeReferenceSeq.setLabel(MessageManager
389 .getString("action.set_as_reference")); // );
391 repGroup.setLabel(MessageManager.formatMessage(
392 "label.represent_group_with", new Object[] { seq.getName() }));
399 if (!ap.av.hasHiddenRows())
406 final int index = ap.av.getAlignment().findIndex(seq);
408 if (ap.av.adjustForHiddenSeqs(index)
409 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
411 revealSeq_index = index;
421 * Build menus for annotation types that may be shown or hidden, and for
422 * 'reference annotations' that may be added to the alignment.
424 private void buildAnnotationSubmenus()
427 * First for the currently selected sequence (if there is one):
429 final List<SequenceI> selectedSequence = (seq == null ? Collections
430 .<SequenceI> emptyList() : Arrays.asList(seq));
431 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
432 seqHideAnnotationsMenu, selectedSequence);
433 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
437 * and repeat for the current selection group (if there is one):
439 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
440 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
442 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
443 groupHideAnnotationsMenu, selectedGroup);
444 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
449 * Determine whether or not to enable 'add reference annotations' menu item.
450 * It is enable if there are any annotations, on any of the selected
451 * sequences, which are not yet on the alignment (visible or not).
454 * @param forSequences
456 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
457 List<SequenceI> forSequences)
459 menuItem.setEnabled(false);
462 * Temporary store to hold distinct calcId / type pairs for the tooltip.
463 * Using TreeMap means calcIds are shown in alphabetical order.
465 Map<String, String> tipEntries = new TreeMap<String, String>();
466 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
467 AlignmentI al = this.ap.av.getAlignment();
468 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
469 tipEntries, candidates, al);
470 if (!candidates.isEmpty())
472 StringBuilder tooltip = new StringBuilder(64);
473 tooltip.append(MessageManager.getString("label.add_annotations_for"));
476 * Found annotations that could be added. Enable the menu item, and
477 * configure its action.
479 menuItem.setEnabled(true);
481 menuItem.addActionListener(new ActionListener()
484 public void actionPerformed(ActionEvent e)
486 addReferenceAnnotations_actionPerformed(candidates);
493 * Add annotations to the sequences and to the alignment.
496 * a map whose keys are sequences on the alignment, and values a list
497 * of annotations to add to each sequence
499 protected void addReferenceAnnotations_actionPerformed(
500 Map<SequenceI, List<AlignmentAnnotation>> candidates)
502 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
503 final AlignmentI alignment = this.ap.getAlignment();
504 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
510 * add a show URL menu item to the given linkMenu
514 * - menu label string
518 private void addshowLink(Menu linkMenu, final String target,
521 addshowLink(linkMenu, target, target, url);
525 * add a show URL menu item to the given linkMenu
529 * - URL target window
531 * - menu label string
535 private void addshowLink(Menu linkMenu, final String target,
536 final String label, final String url)
538 MenuItem item = new MenuItem(label);
539 item.addActionListener(new java.awt.event.ActionListener()
542 public void actionPerformed(ActionEvent e)
544 ap.alignFrame.showURL(url, target);
551 public void itemStateChanged(ItemEvent evt)
553 if (evt.getSource() == abovePIDColour)
555 abovePIDColour_itemStateChanged();
557 else if (evt.getSource() == showColourText)
559 showColourText_itemStateChanged();
561 else if (evt.getSource() == showText)
563 showText_itemStateChanged();
565 else if (evt.getSource() == showBoxes)
567 showBoxes_itemStateChanged();
569 else if (evt.getSource() == displayNonconserved)
571 this.showNonconserved_itemStateChanged();
576 public void actionPerformed(ActionEvent evt)
578 Object source = evt.getSource();
579 if (source == clustalColour)
581 clustalColour_actionPerformed();
583 else if (source == zappoColour)
585 zappoColour_actionPerformed();
587 else if (source == taylorColour)
589 taylorColour_actionPerformed();
591 else if (source == hydrophobicityColour)
593 hydrophobicityColour_actionPerformed();
595 else if (source == helixColour)
597 helixColour_actionPerformed();
599 else if (source == strandColour)
601 strandColour_actionPerformed();
603 else if (source == turnColour)
605 turnColour_actionPerformed();
607 else if (source == buriedColour)
609 buriedColour_actionPerformed();
611 else if (source == nucleotideMenuItem)
613 nucleotideMenuItem_actionPerformed();
616 else if (source == userDefinedColour)
618 userDefinedColour_actionPerformed();
620 else if (source == PIDColour)
622 PIDColour_actionPerformed();
624 else if (source == BLOSUM62Colour)
626 BLOSUM62Colour_actionPerformed();
628 else if (source == noColourmenuItem)
630 noColourmenuItem_actionPerformed();
632 else if (source == conservationMenuItem)
634 conservationMenuItem_itemStateChanged();
636 else if (source == unGroupMenuItem)
638 unGroupMenuItem_actionPerformed();
641 else if (source == createGroupMenuItem)
643 createGroupMenuItem_actionPerformed();
646 else if (source == sequenceName)
650 else if (source == makeReferenceSeq)
652 makeReferenceSeq_actionPerformed();
654 else if (source == sequenceDetails)
656 showSequenceDetails();
658 else if (source == selSeqDetails)
660 showSequenceSelectionDetails();
662 else if (source == pdb)
666 else if (source == hideSeqs)
668 hideSequences(false);
670 else if (source == repGroup)
674 else if (source == revealSeq)
676 ap.av.showSequence(revealSeq_index);
678 else if (source == revealAll)
680 ap.av.showAllHiddenSeqs();
683 else if (source == editGroupName)
685 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
686 getGroup().getDescription(), " Group Name",
687 "Group Description", ap.alignFrame,
688 "Edit Group Name / Description", 500, 100, true);
692 getGroup().setName(dialog.getName().replace(' ', '_'));
693 getGroup().setDescription(dialog.getDescription());
697 else if (source == copy)
699 ap.alignFrame.copy_actionPerformed();
701 else if (source == cut)
703 ap.alignFrame.cut_actionPerformed();
705 else if (source == editSequence)
707 SequenceGroup sg = ap.av.getSelectionGroup();
713 seq = sg.getSequenceAt(0);
716 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
717 sg.getStartRes(), sg.getEndRes() + 1), null,
718 "Edit Sequence ", null,
720 ap.alignFrame, "Edit Sequence", 500, 100, true);
724 EditCommand editCommand = new EditCommand(
725 MessageManager.getString("label.edit_sequences"),
726 Action.REPLACE, dialog.getName().replace(' ',
727 ap.av.getGapCharacter()),
728 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
729 sg.getStartRes(), sg.getEndRes() + 1,
730 ap.av.getAlignment());
732 ap.alignFrame.addHistoryItem(editCommand);
734 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
739 else if (source == toUpper || source == toLower || source == toggleCase)
741 SequenceGroup sg = ap.av.getSelectionGroup();
744 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
745 sg.getStartRes(), sg.getEndRes() + 1);
750 if (source == toggleCase)
752 description = "Toggle Case";
753 caseChange = ChangeCaseCommand.TOGGLE_CASE;
755 else if (source == toUpper)
757 description = "To Upper Case";
758 caseChange = ChangeCaseCommand.TO_UPPER;
762 description = "To Lower Case";
763 caseChange = ChangeCaseCommand.TO_LOWER;
766 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
767 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
768 startEnd, caseChange);
770 ap.alignFrame.addHistoryItem(caseCommand);
772 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
777 else if (source == sequenceFeature)
779 SequenceGroup sg = ap.av.getSelectionGroup();
785 int rsize = 0, gSize = sg.getSize();
786 SequenceI[] rseqs, seqs = new SequenceI[gSize];
787 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
789 for (int i = 0; i < gSize; i++)
791 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
792 int end = sg.findEndRes(sg.getSequenceAt(i));
795 seqs[rsize] = sg.getSequenceAt(i);
796 features[rsize] = new SequenceFeature(null, null, null, start,
801 rseqs = new SequenceI[rsize];
802 tfeatures = new SequenceFeature[rsize];
803 System.arraycopy(seqs, 0, rseqs, 0, rsize);
804 System.arraycopy(features, 0, tfeatures, 0, rsize);
805 features = tfeatures;
808 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
811 ap.alignFrame.sequenceFeatures.setState(true);
812 ap.av.setShowSequenceFeatures(true);
814 ap.highlightSearchResults(null);
824 void outputText(ActionEvent e)
826 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
828 Frame frame = new Frame();
830 JalviewLite.addFrame(frame, MessageManager.formatMessage(
831 "label.selection_output_command",
832 new Object[] { e.getActionCommand() }), 600, 500);
833 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
834 // now returns a full copy of sequence data
835 // TODO consider using getSequenceSelection instead here
837 FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
838 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
839 ap.av.getShowJVSuffix(), ap, true));
843 protected void showSequenceSelectionDetails()
845 createSequenceDetailsReport(ap.av.getSequenceSelection());
848 protected void showSequenceDetails()
850 createSequenceDetailsReport(new SequenceI[] { seq });
853 public void createSequenceDetailsReport(SequenceI[] sequences)
856 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
858 StringBuffer contents = new StringBuffer();
859 for (SequenceI seq : sequences)
861 contents.append(MessageManager.formatMessage(
862 "label.annotation_for_displayid",
863 new Object[] { seq.getDisplayId(true) }));
864 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
870 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
871 .getMinMax() : null);
872 contents.append("</p>");
874 Frame frame = new Frame();
876 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
877 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
878 : "Selection"), 600, 500);
879 cap.setText(MessageManager.formatMessage("label.html_content",
880 new Object[] { contents.toString() }));
885 EditNameDialog dialog = new EditNameDialog(seq.getName(),
886 seq.getDescription(), " Sequence Name",
887 "Sequence Description", ap.alignFrame,
888 "Edit Sequence Name / Description", 500, 100, true);
892 seq.setName(dialog.getName());
893 seq.setDescription(dialog.getDescription());
894 ap.paintAlignment(false);
900 if (seq.getAllPDBEntries() != null)
902 PDBEntry entry = seq.getAllPDBEntries().firstElement();
904 if (ap.av.applet.jmolAvailable)
906 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
907 null, ap, DataSourceType.URL);
911 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
912 ap, DataSourceType.URL);
918 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
919 cap.setText(MessageManager.getString("label.paste_pdb_file"));
920 cap.setPDBImport(seq);
921 Frame frame = new Frame();
923 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
924 "label.paste_pdb_file_for_sequence",
925 new Object[] { seq.getName() }), 400, 300);
929 private void jbInit() throws Exception
931 groupMenu.setLabel(MessageManager.getString("label.selection"));
932 sequenceFeature.addActionListener(this);
934 editGroupName.addActionListener(this);
935 unGroupMenuItem.setLabel(MessageManager
936 .getString("action.remove_group"));
937 unGroupMenuItem.addActionListener(this);
939 createGroupMenuItem.setLabel(MessageManager
940 .getString("action.create_group"));
941 createGroupMenuItem.addActionListener(this);
943 nucleotideMenuItem.setLabel(MessageManager
944 .getString("label.nucleotide"));
945 nucleotideMenuItem.addActionListener(this);
946 conservationMenuItem.addItemListener(this);
947 abovePIDColour.addItemListener(this);
948 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
949 showBoxes.setLabel(MessageManager.getString("action.boxes"));
950 showBoxes.setState(true);
951 showBoxes.addItemListener(this);
952 sequenceName.addActionListener(this);
953 sequenceDetails.addActionListener(this);
954 selSeqDetails.addActionListener(this);
955 displayNonconserved.setLabel(MessageManager
956 .getString("label.show_non_conversed"));
957 displayNonconserved.setState(false);
958 displayNonconserved.addItemListener(this);
959 showText.setLabel(MessageManager.getString("action.text"));
960 showText.addItemListener(this);
961 showColourText.setLabel(MessageManager.getString("label.colour_text"));
962 showColourText.addItemListener(this);
963 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
964 seqMenu.setLabel(MessageManager.getString("label.sequence"));
965 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
966 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
967 repGroup.setLabel(MessageManager.formatMessage(
968 "label.represent_group_with", new Object[] { "" }));
969 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
970 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
971 menu1.setLabel(MessageManager.getString("label.group:"));
977 // groupMenu.add(selSeqDetails);
978 groupMenu.add(groupShowAnnotationsMenu);
979 groupMenu.add(groupHideAnnotationsMenu);
980 groupMenu.add(groupAddReferenceAnnotations);
981 groupMenu.add(editMenu);
982 groupMenu.add(outputmenu);
983 groupMenu.add(sequenceFeature);
984 groupMenu.add(createGroupMenuItem);
985 groupMenu.add(unGroupMenuItem);
986 groupMenu.add(menu1);
988 colourMenu.add(noColourmenuItem);
989 colourMenu.add(clustalColour);
990 colourMenu.add(BLOSUM62Colour);
991 colourMenu.add(PIDColour);
992 colourMenu.add(zappoColour);
993 colourMenu.add(taylorColour);
994 colourMenu.add(hydrophobicityColour);
995 colourMenu.add(helixColour);
996 colourMenu.add(strandColour);
997 colourMenu.add(turnColour);
998 colourMenu.add(buriedColour);
999 colourMenu.add(nucleotideMenuItem);
1000 colourMenu.add(userDefinedColour);
1001 colourMenu.addSeparator();
1002 colourMenu.add(abovePIDColour);
1003 colourMenu.add(conservationMenuItem);
1005 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
1006 noColourmenuItem.addActionListener(this);
1008 clustalColour.setLabel(MessageManager
1009 .getString("label.clustalx_colours"));
1010 clustalColour.addActionListener(this);
1011 zappoColour.setLabel(MessageManager.getString("label.zappo"));
1012 zappoColour.addActionListener(this);
1013 taylorColour.setLabel(MessageManager.getString("label.taylor"));
1014 taylorColour.addActionListener(this);
1015 hydrophobicityColour.setLabel(MessageManager
1016 .getString("label.hydrophobicity"));
1017 hydrophobicityColour.addActionListener(this);
1019 .setLabel(MessageManager.getString("label.helix_propensity"));
1020 helixColour.addActionListener(this);
1021 strandColour.setLabel(MessageManager
1022 .getString("label.strand_propensity"));
1023 strandColour.addActionListener(this);
1024 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
1025 turnColour.addActionListener(this);
1026 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
1027 buriedColour.addActionListener(this);
1028 abovePIDColour.setLabel(MessageManager
1029 .getString("label.above_identity_percentage"));
1031 userDefinedColour.setLabel(MessageManager
1032 .getString("action.user_defined"));
1033 userDefinedColour.addActionListener(this);
1034 PIDColour.setLabel(MessageManager
1035 .getString("label.percentage_identity"));
1036 PIDColour.addActionListener(this);
1037 BLOSUM62Colour.setLabel("BLOSUM62");
1038 BLOSUM62Colour.addActionListener(this);
1039 conservationMenuItem.setLabel(MessageManager
1040 .getString("label.conservation"));
1043 copy.addActionListener(this);
1045 cut.addActionListener(this);
1047 editMenu.add(editSequence);
1048 editSequence.addActionListener(this);
1050 editMenu.add(toUpper);
1051 toUpper.addActionListener(this);
1052 editMenu.add(toLower);
1053 toLower.addActionListener(this);
1054 editMenu.add(toggleCase);
1055 seqMenu.add(seqShowAnnotationsMenu);
1056 seqMenu.add(seqHideAnnotationsMenu);
1057 seqMenu.add(seqAddReferenceAnnotations);
1058 seqMenu.add(sequenceName);
1059 seqMenu.add(makeReferenceSeq);
1060 // seqMenu.add(sequenceDetails);
1062 if (!ap.av.applet.useXtrnalSviewer)
1066 seqMenu.add(repGroup);
1067 menu1.add(editGroupName);
1068 menu1.add(colourMenu);
1069 menu1.add(showBoxes);
1070 menu1.add(showText);
1071 menu1.add(showColourText);
1072 menu1.add(displayNonconserved);
1073 toggleCase.addActionListener(this);
1074 pdb.addActionListener(this);
1075 hideSeqs.addActionListener(this);
1076 repGroup.addActionListener(this);
1077 revealAll.addActionListener(this);
1078 revealSeq.addActionListener(this);
1079 makeReferenceSeq.addActionListener(this);
1084 ap.paintAlignment(true);
1087 protected void clustalColour_actionPerformed()
1089 SequenceGroup sg = getGroup();
1090 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1094 protected void zappoColour_actionPerformed()
1096 getGroup().cs = new ZappoColourScheme();
1100 protected void taylorColour_actionPerformed()
1102 getGroup().cs = new TaylorColourScheme();
1106 protected void hydrophobicityColour_actionPerformed()
1108 getGroup().cs = new HydrophobicColourScheme();
1112 protected void helixColour_actionPerformed()
1114 getGroup().cs = new HelixColourScheme();
1118 protected void strandColour_actionPerformed()
1120 getGroup().cs = new StrandColourScheme();
1124 protected void turnColour_actionPerformed()
1126 getGroup().cs = new TurnColourScheme();
1130 protected void buriedColour_actionPerformed()
1132 getGroup().cs = new BuriedColourScheme();
1136 public void nucleotideMenuItem_actionPerformed()
1138 getGroup().cs = new NucleotideColourScheme();
1142 protected void abovePIDColour_itemStateChanged()
1144 SequenceGroup sg = getGroup();
1150 if (abovePIDColour.getState())
1152 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1153 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1154 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1157 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1159 SliderPanel.showPIDSlider();
1163 // remove PIDColouring
1165 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1172 protected void userDefinedColour_actionPerformed()
1174 new UserDefinedColours(ap, getGroup());
1177 protected void PIDColour_actionPerformed()
1179 SequenceGroup sg = getGroup();
1180 sg.cs = new PIDColourScheme();
1181 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1182 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1186 protected void BLOSUM62Colour_actionPerformed()
1188 SequenceGroup sg = getGroup();
1190 sg.cs = new Blosum62ColourScheme();
1192 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1193 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1198 protected void noColourmenuItem_actionPerformed()
1200 getGroup().cs = null;
1204 protected void conservationMenuItem_itemStateChanged()
1206 SequenceGroup sg = getGroup();
1212 if (conservationMenuItem.getState())
1215 sg.cs.setConservation(Conservation.calculateConservation("Group",
1216 ResidueProperties.propHash, 3, sg.getSequences(ap.av
1217 .getHiddenRepSequences()), 0, ap.av.getAlignment()
1218 .getWidth(), false, ap.av.getConsPercGaps(), false));
1219 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1220 SliderPanel.showConservationSlider();
1223 // remove ConservationColouring
1225 sg.cs.setConservation(null);
1231 SequenceGroup getGroup()
1233 SequenceGroup sg = ap.av.getSelectionGroup();
1235 // this method won't add a new group if it already exists
1238 ap.av.getAlignment().addGroup(sg);
1244 void unGroupMenuItem_actionPerformed()
1246 SequenceGroup sg = ap.av.getSelectionGroup();
1247 ap.av.getAlignment().deleteGroup(sg);
1248 ap.av.setSelectionGroup(null);
1249 ap.paintAlignment(true);
1252 void createGroupMenuItem_actionPerformed()
1254 getGroup(); // implicitly create group
1258 public void showColourText_itemStateChanged()
1260 getGroup().setColourText(showColourText.getState());
1264 public void showText_itemStateChanged()
1266 getGroup().setDisplayText(showText.getState());
1270 public void makeReferenceSeq_actionPerformed()
1272 if (!ap.av.getAlignment().hasSeqrep())
1274 // initialise the display flags so the user sees something happen
1275 ap.av.setDisplayReferenceSeq(true);
1276 ap.av.setColourByReferenceSeq(true);
1277 ap.av.getAlignment().setSeqrep(seq);
1281 if (ap.av.getAlignment().getSeqrep() == seq)
1283 ap.av.getAlignment().setSeqrep(null);
1287 ap.av.getAlignment().setSeqrep(seq);
1293 public void showNonconserved_itemStateChanged()
1295 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1299 public void showBoxes_itemStateChanged()
1301 getGroup().setDisplayBoxes(showBoxes.getState());
1305 void hideSequences(boolean representGroup)
1307 ap.av.hideSequences(seq, representGroup);
1311 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1312 * "All" is added first, followed by a separator. Then add any annotation
1313 * types associated with the current selection. Separate menus are built for
1314 * the selected sequence group (if any), and the selected sequence.
1316 * Some annotation rows are always rendered together - these can be identified
1317 * by a common graphGroup property > -1. Only one of each group will be marked
1318 * as visible (to avoid duplication of the display). For such groups we add a
1319 * composite type name, e.g.
1321 * IUPredWS (Long), IUPredWS (Short)
1325 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1326 List<SequenceI> forSequences)
1328 showMenu.removeAll();
1329 hideMenu.removeAll();
1331 final List<String> all = Arrays.asList(new String[] { MessageManager
1332 .getString("label.all") });
1333 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1334 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1336 showMenu.addSeparator();
1337 hideMenu.addSeparator();
1339 final AlignmentAnnotation[] annotations = ap.getAlignment()
1340 .getAlignmentAnnotation();
1343 * Find shown/hidden annotations types, distinguished by source (calcId),
1344 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1345 * the insertion order, which is the order of the annotations on the
1348 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1349 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1350 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1351 AlignmentAnnotationUtils.asList(annotations), forSequences);
1353 for (String calcId : hiddenTypes.keySet())
1355 for (List<String> type : hiddenTypes.get(calcId))
1357 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1361 // grey out 'show annotations' if none are hidden
1362 showMenu.setEnabled(!hiddenTypes.isEmpty());
1364 for (String calcId : shownTypes.keySet())
1366 for (List<String> type : shownTypes.get(calcId))
1368 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1372 // grey out 'hide annotations' if none are shown
1373 hideMenu.setEnabled(!shownTypes.isEmpty());
1377 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1380 * @param showOrHideMenu
1381 * the menu to add to
1382 * @param forSequences
1383 * the sequences whose annotations may be shown or hidden
1388 * if true this is a special label meaning 'All'
1389 * @param actionIsShow
1390 * if true, the select menu item action is to show the annotation
1393 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1394 final List<SequenceI> forSequences, String calcId,
1395 final List<String> types, final boolean allTypes,
1396 final boolean actionIsShow)
1398 String label = types.toString(); // [a, b, c]
1399 label = label.substring(1, label.length() - 1);
1400 final MenuItem item = new MenuItem(label);
1401 item.addActionListener(new java.awt.event.ActionListener()
1404 public void actionPerformed(ActionEvent e)
1406 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1407 types, forSequences, allTypes, actionIsShow);
1411 showOrHideMenu.add(item);