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.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.DBRefEntry;
31 import jalview.datamodel.PDBEntry;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceFeature;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.io.FormatAdapter;
37 import jalview.io.SequenceAnnotationReport;
38 import jalview.schemes.AnnotationColourGradient;
39 import jalview.schemes.Blosum62ColourScheme;
40 import jalview.schemes.BuriedColourScheme;
41 import jalview.schemes.ClustalxColourScheme;
42 import jalview.schemes.HelixColourScheme;
43 import jalview.schemes.HydrophobicColourScheme;
44 import jalview.schemes.NucleotideColourScheme;
45 import jalview.schemes.PIDColourScheme;
46 import jalview.schemes.PurinePyrimidineColourScheme;
47 import jalview.schemes.ResidueProperties;
48 import jalview.schemes.StrandColourScheme;
49 import jalview.schemes.TaylorColourScheme;
50 import jalview.schemes.TurnColourScheme;
51 import jalview.schemes.UserColourScheme;
52 import jalview.schemes.ZappoColourScheme;
53 import jalview.util.GroupUrlLink;
54 import jalview.util.GroupUrlLink.UrlStringTooLongException;
55 import jalview.util.MessageManager;
56 import jalview.util.UrlLink;
58 import java.awt.Color;
59 import java.awt.event.ActionEvent;
60 import java.awt.event.ActionListener;
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.Collection;
64 import java.util.Collections;
65 import java.util.Hashtable;
66 import java.util.LinkedHashMap;
67 import java.util.List;
69 import java.util.TreeMap;
70 import java.util.Vector;
72 import javax.swing.ButtonGroup;
73 import javax.swing.JCheckBoxMenuItem;
74 import javax.swing.JColorChooser;
75 import javax.swing.JMenu;
76 import javax.swing.JMenuItem;
77 import javax.swing.JOptionPane;
78 import javax.swing.JPopupMenu;
79 import javax.swing.JRadioButtonMenuItem;
85 * @version $Revision: 1.118 $
87 public class PopupMenu extends JPopupMenu
89 private static final String ALL_ANNOTATIONS = "All";
91 private static final String COMMA = ",";
93 JMenu groupMenu = new JMenu();
95 JMenuItem groupName = new JMenuItem();
97 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
99 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
113 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
115 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
117 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
125 // protected JRadioButtonMenuItem covariationColour = new
126 // JRadioButtonMenuItem();
128 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
130 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
134 JMenu sequenceMenu = new JMenu();
136 JMenuItem sequenceName = new JMenuItem();
138 JMenuItem sequenceDetails = new JMenuItem();
140 JMenuItem sequenceSelDetails = new JMenuItem();
142 JMenuItem chooseAnnotations = new JMenuItem();
146 JMenuItem createGroupMenuItem = new JMenuItem();
148 JMenuItem unGroupMenuItem = new JMenuItem();
150 JMenuItem outline = new JMenuItem();
152 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
154 JMenu colourMenu = new JMenu();
156 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
158 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
164 JMenu editMenu = new JMenu();
166 JMenuItem cut = new JMenuItem();
168 JMenuItem copy = new JMenuItem();
170 JMenuItem upperCase = new JMenuItem();
172 JMenuItem lowerCase = new JMenuItem();
174 JMenuItem toggle = new JMenuItem();
176 JMenu pdbMenu = new JMenu();
178 JMenuItem pdbFromFile = new JMenuItem();
180 // JBPNote: Commented these out - Should add these services via the web
181 // services menu system.
182 // JMenuItem ContraFold = new JMenuItem();
184 // JMenuItem RNAFold = new JMenuItem();
186 JMenuItem enterPDB = new JMenuItem();
188 JMenuItem discoverPDB = new JMenuItem();
190 JMenu outputMenu = new JMenu();
192 JMenu seqShowAnnotationsMenu = new JMenu();
194 JMenu seqHideAnnotationsMenu = new JMenu();
196 JMenuItem seqAddReferenceAnnotations = new JMenuItem();
198 JMenu groupShowAnnotationsMenu = new JMenu();
200 JMenu groupHideAnnotationsMenu = new JMenu();
202 JMenuItem groupAddReferenceAnnotations = new JMenuItem();
204 JMenuItem sequenceFeature = new JMenuItem();
206 JMenuItem textColour = new JMenuItem();
208 JMenu jMenu1 = new JMenu();
210 JMenu structureMenu = new JMenu();
212 JMenu viewStructureMenu = new JMenu();
214 // JMenu colStructureMenu = new JMenu();
215 JMenuItem editSequence = new JMenuItem();
217 // JMenuItem annotationMenuItem = new JMenuItem();
219 JMenu groupLinksMenu;
222 * Creates a new PopupMenu object.
229 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
231 this(ap, seq, links, null);
241 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
242 Vector links, Vector groupLinks)
244 // /////////////////////////////////////////////////////////
245 // If this is activated from the sequence panel, the user may want to
246 // edit or annotate a particular residue. Therefore display the residue menu
248 // If from the IDPanel, we must display the sequence menu
249 // ////////////////////////////////////////////////////////
253 ButtonGroup colours = new ButtonGroup();
254 colours.add(noColourmenuItem);
255 colours.add(clustalColour);
256 colours.add(zappoColour);
257 colours.add(taylorColour);
258 colours.add(hydrophobicityColour);
259 colours.add(helixColour);
260 colours.add(strandColour);
261 colours.add(turnColour);
262 colours.add(buriedColour);
263 colours.add(abovePIDColour);
264 colours.add(userDefinedColour);
265 colours.add(PIDColour);
266 colours.add(BLOSUM62Colour);
267 colours.add(purinePyrimidineColour);
268 colours.add(RNAInteractionColour);
269 // colours.add(covariationColour);
271 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
273 JMenuItem item = new JMenuItem(
274 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
276 item.addActionListener(new java.awt.event.ActionListener()
279 public void actionPerformed(ActionEvent e)
281 outputText_actionPerformed(e);
285 outputMenu.add(item);
289 * Build menus for annotation types that may be shown or hidden, and for
290 * 'reference annotations' that may be added to the alignment. First for the
291 * currently selected sequence (if there is one):
293 final List<SequenceI> selectedSequence = (seq == null ? Collections
294 .<SequenceI> emptyList() : Arrays.asList(seq));
295 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
296 seqHideAnnotationsMenu, selectedSequence);
297 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
301 * And repeat for the current selection group (if there is one):
303 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
304 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
306 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
307 groupHideAnnotationsMenu, selectedGroup);
308 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
314 } catch (Exception e)
322 sequenceMenu.setText(sequence.getName());
324 if (seq.getDatasetSequence().getPDBId() != null
325 && seq.getDatasetSequence().getPDBId().size() > 0)
327 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
330 while (e.hasMoreElements())
332 final PDBEntry pdb = (PDBEntry) e.nextElement();
334 menuItem = new JMenuItem();
335 menuItem.setText(pdb.getId());
336 menuItem.addActionListener(new ActionListener()
339 public void actionPerformed(ActionEvent e)
341 // TODO re JAL-860: optionally open dialog or provide a menu entry
342 // allowing user to open just one structure per sequence
343 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
344 // { pdb })[0], null, ap);
345 new StructureViewer(ap.getStructureSelectionManager())
347 ap.av.collateForPDB(new PDBEntry[]
348 { pdb })[0], null, ap);
351 viewStructureMenu.add(menuItem);
354 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
355 * menuItem.addActionListener(new java.awt.event.ActionListener() {
356 * public void actionPerformed(ActionEvent e) {
357 * colourByStructure(pdb.getId()); } });
358 * colStructureMenu.add(menuItem);
364 if (ap.av.getAlignment().isNucleotide() == false)
366 structureMenu.remove(viewStructureMenu);
368 // structureMenu.remove(colStructureMenu);
371 if (ap.av.getAlignment().isNucleotide() == true)
373 AlignmentAnnotation[] aa = ap.av.getAlignment()
374 .getAlignmentAnnotation();
375 for (int i = 0; i < aa.length; i++)
377 if (aa[i].getRNAStruc() != null)
379 final String rnastruc = aa[i].getRNAStruc();
380 final String structureLine = aa[i].label;
381 menuItem = new JMenuItem();
382 menuItem.setText(MessageManager.formatMessage(
383 "label.2d_rna_structure_line", new String[]
385 menuItem.addActionListener(new java.awt.event.ActionListener()
388 public void actionPerformed(ActionEvent e)
390 // System.out.println("1:"+structureLine);
391 System.out.println("1:sname" + seq.getName());
392 System.out.println("2:seq" + seq);
394 // System.out.println("3:"+seq.getSequenceAsString());
395 System.out.println("3:strucseq" + rnastruc);
396 // System.out.println("4:struc"+seq.getRNA());
397 System.out.println("5:name" + seq.getName());
398 System.out.println("6:ap" + ap);
399 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
400 rnastruc, seq.getName(), ap);
401 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
402 // seq.getName(), ap);
403 System.out.println("end");
406 viewStructureMenu.add(menuItem);
410 // SequenceFeatures[] test = seq.getSequenceFeatures();
412 if (seq.getAnnotation() != null)
414 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
415 for (int i = 0; i < seqAnno.length; i++)
417 if (seqAnno[i].getRNAStruc() != null)
419 final String rnastruc = seqAnno[i].getRNAStruc();
421 // TODO: make rnastrucF a bit more nice
422 menuItem = new JMenuItem();
423 menuItem.setText(MessageManager.formatMessage(
424 "label.2d_rna_sequence_name", new String[]
426 menuItem.addActionListener(new java.awt.event.ActionListener()
429 public void actionPerformed(ActionEvent e)
431 // TODO: VARNA does'nt print gaps in the sequence
433 new AppVarna(seq.getName() + " structure", seq, seq
434 .getSequenceAsString(), rnastruc, seq.getName(),
438 viewStructureMenu.add(menuItem);
445 menuItem = new JMenuItem(
446 MessageManager.getString("action.hide_sequences"));
447 menuItem.addActionListener(new java.awt.event.ActionListener()
450 public void actionPerformed(ActionEvent e)
452 hideSequences(false);
457 if (ap.av.getSelectionGroup() != null
458 && ap.av.getSelectionGroup().getSize() > 1)
460 menuItem = new JMenuItem(MessageManager.formatMessage(
461 "label.represent_group_with", new String[]
463 menuItem.addActionListener(new java.awt.event.ActionListener()
466 public void actionPerformed(ActionEvent e)
471 sequenceMenu.add(menuItem);
474 if (ap.av.hasHiddenRows())
476 final int index = ap.av.getAlignment().findIndex(seq);
478 if (ap.av.adjustForHiddenSeqs(index)
479 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
481 menuItem = new JMenuItem(
482 MessageManager.getString("action.reveal_sequences"));
483 menuItem.addActionListener(new ActionListener()
486 public void actionPerformed(ActionEvent e)
488 ap.av.showSequence(index);
489 if (ap.overviewPanel != null)
491 ap.overviewPanel.updateOverviewImage();
499 // for the case when no sequences are even visible
500 if (ap.av.hasHiddenRows())
503 menuItem = new JMenuItem(
504 MessageManager.getString("action.reveal_all"));
505 menuItem.addActionListener(new ActionListener()
508 public void actionPerformed(ActionEvent e)
510 ap.av.showAllHiddenSeqs();
511 if (ap.overviewPanel != null)
513 ap.overviewPanel.updateOverviewImage();
523 SequenceGroup sg = ap.av.getSelectionGroup();
524 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
525 .getGroups().contains(sg) : false;
527 if (sg != null && sg.getSize() > 0)
529 groupName.setText(MessageManager.formatMessage("label.name_param",
532 groupName.setText(MessageManager
533 .getString("label.edit_name_and_description_current_group"));
535 if (sg.cs instanceof ZappoColourScheme)
537 zappoColour.setSelected(true);
539 else if (sg.cs instanceof TaylorColourScheme)
541 taylorColour.setSelected(true);
543 else if (sg.cs instanceof PIDColourScheme)
545 PIDColour.setSelected(true);
547 else if (sg.cs instanceof Blosum62ColourScheme)
549 BLOSUM62Colour.setSelected(true);
551 else if (sg.cs instanceof UserColourScheme)
553 userDefinedColour.setSelected(true);
555 else if (sg.cs instanceof HydrophobicColourScheme)
557 hydrophobicityColour.setSelected(true);
559 else if (sg.cs instanceof HelixColourScheme)
561 helixColour.setSelected(true);
563 else if (sg.cs instanceof StrandColourScheme)
565 strandColour.setSelected(true);
567 else if (sg.cs instanceof TurnColourScheme)
569 turnColour.setSelected(true);
571 else if (sg.cs instanceof BuriedColourScheme)
573 buriedColour.setSelected(true);
575 else if (sg.cs instanceof ClustalxColourScheme)
577 clustalColour.setSelected(true);
579 else if (sg.cs instanceof PurinePyrimidineColourScheme)
581 purinePyrimidineColour.setSelected(true);
585 * else if (sg.cs instanceof CovariationColourScheme) {
586 * covariationColour.setSelected(true); }
590 noColourmenuItem.setSelected(true);
593 if (sg.cs != null && sg.cs.conservationApplied())
595 conservationMenuItem.setSelected(true);
597 displayNonconserved.setSelected(sg.getShowNonconserved());
598 showText.setSelected(sg.getDisplayText());
599 showColourText.setSelected(sg.getColourText());
600 showBoxes.setSelected(sg.getDisplayBoxes());
601 // add any groupURLs to the groupURL submenu and make it visible
602 if (groupLinks != null && groupLinks.size() > 0)
604 buildGroupURLMenu(sg, groupLinks);
606 // Add a 'show all structures' for the current selection
607 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
608 SequenceI sqass = null;
609 for (SequenceI sq : ap.av.getSequenceSelection())
611 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
612 if (pes != null && pes.size() > 0)
614 reppdb.put(pes.get(0).getId(), pes.get(0));
615 for (PDBEntry pe : pes)
617 pdbe.put(pe.getId(), pe);
627 final PDBEntry[] pe = pdbe.values().toArray(
628 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
629 new PDBEntry[reppdb.size()]);
630 final JMenuItem gpdbview, rpdbview;
631 if (pdbe.size() == 1)
633 structureMenu.add(gpdbview = new JMenuItem(MessageManager
634 .formatMessage("label.view_structure_for", new String[]
635 { sqass.getDisplayId(false) })));
639 structureMenu.add(gpdbview = new JMenuItem(MessageManager
640 .formatMessage("label.view_all_structures", new String[]
641 { new Integer(pdbe.size()).toString() })));
643 gpdbview.setToolTipText(MessageManager
644 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
645 gpdbview.addActionListener(new ActionListener()
649 public void actionPerformed(ActionEvent e)
651 new StructureViewer(ap.getStructureSelectionManager())
652 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
655 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
657 structureMenu.add(rpdbview = new JMenuItem(MessageManager
659 "label.view_all_representative_structures",
661 { new Integer(reppdb.size()).toString() })));
662 rpdbview.setToolTipText(MessageManager
663 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
664 rpdbview.addActionListener(new ActionListener()
668 public void actionPerformed(ActionEvent e)
670 new StructureViewer(ap.getStructureSelectionManager())
671 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
679 groupMenu.setVisible(false);
680 editMenu.setVisible(false);
685 createGroupMenuItem.setVisible(true);
686 unGroupMenuItem.setVisible(false);
687 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
691 createGroupMenuItem.setVisible(false);
692 unGroupMenuItem.setVisible(true);
693 jMenu1.setText(MessageManager.getString("action.edit_group"));
698 sequenceMenu.setVisible(false);
699 structureMenu.setVisible(false);
702 if (links != null && links.size() > 0)
705 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
706 Vector linkset = new Vector();
707 for (int i = 0; i < links.size(); i++)
709 String link = links.elementAt(i).toString();
710 UrlLink urlLink = null;
713 urlLink = new UrlLink(link);
714 } catch (Exception foo)
716 jalview.bin.Cache.log.error("Exception for URLLink '" + link
721 if (!urlLink.isValid())
723 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
726 final String label = urlLink.getLabel();
727 if (seq != null && urlLink.isDynamic())
730 // collect matching db-refs
731 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
732 seq.getDBRef(), new String[]
733 { urlLink.getTarget() });
734 // collect id string too
735 String id = seq.getName();
736 String descr = seq.getDescription();
737 if (descr != null && descr.length() < 1)
744 for (int r = 0; r < dbr.length; r++)
746 if (id != null && dbr[r].getAccessionId().equals(id))
748 // suppress duplicate link creation for the bare sequence ID
749 // string with this link
752 // create Bare ID link for this RUL
753 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
757 for (int u = 0; u < urls.length; u += 2)
759 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
761 linkset.addElement(urls[u] + "|" + urls[u + 1]);
762 addshowLink(linkMenu, label + "|" + urls[u],
771 // create Bare ID link for this RUL
772 String[] urls = urlLink.makeUrls(id, true);
775 for (int u = 0; u < urls.length; u += 2)
777 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
779 linkset.addElement(urls[u] + "|" + urls[u + 1]);
780 addshowLink(linkMenu, label, urls[u + 1]);
785 // Create urls from description but only for URL links which are regex
787 if (descr != null && urlLink.getRegexReplace() != null)
789 // create link for this URL from description where regex matches
790 String[] urls = urlLink.makeUrls(descr, true);
793 for (int u = 0; u < urls.length; u += 2)
795 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
797 linkset.addElement(urls[u] + "|" + urls[u + 1]);
798 addshowLink(linkMenu, label, urls[u + 1]);
806 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
808 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
809 // Add a non-dynamic link
810 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
814 if (sequence != null)
816 sequenceMenu.add(linkMenu);
826 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
827 * "All" is added first, followed by a separator. Then add any annotation
828 * types associated with the current selection. Separate menus are built for
829 * the selected sequence group (if any), and the selected sequence.
831 * Some annotation rows are always rendered together - these can be identified
832 * by a common graphGroup property > -1. Only one of each group will be marked
833 * as visible (to avoid duplication of the display). For such groups we add a
834 * composite type name, e.g.
836 * IUPredWS (Long), IUPredWS (Short)
840 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
841 List<SequenceI> forSequences)
843 showMenu.removeAll();
844 hideMenu.removeAll();
846 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
847 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
848 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
850 showMenu.addSeparator();
851 hideMenu.addSeparator();
853 final AlignmentAnnotation[] annotations = ap.getAlignment()
854 .getAlignmentAnnotation();
857 * Find shown/hidden annotations types, distinguished by source (calcId),
858 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
859 * the insertion order, which is the order of the annotations on the
862 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
863 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
864 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
866 AlignmentAnnotationUtils.asList(annotations),
869 for (String calcId : hiddenTypes.keySet())
871 for (List<String> type : hiddenTypes.get(calcId))
873 addAnnotationTypeToShowHide(showMenu, forSequences,
874 calcId, type, false, true);
877 // grey out 'show annotations' if none are hidden
878 showMenu.setEnabled(!hiddenTypes.isEmpty());
880 for (String calcId : shownTypes.keySet())
882 for (List<String> type : shownTypes.get(calcId))
884 addAnnotationTypeToShowHide(hideMenu, forSequences,
885 calcId, type, false, false);
888 // grey out 'hide annotations' if none are shown
889 hideMenu.setEnabled(!shownTypes.isEmpty());
893 * Returns a list of sequences - either the current selection group (if there
894 * is one), else the specified single sequence.
899 protected List<SequenceI> getSequenceScope(SequenceI seq)
901 List<SequenceI> forSequences = null;
902 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
903 if (selectionGroup != null && selectionGroup.getSize() > 0)
905 forSequences = selectionGroup.getSequences();
909 forSequences = seq == null ? Collections.<SequenceI> emptyList()
910 : Arrays.asList(seq);
916 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
919 * @param showOrHideMenu
921 * @param forSequences
922 * the sequences whose annotations may be shown or hidden
927 * if true this is a special label meaning 'All'
928 * @param actionIsShow
929 * if true, the select menu item action is to show the annotation
932 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
933 final List<SequenceI> forSequences, String calcId,
934 final List<String> types, final boolean allTypes,
935 final boolean actionIsShow)
937 String label = types.toString(); // [a, b, c]
938 label = label.substring(1, label.length() - 1);
939 final JMenuItem item = new JMenuItem(label);
940 item.setToolTipText(calcId);
941 item.addActionListener(new java.awt.event.ActionListener()
944 public void actionPerformed(ActionEvent e)
946 showHideAnnotation_actionPerformed(types, forSequences, allTypes,
950 showOrHideMenu.add(item);
954 * Action on selecting a list of annotation type (or the 'all types' values)
955 * to show or hide for the specified sequences.
958 * @param forSequences
962 protected void showHideAnnotation_actionPerformed(
963 Collection<String> types, List<SequenceI> forSequences,
964 boolean anyType, boolean doShow)
966 for (AlignmentAnnotation aa : ap.getAlignment()
967 .getAlignmentAnnotation())
969 if (anyType || types.contains(aa.label))
971 if ((aa.sequenceRef != null)
972 && forSequences.contains(aa.sequenceRef))
981 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
984 // TODO: usability: thread off the generation of group url content so root
986 // sequence only URLs
987 // ID/regex match URLs
988 groupLinksMenu = new JMenu(
989 MessageManager.getString("action.group_link"));
990 JMenu[] linkMenus = new JMenu[]
991 { null, new JMenu(MessageManager.getString("action.ids")),
992 new JMenu(MessageManager.getString("action.sequences")),
993 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1000 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1001 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1002 Hashtable commonDbrefs = new Hashtable();
1003 for (int sq = 0; sq < seqs.length; sq++)
1006 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1007 .findPosition(sg.getEndRes());
1008 // just collect ids from dataset sequence
1009 // TODO: check if IDs collected from selecton group intersects with the
1010 // current selection, too
1011 SequenceI sqi = seqs[sq];
1012 while (sqi.getDatasetSequence() != null)
1014 sqi = sqi.getDatasetSequence();
1016 DBRefEntry[] dbr = sqi.getDBRef();
1017 if (dbr != null && dbr.length > 0)
1019 for (int d = 0; d < dbr.length; d++)
1021 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1022 Object[] sarray = (Object[]) commonDbrefs.get(src);
1025 sarray = new Object[2];
1026 sarray[0] = new int[]
1028 sarray[1] = new String[seqs.length];
1030 commonDbrefs.put(src, sarray);
1033 if (((String[]) sarray[1])[sq] == null)
1035 if (!dbr[d].hasMap()
1036 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1038 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1039 ((int[]) sarray[0])[0]++;
1045 // now create group links for all distinct ID/sequence sets.
1046 boolean addMenu = false; // indicates if there are any group links to give
1048 for (int i = 0; i < groupLinks.size(); i++)
1050 String link = groupLinks.elementAt(i).toString();
1051 GroupUrlLink urlLink = null;
1054 urlLink = new GroupUrlLink(link);
1055 } catch (Exception foo)
1057 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1062 if (!urlLink.isValid())
1064 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1067 final String label = urlLink.getLabel();
1068 boolean usingNames = false;
1069 // Now see which parts of the group apply for this URL
1070 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1071 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1072 String[] seqstr, ids; // input to makeUrl
1075 int numinput = ((int[]) idset[0])[0];
1076 String[] allids = ((String[]) idset[1]);
1077 seqstr = new String[numinput];
1078 ids = new String[numinput];
1079 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1081 if (allids[sq] != null)
1083 ids[idcount] = allids[sq];
1084 seqstr[idcount++] = idandseqs[1][sq];
1090 // just use the id/seq set
1091 seqstr = idandseqs[1];
1095 // and try and make the groupURL!
1097 Object[] urlset = null;
1100 urlset = urlLink.makeUrlStubs(ids, seqstr,
1101 "FromJalview" + System.currentTimeMillis(), false);
1102 } catch (UrlStringTooLongException e)
1107 int type = urlLink.getGroupURLType() & 3;
1108 // System.out.println(urlLink.getGroupURLType()
1109 // +" "+((String[])urlset[3])[0]);
1110 // first two bits ofurlLink type bitfield are sequenceids and sequences
1111 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1112 addshowLink(linkMenus[type], label
1113 + (((type & 1) == 1) ? ("("
1114 + (usingNames ? "Names" : ltarget) + ")") : ""),
1121 groupLinksMenu = new JMenu(
1122 MessageManager.getString("action.group_link"));
1123 for (int m = 0; m < linkMenus.length; m++)
1125 if (linkMenus[m] != null
1126 && linkMenus[m].getMenuComponentCount() > 0)
1128 groupLinksMenu.add(linkMenus[m]);
1132 groupMenu.add(groupLinksMenu);
1137 * add a show URL menu item to the given linkMenu
1141 * - menu label string
1145 private void addshowLink(JMenu linkMenu, String label, final String url)
1147 JMenuItem item = new JMenuItem(label);
1148 item.setToolTipText(MessageManager.formatMessage(
1149 "label.open_url_param", new String[]
1151 item.addActionListener(new java.awt.event.ActionListener()
1154 public void actionPerformed(ActionEvent e)
1156 new Thread(new Runnable()
1173 * add a late bound groupURL item to the given linkMenu
1177 * - menu label string
1178 * @param urlgenerator
1179 * GroupURLLink used to generate URL
1181 * Object array returned from the makeUrlStubs function.
1183 private void addshowLink(JMenu linkMenu, String label,
1184 final GroupUrlLink urlgenerator, final Object[] urlstub)
1186 JMenuItem item = new JMenuItem(label);
1187 item.setToolTipText(MessageManager.formatMessage(
1188 "label.open_url_seqs_param",
1190 { urlgenerator.getUrl_prefix(),
1191 urlgenerator.getNumberInvolved(urlstub) }));
1192 // TODO: put in info about what is being sent.
1193 item.addActionListener(new java.awt.event.ActionListener()
1196 public void actionPerformed(ActionEvent e)
1198 new Thread(new Runnable()
1206 showLink(urlgenerator.constructFrom(urlstub));
1207 } catch (UrlStringTooLongException e)
1225 private void jbInit() throws Exception
1227 groupMenu.setText(MessageManager.getString("label.group"));
1228 groupMenu.setText(MessageManager.getString("label.selection"));
1229 groupName.setText(MessageManager.getString("label.name"));
1230 groupName.addActionListener(new java.awt.event.ActionListener()
1233 public void actionPerformed(ActionEvent e)
1235 groupName_actionPerformed();
1238 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1239 sequenceName.setText(MessageManager
1240 .getString("label.edit_name_description"));
1241 sequenceName.addActionListener(new java.awt.event.ActionListener()
1244 public void actionPerformed(ActionEvent e)
1246 sequenceName_actionPerformed();
1249 chooseAnnotations.setText(MessageManager
1250 .getString("label.choose_annotations") + "...");
1251 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1254 public void actionPerformed(ActionEvent e)
1256 chooseAnnotations_actionPerformed(e);
1259 sequenceDetails.setText(MessageManager
1260 .getString("label.sequence_details") + "...");
1261 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1264 public void actionPerformed(ActionEvent e)
1266 sequenceDetails_actionPerformed();
1269 sequenceSelDetails.setText(MessageManager
1270 .getString("label.sequence_details") + "...");
1272 .addActionListener(new java.awt.event.ActionListener()
1275 public void actionPerformed(ActionEvent e)
1277 sequenceSelectionDetails_actionPerformed();
1280 PIDColour.setFocusPainted(false);
1282 .setText(MessageManager.getString("action.remove_group"));
1283 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1286 public void actionPerformed(ActionEvent e)
1288 unGroupMenuItem_actionPerformed();
1291 createGroupMenuItem.setText(MessageManager
1292 .getString("action.create_group"));
1294 .addActionListener(new java.awt.event.ActionListener()
1297 public void actionPerformed(ActionEvent e)
1299 createGroupMenuItem_actionPerformed();
1303 outline.setText(MessageManager.getString("action.border_colour"));
1304 outline.addActionListener(new java.awt.event.ActionListener()
1307 public void actionPerformed(ActionEvent e)
1309 outline_actionPerformed();
1313 .setText(MessageManager.getString("label.nucleotide"));
1314 nucleotideMenuItem.addActionListener(new ActionListener()
1317 public void actionPerformed(ActionEvent e)
1319 nucleotideMenuItem_actionPerformed();
1322 colourMenu.setText(MessageManager.getString("label.group_colour"));
1323 showBoxes.setText(MessageManager.getString("action.boxes"));
1324 showBoxes.setState(true);
1325 showBoxes.addActionListener(new ActionListener()
1328 public void actionPerformed(ActionEvent e)
1330 showBoxes_actionPerformed();
1333 showText.setText(MessageManager.getString("action.text"));
1334 showText.setState(true);
1335 showText.addActionListener(new ActionListener()
1338 public void actionPerformed(ActionEvent e)
1340 showText_actionPerformed();
1343 showColourText.setText(MessageManager.getString("label.colour_text"));
1344 showColourText.addActionListener(new ActionListener()
1347 public void actionPerformed(ActionEvent e)
1349 showColourText_actionPerformed();
1352 displayNonconserved.setText(MessageManager
1353 .getString("label.show_non_conversed"));
1354 displayNonconserved.setState(true);
1355 displayNonconserved.addActionListener(new ActionListener()
1358 public void actionPerformed(ActionEvent e)
1360 showNonconserved_actionPerformed();
1363 editMenu.setText(MessageManager.getString("action.edit"));
1364 cut.setText(MessageManager.getString("action.cut"));
1365 cut.addActionListener(new ActionListener()
1368 public void actionPerformed(ActionEvent e)
1370 cut_actionPerformed();
1373 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1374 upperCase.addActionListener(new ActionListener()
1377 public void actionPerformed(ActionEvent e)
1382 copy.setText(MessageManager.getString("action.copy"));
1383 copy.addActionListener(new ActionListener()
1386 public void actionPerformed(ActionEvent e)
1388 copy_actionPerformed();
1391 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1392 lowerCase.addActionListener(new ActionListener()
1395 public void actionPerformed(ActionEvent e)
1400 toggle.setText(MessageManager.getString("label.toggle_case"));
1401 toggle.addActionListener(new ActionListener()
1404 public void actionPerformed(ActionEvent e)
1409 pdbMenu.setText(MessageManager
1410 .getString("label.associate_structure_with_sequence"));
1411 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1412 pdbFromFile.addActionListener(new ActionListener()
1415 public void actionPerformed(ActionEvent e)
1417 pdbFromFile_actionPerformed();
1420 // RNAFold.setText("From RNA Fold with predict2D");
1421 // RNAFold.addActionListener(new ActionListener()
1423 // public void actionPerformed(ActionEvent e)
1426 // RNAFold_actionPerformed();
1427 // } catch (Exception e1) {
1428 // // TODO Auto-generated catch block
1429 // e1.printStackTrace();
1433 // ContraFold.setText("From Contra Fold with predict2D");
1434 // ContraFold.addActionListener(new ActionListener()
1436 // public void actionPerformed(ActionEvent e)
1439 // ContraFold_actionPerformed();
1440 // } catch (Exception e1) {
1441 // // TODO Auto-generated catch block
1442 // e1.printStackTrace();
1446 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1447 enterPDB.addActionListener(new ActionListener()
1450 public void actionPerformed(ActionEvent e)
1452 enterPDB_actionPerformed();
1455 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1456 discoverPDB.addActionListener(new ActionListener()
1459 public void actionPerformed(ActionEvent e)
1461 discoverPDB_actionPerformed();
1464 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1466 seqShowAnnotationsMenu.setText(MessageManager
1467 .getString("label.show_annotations"));
1468 seqHideAnnotationsMenu.setText(MessageManager
1469 .getString("label.hide_annotations"));
1470 groupShowAnnotationsMenu.setText(MessageManager
1471 .getString("label.show_annotations"));
1472 groupHideAnnotationsMenu.setText(MessageManager
1473 .getString("label.hide_annotations"));
1474 sequenceFeature.setText(MessageManager
1475 .getString("label.create_sequence_feature"));
1476 sequenceFeature.addActionListener(new ActionListener()
1479 public void actionPerformed(ActionEvent e)
1481 sequenceFeature_actionPerformed();
1484 textColour.setText(MessageManager.getString("label.text_colour"));
1485 textColour.addActionListener(new ActionListener()
1488 public void actionPerformed(ActionEvent e)
1490 textColour_actionPerformed();
1493 jMenu1.setText(MessageManager.getString("label.group"));
1494 structureMenu.setText(MessageManager.getString("label.structure"));
1495 viewStructureMenu.setText(MessageManager
1496 .getString("label.view_structure"));
1497 // colStructureMenu.setText("Colour By Structure");
1498 editSequence.setText(MessageManager.getString("label.edit_sequence")
1500 editSequence.addActionListener(new ActionListener()
1503 public void actionPerformed(ActionEvent actionEvent)
1505 editSequence_actionPerformed(actionEvent);
1510 * annotationMenuItem.setText("By Annotation");
1511 * annotationMenuItem.addActionListener(new ActionListener() { public void
1512 * actionPerformed(ActionEvent actionEvent) {
1513 * annotationMenuItem_actionPerformed(actionEvent); } });
1515 groupMenu.add(sequenceSelDetails);
1518 this.add(structureMenu);
1519 // annotations configuration panel suppressed for now
1520 // groupMenu.add(chooseAnnotations);
1523 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1524 * (if a selection group is in force).
1526 sequenceMenu.add(seqShowAnnotationsMenu);
1527 sequenceMenu.add(seqHideAnnotationsMenu);
1528 sequenceMenu.add(seqAddReferenceAnnotations);
1529 groupMenu.add(groupShowAnnotationsMenu);
1530 groupMenu.add(groupHideAnnotationsMenu);
1531 groupMenu.add(groupAddReferenceAnnotations);
1532 groupMenu.add(editMenu);
1533 groupMenu.add(outputMenu);
1534 groupMenu.add(sequenceFeature);
1535 groupMenu.add(createGroupMenuItem);
1536 groupMenu.add(unGroupMenuItem);
1537 groupMenu.add(jMenu1);
1538 sequenceMenu.add(sequenceName);
1539 sequenceMenu.add(sequenceDetails);
1540 colourMenu.add(textColour);
1541 colourMenu.add(noColourmenuItem);
1542 colourMenu.add(clustalColour);
1543 colourMenu.add(BLOSUM62Colour);
1544 colourMenu.add(PIDColour);
1545 colourMenu.add(zappoColour);
1546 colourMenu.add(taylorColour);
1547 colourMenu.add(hydrophobicityColour);
1548 colourMenu.add(helixColour);
1549 colourMenu.add(strandColour);
1550 colourMenu.add(turnColour);
1551 colourMenu.add(buriedColour);
1552 colourMenu.add(nucleotideMenuItem);
1553 if (ap.getAlignment().isNucleotide())
1555 // JBPNote - commented since the colourscheme isn't functional
1556 // colourMenu.add(RNAInteractionColour);
1557 colourMenu.add(purinePyrimidineColour);
1559 // colourMenu.add(covariationColour);
1560 colourMenu.add(userDefinedColour);
1562 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1564 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1565 .getUserColourSchemes().keys();
1567 while (userColours.hasMoreElements())
1569 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1570 item.addActionListener(new ActionListener()
1573 public void actionPerformed(ActionEvent evt)
1575 userDefinedColour_actionPerformed(evt);
1578 colourMenu.add(item);
1582 colourMenu.addSeparator();
1583 colourMenu.add(abovePIDColour);
1584 colourMenu.add(conservationMenuItem);
1585 // colourMenu.add(annotationMenuItem);
1588 editMenu.add(editSequence);
1589 editMenu.add(upperCase);
1590 editMenu.add(lowerCase);
1591 editMenu.add(toggle);
1592 pdbMenu.add(pdbFromFile);
1593 // JBPNote: These shouldn't be added here - should appear in a generic
1594 // 'apply web service to this sequence menu'
1595 // pdbMenu.add(RNAFold);
1596 // pdbMenu.add(ContraFold);
1597 pdbMenu.add(enterPDB);
1598 pdbMenu.add(discoverPDB);
1599 jMenu1.add(groupName);
1600 jMenu1.add(colourMenu);
1601 jMenu1.add(showBoxes);
1602 jMenu1.add(showText);
1603 jMenu1.add(showColourText);
1604 jMenu1.add(outline);
1605 jMenu1.add(displayNonconserved);
1606 structureMenu.add(pdbMenu);
1607 structureMenu.add(viewStructureMenu);
1608 // structureMenu.add(colStructureMenu);
1609 noColourmenuItem.setText(MessageManager.getString("label.none"));
1610 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1613 public void actionPerformed(ActionEvent e)
1615 noColourmenuItem_actionPerformed();
1619 clustalColour.setText(MessageManager
1620 .getString("label.clustalx_colours"));
1621 clustalColour.addActionListener(new java.awt.event.ActionListener()
1624 public void actionPerformed(ActionEvent e)
1626 clustalColour_actionPerformed();
1629 zappoColour.setText(MessageManager.getString("label.zappo"));
1630 zappoColour.addActionListener(new java.awt.event.ActionListener()
1633 public void actionPerformed(ActionEvent e)
1635 zappoColour_actionPerformed();
1638 taylorColour.setText(MessageManager.getString("label.taylor"));
1639 taylorColour.addActionListener(new java.awt.event.ActionListener()
1642 public void actionPerformed(ActionEvent e)
1644 taylorColour_actionPerformed();
1647 hydrophobicityColour.setText(MessageManager
1648 .getString("label.hydrophobicity"));
1649 hydrophobicityColour
1650 .addActionListener(new java.awt.event.ActionListener()
1653 public void actionPerformed(ActionEvent e)
1655 hydrophobicityColour_actionPerformed();
1658 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1659 helixColour.addActionListener(new java.awt.event.ActionListener()
1662 public void actionPerformed(ActionEvent e)
1664 helixColour_actionPerformed();
1667 strandColour.setText(MessageManager
1668 .getString("label.strand_propensity"));
1669 strandColour.addActionListener(new java.awt.event.ActionListener()
1672 public void actionPerformed(ActionEvent e)
1674 strandColour_actionPerformed();
1677 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1678 turnColour.addActionListener(new java.awt.event.ActionListener()
1681 public void actionPerformed(ActionEvent e)
1683 turnColour_actionPerformed();
1686 buriedColour.setText(MessageManager.getString("label.buried_index"));
1687 buriedColour.addActionListener(new java.awt.event.ActionListener()
1690 public void actionPerformed(ActionEvent e)
1692 buriedColour_actionPerformed();
1695 abovePIDColour.setText(MessageManager
1696 .getString("label.above_identity_percentage"));
1697 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1700 public void actionPerformed(ActionEvent e)
1702 abovePIDColour_actionPerformed();
1705 userDefinedColour.setText(MessageManager
1706 .getString("action.user_defined"));
1707 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1710 public void actionPerformed(ActionEvent e)
1712 userDefinedColour_actionPerformed(e);
1716 .setText(MessageManager.getString("label.percentage_identity"));
1717 PIDColour.addActionListener(new java.awt.event.ActionListener()
1720 public void actionPerformed(ActionEvent e)
1722 PIDColour_actionPerformed();
1725 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1726 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1729 public void actionPerformed(ActionEvent e)
1731 BLOSUM62Colour_actionPerformed();
1734 purinePyrimidineColour.setText(MessageManager
1735 .getString("label.purine_pyrimidine"));
1736 purinePyrimidineColour
1737 .addActionListener(new java.awt.event.ActionListener()
1740 public void actionPerformed(ActionEvent e)
1742 purinePyrimidineColour_actionPerformed();
1747 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1748 * public void actionPerformed(ActionEvent e) {
1749 * covariationColour_actionPerformed(); } });
1752 conservationMenuItem.setText(MessageManager
1753 .getString("label.conservation"));
1754 conservationMenuItem
1755 .addActionListener(new java.awt.event.ActionListener()
1758 public void actionPerformed(ActionEvent e)
1760 conservationMenuItem_actionPerformed();
1766 * Check for any annotations on the underlying dataset sequences (for the
1767 * current selection group) which are not on the alignment annotations for the
1768 * sequence. If any are found, enable the option to add them to the alignment.
1769 * The criteria for 'on the alignment' is finding an alignment annotation on
1770 * the sequence, that matches on calcId and label. A tooltip is also
1771 * constructed that displays the source (calcId) and type (label) of the
1772 * annotations that can be added.
1775 * @param forSequences
1777 protected void configureReferenceAnnotationsMenu(
1778 JMenuItem menuItem, List<SequenceI> forSequences)
1780 menuItem.setText(MessageManager
1781 .getString("label.add_reference_annotations"));
1782 menuItem.setEnabled(false);
1783 if (forSequences == null)
1789 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1790 * Using TreeMap means calcIds are shown in alphabetical order.
1792 Map<String, String> tipEntries = new TreeMap<String, String>();
1793 StringBuilder tooltip = new StringBuilder(64);
1794 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1797 * For each sequence selected in the alignment, make a list of any
1798 * annotations on the underlying dataset sequence which are not already on
1799 * the sequence in the alignment.
1801 * Build a map of { alignmentSequence, <List of annotations to add> }
1803 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1804 for (SequenceI seq : forSequences)
1806 SequenceI dataset = seq.getDatasetSequence();
1807 if (dataset == null)
1811 AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
1812 if (datasetAnnotations == null)
1816 final List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1817 for (AlignmentAnnotation dsann : datasetAnnotations)
1820 * If the sequence has no annotation that matches this one, then add
1821 * this one to the results list.
1823 if (seq.getAlignmentAnnotations(dsann.getCalcId(), dsann.label)
1827 tipEntries.put(dsann.getCalcId(), dsann.label);
1831 * Save any addable annotations for this sequence
1833 if (!result.isEmpty())
1835 candidates.put(seq, result);
1838 if (!candidates.isEmpty())
1841 * Found annotations that could be added. Enable the menu item, and
1842 * configure its tooltip and action.
1844 menuItem.setEnabled(true);
1845 for (String calcId : tipEntries.keySet())
1847 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1849 String tooltipText = JvSwingUtils.wrapTooltip(true,
1850 tooltip.toString());
1851 menuItem.setToolTipText(tooltipText);
1853 menuItem.addActionListener(new ActionListener()
1856 public void actionPerformed(ActionEvent e)
1858 addReferenceAnnotations_actionPerformed(candidates);
1865 * Add annotations to the sequences and to the alignment.
1868 * a map whose keys are sequences on the alignment, and values a list
1869 * of annotations to add to each sequence
1871 protected void addReferenceAnnotations_actionPerformed(
1872 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1875 * Add annotations at the top of the annotation, in the same order as their
1876 * related sequences.
1878 int insertPosition = 0;
1879 for (SequenceI seq : candidates.keySet())
1881 for (AlignmentAnnotation ann : candidates.get(seq))
1883 AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
1885 int endRes = ann.annotations.length;
1886 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1887 if (selectionGroup != null)
1889 startRes = selectionGroup.getStartRes();
1890 endRes = selectionGroup.getEndRes();
1892 copyAnn.restrict(startRes, endRes);
1894 // add to the sequence (sets copyAnn.datasetSequence)
1895 seq.addAlignmentAnnotation(copyAnn);
1897 copyAnn.adjustForAlignment();
1898 // add to the alignment and set visible
1899 this.ap.getAlignment().addAnnotation(copyAnn, insertPosition++);
1900 copyAnn.visible = true;
1906 protected void sequenceSelectionDetails_actionPerformed()
1908 createSequenceDetailsReport(ap.av.getSequenceSelection());
1911 protected void sequenceDetails_actionPerformed()
1913 createSequenceDetailsReport(new SequenceI[]
1917 public void createSequenceDetailsReport(SequenceI[] sequences)
1919 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1920 StringBuffer contents = new StringBuffer();
1921 for (SequenceI seq : sequences)
1923 contents.append("<p><h2>"
1926 "label.create_sequence_details_report_annotation_for",
1928 { seq.getDisplayId(true) }) + "</h2></p><p>");
1929 new SequenceAnnotationReport(null)
1930 .createSequenceAnnotationReport(
1936 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax
1938 contents.append("</p>");
1940 cap.setText("<html>" + contents.toString() + "</html>");
1942 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
1943 "label.sequece_details_for",
1944 (sequences.length == 1 ? new String[]
1945 { sequences[0].getDisplayId(true) } : new String[]
1946 { MessageManager.getString("label.selection") })), 500, 400);
1950 protected void showNonconserved_actionPerformed()
1952 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1957 * call to refresh view after settings change
1961 ap.updateAnnotation();
1962 ap.paintAlignment(true);
1964 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1973 protected void clustalColour_actionPerformed()
1975 SequenceGroup sg = getGroup();
1976 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1986 protected void zappoColour_actionPerformed()
1988 getGroup().cs = new ZappoColourScheme();
1998 protected void taylorColour_actionPerformed()
2000 getGroup().cs = new TaylorColourScheme();
2010 protected void hydrophobicityColour_actionPerformed()
2012 getGroup().cs = new HydrophobicColourScheme();
2022 protected void helixColour_actionPerformed()
2024 getGroup().cs = new HelixColourScheme();
2034 protected void strandColour_actionPerformed()
2036 getGroup().cs = new StrandColourScheme();
2046 protected void turnColour_actionPerformed()
2048 getGroup().cs = new TurnColourScheme();
2058 protected void buriedColour_actionPerformed()
2060 getGroup().cs = new BuriedColourScheme();
2070 public void nucleotideMenuItem_actionPerformed()
2072 getGroup().cs = new NucleotideColourScheme();
2076 protected void purinePyrimidineColour_actionPerformed()
2078 getGroup().cs = new PurinePyrimidineColourScheme();
2083 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2084 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2092 protected void abovePIDColour_actionPerformed()
2094 SequenceGroup sg = getGroup();
2100 if (abovePIDColour.isSelected())
2102 sg.cs.setConsensus(AAFrequency.calculate(
2103 sg.getSequences(ap.av.getHiddenRepSequences()),
2104 sg.getStartRes(), sg.getEndRes() + 1));
2106 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2109 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
2111 SliderPanel.showPIDSlider();
2114 // remove PIDColouring
2116 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
2128 protected void userDefinedColour_actionPerformed(ActionEvent e)
2130 SequenceGroup sg = getGroup();
2132 if (e.getSource().equals(userDefinedColour))
2134 new UserDefinedColours(ap, sg);
2138 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2139 .getUserColourSchemes().get(e.getActionCommand());
2147 * Open a panel where the user can choose which types of sequence annotation
2152 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2154 // todo correct way to guard against opening a duplicate panel?
2155 new AnnotationChooser(ap);
2164 protected void PIDColour_actionPerformed()
2166 SequenceGroup sg = getGroup();
2167 sg.cs = new PIDColourScheme();
2168 sg.cs.setConsensus(AAFrequency.calculate(
2169 sg.getSequences(ap.av.getHiddenRepSequences()),
2170 sg.getStartRes(), sg.getEndRes() + 1));
2180 protected void BLOSUM62Colour_actionPerformed()
2182 SequenceGroup sg = getGroup();
2184 sg.cs = new Blosum62ColourScheme();
2186 sg.cs.setConsensus(AAFrequency.calculate(
2187 sg.getSequences(ap.av.getHiddenRepSequences()),
2188 sg.getStartRes(), sg.getEndRes() + 1));
2199 protected void noColourmenuItem_actionPerformed()
2201 getGroup().cs = null;
2211 protected void conservationMenuItem_actionPerformed()
2213 SequenceGroup sg = getGroup();
2219 if (conservationMenuItem.isSelected())
2221 // JBPNote: Conservation name shouldn't be i18n translated
2222 Conservation c = new Conservation("Group",
2223 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2224 .getHiddenRepSequences()), sg.getStartRes(),
2225 sg.getEndRes() + 1);
2228 c.verdict(false, ap.av.getConsPercGaps());
2230 sg.cs.setConservation(c);
2232 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2233 SliderPanel.showConservationSlider();
2236 // remove ConservationColouring
2238 sg.cs.setConservation(null);
2244 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2246 SequenceGroup sg = getGroup();
2252 AnnotationColourGradient acg = new AnnotationColourGradient(
2253 sequence.getAnnotation()[0], null,
2254 AnnotationColourGradient.NO_THRESHOLD);
2256 acg.setPredefinedColours(true);
2268 protected void groupName_actionPerformed()
2271 SequenceGroup sg = getGroup();
2272 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2273 sg.getDescription(), " "
2274 + MessageManager.getString("label.group_name") + " ",
2275 MessageManager.getString("label.group_description") + " ",
2276 MessageManager.getString("label.edit_group_name_description"),
2284 sg.setName(dialog.getName());
2285 sg.setDescription(dialog.getDescription());
2290 * Get selection group - adding it to the alignment if necessary.
2292 * @return sequence group to operate on
2294 SequenceGroup getGroup()
2296 SequenceGroup sg = ap.av.getSelectionGroup();
2297 // this method won't add a new group if it already exists
2300 ap.av.getAlignment().addGroup(sg);
2312 void sequenceName_actionPerformed()
2314 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2315 sequence.getDescription(),
2316 " " + MessageManager.getString("label.sequence_name")
2318 MessageManager.getString("label.sequence_description") + " ",
2320 .getString("label.edit_sequence_name_description"),
2328 if (dialog.getName() != null)
2330 if (dialog.getName().indexOf(" ") > -1)
2336 .getString("label.spaces_converted_to_backslashes"),
2338 .getString("label.no_spaces_allowed_sequence_name"),
2339 JOptionPane.WARNING_MESSAGE);
2342 sequence.setName(dialog.getName().replace(' ', '_'));
2343 ap.paintAlignment(false);
2346 sequence.setDescription(dialog.getDescription());
2348 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2359 void unGroupMenuItem_actionPerformed()
2361 SequenceGroup sg = ap.av.getSelectionGroup();
2362 ap.av.getAlignment().deleteGroup(sg);
2363 ap.av.setSelectionGroup(null);
2367 void createGroupMenuItem_actionPerformed()
2369 getGroup(); // implicitly creates group - note - should apply defaults / use
2370 // standard alignment window logic for this
2380 protected void outline_actionPerformed()
2382 SequenceGroup sg = getGroup();
2383 Color col = JColorChooser.showDialog(this,
2384 MessageManager.getString("label.select_outline_colour"),
2389 sg.setOutlineColour(col);
2401 public void showBoxes_actionPerformed()
2403 getGroup().setDisplayBoxes(showBoxes.isSelected());
2413 public void showText_actionPerformed()
2415 getGroup().setDisplayText(showText.isSelected());
2425 public void showColourText_actionPerformed()
2427 getGroup().setColourText(showColourText.isSelected());
2431 public void showLink(String url)
2435 jalview.util.BrowserLauncher.openURL(url);
2436 } catch (Exception ex)
2438 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2439 MessageManager.getString("label.web_browser_not_found_unix"),
2440 MessageManager.getString("label.web_browser_not_found"),
2441 JOptionPane.WARNING_MESSAGE);
2443 ex.printStackTrace();
2447 void hideSequences(boolean representGroup)
2449 SequenceGroup sg = ap.av.getSelectionGroup();
2450 if (sg == null || sg.getSize() < 1)
2452 ap.av.hideSequence(new SequenceI[]
2457 ap.av.setSelectionGroup(null);
2461 ap.av.hideRepSequences(sequence, sg);
2466 int gsize = sg.getSize();
2469 hseqs = new SequenceI[gsize];
2472 for (int i = 0; i < gsize; i++)
2474 hseqs[index++] = sg.getSequenceAt(i);
2477 ap.av.hideSequence(hseqs);
2478 // refresh(); TODO: ? needed ?
2479 ap.av.sendSelection();
2482 public void copy_actionPerformed()
2484 ap.alignFrame.copy_actionPerformed(null);
2487 public void cut_actionPerformed()
2489 ap.alignFrame.cut_actionPerformed(null);
2492 void changeCase(ActionEvent e)
2494 Object source = e.getSource();
2495 SequenceGroup sg = ap.av.getSelectionGroup();
2499 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
2500 sg.getEndRes() + 1);
2505 if (source == toggle)
2507 description = MessageManager.getString("label.toggle_case");
2508 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2510 else if (source == upperCase)
2512 description = MessageManager.getString("label.to_upper_case");
2513 caseChange = ChangeCaseCommand.TO_UPPER;
2517 description = MessageManager.getString("label.to_lower_case");
2518 caseChange = ChangeCaseCommand.TO_LOWER;
2521 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2522 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2523 startEnd, caseChange);
2525 ap.alignFrame.addHistoryItem(caseCommand);
2527 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2533 public void outputText_actionPerformed(ActionEvent e)
2535 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2536 cap.setForInput(null);
2537 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2538 "label.alignment_output_command", new String[]
2539 { e.getActionCommand() }), 600, 500);
2541 String[] omitHidden = null;
2543 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2544 // or we simply trust the user wants
2545 // wysiwig behaviour
2547 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2551 public void pdbFromFile_actionPerformed()
2553 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2554 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2555 chooser.setFileView(new jalview.io.JalviewFileView());
2556 chooser.setDialogTitle(MessageManager.formatMessage(
2557 "label.select_pdb_file_for", new String[]
2558 { sequence.getDisplayId(false) }));
2559 chooser.setToolTipText(MessageManager.formatMessage(
2560 "label.load_pdb_file_associate_with_sequence", new String[]
2561 { sequence.getDisplayId(false) }));
2563 int value = chooser.showOpenDialog(null);
2565 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2567 String choice = chooser.getSelectedFile().getPath();
2568 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2569 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2570 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2576 // JBNote: commented out - these won't be instantiated here...!
2577 // public void RNAFold_actionPerformed() throws Exception
2579 // Predict2D P2D = new Predict2D();
2580 // P2D.getStructure2DFromRNAFold("toto");
2583 // public void ContraFold_actionPerformed() throws Exception
2585 // Predict2D P2D = new Predict2D();
2586 // P2D.getStructure2DFromContraFold("toto");
2588 public void enterPDB_actionPerformed()
2590 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2591 MessageManager.getString("label.enter_pdb_id"),
2592 MessageManager.getString("label.enter_pdb_id"),
2593 JOptionPane.QUESTION_MESSAGE);
2595 if (id != null && id.length() > 0)
2597 PDBEntry entry = new PDBEntry();
2598 entry.setId(id.toUpperCase());
2599 sequence.getDatasetSequence().addPDBId(entry);
2603 public void discoverPDB_actionPerformed()
2606 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2608 : ap.av.getSequenceSelection());
2609 Thread discpdb = new Thread(new Runnable()
2615 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2616 .fetchDBRefs(false);
2623 public void sequenceFeature_actionPerformed()
2625 SequenceGroup sg = ap.av.getSelectionGroup();
2631 int rsize = 0, gSize = sg.getSize();
2632 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2633 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2635 for (int i = 0; i < gSize; i++)
2637 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2638 int end = sg.findEndRes(sg.getSequenceAt(i));
2641 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2642 features[rsize] = new SequenceFeature(null, null, null, start, end,
2647 rseqs = new SequenceI[rsize];
2648 tfeatures = new SequenceFeature[rsize];
2649 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2650 System.arraycopy(features, 0, tfeatures, 0, rsize);
2651 features = tfeatures;
2653 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2654 features, true, ap))
2656 ap.alignFrame.setShowSeqFeatures(true);
2657 ap.highlightSearchResults(null);
2661 public void textColour_actionPerformed()
2663 SequenceGroup sg = getGroup();
2666 new TextColourChooser().chooseColour(ap, sg);
2670 public void colourByStructure(String pdbid)
2672 Annotation[] anots = ap.av.getStructureSelectionManager()
2673 .colourSequenceFromStructure(sequence, pdbid);
2675 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2676 "Coloured by " + pdbid, anots);
2678 ap.av.getAlignment().addAnnotation(an);
2679 an.createSequenceMapping(sequence, 0, true);
2680 // an.adjustForAlignment();
2681 ap.av.getAlignment().setAnnotationIndex(an, 0);
2683 ap.adjustAnnotationHeight();
2685 sequence.addAlignmentAnnotation(an);
2689 public void editSequence_actionPerformed(ActionEvent actionEvent)
2691 SequenceGroup sg = ap.av.getSelectionGroup();
2695 if (sequence == null)
2697 sequence = sg.getSequenceAt(0);
2700 EditNameDialog dialog = new EditNameDialog(
2701 sequence.getSequenceAsString(sg.getStartRes(),
2702 sg.getEndRes() + 1), null,
2703 MessageManager.getString("label.edit_sequence"), null,
2704 MessageManager.getString("label.edit_sequence"),
2709 EditCommand editCommand = new EditCommand(
2710 MessageManager.getString("label.edit_sequences"),
2711 EditCommand.REPLACE, dialog.getName().replace(' ',
2712 ap.av.getGapCharacter()),
2713 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2714 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2716 ap.alignFrame.addHistoryItem(editCommand);
2718 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()