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.Hashtable;
66 import java.util.LinkedHashMap;
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 java.awt.event.ActionListener()
313 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()
363 public void actionPerformed(ActionEvent e)
365 // System.out.println("1:"+structureLine);
366 System.out.println("1:sname" + seq.getName());
367 System.out.println("2:seq" + seq);
369 // System.out.println("3:"+seq.getSequenceAsString());
370 System.out.println("3:strucseq" + rnastruc);
371 // System.out.println("4:struc"+seq.getRNA());
372 System.out.println("5:name" + seq.getName());
373 System.out.println("6:ap" + ap);
374 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
375 rnastruc, seq.getName(), ap);
376 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
377 // seq.getName(), ap);
378 System.out.println("end");
381 viewStructureMenu.add(menuItem);
385 // SequenceFeatures[] test = seq.getSequenceFeatures();
387 if (seq.getAnnotation() != null)
389 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
390 for (int i = 0; i < seqAnno.length; i++)
392 if (seqAnno[i].getRNAStruc() != null)
394 final String rnastruc = seqAnno[i].getRNAStruc();
396 // TODO: make rnastrucF a bit more nice
397 menuItem = new JMenuItem();
398 menuItem.setText(MessageManager.formatMessage(
399 "label.2d_rna_sequence_name", new String[]
401 menuItem.addActionListener(new java.awt.event.ActionListener()
404 public void actionPerformed(ActionEvent e)
406 // TODO: VARNA does'nt print gaps in the sequence
408 new AppVarna(seq.getName() + " structure", seq, seq
409 .getSequenceAsString(), rnastruc, seq.getName(),
413 viewStructureMenu.add(menuItem);
420 menuItem = new JMenuItem(
421 MessageManager.getString("action.hide_sequences"));
422 menuItem.addActionListener(new java.awt.event.ActionListener()
425 public void actionPerformed(ActionEvent e)
427 hideSequences(false);
432 if (ap.av.getSelectionGroup() != null
433 && ap.av.getSelectionGroup().getSize() > 1)
435 menuItem = new JMenuItem(MessageManager.formatMessage(
436 "label.represent_group_with", new String[]
438 menuItem.addActionListener(new java.awt.event.ActionListener()
441 public void actionPerformed(ActionEvent e)
446 sequenceMenu.add(menuItem);
449 if (ap.av.hasHiddenRows())
451 final int index = ap.av.getAlignment().findIndex(seq);
453 if (ap.av.adjustForHiddenSeqs(index)
454 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
456 menuItem = new JMenuItem(
457 MessageManager.getString("action.reveal_sequences"));
458 menuItem.addActionListener(new ActionListener()
461 public void actionPerformed(ActionEvent e)
463 ap.av.showSequence(index);
464 if (ap.overviewPanel != null)
466 ap.overviewPanel.updateOverviewImage();
474 // for the case when no sequences are even visible
475 if (ap.av.hasHiddenRows())
478 menuItem = new JMenuItem(
479 MessageManager.getString("action.reveal_all"));
480 menuItem.addActionListener(new ActionListener()
483 public void actionPerformed(ActionEvent e)
485 ap.av.showAllHiddenSeqs();
486 if (ap.overviewPanel != null)
488 ap.overviewPanel.updateOverviewImage();
498 SequenceGroup sg = ap.av.getSelectionGroup();
499 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
500 .getGroups().contains(sg) : false;
502 if (sg != null && sg.getSize() > 0)
504 groupName.setText(MessageManager.formatMessage("label.name_param",
507 groupName.setText(MessageManager
508 .getString("label.edit_name_and_description_current_group"));
510 if (sg.cs instanceof ZappoColourScheme)
512 zappoColour.setSelected(true);
514 else if (sg.cs instanceof TaylorColourScheme)
516 taylorColour.setSelected(true);
518 else if (sg.cs instanceof PIDColourScheme)
520 PIDColour.setSelected(true);
522 else if (sg.cs instanceof Blosum62ColourScheme)
524 BLOSUM62Colour.setSelected(true);
526 else if (sg.cs instanceof UserColourScheme)
528 userDefinedColour.setSelected(true);
530 else if (sg.cs instanceof HydrophobicColourScheme)
532 hydrophobicityColour.setSelected(true);
534 else if (sg.cs instanceof HelixColourScheme)
536 helixColour.setSelected(true);
538 else if (sg.cs instanceof StrandColourScheme)
540 strandColour.setSelected(true);
542 else if (sg.cs instanceof TurnColourScheme)
544 turnColour.setSelected(true);
546 else if (sg.cs instanceof BuriedColourScheme)
548 buriedColour.setSelected(true);
550 else if (sg.cs instanceof ClustalxColourScheme)
552 clustalColour.setSelected(true);
554 else if (sg.cs instanceof PurinePyrimidineColourScheme)
556 purinePyrimidineColour.setSelected(true);
560 * else if (sg.cs instanceof CovariationColourScheme) {
561 * covariationColour.setSelected(true); }
565 noColourmenuItem.setSelected(true);
568 if (sg.cs != null && sg.cs.conservationApplied())
570 conservationMenuItem.setSelected(true);
572 displayNonconserved.setSelected(sg.getShowNonconserved());
573 showText.setSelected(sg.getDisplayText());
574 showColourText.setSelected(sg.getColourText());
575 showBoxes.setSelected(sg.getDisplayBoxes());
576 // add any groupURLs to the groupURL submenu and make it visible
577 if (groupLinks != null && groupLinks.size() > 0)
579 buildGroupURLMenu(sg, groupLinks);
581 // Add a 'show all structures' for the current selection
582 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
583 SequenceI sqass = null;
584 for (SequenceI sq : ap.av.getSequenceSelection())
586 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
587 if (pes != null && pes.size() > 0)
589 reppdb.put(pes.get(0).getId(), pes.get(0));
590 for (PDBEntry pe : pes)
592 pdbe.put(pe.getId(), pe);
602 final PDBEntry[] pe = pdbe.values().toArray(
603 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
604 new PDBEntry[reppdb.size()]);
605 final JMenuItem gpdbview, rpdbview;
606 if (pdbe.size() == 1)
608 structureMenu.add(gpdbview = new JMenuItem(MessageManager
609 .formatMessage("label.view_structure_for", new String[]
610 { sqass.getDisplayId(false) })));
614 structureMenu.add(gpdbview = new JMenuItem(MessageManager
615 .formatMessage("label.view_all_structures", new String[]
616 { new Integer(pdbe.size()).toString() })));
618 gpdbview.setToolTipText(MessageManager
619 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
620 gpdbview.addActionListener(new ActionListener()
624 public void actionPerformed(ActionEvent e)
626 new StructureViewer(ap.getStructureSelectionManager())
627 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
630 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
632 structureMenu.add(rpdbview = new JMenuItem(MessageManager
634 "label.view_all_representative_structures",
636 { new Integer(reppdb.size()).toString() })));
637 rpdbview.setToolTipText(MessageManager
638 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
639 rpdbview.addActionListener(new ActionListener()
643 public void actionPerformed(ActionEvent e)
645 new StructureViewer(ap.getStructureSelectionManager())
646 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
654 groupMenu.setVisible(false);
655 editMenu.setVisible(false);
660 createGroupMenuItem.setVisible(true);
661 unGroupMenuItem.setVisible(false);
662 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
666 createGroupMenuItem.setVisible(false);
667 unGroupMenuItem.setVisible(true);
668 jMenu1.setText(MessageManager.getString("action.edit_group"));
673 sequenceMenu.setVisible(false);
674 structureMenu.setVisible(false);
677 if (links != null && links.size() > 0)
680 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
681 Vector linkset = new Vector();
682 for (int i = 0; i < links.size(); i++)
684 String link = links.elementAt(i).toString();
685 UrlLink urlLink = null;
688 urlLink = new UrlLink(link);
689 } catch (Exception foo)
691 jalview.bin.Cache.log.error("Exception for URLLink '" + link
696 if (!urlLink.isValid())
698 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
701 final String label = urlLink.getLabel();
702 if (seq != null && urlLink.isDynamic())
705 // collect matching db-refs
706 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
707 seq.getDBRef(), new String[]
708 { urlLink.getTarget() });
709 // collect id string too
710 String id = seq.getName();
711 String descr = seq.getDescription();
712 if (descr != null && descr.length() < 1)
719 for (int r = 0; r < dbr.length; r++)
721 if (id != null && dbr[r].getAccessionId().equals(id))
723 // suppress duplicate link creation for the bare sequence ID
724 // string with this link
727 // create Bare ID link for this RUL
728 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
732 for (int u = 0; u < urls.length; u += 2)
734 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
736 linkset.addElement(urls[u] + "|" + urls[u + 1]);
737 addshowLink(linkMenu, label + "|" + urls[u],
746 // create Bare ID link for this RUL
747 String[] urls = urlLink.makeUrls(id, true);
750 for (int u = 0; u < urls.length; u += 2)
752 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
754 linkset.addElement(urls[u] + "|" + urls[u + 1]);
755 addshowLink(linkMenu, label, urls[u + 1]);
760 // Create urls from description but only for URL links which are regex
762 if (descr != null && urlLink.getRegexReplace() != null)
764 // create link for this URL from description where regex matches
765 String[] urls = urlLink.makeUrls(descr, true);
768 for (int u = 0; u < urls.length; u += 2)
770 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
772 linkset.addElement(urls[u] + "|" + urls[u + 1]);
773 addshowLink(linkMenu, label, urls[u + 1]);
781 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
783 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
784 // Add a non-dynamic link
785 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
789 if (sequence != null)
791 sequenceMenu.add(linkMenu);
801 * Add annotation types to a 'Show annotations' or 'Hide annotations' menu.
802 * "All" is added first, followed by a separator. Then add any annotation
803 * types associated with the current selection.
805 * Some annotation rows are always rendered together - these can be identified
806 * by a common graphGroup property > -1. Only one of each group will be marked
807 * as visible (to avoid duplication of the display). For such groups we add a
808 * composite type name, e.g.
810 * IUPredWS (Long), IUPredWS (Short)
812 protected void buildAnnotationTypesMenus()
814 showAnnotationsMenu.removeAll();
815 hideAnnotationsMenu.removeAll();
816 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
817 addAnnotationTypeToShowHide(showAnnotationsMenu, all, true, true);
818 addAnnotationTypeToShowHide(hideAnnotationsMenu, all, true, false);
819 showAnnotationsMenu.addSeparator();
820 hideAnnotationsMenu.addSeparator();
822 final AlignmentAnnotation[] annotations = ap.getAlignment()
823 .getAlignmentAnnotation();
824 BitSet visibleGraphGroups = PopupMenu
825 .getVisibleLineGraphGroups(annotations);
827 List<List<String>> shownTypes = new ArrayList<List<String>>();
828 List<List<String>> hiddenTypes = new ArrayList<List<String>>();
829 PopupMenu.getAnnotationTypesForShowHide(shownTypes, hiddenTypes,
830 visibleGraphGroups, annotations, ap.av.getSelectionGroup());
832 for (List<String> types : hiddenTypes)
834 addAnnotationTypeToShowHide(showAnnotationsMenu, types, false, true);
837 for (List<String> types : shownTypes)
839 addAnnotationTypeToShowHide(hideAnnotationsMenu, types, false, false);
844 * Helper method to populate lists of annotation types for the Show/Hide
845 * Annotations menus. If sequenceGroup is not null, this is restricted to
846 * annotations which are associated with sequences in the selection group.
848 * If an annotation row is currently visible, its type (label) is added (once
849 * only per type), to the shownTypes list. If it is currently hidden, it is
850 * added to the hiddenTypesList.
852 * For rows that belong to a line graph group, so are always rendered
855 * <li>Treat all rows in the group as visible, if at least one of them is</li>
856 * <li>Build a comma-separated label with all the types that belong to the
862 * @param visibleGraphGroups
864 * @param sequenceGroup
866 public static void getAnnotationTypesForShowHide(
867 List<List<String>> shownTypes, List<List<String>> hiddenTypes,
868 BitSet visibleGraphGroups, AlignmentAnnotation[] annotations,
869 SequenceGroup sequenceGroup)
871 // lookup table, key = graph group, value = list of types in the group
872 Map<Integer, List<String>> groupLabels = new LinkedHashMap<Integer, List<String>>();
874 List<String> addedToShown = new ArrayList<String>();
875 List<String> addedToHidden = new ArrayList<String>();
877 for (AlignmentAnnotation aa : annotations)
880 if (sequenceGroup == null
881 || (aa.sequenceRef != null && sequenceGroup.getSequences()
882 .contains(aa.sequenceRef)))
885 * Build a 'composite label' for types in line graph groups.
887 final List<String> labelAsList = new ArrayList<String>();
888 labelAsList.add(aa.label);
889 if (aa.graph == AlignmentAnnotation.LINE_GRAPH
890 && aa.graphGroup > -1)
892 if (groupLabels.containsKey(aa.graphGroup))
894 if (!groupLabels.get(aa.graphGroup).contains(aa.label))
896 groupLabels.get(aa.graphGroup).add(aa.label);
901 groupLabels.put(aa.graphGroup, labelAsList);
904 else if (aa.visible && !addedToShown.contains(aa.label))
906 shownTypes.add(labelAsList);
907 addedToShown.add(aa.label);
911 if (!aa.visible && !addedToHidden.contains(aa.label))
913 hiddenTypes.add(labelAsList);
914 addedToHidden.add(aa.label);
920 * finally add the 'composite group labels' to the appropriate lists,
921 * depending on whether the group is identified as visible or hidden
923 for (int group : groupLabels.keySet())
925 final List<String> groupLabel = groupLabels.get(group);
926 if (visibleGraphGroups.get(group))
928 if (!shownTypes.contains(groupLabel))
930 shownTypes.add(groupLabel);
933 else if (!hiddenTypes.contains(groupLabel))
935 hiddenTypes.add(groupLabel);
941 * Returns a BitSet (possibly empty) of those graphGroups for line graph
942 * annotations, which have at least one member annotation row marked visible.
943 * The logic is that only one row in the group is marked visible, but when it
944 * is drawn, so are all the other rows in the same group.
946 * This lookup set allows us to check whether rows marked not visible are in
949 * @see AnnotationRenderer#drawComponent
953 public static BitSet getVisibleLineGraphGroups(
954 AlignmentAnnotation[] annotations)
956 // todo move to a utility class
957 BitSet result = new BitSet();
958 for (AlignmentAnnotation ann : annotations)
960 if (ann.graph == AlignmentAnnotation.LINE_GRAPH && ann.visible)
962 int gg = ann.graphGroup;
973 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
976 * @param showOrHideMenu
981 * if true this is a special label meaning 'All'
982 * @param actionIsShow
983 * if true, the select menu item action is to show the annotation
986 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
987 final Collection<String> types, final boolean allTypes,
988 final boolean actionIsShow)
990 String label = types.toString(); // [a, b, c]
991 label = label.substring(1, label.length() - 1);
992 final JMenuItem item = new JMenuItem(label);
993 item.addActionListener(new java.awt.event.ActionListener()
996 public void actionPerformed(ActionEvent e)
998 showHideAnnotation_actionPerformed(types, allTypes, actionIsShow);
1001 showOrHideMenu.add(item);
1005 * Action on selecting a list of annotation type (or the 'all types' values)
1006 * to show or hide for the selection.
1012 protected void showHideAnnotation_actionPerformed(
1013 Collection<String> types, boolean anyType, boolean doShow)
1015 for (AlignmentAnnotation aa : ap.getAlignment()
1016 .getAlignmentAnnotation())
1018 if (anyType || types.contains(aa.label))
1020 if ((aa.sequenceRef != null)
1021 && ap.av.getSelectionGroup().getSequences()
1022 .contains(aa.sequenceRef))
1024 aa.visible = doShow;
1031 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
1034 // TODO: usability: thread off the generation of group url content so root
1035 // menu appears asap
1036 // sequence only URLs
1037 // ID/regex match URLs
1038 groupLinksMenu = new JMenu(
1039 MessageManager.getString("action.group_link"));
1040 JMenu[] linkMenus = new JMenu[]
1041 { null, new JMenu(MessageManager.getString("action.ids")),
1042 new JMenu(MessageManager.getString("action.sequences")),
1043 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1050 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1051 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1052 Hashtable commonDbrefs = new Hashtable();
1053 for (int sq = 0; sq < seqs.length; sq++)
1056 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1057 .findPosition(sg.getEndRes());
1058 // just collect ids from dataset sequence
1059 // TODO: check if IDs collected from selecton group intersects with the
1060 // current selection, too
1061 SequenceI sqi = seqs[sq];
1062 while (sqi.getDatasetSequence() != null)
1064 sqi = sqi.getDatasetSequence();
1066 DBRefEntry[] dbr = sqi.getDBRef();
1067 if (dbr != null && dbr.length > 0)
1069 for (int d = 0; d < dbr.length; d++)
1071 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1072 Object[] sarray = (Object[]) commonDbrefs.get(src);
1075 sarray = new Object[2];
1076 sarray[0] = new int[]
1078 sarray[1] = new String[seqs.length];
1080 commonDbrefs.put(src, sarray);
1083 if (((String[]) sarray[1])[sq] == null)
1085 if (!dbr[d].hasMap()
1086 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1088 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1089 ((int[]) sarray[0])[0]++;
1095 // now create group links for all distinct ID/sequence sets.
1096 boolean addMenu = false; // indicates if there are any group links to give
1098 for (int i = 0; i < groupLinks.size(); i++)
1100 String link = groupLinks.elementAt(i).toString();
1101 GroupUrlLink urlLink = null;
1104 urlLink = new GroupUrlLink(link);
1105 } catch (Exception foo)
1107 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1112 if (!urlLink.isValid())
1114 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1117 final String label = urlLink.getLabel();
1118 boolean usingNames = false;
1119 // Now see which parts of the group apply for this URL
1120 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1121 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1122 String[] seqstr, ids; // input to makeUrl
1125 int numinput = ((int[]) idset[0])[0];
1126 String[] allids = ((String[]) idset[1]);
1127 seqstr = new String[numinput];
1128 ids = new String[numinput];
1129 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1131 if (allids[sq] != null)
1133 ids[idcount] = allids[sq];
1134 seqstr[idcount++] = idandseqs[1][sq];
1140 // just use the id/seq set
1141 seqstr = idandseqs[1];
1145 // and try and make the groupURL!
1147 Object[] urlset = null;
1150 urlset = urlLink.makeUrlStubs(ids, seqstr,
1151 "FromJalview" + System.currentTimeMillis(), false);
1152 } catch (UrlStringTooLongException e)
1157 int type = urlLink.getGroupURLType() & 3;
1158 // System.out.println(urlLink.getGroupURLType()
1159 // +" "+((String[])urlset[3])[0]);
1160 // first two bits ofurlLink type bitfield are sequenceids and sequences
1161 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1162 addshowLink(linkMenus[type], label
1163 + (((type & 1) == 1) ? ("("
1164 + (usingNames ? "Names" : ltarget) + ")") : ""),
1171 groupLinksMenu = new JMenu(
1172 MessageManager.getString("action.group_link"));
1173 for (int m = 0; m < linkMenus.length; m++)
1175 if (linkMenus[m] != null
1176 && linkMenus[m].getMenuComponentCount() > 0)
1178 groupLinksMenu.add(linkMenus[m]);
1182 groupMenu.add(groupLinksMenu);
1187 * add a show URL menu item to the given linkMenu
1191 * - menu label string
1195 private void addshowLink(JMenu linkMenu, String label, final String url)
1197 JMenuItem item = new JMenuItem(label);
1198 item.setToolTipText(MessageManager.formatMessage(
1199 "label.open_url_param", new String[]
1201 item.addActionListener(new java.awt.event.ActionListener()
1204 public void actionPerformed(ActionEvent e)
1206 new Thread(new Runnable()
1223 * add a late bound groupURL item to the given linkMenu
1227 * - menu label string
1228 * @param urlgenerator
1229 * GroupURLLink used to generate URL
1231 * Object array returned from the makeUrlStubs function.
1233 private void addshowLink(JMenu linkMenu, String label,
1234 final GroupUrlLink urlgenerator, final Object[] urlstub)
1236 JMenuItem item = new JMenuItem(label);
1237 item.setToolTipText(MessageManager.formatMessage(
1238 "label.open_url_seqs_param",
1240 { urlgenerator.getUrl_prefix(),
1241 urlgenerator.getNumberInvolved(urlstub) }));
1242 // TODO: put in info about what is being sent.
1243 item.addActionListener(new java.awt.event.ActionListener()
1246 public void actionPerformed(ActionEvent e)
1248 new Thread(new Runnable()
1256 showLink(urlgenerator.constructFrom(urlstub));
1257 } catch (UrlStringTooLongException e)
1275 private void jbInit() throws Exception
1277 groupMenu.setText(MessageManager.getString("label.group"));
1278 groupMenu.setText(MessageManager.getString("label.selection"));
1279 groupName.setText(MessageManager.getString("label.name"));
1280 groupName.addActionListener(new java.awt.event.ActionListener()
1283 public void actionPerformed(ActionEvent e)
1285 groupName_actionPerformed();
1288 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1289 sequenceName.setText(MessageManager
1290 .getString("label.edit_name_description"));
1291 sequenceName.addActionListener(new java.awt.event.ActionListener()
1294 public void actionPerformed(ActionEvent e)
1296 sequenceName_actionPerformed();
1299 chooseAnnotations.setText(MessageManager
1300 .getString("label.choose_annotations") + "...");
1301 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1304 public void actionPerformed(ActionEvent e)
1306 chooseAnnotations_actionPerformed(e);
1309 sequenceDetails.setText(MessageManager
1310 .getString("label.sequence_details") + "...");
1311 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1314 public void actionPerformed(ActionEvent e)
1316 sequenceDetails_actionPerformed();
1319 sequenceSelDetails.setText(MessageManager
1320 .getString("label.sequence_details") + "...");
1322 .addActionListener(new java.awt.event.ActionListener()
1325 public void actionPerformed(ActionEvent e)
1327 sequenceSelectionDetails_actionPerformed();
1330 PIDColour.setFocusPainted(false);
1332 .setText(MessageManager.getString("action.remove_group"));
1333 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1336 public void actionPerformed(ActionEvent e)
1338 unGroupMenuItem_actionPerformed();
1341 createGroupMenuItem.setText(MessageManager
1342 .getString("action.create_group"));
1344 .addActionListener(new java.awt.event.ActionListener()
1347 public void actionPerformed(ActionEvent e)
1349 createGroupMenuItem_actionPerformed();
1353 outline.setText(MessageManager.getString("action.border_colour"));
1354 outline.addActionListener(new java.awt.event.ActionListener()
1357 public void actionPerformed(ActionEvent e)
1359 outline_actionPerformed();
1363 .setText(MessageManager.getString("label.nucleotide"));
1364 nucleotideMenuItem.addActionListener(new ActionListener()
1367 public void actionPerformed(ActionEvent e)
1369 nucleotideMenuItem_actionPerformed();
1372 colourMenu.setText(MessageManager.getString("label.group_colour"));
1373 showBoxes.setText(MessageManager.getString("action.boxes"));
1374 showBoxes.setState(true);
1375 showBoxes.addActionListener(new ActionListener()
1378 public void actionPerformed(ActionEvent e)
1380 showBoxes_actionPerformed();
1383 showText.setText(MessageManager.getString("action.text"));
1384 showText.setState(true);
1385 showText.addActionListener(new ActionListener()
1388 public void actionPerformed(ActionEvent e)
1390 showText_actionPerformed();
1393 showColourText.setText(MessageManager.getString("label.colour_text"));
1394 showColourText.addActionListener(new ActionListener()
1397 public void actionPerformed(ActionEvent e)
1399 showColourText_actionPerformed();
1402 displayNonconserved.setText(MessageManager
1403 .getString("label.show_non_conversed"));
1404 displayNonconserved.setState(true);
1405 displayNonconserved.addActionListener(new ActionListener()
1408 public void actionPerformed(ActionEvent e)
1410 showNonconserved_actionPerformed();
1413 editMenu.setText(MessageManager.getString("action.edit"));
1414 cut.setText(MessageManager.getString("action.cut"));
1415 cut.addActionListener(new ActionListener()
1418 public void actionPerformed(ActionEvent e)
1420 cut_actionPerformed();
1423 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1424 upperCase.addActionListener(new ActionListener()
1427 public void actionPerformed(ActionEvent e)
1432 copy.setText(MessageManager.getString("action.copy"));
1433 copy.addActionListener(new ActionListener()
1436 public void actionPerformed(ActionEvent e)
1438 copy_actionPerformed();
1441 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1442 lowerCase.addActionListener(new ActionListener()
1445 public void actionPerformed(ActionEvent e)
1450 toggle.setText(MessageManager.getString("label.toggle_case"));
1451 toggle.addActionListener(new ActionListener()
1454 public void actionPerformed(ActionEvent e)
1459 pdbMenu.setText(MessageManager
1460 .getString("label.associate_structure_with_sequence"));
1461 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1462 pdbFromFile.addActionListener(new ActionListener()
1465 public void actionPerformed(ActionEvent e)
1467 pdbFromFile_actionPerformed();
1470 // RNAFold.setText("From RNA Fold with predict2D");
1471 // RNAFold.addActionListener(new ActionListener()
1473 // public void actionPerformed(ActionEvent e)
1476 // RNAFold_actionPerformed();
1477 // } catch (Exception e1) {
1478 // // TODO Auto-generated catch block
1479 // e1.printStackTrace();
1483 // ContraFold.setText("From Contra Fold with predict2D");
1484 // ContraFold.addActionListener(new ActionListener()
1486 // public void actionPerformed(ActionEvent e)
1489 // ContraFold_actionPerformed();
1490 // } catch (Exception e1) {
1491 // // TODO Auto-generated catch block
1492 // e1.printStackTrace();
1496 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1497 enterPDB.addActionListener(new ActionListener()
1500 public void actionPerformed(ActionEvent e)
1502 enterPDB_actionPerformed();
1505 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1506 discoverPDB.addActionListener(new ActionListener()
1509 public void actionPerformed(ActionEvent e)
1511 discoverPDB_actionPerformed();
1514 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1516 showAnnotationsMenu.setText(MessageManager
1517 .getString("label.show_annotations"));
1518 hideAnnotationsMenu.setText(MessageManager
1519 .getString("label.hide_annotations"));
1520 final List<AlignmentAnnotation> referenceAnns = getDatasequenceAnnotationsNotOnAlignment(ap.av
1521 .getSelectionGroup());
1522 addDatasequenceAnnotations.setText(MessageManager
1523 .getString("label.add_reference_annotations"));
1524 addDatasequenceAnnotations.setEnabled(!referenceAnns.isEmpty());
1525 addDatasequenceAnnotations.addActionListener(new ActionListener()
1528 public void actionPerformed(ActionEvent e)
1530 addReferenceAnnotations_actionPerformed(referenceAnns);
1533 sequenceFeature.setText(MessageManager
1534 .getString("label.create_sequence_feature"));
1535 sequenceFeature.addActionListener(new ActionListener()
1538 public void actionPerformed(ActionEvent e)
1540 sequenceFeature_actionPerformed();
1543 textColour.setText(MessageManager.getString("label.text_colour"));
1544 textColour.addActionListener(new ActionListener()
1547 public void actionPerformed(ActionEvent e)
1549 textColour_actionPerformed();
1552 jMenu1.setText(MessageManager.getString("label.group"));
1553 structureMenu.setText(MessageManager.getString("label.structure"));
1554 viewStructureMenu.setText(MessageManager
1555 .getString("label.view_structure"));
1556 // colStructureMenu.setText("Colour By Structure");
1557 editSequence.setText(MessageManager.getString("label.edit_sequence")
1559 editSequence.addActionListener(new ActionListener()
1562 public void actionPerformed(ActionEvent actionEvent)
1564 editSequence_actionPerformed(actionEvent);
1569 * annotationMenuItem.setText("By Annotation");
1570 * annotationMenuItem.addActionListener(new ActionListener() { public void
1571 * actionPerformed(ActionEvent actionEvent) {
1572 * annotationMenuItem_actionPerformed(actionEvent); } });
1574 groupMenu.add(sequenceSelDetails);
1577 this.add(structureMenu);
1578 // groupMenu.add(chooseAnnotations);
1579 groupMenu.add(showAnnotationsMenu);
1580 groupMenu.add(hideAnnotationsMenu);
1581 groupMenu.add(addDatasequenceAnnotations);
1582 groupMenu.add(editMenu);
1583 groupMenu.add(outputMenu);
1584 groupMenu.add(sequenceFeature);
1585 groupMenu.add(createGroupMenuItem);
1586 groupMenu.add(unGroupMenuItem);
1587 groupMenu.add(jMenu1);
1588 sequenceMenu.add(sequenceName);
1589 sequenceMenu.add(sequenceDetails);
1590 colourMenu.add(textColour);
1591 colourMenu.add(noColourmenuItem);
1592 colourMenu.add(clustalColour);
1593 colourMenu.add(BLOSUM62Colour);
1594 colourMenu.add(PIDColour);
1595 colourMenu.add(zappoColour);
1596 colourMenu.add(taylorColour);
1597 colourMenu.add(hydrophobicityColour);
1598 colourMenu.add(helixColour);
1599 colourMenu.add(strandColour);
1600 colourMenu.add(turnColour);
1601 colourMenu.add(buriedColour);
1602 colourMenu.add(nucleotideMenuItem);
1603 if (ap.getAlignment().isNucleotide())
1605 // JBPNote - commented since the colourscheme isn't functional
1606 // colourMenu.add(RNAInteractionColour);
1607 colourMenu.add(purinePyrimidineColour);
1609 // colourMenu.add(covariationColour);
1610 colourMenu.add(userDefinedColour);
1612 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1614 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1615 .getUserColourSchemes().keys();
1617 while (userColours.hasMoreElements())
1619 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1620 item.addActionListener(new ActionListener()
1623 public void actionPerformed(ActionEvent evt)
1625 userDefinedColour_actionPerformed(evt);
1628 colourMenu.add(item);
1632 colourMenu.addSeparator();
1633 colourMenu.add(abovePIDColour);
1634 colourMenu.add(conservationMenuItem);
1635 // colourMenu.add(annotationMenuItem);
1638 editMenu.add(editSequence);
1639 editMenu.add(upperCase);
1640 editMenu.add(lowerCase);
1641 editMenu.add(toggle);
1642 pdbMenu.add(pdbFromFile);
1643 // JBPNote: These shouldn't be added here - should appear in a generic
1644 // 'apply web service to this sequence menu'
1645 // pdbMenu.add(RNAFold);
1646 // pdbMenu.add(ContraFold);
1647 pdbMenu.add(enterPDB);
1648 pdbMenu.add(discoverPDB);
1649 jMenu1.add(groupName);
1650 jMenu1.add(colourMenu);
1651 jMenu1.add(showBoxes);
1652 jMenu1.add(showText);
1653 jMenu1.add(showColourText);
1654 jMenu1.add(outline);
1655 jMenu1.add(displayNonconserved);
1656 structureMenu.add(pdbMenu);
1657 structureMenu.add(viewStructureMenu);
1658 // structureMenu.add(colStructureMenu);
1659 noColourmenuItem.setText(MessageManager.getString("label.none"));
1660 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1663 public void actionPerformed(ActionEvent e)
1665 noColourmenuItem_actionPerformed();
1669 clustalColour.setText(MessageManager
1670 .getString("label.clustalx_colours"));
1671 clustalColour.addActionListener(new java.awt.event.ActionListener()
1674 public void actionPerformed(ActionEvent e)
1676 clustalColour_actionPerformed();
1679 zappoColour.setText(MessageManager.getString("label.zappo"));
1680 zappoColour.addActionListener(new java.awt.event.ActionListener()
1683 public void actionPerformed(ActionEvent e)
1685 zappoColour_actionPerformed();
1688 taylorColour.setText(MessageManager.getString("label.taylor"));
1689 taylorColour.addActionListener(new java.awt.event.ActionListener()
1692 public void actionPerformed(ActionEvent e)
1694 taylorColour_actionPerformed();
1697 hydrophobicityColour.setText(MessageManager
1698 .getString("label.hydrophobicity"));
1699 hydrophobicityColour
1700 .addActionListener(new java.awt.event.ActionListener()
1703 public void actionPerformed(ActionEvent e)
1705 hydrophobicityColour_actionPerformed();
1708 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1709 helixColour.addActionListener(new java.awt.event.ActionListener()
1712 public void actionPerformed(ActionEvent e)
1714 helixColour_actionPerformed();
1717 strandColour.setText(MessageManager
1718 .getString("label.strand_propensity"));
1719 strandColour.addActionListener(new java.awt.event.ActionListener()
1722 public void actionPerformed(ActionEvent e)
1724 strandColour_actionPerformed();
1727 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1728 turnColour.addActionListener(new java.awt.event.ActionListener()
1731 public void actionPerformed(ActionEvent e)
1733 turnColour_actionPerformed();
1736 buriedColour.setText(MessageManager.getString("label.buried_index"));
1737 buriedColour.addActionListener(new java.awt.event.ActionListener()
1740 public void actionPerformed(ActionEvent e)
1742 buriedColour_actionPerformed();
1745 abovePIDColour.setText(MessageManager
1746 .getString("label.above_identity_percentage"));
1747 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1750 public void actionPerformed(ActionEvent e)
1752 abovePIDColour_actionPerformed();
1755 userDefinedColour.setText(MessageManager
1756 .getString("action.user_defined"));
1757 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1760 public void actionPerformed(ActionEvent e)
1762 userDefinedColour_actionPerformed(e);
1766 .setText(MessageManager.getString("label.percentage_identity"));
1767 PIDColour.addActionListener(new java.awt.event.ActionListener()
1770 public void actionPerformed(ActionEvent e)
1772 PIDColour_actionPerformed();
1775 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1776 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1779 public void actionPerformed(ActionEvent e)
1781 BLOSUM62Colour_actionPerformed();
1784 purinePyrimidineColour.setText(MessageManager
1785 .getString("label.purine_pyrimidine"));
1786 purinePyrimidineColour
1787 .addActionListener(new java.awt.event.ActionListener()
1790 public void actionPerformed(ActionEvent e)
1792 purinePyrimidineColour_actionPerformed();
1797 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1798 * public void actionPerformed(ActionEvent e) {
1799 * covariationColour_actionPerformed(); } });
1802 conservationMenuItem.setText(MessageManager
1803 .getString("label.conservation"));
1804 conservationMenuItem
1805 .addActionListener(new java.awt.event.ActionListener()
1808 public void actionPerformed(ActionEvent e)
1810 conservationMenuItem_actionPerformed();
1816 * Get a list of any annotations on the dataset sequences in the current
1817 * selection group that are not also on the alignment.
1819 * The criteria for 'on the alignment' is finding an annotation that matches
1820 * on sequenceRef.datasetSequence, calcId and label.
1824 protected List<AlignmentAnnotation> getDatasequenceAnnotationsNotOnAlignment(
1827 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1829 for (SequenceI seq : sg.getSequences())
1831 SequenceI dataset = seq.getDatasetSequence();
1832 AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
1833 if (datasetAnnotations != null)
1835 for (AlignmentAnnotation dsann : datasetAnnotations)
1838 * If the alignment has no annotation that matches this one...
1840 if (!ap.getAlignment()
1841 .findAnnotation(dataset, dsann.getCalcId(), dsann.label)
1842 .iterator().hasNext())
1845 * ...then add it to the result list
1856 * Add any annotations on the sequence dataset to the alignment (that are not
1857 * already copied to it).
1859 protected void addReferenceAnnotations_actionPerformed(
1860 List<AlignmentAnnotation> anns)
1862 for (AlignmentAnnotation ann : anns)
1864 // todo: copy, add, adjust...
1868 protected void sequenceSelectionDetails_actionPerformed()
1870 createSequenceDetailsReport(ap.av.getSequenceSelection());
1873 protected void sequenceDetails_actionPerformed()
1875 createSequenceDetailsReport(new SequenceI[]
1879 public void createSequenceDetailsReport(SequenceI[] sequences)
1881 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1882 StringBuffer contents = new StringBuffer();
1883 for (SequenceI seq : sequences)
1885 contents.append("<p><h2>"
1888 "label.create_sequence_details_report_annotation_for",
1890 { seq.getDisplayId(true) }) + "</h2></p><p>");
1891 new SequenceAnnotationReport(null)
1892 .createSequenceAnnotationReport(
1898 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax
1900 contents.append("</p>");
1902 cap.setText("<html>" + contents.toString() + "</html>");
1904 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
1905 "label.sequece_details_for",
1906 (sequences.length == 1 ? new String[]
1907 { sequences[0].getDisplayId(true) } : new String[]
1908 { MessageManager.getString("label.selection") })), 500, 400);
1912 protected void showNonconserved_actionPerformed()
1914 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1919 * call to refresh view after settings change
1923 ap.updateAnnotation();
1924 ap.paintAlignment(true);
1926 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1935 protected void clustalColour_actionPerformed()
1937 SequenceGroup sg = getGroup();
1938 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1948 protected void zappoColour_actionPerformed()
1950 getGroup().cs = new ZappoColourScheme();
1960 protected void taylorColour_actionPerformed()
1962 getGroup().cs = new TaylorColourScheme();
1972 protected void hydrophobicityColour_actionPerformed()
1974 getGroup().cs = new HydrophobicColourScheme();
1984 protected void helixColour_actionPerformed()
1986 getGroup().cs = new HelixColourScheme();
1996 protected void strandColour_actionPerformed()
1998 getGroup().cs = new StrandColourScheme();
2008 protected void turnColour_actionPerformed()
2010 getGroup().cs = new TurnColourScheme();
2020 protected void buriedColour_actionPerformed()
2022 getGroup().cs = new BuriedColourScheme();
2032 public void nucleotideMenuItem_actionPerformed()
2034 getGroup().cs = new NucleotideColourScheme();
2038 protected void purinePyrimidineColour_actionPerformed()
2040 getGroup().cs = new PurinePyrimidineColourScheme();
2045 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2046 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2054 protected void abovePIDColour_actionPerformed()
2056 SequenceGroup sg = getGroup();
2062 if (abovePIDColour.isSelected())
2064 sg.cs.setConsensus(AAFrequency.calculate(
2065 sg.getSequences(ap.av.getHiddenRepSequences()),
2066 sg.getStartRes(), sg.getEndRes() + 1));
2068 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2071 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
2073 SliderPanel.showPIDSlider();
2076 // remove PIDColouring
2078 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
2090 protected void userDefinedColour_actionPerformed(ActionEvent e)
2092 SequenceGroup sg = getGroup();
2094 if (e.getSource().equals(userDefinedColour))
2096 new UserDefinedColours(ap, sg);
2100 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2101 .getUserColourSchemes().get(e.getActionCommand());
2109 * Open a panel where the user can choose which types of sequence annotation
2114 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2116 // todo correct way to guard against opening a duplicate panel?
2117 new AnnotationChooser(ap);
2126 protected void PIDColour_actionPerformed()
2128 SequenceGroup sg = getGroup();
2129 sg.cs = new PIDColourScheme();
2130 sg.cs.setConsensus(AAFrequency.calculate(
2131 sg.getSequences(ap.av.getHiddenRepSequences()),
2132 sg.getStartRes(), sg.getEndRes() + 1));
2142 protected void BLOSUM62Colour_actionPerformed()
2144 SequenceGroup sg = getGroup();
2146 sg.cs = new Blosum62ColourScheme();
2148 sg.cs.setConsensus(AAFrequency.calculate(
2149 sg.getSequences(ap.av.getHiddenRepSequences()),
2150 sg.getStartRes(), sg.getEndRes() + 1));
2161 protected void noColourmenuItem_actionPerformed()
2163 getGroup().cs = null;
2173 protected void conservationMenuItem_actionPerformed()
2175 SequenceGroup sg = getGroup();
2181 if (conservationMenuItem.isSelected())
2183 // JBPNote: Conservation name shouldn't be i18n translated
2184 Conservation c = new Conservation("Group",
2185 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2186 .getHiddenRepSequences()), sg.getStartRes(),
2187 sg.getEndRes() + 1);
2190 c.verdict(false, ap.av.getConsPercGaps());
2192 sg.cs.setConservation(c);
2194 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2195 SliderPanel.showConservationSlider();
2198 // remove ConservationColouring
2200 sg.cs.setConservation(null);
2206 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2208 SequenceGroup sg = getGroup();
2214 AnnotationColourGradient acg = new AnnotationColourGradient(
2215 sequence.getAnnotation()[0], null,
2216 AnnotationColourGradient.NO_THRESHOLD);
2218 acg.setPredefinedColours(true);
2230 protected void groupName_actionPerformed()
2233 SequenceGroup sg = getGroup();
2234 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2235 sg.getDescription(), " "
2236 + MessageManager.getString("label.group_name") + " ",
2237 MessageManager.getString("label.group_description") + " ",
2238 MessageManager.getString("label.edit_group_name_description"),
2246 sg.setName(dialog.getName());
2247 sg.setDescription(dialog.getDescription());
2252 * Get selection group - adding it to the alignment if necessary.
2254 * @return sequence group to operate on
2256 SequenceGroup getGroup()
2258 SequenceGroup sg = ap.av.getSelectionGroup();
2259 // this method won't add a new group if it already exists
2262 ap.av.getAlignment().addGroup(sg);
2274 void sequenceName_actionPerformed()
2276 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2277 sequence.getDescription(),
2278 " " + MessageManager.getString("label.sequence_name")
2280 MessageManager.getString("label.sequence_description") + " ",
2282 .getString("label.edit_sequence_name_description"),
2290 if (dialog.getName() != null)
2292 if (dialog.getName().indexOf(" ") > -1)
2298 .getString("label.spaces_converted_to_backslashes"),
2300 .getString("label.no_spaces_allowed_sequence_name"),
2301 JOptionPane.WARNING_MESSAGE);
2304 sequence.setName(dialog.getName().replace(' ', '_'));
2305 ap.paintAlignment(false);
2308 sequence.setDescription(dialog.getDescription());
2310 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2321 void unGroupMenuItem_actionPerformed()
2323 SequenceGroup sg = ap.av.getSelectionGroup();
2324 ap.av.getAlignment().deleteGroup(sg);
2325 ap.av.setSelectionGroup(null);
2329 void createGroupMenuItem_actionPerformed()
2331 getGroup(); // implicitly creates group - note - should apply defaults / use
2332 // standard alignment window logic for this
2342 protected void outline_actionPerformed()
2344 SequenceGroup sg = getGroup();
2345 Color col = JColorChooser.showDialog(this,
2346 MessageManager.getString("label.select_outline_colour"),
2351 sg.setOutlineColour(col);
2363 public void showBoxes_actionPerformed()
2365 getGroup().setDisplayBoxes(showBoxes.isSelected());
2375 public void showText_actionPerformed()
2377 getGroup().setDisplayText(showText.isSelected());
2387 public void showColourText_actionPerformed()
2389 getGroup().setColourText(showColourText.isSelected());
2393 public void showLink(String url)
2397 jalview.util.BrowserLauncher.openURL(url);
2398 } catch (Exception ex)
2400 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2401 MessageManager.getString("label.web_browser_not_found_unix"),
2402 MessageManager.getString("label.web_browser_not_found"),
2403 JOptionPane.WARNING_MESSAGE);
2405 ex.printStackTrace();
2409 void hideSequences(boolean representGroup)
2411 SequenceGroup sg = ap.av.getSelectionGroup();
2412 if (sg == null || sg.getSize() < 1)
2414 ap.av.hideSequence(new SequenceI[]
2419 ap.av.setSelectionGroup(null);
2423 ap.av.hideRepSequences(sequence, sg);
2428 int gsize = sg.getSize();
2431 hseqs = new SequenceI[gsize];
2434 for (int i = 0; i < gsize; i++)
2436 hseqs[index++] = sg.getSequenceAt(i);
2439 ap.av.hideSequence(hseqs);
2440 // refresh(); TODO: ? needed ?
2441 ap.av.sendSelection();
2444 public void copy_actionPerformed()
2446 ap.alignFrame.copy_actionPerformed(null);
2449 public void cut_actionPerformed()
2451 ap.alignFrame.cut_actionPerformed(null);
2454 void changeCase(ActionEvent e)
2456 Object source = e.getSource();
2457 SequenceGroup sg = ap.av.getSelectionGroup();
2461 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
2462 sg.getEndRes() + 1);
2467 if (source == toggle)
2469 description = MessageManager.getString("label.toggle_case");
2470 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2472 else if (source == upperCase)
2474 description = MessageManager.getString("label.to_upper_case");
2475 caseChange = ChangeCaseCommand.TO_UPPER;
2479 description = MessageManager.getString("label.to_lower_case");
2480 caseChange = ChangeCaseCommand.TO_LOWER;
2483 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2484 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2485 startEnd, caseChange);
2487 ap.alignFrame.addHistoryItem(caseCommand);
2489 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2495 public void outputText_actionPerformed(ActionEvent e)
2497 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2498 cap.setForInput(null);
2499 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2500 "label.alignment_output_command", new String[]
2501 { e.getActionCommand() }), 600, 500);
2503 String[] omitHidden = null;
2505 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2506 // or we simply trust the user wants
2507 // wysiwig behaviour
2509 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2513 public void pdbFromFile_actionPerformed()
2515 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2516 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2517 chooser.setFileView(new jalview.io.JalviewFileView());
2518 chooser.setDialogTitle(MessageManager.formatMessage(
2519 "label.select_pdb_file_for", new String[]
2520 { sequence.getDisplayId(false) }));
2521 chooser.setToolTipText(MessageManager.formatMessage(
2522 "label.load_pdb_file_associate_with_sequence", new String[]
2523 { sequence.getDisplayId(false) }));
2525 int value = chooser.showOpenDialog(null);
2527 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2529 String choice = chooser.getSelectedFile().getPath();
2530 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2531 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2532 jalview.io.AppletFormatAdapter.FILE, sequence, true);
2537 // JBNote: commented out - these won't be instantiated here...!
2538 // public void RNAFold_actionPerformed() throws Exception
2540 // Predict2D P2D = new Predict2D();
2541 // P2D.getStructure2DFromRNAFold("toto");
2544 // public void ContraFold_actionPerformed() throws Exception
2546 // Predict2D P2D = new Predict2D();
2547 // P2D.getStructure2DFromContraFold("toto");
2549 public void enterPDB_actionPerformed()
2551 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2552 MessageManager.getString("label.enter_pdb_id"),
2553 MessageManager.getString("label.enter_pdb_id"),
2554 JOptionPane.QUESTION_MESSAGE);
2556 if (id != null && id.length() > 0)
2558 PDBEntry entry = new PDBEntry();
2559 entry.setId(id.toUpperCase());
2560 sequence.getDatasetSequence().addPDBId(entry);
2564 public void discoverPDB_actionPerformed()
2567 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2569 : ap.av.getSequenceSelection());
2570 Thread discpdb = new Thread(new Runnable()
2576 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2577 .fetchDBRefs(false);
2584 public void sequenceFeature_actionPerformed()
2586 SequenceGroup sg = ap.av.getSelectionGroup();
2592 int rsize = 0, gSize = sg.getSize();
2593 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2594 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2596 for (int i = 0; i < gSize; i++)
2598 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2599 int end = sg.findEndRes(sg.getSequenceAt(i));
2602 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2603 features[rsize] = new SequenceFeature(null, null, null, start, end,
2608 rseqs = new SequenceI[rsize];
2609 tfeatures = new SequenceFeature[rsize];
2610 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2611 System.arraycopy(features, 0, tfeatures, 0, rsize);
2612 features = tfeatures;
2614 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2615 features, true, ap))
2617 ap.alignFrame.setShowSeqFeatures(true);
2618 ap.highlightSearchResults(null);
2622 public void textColour_actionPerformed()
2624 SequenceGroup sg = getGroup();
2627 new TextColourChooser().chooseColour(ap, sg);
2631 public void colourByStructure(String pdbid)
2633 Annotation[] anots = ap.av.getStructureSelectionManager()
2634 .colourSequenceFromStructure(sequence, pdbid);
2636 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2637 "Coloured by " + pdbid, anots);
2639 ap.av.getAlignment().addAnnotation(an);
2640 an.createSequenceMapping(sequence, 0, true);
2641 // an.adjustForAlignment();
2642 ap.av.getAlignment().setAnnotationIndex(an, 0);
2644 ap.adjustAnnotationHeight();
2646 sequence.addAlignmentAnnotation(an);
2650 public void editSequence_actionPerformed(ActionEvent actionEvent)
2652 SequenceGroup sg = ap.av.getSelectionGroup();
2656 if (sequence == null)
2657 sequence = sg.getSequenceAt(0);
2659 EditNameDialog dialog = new EditNameDialog(
2660 sequence.getSequenceAsString(sg.getStartRes(),
2661 sg.getEndRes() + 1), null,
2662 MessageManager.getString("label.edit_sequence"), null,
2663 MessageManager.getString("label.edit_sequence"),
2668 EditCommand editCommand = new EditCommand(
2669 MessageManager.getString("label.edit_sequences"),
2670 EditCommand.REPLACE, dialog.getName().replace(' ',
2671 ap.av.getGapCharacter()),
2672 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2673 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2675 ap.alignFrame.addHistoryItem(editCommand);
2677 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()