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.Conservation;
25 import jalview.commands.ChangeCaseCommand;
26 import jalview.commands.EditCommand;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.Annotation;
29 import jalview.datamodel.DBRefEntry;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceFeature;
33 import jalview.datamodel.SequenceGroup;
34 import jalview.datamodel.SequenceI;
35 import jalview.io.FormatAdapter;
36 import jalview.io.SequenceAnnotationReport;
37 import jalview.renderer.AnnotationRenderer;
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.BitSet;
64 import java.util.Collection;
65 import java.util.HashMap;
66 import java.util.Hashtable;
67 import java.util.List;
69 import java.util.Vector;
71 import javax.swing.ButtonGroup;
72 import javax.swing.JCheckBoxMenuItem;
73 import javax.swing.JColorChooser;
74 import javax.swing.JMenu;
75 import javax.swing.JMenuItem;
76 import javax.swing.JOptionPane;
77 import javax.swing.JPopupMenu;
78 import javax.swing.JRadioButtonMenuItem;
84 * @version $Revision: 1.118 $
86 public class PopupMenu extends JPopupMenu
88 private static final String ALL_ANNOTATIONS = "All";
90 private static final String COMMA = ",";
92 JMenu groupMenu = new JMenu();
94 JMenuItem groupName = new JMenuItem();
96 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
98 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
100 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
102 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
112 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
114 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
116 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
118 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
124 // protected JRadioButtonMenuItem covariationColour = new
125 // JRadioButtonMenuItem();
127 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
129 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
133 JMenu sequenceMenu = new JMenu();
135 JMenuItem sequenceName = new JMenuItem();
137 JMenuItem sequenceDetails = new JMenuItem();
139 JMenuItem sequenceSelDetails = new JMenuItem();
141 JMenuItem chooseAnnotations = new JMenuItem();
145 JMenuItem createGroupMenuItem = new JMenuItem();
147 JMenuItem unGroupMenuItem = new JMenuItem();
149 JMenuItem outline = new JMenuItem();
151 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
153 JMenu colourMenu = new JMenu();
155 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
157 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
159 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
163 JMenu editMenu = new JMenu();
165 JMenuItem cut = new JMenuItem();
167 JMenuItem copy = new JMenuItem();
169 JMenuItem upperCase = new JMenuItem();
171 JMenuItem lowerCase = new JMenuItem();
173 JMenuItem toggle = new JMenuItem();
175 JMenu pdbMenu = new JMenu();
177 JMenuItem pdbFromFile = new JMenuItem();
179 // JBPNote: Commented these out - Should add these services via the web
180 // services menu system.
181 // JMenuItem ContraFold = new JMenuItem();
183 // JMenuItem RNAFold = new JMenuItem();
185 JMenuItem enterPDB = new JMenuItem();
187 JMenuItem discoverPDB = new JMenuItem();
189 JMenu outputMenu = new JMenu();
191 JMenu showAnnotationsMenu = new JMenu();
193 JMenu hideAnnotationsMenu = new JMenu();
195 JMenuItem addDatasequenceAnnotations = new JMenuItem();
197 JMenuItem sequenceFeature = new JMenuItem();
199 JMenuItem textColour = new JMenuItem();
201 JMenu jMenu1 = new JMenu();
203 JMenu structureMenu = new JMenu();
205 JMenu viewStructureMenu = new JMenu();
207 // JMenu colStructureMenu = new JMenu();
208 JMenuItem editSequence = new JMenuItem();
210 // JMenuItem annotationMenuItem = new JMenuItem();
212 JMenu groupLinksMenu;
215 * Creates a new PopupMenu object.
222 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
224 this(ap, seq, links, null);
234 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
235 Vector links, Vector groupLinks)
237 // /////////////////////////////////////////////////////////
238 // If this is activated from the sequence panel, the user may want to
239 // edit or annotate a particular residue. Therefore display the residue menu
241 // If from the IDPanel, we must display the sequence menu
242 // ////////////////////////////////////////////////////////
246 ButtonGroup colours = new ButtonGroup();
247 colours.add(noColourmenuItem);
248 colours.add(clustalColour);
249 colours.add(zappoColour);
250 colours.add(taylorColour);
251 colours.add(hydrophobicityColour);
252 colours.add(helixColour);
253 colours.add(strandColour);
254 colours.add(turnColour);
255 colours.add(buriedColour);
256 colours.add(abovePIDColour);
257 colours.add(userDefinedColour);
258 colours.add(PIDColour);
259 colours.add(BLOSUM62Colour);
260 colours.add(purinePyrimidineColour);
261 colours.add(RNAInteractionColour);
262 // colours.add(covariationColour);
264 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
266 JMenuItem item = new JMenuItem(
267 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
269 item.addActionListener(new java.awt.event.ActionListener()
272 public void actionPerformed(ActionEvent e)
274 outputText_actionPerformed(e);
278 outputMenu.add(item);
282 * Build menus for annotation types that may be shown or hidden.
284 buildAnnotationTypesMenus();
289 } catch (Exception e)
297 sequenceMenu.setText(sequence.getName());
299 if (seq.getDatasetSequence().getPDBId() != null
300 && seq.getDatasetSequence().getPDBId().size() > 0)
302 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
305 while (e.hasMoreElements())
307 final PDBEntry pdb = (PDBEntry) e.nextElement();
309 menuItem = new JMenuItem();
310 menuItem.setText(pdb.getId());
311 menuItem.addActionListener(new ActionListener()
314 public void actionPerformed(ActionEvent e) {
315 // TODO re JAL-860: optionally open dialog or provide a menu entry
316 // allowing user to open just one structure per sequence
317 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
318 // { pdb })[0], null, ap);
319 new StructureViewer(ap.getStructureSelectionManager())
321 ap.av.collateForPDB(new PDBEntry[]
322 { pdb })[0], null, ap);
325 viewStructureMenu.add(menuItem);
328 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
329 * menuItem.addActionListener(new java.awt.event.ActionListener() {
330 * public void actionPerformed(ActionEvent e) {
331 * colourByStructure(pdb.getId()); } });
332 * colStructureMenu.add(menuItem);
338 if (ap.av.getAlignment().isNucleotide() == false)
340 structureMenu.remove(viewStructureMenu);
342 // structureMenu.remove(colStructureMenu);
345 if (ap.av.getAlignment().isNucleotide() == true)
347 AlignmentAnnotation[] aa = ap.av.getAlignment()
348 .getAlignmentAnnotation();
349 for (int i = 0; i < aa.length; i++)
351 if (aa[i].getRNAStruc() != null)
353 final String rnastruc = aa[i].getRNAStruc();
354 final String structureLine = aa[i].label;
355 menuItem = new JMenuItem();
356 menuItem.setText(MessageManager.formatMessage(
357 "label.2d_rna_structure_line", new String[]
359 menuItem.addActionListener(new java.awt.event.ActionListener()
362 public void actionPerformed(ActionEvent e)
364 // System.out.println("1:"+structureLine);
365 System.out.println("1:sname" + seq.getName());
366 System.out.println("2:seq" + seq);
368 // System.out.println("3:"+seq.getSequenceAsString());
369 System.out.println("3:strucseq" + rnastruc);
370 // System.out.println("4:struc"+seq.getRNA());
371 System.out.println("5:name" + seq.getName());
372 System.out.println("6:ap" + ap);
373 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
374 rnastruc, seq.getName(), ap);
375 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
376 // seq.getName(), ap);
377 System.out.println("end");
380 viewStructureMenu.add(menuItem);
384 // SequenceFeatures[] test = seq.getSequenceFeatures();
386 if (seq.getAnnotation() != null)
388 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
389 for (int i = 0; i < seqAnno.length; i++)
391 if (seqAnno[i].getRNAStruc() != null)
393 final String rnastruc = seqAnno[i].getRNAStruc();
395 // TODO: make rnastrucF a bit more nice
396 menuItem = new JMenuItem();
397 menuItem.setText(MessageManager.formatMessage(
398 "label.2d_rna_sequence_name", new String[]
400 menuItem.addActionListener(new java.awt.event.ActionListener()
403 public void actionPerformed(ActionEvent e)
405 // TODO: VARNA does'nt print gaps in the sequence
407 new AppVarna(seq.getName() + " structure", seq, seq
408 .getSequenceAsString(), rnastruc, seq.getName(),
412 viewStructureMenu.add(menuItem);
419 menuItem = new JMenuItem(
420 MessageManager.getString("action.hide_sequences"));
421 menuItem.addActionListener(new java.awt.event.ActionListener()
424 public void actionPerformed(ActionEvent e)
426 hideSequences(false);
431 if (ap.av.getSelectionGroup() != null
432 && ap.av.getSelectionGroup().getSize() > 1)
434 menuItem = new JMenuItem(MessageManager.formatMessage(
435 "label.represent_group_with", new String[]
437 menuItem.addActionListener(new java.awt.event.ActionListener()
440 public void actionPerformed(ActionEvent e)
445 sequenceMenu.add(menuItem);
448 if (ap.av.hasHiddenRows())
450 final int index = ap.av.getAlignment().findIndex(seq);
452 if (ap.av.adjustForHiddenSeqs(index)
453 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
455 menuItem = new JMenuItem(
456 MessageManager.getString("action.reveal_sequences"));
457 menuItem.addActionListener(new ActionListener()
460 public void actionPerformed(ActionEvent e)
462 ap.av.showSequence(index);
463 if (ap.overviewPanel != null)
465 ap.overviewPanel.updateOverviewImage();
473 // for the case when no sequences are even visible
474 if (ap.av.hasHiddenRows())
477 menuItem = new JMenuItem(
478 MessageManager.getString("action.reveal_all"));
479 menuItem.addActionListener(new ActionListener()
482 public void actionPerformed(ActionEvent e)
484 ap.av.showAllHiddenSeqs();
485 if (ap.overviewPanel != null)
487 ap.overviewPanel.updateOverviewImage();
497 SequenceGroup sg = ap.av.getSelectionGroup();
498 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
499 .getGroups().contains(sg) : false;
501 if (sg != null && sg.getSize() > 0)
503 groupName.setText(MessageManager.formatMessage("label.name_param",
506 groupName.setText(MessageManager
507 .getString("label.edit_name_and_description_current_group"));
509 if (sg.cs instanceof ZappoColourScheme)
511 zappoColour.setSelected(true);
513 else if (sg.cs instanceof TaylorColourScheme)
515 taylorColour.setSelected(true);
517 else if (sg.cs instanceof PIDColourScheme)
519 PIDColour.setSelected(true);
521 else if (sg.cs instanceof Blosum62ColourScheme)
523 BLOSUM62Colour.setSelected(true);
525 else if (sg.cs instanceof UserColourScheme)
527 userDefinedColour.setSelected(true);
529 else if (sg.cs instanceof HydrophobicColourScheme)
531 hydrophobicityColour.setSelected(true);
533 else if (sg.cs instanceof HelixColourScheme)
535 helixColour.setSelected(true);
537 else if (sg.cs instanceof StrandColourScheme)
539 strandColour.setSelected(true);
541 else if (sg.cs instanceof TurnColourScheme)
543 turnColour.setSelected(true);
545 else if (sg.cs instanceof BuriedColourScheme)
547 buriedColour.setSelected(true);
549 else if (sg.cs instanceof ClustalxColourScheme)
551 clustalColour.setSelected(true);
553 else if (sg.cs instanceof PurinePyrimidineColourScheme)
555 purinePyrimidineColour.setSelected(true);
559 * else if (sg.cs instanceof CovariationColourScheme) {
560 * covariationColour.setSelected(true); }
564 noColourmenuItem.setSelected(true);
567 if (sg.cs != null && sg.cs.conservationApplied())
569 conservationMenuItem.setSelected(true);
571 displayNonconserved.setSelected(sg.getShowNonconserved());
572 showText.setSelected(sg.getDisplayText());
573 showColourText.setSelected(sg.getColourText());
574 showBoxes.setSelected(sg.getDisplayBoxes());
575 // add any groupURLs to the groupURL submenu and make it visible
576 if (groupLinks != null && groupLinks.size() > 0)
578 buildGroupURLMenu(sg, groupLinks);
580 // Add a 'show all structures' for the current selection
581 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
582 SequenceI sqass = null;
583 for (SequenceI sq : ap.av.getSequenceSelection())
585 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
586 if (pes != null && pes.size() > 0)
588 reppdb.put(pes.get(0).getId(), pes.get(0));
589 for (PDBEntry pe : pes)
591 pdbe.put(pe.getId(), pe);
601 final PDBEntry[] pe = pdbe.values().toArray(
602 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
603 new PDBEntry[reppdb.size()]);
604 final JMenuItem gpdbview, rpdbview;
605 if (pdbe.size() == 1)
607 structureMenu.add(gpdbview = new JMenuItem(MessageManager
608 .formatMessage("label.view_structure_for", new String[]
609 { sqass.getDisplayId(false) })));
613 structureMenu.add(gpdbview = new JMenuItem(MessageManager
614 .formatMessage("label.view_all_structures", new String[]
615 { new Integer(pdbe.size()).toString() })));
617 gpdbview.setToolTipText(MessageManager
618 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
619 gpdbview.addActionListener(new ActionListener()
623 public void actionPerformed(ActionEvent e)
625 new StructureViewer(ap.getStructureSelectionManager())
626 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
629 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
631 structureMenu.add(rpdbview = new JMenuItem(MessageManager
633 "label.view_all_representative_structures",
635 { new Integer(reppdb.size()).toString() })));
636 rpdbview.setToolTipText(MessageManager
637 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
638 rpdbview.addActionListener(new ActionListener()
642 public void actionPerformed(ActionEvent e)
644 new StructureViewer(ap.getStructureSelectionManager())
645 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
653 groupMenu.setVisible(false);
654 editMenu.setVisible(false);
659 createGroupMenuItem.setVisible(true);
660 unGroupMenuItem.setVisible(false);
661 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
665 createGroupMenuItem.setVisible(false);
666 unGroupMenuItem.setVisible(true);
667 jMenu1.setText(MessageManager.getString("action.edit_group"));
672 sequenceMenu.setVisible(false);
673 structureMenu.setVisible(false);
676 if (links != null && links.size() > 0)
679 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
680 Vector linkset = new Vector();
681 for (int i = 0; i < links.size(); i++)
683 String link = links.elementAt(i).toString();
684 UrlLink urlLink = null;
687 urlLink = new UrlLink(link);
688 } catch (Exception foo)
690 jalview.bin.Cache.log.error("Exception for URLLink '" + link
695 if (!urlLink.isValid())
697 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
700 final String label = urlLink.getLabel();
701 if (seq != null && urlLink.isDynamic())
704 // collect matching db-refs
705 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
706 seq.getDBRef(), new String[]
707 { urlLink.getTarget() });
708 // collect id string too
709 String id = seq.getName();
710 String descr = seq.getDescription();
711 if (descr != null && descr.length() < 1)
718 for (int r = 0; r < dbr.length; r++)
720 if (id != null && dbr[r].getAccessionId().equals(id))
722 // suppress duplicate link creation for the bare sequence ID
723 // string with this link
726 // create Bare ID link for this RUL
727 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
731 for (int u = 0; u < urls.length; u += 2)
733 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
735 linkset.addElement(urls[u] + "|" + urls[u + 1]);
736 addshowLink(linkMenu, label + "|" + urls[u],
745 // create Bare ID link for this RUL
746 String[] urls = urlLink.makeUrls(id, true);
749 for (int u = 0; u < urls.length; u += 2)
751 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
753 linkset.addElement(urls[u] + "|" + urls[u + 1]);
754 addshowLink(linkMenu, label, urls[u + 1]);
759 // Create urls from description but only for URL links which are regex
761 if (descr != null && urlLink.getRegexReplace() != null)
763 // create link for this URL from description where regex matches
764 String[] urls = urlLink.makeUrls(descr, true);
767 for (int u = 0; u < urls.length; u += 2)
769 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
771 linkset.addElement(urls[u] + "|" + urls[u + 1]);
772 addshowLink(linkMenu, label, urls[u + 1]);
780 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
782 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
783 // Add a non-dynamic link
784 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
788 if (sequence != null)
790 sequenceMenu.add(linkMenu);
800 * Add annotation types to a 'Show annotations' or 'Hide annotations' menu.
801 * "All" is added first, followed by a separator. Then add any annotation
802 * types associated with the current selection.
804 * Some annotation rows are always rendered together - these can be identified
805 * by a common graphGroup property > -1. Only one of each group will be marked
806 * as visible (to avoid duplication of the display). For such groups we add a
807 * composite type name, e.g.
809 * IUPredWS (Long), IUPredWS (Short)
811 protected void buildAnnotationTypesMenus()
813 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
814 if (selectionGroup == null)
816 // this menu option is only for a selection
820 showAnnotationsMenu.removeAll();
821 hideAnnotationsMenu.removeAll();
822 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
823 addAnnotationTypeToShowHide(showAnnotationsMenu, "", all, true, true);
824 addAnnotationTypeToShowHide(hideAnnotationsMenu, "", all, true, false);
825 showAnnotationsMenu.addSeparator();
826 hideAnnotationsMenu.addSeparator();
828 final AlignmentAnnotation[] annotations = ap.getAlignment()
829 .getAlignmentAnnotation();
830 BitSet visibleGraphGroups = PopupMenu
831 .getVisibleLineGraphGroups(annotations);
834 * Find shown/hidden annotations types, distinguished by source (calcId),
835 * and grouped by graphGroup.
837 Map<String, List<List<String>>> shownTypes = new HashMap<String, List<List<String>>>();
838 Map<String, List<List<String>>> hiddenTypes = new HashMap<String, List<List<String>>>();
839 PopupMenu.getAnnotationTypesForShowHide(shownTypes, hiddenTypes,
840 visibleGraphGroups, annotations, selectionGroup);
842 for (String calcId : hiddenTypes.keySet())
844 for (List<String> type : hiddenTypes.get(calcId))
846 addAnnotationTypeToShowHide(showAnnotationsMenu, calcId, type,
851 for (String calcId : shownTypes.keySet())
853 for (List<String> type : shownTypes.get(calcId))
855 addAnnotationTypeToShowHide(hideAnnotationsMenu, calcId, type,
862 * Helper method to populate lists of annotation types for the Show/Hide
863 * Annotations menus. If sequenceGroup is not null, this is restricted to
864 * annotations which are associated with sequences in the selection group.
866 * If an annotation row is currently visible, its type (label) is added (once
867 * only per type), to the shownTypes list. If it is currently hidden, it is
868 * added to the hiddenTypesList.
870 * For rows that belong to a line graph group, so are always rendered
873 * <li>Treat all rows in the group as visible, if at least one of them is</li>
874 * <li>Build a comma-separated label with all the types that belong to the
879 * a map, keyed by calcId (annotation source), whose entries are the
880 * lists of annotation types found for the calcId; each annotation
881 * type in turn may be a list (in the case of grouped annotations)
883 * a map, similar to shownTypes, but for hidden annotation types
884 * @param visibleGraphGroups
885 * a lookup keyed by graphGroup identifier
887 * the annotations on the alignment to scan
888 * @param sequenceGroup
889 * the sequence group to restrict search to
891 public static void getAnnotationTypesForShowHide(
892 Map<String, List<List<String>>> shownTypes,
893 Map<String, List<List<String>>> hiddenTypes,
894 BitSet visibleGraphGroups, AlignmentAnnotation[] annotations,
895 SequenceGroup sequenceGroup)
898 * Build a lookup, by calcId (annotation source), of all annotation types in
901 Map<String, Map<Integer, List<String>>> groupLabels = new HashMap<String, Map<Integer, List<String>>>();
903 // trackers for which calcId!label combinations we have dealt with
904 List<String> addedToShown = new ArrayList<String>();
905 List<String> addedToHidden = new ArrayList<String>();
907 for (AlignmentAnnotation aa : annotations)
910 if (sequenceGroup == null
911 || (aa.sequenceRef != null && sequenceGroup.getSequences()
912 .contains(aa.sequenceRef)))
914 String calcId = aa.getCalcId();
917 * Build a 'composite label' for types in line graph groups.
919 final List<String> labelAsList = new ArrayList<String>();
920 final String displayLabel = aa.label;
921 labelAsList.add(displayLabel);
922 if (aa.graph == AlignmentAnnotation.LINE_GRAPH
923 && aa.graphGroup > -1)
925 if (!groupLabels.containsKey(calcId))
927 groupLabels.put(calcId, new HashMap<Integer, List<String>>());
929 Map<Integer, List<String>> groupLabelsForCalcId = groupLabels
931 if (groupLabelsForCalcId.containsKey(aa.graphGroup))
933 if (!groupLabelsForCalcId.get(aa.graphGroup).contains(
936 groupLabelsForCalcId.get(aa.graphGroup).add(displayLabel);
941 groupLabelsForCalcId.put(aa.graphGroup, labelAsList);
946 * 'Simple case' - not a grouped annotation type - list of one label
950 String rememberAs = calcId + "!" + displayLabel;
951 if (aa.visible && !addedToShown.contains(rememberAs))
953 if (!shownTypes.containsKey(calcId))
955 shownTypes.put(calcId, new ArrayList<List<String>>());
957 shownTypes.get(calcId).add(labelAsList);
958 addedToShown.add(rememberAs);
962 if (!aa.visible && !addedToHidden.contains(rememberAs))
964 if (!hiddenTypes.containsKey(calcId))
966 hiddenTypes.put(calcId, new ArrayList<List<String>>());
968 hiddenTypes.get(calcId).add(labelAsList);
969 addedToHidden.add(rememberAs);
976 * finally add the 'composite group labels' to the appropriate lists,
977 * depending on whether the group is identified as visible or hidden
979 for (String calcId : groupLabels.keySet())
981 for (int group : groupLabels.get(calcId).keySet())
983 final List<String> groupLabel = groupLabels.get(calcId).get(group);
984 if (visibleGraphGroups.get(group))
986 if (!shownTypes.containsKey(calcId))
988 shownTypes.put(calcId, new ArrayList<List<String>>());
990 shownTypes.get(calcId).add(groupLabel);
994 if (!hiddenTypes.containsKey(calcId))
996 hiddenTypes.put(calcId, new ArrayList<List<String>>());
998 hiddenTypes.get(calcId).add(groupLabel);
1005 * Returns a BitSet (possibly empty) of those graphGroups for line graph
1006 * annotations, which have at least one member annotation row marked visible.
1007 * The logic is that only one row in the group is marked visible, but when it
1008 * is drawn, so are all the other rows in the same group.
1010 * This lookup set allows us to check whether rows marked not visible are in
1013 * @see AnnotationRenderer#drawComponent
1014 * @param annotations
1017 public static BitSet getVisibleLineGraphGroups(
1018 AlignmentAnnotation[] annotations)
1020 // todo move to a utility class
1021 BitSet result = new BitSet();
1022 for (AlignmentAnnotation ann : annotations)
1024 if (ann.graph == AlignmentAnnotation.LINE_GRAPH && ann.visible)
1026 int gg = ann.graphGroup;
1037 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1040 * @param showOrHideMenu
1041 * the menu to add to
1046 * if true this is a special label meaning 'All'
1047 * @param actionIsShow
1048 * if true, the select menu item action is to show the annotation
1051 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1052 String calcId, final List<String> types, final boolean allTypes,
1053 final boolean actionIsShow)
1055 String label = types.toString(); // [a, b, c]
1056 label = label.substring(1, label.length() - 1);
1057 final JMenuItem item = new JMenuItem(label);
1058 item.setToolTipText(calcId);
1059 item.addActionListener(new java.awt.event.ActionListener()
1062 public void actionPerformed(ActionEvent e)
1064 showHideAnnotation_actionPerformed(types, allTypes, actionIsShow);
1067 showOrHideMenu.add(item);
1071 * Action on selecting a list of annotation type (or the 'all types' values)
1072 * to show or hide for the selection.
1078 protected void showHideAnnotation_actionPerformed(
1079 Collection<String> types, boolean anyType, boolean doShow)
1081 for (AlignmentAnnotation aa : ap.getAlignment()
1082 .getAlignmentAnnotation())
1084 // TODO: select by calcId (source of annotation) as well as label
1085 // e.g. by refactoring of buildAnnotationTypeMenus to as
1086 // to construct the actionPerformed methods as the calcId/labels are found
1087 if (anyType || types.contains(aa.label))
1089 if ((aa.sequenceRef != null)
1090 && ap.av.getSelectionGroup().getSequences()
1091 .contains(aa.sequenceRef))
1093 aa.visible = doShow;
1100 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
1103 // TODO: usability: thread off the generation of group url content so root
1104 // menu appears asap
1105 // sequence only URLs
1106 // ID/regex match URLs
1107 groupLinksMenu = new JMenu(
1108 MessageManager.getString("action.group_link"));
1109 JMenu[] linkMenus = new JMenu[]
1110 { null, new JMenu(MessageManager.getString("action.ids")),
1111 new JMenu(MessageManager.getString("action.sequences")),
1112 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1119 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1120 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1121 Hashtable commonDbrefs = new Hashtable();
1122 for (int sq = 0; sq < seqs.length; sq++)
1125 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1126 .findPosition(sg.getEndRes());
1127 // just collect ids from dataset sequence
1128 // TODO: check if IDs collected from selecton group intersects with the
1129 // current selection, too
1130 SequenceI sqi = seqs[sq];
1131 while (sqi.getDatasetSequence() != null)
1133 sqi = sqi.getDatasetSequence();
1135 DBRefEntry[] dbr = sqi.getDBRef();
1136 if (dbr != null && dbr.length > 0)
1138 for (int d = 0; d < dbr.length; d++)
1140 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1141 Object[] sarray = (Object[]) commonDbrefs.get(src);
1144 sarray = new Object[2];
1145 sarray[0] = new int[]
1147 sarray[1] = new String[seqs.length];
1149 commonDbrefs.put(src, sarray);
1152 if (((String[]) sarray[1])[sq] == null)
1154 if (!dbr[d].hasMap()
1155 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1157 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1158 ((int[]) sarray[0])[0]++;
1164 // now create group links for all distinct ID/sequence sets.
1165 boolean addMenu = false; // indicates if there are any group links to give
1167 for (int i = 0; i < groupLinks.size(); i++)
1169 String link = groupLinks.elementAt(i).toString();
1170 GroupUrlLink urlLink = null;
1173 urlLink = new GroupUrlLink(link);
1174 } catch (Exception foo)
1176 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1181 if (!urlLink.isValid())
1183 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1186 final String label = urlLink.getLabel();
1187 boolean usingNames = false;
1188 // Now see which parts of the group apply for this URL
1189 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1190 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1191 String[] seqstr, ids; // input to makeUrl
1194 int numinput = ((int[]) idset[0])[0];
1195 String[] allids = ((String[]) idset[1]);
1196 seqstr = new String[numinput];
1197 ids = new String[numinput];
1198 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1200 if (allids[sq] != null)
1202 ids[idcount] = allids[sq];
1203 seqstr[idcount++] = idandseqs[1][sq];
1209 // just use the id/seq set
1210 seqstr = idandseqs[1];
1214 // and try and make the groupURL!
1216 Object[] urlset = null;
1219 urlset = urlLink.makeUrlStubs(ids, seqstr,
1220 "FromJalview" + System.currentTimeMillis(), false);
1221 } catch (UrlStringTooLongException e)
1226 int type = urlLink.getGroupURLType() & 3;
1227 // System.out.println(urlLink.getGroupURLType()
1228 // +" "+((String[])urlset[3])[0]);
1229 // first two bits ofurlLink type bitfield are sequenceids and sequences
1230 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1231 addshowLink(linkMenus[type], label
1232 + (((type & 1) == 1) ? ("("
1233 + (usingNames ? "Names" : ltarget) + ")") : ""),
1240 groupLinksMenu = new JMenu(
1241 MessageManager.getString("action.group_link"));
1242 for (int m = 0; m < linkMenus.length; m++)
1244 if (linkMenus[m] != null
1245 && linkMenus[m].getMenuComponentCount() > 0)
1247 groupLinksMenu.add(linkMenus[m]);
1251 groupMenu.add(groupLinksMenu);
1256 * add a show URL menu item to the given linkMenu
1260 * - menu label string
1264 private void addshowLink(JMenu linkMenu, String label, final String url)
1266 JMenuItem item = new JMenuItem(label);
1267 item.setToolTipText(MessageManager.formatMessage(
1268 "label.open_url_param", new String[]
1270 item.addActionListener(new java.awt.event.ActionListener()
1273 public void actionPerformed(ActionEvent e)
1275 new Thread(new Runnable()
1292 * add a late bound groupURL item to the given linkMenu
1296 * - menu label string
1297 * @param urlgenerator
1298 * GroupURLLink used to generate URL
1300 * Object array returned from the makeUrlStubs function.
1302 private void addshowLink(JMenu linkMenu, String label,
1303 final GroupUrlLink urlgenerator, final Object[] urlstub)
1305 JMenuItem item = new JMenuItem(label);
1306 item.setToolTipText(MessageManager.formatMessage(
1307 "label.open_url_seqs_param",
1309 { urlgenerator.getUrl_prefix(),
1310 urlgenerator.getNumberInvolved(urlstub) }));
1311 // TODO: put in info about what is being sent.
1312 item.addActionListener(new java.awt.event.ActionListener()
1315 public void actionPerformed(ActionEvent e)
1317 new Thread(new Runnable()
1325 showLink(urlgenerator.constructFrom(urlstub));
1326 } catch (UrlStringTooLongException e)
1344 private void jbInit() throws Exception
1346 groupMenu.setText(MessageManager.getString("label.group"));
1347 groupMenu.setText(MessageManager.getString("label.selection"));
1348 groupName.setText(MessageManager.getString("label.name"));
1349 groupName.addActionListener(new java.awt.event.ActionListener()
1352 public void actionPerformed(ActionEvent e)
1354 groupName_actionPerformed();
1357 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1358 sequenceName.setText(MessageManager
1359 .getString("label.edit_name_description"));
1360 sequenceName.addActionListener(new java.awt.event.ActionListener()
1363 public void actionPerformed(ActionEvent e)
1365 sequenceName_actionPerformed();
1368 chooseAnnotations.setText(MessageManager
1369 .getString("label.choose_annotations") + "...");
1370 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1373 public void actionPerformed(ActionEvent e)
1375 chooseAnnotations_actionPerformed(e);
1378 sequenceDetails.setText(MessageManager
1379 .getString("label.sequence_details") + "...");
1380 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1383 public void actionPerformed(ActionEvent e)
1385 sequenceDetails_actionPerformed();
1388 sequenceSelDetails.setText(MessageManager
1389 .getString("label.sequence_details") + "...");
1391 .addActionListener(new java.awt.event.ActionListener()
1394 public void actionPerformed(ActionEvent e)
1396 sequenceSelectionDetails_actionPerformed();
1399 PIDColour.setFocusPainted(false);
1401 .setText(MessageManager.getString("action.remove_group"));
1402 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1405 public void actionPerformed(ActionEvent e)
1407 unGroupMenuItem_actionPerformed();
1410 createGroupMenuItem.setText(MessageManager
1411 .getString("action.create_group"));
1413 .addActionListener(new java.awt.event.ActionListener()
1416 public void actionPerformed(ActionEvent e)
1418 createGroupMenuItem_actionPerformed();
1422 outline.setText(MessageManager.getString("action.border_colour"));
1423 outline.addActionListener(new java.awt.event.ActionListener()
1426 public void actionPerformed(ActionEvent e)
1428 outline_actionPerformed();
1432 .setText(MessageManager.getString("label.nucleotide"));
1433 nucleotideMenuItem.addActionListener(new ActionListener()
1436 public void actionPerformed(ActionEvent e)
1438 nucleotideMenuItem_actionPerformed();
1441 colourMenu.setText(MessageManager.getString("label.group_colour"));
1442 showBoxes.setText(MessageManager.getString("action.boxes"));
1443 showBoxes.setState(true);
1444 showBoxes.addActionListener(new ActionListener()
1447 public void actionPerformed(ActionEvent e)
1449 showBoxes_actionPerformed();
1452 showText.setText(MessageManager.getString("action.text"));
1453 showText.setState(true);
1454 showText.addActionListener(new ActionListener()
1457 public void actionPerformed(ActionEvent e)
1459 showText_actionPerformed();
1462 showColourText.setText(MessageManager.getString("label.colour_text"));
1463 showColourText.addActionListener(new ActionListener()
1466 public void actionPerformed(ActionEvent e)
1468 showColourText_actionPerformed();
1471 displayNonconserved.setText(MessageManager
1472 .getString("label.show_non_conversed"));
1473 displayNonconserved.setState(true);
1474 displayNonconserved.addActionListener(new ActionListener()
1477 public void actionPerformed(ActionEvent e)
1479 showNonconserved_actionPerformed();
1482 editMenu.setText(MessageManager.getString("action.edit"));
1483 cut.setText(MessageManager.getString("action.cut"));
1484 cut.addActionListener(new ActionListener()
1487 public void actionPerformed(ActionEvent e)
1489 cut_actionPerformed();
1492 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1493 upperCase.addActionListener(new ActionListener()
1496 public void actionPerformed(ActionEvent e)
1501 copy.setText(MessageManager.getString("action.copy"));
1502 copy.addActionListener(new ActionListener()
1505 public void actionPerformed(ActionEvent e)
1507 copy_actionPerformed();
1510 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1511 lowerCase.addActionListener(new ActionListener()
1514 public void actionPerformed(ActionEvent e)
1519 toggle.setText(MessageManager.getString("label.toggle_case"));
1520 toggle.addActionListener(new ActionListener()
1523 public void actionPerformed(ActionEvent e)
1528 pdbMenu.setText(MessageManager
1529 .getString("label.associate_structure_with_sequence"));
1530 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1531 pdbFromFile.addActionListener(new ActionListener()
1534 public void actionPerformed(ActionEvent e)
1536 pdbFromFile_actionPerformed();
1539 // RNAFold.setText("From RNA Fold with predict2D");
1540 // RNAFold.addActionListener(new ActionListener()
1542 // public void actionPerformed(ActionEvent e)
1545 // RNAFold_actionPerformed();
1546 // } catch (Exception e1) {
1547 // // TODO Auto-generated catch block
1548 // e1.printStackTrace();
1552 // ContraFold.setText("From Contra Fold with predict2D");
1553 // ContraFold.addActionListener(new ActionListener()
1555 // public void actionPerformed(ActionEvent e)
1558 // ContraFold_actionPerformed();
1559 // } catch (Exception e1) {
1560 // // TODO Auto-generated catch block
1561 // e1.printStackTrace();
1565 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1566 enterPDB.addActionListener(new ActionListener()
1569 public void actionPerformed(ActionEvent e)
1571 enterPDB_actionPerformed();
1574 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1575 discoverPDB.addActionListener(new ActionListener()
1578 public void actionPerformed(ActionEvent e)
1580 discoverPDB_actionPerformed();
1583 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1585 showAnnotationsMenu.setText(MessageManager
1586 .getString("label.show_annotations"));
1587 hideAnnotationsMenu.setText(MessageManager
1588 .getString("label.hide_annotations"));
1589 configureReferenceAnnotationsMenu();
1590 sequenceFeature.setText(MessageManager
1591 .getString("label.create_sequence_feature"));
1592 sequenceFeature.addActionListener(new ActionListener()
1595 public void actionPerformed(ActionEvent e)
1597 sequenceFeature_actionPerformed();
1600 textColour.setText(MessageManager.getString("label.text_colour"));
1601 textColour.addActionListener(new ActionListener()
1604 public void actionPerformed(ActionEvent e)
1606 textColour_actionPerformed();
1609 jMenu1.setText(MessageManager.getString("label.group"));
1610 structureMenu.setText(MessageManager.getString("label.structure"));
1611 viewStructureMenu.setText(MessageManager
1612 .getString("label.view_structure"));
1613 // colStructureMenu.setText("Colour By Structure");
1614 editSequence.setText(MessageManager.getString("label.edit_sequence")
1616 editSequence.addActionListener(new ActionListener()
1619 public void actionPerformed(ActionEvent actionEvent)
1621 editSequence_actionPerformed(actionEvent);
1626 * annotationMenuItem.setText("By Annotation");
1627 * annotationMenuItem.addActionListener(new ActionListener() { public void
1628 * actionPerformed(ActionEvent actionEvent) {
1629 * annotationMenuItem_actionPerformed(actionEvent); } });
1631 groupMenu.add(sequenceSelDetails);
1634 this.add(structureMenu);
1635 // groupMenu.add(chooseAnnotations);
1636 groupMenu.add(showAnnotationsMenu);
1637 groupMenu.add(hideAnnotationsMenu);
1638 groupMenu.add(addDatasequenceAnnotations);
1639 groupMenu.add(editMenu);
1640 groupMenu.add(outputMenu);
1641 groupMenu.add(sequenceFeature);
1642 groupMenu.add(createGroupMenuItem);
1643 groupMenu.add(unGroupMenuItem);
1644 groupMenu.add(jMenu1);
1645 sequenceMenu.add(sequenceName);
1646 sequenceMenu.add(sequenceDetails);
1647 colourMenu.add(textColour);
1648 colourMenu.add(noColourmenuItem);
1649 colourMenu.add(clustalColour);
1650 colourMenu.add(BLOSUM62Colour);
1651 colourMenu.add(PIDColour);
1652 colourMenu.add(zappoColour);
1653 colourMenu.add(taylorColour);
1654 colourMenu.add(hydrophobicityColour);
1655 colourMenu.add(helixColour);
1656 colourMenu.add(strandColour);
1657 colourMenu.add(turnColour);
1658 colourMenu.add(buriedColour);
1659 colourMenu.add(nucleotideMenuItem);
1660 if (ap.getAlignment().isNucleotide())
1662 // JBPNote - commented since the colourscheme isn't functional
1663 // colourMenu.add(RNAInteractionColour);
1664 colourMenu.add(purinePyrimidineColour);
1666 // colourMenu.add(covariationColour);
1667 colourMenu.add(userDefinedColour);
1669 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1671 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1672 .getUserColourSchemes().keys();
1674 while (userColours.hasMoreElements())
1676 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1677 item.addActionListener(new ActionListener()
1680 public void actionPerformed(ActionEvent evt)
1682 userDefinedColour_actionPerformed(evt);
1685 colourMenu.add(item);
1689 colourMenu.addSeparator();
1690 colourMenu.add(abovePIDColour);
1691 colourMenu.add(conservationMenuItem);
1692 // colourMenu.add(annotationMenuItem);
1695 editMenu.add(editSequence);
1696 editMenu.add(upperCase);
1697 editMenu.add(lowerCase);
1698 editMenu.add(toggle);
1699 pdbMenu.add(pdbFromFile);
1700 // JBPNote: These shouldn't be added here - should appear in a generic
1701 // 'apply web service to this sequence menu'
1702 // pdbMenu.add(RNAFold);
1703 // pdbMenu.add(ContraFold);
1704 pdbMenu.add(enterPDB);
1705 pdbMenu.add(discoverPDB);
1706 jMenu1.add(groupName);
1707 jMenu1.add(colourMenu);
1708 jMenu1.add(showBoxes);
1709 jMenu1.add(showText);
1710 jMenu1.add(showColourText);
1711 jMenu1.add(outline);
1712 jMenu1.add(displayNonconserved);
1713 structureMenu.add(pdbMenu);
1714 structureMenu.add(viewStructureMenu);
1715 // structureMenu.add(colStructureMenu);
1716 noColourmenuItem.setText(MessageManager.getString("label.none"));
1717 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1720 public void actionPerformed(ActionEvent e)
1722 noColourmenuItem_actionPerformed();
1726 clustalColour.setText(MessageManager
1727 .getString("label.clustalx_colours"));
1728 clustalColour.addActionListener(new java.awt.event.ActionListener()
1731 public void actionPerformed(ActionEvent e)
1733 clustalColour_actionPerformed();
1736 zappoColour.setText(MessageManager.getString("label.zappo"));
1737 zappoColour.addActionListener(new java.awt.event.ActionListener()
1740 public void actionPerformed(ActionEvent e)
1742 zappoColour_actionPerformed();
1745 taylorColour.setText(MessageManager.getString("label.taylor"));
1746 taylorColour.addActionListener(new java.awt.event.ActionListener()
1749 public void actionPerformed(ActionEvent e)
1751 taylorColour_actionPerformed();
1754 hydrophobicityColour.setText(MessageManager
1755 .getString("label.hydrophobicity"));
1756 hydrophobicityColour
1757 .addActionListener(new java.awt.event.ActionListener()
1760 public void actionPerformed(ActionEvent e)
1762 hydrophobicityColour_actionPerformed();
1765 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1766 helixColour.addActionListener(new java.awt.event.ActionListener()
1769 public void actionPerformed(ActionEvent e)
1771 helixColour_actionPerformed();
1774 strandColour.setText(MessageManager
1775 .getString("label.strand_propensity"));
1776 strandColour.addActionListener(new java.awt.event.ActionListener()
1779 public void actionPerformed(ActionEvent e)
1781 strandColour_actionPerformed();
1784 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1785 turnColour.addActionListener(new java.awt.event.ActionListener()
1788 public void actionPerformed(ActionEvent e)
1790 turnColour_actionPerformed();
1793 buriedColour.setText(MessageManager.getString("label.buried_index"));
1794 buriedColour.addActionListener(new java.awt.event.ActionListener()
1797 public void actionPerformed(ActionEvent e)
1799 buriedColour_actionPerformed();
1802 abovePIDColour.setText(MessageManager
1803 .getString("label.above_identity_percentage"));
1804 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1807 public void actionPerformed(ActionEvent e)
1809 abovePIDColour_actionPerformed();
1812 userDefinedColour.setText(MessageManager
1813 .getString("action.user_defined"));
1814 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1817 public void actionPerformed(ActionEvent e)
1819 userDefinedColour_actionPerformed(e);
1823 .setText(MessageManager.getString("label.percentage_identity"));
1824 PIDColour.addActionListener(new java.awt.event.ActionListener()
1827 public void actionPerformed(ActionEvent e)
1829 PIDColour_actionPerformed();
1832 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1833 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1836 public void actionPerformed(ActionEvent e)
1838 BLOSUM62Colour_actionPerformed();
1841 purinePyrimidineColour.setText(MessageManager
1842 .getString("label.purine_pyrimidine"));
1843 purinePyrimidineColour
1844 .addActionListener(new java.awt.event.ActionListener()
1847 public void actionPerformed(ActionEvent e)
1849 purinePyrimidineColour_actionPerformed();
1854 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1855 * public void actionPerformed(ActionEvent e) {
1856 * covariationColour_actionPerformed(); } });
1859 conservationMenuItem.setText(MessageManager
1860 .getString("label.conservation"));
1861 conservationMenuItem
1862 .addActionListener(new java.awt.event.ActionListener()
1865 public void actionPerformed(ActionEvent e)
1867 conservationMenuItem_actionPerformed();
1873 * Check for any annotations on the underlying dataset sequences (for the
1874 * current selection group) which are not on the alignment. If any are found,
1875 * enable the option to add them to the alignment. The criteria for 'on the
1876 * alignment' is finding an annotation that matches on
1877 * sequenceRef.datasetSequence, calcId and label.
1879 protected void configureReferenceAnnotationsMenu()
1881 addDatasequenceAnnotations.setText(MessageManager
1882 .getString("label.add_reference_annotations"));
1883 addDatasequenceAnnotations.setEnabled(false);
1886 * Temporary store so we can write distinct calcId / type pairs on the
1889 Map<String, String> tipEntries = new HashMap<String, String>();
1890 StringBuilder tooltip = new StringBuilder(64);
1891 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1893 // this menu option only applies for a Selection
1894 if (this.ap.av.getSelectionGroup() == null)
1900 * For each sequence selected in the alignment, make a list of any
1901 * annotations on the underlying dataset sequence which are not already on
1902 * the sequence in the alignment.
1904 * Build a map of { alignmentSequence, <List of annotations to add> }
1906 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new HashMap<SequenceI, List<AlignmentAnnotation>>();
1907 for (SequenceI seq : this.ap.av.getSelectionGroup().getSequences())
1909 SequenceI dataset = seq.getDatasetSequence();
1910 if (dataset == null)
1914 AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
1915 if (datasetAnnotations == null)
1919 final List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1920 for (AlignmentAnnotation dsann : datasetAnnotations)
1923 * If the sequence has no annotation that matches this one, then add
1924 * this one to the results list.
1926 if (seq.getAlignmentAnnotations(dsann.getCalcId(), dsann.label)
1930 tipEntries.put(dsann.getCalcId(), dsann.label);
1934 * Save any addable annotations for this sequence
1936 if (!result.isEmpty())
1938 candidates.put(seq, result);
1941 if (!candidates.isEmpty())
1944 * Found annotations that could be added. Enable the menu item, and
1945 * configure its tooltip and action.
1947 addDatasequenceAnnotations.setEnabled(true);
1948 for (String calcId : tipEntries.keySet())
1950 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1952 String tooltipText = JvSwingUtils.wrapTooltip(true,
1953 tooltip.toString());
1954 addDatasequenceAnnotations.setToolTipText(tooltipText);
1956 addDatasequenceAnnotations.addActionListener(new ActionListener()
1959 public void actionPerformed(ActionEvent e)
1961 addReferenceAnnotations_actionPerformed(candidates);
1968 * Add annotations to the sequences and to the alignment.
1971 * a map whose keys are sequences on the alignment, and values a list
1972 * of annotations to add to each sequence
1974 protected void addReferenceAnnotations_actionPerformed(
1975 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1977 for (SequenceI seq : candidates.keySet())
1979 for (AlignmentAnnotation ann : candidates.get(seq))
1981 AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
1983 int endRes = ann.annotations.length;
1984 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1985 if (selectionGroup != null)
1987 startRes = selectionGroup.getStartRes();
1988 endRes = selectionGroup.getEndRes();
1990 copyAnn.restrict(startRes, endRes);
1992 // add to the sequence (sets correct copyAnn.datasetSequence)
1993 seq.addAlignmentAnnotation(copyAnn);
1995 copyAnn.adjustForAlignment();
1996 // add to the alignment and set visible
1997 this.ap.getAlignment().addAnnotation(copyAnn);
1998 copyAnn.visible = true;
2004 protected void sequenceSelectionDetails_actionPerformed()
2006 createSequenceDetailsReport(ap.av.getSequenceSelection());
2009 protected void sequenceDetails_actionPerformed()
2011 createSequenceDetailsReport(new SequenceI[]
2015 public void createSequenceDetailsReport(SequenceI[] sequences)
2017 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
2018 StringBuffer contents = new StringBuffer();
2019 for (SequenceI seq : sequences)
2021 contents.append("<p><h2>"
2024 "label.create_sequence_details_report_annotation_for",
2026 { seq.getDisplayId(true) }) + "</h2></p><p>");
2027 new SequenceAnnotationReport(null)
2028 .createSequenceAnnotationReport(
2034 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax
2036 contents.append("</p>");
2038 cap.setText("<html>" + contents.toString() + "</html>");
2040 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
2041 "label.sequece_details_for",
2042 (sequences.length == 1 ? new String[]
2043 { sequences[0].getDisplayId(true) } : new String[]
2044 { MessageManager.getString("label.selection") })), 500, 400);
2048 protected void showNonconserved_actionPerformed()
2050 getGroup().setShowNonconserved(displayNonconserved.isSelected());
2055 * call to refresh view after settings change
2059 ap.updateAnnotation();
2060 ap.paintAlignment(true);
2062 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
2071 protected void clustalColour_actionPerformed()
2073 SequenceGroup sg = getGroup();
2074 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
2084 protected void zappoColour_actionPerformed()
2086 getGroup().cs = new ZappoColourScheme();
2096 protected void taylorColour_actionPerformed()
2098 getGroup().cs = new TaylorColourScheme();
2108 protected void hydrophobicityColour_actionPerformed()
2110 getGroup().cs = new HydrophobicColourScheme();
2120 protected void helixColour_actionPerformed()
2122 getGroup().cs = new HelixColourScheme();
2132 protected void strandColour_actionPerformed()
2134 getGroup().cs = new StrandColourScheme();
2144 protected void turnColour_actionPerformed()
2146 getGroup().cs = new TurnColourScheme();
2156 protected void buriedColour_actionPerformed()
2158 getGroup().cs = new BuriedColourScheme();
2168 public void nucleotideMenuItem_actionPerformed()
2170 getGroup().cs = new NucleotideColourScheme();
2174 protected void purinePyrimidineColour_actionPerformed()
2176 getGroup().cs = new PurinePyrimidineColourScheme();
2181 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2182 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2190 protected void abovePIDColour_actionPerformed()
2192 SequenceGroup sg = getGroup();
2198 if (abovePIDColour.isSelected())
2200 sg.cs.setConsensus(AAFrequency.calculate(
2201 sg.getSequences(ap.av.getHiddenRepSequences()),
2202 sg.getStartRes(), sg.getEndRes() + 1));
2204 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2207 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
2209 SliderPanel.showPIDSlider();
2212 // remove PIDColouring
2214 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
2226 protected void userDefinedColour_actionPerformed(ActionEvent e)
2228 SequenceGroup sg = getGroup();
2230 if (e.getSource().equals(userDefinedColour))
2232 new UserDefinedColours(ap, sg);
2236 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2237 .getUserColourSchemes().get(e.getActionCommand());
2245 * Open a panel where the user can choose which types of sequence annotation
2250 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2252 // todo correct way to guard against opening a duplicate panel?
2253 new AnnotationChooser(ap);
2262 protected void PIDColour_actionPerformed()
2264 SequenceGroup sg = getGroup();
2265 sg.cs = new PIDColourScheme();
2266 sg.cs.setConsensus(AAFrequency.calculate(
2267 sg.getSequences(ap.av.getHiddenRepSequences()),
2268 sg.getStartRes(), sg.getEndRes() + 1));
2278 protected void BLOSUM62Colour_actionPerformed()
2280 SequenceGroup sg = getGroup();
2282 sg.cs = new Blosum62ColourScheme();
2284 sg.cs.setConsensus(AAFrequency.calculate(
2285 sg.getSequences(ap.av.getHiddenRepSequences()),
2286 sg.getStartRes(), sg.getEndRes() + 1));
2297 protected void noColourmenuItem_actionPerformed()
2299 getGroup().cs = null;
2309 protected void conservationMenuItem_actionPerformed()
2311 SequenceGroup sg = getGroup();
2317 if (conservationMenuItem.isSelected())
2319 // JBPNote: Conservation name shouldn't be i18n translated
2320 Conservation c = new Conservation("Group",
2321 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2322 .getHiddenRepSequences()), sg.getStartRes(),
2323 sg.getEndRes() + 1);
2326 c.verdict(false, ap.av.getConsPercGaps());
2328 sg.cs.setConservation(c);
2330 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2331 SliderPanel.showConservationSlider();
2334 // remove ConservationColouring
2336 sg.cs.setConservation(null);
2342 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2344 SequenceGroup sg = getGroup();
2350 AnnotationColourGradient acg = new AnnotationColourGradient(
2351 sequence.getAnnotation()[0], null,
2352 AnnotationColourGradient.NO_THRESHOLD);
2354 acg.setPredefinedColours(true);
2366 protected void groupName_actionPerformed()
2369 SequenceGroup sg = getGroup();
2370 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2371 sg.getDescription(), " "
2372 + MessageManager.getString("label.group_name") + " ",
2373 MessageManager.getString("label.group_description") + " ",
2374 MessageManager.getString("label.edit_group_name_description"),
2382 sg.setName(dialog.getName());
2383 sg.setDescription(dialog.getDescription());
2388 * Get selection group - adding it to the alignment if necessary.
2390 * @return sequence group to operate on
2392 SequenceGroup getGroup()
2394 SequenceGroup sg = ap.av.getSelectionGroup();
2395 // this method won't add a new group if it already exists
2398 ap.av.getAlignment().addGroup(sg);
2410 void sequenceName_actionPerformed()
2412 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2413 sequence.getDescription(),
2414 " " + MessageManager.getString("label.sequence_name")
2416 MessageManager.getString("label.sequence_description") + " ",
2418 .getString("label.edit_sequence_name_description"),
2426 if (dialog.getName() != null)
2428 if (dialog.getName().indexOf(" ") > -1)
2434 .getString("label.spaces_converted_to_backslashes"),
2436 .getString("label.no_spaces_allowed_sequence_name"),
2437 JOptionPane.WARNING_MESSAGE);
2440 sequence.setName(dialog.getName().replace(' ', '_'));
2441 ap.paintAlignment(false);
2444 sequence.setDescription(dialog.getDescription());
2446 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2457 void unGroupMenuItem_actionPerformed()
2459 SequenceGroup sg = ap.av.getSelectionGroup();
2460 ap.av.getAlignment().deleteGroup(sg);
2461 ap.av.setSelectionGroup(null);
2465 void createGroupMenuItem_actionPerformed()
2467 getGroup(); // implicitly creates group - note - should apply defaults / use
2468 // standard alignment window logic for this
2478 protected void outline_actionPerformed()
2480 SequenceGroup sg = getGroup();
2481 Color col = JColorChooser.showDialog(this,
2482 MessageManager.getString("label.select_outline_colour"),
2487 sg.setOutlineColour(col);
2499 public void showBoxes_actionPerformed()
2501 getGroup().setDisplayBoxes(showBoxes.isSelected());
2511 public void showText_actionPerformed()
2513 getGroup().setDisplayText(showText.isSelected());
2523 public void showColourText_actionPerformed()
2525 getGroup().setColourText(showColourText.isSelected());
2529 public void showLink(String url)
2533 jalview.util.BrowserLauncher.openURL(url);
2534 } catch (Exception ex)
2536 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2537 MessageManager.getString("label.web_browser_not_found_unix"),
2538 MessageManager.getString("label.web_browser_not_found"),
2539 JOptionPane.WARNING_MESSAGE);
2541 ex.printStackTrace();
2545 void hideSequences(boolean representGroup)
2547 SequenceGroup sg = ap.av.getSelectionGroup();
2548 if (sg == null || sg.getSize() < 1)
2550 ap.av.hideSequence(new SequenceI[]
2555 ap.av.setSelectionGroup(null);
2559 ap.av.hideRepSequences(sequence, sg);
2564 int gsize = sg.getSize();
2567 hseqs = new SequenceI[gsize];
2570 for (int i = 0; i < gsize; i++)
2572 hseqs[index++] = sg.getSequenceAt(i);
2575 ap.av.hideSequence(hseqs);
2576 // refresh(); TODO: ? needed ?
2577 ap.av.sendSelection();
2580 public void copy_actionPerformed()
2582 ap.alignFrame.copy_actionPerformed(null);
2585 public void cut_actionPerformed()
2587 ap.alignFrame.cut_actionPerformed(null);
2590 void changeCase(ActionEvent e)
2592 Object source = e.getSource();
2593 SequenceGroup sg = ap.av.getSelectionGroup();
2597 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
2598 sg.getEndRes() + 1);
2603 if (source == toggle)
2605 description = MessageManager.getString("label.toggle_case");
2606 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2608 else if (source == upperCase)
2610 description = MessageManager.getString("label.to_upper_case");
2611 caseChange = ChangeCaseCommand.TO_UPPER;
2615 description = MessageManager.getString("label.to_lower_case");
2616 caseChange = ChangeCaseCommand.TO_LOWER;
2619 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2620 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2621 startEnd, caseChange);
2623 ap.alignFrame.addHistoryItem(caseCommand);
2625 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2631 public void outputText_actionPerformed(ActionEvent e)
2633 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2634 cap.setForInput(null);
2635 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2636 "label.alignment_output_command", new String[]
2637 { e.getActionCommand() }), 600, 500);
2639 String[] omitHidden = null;
2641 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2642 // or we simply trust the user wants
2643 // wysiwig behaviour
2645 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2649 public void pdbFromFile_actionPerformed()
2651 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2652 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2653 chooser.setFileView(new jalview.io.JalviewFileView());
2654 chooser.setDialogTitle(MessageManager.formatMessage(
2655 "label.select_pdb_file_for", new String[]
2656 { sequence.getDisplayId(false) }));
2657 chooser.setToolTipText(MessageManager.formatMessage(
2658 "label.load_pdb_file_associate_with_sequence", new String[]
2659 { sequence.getDisplayId(false) }));
2661 int value = chooser.showOpenDialog(null);
2663 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2665 String choice = chooser.getSelectedFile().getPath();
2666 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2667 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2668 jalview.io.AppletFormatAdapter.FILE, sequence, true);
2673 // JBNote: commented out - these won't be instantiated here...!
2674 // public void RNAFold_actionPerformed() throws Exception
2676 // Predict2D P2D = new Predict2D();
2677 // P2D.getStructure2DFromRNAFold("toto");
2680 // public void ContraFold_actionPerformed() throws Exception
2682 // Predict2D P2D = new Predict2D();
2683 // P2D.getStructure2DFromContraFold("toto");
2685 public void enterPDB_actionPerformed()
2687 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2688 MessageManager.getString("label.enter_pdb_id"),
2689 MessageManager.getString("label.enter_pdb_id"),
2690 JOptionPane.QUESTION_MESSAGE);
2692 if (id != null && id.length() > 0)
2694 PDBEntry entry = new PDBEntry();
2695 entry.setId(id.toUpperCase());
2696 sequence.getDatasetSequence().addPDBId(entry);
2700 public void discoverPDB_actionPerformed()
2703 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2705 : ap.av.getSequenceSelection());
2706 Thread discpdb = new Thread(new Runnable()
2712 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2713 .fetchDBRefs(false);
2720 public void sequenceFeature_actionPerformed()
2722 SequenceGroup sg = ap.av.getSelectionGroup();
2728 int rsize = 0, gSize = sg.getSize();
2729 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2730 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2732 for (int i = 0; i < gSize; i++)
2734 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2735 int end = sg.findEndRes(sg.getSequenceAt(i));
2738 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2739 features[rsize] = new SequenceFeature(null, null, null, start, end,
2744 rseqs = new SequenceI[rsize];
2745 tfeatures = new SequenceFeature[rsize];
2746 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2747 System.arraycopy(features, 0, tfeatures, 0, rsize);
2748 features = tfeatures;
2750 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2751 features, true, ap))
2753 ap.alignFrame.setShowSeqFeatures(true);
2754 ap.highlightSearchResults(null);
2758 public void textColour_actionPerformed()
2760 SequenceGroup sg = getGroup();
2763 new TextColourChooser().chooseColour(ap, sg);
2767 public void colourByStructure(String pdbid)
2769 Annotation[] anots = ap.av.getStructureSelectionManager()
2770 .colourSequenceFromStructure(sequence, pdbid);
2772 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2773 "Coloured by " + pdbid, anots);
2775 ap.av.getAlignment().addAnnotation(an);
2776 an.createSequenceMapping(sequence, 0, true);
2777 // an.adjustForAlignment();
2778 ap.av.getAlignment().setAnnotationIndex(an, 0);
2780 ap.adjustAnnotationHeight();
2782 sequence.addAlignmentAnnotation(an);
2786 public void editSequence_actionPerformed(ActionEvent actionEvent)
2788 SequenceGroup sg = ap.av.getSelectionGroup();
2792 if (sequence == null)
2793 sequence = sg.getSequenceAt(0);
2795 EditNameDialog dialog = new EditNameDialog(
2796 sequence.getSequenceAsString(sg.getStartRes(),
2797 sg.getEndRes() + 1), null,
2798 MessageManager.getString("label.edit_sequence"), null,
2799 MessageManager.getString("label.edit_sequence"),
2804 EditCommand editCommand = new EditCommand(
2805 MessageManager.getString("label.edit_sequences"),
2806 EditCommand.REPLACE, dialog.getName().replace(' ',
2807 ap.av.getGapCharacter()),
2808 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2809 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2811 ap.alignFrame.addHistoryItem(editCommand);
2813 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()