2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.Conservation;
26 import jalview.commands.ChangeCaseCommand;
27 import jalview.commands.EditCommand;
28 import jalview.commands.EditCommand.Action;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.DBRefEntry;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceFeature;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.io.FormatAdapter;
39 import jalview.io.SequenceAnnotationReport;
40 import jalview.schemes.AnnotationColourGradient;
41 import jalview.schemes.Blosum62ColourScheme;
42 import jalview.schemes.BuriedColourScheme;
43 import jalview.schemes.ClustalxColourScheme;
44 import jalview.schemes.HelixColourScheme;
45 import jalview.schemes.HydrophobicColourScheme;
46 import jalview.schemes.NucleotideColourScheme;
47 import jalview.schemes.PIDColourScheme;
48 import jalview.schemes.PurinePyrimidineColourScheme;
49 import jalview.schemes.ResidueProperties;
50 import jalview.schemes.StrandColourScheme;
51 import jalview.schemes.TaylorColourScheme;
52 import jalview.schemes.TurnColourScheme;
53 import jalview.schemes.UserColourScheme;
54 import jalview.schemes.ZappoColourScheme;
55 import jalview.util.GroupUrlLink;
56 import jalview.util.GroupUrlLink.UrlStringTooLongException;
57 import jalview.util.MessageManager;
58 import jalview.util.UrlLink;
60 import java.awt.Color;
61 import java.awt.event.ActionEvent;
62 import java.awt.event.ActionListener;
63 import java.util.ArrayList;
64 import java.util.Arrays;
65 import java.util.Collection;
66 import java.util.Collections;
67 import java.util.Hashtable;
68 import java.util.LinkedHashMap;
69 import java.util.List;
71 import java.util.TreeMap;
72 import java.util.Vector;
74 import javax.swing.ButtonGroup;
75 import javax.swing.JCheckBoxMenuItem;
76 import javax.swing.JColorChooser;
77 import javax.swing.JMenu;
78 import javax.swing.JMenuItem;
79 import javax.swing.JOptionPane;
80 import javax.swing.JPopupMenu;
81 import javax.swing.JRadioButtonMenuItem;
87 * @version $Revision: 1.118 $
89 public class PopupMenu extends JPopupMenu
91 private static final String ALL_ANNOTATIONS = "All";
93 private static final String COMMA = ",";
95 JMenu groupMenu = new JMenu();
97 JMenuItem groupName = new JMenuItem();
99 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
113 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
115 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
117 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
125 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
127 // protected JRadioButtonMenuItem covariationColour = new
128 // JRadioButtonMenuItem();
130 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
132 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
136 JMenu sequenceMenu = new JMenu();
138 JMenuItem sequenceName = new JMenuItem();
140 JMenuItem sequenceDetails = new JMenuItem();
142 JMenuItem sequenceSelDetails = new JMenuItem();
144 JMenuItem chooseAnnotations = new JMenuItem();
148 JMenuItem createGroupMenuItem = new JMenuItem();
150 JMenuItem unGroupMenuItem = new JMenuItem();
152 JMenuItem outline = new JMenuItem();
154 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
156 JMenu colourMenu = new JMenu();
158 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
164 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
166 JMenu editMenu = new JMenu();
168 JMenuItem cut = new JMenuItem();
170 JMenuItem copy = new JMenuItem();
172 JMenuItem upperCase = new JMenuItem();
174 JMenuItem lowerCase = new JMenuItem();
176 JMenuItem toggle = new JMenuItem();
178 JMenu pdbMenu = new JMenu();
180 JMenuItem pdbFromFile = new JMenuItem();
182 // JBPNote: Commented these out - Should add these services via the web
183 // services menu system.
184 // JMenuItem ContraFold = new JMenuItem();
186 // JMenuItem RNAFold = new JMenuItem();
188 JMenuItem enterPDB = new JMenuItem();
190 JMenuItem discoverPDB = new JMenuItem();
192 JMenu outputMenu = new JMenu();
194 JMenu seqShowAnnotationsMenu = new JMenu();
196 JMenu seqHideAnnotationsMenu = new JMenu();
198 JMenuItem seqAddReferenceAnnotations = new JMenuItem();
200 JMenu groupShowAnnotationsMenu = new JMenu();
202 JMenu groupHideAnnotationsMenu = new JMenu();
204 JMenuItem groupAddReferenceAnnotations = new JMenuItem();
206 JMenuItem sequenceFeature = new JMenuItem();
208 JMenuItem textColour = new JMenuItem();
210 JMenu jMenu1 = new JMenu();
212 JMenu structureMenu = new JMenu();
214 JMenu viewStructureMenu = new JMenu();
216 // JMenu colStructureMenu = new JMenu();
217 JMenuItem editSequence = new JMenuItem();
219 // JMenuItem annotationMenuItem = new JMenuItem();
221 JMenu groupLinksMenu;
224 * Creates a new PopupMenu object.
231 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
233 this(ap, seq, links, null);
243 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
244 Vector links, Vector groupLinks)
246 // /////////////////////////////////////////////////////////
247 // If this is activated from the sequence panel, the user may want to
248 // edit or annotate a particular residue. Therefore display the residue menu
250 // If from the IDPanel, we must display the sequence menu
251 // ////////////////////////////////////////////////////////
255 ButtonGroup colours = new ButtonGroup();
256 colours.add(noColourmenuItem);
257 colours.add(clustalColour);
258 colours.add(zappoColour);
259 colours.add(taylorColour);
260 colours.add(hydrophobicityColour);
261 colours.add(helixColour);
262 colours.add(strandColour);
263 colours.add(turnColour);
264 colours.add(buriedColour);
265 colours.add(abovePIDColour);
266 colours.add(userDefinedColour);
267 colours.add(PIDColour);
268 colours.add(BLOSUM62Colour);
269 colours.add(purinePyrimidineColour);
270 colours.add(RNAInteractionColour);
271 // colours.add(covariationColour);
273 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
275 JMenuItem item = new JMenuItem(
276 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
278 item.addActionListener(new java.awt.event.ActionListener()
281 public void actionPerformed(ActionEvent e)
283 outputText_actionPerformed(e);
287 outputMenu.add(item);
291 * Build menus for annotation types that may be shown or hidden, and for
292 * 'reference annotations' that may be added to the alignment. First for the
293 * currently selected sequence (if there is one):
295 final List<SequenceI> selectedSequence = (seq == null ? Collections
296 .<SequenceI> emptyList() : Arrays.asList(seq));
297 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
298 seqHideAnnotationsMenu, selectedSequence);
299 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
303 * And repeat for the current selection group (if there is one):
305 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
306 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
308 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
309 groupHideAnnotationsMenu, selectedGroup);
310 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
316 } catch (Exception e)
324 sequenceMenu.setText(sequence.getName());
326 if (seq.getDatasetSequence().getPDBId() != null
327 && seq.getDatasetSequence().getPDBId().size() > 0)
329 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
332 while (e.hasMoreElements())
334 final PDBEntry pdb = (PDBEntry) e.nextElement();
336 menuItem = new JMenuItem();
337 menuItem.setText(pdb.getId());
338 menuItem.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent e)
343 // TODO re JAL-860: optionally open dialog or provide a menu entry
344 // allowing user to open just one structure per sequence
345 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
346 // { pdb })[0], null, ap);
347 new StructureViewer(ap.getStructureSelectionManager())
349 ap.av.collateForPDB(new PDBEntry[]
350 { pdb })[0], null, ap);
353 viewStructureMenu.add(menuItem);
356 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
357 * menuItem.addActionListener(new java.awt.event.ActionListener() {
358 * public void actionPerformed(ActionEvent e) {
359 * colourByStructure(pdb.getId()); } });
360 * colStructureMenu.add(menuItem);
366 if (ap.av.getAlignment().isNucleotide() == false)
368 structureMenu.remove(viewStructureMenu);
370 // structureMenu.remove(colStructureMenu);
373 if (ap.av.getAlignment().isNucleotide() == true)
375 AlignmentAnnotation[] aa = ap.av.getAlignment()
376 .getAlignmentAnnotation();
377 for (int i = 0; aa != null && i < aa.length; i++)
379 if (aa[i].isValidStruc() && aa[i].sequenceRef == null)
381 final String rnastruc = aa[i].getRNAStruc();
382 final String structureLine = aa[i].label + " (alignment)";
383 menuItem = new JMenuItem();
384 menuItem.setText(MessageManager.formatMessage(
385 "label.2d_rna_structure_line", new String[]
387 menuItem.addActionListener(new java.awt.event.ActionListener()
390 public void actionPerformed(ActionEvent e)
392 // // System.out.println("1:"+structureLine);
393 // System.out.println("1:sname" + seq.getName());
394 // System.out.println("2:seq" + seq);
396 // // System.out.println("3:"+seq.getSequenceAsString());
397 // System.out.println("3:strucseq" + rnastruc);
398 // // System.out.println("4:struc"+seq.getRNA());
399 // System.out.println("5:name" + seq.getName());
400 // System.out.println("6:ap" + ap);
401 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
402 rnastruc, seq.getName(), ap);
403 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
404 // seq.getName(), ap);
405 System.out.println("end");
408 viewStructureMenu.add(menuItem);
412 // SequenceFeatures[] test = seq.getSequenceFeatures();
414 if (seq.getAnnotation() != null)
416 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
417 for (int i = 0; i < seqAnno.length; i++)
419 if (seqAnno[i].isValidStruc())
421 final String rnastruc = seqAnno[i].getRNAStruc();
423 // TODO: make rnastrucF a bit more nice
424 menuItem = new JMenuItem();
425 menuItem.setText(MessageManager.formatMessage(
426 "label.2d_rna_sequence_name", new String[]
428 menuItem.addActionListener(new java.awt.event.ActionListener()
431 public void actionPerformed(ActionEvent e)
433 // TODO: VARNA does'nt print gaps in the sequence
435 new AppVarna(seq.getName() + " structure", seq, seq
436 .getSequenceAsString(), rnastruc, seq.getName(),
440 viewStructureMenu.add(menuItem);
447 menuItem = new JMenuItem(
448 MessageManager.getString("action.hide_sequences"));
449 menuItem.addActionListener(new java.awt.event.ActionListener()
452 public void actionPerformed(ActionEvent e)
454 hideSequences(false);
459 if (ap.av.getSelectionGroup() != null
460 && ap.av.getSelectionGroup().getSize() > 1)
462 menuItem = new JMenuItem(MessageManager.formatMessage(
463 "label.represent_group_with", new String[]
465 menuItem.addActionListener(new java.awt.event.ActionListener()
468 public void actionPerformed(ActionEvent e)
473 sequenceMenu.add(menuItem);
476 if (ap.av.hasHiddenRows())
478 final int index = ap.av.getAlignment().findIndex(seq);
480 if (ap.av.adjustForHiddenSeqs(index)
481 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
483 menuItem = new JMenuItem(
484 MessageManager.getString("action.reveal_sequences"));
485 menuItem.addActionListener(new ActionListener()
488 public void actionPerformed(ActionEvent e)
490 ap.av.showSequence(index);
491 if (ap.overviewPanel != null)
493 ap.overviewPanel.updateOverviewImage();
501 // for the case when no sequences are even visible
502 if (ap.av.hasHiddenRows())
505 menuItem = new JMenuItem(
506 MessageManager.getString("action.reveal_all"));
507 menuItem.addActionListener(new ActionListener()
510 public void actionPerformed(ActionEvent e)
512 ap.av.showAllHiddenSeqs();
513 if (ap.overviewPanel != null)
515 ap.overviewPanel.updateOverviewImage();
525 SequenceGroup sg = ap.av.getSelectionGroup();
526 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
527 .getGroups().contains(sg) : false;
529 if (sg != null && sg.getSize() > 0)
531 groupName.setText(MessageManager.formatMessage("label.name_param",
534 groupName.setText(MessageManager
535 .getString("label.edit_name_and_description_current_group"));
537 if (sg.cs instanceof ZappoColourScheme)
539 zappoColour.setSelected(true);
541 else if (sg.cs instanceof TaylorColourScheme)
543 taylorColour.setSelected(true);
545 else if (sg.cs instanceof PIDColourScheme)
547 PIDColour.setSelected(true);
549 else if (sg.cs instanceof Blosum62ColourScheme)
551 BLOSUM62Colour.setSelected(true);
553 else if (sg.cs instanceof UserColourScheme)
555 userDefinedColour.setSelected(true);
557 else if (sg.cs instanceof HydrophobicColourScheme)
559 hydrophobicityColour.setSelected(true);
561 else if (sg.cs instanceof HelixColourScheme)
563 helixColour.setSelected(true);
565 else if (sg.cs instanceof StrandColourScheme)
567 strandColour.setSelected(true);
569 else if (sg.cs instanceof TurnColourScheme)
571 turnColour.setSelected(true);
573 else if (sg.cs instanceof BuriedColourScheme)
575 buriedColour.setSelected(true);
577 else if (sg.cs instanceof ClustalxColourScheme)
579 clustalColour.setSelected(true);
581 else if (sg.cs instanceof PurinePyrimidineColourScheme)
583 purinePyrimidineColour.setSelected(true);
587 * else if (sg.cs instanceof CovariationColourScheme) {
588 * covariationColour.setSelected(true); }
592 noColourmenuItem.setSelected(true);
595 if (sg.cs != null && sg.cs.conservationApplied())
597 conservationMenuItem.setSelected(true);
599 displayNonconserved.setSelected(sg.getShowNonconserved());
600 showText.setSelected(sg.getDisplayText());
601 showColourText.setSelected(sg.getColourText());
602 showBoxes.setSelected(sg.getDisplayBoxes());
603 // add any groupURLs to the groupURL submenu and make it visible
604 if (groupLinks != null && groupLinks.size() > 0)
606 buildGroupURLMenu(sg, groupLinks);
608 // Add a 'show all structures' for the current selection
609 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
610 SequenceI sqass = null;
611 for (SequenceI sq : ap.av.getSequenceSelection())
613 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
614 if (pes != null && pes.size() > 0)
616 reppdb.put(pes.get(0).getId(), pes.get(0));
617 for (PDBEntry pe : pes)
619 pdbe.put(pe.getId(), pe);
629 final PDBEntry[] pe = pdbe.values().toArray(
630 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
631 new PDBEntry[reppdb.size()]);
632 final JMenuItem gpdbview, rpdbview;
633 if (pdbe.size() == 1)
635 structureMenu.add(gpdbview = new JMenuItem(MessageManager
636 .formatMessage("label.view_structure_for", new String[]
637 { sqass.getDisplayId(false) })));
641 structureMenu.add(gpdbview = new JMenuItem(MessageManager
642 .formatMessage("label.view_all_structures", new String[]
643 { new Integer(pdbe.size()).toString() })));
645 gpdbview.setToolTipText(MessageManager
646 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
647 gpdbview.addActionListener(new ActionListener()
651 public void actionPerformed(ActionEvent e)
653 new StructureViewer(ap.getStructureSelectionManager())
654 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
657 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
659 structureMenu.add(rpdbview = new JMenuItem(MessageManager
661 "label.view_all_representative_structures",
663 { new Integer(reppdb.size()).toString() })));
664 rpdbview.setToolTipText(MessageManager
665 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
666 rpdbview.addActionListener(new ActionListener()
670 public void actionPerformed(ActionEvent e)
672 new StructureViewer(ap.getStructureSelectionManager())
673 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
681 groupMenu.setVisible(false);
682 editMenu.setVisible(false);
687 createGroupMenuItem.setVisible(true);
688 unGroupMenuItem.setVisible(false);
689 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
693 createGroupMenuItem.setVisible(false);
694 unGroupMenuItem.setVisible(true);
695 jMenu1.setText(MessageManager.getString("action.edit_group"));
700 sequenceMenu.setVisible(false);
701 structureMenu.setVisible(false);
704 if (links != null && links.size() > 0)
707 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
708 Vector linkset = new Vector();
709 for (int i = 0; i < links.size(); i++)
711 String link = links.elementAt(i).toString();
712 UrlLink urlLink = null;
715 urlLink = new UrlLink(link);
716 } catch (Exception foo)
718 jalview.bin.Cache.log.error("Exception for URLLink '" + link
723 if (!urlLink.isValid())
725 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
728 final String label = urlLink.getLabel();
729 if (seq != null && urlLink.isDynamic())
732 // collect matching db-refs
733 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
734 seq.getDBRef(), new String[]
735 { urlLink.getTarget() });
736 // collect id string too
737 String id = seq.getName();
738 String descr = seq.getDescription();
739 if (descr != null && descr.length() < 1)
746 for (int r = 0; r < dbr.length; r++)
748 if (id != null && dbr[r].getAccessionId().equals(id))
750 // suppress duplicate link creation for the bare sequence ID
751 // string with this link
754 // create Bare ID link for this RUL
755 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
759 for (int u = 0; u < urls.length; u += 2)
761 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
763 linkset.addElement(urls[u] + "|" + urls[u + 1]);
764 addshowLink(linkMenu, label + "|" + urls[u],
773 // create Bare ID link for this RUL
774 String[] urls = urlLink.makeUrls(id, true);
777 for (int u = 0; u < urls.length; u += 2)
779 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
781 linkset.addElement(urls[u] + "|" + urls[u + 1]);
782 addshowLink(linkMenu, label, urls[u + 1]);
787 // Create urls from description but only for URL links which are regex
789 if (descr != null && urlLink.getRegexReplace() != null)
791 // create link for this URL from description where regex matches
792 String[] urls = urlLink.makeUrls(descr, true);
795 for (int u = 0; u < urls.length; u += 2)
797 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
799 linkset.addElement(urls[u] + "|" + urls[u + 1]);
800 addshowLink(linkMenu, label, urls[u + 1]);
808 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
810 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
811 // Add a non-dynamic link
812 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
816 if (sequence != null)
818 sequenceMenu.add(linkMenu);
828 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
829 * "All" is added first, followed by a separator. Then add any annotation
830 * types associated with the current selection. Separate menus are built for
831 * the selected sequence group (if any), and the selected sequence.
833 * Some annotation rows are always rendered together - these can be identified
834 * by a common graphGroup property > -1. Only one of each group will be marked
835 * as visible (to avoid duplication of the display). For such groups we add a
836 * composite type name, e.g.
838 * IUPredWS (Long), IUPredWS (Short)
842 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
843 List<SequenceI> forSequences)
845 showMenu.removeAll();
846 hideMenu.removeAll();
848 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
849 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
850 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
852 showMenu.addSeparator();
853 hideMenu.addSeparator();
855 final AlignmentAnnotation[] annotations = ap.getAlignment()
856 .getAlignmentAnnotation();
859 * Find shown/hidden annotations types, distinguished by source (calcId),
860 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
861 * the insertion order, which is the order of the annotations on the
864 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
865 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
866 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
868 AlignmentAnnotationUtils.asList(annotations),
871 for (String calcId : hiddenTypes.keySet())
873 for (List<String> type : hiddenTypes.get(calcId))
875 addAnnotationTypeToShowHide(showMenu, forSequences,
876 calcId, type, false, true);
879 // grey out 'show annotations' if none are hidden
880 showMenu.setEnabled(!hiddenTypes.isEmpty());
882 for (String calcId : shownTypes.keySet())
884 for (List<String> type : shownTypes.get(calcId))
886 addAnnotationTypeToShowHide(hideMenu, forSequences,
887 calcId, type, false, false);
890 // grey out 'hide annotations' if none are shown
891 hideMenu.setEnabled(!shownTypes.isEmpty());
895 * Returns a list of sequences - either the current selection group (if there
896 * is one), else the specified single sequence.
901 protected List<SequenceI> getSequenceScope(SequenceI seq)
903 List<SequenceI> forSequences = null;
904 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
905 if (selectionGroup != null && selectionGroup.getSize() > 0)
907 forSequences = selectionGroup.getSequences();
911 forSequences = seq == null ? Collections.<SequenceI> emptyList()
912 : Arrays.asList(seq);
918 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
921 * @param showOrHideMenu
923 * @param forSequences
924 * the sequences whose annotations may be shown or hidden
929 * if true this is a special label meaning 'All'
930 * @param actionIsShow
931 * if true, the select menu item action is to show the annotation
934 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
935 final List<SequenceI> forSequences, String calcId,
936 final List<String> types, final boolean allTypes,
937 final boolean actionIsShow)
939 String label = types.toString(); // [a, b, c]
940 label = label.substring(1, label.length() - 1);
941 final JMenuItem item = new JMenuItem(label);
942 item.setToolTipText(calcId);
943 item.addActionListener(new java.awt.event.ActionListener()
946 public void actionPerformed(ActionEvent e)
948 showHideAnnotation_actionPerformed(types, forSequences, allTypes,
952 showOrHideMenu.add(item);
956 * Action on selecting a list of annotation type (or the 'all types' values)
957 * to show or hide for the specified sequences.
960 * @param forSequences
964 protected void showHideAnnotation_actionPerformed(
965 Collection<String> types, List<SequenceI> forSequences,
966 boolean anyType, boolean doShow)
968 for (AlignmentAnnotation aa : ap.getAlignment()
969 .getAlignmentAnnotation())
971 if (anyType || types.contains(aa.label))
973 if ((aa.sequenceRef != null)
974 && forSequences.contains(aa.sequenceRef))
983 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
986 // TODO: usability: thread off the generation of group url content so root
988 // sequence only URLs
989 // ID/regex match URLs
990 groupLinksMenu = new JMenu(
991 MessageManager.getString("action.group_link"));
992 JMenu[] linkMenus = new JMenu[]
993 { null, new JMenu(MessageManager.getString("action.ids")),
994 new JMenu(MessageManager.getString("action.sequences")),
995 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1002 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1003 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1004 Hashtable commonDbrefs = new Hashtable();
1005 for (int sq = 0; sq < seqs.length; sq++)
1008 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1009 .findPosition(sg.getEndRes());
1010 // just collect ids from dataset sequence
1011 // TODO: check if IDs collected from selecton group intersects with the
1012 // current selection, too
1013 SequenceI sqi = seqs[sq];
1014 while (sqi.getDatasetSequence() != null)
1016 sqi = sqi.getDatasetSequence();
1018 DBRefEntry[] dbr = sqi.getDBRef();
1019 if (dbr != null && dbr.length > 0)
1021 for (int d = 0; d < dbr.length; d++)
1023 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1024 Object[] sarray = (Object[]) commonDbrefs.get(src);
1027 sarray = new Object[2];
1028 sarray[0] = new int[]
1030 sarray[1] = new String[seqs.length];
1032 commonDbrefs.put(src, sarray);
1035 if (((String[]) sarray[1])[sq] == null)
1037 if (!dbr[d].hasMap()
1038 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1040 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1041 ((int[]) sarray[0])[0]++;
1047 // now create group links for all distinct ID/sequence sets.
1048 boolean addMenu = false; // indicates if there are any group links to give
1050 for (int i = 0; i < groupLinks.size(); i++)
1052 String link = groupLinks.elementAt(i).toString();
1053 GroupUrlLink urlLink = null;
1056 urlLink = new GroupUrlLink(link);
1057 } catch (Exception foo)
1059 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1064 if (!urlLink.isValid())
1066 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1069 final String label = urlLink.getLabel();
1070 boolean usingNames = false;
1071 // Now see which parts of the group apply for this URL
1072 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1073 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1074 String[] seqstr, ids; // input to makeUrl
1077 int numinput = ((int[]) idset[0])[0];
1078 String[] allids = ((String[]) idset[1]);
1079 seqstr = new String[numinput];
1080 ids = new String[numinput];
1081 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1083 if (allids[sq] != null)
1085 ids[idcount] = allids[sq];
1086 seqstr[idcount++] = idandseqs[1][sq];
1092 // just use the id/seq set
1093 seqstr = idandseqs[1];
1097 // and try and make the groupURL!
1099 Object[] urlset = null;
1102 urlset = urlLink.makeUrlStubs(ids, seqstr,
1103 "FromJalview" + System.currentTimeMillis(), false);
1104 } catch (UrlStringTooLongException e)
1109 int type = urlLink.getGroupURLType() & 3;
1110 // System.out.println(urlLink.getGroupURLType()
1111 // +" "+((String[])urlset[3])[0]);
1112 // first two bits ofurlLink type bitfield are sequenceids and sequences
1113 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1114 addshowLink(linkMenus[type], label
1115 + (((type & 1) == 1) ? ("("
1116 + (usingNames ? "Names" : ltarget) + ")") : ""),
1123 groupLinksMenu = new JMenu(
1124 MessageManager.getString("action.group_link"));
1125 for (int m = 0; m < linkMenus.length; m++)
1127 if (linkMenus[m] != null
1128 && linkMenus[m].getMenuComponentCount() > 0)
1130 groupLinksMenu.add(linkMenus[m]);
1134 groupMenu.add(groupLinksMenu);
1139 * add a show URL menu item to the given linkMenu
1143 * - menu label string
1147 private void addshowLink(JMenu linkMenu, String label, final String url)
1149 JMenuItem item = new JMenuItem(label);
1150 item.setToolTipText(MessageManager.formatMessage(
1151 "label.open_url_param", new String[]
1153 item.addActionListener(new java.awt.event.ActionListener()
1156 public void actionPerformed(ActionEvent e)
1158 new Thread(new Runnable()
1175 * add a late bound groupURL item to the given linkMenu
1179 * - menu label string
1180 * @param urlgenerator
1181 * GroupURLLink used to generate URL
1183 * Object array returned from the makeUrlStubs function.
1185 private void addshowLink(JMenu linkMenu, String label,
1186 final GroupUrlLink urlgenerator, final Object[] urlstub)
1188 JMenuItem item = new JMenuItem(label);
1189 item.setToolTipText(MessageManager.formatMessage(
1190 "label.open_url_seqs_param",
1192 { urlgenerator.getUrl_prefix(),
1193 urlgenerator.getNumberInvolved(urlstub) }));
1194 // TODO: put in info about what is being sent.
1195 item.addActionListener(new java.awt.event.ActionListener()
1198 public void actionPerformed(ActionEvent e)
1200 new Thread(new Runnable()
1208 showLink(urlgenerator.constructFrom(urlstub));
1209 } catch (UrlStringTooLongException e)
1227 private void jbInit() throws Exception
1229 groupMenu.setText(MessageManager.getString("label.group"));
1230 groupMenu.setText(MessageManager.getString("label.selection"));
1231 groupName.setText(MessageManager.getString("label.name"));
1232 groupName.addActionListener(new java.awt.event.ActionListener()
1235 public void actionPerformed(ActionEvent e)
1237 groupName_actionPerformed();
1240 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1241 sequenceName.setText(MessageManager
1242 .getString("label.edit_name_description"));
1243 sequenceName.addActionListener(new java.awt.event.ActionListener()
1246 public void actionPerformed(ActionEvent e)
1248 sequenceName_actionPerformed();
1251 chooseAnnotations.setText(MessageManager
1252 .getString("label.choose_annotations") + "...");
1253 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1256 public void actionPerformed(ActionEvent e)
1258 chooseAnnotations_actionPerformed(e);
1261 sequenceDetails.setText(MessageManager
1262 .getString("label.sequence_details") + "...");
1263 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1266 public void actionPerformed(ActionEvent e)
1268 sequenceDetails_actionPerformed();
1271 sequenceSelDetails.setText(MessageManager
1272 .getString("label.sequence_details") + "...");
1274 .addActionListener(new java.awt.event.ActionListener()
1277 public void actionPerformed(ActionEvent e)
1279 sequenceSelectionDetails_actionPerformed();
1282 PIDColour.setFocusPainted(false);
1284 .setText(MessageManager.getString("action.remove_group"));
1285 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1288 public void actionPerformed(ActionEvent e)
1290 unGroupMenuItem_actionPerformed();
1293 createGroupMenuItem.setText(MessageManager
1294 .getString("action.create_group"));
1296 .addActionListener(new java.awt.event.ActionListener()
1299 public void actionPerformed(ActionEvent e)
1301 createGroupMenuItem_actionPerformed();
1305 outline.setText(MessageManager.getString("action.border_colour"));
1306 outline.addActionListener(new java.awt.event.ActionListener()
1309 public void actionPerformed(ActionEvent e)
1311 outline_actionPerformed();
1315 .setText(MessageManager.getString("label.nucleotide"));
1316 nucleotideMenuItem.addActionListener(new ActionListener()
1319 public void actionPerformed(ActionEvent e)
1321 nucleotideMenuItem_actionPerformed();
1324 colourMenu.setText(MessageManager.getString("label.group_colour"));
1325 showBoxes.setText(MessageManager.getString("action.boxes"));
1326 showBoxes.setState(true);
1327 showBoxes.addActionListener(new ActionListener()
1330 public void actionPerformed(ActionEvent e)
1332 showBoxes_actionPerformed();
1335 showText.setText(MessageManager.getString("action.text"));
1336 showText.setState(true);
1337 showText.addActionListener(new ActionListener()
1340 public void actionPerformed(ActionEvent e)
1342 showText_actionPerformed();
1345 showColourText.setText(MessageManager.getString("label.colour_text"));
1346 showColourText.addActionListener(new ActionListener()
1349 public void actionPerformed(ActionEvent e)
1351 showColourText_actionPerformed();
1354 displayNonconserved.setText(MessageManager
1355 .getString("label.show_non_conversed"));
1356 displayNonconserved.setState(true);
1357 displayNonconserved.addActionListener(new ActionListener()
1360 public void actionPerformed(ActionEvent e)
1362 showNonconserved_actionPerformed();
1365 editMenu.setText(MessageManager.getString("action.edit"));
1366 cut.setText(MessageManager.getString("action.cut"));
1367 cut.addActionListener(new ActionListener()
1370 public void actionPerformed(ActionEvent e)
1372 cut_actionPerformed();
1375 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1376 upperCase.addActionListener(new ActionListener()
1379 public void actionPerformed(ActionEvent e)
1384 copy.setText(MessageManager.getString("action.copy"));
1385 copy.addActionListener(new ActionListener()
1388 public void actionPerformed(ActionEvent e)
1390 copy_actionPerformed();
1393 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1394 lowerCase.addActionListener(new ActionListener()
1397 public void actionPerformed(ActionEvent e)
1402 toggle.setText(MessageManager.getString("label.toggle_case"));
1403 toggle.addActionListener(new ActionListener()
1406 public void actionPerformed(ActionEvent e)
1411 pdbMenu.setText(MessageManager
1412 .getString("label.associate_structure_with_sequence"));
1413 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1414 pdbFromFile.addActionListener(new ActionListener()
1417 public void actionPerformed(ActionEvent e)
1419 pdbFromFile_actionPerformed();
1422 // RNAFold.setText("From RNA Fold with predict2D");
1423 // RNAFold.addActionListener(new ActionListener()
1425 // public void actionPerformed(ActionEvent e)
1428 // RNAFold_actionPerformed();
1429 // } catch (Exception e1) {
1430 // // TODO Auto-generated catch block
1431 // e1.printStackTrace();
1435 // ContraFold.setText("From Contra Fold with predict2D");
1436 // ContraFold.addActionListener(new ActionListener()
1438 // public void actionPerformed(ActionEvent e)
1441 // ContraFold_actionPerformed();
1442 // } catch (Exception e1) {
1443 // // TODO Auto-generated catch block
1444 // e1.printStackTrace();
1448 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1449 enterPDB.addActionListener(new ActionListener()
1452 public void actionPerformed(ActionEvent e)
1454 enterPDB_actionPerformed();
1457 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1458 discoverPDB.addActionListener(new ActionListener()
1461 public void actionPerformed(ActionEvent e)
1463 discoverPDB_actionPerformed();
1466 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1468 seqShowAnnotationsMenu.setText(MessageManager
1469 .getString("label.show_annotations"));
1470 seqHideAnnotationsMenu.setText(MessageManager
1471 .getString("label.hide_annotations"));
1472 groupShowAnnotationsMenu.setText(MessageManager
1473 .getString("label.show_annotations"));
1474 groupHideAnnotationsMenu.setText(MessageManager
1475 .getString("label.hide_annotations"));
1476 sequenceFeature.setText(MessageManager
1477 .getString("label.create_sequence_feature"));
1478 sequenceFeature.addActionListener(new ActionListener()
1481 public void actionPerformed(ActionEvent e)
1483 sequenceFeature_actionPerformed();
1486 textColour.setText(MessageManager.getString("label.text_colour"));
1487 textColour.addActionListener(new ActionListener()
1490 public void actionPerformed(ActionEvent e)
1492 textColour_actionPerformed();
1495 jMenu1.setText(MessageManager.getString("label.group"));
1496 structureMenu.setText(MessageManager.getString("label.structure"));
1497 viewStructureMenu.setText(MessageManager
1498 .getString("label.view_structure"));
1499 // colStructureMenu.setText("Colour By Structure");
1500 editSequence.setText(MessageManager.getString("label.edit_sequence")
1502 editSequence.addActionListener(new ActionListener()
1505 public void actionPerformed(ActionEvent actionEvent)
1507 editSequence_actionPerformed(actionEvent);
1512 * annotationMenuItem.setText("By Annotation");
1513 * annotationMenuItem.addActionListener(new ActionListener() { public void
1514 * actionPerformed(ActionEvent actionEvent) {
1515 * annotationMenuItem_actionPerformed(actionEvent); } });
1517 groupMenu.add(sequenceSelDetails);
1520 this.add(structureMenu);
1521 // annotations configuration panel suppressed for now
1522 // groupMenu.add(chooseAnnotations);
1525 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1526 * (if a selection group is in force).
1528 sequenceMenu.add(seqShowAnnotationsMenu);
1529 sequenceMenu.add(seqHideAnnotationsMenu);
1530 sequenceMenu.add(seqAddReferenceAnnotations);
1531 groupMenu.add(groupShowAnnotationsMenu);
1532 groupMenu.add(groupHideAnnotationsMenu);
1533 groupMenu.add(groupAddReferenceAnnotations);
1534 groupMenu.add(editMenu);
1535 groupMenu.add(outputMenu);
1536 groupMenu.add(sequenceFeature);
1537 groupMenu.add(createGroupMenuItem);
1538 groupMenu.add(unGroupMenuItem);
1539 groupMenu.add(jMenu1);
1540 sequenceMenu.add(sequenceName);
1541 sequenceMenu.add(sequenceDetails);
1542 colourMenu.add(textColour);
1543 colourMenu.add(noColourmenuItem);
1544 colourMenu.add(clustalColour);
1545 colourMenu.add(BLOSUM62Colour);
1546 colourMenu.add(PIDColour);
1547 colourMenu.add(zappoColour);
1548 colourMenu.add(taylorColour);
1549 colourMenu.add(hydrophobicityColour);
1550 colourMenu.add(helixColour);
1551 colourMenu.add(strandColour);
1552 colourMenu.add(turnColour);
1553 colourMenu.add(buriedColour);
1554 colourMenu.add(nucleotideMenuItem);
1555 if (ap.getAlignment().isNucleotide())
1557 // JBPNote - commented since the colourscheme isn't functional
1558 // colourMenu.add(RNAInteractionColour);
1559 colourMenu.add(purinePyrimidineColour);
1561 // colourMenu.add(covariationColour);
1562 colourMenu.add(userDefinedColour);
1564 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1566 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1567 .getUserColourSchemes().keys();
1569 while (userColours.hasMoreElements())
1571 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1572 item.addActionListener(new ActionListener()
1575 public void actionPerformed(ActionEvent evt)
1577 userDefinedColour_actionPerformed(evt);
1580 colourMenu.add(item);
1584 colourMenu.addSeparator();
1585 colourMenu.add(abovePIDColour);
1586 colourMenu.add(conservationMenuItem);
1587 // colourMenu.add(annotationMenuItem);
1590 editMenu.add(editSequence);
1591 editMenu.add(upperCase);
1592 editMenu.add(lowerCase);
1593 editMenu.add(toggle);
1594 pdbMenu.add(pdbFromFile);
1595 // JBPNote: These shouldn't be added here - should appear in a generic
1596 // 'apply web service to this sequence menu'
1597 // pdbMenu.add(RNAFold);
1598 // pdbMenu.add(ContraFold);
1599 pdbMenu.add(enterPDB);
1600 pdbMenu.add(discoverPDB);
1601 jMenu1.add(groupName);
1602 jMenu1.add(colourMenu);
1603 jMenu1.add(showBoxes);
1604 jMenu1.add(showText);
1605 jMenu1.add(showColourText);
1606 jMenu1.add(outline);
1607 jMenu1.add(displayNonconserved);
1608 structureMenu.add(pdbMenu);
1609 structureMenu.add(viewStructureMenu);
1610 // structureMenu.add(colStructureMenu);
1611 noColourmenuItem.setText(MessageManager.getString("label.none"));
1612 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1615 public void actionPerformed(ActionEvent e)
1617 noColourmenuItem_actionPerformed();
1621 clustalColour.setText(MessageManager
1622 .getString("label.clustalx_colours"));
1623 clustalColour.addActionListener(new java.awt.event.ActionListener()
1626 public void actionPerformed(ActionEvent e)
1628 clustalColour_actionPerformed();
1631 zappoColour.setText(MessageManager.getString("label.zappo"));
1632 zappoColour.addActionListener(new java.awt.event.ActionListener()
1635 public void actionPerformed(ActionEvent e)
1637 zappoColour_actionPerformed();
1640 taylorColour.setText(MessageManager.getString("label.taylor"));
1641 taylorColour.addActionListener(new java.awt.event.ActionListener()
1644 public void actionPerformed(ActionEvent e)
1646 taylorColour_actionPerformed();
1649 hydrophobicityColour.setText(MessageManager
1650 .getString("label.hydrophobicity"));
1651 hydrophobicityColour
1652 .addActionListener(new java.awt.event.ActionListener()
1655 public void actionPerformed(ActionEvent e)
1657 hydrophobicityColour_actionPerformed();
1660 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1661 helixColour.addActionListener(new java.awt.event.ActionListener()
1664 public void actionPerformed(ActionEvent e)
1666 helixColour_actionPerformed();
1669 strandColour.setText(MessageManager
1670 .getString("label.strand_propensity"));
1671 strandColour.addActionListener(new java.awt.event.ActionListener()
1674 public void actionPerformed(ActionEvent e)
1676 strandColour_actionPerformed();
1679 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1680 turnColour.addActionListener(new java.awt.event.ActionListener()
1683 public void actionPerformed(ActionEvent e)
1685 turnColour_actionPerformed();
1688 buriedColour.setText(MessageManager.getString("label.buried_index"));
1689 buriedColour.addActionListener(new java.awt.event.ActionListener()
1692 public void actionPerformed(ActionEvent e)
1694 buriedColour_actionPerformed();
1697 abovePIDColour.setText(MessageManager
1698 .getString("label.above_identity_percentage"));
1699 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1702 public void actionPerformed(ActionEvent e)
1704 abovePIDColour_actionPerformed();
1707 userDefinedColour.setText(MessageManager
1708 .getString("action.user_defined"));
1709 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1712 public void actionPerformed(ActionEvent e)
1714 userDefinedColour_actionPerformed(e);
1718 .setText(MessageManager.getString("label.percentage_identity"));
1719 PIDColour.addActionListener(new java.awt.event.ActionListener()
1722 public void actionPerformed(ActionEvent e)
1724 PIDColour_actionPerformed();
1727 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1728 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1731 public void actionPerformed(ActionEvent e)
1733 BLOSUM62Colour_actionPerformed();
1736 purinePyrimidineColour.setText(MessageManager
1737 .getString("label.purine_pyrimidine"));
1738 purinePyrimidineColour
1739 .addActionListener(new java.awt.event.ActionListener()
1742 public void actionPerformed(ActionEvent e)
1744 purinePyrimidineColour_actionPerformed();
1749 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1750 * public void actionPerformed(ActionEvent e) {
1751 * covariationColour_actionPerformed(); } });
1754 conservationMenuItem.setText(MessageManager
1755 .getString("label.conservation"));
1756 conservationMenuItem
1757 .addActionListener(new java.awt.event.ActionListener()
1760 public void actionPerformed(ActionEvent e)
1762 conservationMenuItem_actionPerformed();
1768 * Check for any annotations on the underlying dataset sequences (for the
1769 * current selection group) which are not 'on the alignment'.If any are found,
1770 * enable the option to add them to the alignment. The criteria for 'on the
1771 * alignment' is finding an alignment annotation on the alignment, matched on
1772 * calcId, label and sequenceRef.
1774 * A tooltip is also constructed that displays the source (calcId) and type
1775 * (label) of the annotations that can be added.
1778 * @param forSequences
1780 protected void configureReferenceAnnotationsMenu(
1781 JMenuItem menuItem, List<SequenceI> forSequences)
1783 menuItem.setText(MessageManager
1784 .getString("label.add_reference_annotations"));
1785 menuItem.setEnabled(false);
1786 if (forSequences == null)
1792 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1793 * Using TreeMap means calcIds are shown in alphabetical order.
1795 Map<String, String> tipEntries = new TreeMap<String, String>();
1796 StringBuilder tooltip = new StringBuilder(64);
1797 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1800 * For each sequence selected in the alignment, make a list of any
1801 * annotations on the underlying dataset sequence which are not already on
1804 * Build a map of { alignmentSequence, <List of annotations to add> }
1806 AlignmentI al = this.ap.av.getAlignment();
1807 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1808 for (SequenceI seq : forSequences)
1810 SequenceI dataset = seq.getDatasetSequence();
1811 if (dataset == null)
1815 AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
1816 if (datasetAnnotations == null)
1820 final List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1821 for (AlignmentAnnotation dsann : datasetAnnotations)
1824 * Find matching annotations on the alignment.
1826 final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al
1827 .findAnnotations(seq, dsann.getCalcId(),
1829 if (!matchedAlignmentAnnotations.iterator().hasNext())
1832 tipEntries.put(dsann.getCalcId(), dsann.label);
1836 * Save any addable annotations for this sequence
1838 if (!result.isEmpty())
1840 candidates.put(seq, result);
1843 if (!candidates.isEmpty())
1846 * Found annotations that could be added. Enable the menu item, and
1847 * configure its tooltip and action.
1849 menuItem.setEnabled(true);
1850 for (String calcId : tipEntries.keySet())
1852 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1854 String tooltipText = JvSwingUtils.wrapTooltip(true,
1855 tooltip.toString());
1856 menuItem.setToolTipText(tooltipText);
1858 menuItem.addActionListener(new ActionListener()
1861 public void actionPerformed(ActionEvent e)
1863 addReferenceAnnotations_actionPerformed(candidates);
1870 * Add annotations to the sequences and to the alignment.
1873 * a map whose keys are sequences on the alignment, and values a list
1874 * of annotations to add to each sequence
1876 protected void addReferenceAnnotations_actionPerformed(
1877 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1880 * Add annotations at the top of the annotation, in the same order as their
1881 * related sequences.
1883 for (SequenceI seq : candidates.keySet())
1885 for (AlignmentAnnotation ann : candidates.get(seq))
1887 AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
1889 int endRes = ann.annotations.length;
1890 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1891 if (selectionGroup != null)
1893 startRes = selectionGroup.getStartRes();
1894 endRes = selectionGroup.getEndRes();
1896 copyAnn.restrict(startRes, endRes);
1899 * Add to the sequence (sets copyAnn.datasetSequence), unless the
1900 * original annotation is already on the sequence.
1902 if (!seq.hasAnnotation(ann))
1904 seq.addAlignmentAnnotation(copyAnn);
1907 copyAnn.adjustForAlignment();
1908 // add to the alignment and set visible
1909 this.ap.getAlignment().addAnnotation(copyAnn);
1910 copyAnn.visible = true;
1916 protected void sequenceSelectionDetails_actionPerformed()
1918 createSequenceDetailsReport(ap.av.getSequenceSelection());
1921 protected void sequenceDetails_actionPerformed()
1923 createSequenceDetailsReport(new SequenceI[]
1927 public void createSequenceDetailsReport(SequenceI[] sequences)
1929 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1930 StringBuffer contents = new StringBuffer();
1931 for (SequenceI seq : sequences)
1933 contents.append("<p><h2>"
1936 "label.create_sequence_details_report_annotation_for",
1938 { seq.getDisplayId(true) }) + "</h2></p><p>");
1939 new SequenceAnnotationReport(null)
1940 .createSequenceAnnotationReport(
1946 (ap.getSeqPanel().seqCanvas.fr != null) ? ap.getSeqPanel().seqCanvas.fr.minmax
1948 contents.append("</p>");
1950 cap.setText("<html>" + contents.toString() + "</html>");
1952 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
1953 "label.sequece_details_for",
1954 (sequences.length == 1 ? new String[]
1955 { sequences[0].getDisplayId(true) } : new String[]
1956 { MessageManager.getString("label.selection") })), 500, 400);
1960 protected void showNonconserved_actionPerformed()
1962 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1967 * call to refresh view after settings change
1971 ap.updateAnnotation();
1972 ap.paintAlignment(true);
1974 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1983 protected void clustalColour_actionPerformed()
1985 SequenceGroup sg = getGroup();
1986 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1996 protected void zappoColour_actionPerformed()
1998 getGroup().cs = new ZappoColourScheme();
2008 protected void taylorColour_actionPerformed()
2010 getGroup().cs = new TaylorColourScheme();
2020 protected void hydrophobicityColour_actionPerformed()
2022 getGroup().cs = new HydrophobicColourScheme();
2032 protected void helixColour_actionPerformed()
2034 getGroup().cs = new HelixColourScheme();
2044 protected void strandColour_actionPerformed()
2046 getGroup().cs = new StrandColourScheme();
2056 protected void turnColour_actionPerformed()
2058 getGroup().cs = new TurnColourScheme();
2068 protected void buriedColour_actionPerformed()
2070 getGroup().cs = new BuriedColourScheme();
2080 public void nucleotideMenuItem_actionPerformed()
2082 getGroup().cs = new NucleotideColourScheme();
2086 protected void purinePyrimidineColour_actionPerformed()
2088 getGroup().cs = new PurinePyrimidineColourScheme();
2093 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2094 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2102 protected void abovePIDColour_actionPerformed()
2104 SequenceGroup sg = getGroup();
2110 if (abovePIDColour.isSelected())
2112 sg.cs.setConsensus(AAFrequency.calculate(
2113 sg.getSequences(ap.av.getHiddenRepSequences()),
2114 sg.getStartRes(), sg.getEndRes() + 1));
2116 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2119 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
2121 SliderPanel.showPIDSlider();
2124 // remove PIDColouring
2126 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
2138 protected void userDefinedColour_actionPerformed(ActionEvent e)
2140 SequenceGroup sg = getGroup();
2142 if (e.getSource().equals(userDefinedColour))
2144 new UserDefinedColours(ap, sg);
2148 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2149 .getUserColourSchemes().get(e.getActionCommand());
2157 * Open a panel where the user can choose which types of sequence annotation
2162 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2164 // todo correct way to guard against opening a duplicate panel?
2165 new AnnotationChooser(ap);
2174 protected void PIDColour_actionPerformed()
2176 SequenceGroup sg = getGroup();
2177 sg.cs = new PIDColourScheme();
2178 sg.cs.setConsensus(AAFrequency.calculate(
2179 sg.getSequences(ap.av.getHiddenRepSequences()),
2180 sg.getStartRes(), sg.getEndRes() + 1));
2190 protected void BLOSUM62Colour_actionPerformed()
2192 SequenceGroup sg = getGroup();
2194 sg.cs = new Blosum62ColourScheme();
2196 sg.cs.setConsensus(AAFrequency.calculate(
2197 sg.getSequences(ap.av.getHiddenRepSequences()),
2198 sg.getStartRes(), sg.getEndRes() + 1));
2209 protected void noColourmenuItem_actionPerformed()
2211 getGroup().cs = null;
2221 protected void conservationMenuItem_actionPerformed()
2223 SequenceGroup sg = getGroup();
2229 if (conservationMenuItem.isSelected())
2231 // JBPNote: Conservation name shouldn't be i18n translated
2232 Conservation c = new Conservation("Group",
2233 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2234 .getHiddenRepSequences()), sg.getStartRes(),
2235 sg.getEndRes() + 1);
2238 c.verdict(false, ap.av.getConsPercGaps());
2240 sg.cs.setConservation(c);
2242 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2243 SliderPanel.showConservationSlider();
2246 // remove ConservationColouring
2248 sg.cs.setConservation(null);
2254 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2256 SequenceGroup sg = getGroup();
2262 AnnotationColourGradient acg = new AnnotationColourGradient(
2263 sequence.getAnnotation()[0], null,
2264 AnnotationColourGradient.NO_THRESHOLD);
2266 acg.setPredefinedColours(true);
2278 protected void groupName_actionPerformed()
2281 SequenceGroup sg = getGroup();
2282 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2283 sg.getDescription(), " "
2284 + MessageManager.getString("label.group_name") + " ",
2285 MessageManager.getString("label.group_description") + " ",
2286 MessageManager.getString("label.edit_group_name_description"),
2294 sg.setName(dialog.getName());
2295 sg.setDescription(dialog.getDescription());
2300 * Get selection group - adding it to the alignment if necessary.
2302 * @return sequence group to operate on
2304 SequenceGroup getGroup()
2306 SequenceGroup sg = ap.av.getSelectionGroup();
2307 // this method won't add a new group if it already exists
2310 ap.av.getAlignment().addGroup(sg);
2322 void sequenceName_actionPerformed()
2324 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2325 sequence.getDescription(),
2326 " " + MessageManager.getString("label.sequence_name")
2328 MessageManager.getString("label.sequence_description") + " ",
2330 .getString("label.edit_sequence_name_description"),
2338 if (dialog.getName() != null)
2340 if (dialog.getName().indexOf(" ") > -1)
2346 .getString("label.spaces_converted_to_backslashes"),
2348 .getString("label.no_spaces_allowed_sequence_name"),
2349 JOptionPane.WARNING_MESSAGE);
2352 sequence.setName(dialog.getName().replace(' ', '_'));
2353 ap.paintAlignment(false);
2356 sequence.setDescription(dialog.getDescription());
2358 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2369 void unGroupMenuItem_actionPerformed()
2371 SequenceGroup sg = ap.av.getSelectionGroup();
2372 ap.av.getAlignment().deleteGroup(sg);
2373 ap.av.setSelectionGroup(null);
2377 void createGroupMenuItem_actionPerformed()
2379 getGroup(); // implicitly creates group - note - should apply defaults / use
2380 // standard alignment window logic for this
2390 protected void outline_actionPerformed()
2392 SequenceGroup sg = getGroup();
2393 Color col = JColorChooser.showDialog(this,
2394 MessageManager.getString("label.select_outline_colour"),
2399 sg.setOutlineColour(col);
2411 public void showBoxes_actionPerformed()
2413 getGroup().setDisplayBoxes(showBoxes.isSelected());
2423 public void showText_actionPerformed()
2425 getGroup().setDisplayText(showText.isSelected());
2435 public void showColourText_actionPerformed()
2437 getGroup().setColourText(showColourText.isSelected());
2441 public void showLink(String url)
2445 jalview.util.BrowserLauncher.openURL(url);
2446 } catch (Exception ex)
2448 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2449 MessageManager.getString("label.web_browser_not_found_unix"),
2450 MessageManager.getString("label.web_browser_not_found"),
2451 JOptionPane.WARNING_MESSAGE);
2453 ex.printStackTrace();
2457 void hideSequences(boolean representGroup)
2459 SequenceGroup sg = ap.av.getSelectionGroup();
2460 if (sg == null || sg.getSize() < 1)
2462 ap.av.hideSequence(new SequenceI[]
2467 ap.av.setSelectionGroup(null);
2471 ap.av.hideRepSequences(sequence, sg);
2476 int gsize = sg.getSize();
2479 hseqs = new SequenceI[gsize];
2482 for (int i = 0; i < gsize; i++)
2484 hseqs[index++] = sg.getSequenceAt(i);
2487 ap.av.hideSequence(hseqs);
2488 // refresh(); TODO: ? needed ?
2489 ap.av.sendSelection();
2492 public void copy_actionPerformed()
2494 ap.alignFrame.copy_actionPerformed(null);
2497 public void cut_actionPerformed()
2499 ap.alignFrame.cut_actionPerformed(null);
2502 void changeCase(ActionEvent e)
2504 Object source = e.getSource();
2505 SequenceGroup sg = ap.av.getSelectionGroup();
2509 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
2510 sg.getEndRes() + 1);
2515 if (source == toggle)
2517 description = MessageManager.getString("label.toggle_case");
2518 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2520 else if (source == upperCase)
2522 description = MessageManager.getString("label.to_upper_case");
2523 caseChange = ChangeCaseCommand.TO_UPPER;
2527 description = MessageManager.getString("label.to_lower_case");
2528 caseChange = ChangeCaseCommand.TO_LOWER;
2531 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2532 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2533 startEnd, caseChange);
2535 ap.alignFrame.addHistoryItem(caseCommand);
2537 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2543 public void outputText_actionPerformed(ActionEvent e)
2545 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2546 cap.setForInput(null);
2547 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2548 "label.alignment_output_command", new String[]
2549 { e.getActionCommand() }), 600, 500);
2551 String[] omitHidden = null;
2553 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2554 // or we simply trust the user wants
2555 // wysiwig behaviour
2557 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2561 public void pdbFromFile_actionPerformed()
2563 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2564 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2565 chooser.setFileView(new jalview.io.JalviewFileView());
2566 chooser.setDialogTitle(MessageManager.formatMessage(
2567 "label.select_pdb_file_for", new String[]
2568 { sequence.getDisplayId(false) }));
2569 chooser.setToolTipText(MessageManager.formatMessage(
2570 "label.load_pdb_file_associate_with_sequence", new String[]
2571 { sequence.getDisplayId(false) }));
2573 int value = chooser.showOpenDialog(null);
2575 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2577 String choice = chooser.getSelectedFile().getPath();
2578 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2579 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2580 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2586 // JBNote: commented out - these won't be instantiated here...!
2587 // public void RNAFold_actionPerformed() throws Exception
2589 // Predict2D P2D = new Predict2D();
2590 // P2D.getStructure2DFromRNAFold("toto");
2593 // public void ContraFold_actionPerformed() throws Exception
2595 // Predict2D P2D = new Predict2D();
2596 // P2D.getStructure2DFromContraFold("toto");
2598 public void enterPDB_actionPerformed()
2600 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2601 MessageManager.getString("label.enter_pdb_id"),
2602 MessageManager.getString("label.enter_pdb_id"),
2603 JOptionPane.QUESTION_MESSAGE);
2605 if (id != null && id.length() > 0)
2607 PDBEntry entry = new PDBEntry();
2608 entry.setId(id.toUpperCase());
2609 sequence.getDatasetSequence().addPDBId(entry);
2613 public void discoverPDB_actionPerformed()
2616 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2618 : ap.av.getSequenceSelection());
2619 Thread discpdb = new Thread(new Runnable()
2625 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2626 .fetchDBRefs(false);
2633 public void sequenceFeature_actionPerformed()
2635 SequenceGroup sg = ap.av.getSelectionGroup();
2641 int rsize = 0, gSize = sg.getSize();
2642 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2643 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2645 for (int i = 0; i < gSize; i++)
2647 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2648 int end = sg.findEndRes(sg.getSequenceAt(i));
2651 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2652 features[rsize] = new SequenceFeature(null, null, null, start, end,
2657 rseqs = new SequenceI[rsize];
2658 tfeatures = new SequenceFeature[rsize];
2659 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2660 System.arraycopy(features, 0, tfeatures, 0, rsize);
2661 features = tfeatures;
2663 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2664 features, true, ap))
2666 ap.alignFrame.setShowSeqFeatures(true);
2667 ap.highlightSearchResults(null);
2671 public void textColour_actionPerformed()
2673 SequenceGroup sg = getGroup();
2676 new TextColourChooser().chooseColour(ap, sg);
2680 public void colourByStructure(String pdbid)
2682 Annotation[] anots = ap.av.getStructureSelectionManager()
2683 .colourSequenceFromStructure(sequence, pdbid);
2685 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2686 "Coloured by " + pdbid, anots);
2688 ap.av.getAlignment().addAnnotation(an);
2689 an.createSequenceMapping(sequence, 0, true);
2690 // an.adjustForAlignment();
2691 ap.av.getAlignment().setAnnotationIndex(an, 0);
2693 ap.adjustAnnotationHeight();
2695 sequence.addAlignmentAnnotation(an);
2699 public void editSequence_actionPerformed(ActionEvent actionEvent)
2701 SequenceGroup sg = ap.av.getSelectionGroup();
2705 if (sequence == null)
2707 sequence = sg.getSequenceAt(0);
2710 EditNameDialog dialog = new EditNameDialog(
2711 sequence.getSequenceAsString(sg.getStartRes(),
2712 sg.getEndRes() + 1), null,
2713 MessageManager.getString("label.edit_sequence"), null,
2714 MessageManager.getString("label.edit_sequence"),
2719 EditCommand editCommand = new EditCommand(
2720 MessageManager.getString("label.edit_sequences"),
2721 Action.REPLACE, dialog.getName().replace(' ',
2722 ap.av.getGapCharacter()),
2723 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2724 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2726 ap.alignFrame.addHistoryItem(editCommand);
2728 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()