2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.JalviewLite;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.DataSourceType;
39 import jalview.io.FileFormatI;
40 import jalview.io.FileFormats;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.renderer.ResidueShader;
43 import jalview.renderer.ResidueShaderI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.JalviewColourScheme;
50 import jalview.schemes.NucleotideColourScheme;
51 import jalview.schemes.PIDColourScheme;
52 import jalview.schemes.PurinePyrimidineColourScheme;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.MessageManager;
58 import jalview.util.UrlLink;
60 import java.awt.CheckboxMenuItem;
61 import java.awt.Frame;
63 import java.awt.MenuItem;
64 import java.awt.event.ActionEvent;
65 import java.awt.event.ActionListener;
66 import java.awt.event.ItemEvent;
67 import java.awt.event.ItemListener;
68 import java.util.Arrays;
69 import java.util.Collection;
70 import java.util.Collections;
71 import java.util.LinkedHashMap;
72 import java.util.List;
74 import java.util.SortedMap;
75 import java.util.TreeMap;
76 import java.util.Vector;
78 public class APopupMenu extends java.awt.PopupMenu implements
79 ActionListener, ItemListener
81 Menu groupMenu = new Menu();
83 MenuItem editGroupName = new MenuItem();
85 CheckboxMenuItem noColour = new CheckboxMenuItem();
87 protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
89 protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
91 protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
93 protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
95 protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
97 protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
99 protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
101 protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
103 protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
105 protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
107 CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
109 CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
111 protected MenuItem userDefinedColour = new MenuItem();
113 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
115 MenuItem modifyPID = new MenuItem();
117 protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
119 MenuItem modifyConservation = new MenuItem();
121 MenuItem noColourmenuItem = new MenuItem();
123 final AlignmentPanel ap;
125 MenuItem unGroupMenuItem = new MenuItem();
127 MenuItem createGroupMenuItem = new MenuItem();
129 Menu colourMenu = new Menu();
131 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
133 CheckboxMenuItem showText = new CheckboxMenuItem();
135 CheckboxMenuItem showColourText = new CheckboxMenuItem();
137 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
139 Menu seqShowAnnotationsMenu = new Menu(
140 MessageManager.getString("label.show_annotations"));
142 Menu seqHideAnnotationsMenu = new Menu(
143 MessageManager.getString("label.hide_annotations"));
145 MenuItem seqAddReferenceAnnotations = new MenuItem(
146 MessageManager.getString("label.add_reference_annotations"));
148 Menu groupShowAnnotationsMenu = new Menu(
149 MessageManager.getString("label.show_annotations"));
151 Menu groupHideAnnotationsMenu = new Menu(
152 MessageManager.getString("label.hide_annotations"));
154 MenuItem groupAddReferenceAnnotations = new MenuItem(
155 MessageManager.getString("label.add_reference_annotations"));
157 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
159 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
161 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
163 MenuItem toUpper = new MenuItem(
164 MessageManager.getString("label.to_upper_case"));
166 MenuItem toLower = new MenuItem(
167 MessageManager.getString("label.to_lower_case"));
169 MenuItem toggleCase = new MenuItem(
170 MessageManager.getString("label.toggle_case"));
172 Menu outputmenu = new Menu();
174 Menu seqMenu = new Menu();
176 MenuItem pdb = new MenuItem();
178 MenuItem hideSeqs = new MenuItem();
180 MenuItem repGroup = new MenuItem();
182 MenuItem sequenceName = new MenuItem(
183 MessageManager.getString("label.edit_name_description"));
185 MenuItem sequenceFeature = new MenuItem(
186 MessageManager.getString("label.create_sequence_feature"));
188 MenuItem editSequence = new MenuItem(
189 MessageManager.getString("label.edit_sequence"));
191 MenuItem sequenceDetails = new MenuItem(
192 MessageManager.getString("label.sequence_details"));
194 MenuItem selSeqDetails = new MenuItem(
195 MessageManager.getString("label.sequence_details"));
197 MenuItem makeReferenceSeq = new MenuItem();
201 MenuItem revealAll = new MenuItem();
203 MenuItem revealSeq = new MenuItem();
206 * index of sequence to be revealed
208 int revealSeq_index = -1;
210 Menu menu1 = new Menu();
212 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
215 // /////////////////////////////////////////////////////////
216 // If this is activated from the sequence panel, the user may want to
217 // edit or annotate a particular residue. Therefore display the residue menu
219 // If from the IDPanel, we must display the sequence menu
220 // ////////////////////////////////////////////////////////
228 } catch (Exception e)
233 for (String ff : FileFormats.getInstance().getWritableFormats(true))
235 MenuItem item = new MenuItem(ff);
237 item.addActionListener(this);
238 outputmenu.add(item);
241 buildAnnotationSubmenus();
243 SequenceGroup sg = ap.av.getSelectionGroup();
244 if (sg != null && sg.getSize() > 0)
246 if (sg.isNucleotide())
248 conservationColour.setEnabled(false);
249 clustalColour.setEnabled(false);
250 BLOSUM62Colour.setEnabled(false);
251 zappoColour.setEnabled(false);
252 taylorColour.setEnabled(false);
253 hydrophobicityColour.setEnabled(false);
254 helixColour.setEnabled(false);
255 strandColour.setEnabled(false);
256 turnColour.setEnabled(false);
257 buriedColour.setEnabled(false);
261 purinePyrimidineColour.setEnabled(false);
262 nucleotideColour.setEnabled(false);
264 editGroupName.setLabel(MessageManager.formatMessage(
265 "label.name_param", new Object[] { sg.getName() }));
266 showText.setState(sg.getDisplayText());
267 showColourText.setState(sg.getColourText());
268 showBoxes.setState(sg.getDisplayBoxes());
269 displayNonconserved.setState(sg.getShowNonconserved());
270 if (!ap.av.getAlignment().getGroups().contains(sg))
272 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
273 groupMenu.remove(unGroupMenuItem);
277 menu1.setLabel(MessageManager.getString("action.edit_group"));
278 groupMenu.remove(createGroupMenuItem);
281 abovePIDColour.setState(sg.cs.getThreshold() > 0);
282 conservationColour.setState(sg.cs.conservationApplied());
283 modifyPID.setEnabled(abovePIDColour.getState());
284 modifyConservation.setEnabled(conservationColour.getState());
287 setSelectedColour(sg.cs);
295 if (links != null && links.size() > 0)
297 addFeatureLinks(seq, links);
300 // TODO: add group link menu entry here
303 seqMenu.setLabel(seq.getName());
304 if (seq == ap.av.getAlignment().getSeqrep())
306 makeReferenceSeq.setLabel(MessageManager
307 .getString("action.unmark_as_reference"));// Unmark
312 makeReferenceSeq.setLabel(MessageManager
313 .getString("action.set_as_reference")); // );
315 repGroup.setLabel(MessageManager.formatMessage(
316 "label.represent_group_with", new Object[] { seq.getName() }));
323 if (!ap.av.hasHiddenRows())
330 final int index = ap.av.getAlignment().findIndex(seq);
332 if (ap.av.adjustForHiddenSeqs(index)
333 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
335 revealSeq_index = index;
345 * Select the menu item (if any) matching the current colour scheme. This
346 * works by matching the menu item name (not display text) to the canonical
347 * name of the colour scheme.
351 protected void setSelectedColour(ResidueShaderI cs)
353 if (cs == null || cs.getColourScheme() == null)
355 noColour.setState(true);
359 String name = cs.getColourScheme().getSchemeName();
360 for (int i = 0; i < colourMenu.getItemCount(); i++)
362 MenuItem item = colourMenu.getItem(i);
363 if (item instanceof CheckboxMenuItem)
365 if (name.equals(item.getName()))
367 ((CheckboxMenuItem) item).setState(true);
375 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
380 void addFeatureLinks(final SequenceI seq, List<String> links)
382 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
383 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
385 for (String link : links)
387 UrlLink urlLink = null;
390 urlLink = new UrlLink(link);
391 } catch (Exception foo)
393 System.err.println("Exception for URLLink '" + link + "': "
398 if (!urlLink.isValid())
400 System.err.println(urlLink.getInvalidMessage());
404 urlLink.createLinksFromSeq(seq, linkset);
407 addshowLinks(linkMenu, linkset.values());
409 // disable link menu if there are no valid entries
410 if (linkMenu.getItemCount() > 0)
412 linkMenu.setEnabled(true);
416 linkMenu.setEnabled(false);
421 seqMenu.add(linkMenu);
430 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
432 for (List<String> linkstrset : linkset)
434 // split linkstr into label and url
435 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
440 * Build menus for annotation types that may be shown or hidden, and for
441 * 'reference annotations' that may be added to the alignment.
443 private void buildAnnotationSubmenus()
446 * First for the currently selected sequence (if there is one):
448 final List<SequenceI> selectedSequence = (seq == null ? Collections
449 .<SequenceI> emptyList() : Arrays.asList(seq));
450 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
451 seqHideAnnotationsMenu, selectedSequence);
452 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
456 * and repeat for the current selection group (if there is one):
458 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
459 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
461 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
462 groupHideAnnotationsMenu, selectedGroup);
463 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
468 * Determine whether or not to enable 'add reference annotations' menu item.
469 * It is enable if there are any annotations, on any of the selected
470 * sequences, which are not yet on the alignment (visible or not).
473 * @param forSequences
475 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
476 List<SequenceI> forSequences)
478 menuItem.setEnabled(false);
481 * Temporary store to hold distinct calcId / type pairs for the tooltip.
482 * Using TreeMap means calcIds are shown in alphabetical order.
484 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
485 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
486 AlignmentI al = this.ap.av.getAlignment();
487 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
488 tipEntries, candidates, al);
489 if (!candidates.isEmpty())
491 StringBuilder tooltip = new StringBuilder(64);
492 tooltip.append(MessageManager.getString("label.add_annotations_for"));
495 * Found annotations that could be added. Enable the menu item, and
496 * configure its action.
498 menuItem.setEnabled(true);
500 menuItem.addActionListener(new ActionListener()
503 public void actionPerformed(ActionEvent e)
505 addReferenceAnnotations_actionPerformed(candidates);
512 * Add annotations to the sequences and to the alignment.
515 * a map whose keys are sequences on the alignment, and values a list
516 * of annotations to add to each sequence
518 protected void addReferenceAnnotations_actionPerformed(
519 Map<SequenceI, List<AlignmentAnnotation>> candidates)
521 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
522 final AlignmentI alignment = this.ap.getAlignment();
523 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
529 * add a show URL menu item to the given linkMenu
533 * - menu label string
537 private void addshowLink(Menu linkMenu, final String target,
540 addshowLink(linkMenu, target, target, url);
544 * add a show URL menu item to the given linkMenu
548 * - URL target window
550 * - menu label string
554 private void addshowLink(Menu linkMenu, final String target,
555 final String label, final String url)
557 MenuItem item = new MenuItem(label);
558 item.addActionListener(new java.awt.event.ActionListener()
561 public void actionPerformed(ActionEvent e)
563 ap.alignFrame.showURL(url, target);
570 * Actions on selecting / unselecting a checkbox menu item
573 public void itemStateChanged(ItemEvent evt)
575 Object source = evt.getSource();
576 if (source == noColour)
578 noColourmenuItem_actionPerformed();
580 else if (source == clustalColour)
582 clustalColour_actionPerformed();
584 else if (source == BLOSUM62Colour)
586 BLOSUM62Colour_actionPerformed();
588 else if (evt.getSource() == PIDColour)
590 PIDColour_actionPerformed();
592 else if (source == zappoColour)
594 zappoColour_actionPerformed();
596 else if (source == taylorColour)
598 taylorColour_actionPerformed();
600 else if (source == hydrophobicityColour)
602 hydrophobicityColour_actionPerformed();
604 else if (source == helixColour)
606 helixColour_actionPerformed();
608 else if (source == strandColour)
610 strandColour_actionPerformed();
612 else if (source == turnColour)
614 turnColour_actionPerformed();
616 else if (source == buriedColour)
618 buriedColour_actionPerformed();
620 else if (source == nucleotideColour)
622 nucleotideMenuItem_actionPerformed();
624 else if (source == purinePyrimidineColour)
626 purinePyrimidineColour_actionPerformed();
628 else if (source == abovePIDColour)
630 abovePIDColour_itemStateChanged();
632 else if (source == conservationColour)
634 conservationMenuItem_itemStateChanged();
636 else if (source == showColourText)
638 showColourText_itemStateChanged();
640 else if (source == showText)
642 showText_itemStateChanged();
644 else if (source == showBoxes)
646 showBoxes_itemStateChanged();
648 else if (source == displayNonconserved)
650 this.showNonconserved_itemStateChanged();
655 * Actions on clicking a menu item
658 public void actionPerformed(ActionEvent evt)
660 Object source = evt.getSource();
661 if (source == userDefinedColour)
663 userDefinedColour_actionPerformed();
665 else if (source == modifyConservation)
667 conservationMenuItem_itemStateChanged();
669 else if (source == modifyPID)
671 abovePIDColour_itemStateChanged();
673 else if (source == unGroupMenuItem)
675 unGroupMenuItem_actionPerformed();
678 else if (source == createGroupMenuItem)
680 createGroupMenuItem_actionPerformed();
683 else if (source == sequenceName)
687 else if (source == makeReferenceSeq)
689 makeReferenceSeq_actionPerformed();
691 else if (source == sequenceDetails)
693 showSequenceDetails();
695 else if (source == selSeqDetails)
697 showSequenceSelectionDetails();
699 else if (source == pdb)
703 else if (source == hideSeqs)
705 hideSequences(false);
707 else if (source == repGroup)
711 else if (source == revealSeq)
713 ap.av.showSequence(revealSeq_index);
715 else if (source == revealAll)
717 ap.av.showAllHiddenSeqs();
720 else if (source == editGroupName)
722 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
723 getGroup().getDescription(), " Group Name",
724 "Group Description", ap.alignFrame,
725 "Edit Group Name / Description", 500, 100, true);
729 getGroup().setName(dialog.getName().replace(' ', '_'));
730 getGroup().setDescription(dialog.getDescription());
734 else if (source == copy)
736 ap.alignFrame.copy_actionPerformed();
738 else if (source == cut)
740 ap.alignFrame.cut_actionPerformed();
742 else if (source == editSequence)
744 SequenceGroup sg = ap.av.getSelectionGroup();
750 seq = sg.getSequenceAt(0);
753 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
754 sg.getStartRes(), sg.getEndRes() + 1), null,
755 "Edit Sequence ", null,
757 ap.alignFrame, "Edit Sequence", 500, 100, true);
761 EditCommand editCommand = new EditCommand(
762 MessageManager.getString("label.edit_sequences"),
763 Action.REPLACE, dialog.getName().replace(' ',
764 ap.av.getGapCharacter()),
765 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
766 sg.getStartRes(), sg.getEndRes() + 1,
767 ap.av.getAlignment());
769 ap.alignFrame.addHistoryItem(editCommand);
771 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
776 else if (source == toUpper || source == toLower || source == toggleCase)
778 SequenceGroup sg = ap.av.getSelectionGroup();
781 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
782 sg.getStartRes(), sg.getEndRes() + 1);
787 if (source == toggleCase)
789 description = "Toggle Case";
790 caseChange = ChangeCaseCommand.TOGGLE_CASE;
792 else if (source == toUpper)
794 description = "To Upper Case";
795 caseChange = ChangeCaseCommand.TO_UPPER;
799 description = "To Lower Case";
800 caseChange = ChangeCaseCommand.TO_LOWER;
803 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
804 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
805 startEnd, caseChange);
807 ap.alignFrame.addHistoryItem(caseCommand);
809 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
814 else if (source == sequenceFeature)
816 SequenceGroup sg = ap.av.getSelectionGroup();
822 int rsize = 0, gSize = sg.getSize();
823 SequenceI[] rseqs, seqs = new SequenceI[gSize];
824 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
826 for (int i = 0; i < gSize; i++)
828 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
829 int end = sg.findEndRes(sg.getSequenceAt(i));
832 seqs[rsize] = sg.getSequenceAt(i);
833 features[rsize] = new SequenceFeature(null, null, null, start,
838 rseqs = new SequenceI[rsize];
839 tfeatures = new SequenceFeature[rsize];
840 System.arraycopy(seqs, 0, rseqs, 0, rsize);
841 System.arraycopy(features, 0, tfeatures, 0, rsize);
842 features = tfeatures;
845 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
848 ap.alignFrame.sequenceFeatures.setState(true);
849 ap.av.setShowSequenceFeatures(true);
851 ap.highlightSearchResults(null);
861 void outputText(ActionEvent e)
863 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
865 Frame frame = new Frame();
867 JalviewLite.addFrame(frame, MessageManager.formatMessage(
868 "label.selection_output_command",
869 new Object[] { e.getActionCommand() }), 600, 500);
870 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
871 // now returns a full copy of sequence data
872 // TODO consider using getSequenceSelection instead here
874 FileFormatI fileFormat = FileFormats.getInstance().forName(
875 e.getActionCommand());
876 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
877 ap.av.getShowJVSuffix(), ap, true));
881 protected void showSequenceSelectionDetails()
883 createSequenceDetailsReport(ap.av.getSequenceSelection());
886 protected void showSequenceDetails()
888 createSequenceDetailsReport(new SequenceI[] { seq });
891 public void createSequenceDetailsReport(SequenceI[] sequences)
894 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
896 StringBuilder contents = new StringBuilder(128);
897 for (SequenceI seq : sequences)
899 contents.append(MessageManager.formatMessage(
900 "label.annotation_for_displayid",
901 new Object[] { seq.getDisplayId(true) }));
902 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
907 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
908 .getMinMax() : null);
909 contents.append("</p>");
911 Frame frame = new Frame();
913 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
914 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
915 : "Selection"), 600, 500);
916 cap.setText(MessageManager.formatMessage("label.html_content",
917 new Object[] { contents.toString() }));
922 EditNameDialog dialog = new EditNameDialog(seq.getName(),
923 seq.getDescription(), " Sequence Name",
924 "Sequence Description", ap.alignFrame,
925 "Edit Sequence Name / Description", 500, 100, true);
929 seq.setName(dialog.getName());
930 seq.setDescription(dialog.getDescription());
931 ap.paintAlignment(false);
937 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
938 if (pdbs != null && !pdbs.isEmpty())
940 PDBEntry entry = pdbs.firstElement();
942 if (ap.av.applet.jmolAvailable)
944 new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
949 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
950 ap, DataSourceType.URL);
956 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
957 cap.setText(MessageManager.getString("label.paste_pdb_file"));
958 cap.setPDBImport(seq);
959 Frame frame = new Frame();
961 JalviewLite.addFrame(frame, MessageManager.formatMessage(
962 "label.paste_pdb_file_for_sequence",
963 new Object[] { seq.getName() }), 400, 300);
967 private void jbInit() throws Exception
969 groupMenu.setLabel(MessageManager.getString("label.selection"));
970 sequenceFeature.addActionListener(this);
972 editGroupName.addActionListener(this);
973 unGroupMenuItem.setLabel(MessageManager
974 .getString("action.remove_group"));
975 unGroupMenuItem.addActionListener(this);
977 createGroupMenuItem.setLabel(MessageManager
978 .getString("action.create_group"));
979 createGroupMenuItem.addActionListener(this);
981 modifyPID.setEnabled(abovePIDColour.getState());
982 modifyConservation.setEnabled(conservationColour.getState());
983 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
984 showBoxes.setLabel(MessageManager.getString("action.boxes"));
985 showBoxes.setState(true);
986 showBoxes.addItemListener(this);
987 sequenceName.addActionListener(this);
988 sequenceDetails.addActionListener(this);
989 selSeqDetails.addActionListener(this);
990 displayNonconserved.setLabel(MessageManager
991 .getString("label.show_non_conserved"));
992 displayNonconserved.setState(false);
993 displayNonconserved.addItemListener(this);
994 showText.setLabel(MessageManager.getString("action.text"));
995 showText.addItemListener(this);
996 showColourText.setLabel(MessageManager.getString("label.colour_text"));
997 showColourText.addItemListener(this);
998 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
999 seqMenu.setLabel(MessageManager.getString("label.sequence"));
1000 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
1001 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
1002 repGroup.setLabel(MessageManager.formatMessage(
1003 "label.represent_group_with", new Object[] { "" }));
1004 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
1005 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
1006 menu1.setLabel(MessageManager.getString("label.group:"));
1010 this.add(revealSeq);
1011 this.add(revealAll);
1012 // groupMenu.add(selSeqDetails);
1013 groupMenu.add(groupShowAnnotationsMenu);
1014 groupMenu.add(groupHideAnnotationsMenu);
1015 groupMenu.add(groupAddReferenceAnnotations);
1016 groupMenu.add(editMenu);
1017 groupMenu.add(outputmenu);
1018 groupMenu.add(sequenceFeature);
1019 groupMenu.add(createGroupMenuItem);
1020 groupMenu.add(unGroupMenuItem);
1021 groupMenu.add(menu1);
1023 colourMenu.add(noColour);
1024 colourMenu.add(clustalColour);
1025 colourMenu.add(BLOSUM62Colour);
1026 colourMenu.add(PIDColour);
1027 colourMenu.add(zappoColour);
1028 colourMenu.add(taylorColour);
1029 colourMenu.add(hydrophobicityColour);
1030 colourMenu.add(helixColour);
1031 colourMenu.add(strandColour);
1032 colourMenu.add(turnColour);
1033 colourMenu.add(buriedColour);
1034 colourMenu.add(nucleotideColour);
1035 colourMenu.add(purinePyrimidineColour);
1036 colourMenu.add(userDefinedColour);
1037 colourMenu.addSeparator();
1038 colourMenu.add(conservationColour);
1039 colourMenu.add(modifyConservation);
1040 colourMenu.add(abovePIDColour);
1041 colourMenu.add(modifyPID);
1043 noColour.setLabel(MessageManager.getString("label.none"));
1044 noColour.addItemListener(this);
1047 * setName allows setSelectedColour to do its thing
1049 clustalColour.setLabel(MessageManager
1050 .getString("label.colourScheme_clustal"));
1051 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1052 clustalColour.addItemListener(this);
1053 BLOSUM62Colour.setLabel(MessageManager
1054 .getString("label.colourScheme_blosum62"));
1055 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1056 BLOSUM62Colour.addItemListener(this);
1057 PIDColour.setLabel(MessageManager
1058 .getString("label.colourScheme_%_identity"));
1059 PIDColour.setName(JalviewColourScheme.PID.toString());
1060 PIDColour.addItemListener(this);
1061 zappoColour.setLabel(MessageManager
1062 .getString("label.colourScheme_zappo"));
1063 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1064 zappoColour.addItemListener(this);
1065 taylorColour.setLabel(MessageManager
1066 .getString("label.colourScheme_taylor"));
1067 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1068 taylorColour.addItemListener(this);
1069 hydrophobicityColour.setLabel(MessageManager
1070 .getString("label.colourScheme_hydrophobic"));
1071 hydrophobicityColour
1072 .setName(JalviewColourScheme.Hydrophobic.toString());
1073 hydrophobicityColour.addItemListener(this);
1074 helixColour.setLabel(MessageManager
1075 .getString("label.colourScheme_helix_propensity"));
1076 helixColour.setName(JalviewColourScheme.Helix.toString());
1077 helixColour.addItemListener(this);
1078 strandColour.setLabel(MessageManager
1079 .getString("label.colourScheme_strand_propensity"));
1080 strandColour.setName(JalviewColourScheme.Strand.toString());
1081 strandColour.addItemListener(this);
1082 turnColour.setLabel(MessageManager
1083 .getString("label.colourScheme_turn_propensity"));
1084 turnColour.setName(JalviewColourScheme.Turn.toString());
1085 turnColour.addItemListener(this);
1086 buriedColour.setLabel(MessageManager
1087 .getString("label.colourScheme_buried_index"));
1088 buriedColour.setName(JalviewColourScheme.Buried.toString());
1089 buriedColour.addItemListener(this);
1090 nucleotideColour.setLabel(MessageManager
1091 .getString("label.colourScheme_nucleotide"));
1092 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1093 nucleotideColour.addItemListener(this);
1094 purinePyrimidineColour.setLabel(MessageManager
1095 .getString("label.colourScheme_purine/pyrimidine"));
1096 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1098 purinePyrimidineColour.addItemListener(this);
1100 userDefinedColour.setLabel(MessageManager
1101 .getString("action.user_defined"));
1102 userDefinedColour.addActionListener(this);
1104 abovePIDColour.setLabel(MessageManager
1105 .getString("label.above_identity_threshold"));
1106 abovePIDColour.addItemListener(this);
1107 modifyPID.setLabel(MessageManager
1108 .getString("label.modify_identity_threshold"));
1109 modifyPID.addActionListener(this);
1110 conservationColour.setLabel(MessageManager
1111 .getString("action.by_conservation"));
1112 conservationColour.addItemListener(this);
1113 modifyConservation.setLabel(MessageManager
1114 .getString("label.modify_conservation_threshold"));
1115 modifyConservation.addActionListener(this);
1117 PIDColour.addActionListener(this);
1118 BLOSUM62Colour.addActionListener(this);
1121 copy.addActionListener(this);
1123 cut.addActionListener(this);
1125 editMenu.add(editSequence);
1126 editSequence.addActionListener(this);
1128 editMenu.add(toUpper);
1129 toUpper.addActionListener(this);
1130 editMenu.add(toLower);
1131 toLower.addActionListener(this);
1132 editMenu.add(toggleCase);
1133 seqMenu.add(seqShowAnnotationsMenu);
1134 seqMenu.add(seqHideAnnotationsMenu);
1135 seqMenu.add(seqAddReferenceAnnotations);
1136 seqMenu.add(sequenceName);
1137 seqMenu.add(makeReferenceSeq);
1138 // seqMenu.add(sequenceDetails);
1140 if (!ap.av.applet.useXtrnalSviewer)
1144 seqMenu.add(repGroup);
1145 menu1.add(editGroupName);
1146 menu1.add(colourMenu);
1147 menu1.add(showBoxes);
1148 menu1.add(showText);
1149 menu1.add(showColourText);
1150 menu1.add(displayNonconserved);
1151 toggleCase.addActionListener(this);
1152 pdb.addActionListener(this);
1153 hideSeqs.addActionListener(this);
1154 repGroup.addActionListener(this);
1155 revealAll.addActionListener(this);
1156 revealSeq.addActionListener(this);
1157 makeReferenceSeq.addActionListener(this);
1162 ap.paintAlignment(true);
1165 protected void clustalColour_actionPerformed()
1167 SequenceGroup sg = getGroup();
1168 sg.cs = new ResidueShader(new ClustalxColourScheme(sg,
1169 ap.av.getHiddenRepSequences()));
1173 protected void zappoColour_actionPerformed()
1175 getGroup().cs = new ResidueShader(new ZappoColourScheme());
1179 protected void taylorColour_actionPerformed()
1181 getGroup().cs = new ResidueShader(new TaylorColourScheme());
1185 protected void hydrophobicityColour_actionPerformed()
1187 getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
1191 protected void helixColour_actionPerformed()
1193 getGroup().cs = new ResidueShader(new HelixColourScheme());
1197 protected void strandColour_actionPerformed()
1199 getGroup().cs = new ResidueShader(new StrandColourScheme());
1203 protected void turnColour_actionPerformed()
1205 getGroup().cs = new ResidueShader(new TurnColourScheme());
1209 protected void buriedColour_actionPerformed()
1211 getGroup().cs = new ResidueShader(new BuriedColourScheme());
1215 public void nucleotideMenuItem_actionPerformed()
1217 getGroup().cs = new ResidueShader(new NucleotideColourScheme());
1221 public void purinePyrimidineColour_actionPerformed()
1223 getGroup().cs = new ResidueShader(
1224 new PurinePyrimidineColourScheme());
1228 protected void abovePIDColour_itemStateChanged()
1230 SequenceGroup sg = getGroup();
1236 if (abovePIDColour.getState())
1238 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1239 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1240 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1243 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1245 SliderPanel.showPIDSlider();
1249 // remove PIDColouring
1251 SliderPanel.hidePIDSlider();
1252 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1254 modifyPID.setEnabled(abovePIDColour.getState());
1258 protected void userDefinedColour_actionPerformed()
1260 new UserDefinedColours(ap, getGroup());
1263 protected void PIDColour_actionPerformed()
1265 SequenceGroup sg = getGroup();
1266 sg.cs = new ResidueShader(new PIDColourScheme());
1267 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1268 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1272 protected void BLOSUM62Colour_actionPerformed()
1274 SequenceGroup sg = getGroup();
1276 sg.cs = new ResidueShader(new Blosum62ColourScheme());
1278 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1279 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1284 protected void noColourmenuItem_actionPerformed()
1286 getGroup().cs = null;
1290 protected void conservationMenuItem_itemStateChanged()
1292 SequenceGroup sg = getGroup();
1298 if (conservationColour.getState())
1300 Conservation conservation = Conservation.calculateConservation(
1302 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1303 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1305 sg.getGroupColourScheme().setConservation(conservation);
1306 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1307 SliderPanel.showConservationSlider();
1310 // remove ConservationColouring
1312 SliderPanel.hideConservationSlider();
1313 sg.cs.setConservation(null);
1315 modifyConservation.setEnabled(conservationColour.getState());
1319 SequenceGroup getGroup()
1321 SequenceGroup sg = ap.av.getSelectionGroup();
1323 // this method won't add a new group if it already exists
1326 ap.av.getAlignment().addGroup(sg);
1332 void unGroupMenuItem_actionPerformed()
1334 SequenceGroup sg = ap.av.getSelectionGroup();
1335 ap.av.getAlignment().deleteGroup(sg);
1336 ap.av.setSelectionGroup(null);
1337 ap.paintAlignment(true);
1340 void createGroupMenuItem_actionPerformed()
1342 getGroup(); // implicitly create group
1346 public void showColourText_itemStateChanged()
1348 getGroup().setColourText(showColourText.getState());
1352 public void showText_itemStateChanged()
1354 getGroup().setDisplayText(showText.getState());
1358 public void makeReferenceSeq_actionPerformed()
1360 if (!ap.av.getAlignment().hasSeqrep())
1362 // initialise the display flags so the user sees something happen
1363 ap.av.setDisplayReferenceSeq(true);
1364 ap.av.setColourByReferenceSeq(true);
1365 ap.av.getAlignment().setSeqrep(seq);
1369 if (ap.av.getAlignment().getSeqrep() == seq)
1371 ap.av.getAlignment().setSeqrep(null);
1375 ap.av.getAlignment().setSeqrep(seq);
1381 public void showNonconserved_itemStateChanged()
1383 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1387 public void showBoxes_itemStateChanged()
1389 getGroup().setDisplayBoxes(showBoxes.getState());
1393 void hideSequences(boolean representGroup)
1395 ap.av.hideSequences(seq, representGroup);
1399 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1400 * "All" is added first, followed by a separator. Then add any annotation
1401 * types associated with the current selection. Separate menus are built for
1402 * the selected sequence group (if any), and the selected sequence.
1404 * Some annotation rows are always rendered together - these can be identified
1405 * by a common graphGroup property > -1. Only one of each group will be marked
1406 * as visible (to avoid duplication of the display). For such groups we add a
1407 * composite type name, e.g.
1409 * IUPredWS (Long), IUPredWS (Short)
1413 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1414 List<SequenceI> forSequences)
1416 showMenu.removeAll();
1417 hideMenu.removeAll();
1419 final List<String> all = Arrays.asList(new String[] { MessageManager
1420 .getString("label.all") });
1421 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1422 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1424 showMenu.addSeparator();
1425 hideMenu.addSeparator();
1427 final AlignmentAnnotation[] annotations = ap.getAlignment()
1428 .getAlignmentAnnotation();
1431 * Find shown/hidden annotations types, distinguished by source (calcId),
1432 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1433 * the insertion order, which is the order of the annotations on the
1436 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1437 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1438 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1439 AlignmentAnnotationUtils.asList(annotations), forSequences);
1441 for (String calcId : hiddenTypes.keySet())
1443 for (List<String> type : hiddenTypes.get(calcId))
1445 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1449 // grey out 'show annotations' if none are hidden
1450 showMenu.setEnabled(!hiddenTypes.isEmpty());
1452 for (String calcId : shownTypes.keySet())
1454 for (List<String> type : shownTypes.get(calcId))
1456 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1460 // grey out 'hide annotations' if none are shown
1461 hideMenu.setEnabled(!shownTypes.isEmpty());
1465 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1468 * @param showOrHideMenu
1469 * the menu to add to
1470 * @param forSequences
1471 * the sequences whose annotations may be shown or hidden
1476 * if true this is a special label meaning 'All'
1477 * @param actionIsShow
1478 * if true, the select menu item action is to show the annotation
1481 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1482 final List<SequenceI> forSequences, String calcId,
1483 final List<String> types, final boolean allTypes,
1484 final boolean actionIsShow)
1486 String label = types.toString(); // [a, b, c]
1487 label = label.substring(1, label.length() - 1);
1488 final MenuItem item = new MenuItem(label);
1489 item.addActionListener(new java.awt.event.ActionListener()
1492 public void actionPerformed(ActionEvent e)
1494 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1495 types, forSequences, allTypes, actionIsShow);
1499 showOrHideMenu.add(item);