2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.api.AlignViewportI;
28 import jalview.bin.Cache;
29 import jalview.commands.ChangeCaseCommand;
30 import jalview.commands.EditCommand;
31 import jalview.commands.EditCommand.Action;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.DBRefEntry;
35 import jalview.datamodel.HiddenColumns;
36 import jalview.datamodel.MappedFeatures;
37 import jalview.datamodel.PDBEntry;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.gui.ColourMenuHelper.ColourChangeListener;
42 import jalview.gui.JalviewColourChooser.ColourChooserListener;
43 import jalview.io.FileFormatI;
44 import jalview.io.FileFormats;
45 import jalview.io.FormatAdapter;
46 import jalview.io.SequenceAnnotationReport;
47 import jalview.schemes.Blosum62ColourScheme;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.schemes.ColourSchemes;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.ResidueColourScheme;
52 import jalview.util.Comparison;
53 import jalview.util.GroupUrlLink;
54 import jalview.util.GroupUrlLink.UrlStringTooLongException;
55 import jalview.util.MessageManager;
56 import jalview.util.Platform;
57 import jalview.util.StringUtils;
58 import jalview.util.UrlLink;
59 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
61 import java.awt.BorderLayout;
62 import java.awt.Color;
63 import java.awt.event.ActionEvent;
64 import java.awt.event.ActionListener;
65 import java.util.ArrayList;
66 import java.util.Arrays;
67 import java.util.BitSet;
68 import java.util.Collection;
69 import java.util.Collections;
70 import java.util.Hashtable;
71 import java.util.LinkedHashMap;
72 import java.util.List;
74 import java.util.Objects;
75 import java.util.SortedMap;
76 import java.util.TreeMap;
77 import java.util.Vector;
79 import javax.swing.ButtonGroup;
80 import javax.swing.JCheckBoxMenuItem;
81 import javax.swing.JInternalFrame;
82 import javax.swing.JLabel;
83 import javax.swing.JMenu;
84 import javax.swing.JMenuItem;
85 import javax.swing.JPanel;
86 import javax.swing.JPopupMenu;
87 import javax.swing.JRadioButtonMenuItem;
88 import javax.swing.JScrollPane;
91 * The popup menu that is displayed on right-click on a sequence id, or in the
94 public class PopupMenu extends JPopupMenu implements ColourChangeListener
97 * true for ID Panel menu, false for alignment panel menu
99 private final boolean forIdPanel;
101 private final AlignmentPanel ap;
104 * the sequence under the cursor when clicked
105 * (additional sequences may be selected)
107 private final SequenceI sequence;
109 JMenu groupMenu = new JMenu();
111 JMenuItem groupName = new JMenuItem();
113 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
115 protected JMenuItem modifyPID = new JMenuItem();
117 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
119 protected JRadioButtonMenuItem annotationColour;
121 protected JMenuItem modifyConservation = new JMenuItem();
123 JMenu sequenceMenu = new JMenu();
125 JMenuItem makeReferenceSeq = new JMenuItem();
127 JMenuItem createGroupMenuItem = new JMenuItem();
129 JMenuItem unGroupMenuItem = new JMenuItem();
131 JMenu colourMenu = new JMenu();
133 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
135 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
137 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
139 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
141 JMenu editMenu = new JMenu();
143 JMenuItem upperCase = new JMenuItem();
145 JMenuItem lowerCase = new JMenuItem();
147 JMenuItem toggle = new JMenuItem();
149 JMenu outputMenu = new JMenu();
151 JMenu seqShowAnnotationsMenu = new JMenu();
153 JMenu seqHideAnnotationsMenu = new JMenu();
155 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
156 MessageManager.getString("label.add_reference_annotations"));
158 JMenu groupShowAnnotationsMenu = new JMenu();
160 JMenu groupHideAnnotationsMenu = new JMenu();
162 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
163 MessageManager.getString("label.add_reference_annotations"));
165 JMenuItem textColour = new JMenuItem();
167 JMenu editGroupMenu = new JMenu();
169 JMenuItem chooseStructure = new JMenuItem();
171 JMenu rnaStructureMenu = new JMenu();
174 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
175 * and/or features provided. Hyperlinks may include a lookup by sequence id,
176 * or database cross-references, depending on which links are enabled in user
183 protected static JMenu buildLinkMenu(final SequenceI seq,
184 List<SequenceFeature> features)
186 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
188 List<String> nlinks = null;
191 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
192 UrlLink.sort(nlinks);
196 nlinks = new ArrayList<>();
199 if (features != null)
201 for (SequenceFeature sf : features)
203 if (sf.links != null)
205 for (String link : sf.links)
214 * instantiate the hyperlinklink templates from sequence data;
215 * note the order of the templates is preserved in the map
217 Map<String, List<String>> linkset = new LinkedHashMap<>();
218 for (String link : nlinks)
220 UrlLink urlLink = null;
223 urlLink = new UrlLink(link);
224 } catch (Exception foo)
226 Cache.log.error("Exception for URLLink '" + link + "'", foo);
230 if (!urlLink.isValid())
232 Cache.log.error(urlLink.getInvalidMessage());
236 urlLink.createLinksFromSeq(seq, linkset);
240 * construct menu items for the hyperlinks (still preserving
241 * the order of the sorted templates)
243 addUrlLinks(linkMenu, linkset.values());
249 * A helper method that builds menu items from the given links, with action
250 * handlers to open the link URL, and adds them to the linkMenu. Each provided
251 * link should be a list whose second item is the menu text, and whose fourth
252 * item is the URL to open when the menu item is selected.
257 static private void addUrlLinks(JMenu linkMenu,
258 Collection<List<String>> linkset)
260 for (List<String> linkstrset : linkset)
262 final String url = linkstrset.get(3);
263 JMenuItem item = new JMenuItem(linkstrset.get(1));
264 item.setToolTipText(MessageManager
265 .formatMessage("label.open_url_param", new Object[]
267 item.addActionListener(new ActionListener()
270 public void actionPerformed(ActionEvent e)
272 new Thread(new Runnable()
287 * Opens the provided url in the default web browser, or shows an error
288 * message if this fails
292 static void showLink(String url)
296 jalview.util.BrowserLauncher.openURL(url);
297 } catch (Exception ex)
299 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
300 MessageManager.getString("label.web_browser_not_found_unix"),
301 MessageManager.getString("label.web_browser_not_found"),
302 JvOptionPane.WARNING_MESSAGE);
304 ex.printStackTrace();
309 * add a late bound groupURL item to the given linkMenu
313 * - menu label string
314 * @param urlgenerator
315 * GroupURLLink used to generate URL
317 * Object array returned from the makeUrlStubs function.
319 static void addshowLink(JMenu linkMenu, String label,
320 final GroupUrlLink urlgenerator, final Object[] urlstub)
322 JMenuItem item = new JMenuItem(label);
323 item.setToolTipText(MessageManager
324 .formatMessage("label.open_url_seqs_param", new Object[]
325 { urlgenerator.getUrl_prefix(),
326 urlgenerator.getNumberInvolved(urlstub) }));
327 // TODO: put in info about what is being sent.
328 item.addActionListener(new ActionListener()
331 public void actionPerformed(ActionEvent e)
333 new Thread(new Runnable()
341 showLink(urlgenerator.constructFrom(urlstub));
342 } catch (UrlStringTooLongException e2)
355 * Constructor for a PopupMenu for a click in the alignment panel (on a residue)
358 * the panel in which the mouse is clicked
360 * the sequence under the mouse
361 * @throws NullPointerException
364 public PopupMenu(final AlignmentPanel ap, SequenceI seq, int column)
366 this(false, ap, seq, column, null);
370 * Constructor for a PopupMenu for a click in the sequence id panel
373 * the panel in which the mouse is clicked
375 * the sequence under the mouse click
377 * templates for sequence external links
378 * @throws NullPointerException
381 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
382 List<String> groupLinks)
384 this(true, alignPanel, seq, -1, groupLinks);
388 * Private constructor that constructs a popup menu for either sequence ID
389 * Panel, or alignment context
395 * aligned column position (0...)
398 private PopupMenu(boolean fromIdPanel,
399 final AlignmentPanel alignPanel,
400 final SequenceI seq, final int column, List<String> groupLinks)
402 Objects.requireNonNull(seq);
403 this.forIdPanel = fromIdPanel;
404 this.ap = alignPanel;
407 for (String ff : FileFormats.getInstance().getWritableFormats(true))
409 JMenuItem item = new JMenuItem(ff);
411 item.addActionListener(new ActionListener()
414 public void actionPerformed(ActionEvent e)
416 outputText_actionPerformed(e);
420 outputMenu.add(item);
424 * Build menus for annotation types that may be shown or hidden, and for
425 * 'reference annotations' that may be added to the alignment. First for the
426 * currently selected sequence (if there is one):
428 final List<SequenceI> selectedSequence = (forIdPanel && seq != null
430 : Collections.<SequenceI> emptyList());
431 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
432 seqHideAnnotationsMenu, selectedSequence);
433 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
437 * And repeat for the current selection group (if there is one):
439 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
440 ? Collections.<SequenceI> emptyList()
441 : alignPanel.av.getSelectionGroup().getSequences());
442 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
443 groupHideAnnotationsMenu, selectedGroup);
444 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
450 } catch (Exception e)
458 sequenceMenu.setText(sequence.getName());
459 if (seq == alignPanel.av.getAlignment().getSeqrep())
461 makeReferenceSeq.setText(
462 MessageManager.getString("action.unmark_as_reference"));
466 makeReferenceSeq.setText(
467 MessageManager.getString("action.set_as_reference"));
470 if (!alignPanel.av.getAlignment().isNucleotide())
472 remove(rnaStructureMenu);
476 int origCount = rnaStructureMenu.getItemCount();
478 * add menu items to 2D-render any alignment or sequence secondary
479 * structure annotation
481 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
482 .getAlignmentAnnotation();
485 for (final AlignmentAnnotation aa : aas)
487 if (aa.isValidStruc() && aa.sequenceRef == null)
490 * valid alignment RNA secondary structure annotation
492 menuItem = new JMenuItem();
493 menuItem.setText(MessageManager.formatMessage(
494 "label.2d_rna_structure_line", new Object[]
496 menuItem.addActionListener(new ActionListener()
499 public void actionPerformed(ActionEvent e)
501 new AppVarna(seq, aa, alignPanel);
504 rnaStructureMenu.add(menuItem);
509 if (seq.getAnnotation() != null)
511 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
512 for (final AlignmentAnnotation aa : seqAnns)
514 if (aa.isValidStruc())
517 * valid sequence RNA secondary structure annotation
519 // TODO: make rnastrucF a bit more nice
520 menuItem = new JMenuItem();
521 menuItem.setText(MessageManager.formatMessage(
522 "label.2d_rna_sequence_name", new Object[]
524 menuItem.addActionListener(new ActionListener()
527 public void actionPerformed(ActionEvent e)
529 // TODO: VARNA does'nt print gaps in the sequence
530 new AppVarna(seq, aa, alignPanel);
533 rnaStructureMenu.add(menuItem);
537 if (rnaStructureMenu.getItemCount() == origCount)
539 remove(rnaStructureMenu);
543 menuItem = new JMenuItem(
544 MessageManager.getString("action.hide_sequences"));
545 menuItem.addActionListener(new ActionListener()
548 public void actionPerformed(ActionEvent e)
550 hideSequences(false);
555 if (alignPanel.av.getSelectionGroup() != null
556 && alignPanel.av.getSelectionGroup().getSize() > 1)
558 menuItem = new JMenuItem(MessageManager
559 .formatMessage("label.represent_group_with", new Object[]
561 menuItem.addActionListener(new ActionListener()
564 public void actionPerformed(ActionEvent e)
569 sequenceMenu.add(menuItem);
572 if (alignPanel.av.hasHiddenRows())
574 final int index = alignPanel.av.getAlignment().findIndex(seq);
576 if (alignPanel.av.adjustForHiddenSeqs(index)
577 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
579 menuItem = new JMenuItem(
580 MessageManager.getString("action.reveal_sequences"));
581 menuItem.addActionListener(new ActionListener()
584 public void actionPerformed(ActionEvent e)
586 alignPanel.av.showSequence(index);
587 if (alignPanel.overviewPanel != null)
589 alignPanel.overviewPanel.updateOverviewImage();
600 * - in the IdPanel (seq not null) if any sequence is hidden
601 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
603 if (alignPanel.av.hasHiddenRows())
605 boolean addOption = seq != null;
606 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
612 JMenuItem menuItem = new JMenuItem(
613 MessageManager.getString("action.reveal_all"));
614 menuItem.addActionListener(new ActionListener()
617 public void actionPerformed(ActionEvent e)
619 alignPanel.av.showAllHiddenSeqs();
620 if (alignPanel.overviewPanel != null)
622 alignPanel.overviewPanel.updateOverviewImage();
630 SequenceGroup sg = alignPanel.av.getSelectionGroup();
631 boolean isDefinedGroup = (sg != null)
632 ? alignPanel.av.getAlignment().getGroups().contains(sg)
635 if (sg != null && sg.getSize() > 0)
637 groupName.setText(MessageManager
638 .getString("label.edit_name_and_description_current_group"));
640 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
642 conservationMenuItem.setEnabled(!sg.isNucleotide());
646 if (sg.cs.conservationApplied())
648 conservationMenuItem.setSelected(true);
650 if (sg.cs.getThreshold() > 0)
652 abovePIDColour.setSelected(true);
655 modifyConservation.setEnabled(conservationMenuItem.isSelected());
656 modifyPID.setEnabled(abovePIDColour.isSelected());
657 displayNonconserved.setSelected(sg.getShowNonconserved());
658 showText.setSelected(sg.getDisplayText());
659 showColourText.setSelected(sg.getColourText());
660 showBoxes.setSelected(sg.getDisplayBoxes());
661 // add any groupURLs to the groupURL submenu and make it visible
662 if (groupLinks != null && groupLinks.size() > 0)
664 buildGroupURLMenu(sg, groupLinks);
666 // Add a 'show all structures' for the current selection
667 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
669 SequenceI sqass = null;
670 for (SequenceI sq : alignPanel.av.getSequenceSelection())
672 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
673 if (pes != null && pes.size() > 0)
675 reppdb.put(pes.get(0).getId(), pes.get(0));
676 for (PDBEntry pe : pes)
678 pdbe.put(pe.getId(), pe);
688 final PDBEntry[] pe = pdbe.values()
689 .toArray(new PDBEntry[pdbe.size()]),
690 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
691 final JMenuItem gpdbview, rpdbview;
696 groupMenu.setVisible(false);
697 editMenu.setVisible(false);
702 createGroupMenuItem.setVisible(true);
703 unGroupMenuItem.setVisible(false);
704 editGroupMenu.setText(MessageManager.getString("action.edit_new_group"));
708 createGroupMenuItem.setVisible(false);
709 unGroupMenuItem.setVisible(true);
710 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
715 sequenceMenu.setVisible(false);
716 chooseStructure.setVisible(false);
717 rnaStructureMenu.setVisible(false);
720 addLinksAndFeatures(seq, column);
726 * <li>configured sequence database links (ID panel popup menu)</li>
727 * <li>non-positional feature links (ID panel popup menu)</li>
728 * <li>positional feature links (alignment panel popup menu)</li>
729 * <li>feature details links (alignment panel popup menu)</li>
731 * If this panel is also showed complementary (CDS/protein) features, then links
732 * to their feature details are also added.
737 void addLinksAndFeatures(final SequenceI seq, final int column)
739 List<SequenceFeature> features = null;
742 features = sequence.getFeatures().getNonPositionalFeatures();
746 features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
750 addLinks(seq, features);
754 addFeatureDetails(features, seq, column);
759 * Add a link to show feature details for each sequence feature
765 protected void addFeatureDetails(List<SequenceFeature> features,
766 SequenceI seq, int column)
769 * add features in CDS/protein complement at the corresponding
770 * position if configured to do so
772 MappedFeatures mf = null;
773 if (ap.av.isShowComplementFeatures())
775 if (!Comparison.isGap(sequence.getCharAt(column)))
777 AlignViewportI complement = ap.getAlignViewport()
778 .getCodingComplement();
779 AlignFrame af = Desktop.getAlignFrameFor(complement);
780 FeatureRendererModel fr2 = af.getFeatureRenderer();
781 int seqPos = sequence.findPosition(column);
782 mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
786 if (features.isEmpty() && mf == null)
789 * no features to show at this position
794 JMenu details = new JMenu(
795 MessageManager.getString("label.feature_details"));
798 String name = seq.getName();
799 for (final SequenceFeature sf : features)
801 addFeatureDetailsMenuItem(details, name, sf);
806 name = mf.fromSeq == seq ? mf.mapping.getTo().getName()
807 : mf.fromSeq.getName();
808 for (final SequenceFeature sf : mf.features)
810 addFeatureDetailsMenuItem(details, name, sf);
816 * A helper method to add one menu item whose action is to show details for one
823 void addFeatureDetailsMenuItem(JMenu details, final String seqName,
824 final SequenceFeature sf)
826 int start = sf.getBegin();
827 int end = sf.getEnd();
831 desc = String.format("%s %d", sf.getType(), start);
835 desc = String.format("%s %d-%d", sf.getType(), start, end);
837 String tooltip = desc;
838 String description = sf.getDescription();
839 if (description != null)
841 description = StringUtils.stripHtmlTags(description);
842 if (description.length() > 12)
844 desc = desc + " " + description.substring(0, 12) + "..";
848 desc = desc + " " + description;
850 tooltip = tooltip + " " + description;
852 if (sf.getFeatureGroup() != null)
854 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
856 JMenuItem item = new JMenuItem(desc);
857 item.setToolTipText(tooltip);
858 item.addActionListener(new ActionListener()
861 public void actionPerformed(ActionEvent e)
863 showFeatureDetails(seqName, sf);
870 * Opens a panel showing a text report of feature dteails
876 protected void showFeatureDetails(String seqName, SequenceFeature sf)
878 JInternalFrame details;
881 details = new JInternalFrame();
882 JPanel panel = new JPanel(new BorderLayout());
883 panel.setOpaque(true);
884 panel.setBackground(Color.white);
885 // TODO JAL-3026 set style of table correctly for feature details
886 JLabel reprt = new JLabel(MessageManager
887 .formatMessage("label.html_content", new Object[]
888 { sf.getDetailsReport(seqName) }));
889 reprt.setBackground(Color.WHITE);
890 reprt.setOpaque(true);
891 panel.add(reprt, BorderLayout.CENTER);
892 details.setContentPane(panel);
902 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
903 // it appears Java's CSS does not support border-collaps :-(
904 cap.addStylesheetRule("table { border-collapse: collapse;}");
905 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
906 cap.setText(sf.getDetailsReport(seqName));
909 Desktop.addInternalFrame(details,
910 MessageManager.getString("label.feature_details"), 500, 500);
914 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
915 * When seq is not null, these are links for the sequence id, which may be to
916 * external web sites for the sequence accession, and/or links embedded in
917 * non-positional features. When seq is null, only links embedded in the
918 * provided features are added. If no links are found, the menu is not added.
923 void addLinks(final SequenceI seq, List<SequenceFeature> features)
925 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
927 // only add link menu if it has entries
928 if (linkMenu.getItemCount() > 0)
932 sequenceMenu.add(linkMenu);
942 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
943 * "All" is added first, followed by a separator. Then add any annotation
944 * types associated with the current selection. Separate menus are built for
945 * the selected sequence group (if any), and the selected sequence.
947 * Some annotation rows are always rendered together - these can be identified
948 * by a common graphGroup property > -1. Only one of each group will be marked
949 * as visible (to avoid duplication of the display). For such groups we add a
950 * composite type name, e.g.
952 * IUPredWS (Long), IUPredWS (Short)
956 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
957 List<SequenceI> forSequences)
959 showMenu.removeAll();
960 hideMenu.removeAll();
962 final List<String> all = Arrays
964 { MessageManager.getString("label.all") });
965 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
967 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
969 showMenu.addSeparator();
970 hideMenu.addSeparator();
972 final AlignmentAnnotation[] annotations = ap.getAlignment()
973 .getAlignmentAnnotation();
976 * Find shown/hidden annotations types, distinguished by source (calcId),
977 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
978 * the insertion order, which is the order of the annotations on the
981 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
982 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
983 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
984 AlignmentAnnotationUtils.asList(annotations), forSequences);
986 for (String calcId : hiddenTypes.keySet())
988 for (List<String> type : hiddenTypes.get(calcId))
990 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
994 // grey out 'show annotations' if none are hidden
995 showMenu.setEnabled(!hiddenTypes.isEmpty());
997 for (String calcId : shownTypes.keySet())
999 for (List<String> type : shownTypes.get(calcId))
1001 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1005 // grey out 'hide annotations' if none are shown
1006 hideMenu.setEnabled(!shownTypes.isEmpty());
1010 * Returns a list of sequences - either the current selection group (if there
1011 * is one), else the specified single sequence.
1016 protected List<SequenceI> getSequenceScope(SequenceI seq)
1018 List<SequenceI> forSequences = null;
1019 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
1020 if (selectionGroup != null && selectionGroup.getSize() > 0)
1022 forSequences = selectionGroup.getSequences();
1026 forSequences = seq == null ? Collections.<SequenceI> emptyList()
1027 : Arrays.asList(seq);
1029 return forSequences;
1033 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1036 * @param showOrHideMenu
1037 * the menu to add to
1038 * @param forSequences
1039 * the sequences whose annotations may be shown or hidden
1044 * if true this is a special label meaning 'All'
1045 * @param actionIsShow
1046 * if true, the select menu item action is to show the annotation
1049 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1050 final List<SequenceI> forSequences, String calcId,
1051 final List<String> types, final boolean allTypes,
1052 final boolean actionIsShow)
1054 String label = types.toString(); // [a, b, c]
1055 label = label.substring(1, label.length() - 1); // a, b, c
1056 final JMenuItem item = new JMenuItem(label);
1057 item.setToolTipText(calcId);
1058 item.addActionListener(new ActionListener()
1061 public void actionPerformed(ActionEvent e)
1063 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1064 types, forSequences, allTypes, actionIsShow);
1068 showOrHideMenu.add(item);
1071 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1074 // TODO: usability: thread off the generation of group url content so root
1075 // menu appears asap
1076 // sequence only URLs
1077 // ID/regex match URLs
1078 JMenu groupLinksMenu = new JMenu(
1079 MessageManager.getString("action.group_link"));
1080 // three types of url that might be created.
1081 JMenu[] linkMenus = new JMenu[] { null,
1082 new JMenu(MessageManager.getString("action.ids")),
1083 new JMenu(MessageManager.getString("action.sequences")),
1084 new JMenu(MessageManager.getString("action.ids_sequences")) };
1086 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1087 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1088 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1089 for (int sq = 0; sq < seqs.length; sq++)
1092 int start = seqs[sq].findPosition(sg.getStartRes()),
1093 end = seqs[sq].findPosition(sg.getEndRes());
1094 // just collect ids from dataset sequence
1095 // TODO: check if IDs collected from selecton group intersects with the
1096 // current selection, too
1097 SequenceI sqi = seqs[sq];
1098 while (sqi.getDatasetSequence() != null)
1100 sqi = sqi.getDatasetSequence();
1102 List<DBRefEntry> dbr = sqi.getDBRefs();
1104 if (dbr != null && (nd = dbr.size()) > 0)
1106 for (int d = 0; d < nd; d++)
1108 DBRefEntry e = dbr.get(d);
1109 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1110 Object[] sarray = commonDbrefs.get(src);
1113 sarray = new Object[2];
1114 sarray[0] = new int[] { 0 };
1115 sarray[1] = new String[seqs.length];
1117 commonDbrefs.put(src, sarray);
1120 if (((String[]) sarray[1])[sq] == null)
1122 if (!e.hasMap() || (e.getMap()
1123 .locateMappedRange(start, end) != null))
1125 ((String[]) sarray[1])[sq] = e.getAccessionId();
1126 ((int[]) sarray[0])[0]++;
1132 // now create group links for all distinct ID/sequence sets.
1133 boolean addMenu = false; // indicates if there are any group links to give
1135 for (String link : groupLinks)
1137 GroupUrlLink urlLink = null;
1140 urlLink = new GroupUrlLink(link);
1141 } catch (Exception foo)
1143 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1146 if (!urlLink.isValid())
1148 Cache.log.error(urlLink.getInvalidMessage());
1151 final String label = urlLink.getLabel();
1152 boolean usingNames = false;
1153 // Now see which parts of the group apply for this URL
1154 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1155 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1156 String[] seqstr, ids; // input to makeUrl
1159 int numinput = ((int[]) idset[0])[0];
1160 String[] allids = ((String[]) idset[1]);
1161 seqstr = new String[numinput];
1162 ids = new String[numinput];
1163 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1165 if (allids[sq] != null)
1167 ids[idcount] = allids[sq];
1168 seqstr[idcount++] = idandseqs[1][sq];
1174 // just use the id/seq set
1175 seqstr = idandseqs[1];
1179 // and try and make the groupURL!
1181 Object[] urlset = null;
1184 urlset = urlLink.makeUrlStubs(ids, seqstr,
1185 "FromJalview" + System.currentTimeMillis(), false);
1186 } catch (UrlStringTooLongException e)
1191 int type = urlLink.getGroupURLType() & 3;
1192 // first two bits ofurlLink type bitfield are sequenceids and sequences
1193 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1194 addshowLink(linkMenus[type],
1195 label + (((type & 1) == 1)
1196 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1204 groupLinksMenu = new JMenu(
1205 MessageManager.getString("action.group_link"));
1206 for (int m = 0; m < linkMenus.length; m++)
1208 if (linkMenus[m] != null
1209 && linkMenus[m].getMenuComponentCount() > 0)
1211 groupLinksMenu.add(linkMenus[m]);
1215 groupMenu.add(groupLinksMenu);
1225 private void jbInit() throws Exception
1227 groupMenu.setText(MessageManager.getString("label.selection"));
1228 groupName.setText(MessageManager.getString("label.name"));
1229 groupName.addActionListener(new ActionListener()
1232 public void actionPerformed(ActionEvent e)
1234 groupName_actionPerformed();
1237 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1239 JMenuItem sequenceName = new JMenuItem(
1240 MessageManager.getString("label.edit_name_description"));
1241 sequenceName.addActionListener(new ActionListener()
1244 public void actionPerformed(ActionEvent e)
1246 sequenceName_actionPerformed();
1249 JMenuItem chooseAnnotations = new JMenuItem(
1250 MessageManager.getString("action.choose_annotations"));
1251 chooseAnnotations.addActionListener(new ActionListener()
1254 public void actionPerformed(ActionEvent e)
1256 chooseAnnotations_actionPerformed(e);
1259 JMenuItem sequenceDetails = new JMenuItem(
1260 MessageManager.getString("label.sequence_details"));
1261 sequenceDetails.addActionListener(new ActionListener()
1264 public void actionPerformed(ActionEvent e)
1266 createSequenceDetailsReport(new SequenceI[] { sequence });
1269 JMenuItem sequenceSelDetails = new JMenuItem(
1270 MessageManager.getString("label.sequence_details"));
1271 sequenceSelDetails.addActionListener(new ActionListener()
1274 public void actionPerformed(ActionEvent e)
1276 createSequenceDetailsReport(ap.av.getSequenceSelection());
1281 .setText(MessageManager.getString("action.remove_group"));
1282 unGroupMenuItem.addActionListener(new ActionListener()
1285 public void actionPerformed(ActionEvent e)
1287 unGroupMenuItem_actionPerformed();
1291 .setText(MessageManager.getString("action.create_group"));
1292 createGroupMenuItem.addActionListener(new ActionListener()
1295 public void actionPerformed(ActionEvent e)
1297 createGroupMenuItem_actionPerformed();
1301 JMenuItem outline = new JMenuItem(
1302 MessageManager.getString("action.border_colour"));
1303 outline.addActionListener(new ActionListener()
1306 public void actionPerformed(ActionEvent e)
1308 outline_actionPerformed();
1311 showBoxes.setText(MessageManager.getString("action.boxes"));
1312 showBoxes.setState(true);
1313 showBoxes.addActionListener(new ActionListener()
1316 public void actionPerformed(ActionEvent e)
1318 showBoxes_actionPerformed();
1321 showText.setText(MessageManager.getString("action.text"));
1322 showText.setState(true);
1323 showText.addActionListener(new ActionListener()
1326 public void actionPerformed(ActionEvent e)
1328 showText_actionPerformed();
1331 showColourText.setText(MessageManager.getString("label.colour_text"));
1332 showColourText.addActionListener(new ActionListener()
1335 public void actionPerformed(ActionEvent e)
1337 showColourText_actionPerformed();
1341 .setText(MessageManager.getString("label.show_non_conserved"));
1342 displayNonconserved.setState(true);
1343 displayNonconserved.addActionListener(new ActionListener()
1346 public void actionPerformed(ActionEvent e)
1348 showNonconserved_actionPerformed();
1351 editMenu.setText(MessageManager.getString("action.edit"));
1352 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1353 cut.addActionListener(new ActionListener()
1356 public void actionPerformed(ActionEvent e)
1358 cut_actionPerformed();
1361 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1362 upperCase.addActionListener(new ActionListener()
1365 public void actionPerformed(ActionEvent e)
1370 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1371 copy.addActionListener(new ActionListener()
1374 public void actionPerformed(ActionEvent e)
1376 copy_actionPerformed();
1379 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1380 lowerCase.addActionListener(new ActionListener()
1383 public void actionPerformed(ActionEvent e)
1388 toggle.setText(MessageManager.getString("label.toggle_case"));
1389 toggle.addActionListener(new ActionListener()
1392 public void actionPerformed(ActionEvent e)
1398 MessageManager.getString("label.out_to_textbox") + "...");
1399 seqShowAnnotationsMenu
1400 .setText(MessageManager.getString("label.show_annotations"));
1401 seqHideAnnotationsMenu
1402 .setText(MessageManager.getString("label.hide_annotations"));
1403 groupShowAnnotationsMenu
1404 .setText(MessageManager.getString("label.show_annotations"));
1405 groupHideAnnotationsMenu
1406 .setText(MessageManager.getString("label.hide_annotations"));
1407 JMenuItem sequenceFeature = new JMenuItem(
1408 MessageManager.getString("label.create_sequence_feature"));
1409 sequenceFeature.addActionListener(new ActionListener()
1412 public void actionPerformed(ActionEvent e)
1414 sequenceFeature_actionPerformed();
1417 editGroupMenu.setText(MessageManager.getString("label.group"));
1418 chooseStructure.setText(
1419 MessageManager.getString("label.show_pdbstruct_dialog"));
1420 chooseStructure.addActionListener(new ActionListener()
1423 public void actionPerformed(ActionEvent actionEvent)
1425 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1426 if (ap.av.getSelectionGroup() != null)
1428 selectedSeqs = ap.av.getSequenceSelection();
1430 new StructureChooser(selectedSeqs, sequence, ap);
1435 .setText(MessageManager.getString("label.view_rna_structure"));
1437 // colStructureMenu.setText("Colour By Structure");
1438 JMenuItem editSequence = new JMenuItem(
1439 MessageManager.getString("label.edit_sequence") + "...");
1440 editSequence.addActionListener(new ActionListener()
1443 public void actionPerformed(ActionEvent actionEvent)
1445 editSequence_actionPerformed();
1448 makeReferenceSeq.setText(
1449 MessageManager.getString("label.mark_as_representative"));
1450 makeReferenceSeq.addActionListener(new ActionListener()
1454 public void actionPerformed(ActionEvent actionEvent)
1456 makeReferenceSeq_actionPerformed(actionEvent);
1461 groupMenu.add(sequenceSelDetails);
1464 add(rnaStructureMenu);
1465 add(chooseStructure);
1468 JMenuItem hideInsertions = new JMenuItem(
1469 MessageManager.getString("label.hide_insertions"));
1470 hideInsertions.addActionListener(new ActionListener()
1474 public void actionPerformed(ActionEvent e)
1476 hideInsertions_actionPerformed(e);
1479 add(hideInsertions);
1481 // annotations configuration panel suppressed for now
1482 // groupMenu.add(chooseAnnotations);
1485 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1486 * (if a selection group is in force).
1488 sequenceMenu.add(seqShowAnnotationsMenu);
1489 sequenceMenu.add(seqHideAnnotationsMenu);
1490 sequenceMenu.add(seqAddReferenceAnnotations);
1491 groupMenu.add(groupShowAnnotationsMenu);
1492 groupMenu.add(groupHideAnnotationsMenu);
1493 groupMenu.add(groupAddReferenceAnnotations);
1494 groupMenu.add(editMenu);
1495 groupMenu.add(outputMenu);
1496 groupMenu.add(sequenceFeature);
1497 groupMenu.add(createGroupMenuItem);
1498 groupMenu.add(unGroupMenuItem);
1499 groupMenu.add(editGroupMenu);
1500 sequenceMenu.add(sequenceName);
1501 sequenceMenu.add(sequenceDetails);
1502 sequenceMenu.add(makeReferenceSeq);
1509 editMenu.add(editSequence);
1510 editMenu.add(upperCase);
1511 editMenu.add(lowerCase);
1512 editMenu.add(toggle);
1513 editGroupMenu.add(groupName);
1514 editGroupMenu.add(colourMenu);
1515 editGroupMenu.add(showBoxes);
1516 editGroupMenu.add(showText);
1517 editGroupMenu.add(showColourText);
1518 editGroupMenu.add(outline);
1519 editGroupMenu.add(displayNonconserved);
1523 * Constructs the entries for the colour menu
1525 protected void initColourMenu()
1527 colourMenu.setText(MessageManager.getString("label.group_colour"));
1528 textColour.setText(MessageManager.getString("label.text_colour"));
1529 textColour.addActionListener(new ActionListener()
1532 public void actionPerformed(ActionEvent e)
1534 textColour_actionPerformed();
1538 abovePIDColour.setText(
1539 MessageManager.getString("label.above_identity_threshold"));
1540 abovePIDColour.addActionListener(new ActionListener()
1543 public void actionPerformed(ActionEvent e)
1545 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1550 MessageManager.getString("label.modify_identity_threshold"));
1551 modifyPID.addActionListener(new ActionListener()
1554 public void actionPerformed(ActionEvent e)
1556 modifyPID_actionPerformed();
1560 conservationMenuItem
1561 .setText(MessageManager.getString("action.by_conservation"));
1562 conservationMenuItem.addActionListener(new ActionListener()
1565 public void actionPerformed(ActionEvent e)
1567 conservationMenuItem_actionPerformed(
1568 conservationMenuItem.isSelected());
1572 annotationColour = new JRadioButtonMenuItem(
1573 MessageManager.getString("action.by_annotation"));
1574 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1575 annotationColour.setEnabled(false);
1576 annotationColour.setToolTipText(
1577 MessageManager.getString("label.by_annotation_tooltip"));
1579 modifyConservation.setText(MessageManager
1580 .getString("label.modify_conservation_threshold"));
1581 modifyConservation.addActionListener(new ActionListener()
1584 public void actionPerformed(ActionEvent e)
1586 modifyConservation_actionPerformed();
1592 * Builds the group colour sub-menu, including any user-defined colours which
1593 * were loaded at startup or during the Jalview session
1595 protected void buildColourMenu()
1597 SequenceGroup sg = ap.av.getSelectionGroup();
1601 * popup menu with no sequence group scope
1605 colourMenu.removeAll();
1606 colourMenu.add(textColour);
1607 colourMenu.addSeparator();
1609 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1611 bg.add(annotationColour);
1612 colourMenu.add(annotationColour);
1614 colourMenu.addSeparator();
1615 colourMenu.add(conservationMenuItem);
1616 colourMenu.add(modifyConservation);
1617 colourMenu.add(abovePIDColour);
1618 colourMenu.add(modifyPID);
1621 protected void modifyConservation_actionPerformed()
1623 SequenceGroup sg = getGroup();
1626 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1627 SliderPanel.showConservationSlider();
1631 protected void modifyPID_actionPerformed()
1633 SequenceGroup sg = getGroup();
1636 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1638 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1639 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1640 SliderPanel.showPIDSlider();
1645 * Check for any annotations on the underlying dataset sequences (for the
1646 * current selection group) which are not 'on the alignment'.If any are found,
1647 * enable the option to add them to the alignment. The criteria for 'on the
1648 * alignment' is finding an alignment annotation on the alignment, matched on
1649 * calcId, label and sequenceRef.
1651 * A tooltip is also constructed that displays the source (calcId) and type
1652 * (label) of the annotations that can be added.
1655 * @param forSequences
1657 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1658 List<SequenceI> forSequences)
1660 menuItem.setEnabled(false);
1663 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1664 * Using TreeMap means calcIds are shown in alphabetical order.
1666 SortedMap<String, String> tipEntries = new TreeMap<>();
1667 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1668 AlignmentI al = this.ap.av.getAlignment();
1669 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1671 if (!candidates.isEmpty())
1673 StringBuilder tooltip = new StringBuilder(64);
1674 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1677 * Found annotations that could be added. Enable the menu item, and
1678 * configure its tooltip and action.
1680 menuItem.setEnabled(true);
1681 for (String calcId : tipEntries.keySet())
1683 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1685 String tooltipText = JvSwingUtils.wrapTooltip(true,
1686 tooltip.toString());
1687 menuItem.setToolTipText(tooltipText);
1689 menuItem.addActionListener(new ActionListener()
1692 public void actionPerformed(ActionEvent e)
1694 addReferenceAnnotations_actionPerformed(candidates);
1701 * Add annotations to the sequences and to the alignment.
1704 * a map whose keys are sequences on the alignment, and values a list
1705 * of annotations to add to each sequence
1707 protected void addReferenceAnnotations_actionPerformed(
1708 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1710 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1711 final AlignmentI alignment = this.ap.getAlignment();
1712 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1717 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1719 if (!ap.av.getAlignment().hasSeqrep())
1721 // initialise the display flags so the user sees something happen
1722 ap.av.setDisplayReferenceSeq(true);
1723 ap.av.setColourByReferenceSeq(true);
1724 ap.av.getAlignment().setSeqrep(sequence);
1728 if (ap.av.getAlignment().getSeqrep() == sequence)
1730 ap.av.getAlignment().setSeqrep(null);
1734 ap.av.getAlignment().setSeqrep(sequence);
1740 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1742 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1743 BitSet inserts = new BitSet();
1745 boolean markedPopup = false;
1746 // mark inserts in current selection
1747 if (ap.av.getSelectionGroup() != null)
1749 // mark just the columns in the selection group to be hidden
1750 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1751 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1753 // now clear columns without gaps
1754 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1760 inserts.and(sq.getInsertionsAsBits());
1762 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1763 ap.av.getSelectionGroup().getEndRes());
1766 // now mark for sequence under popup if we haven't already done it
1767 else if (!markedPopup && sequence != null)
1769 inserts.or(sequence.getInsertionsAsBits());
1771 // and set hidden columns accordingly
1772 hidden.hideColumns(inserts);
1777 protected void sequenceSelectionDetails_actionPerformed()
1779 createSequenceDetailsReport(ap.av.getSequenceSelection());
1782 public void createSequenceDetailsReport(SequenceI[] sequences)
1784 StringBuilder contents = new StringBuilder(128);
1785 contents.append("<html><body>");
1786 for (SequenceI seq : sequences)
1788 contents.append("<p><h2>" + MessageManager.formatMessage(
1789 "label.create_sequence_details_report_annotation_for",
1791 { seq.getDisplayId(true) }) + "</h2></p><p>");
1792 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1793 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1794 contents.append("</p>");
1796 contents.append("</body></html>");
1797 String report = contents.toString();
1799 JInternalFrame frame;
1800 if (Platform.isJS())
1802 JLabel textLabel = new JLabel();
1803 textLabel.setText(report);
1804 textLabel.setBackground(Color.WHITE);
1805 JPanel pane = new JPanel(new BorderLayout());
1806 pane.setOpaque(true);
1807 pane.setBackground(Color.WHITE);
1808 pane.add(textLabel, BorderLayout.NORTH);
1809 frame = new JInternalFrame();
1810 frame.getContentPane().add(new JScrollPane(pane));
1819 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1820 cap.setText(report);
1824 Desktop.addInternalFrame(frame,
1825 MessageManager.formatMessage("label.sequence_details_for",
1826 (sequences.length == 1 ? new Object[]
1827 { sequences[0].getDisplayId(true) }
1830 .getString("label.selection") })),
1834 protected void showNonconserved_actionPerformed()
1836 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1841 * call to refresh view after settings change
1845 ap.updateAnnotation();
1846 // removed paintAlignment(true) here:
1847 // updateAnnotation calls paintAlignment already, so don't need to call
1850 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1854 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1855 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1865 public void abovePIDColour_actionPerformed(boolean selected)
1867 SequenceGroup sg = getGroup();
1875 sg.cs.setConsensus(AAFrequency.calculate(
1876 sg.getSequences(ap.av.getHiddenRepSequences()),
1877 sg.getStartRes(), sg.getEndRes() + 1));
1879 int threshold = SliderPanel.setPIDSliderSource(ap,
1880 sg.getGroupColourScheme(), getGroup().getName());
1882 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1884 SliderPanel.showPIDSlider();
1887 // remove PIDColouring
1889 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1890 SliderPanel.hidePIDSlider();
1892 modifyPID.setEnabled(selected);
1898 * Open a panel where the user can choose which types of sequence annotation
1903 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1905 // todo correct way to guard against opening a duplicate panel?
1906 new AnnotationChooser(ap);
1915 public void conservationMenuItem_actionPerformed(boolean selected)
1917 SequenceGroup sg = getGroup();
1925 // JBPNote: Conservation name shouldn't be i18n translated
1926 Conservation c = new Conservation("Group",
1927 sg.getSequences(ap.av.getHiddenRepSequences()),
1928 sg.getStartRes(), sg.getEndRes() + 1);
1931 c.verdict(false, ap.av.getConsPercGaps());
1932 sg.cs.setConservation(c);
1934 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1936 SliderPanel.showConservationSlider();
1939 // remove ConservationColouring
1941 sg.cs.setConservation(null);
1942 SliderPanel.hideConservationSlider();
1944 modifyConservation.setEnabled(selected);
1950 * Shows a dialog where group name and description may be edited
1952 protected void groupName_actionPerformed()
1954 SequenceGroup sg = getGroup();
1955 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1956 sg.getDescription(),
1957 MessageManager.getString("label.group_name"),
1958 MessageManager.getString("label.group_description"));
1959 dialog.showDialog(ap.alignFrame,
1960 MessageManager.getString("label.edit_group_name_description"),
1966 sg.setName(dialog.getName());
1967 sg.setDescription(dialog.getDescription());
1974 * Get selection group - adding it to the alignment if necessary.
1976 * @return sequence group to operate on
1978 SequenceGroup getGroup()
1980 SequenceGroup sg = ap.av.getSelectionGroup();
1981 // this method won't add a new group if it already exists
1984 ap.av.getAlignment().addGroup(sg);
1991 * Shows a dialog where the sequence name and description may be edited. If a
1992 * name containing spaces is entered, these are converted to underscores, with a
1995 void sequenceName_actionPerformed()
1997 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1998 sequence.getDescription(),
1999 MessageManager.getString("label.sequence_name"),
2000 MessageManager.getString("label.sequence_description"));
2001 dialog.showDialog(ap.alignFrame,
2002 MessageManager.getString(
2003 "label.edit_sequence_name_description"),
2009 if (dialog.getName() != null)
2011 if (dialog.getName().indexOf(" ") > -1)
2013 JvOptionPane.showMessageDialog(ap,
2014 MessageManager.getString(
2015 "label.spaces_converted_to_underscores"),
2016 MessageManager.getString(
2017 "label.no_spaces_allowed_sequence_name"),
2018 JvOptionPane.WARNING_MESSAGE);
2020 sequence.setName(dialog.getName().replace(' ', '_'));
2021 ap.paintAlignment(false, false);
2023 sequence.setDescription(dialog.getDescription());
2024 ap.av.firePropertyChange("alignment", null,
2025 ap.av.getAlignment().getSequences());
2036 void unGroupMenuItem_actionPerformed()
2038 SequenceGroup sg = ap.av.getSelectionGroup();
2039 ap.av.getAlignment().deleteGroup(sg);
2040 ap.av.setSelectionGroup(null);
2044 void createGroupMenuItem_actionPerformed()
2046 getGroup(); // implicitly creates group - note - should apply defaults / use
2047 // standard alignment window logic for this
2052 * Offers a colour chooser and sets the selected colour as the group outline
2054 protected void outline_actionPerformed()
2056 String title = MessageManager
2057 .getString("label.select_outline_colour");
2058 ColourChooserListener listener = new ColourChooserListener()
2061 public void colourSelected(Color c)
2063 getGroup().setOutlineColour(c);
2067 JalviewColourChooser.showColourChooser(Desktop.getDesktop(),
2068 title, Color.BLUE, listener);
2077 public void showBoxes_actionPerformed()
2079 getGroup().setDisplayBoxes(showBoxes.isSelected());
2089 public void showText_actionPerformed()
2091 getGroup().setDisplayText(showText.isSelected());
2101 public void showColourText_actionPerformed()
2103 getGroup().setColourText(showColourText.isSelected());
2107 void hideSequences(boolean representGroup)
2109 ap.av.hideSequences(sequence, representGroup);
2112 public void copy_actionPerformed()
2114 ap.alignFrame.copy_actionPerformed();
2117 public void cut_actionPerformed()
2119 ap.alignFrame.cut_actionPerformed();
2122 void changeCase(ActionEvent e)
2124 Object source = e.getSource();
2125 SequenceGroup sg = ap.av.getSelectionGroup();
2129 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2130 sg.getStartRes(), sg.getEndRes() + 1);
2135 if (source == toggle)
2137 description = MessageManager.getString("label.toggle_case");
2138 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2140 else if (source == upperCase)
2142 description = MessageManager.getString("label.to_upper_case");
2143 caseChange = ChangeCaseCommand.TO_UPPER;
2147 description = MessageManager.getString("label.to_lower_case");
2148 caseChange = ChangeCaseCommand.TO_LOWER;
2151 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2152 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2153 startEnd, caseChange);
2155 ap.alignFrame.addHistoryItem(caseCommand);
2157 ap.av.firePropertyChange("alignment", null,
2158 ap.av.getAlignment().getSequences());
2163 public void outputText_actionPerformed(ActionEvent e)
2165 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2166 cap.setForInput(null);
2167 Desktop.addInternalFrame(cap, MessageManager
2168 .formatMessage("label.alignment_output_command", new Object[]
2169 { e.getActionCommand() }), 600, 500);
2171 String[] omitHidden = null;
2173 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2174 // or we simply trust the user wants
2175 // wysiwig behaviour
2177 FileFormatI fileFormat = FileFormats.getInstance()
2178 .forName(e.getActionCommand());
2180 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2183 public void sequenceFeature_actionPerformed()
2185 SequenceGroup sg = ap.av.getSelectionGroup();
2191 List<SequenceI> seqs = new ArrayList<>();
2192 List<SequenceFeature> features = new ArrayList<>();
2195 * assemble dataset sequences, and template new sequence features,
2196 * for the amend features dialog
2198 int gSize = sg.getSize();
2199 for (int i = 0; i < gSize; i++)
2201 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2202 int end = sg.findEndRes(sg.getSequenceAt(i));
2205 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2206 features.add(new SequenceFeature(null, null, start, end, null));
2211 * an entirely gapped region will generate empty lists of sequence / features
2213 if (!seqs.isEmpty())
2215 new FeatureEditor(ap, seqs, features, true).showDialog();
2219 public void textColour_actionPerformed()
2221 SequenceGroup sg = getGroup();
2224 new TextColourChooser().chooseColour(ap, sg);
2229 * Shows a dialog where sequence characters may be edited. Any changes are
2230 * applied, and added as an available 'Undo' item in the edit commands
2233 public void editSequence_actionPerformed()
2235 SequenceGroup sg = ap.av.getSelectionGroup();
2237 SequenceI seq = sequence;
2242 seq = sg.getSequenceAt(0);
2245 EditNameDialog dialog = new EditNameDialog(
2246 seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
2247 null, MessageManager.getString("label.edit_sequence"), null);
2248 dialog.showDialog(ap.alignFrame,
2249 MessageManager.getString("label.edit_sequence"),
2255 EditCommand editCommand = new EditCommand(
2256 MessageManager.getString("label.edit_sequences"),
2258 dialog.getName().replace(' ',
2259 ap.av.getGapCharacter()),
2260 sg.getSequencesAsArray(
2261 ap.av.getHiddenRepSequences()),
2262 sg.getStartRes(), sg.getEndRes() + 1,
2263 ap.av.getAlignment());
2264 ap.alignFrame.addHistoryItem(editCommand);
2265 ap.av.firePropertyChange("alignment", null,
2266 ap.av.getAlignment().getSequences());
2273 * Action on user selecting an item from the colour menu (that does not have
2274 * its bespoke action handler)
2279 public void changeColour_actionPerformed(String colourSchemeName)
2281 SequenceGroup sg = getGroup();
2283 * switch to the chosen colour scheme (or null for None)
2285 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2286 .getColourScheme(colourSchemeName, ap.av, sg,
2287 ap.av.getHiddenRepSequences());
2288 sg.setColourScheme(colourScheme);
2289 if (colourScheme instanceof Blosum62ColourScheme
2290 || colourScheme instanceof PIDColourScheme)
2292 sg.cs.setConsensus(AAFrequency.calculate(
2293 sg.getSequences(ap.av.getHiddenRepSequences()),
2294 sg.getStartRes(), sg.getEndRes() + 1));