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 makeReferenceSeq = new JMenuItem();
146 JMenuItem chooseAnnotations = new JMenuItem();
150 JMenuItem createGroupMenuItem = new JMenuItem();
152 JMenuItem unGroupMenuItem = new JMenuItem();
154 JMenuItem outline = new JMenuItem();
156 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
158 JMenu colourMenu = new JMenu();
160 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
164 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
166 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
168 JMenu editMenu = new JMenu();
170 JMenuItem cut = new JMenuItem();
172 JMenuItem copy = new JMenuItem();
174 JMenuItem upperCase = new JMenuItem();
176 JMenuItem lowerCase = new JMenuItem();
178 JMenuItem toggle = new JMenuItem();
180 JMenu pdbMenu = new JMenu();
182 JMenuItem pdbFromFile = new JMenuItem();
184 // JBPNote: Commented these out - Should add these services via the web
185 // services menu system.
186 // JMenuItem ContraFold = new JMenuItem();
188 // JMenuItem RNAFold = new JMenuItem();
190 JMenuItem enterPDB = new JMenuItem();
192 JMenuItem discoverPDB = new JMenuItem();
194 JMenu outputMenu = new JMenu();
196 JMenu seqShowAnnotationsMenu = new JMenu();
198 JMenu seqHideAnnotationsMenu = new JMenu();
200 JMenuItem seqAddReferenceAnnotations = new JMenuItem();
202 JMenu groupShowAnnotationsMenu = new JMenu();
204 JMenu groupHideAnnotationsMenu = new JMenu();
206 JMenuItem groupAddReferenceAnnotations = new JMenuItem();
208 JMenuItem sequenceFeature = new JMenuItem();
210 JMenuItem textColour = new JMenuItem();
212 JMenu jMenu1 = new JMenu();
214 JMenu structureMenu = new JMenu();
216 JMenu viewStructureMenu = new JMenu();
218 // JMenu colStructureMenu = new JMenu();
219 JMenuItem editSequence = new JMenuItem();
221 // JMenuItem annotationMenuItem = new JMenuItem();
223 JMenu groupLinksMenu;
226 * Creates a new PopupMenu object.
233 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
235 this(ap, seq, links, null);
245 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
246 Vector links, Vector groupLinks)
248 // /////////////////////////////////////////////////////////
249 // If this is activated from the sequence panel, the user may want to
250 // edit or annotate a particular residue. Therefore display the residue menu
252 // If from the IDPanel, we must display the sequence menu
253 // ////////////////////////////////////////////////////////
257 ButtonGroup colours = new ButtonGroup();
258 colours.add(noColourmenuItem);
259 colours.add(clustalColour);
260 colours.add(zappoColour);
261 colours.add(taylorColour);
262 colours.add(hydrophobicityColour);
263 colours.add(helixColour);
264 colours.add(strandColour);
265 colours.add(turnColour);
266 colours.add(buriedColour);
267 colours.add(abovePIDColour);
268 colours.add(userDefinedColour);
269 colours.add(PIDColour);
270 colours.add(BLOSUM62Colour);
271 colours.add(purinePyrimidineColour);
272 colours.add(RNAInteractionColour);
273 // colours.add(covariationColour);
275 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
277 JMenuItem item = new JMenuItem(
278 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
280 item.addActionListener(new java.awt.event.ActionListener()
283 public void actionPerformed(ActionEvent e)
285 outputText_actionPerformed(e);
289 outputMenu.add(item);
293 * Build menus for annotation types that may be shown or hidden, and for
294 * 'reference annotations' that may be added to the alignment. First for the
295 * currently selected sequence (if there is one):
297 final List<SequenceI> selectedSequence = (seq == null ? Collections
298 .<SequenceI> emptyList() : Arrays.asList(seq));
299 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
300 seqHideAnnotationsMenu, selectedSequence);
301 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
305 * And repeat for the current selection group (if there is one):
307 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
308 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
310 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
311 groupHideAnnotationsMenu, selectedGroup);
312 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
318 } catch (Exception e)
326 sequenceMenu.setText(sequence.getName());
327 if (seq == ap.av.getAlignment().getSeqrep())
329 makeReferenceSeq.setText("Unmark representative");
331 makeReferenceSeq.setText("Mark as representative");
334 if (seq.getDatasetSequence().getPDBId() != null
335 && seq.getDatasetSequence().getPDBId().size() > 0)
337 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
340 while (e.hasMoreElements())
342 final PDBEntry pdb = (PDBEntry) e.nextElement();
344 menuItem = new JMenuItem();
345 menuItem.setText(pdb.getId());
346 menuItem.addActionListener(new ActionListener()
349 public void actionPerformed(ActionEvent e)
351 // TODO re JAL-860: optionally open dialog or provide a menu entry
352 // allowing user to open just one structure per sequence
353 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
354 // { pdb })[0], null, ap);
355 new StructureViewer(ap.getStructureSelectionManager())
357 ap.av.collateForPDB(new PDBEntry[]
358 { pdb })[0], null, ap);
361 viewStructureMenu.add(menuItem);
364 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
365 * menuItem.addActionListener(new java.awt.event.ActionListener() {
366 * public void actionPerformed(ActionEvent e) {
367 * colourByStructure(pdb.getId()); } });
368 * colStructureMenu.add(menuItem);
374 if (ap.av.getAlignment().isNucleotide() == false)
376 structureMenu.remove(viewStructureMenu);
378 // structureMenu.remove(colStructureMenu);
380 if (ap.av.getAlignment().isNucleotide() == true)
382 AlignmentAnnotation[] aa = ap.av.getAlignment()
383 .getAlignmentAnnotation();
384 for (int i = 0; aa != null && i < aa.length; i++)
386 if (aa[i].isValidStruc() && aa[i].sequenceRef == null)
388 final String rnastruc = aa[i].getRNAStruc();
389 final String structureLine = aa[i].label + " (alignment)";
390 menuItem = new JMenuItem();
391 menuItem.setText(MessageManager.formatMessage(
392 "label.2d_rna_structure_line", new String[]
394 menuItem.addActionListener(new java.awt.event.ActionListener()
397 public void actionPerformed(ActionEvent e)
399 // // System.out.println("1:"+structureLine);
400 // System.out.println("1:sname" + seq.getName());
401 // System.out.println("2:seq" + seq);
403 // // System.out.println("3:"+seq.getSequenceAsString());
404 // System.out.println("3:strucseq" + rnastruc);
405 // // System.out.println("4:struc"+seq.getRNA());
406 // System.out.println("5:name" + seq.getName());
407 // System.out.println("6:ap" + ap);
408 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
409 rnastruc, seq.getName(), ap);
410 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
411 // seq.getName(), ap);
412 System.out.println("end");
415 viewStructureMenu.add(menuItem);
419 // SequenceFeatures[] test = seq.getSequenceFeatures();
421 if (seq.getAnnotation() != null)
423 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
424 for (int i = 0; i < seqAnno.length; i++)
426 if (seqAnno[i].isValidStruc())
428 final String rnastruc = seqAnno[i].getRNAStruc();
430 // TODO: make rnastrucF a bit more nice
431 menuItem = new JMenuItem();
432 menuItem.setText(MessageManager.formatMessage(
433 "label.2d_rna_sequence_name", new String[]
435 menuItem.addActionListener(new java.awt.event.ActionListener()
438 public void actionPerformed(ActionEvent e)
440 // TODO: VARNA does'nt print gaps in the sequence
442 new AppVarna(seq.getName() + " structure", seq, seq
443 .getSequenceAsString(), rnastruc, seq.getName(),
447 viewStructureMenu.add(menuItem);
453 menuItem = new JMenuItem(
454 MessageManager.getString("action.hide_sequences"));
455 menuItem.addActionListener(new java.awt.event.ActionListener()
458 public void actionPerformed(ActionEvent e)
460 hideSequences(false);
465 if (ap.av.getSelectionGroup() != null
466 && ap.av.getSelectionGroup().getSize() > 1)
468 menuItem = new JMenuItem(MessageManager.formatMessage(
469 "label.represent_group_with", new String[]
471 menuItem.addActionListener(new java.awt.event.ActionListener()
474 public void actionPerformed(ActionEvent e)
479 sequenceMenu.add(menuItem);
482 if (ap.av.hasHiddenRows())
484 final int index = ap.av.getAlignment().findIndex(seq);
486 if (ap.av.adjustForHiddenSeqs(index)
487 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
489 menuItem = new JMenuItem(
490 MessageManager.getString("action.reveal_sequences"));
491 menuItem.addActionListener(new ActionListener()
494 public void actionPerformed(ActionEvent e)
496 ap.av.showSequence(index);
497 if (ap.overviewPanel != null)
499 ap.overviewPanel.updateOverviewImage();
507 // for the case when no sequences are even visible
508 if (ap.av.hasHiddenRows())
511 menuItem = new JMenuItem(
512 MessageManager.getString("action.reveal_all"));
513 menuItem.addActionListener(new ActionListener()
516 public void actionPerformed(ActionEvent e)
518 ap.av.showAllHiddenSeqs();
519 if (ap.overviewPanel != null)
521 ap.overviewPanel.updateOverviewImage();
531 SequenceGroup sg = ap.av.getSelectionGroup();
532 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
533 .getGroups().contains(sg) : false;
535 if (sg != null && sg.getSize() > 0)
537 groupName.setText(MessageManager.formatMessage("label.name_param",
540 groupName.setText(MessageManager
541 .getString("label.edit_name_and_description_current_group"));
543 if (sg.cs instanceof ZappoColourScheme)
545 zappoColour.setSelected(true);
547 else if (sg.cs instanceof TaylorColourScheme)
549 taylorColour.setSelected(true);
551 else if (sg.cs instanceof PIDColourScheme)
553 PIDColour.setSelected(true);
555 else if (sg.cs instanceof Blosum62ColourScheme)
557 BLOSUM62Colour.setSelected(true);
559 else if (sg.cs instanceof UserColourScheme)
561 userDefinedColour.setSelected(true);
563 else if (sg.cs instanceof HydrophobicColourScheme)
565 hydrophobicityColour.setSelected(true);
567 else if (sg.cs instanceof HelixColourScheme)
569 helixColour.setSelected(true);
571 else if (sg.cs instanceof StrandColourScheme)
573 strandColour.setSelected(true);
575 else if (sg.cs instanceof TurnColourScheme)
577 turnColour.setSelected(true);
579 else if (sg.cs instanceof BuriedColourScheme)
581 buriedColour.setSelected(true);
583 else if (sg.cs instanceof ClustalxColourScheme)
585 clustalColour.setSelected(true);
587 else if (sg.cs instanceof PurinePyrimidineColourScheme)
589 purinePyrimidineColour.setSelected(true);
593 * else if (sg.cs instanceof CovariationColourScheme) {
594 * covariationColour.setSelected(true); }
598 noColourmenuItem.setSelected(true);
601 if (sg.cs != null && sg.cs.conservationApplied())
603 conservationMenuItem.setSelected(true);
605 displayNonconserved.setSelected(sg.getShowNonconserved());
606 showText.setSelected(sg.getDisplayText());
607 showColourText.setSelected(sg.getColourText());
608 showBoxes.setSelected(sg.getDisplayBoxes());
609 // add any groupURLs to the groupURL submenu and make it visible
610 if (groupLinks != null && groupLinks.size() > 0)
612 buildGroupURLMenu(sg, groupLinks);
614 // Add a 'show all structures' for the current selection
615 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
616 SequenceI sqass = null;
617 for (SequenceI sq : ap.av.getSequenceSelection())
619 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
620 if (pes != null && pes.size() > 0)
622 reppdb.put(pes.get(0).getId(), pes.get(0));
623 for (PDBEntry pe : pes)
625 pdbe.put(pe.getId(), pe);
635 final PDBEntry[] pe = pdbe.values().toArray(
636 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
637 new PDBEntry[reppdb.size()]);
638 final JMenuItem gpdbview, rpdbview;
639 if (pdbe.size() == 1)
641 structureMenu.add(gpdbview = new JMenuItem(MessageManager
642 .formatMessage("label.view_structure_for", new String[]
643 { sqass.getDisplayId(false) })));
647 structureMenu.add(gpdbview = new JMenuItem(MessageManager
648 .formatMessage("label.view_all_structures", new String[]
649 { new Integer(pdbe.size()).toString() })));
651 gpdbview.setToolTipText(MessageManager
652 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
653 gpdbview.addActionListener(new ActionListener()
657 public void actionPerformed(ActionEvent e)
659 new StructureViewer(ap.getStructureSelectionManager())
660 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
663 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
665 structureMenu.add(rpdbview = new JMenuItem(MessageManager
667 "label.view_all_representative_structures",
669 { new Integer(reppdb.size()).toString() })));
670 rpdbview.setToolTipText(MessageManager
671 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
672 rpdbview.addActionListener(new ActionListener()
676 public void actionPerformed(ActionEvent e)
678 new StructureViewer(ap.getStructureSelectionManager())
679 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
687 groupMenu.setVisible(false);
688 editMenu.setVisible(false);
693 createGroupMenuItem.setVisible(true);
694 unGroupMenuItem.setVisible(false);
695 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
699 createGroupMenuItem.setVisible(false);
700 unGroupMenuItem.setVisible(true);
701 jMenu1.setText(MessageManager.getString("action.edit_group"));
706 sequenceMenu.setVisible(false);
707 structureMenu.setVisible(false);
710 if (links != null && links.size() > 0)
713 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
714 Vector linkset = new Vector();
715 for (int i = 0; i < links.size(); i++)
717 String link = links.elementAt(i).toString();
718 UrlLink urlLink = null;
721 urlLink = new UrlLink(link);
722 } catch (Exception foo)
724 jalview.bin.Cache.log.error("Exception for URLLink '" + link
729 if (!urlLink.isValid())
731 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
734 final String label = urlLink.getLabel();
735 if (seq != null && urlLink.isDynamic())
738 // collect matching db-refs
739 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
740 seq.getDBRef(), new String[]
741 { urlLink.getTarget() });
742 // collect id string too
743 String id = seq.getName();
744 String descr = seq.getDescription();
745 if (descr != null && descr.length() < 1)
752 for (int r = 0; r < dbr.length; r++)
754 if (id != null && dbr[r].getAccessionId().equals(id))
756 // suppress duplicate link creation for the bare sequence ID
757 // string with this link
760 // create Bare ID link for this RUL
761 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
765 for (int u = 0; u < urls.length; u += 2)
767 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
769 linkset.addElement(urls[u] + "|" + urls[u + 1]);
770 addshowLink(linkMenu, label + "|" + urls[u],
779 // create Bare ID link for this RUL
780 String[] urls = urlLink.makeUrls(id, true);
783 for (int u = 0; u < urls.length; u += 2)
785 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
787 linkset.addElement(urls[u] + "|" + urls[u + 1]);
788 addshowLink(linkMenu, label, urls[u + 1]);
793 // Create urls from description but only for URL links which are regex
795 if (descr != null && urlLink.getRegexReplace() != null)
797 // create link for this URL from description where regex matches
798 String[] urls = urlLink.makeUrls(descr, true);
801 for (int u = 0; u < urls.length; u += 2)
803 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
805 linkset.addElement(urls[u] + "|" + urls[u + 1]);
806 addshowLink(linkMenu, label, urls[u + 1]);
814 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
816 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
817 // Add a non-dynamic link
818 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
822 if (sequence != null)
824 sequenceMenu.add(linkMenu);
834 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
835 * "All" is added first, followed by a separator. Then add any annotation
836 * types associated with the current selection. Separate menus are built for
837 * the selected sequence group (if any), and the selected sequence.
839 * Some annotation rows are always rendered together - these can be identified
840 * by a common graphGroup property > -1. Only one of each group will be marked
841 * as visible (to avoid duplication of the display). For such groups we add a
842 * composite type name, e.g.
844 * IUPredWS (Long), IUPredWS (Short)
848 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
849 List<SequenceI> forSequences)
851 showMenu.removeAll();
852 hideMenu.removeAll();
854 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
855 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
856 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
858 showMenu.addSeparator();
859 hideMenu.addSeparator();
861 final AlignmentAnnotation[] annotations = ap.getAlignment()
862 .getAlignmentAnnotation();
865 * Find shown/hidden annotations types, distinguished by source (calcId),
866 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
867 * the insertion order, which is the order of the annotations on the
870 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
871 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
872 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
874 AlignmentAnnotationUtils.asList(annotations),
877 for (String calcId : hiddenTypes.keySet())
879 for (List<String> type : hiddenTypes.get(calcId))
881 addAnnotationTypeToShowHide(showMenu, forSequences,
882 calcId, type, false, true);
885 // grey out 'show annotations' if none are hidden
886 showMenu.setEnabled(!hiddenTypes.isEmpty());
888 for (String calcId : shownTypes.keySet())
890 for (List<String> type : shownTypes.get(calcId))
892 addAnnotationTypeToShowHide(hideMenu, forSequences,
893 calcId, type, false, false);
896 // grey out 'hide annotations' if none are shown
897 hideMenu.setEnabled(!shownTypes.isEmpty());
901 * Returns a list of sequences - either the current selection group (if there
902 * is one), else the specified single sequence.
907 protected List<SequenceI> getSequenceScope(SequenceI seq)
909 List<SequenceI> forSequences = null;
910 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
911 if (selectionGroup != null && selectionGroup.getSize() > 0)
913 forSequences = selectionGroup.getSequences();
917 forSequences = seq == null ? Collections.<SequenceI> emptyList()
918 : Arrays.asList(seq);
924 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
927 * @param showOrHideMenu
929 * @param forSequences
930 * the sequences whose annotations may be shown or hidden
935 * if true this is a special label meaning 'All'
936 * @param actionIsShow
937 * if true, the select menu item action is to show the annotation
940 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
941 final List<SequenceI> forSequences, String calcId,
942 final List<String> types, final boolean allTypes,
943 final boolean actionIsShow)
945 String label = types.toString(); // [a, b, c]
946 label = label.substring(1, label.length() - 1);
947 final JMenuItem item = new JMenuItem(label);
948 item.setToolTipText(calcId);
949 item.addActionListener(new java.awt.event.ActionListener()
952 public void actionPerformed(ActionEvent e)
954 showHideAnnotation_actionPerformed(types, forSequences, allTypes,
958 showOrHideMenu.add(item);
962 * Action on selecting a list of annotation type (or the 'all types' values)
963 * to show or hide for the specified sequences.
966 * @param forSequences
970 protected void showHideAnnotation_actionPerformed(
971 Collection<String> types, List<SequenceI> forSequences,
972 boolean anyType, boolean doShow)
974 for (AlignmentAnnotation aa : ap.getAlignment()
975 .getAlignmentAnnotation())
977 if (anyType || types.contains(aa.label))
979 if ((aa.sequenceRef != null)
980 && forSequences.contains(aa.sequenceRef))
989 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
992 // TODO: usability: thread off the generation of group url content so root
994 // sequence only URLs
995 // ID/regex match URLs
996 groupLinksMenu = new JMenu(
997 MessageManager.getString("action.group_link"));
998 JMenu[] linkMenus = new JMenu[]
999 { null, new JMenu(MessageManager.getString("action.ids")),
1000 new JMenu(MessageManager.getString("action.sequences")),
1001 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1008 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1009 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1010 Hashtable commonDbrefs = new Hashtable();
1011 for (int sq = 0; sq < seqs.length; sq++)
1014 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1015 .findPosition(sg.getEndRes());
1016 // just collect ids from dataset sequence
1017 // TODO: check if IDs collected from selecton group intersects with the
1018 // current selection, too
1019 SequenceI sqi = seqs[sq];
1020 while (sqi.getDatasetSequence() != null)
1022 sqi = sqi.getDatasetSequence();
1024 DBRefEntry[] dbr = sqi.getDBRef();
1025 if (dbr != null && dbr.length > 0)
1027 for (int d = 0; d < dbr.length; d++)
1029 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1030 Object[] sarray = (Object[]) commonDbrefs.get(src);
1033 sarray = new Object[2];
1034 sarray[0] = new int[]
1036 sarray[1] = new String[seqs.length];
1038 commonDbrefs.put(src, sarray);
1041 if (((String[]) sarray[1])[sq] == null)
1043 if (!dbr[d].hasMap()
1044 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1046 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1047 ((int[]) sarray[0])[0]++;
1053 // now create group links for all distinct ID/sequence sets.
1054 boolean addMenu = false; // indicates if there are any group links to give
1056 for (int i = 0; i < groupLinks.size(); i++)
1058 String link = groupLinks.elementAt(i).toString();
1059 GroupUrlLink urlLink = null;
1062 urlLink = new GroupUrlLink(link);
1063 } catch (Exception foo)
1065 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1070 if (!urlLink.isValid())
1072 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1075 final String label = urlLink.getLabel();
1076 boolean usingNames = false;
1077 // Now see which parts of the group apply for this URL
1078 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1079 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1080 String[] seqstr, ids; // input to makeUrl
1083 int numinput = ((int[]) idset[0])[0];
1084 String[] allids = ((String[]) idset[1]);
1085 seqstr = new String[numinput];
1086 ids = new String[numinput];
1087 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1089 if (allids[sq] != null)
1091 ids[idcount] = allids[sq];
1092 seqstr[idcount++] = idandseqs[1][sq];
1098 // just use the id/seq set
1099 seqstr = idandseqs[1];
1103 // and try and make the groupURL!
1105 Object[] urlset = null;
1108 urlset = urlLink.makeUrlStubs(ids, seqstr,
1109 "FromJalview" + System.currentTimeMillis(), false);
1110 } catch (UrlStringTooLongException e)
1115 int type = urlLink.getGroupURLType() & 3;
1116 // System.out.println(urlLink.getGroupURLType()
1117 // +" "+((String[])urlset[3])[0]);
1118 // first two bits ofurlLink type bitfield are sequenceids and sequences
1119 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1120 addshowLink(linkMenus[type], label
1121 + (((type & 1) == 1) ? ("("
1122 + (usingNames ? "Names" : ltarget) + ")") : ""),
1129 groupLinksMenu = new JMenu(
1130 MessageManager.getString("action.group_link"));
1131 for (int m = 0; m < linkMenus.length; m++)
1133 if (linkMenus[m] != null
1134 && linkMenus[m].getMenuComponentCount() > 0)
1136 groupLinksMenu.add(linkMenus[m]);
1140 groupMenu.add(groupLinksMenu);
1145 * add a show URL menu item to the given linkMenu
1149 * - menu label string
1153 private void addshowLink(JMenu linkMenu, String label, final String url)
1155 JMenuItem item = new JMenuItem(label);
1156 item.setToolTipText(MessageManager.formatMessage(
1157 "label.open_url_param", new String[]
1159 item.addActionListener(new java.awt.event.ActionListener()
1162 public void actionPerformed(ActionEvent e)
1164 new Thread(new Runnable()
1181 * add a late bound groupURL item to the given linkMenu
1185 * - menu label string
1186 * @param urlgenerator
1187 * GroupURLLink used to generate URL
1189 * Object array returned from the makeUrlStubs function.
1191 private void addshowLink(JMenu linkMenu, String label,
1192 final GroupUrlLink urlgenerator, final Object[] urlstub)
1194 JMenuItem item = new JMenuItem(label);
1195 item.setToolTipText(MessageManager.formatMessage(
1196 "label.open_url_seqs_param",
1198 { urlgenerator.getUrl_prefix(),
1199 urlgenerator.getNumberInvolved(urlstub) }));
1200 // TODO: put in info about what is being sent.
1201 item.addActionListener(new java.awt.event.ActionListener()
1204 public void actionPerformed(ActionEvent e)
1206 new Thread(new Runnable()
1214 showLink(urlgenerator.constructFrom(urlstub));
1215 } catch (UrlStringTooLongException e)
1233 private void jbInit() throws Exception
1235 groupMenu.setText(MessageManager.getString("label.group"));
1236 groupMenu.setText(MessageManager.getString("label.selection"));
1237 groupName.setText(MessageManager.getString("label.name"));
1238 groupName.addActionListener(new java.awt.event.ActionListener()
1241 public void actionPerformed(ActionEvent e)
1243 groupName_actionPerformed();
1246 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1247 sequenceName.setText(MessageManager
1248 .getString("label.edit_name_description"));
1249 sequenceName.addActionListener(new java.awt.event.ActionListener()
1252 public void actionPerformed(ActionEvent e)
1254 sequenceName_actionPerformed();
1257 chooseAnnotations.setText(MessageManager
1258 .getString("label.choose_annotations") + "...");
1259 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1262 public void actionPerformed(ActionEvent e)
1264 chooseAnnotations_actionPerformed(e);
1267 sequenceDetails.setText(MessageManager
1268 .getString("label.sequence_details") + "...");
1269 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1272 public void actionPerformed(ActionEvent e)
1274 sequenceDetails_actionPerformed();
1277 sequenceSelDetails.setText(MessageManager
1278 .getString("label.sequence_details") + "...");
1280 .addActionListener(new java.awt.event.ActionListener()
1283 public void actionPerformed(ActionEvent e)
1285 sequenceSelectionDetails_actionPerformed();
1288 PIDColour.setFocusPainted(false);
1290 .setText(MessageManager.getString("action.remove_group"));
1291 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1294 public void actionPerformed(ActionEvent e)
1296 unGroupMenuItem_actionPerformed();
1299 createGroupMenuItem.setText(MessageManager
1300 .getString("action.create_group"));
1302 .addActionListener(new java.awt.event.ActionListener()
1305 public void actionPerformed(ActionEvent e)
1307 createGroupMenuItem_actionPerformed();
1311 outline.setText(MessageManager.getString("action.border_colour"));
1312 outline.addActionListener(new java.awt.event.ActionListener()
1315 public void actionPerformed(ActionEvent e)
1317 outline_actionPerformed();
1321 .setText(MessageManager.getString("label.nucleotide"));
1322 nucleotideMenuItem.addActionListener(new ActionListener()
1325 public void actionPerformed(ActionEvent e)
1327 nucleotideMenuItem_actionPerformed();
1330 colourMenu.setText(MessageManager.getString("label.group_colour"));
1331 showBoxes.setText(MessageManager.getString("action.boxes"));
1332 showBoxes.setState(true);
1333 showBoxes.addActionListener(new ActionListener()
1336 public void actionPerformed(ActionEvent e)
1338 showBoxes_actionPerformed();
1341 showText.setText(MessageManager.getString("action.text"));
1342 showText.setState(true);
1343 showText.addActionListener(new ActionListener()
1346 public void actionPerformed(ActionEvent e)
1348 showText_actionPerformed();
1351 showColourText.setText(MessageManager.getString("label.colour_text"));
1352 showColourText.addActionListener(new ActionListener()
1355 public void actionPerformed(ActionEvent e)
1357 showColourText_actionPerformed();
1360 displayNonconserved.setText(MessageManager
1361 .getString("label.show_non_conversed"));
1362 displayNonconserved.setState(true);
1363 displayNonconserved.addActionListener(new ActionListener()
1366 public void actionPerformed(ActionEvent e)
1368 showNonconserved_actionPerformed();
1371 editMenu.setText(MessageManager.getString("action.edit"));
1372 cut.setText(MessageManager.getString("action.cut"));
1373 cut.addActionListener(new ActionListener()
1376 public void actionPerformed(ActionEvent e)
1378 cut_actionPerformed();
1381 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1382 upperCase.addActionListener(new ActionListener()
1385 public void actionPerformed(ActionEvent e)
1390 copy.setText(MessageManager.getString("action.copy"));
1391 copy.addActionListener(new ActionListener()
1394 public void actionPerformed(ActionEvent e)
1396 copy_actionPerformed();
1399 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1400 lowerCase.addActionListener(new ActionListener()
1403 public void actionPerformed(ActionEvent e)
1408 toggle.setText(MessageManager.getString("label.toggle_case"));
1409 toggle.addActionListener(new ActionListener()
1412 public void actionPerformed(ActionEvent e)
1417 pdbMenu.setText(MessageManager
1418 .getString("label.associate_structure_with_sequence"));
1419 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1420 pdbFromFile.addActionListener(new ActionListener()
1423 public void actionPerformed(ActionEvent e)
1425 pdbFromFile_actionPerformed();
1428 // RNAFold.setText("From RNA Fold with predict2D");
1429 // RNAFold.addActionListener(new ActionListener()
1431 // public void actionPerformed(ActionEvent e)
1434 // RNAFold_actionPerformed();
1435 // } catch (Exception e1) {
1436 // // TODO Auto-generated catch block
1437 // e1.printStackTrace();
1441 // ContraFold.setText("From Contra Fold with predict2D");
1442 // ContraFold.addActionListener(new ActionListener()
1444 // public void actionPerformed(ActionEvent e)
1447 // ContraFold_actionPerformed();
1448 // } catch (Exception e1) {
1449 // // TODO Auto-generated catch block
1450 // e1.printStackTrace();
1454 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1455 enterPDB.addActionListener(new ActionListener()
1458 public void actionPerformed(ActionEvent e)
1460 enterPDB_actionPerformed();
1463 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1464 discoverPDB.addActionListener(new ActionListener()
1467 public void actionPerformed(ActionEvent e)
1469 discoverPDB_actionPerformed();
1472 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1474 seqShowAnnotationsMenu.setText(MessageManager
1475 .getString("label.show_annotations"));
1476 seqHideAnnotationsMenu.setText(MessageManager
1477 .getString("label.hide_annotations"));
1478 groupShowAnnotationsMenu.setText(MessageManager
1479 .getString("label.show_annotations"));
1480 groupHideAnnotationsMenu.setText(MessageManager
1481 .getString("label.hide_annotations"));
1482 sequenceFeature.setText(MessageManager
1483 .getString("label.create_sequence_feature"));
1484 sequenceFeature.addActionListener(new ActionListener()
1487 public void actionPerformed(ActionEvent e)
1489 sequenceFeature_actionPerformed();
1492 textColour.setText(MessageManager.getString("label.text_colour"));
1493 textColour.addActionListener(new ActionListener()
1496 public void actionPerformed(ActionEvent e)
1498 textColour_actionPerformed();
1501 jMenu1.setText(MessageManager.getString("label.group"));
1502 structureMenu.setText(MessageManager.getString("label.structure"));
1503 viewStructureMenu.setText(MessageManager
1504 .getString("label.view_structure"));
1505 // colStructureMenu.setText("Colour By Structure");
1506 editSequence.setText(MessageManager.getString("label.edit_sequence")
1508 editSequence.addActionListener(new ActionListener()
1511 public void actionPerformed(ActionEvent actionEvent)
1513 editSequence_actionPerformed(actionEvent);
1516 makeReferenceSeq.setText("Mark as representative");
1517 makeReferenceSeq.addActionListener(new ActionListener()
1521 public void actionPerformed(ActionEvent actionEvent)
1523 makeReferenceSeq_actionPerformed(actionEvent);
1528 * annotationMenuItem.setText("By Annotation");
1529 * annotationMenuItem.addActionListener(new ActionListener() { public void
1530 * actionPerformed(ActionEvent actionEvent) {
1531 * annotationMenuItem_actionPerformed(actionEvent); } });
1533 groupMenu.add(sequenceSelDetails);
1536 this.add(structureMenu);
1537 // annotations configuration panel suppressed for now
1538 // groupMenu.add(chooseAnnotations);
1541 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1542 * (if a selection group is in force).
1544 sequenceMenu.add(seqShowAnnotationsMenu);
1545 sequenceMenu.add(seqHideAnnotationsMenu);
1546 sequenceMenu.add(seqAddReferenceAnnotations);
1547 groupMenu.add(groupShowAnnotationsMenu);
1548 groupMenu.add(groupHideAnnotationsMenu);
1549 groupMenu.add(groupAddReferenceAnnotations);
1550 groupMenu.add(editMenu);
1551 groupMenu.add(outputMenu);
1552 groupMenu.add(sequenceFeature);
1553 groupMenu.add(createGroupMenuItem);
1554 groupMenu.add(unGroupMenuItem);
1555 groupMenu.add(jMenu1);
1556 sequenceMenu.add(sequenceName);
1557 sequenceMenu.add(sequenceDetails);
1558 sequenceMenu.add(makeReferenceSeq);
1559 colourMenu.add(textColour);
1560 colourMenu.add(noColourmenuItem);
1561 colourMenu.add(clustalColour);
1562 colourMenu.add(BLOSUM62Colour);
1563 colourMenu.add(PIDColour);
1564 colourMenu.add(zappoColour);
1565 colourMenu.add(taylorColour);
1566 colourMenu.add(hydrophobicityColour);
1567 colourMenu.add(helixColour);
1568 colourMenu.add(strandColour);
1569 colourMenu.add(turnColour);
1570 colourMenu.add(buriedColour);
1571 colourMenu.add(nucleotideMenuItem);
1572 if (ap.getAlignment().isNucleotide())
1574 // JBPNote - commented since the colourscheme isn't functional
1575 // colourMenu.add(RNAInteractionColour);
1576 colourMenu.add(purinePyrimidineColour);
1578 // colourMenu.add(covariationColour);
1579 colourMenu.add(userDefinedColour);
1581 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1583 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1584 .getUserColourSchemes().keys();
1586 while (userColours.hasMoreElements())
1588 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1589 item.addActionListener(new ActionListener()
1592 public void actionPerformed(ActionEvent evt)
1594 userDefinedColour_actionPerformed(evt);
1597 colourMenu.add(item);
1601 colourMenu.addSeparator();
1602 colourMenu.add(abovePIDColour);
1603 colourMenu.add(conservationMenuItem);
1604 // colourMenu.add(annotationMenuItem);
1607 editMenu.add(editSequence);
1608 editMenu.add(upperCase);
1609 editMenu.add(lowerCase);
1610 editMenu.add(toggle);
1611 pdbMenu.add(pdbFromFile);
1612 // JBPNote: These shouldn't be added here - should appear in a generic
1613 // 'apply web service to this sequence menu'
1614 // pdbMenu.add(RNAFold);
1615 // pdbMenu.add(ContraFold);
1616 pdbMenu.add(enterPDB);
1617 pdbMenu.add(discoverPDB);
1618 jMenu1.add(groupName);
1619 jMenu1.add(colourMenu);
1620 jMenu1.add(showBoxes);
1621 jMenu1.add(showText);
1622 jMenu1.add(showColourText);
1623 jMenu1.add(outline);
1624 jMenu1.add(displayNonconserved);
1625 structureMenu.add(pdbMenu);
1626 structureMenu.add(viewStructureMenu);
1627 // structureMenu.add(colStructureMenu);
1628 noColourmenuItem.setText(MessageManager.getString("label.none"));
1629 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1632 public void actionPerformed(ActionEvent e)
1634 noColourmenuItem_actionPerformed();
1638 clustalColour.setText(MessageManager
1639 .getString("label.clustalx_colours"));
1640 clustalColour.addActionListener(new java.awt.event.ActionListener()
1643 public void actionPerformed(ActionEvent e)
1645 clustalColour_actionPerformed();
1648 zappoColour.setText(MessageManager.getString("label.zappo"));
1649 zappoColour.addActionListener(new java.awt.event.ActionListener()
1652 public void actionPerformed(ActionEvent e)
1654 zappoColour_actionPerformed();
1657 taylorColour.setText(MessageManager.getString("label.taylor"));
1658 taylorColour.addActionListener(new java.awt.event.ActionListener()
1661 public void actionPerformed(ActionEvent e)
1663 taylorColour_actionPerformed();
1666 hydrophobicityColour.setText(MessageManager
1667 .getString("label.hydrophobicity"));
1668 hydrophobicityColour
1669 .addActionListener(new java.awt.event.ActionListener()
1672 public void actionPerformed(ActionEvent e)
1674 hydrophobicityColour_actionPerformed();
1677 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1678 helixColour.addActionListener(new java.awt.event.ActionListener()
1681 public void actionPerformed(ActionEvent e)
1683 helixColour_actionPerformed();
1686 strandColour.setText(MessageManager
1687 .getString("label.strand_propensity"));
1688 strandColour.addActionListener(new java.awt.event.ActionListener()
1691 public void actionPerformed(ActionEvent e)
1693 strandColour_actionPerformed();
1696 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1697 turnColour.addActionListener(new java.awt.event.ActionListener()
1700 public void actionPerformed(ActionEvent e)
1702 turnColour_actionPerformed();
1705 buriedColour.setText(MessageManager.getString("label.buried_index"));
1706 buriedColour.addActionListener(new java.awt.event.ActionListener()
1709 public void actionPerformed(ActionEvent e)
1711 buriedColour_actionPerformed();
1714 abovePIDColour.setText(MessageManager
1715 .getString("label.above_identity_percentage"));
1716 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1719 public void actionPerformed(ActionEvent e)
1721 abovePIDColour_actionPerformed();
1724 userDefinedColour.setText(MessageManager
1725 .getString("action.user_defined"));
1726 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1729 public void actionPerformed(ActionEvent e)
1731 userDefinedColour_actionPerformed(e);
1735 .setText(MessageManager.getString("label.percentage_identity"));
1736 PIDColour.addActionListener(new java.awt.event.ActionListener()
1739 public void actionPerformed(ActionEvent e)
1741 PIDColour_actionPerformed();
1744 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1745 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1748 public void actionPerformed(ActionEvent e)
1750 BLOSUM62Colour_actionPerformed();
1753 purinePyrimidineColour.setText(MessageManager
1754 .getString("label.purine_pyrimidine"));
1755 purinePyrimidineColour
1756 .addActionListener(new java.awt.event.ActionListener()
1759 public void actionPerformed(ActionEvent e)
1761 purinePyrimidineColour_actionPerformed();
1766 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1767 * public void actionPerformed(ActionEvent e) {
1768 * covariationColour_actionPerformed(); } });
1771 conservationMenuItem.setText(MessageManager
1772 .getString("label.conservation"));
1773 conservationMenuItem
1774 .addActionListener(new java.awt.event.ActionListener()
1777 public void actionPerformed(ActionEvent e)
1779 conservationMenuItem_actionPerformed();
1785 * Check for any annotations on the underlying dataset sequences (for the
1786 * current selection group) which are not 'on the alignment'.If any are found,
1787 * enable the option to add them to the alignment. The criteria for 'on the
1788 * alignment' is finding an alignment annotation on the alignment, matched on
1789 * calcId, label and sequenceRef.
1791 * A tooltip is also constructed that displays the source (calcId) and type
1792 * (label) of the annotations that can be added.
1795 * @param forSequences
1797 protected void configureReferenceAnnotationsMenu(
1798 JMenuItem menuItem, List<SequenceI> forSequences)
1800 menuItem.setText(MessageManager
1801 .getString("label.add_reference_annotations"));
1802 menuItem.setEnabled(false);
1803 if (forSequences == null)
1809 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1810 * Using TreeMap means calcIds are shown in alphabetical order.
1812 Map<String, String> tipEntries = new TreeMap<String, String>();
1813 StringBuilder tooltip = new StringBuilder(64);
1814 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1817 * For each sequence selected in the alignment, make a list of any
1818 * annotations on the underlying dataset sequence which are not already on
1821 * Build a map of { alignmentSequence, <List of annotations to add> }
1823 AlignmentI al = this.ap.av.getAlignment();
1824 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1825 for (SequenceI seq : forSequences)
1827 SequenceI dataset = seq.getDatasetSequence();
1828 if (dataset == null)
1832 AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
1833 if (datasetAnnotations == null)
1837 final List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1838 for (AlignmentAnnotation dsann : datasetAnnotations)
1841 * Find matching annotations on the alignment.
1843 final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al
1844 .findAnnotations(seq, dsann.getCalcId(),
1846 if (!matchedAlignmentAnnotations.iterator().hasNext())
1849 tipEntries.put(dsann.getCalcId(), dsann.label);
1853 * Save any addable annotations for this sequence
1855 if (!result.isEmpty())
1857 candidates.put(seq, result);
1860 if (!candidates.isEmpty())
1863 * Found annotations that could be added. Enable the menu item, and
1864 * configure its tooltip and action.
1866 menuItem.setEnabled(true);
1867 for (String calcId : tipEntries.keySet())
1869 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1871 String tooltipText = JvSwingUtils.wrapTooltip(true,
1872 tooltip.toString());
1873 menuItem.setToolTipText(tooltipText);
1875 menuItem.addActionListener(new ActionListener()
1878 public void actionPerformed(ActionEvent e)
1880 addReferenceAnnotations_actionPerformed(candidates);
1887 * Add annotations to the sequences and to the alignment.
1890 * a map whose keys are sequences on the alignment, and values a list
1891 * of annotations to add to each sequence
1893 protected void addReferenceAnnotations_actionPerformed(
1894 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1897 * Add annotations at the top of the annotation, in the same order as their
1898 * related sequences.
1900 for (SequenceI seq : candidates.keySet())
1902 for (AlignmentAnnotation ann : candidates.get(seq))
1904 AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
1906 int endRes = ann.annotations.length;
1907 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1908 if (selectionGroup != null)
1910 startRes = selectionGroup.getStartRes();
1911 endRes = selectionGroup.getEndRes();
1913 copyAnn.restrict(startRes, endRes);
1916 * Add to the sequence (sets copyAnn.datasetSequence), unless the
1917 * original annotation is already on the sequence.
1919 if (!seq.hasAnnotation(ann))
1921 seq.addAlignmentAnnotation(copyAnn);
1924 copyAnn.adjustForAlignment();
1925 // add to the alignment and set visible
1926 this.ap.getAlignment().addAnnotation(copyAnn);
1927 copyAnn.visible = true;
1932 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1934 if (!ap.av.getAlignment().hasSeqrep())
1936 // initialise the display flags so the user sees something happen
1937 ap.av.setDisplayReferenceSeq(true);
1938 ap.av.setColourByReferenceSeq(true);
1939 ap.av.getAlignment().setSeqrep(sequence);
1943 if (ap.av.getAlignment().getSeqrep() == sequence)
1945 ap.av.getAlignment().setSeqrep(null);
1949 ap.av.getAlignment().setSeqrep(sequence);
1955 protected void sequenceSelectionDetails_actionPerformed()
1957 createSequenceDetailsReport(ap.av.getSequenceSelection());
1960 protected void sequenceDetails_actionPerformed()
1962 createSequenceDetailsReport(new SequenceI[]
1966 public void createSequenceDetailsReport(SequenceI[] sequences)
1968 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1969 StringBuffer contents = new StringBuffer();
1970 for (SequenceI seq : sequences)
1972 contents.append("<p><h2>"
1975 "label.create_sequence_details_report_annotation_for",
1977 { seq.getDisplayId(true) }) + "</h2></p><p>");
1978 new SequenceAnnotationReport(null)
1979 .createSequenceAnnotationReport(
1985 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1986 .getSeqPanel().seqCanvas.fr
1989 contents.append("</p>");
1991 cap.setText("<html>" + contents.toString() + "</html>");
1993 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
1994 "label.sequece_details_for",
1995 (sequences.length == 1 ? new String[]
1996 { sequences[0].getDisplayId(true) } : new String[]
1997 { MessageManager.getString("label.selection") })), 500, 400);
2001 protected void showNonconserved_actionPerformed()
2003 getGroup().setShowNonconserved(displayNonconserved.isSelected());
2008 * call to refresh view after settings change
2012 ap.updateAnnotation();
2013 ap.paintAlignment(true);
2015 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
2024 protected void clustalColour_actionPerformed()
2026 SequenceGroup sg = getGroup();
2027 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
2037 protected void zappoColour_actionPerformed()
2039 getGroup().cs = new ZappoColourScheme();
2049 protected void taylorColour_actionPerformed()
2051 getGroup().cs = new TaylorColourScheme();
2061 protected void hydrophobicityColour_actionPerformed()
2063 getGroup().cs = new HydrophobicColourScheme();
2073 protected void helixColour_actionPerformed()
2075 getGroup().cs = new HelixColourScheme();
2085 protected void strandColour_actionPerformed()
2087 getGroup().cs = new StrandColourScheme();
2097 protected void turnColour_actionPerformed()
2099 getGroup().cs = new TurnColourScheme();
2109 protected void buriedColour_actionPerformed()
2111 getGroup().cs = new BuriedColourScheme();
2121 public void nucleotideMenuItem_actionPerformed()
2123 getGroup().cs = new NucleotideColourScheme();
2127 protected void purinePyrimidineColour_actionPerformed()
2129 getGroup().cs = new PurinePyrimidineColourScheme();
2134 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2135 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2143 protected void abovePIDColour_actionPerformed()
2145 SequenceGroup sg = getGroup();
2151 if (abovePIDColour.isSelected())
2153 sg.cs.setConsensus(AAFrequency.calculate(
2154 sg.getSequences(ap.av.getHiddenRepSequences()),
2155 sg.getStartRes(), sg.getEndRes() + 1));
2157 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2160 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
2162 SliderPanel.showPIDSlider();
2165 // remove PIDColouring
2167 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
2179 protected void userDefinedColour_actionPerformed(ActionEvent e)
2181 SequenceGroup sg = getGroup();
2183 if (e.getSource().equals(userDefinedColour))
2185 new UserDefinedColours(ap, sg);
2189 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2190 .getUserColourSchemes().get(e.getActionCommand());
2198 * Open a panel where the user can choose which types of sequence annotation
2203 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2205 // todo correct way to guard against opening a duplicate panel?
2206 new AnnotationChooser(ap);
2215 protected void PIDColour_actionPerformed()
2217 SequenceGroup sg = getGroup();
2218 sg.cs = new PIDColourScheme();
2219 sg.cs.setConsensus(AAFrequency.calculate(
2220 sg.getSequences(ap.av.getHiddenRepSequences()),
2221 sg.getStartRes(), sg.getEndRes() + 1));
2231 protected void BLOSUM62Colour_actionPerformed()
2233 SequenceGroup sg = getGroup();
2235 sg.cs = new Blosum62ColourScheme();
2237 sg.cs.setConsensus(AAFrequency.calculate(
2238 sg.getSequences(ap.av.getHiddenRepSequences()),
2239 sg.getStartRes(), sg.getEndRes() + 1));
2250 protected void noColourmenuItem_actionPerformed()
2252 getGroup().cs = null;
2262 protected void conservationMenuItem_actionPerformed()
2264 SequenceGroup sg = getGroup();
2270 if (conservationMenuItem.isSelected())
2272 // JBPNote: Conservation name shouldn't be i18n translated
2273 Conservation c = new Conservation("Group",
2274 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2275 .getHiddenRepSequences()), sg.getStartRes(),
2276 sg.getEndRes() + 1);
2279 c.verdict(false, ap.av.getConsPercGaps());
2281 sg.cs.setConservation(c);
2283 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2284 SliderPanel.showConservationSlider();
2287 // remove ConservationColouring
2289 sg.cs.setConservation(null);
2295 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2297 SequenceGroup sg = getGroup();
2303 AnnotationColourGradient acg = new AnnotationColourGradient(
2304 sequence.getAnnotation()[0], null,
2305 AnnotationColourGradient.NO_THRESHOLD);
2307 acg.setPredefinedColours(true);
2319 protected void groupName_actionPerformed()
2322 SequenceGroup sg = getGroup();
2323 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2324 sg.getDescription(), " "
2325 + MessageManager.getString("label.group_name") + " ",
2326 MessageManager.getString("label.group_description") + " ",
2327 MessageManager.getString("label.edit_group_name_description"),
2335 sg.setName(dialog.getName());
2336 sg.setDescription(dialog.getDescription());
2341 * Get selection group - adding it to the alignment if necessary.
2343 * @return sequence group to operate on
2345 SequenceGroup getGroup()
2347 SequenceGroup sg = ap.av.getSelectionGroup();
2348 // this method won't add a new group if it already exists
2351 ap.av.getAlignment().addGroup(sg);
2363 void sequenceName_actionPerformed()
2365 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2366 sequence.getDescription(),
2367 " " + MessageManager.getString("label.sequence_name")
2369 MessageManager.getString("label.sequence_description") + " ",
2371 .getString("label.edit_sequence_name_description"),
2379 if (dialog.getName() != null)
2381 if (dialog.getName().indexOf(" ") > -1)
2387 .getString("label.spaces_converted_to_backslashes"),
2389 .getString("label.no_spaces_allowed_sequence_name"),
2390 JOptionPane.WARNING_MESSAGE);
2393 sequence.setName(dialog.getName().replace(' ', '_'));
2394 ap.paintAlignment(false);
2397 sequence.setDescription(dialog.getDescription());
2399 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2410 void unGroupMenuItem_actionPerformed()
2412 SequenceGroup sg = ap.av.getSelectionGroup();
2413 ap.av.getAlignment().deleteGroup(sg);
2414 ap.av.setSelectionGroup(null);
2418 void createGroupMenuItem_actionPerformed()
2420 getGroup(); // implicitly creates group - note - should apply defaults / use
2421 // standard alignment window logic for this
2431 protected void outline_actionPerformed()
2433 SequenceGroup sg = getGroup();
2434 Color col = JColorChooser.showDialog(this,
2435 MessageManager.getString("label.select_outline_colour"),
2440 sg.setOutlineColour(col);
2452 public void showBoxes_actionPerformed()
2454 getGroup().setDisplayBoxes(showBoxes.isSelected());
2464 public void showText_actionPerformed()
2466 getGroup().setDisplayText(showText.isSelected());
2476 public void showColourText_actionPerformed()
2478 getGroup().setColourText(showColourText.isSelected());
2482 public void showLink(String url)
2486 jalview.util.BrowserLauncher.openURL(url);
2487 } catch (Exception ex)
2489 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2490 MessageManager.getString("label.web_browser_not_found_unix"),
2491 MessageManager.getString("label.web_browser_not_found"),
2492 JOptionPane.WARNING_MESSAGE);
2494 ex.printStackTrace();
2498 void hideSequences(boolean representGroup)
2500 SequenceGroup sg = ap.av.getSelectionGroup();
2501 if (sg == null || sg.getSize() < 1)
2503 ap.av.hideSequence(new SequenceI[]
2508 ap.av.setSelectionGroup(null);
2512 ap.av.hideRepSequences(sequence, sg);
2517 int gsize = sg.getSize();
2520 hseqs = new SequenceI[gsize];
2523 for (int i = 0; i < gsize; i++)
2525 hseqs[index++] = sg.getSequenceAt(i);
2528 ap.av.hideSequence(hseqs);
2529 // refresh(); TODO: ? needed ?
2530 ap.av.sendSelection();
2533 public void copy_actionPerformed()
2535 ap.alignFrame.copy_actionPerformed(null);
2538 public void cut_actionPerformed()
2540 ap.alignFrame.cut_actionPerformed(null);
2543 void changeCase(ActionEvent e)
2545 Object source = e.getSource();
2546 SequenceGroup sg = ap.av.getSelectionGroup();
2550 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
2551 sg.getEndRes() + 1);
2556 if (source == toggle)
2558 description = MessageManager.getString("label.toggle_case");
2559 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2561 else if (source == upperCase)
2563 description = MessageManager.getString("label.to_upper_case");
2564 caseChange = ChangeCaseCommand.TO_UPPER;
2568 description = MessageManager.getString("label.to_lower_case");
2569 caseChange = ChangeCaseCommand.TO_LOWER;
2572 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2573 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2574 startEnd, caseChange);
2576 ap.alignFrame.addHistoryItem(caseCommand);
2578 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2584 public void outputText_actionPerformed(ActionEvent e)
2586 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2587 cap.setForInput(null);
2588 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2589 "label.alignment_output_command", new String[]
2590 { e.getActionCommand() }), 600, 500);
2592 String[] omitHidden = null;
2594 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2595 // or we simply trust the user wants
2596 // wysiwig behaviour
2598 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2602 public void pdbFromFile_actionPerformed()
2604 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2605 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2606 chooser.setFileView(new jalview.io.JalviewFileView());
2607 chooser.setDialogTitle(MessageManager.formatMessage(
2608 "label.select_pdb_file_for", new String[]
2609 { sequence.getDisplayId(false) }));
2610 chooser.setToolTipText(MessageManager.formatMessage(
2611 "label.load_pdb_file_associate_with_sequence", new String[]
2612 { sequence.getDisplayId(false) }));
2614 int value = chooser.showOpenDialog(null);
2616 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2618 String choice = chooser.getSelectedFile().getPath();
2619 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2620 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2621 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2627 // JBNote: commented out - these won't be instantiated here...!
2628 // public void RNAFold_actionPerformed() throws Exception
2630 // Predict2D P2D = new Predict2D();
2631 // P2D.getStructure2DFromRNAFold("toto");
2634 // public void ContraFold_actionPerformed() throws Exception
2636 // Predict2D P2D = new Predict2D();
2637 // P2D.getStructure2DFromContraFold("toto");
2639 public void enterPDB_actionPerformed()
2641 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2642 MessageManager.getString("label.enter_pdb_id"),
2643 MessageManager.getString("label.enter_pdb_id"),
2644 JOptionPane.QUESTION_MESSAGE);
2646 if (id != null && id.length() > 0)
2648 PDBEntry entry = new PDBEntry();
2649 entry.setId(id.toUpperCase());
2650 sequence.getDatasetSequence().addPDBId(entry);
2654 public void discoverPDB_actionPerformed()
2657 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2659 : ap.av.getSequenceSelection());
2660 Thread discpdb = new Thread(new Runnable()
2666 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2667 .fetchDBRefs(false);
2674 public void sequenceFeature_actionPerformed()
2676 SequenceGroup sg = ap.av.getSelectionGroup();
2682 int rsize = 0, gSize = sg.getSize();
2683 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2684 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2686 for (int i = 0; i < gSize; i++)
2688 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2689 int end = sg.findEndRes(sg.getSequenceAt(i));
2692 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2693 features[rsize] = new SequenceFeature(null, null, null, start, end,
2698 rseqs = new SequenceI[rsize];
2699 tfeatures = new SequenceFeature[rsize];
2700 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2701 System.arraycopy(features, 0, tfeatures, 0, rsize);
2702 features = tfeatures;
2704 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2705 features, true, ap))
2707 ap.alignFrame.setShowSeqFeatures(true);
2708 ap.highlightSearchResults(null);
2712 public void textColour_actionPerformed()
2714 SequenceGroup sg = getGroup();
2717 new TextColourChooser().chooseColour(ap, sg);
2721 public void colourByStructure(String pdbid)
2723 Annotation[] anots = ap.av.getStructureSelectionManager()
2724 .colourSequenceFromStructure(sequence, pdbid);
2726 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2727 "Coloured by " + pdbid, anots);
2729 ap.av.getAlignment().addAnnotation(an);
2730 an.createSequenceMapping(sequence, 0, true);
2731 // an.adjustForAlignment();
2732 ap.av.getAlignment().setAnnotationIndex(an, 0);
2734 ap.adjustAnnotationHeight();
2736 sequence.addAlignmentAnnotation(an);
2740 public void editSequence_actionPerformed(ActionEvent actionEvent)
2742 SequenceGroup sg = ap.av.getSelectionGroup();
2746 if (sequence == null)
2748 sequence = sg.getSequenceAt(0);
2751 EditNameDialog dialog = new EditNameDialog(
2752 sequence.getSequenceAsString(sg.getStartRes(),
2753 sg.getEndRes() + 1), null,
2754 MessageManager.getString("label.edit_sequence"), null,
2755 MessageManager.getString("label.edit_sequence"),
2760 EditCommand editCommand = new EditCommand(
2761 MessageManager.getString("label.edit_sequences"),
2762 Action.REPLACE, dialog.getName().replace(' ',
2763 ap.av.getGapCharacter()),
2764 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2765 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2767 ap.alignFrame.addHistoryItem(editCommand);
2769 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()