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.bin.Cache;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.Annotation;
34 import jalview.datamodel.ColumnSelection;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.AppletFormatAdapter;
42 import jalview.io.FormatAdapter;
43 import jalview.io.JalviewFileChooser;
44 import jalview.io.SequenceAnnotationReport;
45 import jalview.schemes.AnnotationColourGradient;
46 import jalview.schemes.Blosum62ColourScheme;
47 import jalview.schemes.BuriedColourScheme;
48 import jalview.schemes.ClustalxColourScheme;
49 import jalview.schemes.HelixColourScheme;
50 import jalview.schemes.HydrophobicColourScheme;
51 import jalview.schemes.NucleotideColourScheme;
52 import jalview.schemes.PIDColourScheme;
53 import jalview.schemes.PurinePyrimidineColourScheme;
54 import jalview.schemes.ResidueProperties;
55 import jalview.schemes.StrandColourScheme;
56 import jalview.schemes.TaylorColourScheme;
57 import jalview.schemes.TurnColourScheme;
58 import jalview.schemes.UserColourScheme;
59 import jalview.schemes.ZappoColourScheme;
60 import jalview.util.BrowserLauncher;
61 import jalview.util.DBRefUtils;
62 import jalview.util.GroupUrlLink;
63 import jalview.util.GroupUrlLink.UrlStringTooLongException;
64 import jalview.util.MessageManager;
65 import jalview.util.UrlLink;
66 import jalview.ws.DBRefFetcher;
68 import java.awt.Color;
69 import java.awt.event.ActionEvent;
70 import java.awt.event.ActionListener;
71 import java.util.Arrays;
72 import java.util.Collections;
73 import java.util.Enumeration;
74 import java.util.Hashtable;
75 import java.util.LinkedHashMap;
76 import java.util.List;
78 import java.util.TreeMap;
79 import java.util.Vector;
81 import javax.swing.ButtonGroup;
82 import javax.swing.JCheckBoxMenuItem;
83 import javax.swing.JColorChooser;
84 import javax.swing.JMenu;
85 import javax.swing.JMenuItem;
86 import javax.swing.JOptionPane;
87 import javax.swing.JPopupMenu;
88 import javax.swing.JRadioButtonMenuItem;
94 * @version $Revision: 1.118 $
96 public class PopupMenu extends JPopupMenu
98 private static final String ALL_ANNOTATIONS = "All";
100 private static final String COMMA = ",";
102 JMenu groupMenu = new JMenu();
104 JMenuItem groupName = new JMenuItem();
106 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
112 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
114 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
116 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
118 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
122 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
124 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
126 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
128 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
130 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
132 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
134 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
136 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
140 JMenu sequenceMenu = new JMenu();
142 JMenuItem sequenceName = new JMenuItem();
144 JMenuItem sequenceDetails = new JMenuItem();
146 JMenuItem sequenceSelDetails = new JMenuItem();
148 JMenuItem makeReferenceSeq = new JMenuItem();
150 JMenuItem chooseAnnotations = new JMenuItem();
154 JMenuItem createGroupMenuItem = new JMenuItem();
156 JMenuItem unGroupMenuItem = new JMenuItem();
158 JMenuItem outline = new JMenuItem();
160 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
162 JMenu colourMenu = new JMenu();
164 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
166 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
168 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
170 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
172 JMenu editMenu = new JMenu();
174 JMenuItem cut = new JMenuItem();
176 JMenuItem copy = new JMenuItem();
178 JMenuItem upperCase = new JMenuItem();
180 JMenuItem lowerCase = new JMenuItem();
182 JMenuItem toggle = new JMenuItem();
184 JMenu pdbMenu = new JMenu();
186 JMenuItem pdbFromFile = new JMenuItem();
188 JMenuItem enterPDB = new JMenuItem();
190 JMenuItem discoverPDB = new JMenuItem();
192 JMenu outputMenu = new JMenu();
194 JMenu seqShowAnnotationsMenu = new JMenu();
196 JMenu seqHideAnnotationsMenu = new JMenu();
198 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
199 MessageManager.getString("label.add_reference_annotations"));
201 JMenu groupShowAnnotationsMenu = new JMenu();
203 JMenu groupHideAnnotationsMenu = new JMenu();
205 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
206 MessageManager.getString("label.add_reference_annotations"));
208 JMenuItem sequenceFeature = new JMenuItem();
210 JMenuItem textColour = new JMenuItem();
212 JMenu jMenu1 = new JMenu();
214 JMenuItem proteinStructureMenu = new JMenuItem();
216 JMenu rnaStructureMenu = new JMenu();
218 JMenuItem editSequence = new JMenuItem();
220 JMenu groupLinksMenu;
222 JMenuItem hideInsertions = new JMenuItem();
225 * Creates a new PopupMenu object.
232 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
234 this(ap, seq, links, null);
244 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
245 Vector links, Vector groupLinks)
247 // /////////////////////////////////////////////////////////
248 // If this is activated from the sequence panel, the user may want to
249 // edit or annotate a particular residue. Therefore display the residue menu
251 // If from the IDPanel, we must display the sequence menu
252 // ////////////////////////////////////////////////////////
256 ButtonGroup colours = new ButtonGroup();
257 colours.add(noColourmenuItem);
258 colours.add(clustalColour);
259 colours.add(zappoColour);
260 colours.add(taylorColour);
261 colours.add(hydrophobicityColour);
262 colours.add(helixColour);
263 colours.add(strandColour);
264 colours.add(turnColour);
265 colours.add(buriedColour);
266 colours.add(abovePIDColour);
267 colours.add(userDefinedColour);
268 colours.add(PIDColour);
269 colours.add(BLOSUM62Colour);
270 colours.add(purinePyrimidineColour);
271 colours.add(RNAInteractionColour);
273 for (int i = 0; i < FormatAdapter.WRITEABLE_FORMATS.length; i++)
275 JMenuItem item = new JMenuItem(
276 FormatAdapter.WRITEABLE_FORMATS[i]);
278 item.addActionListener(new java.awt.event.ActionListener()
281 public void actionPerformed(ActionEvent e)
283 outputText_actionPerformed(e);
287 outputMenu.add(item);
291 * Build menus for annotation types that may be shown or hidden, and for
292 * 'reference annotations' that may be added to the alignment. First for the
293 * currently selected sequence (if there is one):
295 final List<SequenceI> selectedSequence = (seq == null ? Collections
296 .<SequenceI> emptyList() : Arrays.asList(seq));
297 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
298 seqHideAnnotationsMenu, selectedSequence);
299 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
303 * And repeat for the current selection group (if there is one):
305 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
306 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
308 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
309 groupHideAnnotationsMenu, selectedGroup);
310 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
316 } catch (Exception e)
324 sequenceMenu.setText(sequence.getName());
325 if (seq == ap.av.getAlignment().getSeqrep())
327 makeReferenceSeq.setText("Unmark representative");
329 makeReferenceSeq.setText("Mark as representative");
332 if (!ap.av.getAlignment().isNucleotide())
334 remove(rnaStructureMenu);
339 * add menu items to 2D-render any alignment or sequence secondary
340 * structure annotation
342 AlignmentAnnotation[] aas = ap.av.getAlignment()
343 .getAlignmentAnnotation();
346 for (final AlignmentAnnotation aa : aas)
348 if (aa.isValidStruc() && aa.sequenceRef == null)
351 * valid alignment RNA secondary structure annotation
353 menuItem = new JMenuItem();
354 menuItem.setText(MessageManager.formatMessage(
355 "label.2d_rna_structure_line", new Object[]
357 menuItem.addActionListener(new java.awt.event.ActionListener()
360 public void actionPerformed(ActionEvent e)
362 new AppVarna(seq, aa, ap);
365 rnaStructureMenu.add(menuItem);
370 if (seq.getAnnotation() != null)
372 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
373 for (final AlignmentAnnotation aa : seqAnns)
375 if (aa.isValidStruc())
378 * valid sequence RNA secondary structure annotation
380 // TODO: make rnastrucF a bit more nice
381 menuItem = new JMenuItem();
382 menuItem.setText(MessageManager.formatMessage(
383 "label.2d_rna_sequence_name", new Object[]
385 menuItem.addActionListener(new java.awt.event.ActionListener()
388 public void actionPerformed(ActionEvent e)
390 // TODO: VARNA does'nt print gaps in the sequence
391 new AppVarna(seq, aa, ap);
394 rnaStructureMenu.add(menuItem);
400 menuItem = new JMenuItem(
401 MessageManager.getString("action.hide_sequences"));
402 menuItem.addActionListener(new java.awt.event.ActionListener()
405 public void actionPerformed(ActionEvent e)
407 hideSequences(false);
412 if (ap.av.getSelectionGroup() != null
413 && ap.av.getSelectionGroup().getSize() > 1)
415 menuItem = new JMenuItem(MessageManager.formatMessage(
416 "label.represent_group_with", new Object[]
418 menuItem.addActionListener(new java.awt.event.ActionListener()
421 public void actionPerformed(ActionEvent e)
426 sequenceMenu.add(menuItem);
429 if (ap.av.hasHiddenRows())
431 final int index = ap.av.getAlignment().findIndex(seq);
433 if (ap.av.adjustForHiddenSeqs(index)
434 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
436 menuItem = new JMenuItem(
437 MessageManager.getString("action.reveal_sequences"));
438 menuItem.addActionListener(new ActionListener()
441 public void actionPerformed(ActionEvent e)
443 ap.av.showSequence(index);
444 if (ap.overviewPanel != null)
446 ap.overviewPanel.updateOverviewImage();
454 // for the case when no sequences are even visible
455 if (ap.av.hasHiddenRows())
458 menuItem = new JMenuItem(
459 MessageManager.getString("action.reveal_all"));
460 menuItem.addActionListener(new ActionListener()
463 public void actionPerformed(ActionEvent e)
465 ap.av.showAllHiddenSeqs();
466 if (ap.overviewPanel != null)
468 ap.overviewPanel.updateOverviewImage();
478 SequenceGroup sg = ap.av.getSelectionGroup();
479 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
480 .getGroups().contains(sg) : false;
482 if (sg != null && sg.getSize() > 0)
484 groupName.setText(MessageManager.formatMessage("label.name_param",
487 groupName.setText(MessageManager
488 .getString("label.edit_name_and_description_current_group"));
490 if (sg.cs instanceof ZappoColourScheme)
492 zappoColour.setSelected(true);
494 else if (sg.cs instanceof TaylorColourScheme)
496 taylorColour.setSelected(true);
498 else if (sg.cs instanceof PIDColourScheme)
500 PIDColour.setSelected(true);
502 else if (sg.cs instanceof Blosum62ColourScheme)
504 BLOSUM62Colour.setSelected(true);
506 else if (sg.cs instanceof UserColourScheme)
508 userDefinedColour.setSelected(true);
510 else if (sg.cs instanceof HydrophobicColourScheme)
512 hydrophobicityColour.setSelected(true);
514 else if (sg.cs instanceof HelixColourScheme)
516 helixColour.setSelected(true);
518 else if (sg.cs instanceof StrandColourScheme)
520 strandColour.setSelected(true);
522 else if (sg.cs instanceof TurnColourScheme)
524 turnColour.setSelected(true);
526 else if (sg.cs instanceof BuriedColourScheme)
528 buriedColour.setSelected(true);
530 else if (sg.cs instanceof ClustalxColourScheme)
532 clustalColour.setSelected(true);
534 else if (sg.cs instanceof PurinePyrimidineColourScheme)
536 purinePyrimidineColour.setSelected(true);
540 * else if (sg.cs instanceof CovariationColourScheme) {
541 * covariationColour.setSelected(true); }
545 noColourmenuItem.setSelected(true);
548 if (sg.cs != null && sg.cs.conservationApplied())
550 conservationMenuItem.setSelected(true);
552 displayNonconserved.setSelected(sg.getShowNonconserved());
553 showText.setSelected(sg.getDisplayText());
554 showColourText.setSelected(sg.getColourText());
555 showBoxes.setSelected(sg.getDisplayBoxes());
556 // add any groupURLs to the groupURL submenu and make it visible
557 if (groupLinks != null && groupLinks.size() > 0)
559 buildGroupURLMenu(sg, groupLinks);
561 // Add a 'show all structures' for the current selection
562 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
563 SequenceI sqass = null;
564 for (SequenceI sq : ap.av.getSequenceSelection())
566 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
567 if (pes != null && pes.size() > 0)
569 reppdb.put(pes.get(0).getId(), pes.get(0));
570 for (PDBEntry pe : pes)
572 pdbe.put(pe.getId(), pe);
582 final PDBEntry[] pe = pdbe.values().toArray(
583 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
584 new PDBEntry[reppdb.size()]);
585 final JMenuItem gpdbview, rpdbview;
590 groupMenu.setVisible(false);
591 editMenu.setVisible(false);
596 createGroupMenuItem.setVisible(true);
597 unGroupMenuItem.setVisible(false);
598 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
602 createGroupMenuItem.setVisible(false);
603 unGroupMenuItem.setVisible(true);
604 jMenu1.setText(MessageManager.getString("action.edit_group"));
609 sequenceMenu.setVisible(false);
610 proteinStructureMenu.setVisible(false);
611 rnaStructureMenu.setVisible(false);
614 if (links != null && links.size() > 0)
617 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
618 Vector linkset = new Vector();
619 for (int i = 0; i < links.size(); i++)
621 String link = links.elementAt(i).toString();
622 UrlLink urlLink = null;
625 urlLink = new UrlLink(link);
626 } catch (Exception foo)
628 Cache.log.error("Exception for URLLink '" + link
633 if (!urlLink.isValid())
635 Cache.log.error(urlLink.getInvalidMessage());
638 final String label = urlLink.getLabel();
639 if (seq != null && urlLink.isDynamic())
642 // collect matching db-refs
643 DBRefEntry[] dbr = DBRefUtils.selectRefs(
644 seq.getDBRef(), new String[]
645 { urlLink.getTarget() });
646 // collect id string too
647 String id = seq.getName();
648 String descr = seq.getDescription();
649 if (descr != null && descr.length() < 1)
656 for (int r = 0; r < dbr.length; r++)
658 if (id != null && dbr[r].getAccessionId().equals(id))
660 // suppress duplicate link creation for the bare sequence ID
661 // string with this link
664 // create Bare ID link for this RUL
665 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
669 for (int u = 0; u < urls.length; u += 2)
671 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
673 linkset.addElement(urls[u] + "|" + urls[u + 1]);
674 addshowLink(linkMenu, label + "|" + urls[u],
683 // create Bare ID link for this RUL
684 String[] urls = urlLink.makeUrls(id, true);
687 for (int u = 0; u < urls.length; u += 2)
689 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
691 linkset.addElement(urls[u] + "|" + urls[u + 1]);
692 addshowLink(linkMenu, label, urls[u + 1]);
697 // Create urls from description but only for URL links which are regex
699 if (descr != null && urlLink.getRegexReplace() != null)
701 // create link for this URL from description where regex matches
702 String[] urls = urlLink.makeUrls(descr, true);
705 for (int u = 0; u < urls.length; u += 2)
707 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
709 linkset.addElement(urls[u] + "|" + urls[u + 1]);
710 addshowLink(linkMenu, label, urls[u + 1]);
718 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
720 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
721 // Add a non-dynamic link
722 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
726 if (sequence != null)
728 sequenceMenu.add(linkMenu);
738 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
739 * "All" is added first, followed by a separator. Then add any annotation
740 * types associated with the current selection. Separate menus are built for
741 * the selected sequence group (if any), and the selected sequence.
743 * Some annotation rows are always rendered together - these can be identified
744 * by a common graphGroup property > -1. Only one of each group will be marked
745 * as visible (to avoid duplication of the display). For such groups we add a
746 * composite type name, e.g.
748 * IUPredWS (Long), IUPredWS (Short)
752 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
753 List<SequenceI> forSequences)
755 showMenu.removeAll();
756 hideMenu.removeAll();
758 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
759 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
760 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
762 showMenu.addSeparator();
763 hideMenu.addSeparator();
765 final AlignmentAnnotation[] annotations = ap.getAlignment()
766 .getAlignmentAnnotation();
769 * Find shown/hidden annotations types, distinguished by source (calcId),
770 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
771 * the insertion order, which is the order of the annotations on the
774 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
775 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
776 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
778 AlignmentAnnotationUtils.asList(annotations),
781 for (String calcId : hiddenTypes.keySet())
783 for (List<String> type : hiddenTypes.get(calcId))
785 addAnnotationTypeToShowHide(showMenu, forSequences,
786 calcId, type, false, true);
789 // grey out 'show annotations' if none are hidden
790 showMenu.setEnabled(!hiddenTypes.isEmpty());
792 for (String calcId : shownTypes.keySet())
794 for (List<String> type : shownTypes.get(calcId))
796 addAnnotationTypeToShowHide(hideMenu, forSequences,
797 calcId, type, false, false);
800 // grey out 'hide annotations' if none are shown
801 hideMenu.setEnabled(!shownTypes.isEmpty());
805 * Returns a list of sequences - either the current selection group (if there
806 * is one), else the specified single sequence.
811 protected List<SequenceI> getSequenceScope(SequenceI seq)
813 List<SequenceI> forSequences = null;
814 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
815 if (selectionGroup != null && selectionGroup.getSize() > 0)
817 forSequences = selectionGroup.getSequences();
821 forSequences = seq == null ? Collections.<SequenceI> emptyList()
822 : Arrays.asList(seq);
828 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
831 * @param showOrHideMenu
833 * @param forSequences
834 * the sequences whose annotations may be shown or hidden
839 * if true this is a special label meaning 'All'
840 * @param actionIsShow
841 * if true, the select menu item action is to show the annotation
844 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
845 final List<SequenceI> forSequences, String calcId,
846 final List<String> types, final boolean allTypes,
847 final boolean actionIsShow)
849 String label = types.toString(); // [a, b, c]
850 label = label.substring(1, label.length() - 1); // a, b, c
851 final JMenuItem item = new JMenuItem(label);
852 item.setToolTipText(calcId);
853 item.addActionListener(new java.awt.event.ActionListener()
856 public void actionPerformed(ActionEvent e)
858 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(), types,
859 forSequences, allTypes, actionIsShow);
863 showOrHideMenu.add(item);
866 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
869 // TODO: usability: thread off the generation of group url content so root
871 // sequence only URLs
872 // ID/regex match URLs
873 groupLinksMenu = new JMenu(
874 MessageManager.getString("action.group_link"));
875 JMenu[] linkMenus = new JMenu[]
876 { null, new JMenu(MessageManager.getString("action.ids")),
877 new JMenu(MessageManager.getString("action.sequences")),
878 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
885 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
886 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
887 Hashtable commonDbrefs = new Hashtable();
888 for (int sq = 0; sq < seqs.length; sq++)
891 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
892 .findPosition(sg.getEndRes());
893 // just collect ids from dataset sequence
894 // TODO: check if IDs collected from selecton group intersects with the
895 // current selection, too
896 SequenceI sqi = seqs[sq];
897 while (sqi.getDatasetSequence() != null)
899 sqi = sqi.getDatasetSequence();
901 DBRefEntry[] dbr = sqi.getDBRef();
902 if (dbr != null && dbr.length > 0)
904 for (int d = 0; d < dbr.length; d++)
906 String src = dbr[d].getSource(); // DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
907 Object[] sarray = (Object[]) commonDbrefs.get(src);
910 sarray = new Object[2];
911 sarray[0] = new int[]
913 sarray[1] = new String[seqs.length];
915 commonDbrefs.put(src, sarray);
918 if (((String[]) sarray[1])[sq] == null)
921 || (dbr[d].getMap().locateMappedRange(start, end) != null))
923 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
924 ((int[]) sarray[0])[0]++;
930 // now create group links for all distinct ID/sequence sets.
931 boolean addMenu = false; // indicates if there are any group links to give
933 for (int i = 0; i < groupLinks.size(); i++)
935 String link = groupLinks.elementAt(i).toString();
936 GroupUrlLink urlLink = null;
939 urlLink = new GroupUrlLink(link);
940 } catch (Exception foo)
942 Cache.log.error("Exception for GroupURLLink '" + link
947 if (!urlLink.isValid())
949 Cache.log.error(urlLink.getInvalidMessage());
952 final String label = urlLink.getLabel();
953 boolean usingNames = false;
954 // Now see which parts of the group apply for this URL
955 String ltarget = urlLink.getTarget(); // DBRefUtils.getCanonicalName(urlLink.getTarget());
956 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
957 String[] seqstr, ids; // input to makeUrl
960 int numinput = ((int[]) idset[0])[0];
961 String[] allids = ((String[]) idset[1]);
962 seqstr = new String[numinput];
963 ids = new String[numinput];
964 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
966 if (allids[sq] != null)
968 ids[idcount] = allids[sq];
969 seqstr[idcount++] = idandseqs[1][sq];
975 // just use the id/seq set
976 seqstr = idandseqs[1];
980 // and try and make the groupURL!
982 Object[] urlset = null;
985 urlset = urlLink.makeUrlStubs(ids, seqstr,
986 "FromJalview" + System.currentTimeMillis(), false);
987 } catch (UrlStringTooLongException e)
992 int type = urlLink.getGroupURLType() & 3;
993 // first two bits ofurlLink type bitfield are sequenceids and sequences
994 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
995 addshowLink(linkMenus[type], label
996 + (((type & 1) == 1) ? ("("
997 + (usingNames ? "Names" : ltarget) + ")") : ""),
1004 groupLinksMenu = new JMenu(
1005 MessageManager.getString("action.group_link"));
1006 for (int m = 0; m < linkMenus.length; m++)
1008 if (linkMenus[m] != null
1009 && linkMenus[m].getMenuComponentCount() > 0)
1011 groupLinksMenu.add(linkMenus[m]);
1015 groupMenu.add(groupLinksMenu);
1020 * add a show URL menu item to the given linkMenu
1024 * - menu label string
1028 private void addshowLink(JMenu linkMenu, String label, final String url)
1030 JMenuItem item = new JMenuItem(label);
1031 item.setToolTipText(MessageManager.formatMessage(
1032 "label.open_url_param", new Object[]
1034 item.addActionListener(new java.awt.event.ActionListener()
1037 public void actionPerformed(ActionEvent e)
1039 new Thread(new Runnable()
1056 * add a late bound groupURL item to the given linkMenu
1060 * - menu label string
1061 * @param urlgenerator
1062 * GroupURLLink used to generate URL
1064 * Object array returned from the makeUrlStubs function.
1066 private void addshowLink(JMenu linkMenu, String label,
1067 final GroupUrlLink urlgenerator, final Object[] urlstub)
1069 JMenuItem item = new JMenuItem(label);
1070 item.setToolTipText(MessageManager.formatMessage(
1071 "label.open_url_seqs_param",
1073 { urlgenerator.getUrl_prefix(),
1074 urlgenerator.getNumberInvolved(urlstub) }));
1075 // TODO: put in info about what is being sent.
1076 item.addActionListener(new java.awt.event.ActionListener()
1079 public void actionPerformed(ActionEvent e)
1081 new Thread(new Runnable()
1089 showLink(urlgenerator.constructFrom(urlstub));
1090 } catch (UrlStringTooLongException e)
1108 private void jbInit() throws Exception
1110 groupMenu.setText(MessageManager.getString("label.group"));
1111 groupMenu.setText(MessageManager.getString("label.selection"));
1112 groupName.setText(MessageManager.getString("label.name"));
1113 groupName.addActionListener(new java.awt.event.ActionListener()
1116 public void actionPerformed(ActionEvent e)
1118 groupName_actionPerformed();
1121 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1122 sequenceName.setText(MessageManager
1123 .getString("label.edit_name_description"));
1124 sequenceName.addActionListener(new java.awt.event.ActionListener()
1127 public void actionPerformed(ActionEvent e)
1129 sequenceName_actionPerformed();
1132 chooseAnnotations.setText(MessageManager
1133 .getString("label.choose_annotations") + "...");
1134 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1137 public void actionPerformed(ActionEvent e)
1139 chooseAnnotations_actionPerformed(e);
1142 sequenceDetails.setText(MessageManager
1143 .getString("label.sequence_details") + "...");
1144 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1147 public void actionPerformed(ActionEvent e)
1149 sequenceDetails_actionPerformed();
1152 sequenceSelDetails.setText(MessageManager
1153 .getString("label.sequence_details") + "...");
1155 .addActionListener(new java.awt.event.ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 sequenceSelectionDetails_actionPerformed();
1163 PIDColour.setFocusPainted(false);
1165 .setText(MessageManager.getString("action.remove_group"));
1166 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1169 public void actionPerformed(ActionEvent e)
1171 unGroupMenuItem_actionPerformed();
1174 createGroupMenuItem.setText(MessageManager
1175 .getString("action.create_group"));
1177 .addActionListener(new java.awt.event.ActionListener()
1180 public void actionPerformed(ActionEvent e)
1182 createGroupMenuItem_actionPerformed();
1186 outline.setText(MessageManager.getString("action.border_colour"));
1187 outline.addActionListener(new java.awt.event.ActionListener()
1190 public void actionPerformed(ActionEvent e)
1192 outline_actionPerformed();
1196 .setText(MessageManager.getString("label.nucleotide"));
1197 nucleotideMenuItem.addActionListener(new ActionListener()
1200 public void actionPerformed(ActionEvent e)
1202 nucleotideMenuItem_actionPerformed();
1205 colourMenu.setText(MessageManager.getString("label.group_colour"));
1206 showBoxes.setText(MessageManager.getString("action.boxes"));
1207 showBoxes.setState(true);
1208 showBoxes.addActionListener(new ActionListener()
1211 public void actionPerformed(ActionEvent e)
1213 showBoxes_actionPerformed();
1216 showText.setText(MessageManager.getString("action.text"));
1217 showText.setState(true);
1218 showText.addActionListener(new ActionListener()
1221 public void actionPerformed(ActionEvent e)
1223 showText_actionPerformed();
1226 showColourText.setText(MessageManager.getString("label.colour_text"));
1227 showColourText.addActionListener(new ActionListener()
1230 public void actionPerformed(ActionEvent e)
1232 showColourText_actionPerformed();
1235 displayNonconserved.setText(MessageManager
1236 .getString("label.show_non_conversed"));
1237 displayNonconserved.setState(true);
1238 displayNonconserved.addActionListener(new ActionListener()
1241 public void actionPerformed(ActionEvent e)
1243 showNonconserved_actionPerformed();
1246 editMenu.setText(MessageManager.getString("action.edit"));
1247 cut.setText(MessageManager.getString("action.cut"));
1248 cut.addActionListener(new ActionListener()
1251 public void actionPerformed(ActionEvent e)
1253 cut_actionPerformed();
1256 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1257 upperCase.addActionListener(new ActionListener()
1260 public void actionPerformed(ActionEvent e)
1265 copy.setText(MessageManager.getString("action.copy"));
1266 copy.addActionListener(new ActionListener()
1269 public void actionPerformed(ActionEvent e)
1271 copy_actionPerformed();
1274 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1275 lowerCase.addActionListener(new ActionListener()
1278 public void actionPerformed(ActionEvent e)
1283 toggle.setText(MessageManager.getString("label.toggle_case"));
1284 toggle.addActionListener(new ActionListener()
1287 public void actionPerformed(ActionEvent e)
1292 pdbMenu.setText(MessageManager
1293 .getString("label.associate_structure_with_sequence"));
1294 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1295 pdbFromFile.addActionListener(new ActionListener()
1298 public void actionPerformed(ActionEvent e)
1300 pdbFromFile_actionPerformed();
1304 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1305 enterPDB.addActionListener(new ActionListener()
1308 public void actionPerformed(ActionEvent e)
1310 enterPDB_actionPerformed();
1313 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1314 discoverPDB.addActionListener(new ActionListener()
1317 public void actionPerformed(ActionEvent e)
1319 discoverPDB_actionPerformed();
1322 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1324 seqShowAnnotationsMenu.setText(MessageManager
1325 .getString("label.show_annotations"));
1326 seqHideAnnotationsMenu.setText(MessageManager
1327 .getString("label.hide_annotations"));
1328 groupShowAnnotationsMenu.setText(MessageManager
1329 .getString("label.show_annotations"));
1330 groupHideAnnotationsMenu.setText(MessageManager
1331 .getString("label.hide_annotations"));
1332 sequenceFeature.setText(MessageManager
1333 .getString("label.create_sequence_feature"));
1334 sequenceFeature.addActionListener(new ActionListener()
1337 public void actionPerformed(ActionEvent e)
1339 sequenceFeature_actionPerformed();
1342 textColour.setText(MessageManager.getString("label.text_colour"));
1343 textColour.addActionListener(new ActionListener()
1346 public void actionPerformed(ActionEvent e)
1348 textColour_actionPerformed();
1351 jMenu1.setText(MessageManager.getString("label.group"));
1352 proteinStructureMenu.setText(MessageManager
1353 .getString("label.view_protein_structure"));
1354 proteinStructureMenu.addActionListener(new ActionListener()
1357 public void actionPerformed(ActionEvent actionEvent)
1359 SequenceI[] selectedSeqs = new SequenceI[]
1361 if (ap.av.getSelectionGroup() != null)
1363 selectedSeqs = ap.av.getSequenceSelection();
1365 new StructureChooser(selectedSeqs, sequence, ap);
1369 rnaStructureMenu.setText(MessageManager
1370 .getString("label.view_rna_structure"));
1372 // colStructureMenu.setText("Colour By Structure");
1373 editSequence.setText(MessageManager.getString("label.edit_sequence")
1375 editSequence.addActionListener(new ActionListener()
1378 public void actionPerformed(ActionEvent actionEvent)
1380 editSequence_actionPerformed(actionEvent);
1383 makeReferenceSeq.setText(MessageManager
1384 .getString("label.mark_as_representative"));
1385 makeReferenceSeq.addActionListener(new ActionListener()
1389 public void actionPerformed(ActionEvent actionEvent)
1391 makeReferenceSeq_actionPerformed(actionEvent);
1395 hideInsertions.setText(MessageManager.getString("label.hide_insertions"));
1396 hideInsertions.addActionListener(new ActionListener()
1400 public void actionPerformed(ActionEvent e)
1402 hideInsertions_actionPerformed(e);
1406 * annotationMenuItem.setText("By Annotation");
1407 * annotationMenuItem.addActionListener(new ActionListener() { public void
1408 * actionPerformed(ActionEvent actionEvent) {
1409 * annotationMenuItem_actionPerformed(actionEvent); } });
1411 groupMenu.add(sequenceSelDetails);
1414 add(rnaStructureMenu);
1415 add(proteinStructureMenu);
1418 add(hideInsertions);
1420 // annotations configuration panel suppressed for now
1421 // groupMenu.add(chooseAnnotations);
1424 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1425 * (if a selection group is in force).
1427 sequenceMenu.add(seqShowAnnotationsMenu);
1428 sequenceMenu.add(seqHideAnnotationsMenu);
1429 sequenceMenu.add(seqAddReferenceAnnotations);
1430 groupMenu.add(groupShowAnnotationsMenu);
1431 groupMenu.add(groupHideAnnotationsMenu);
1432 groupMenu.add(groupAddReferenceAnnotations);
1433 groupMenu.add(editMenu);
1434 groupMenu.add(outputMenu);
1435 groupMenu.add(sequenceFeature);
1436 groupMenu.add(createGroupMenuItem);
1437 groupMenu.add(unGroupMenuItem);
1438 groupMenu.add(jMenu1);
1439 sequenceMenu.add(sequenceName);
1440 sequenceMenu.add(sequenceDetails);
1441 sequenceMenu.add(makeReferenceSeq);
1442 colourMenu.add(textColour);
1443 colourMenu.add(noColourmenuItem);
1444 colourMenu.add(clustalColour);
1445 colourMenu.add(BLOSUM62Colour);
1446 colourMenu.add(PIDColour);
1447 colourMenu.add(zappoColour);
1448 colourMenu.add(taylorColour);
1449 colourMenu.add(hydrophobicityColour);
1450 colourMenu.add(helixColour);
1451 colourMenu.add(strandColour);
1452 colourMenu.add(turnColour);
1453 colourMenu.add(buriedColour);
1454 colourMenu.add(nucleotideMenuItem);
1455 if (ap.getAlignment().isNucleotide())
1457 // JBPNote - commented since the colourscheme isn't functional
1458 colourMenu.add(purinePyrimidineColour);
1460 colourMenu.add(userDefinedColour);
1462 if (UserDefinedColours.getUserColourSchemes() != null)
1464 Enumeration userColours = UserDefinedColours
1465 .getUserColourSchemes().keys();
1467 while (userColours.hasMoreElements())
1469 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1470 item.addActionListener(new ActionListener()
1473 public void actionPerformed(ActionEvent evt)
1475 userDefinedColour_actionPerformed(evt);
1478 colourMenu.add(item);
1482 colourMenu.addSeparator();
1483 colourMenu.add(abovePIDColour);
1484 colourMenu.add(conservationMenuItem);
1487 editMenu.add(editSequence);
1488 editMenu.add(upperCase);
1489 editMenu.add(lowerCase);
1490 editMenu.add(toggle);
1491 pdbMenu.add(pdbFromFile);
1492 // JBPNote: These shouldn't be added here - should appear in a generic
1493 // 'apply web service to this sequence menu'
1494 // pdbMenu.add(RNAFold);
1495 // pdbMenu.add(ContraFold);
1496 pdbMenu.add(enterPDB);
1497 pdbMenu.add(discoverPDB);
1498 jMenu1.add(groupName);
1499 jMenu1.add(colourMenu);
1500 jMenu1.add(showBoxes);
1501 jMenu1.add(showText);
1502 jMenu1.add(showColourText);
1503 jMenu1.add(outline);
1504 jMenu1.add(displayNonconserved);
1505 noColourmenuItem.setText(MessageManager.getString("label.none"));
1506 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1509 public void actionPerformed(ActionEvent e)
1511 noColourmenuItem_actionPerformed();
1515 clustalColour.setText(MessageManager
1516 .getString("label.clustalx_colours"));
1517 clustalColour.addActionListener(new java.awt.event.ActionListener()
1520 public void actionPerformed(ActionEvent e)
1522 clustalColour_actionPerformed();
1525 zappoColour.setText(MessageManager.getString("label.zappo"));
1526 zappoColour.addActionListener(new java.awt.event.ActionListener()
1529 public void actionPerformed(ActionEvent e)
1531 zappoColour_actionPerformed();
1534 taylorColour.setText(MessageManager.getString("label.taylor"));
1535 taylorColour.addActionListener(new java.awt.event.ActionListener()
1538 public void actionPerformed(ActionEvent e)
1540 taylorColour_actionPerformed();
1543 hydrophobicityColour.setText(MessageManager
1544 .getString("label.hydrophobicity"));
1545 hydrophobicityColour
1546 .addActionListener(new java.awt.event.ActionListener()
1549 public void actionPerformed(ActionEvent e)
1551 hydrophobicityColour_actionPerformed();
1554 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1555 helixColour.addActionListener(new java.awt.event.ActionListener()
1558 public void actionPerformed(ActionEvent e)
1560 helixColour_actionPerformed();
1563 strandColour.setText(MessageManager
1564 .getString("label.strand_propensity"));
1565 strandColour.addActionListener(new java.awt.event.ActionListener()
1568 public void actionPerformed(ActionEvent e)
1570 strandColour_actionPerformed();
1573 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1574 turnColour.addActionListener(new java.awt.event.ActionListener()
1577 public void actionPerformed(ActionEvent e)
1579 turnColour_actionPerformed();
1582 buriedColour.setText(MessageManager.getString("label.buried_index"));
1583 buriedColour.addActionListener(new java.awt.event.ActionListener()
1586 public void actionPerformed(ActionEvent e)
1588 buriedColour_actionPerformed();
1591 abovePIDColour.setText(MessageManager
1592 .getString("label.above_identity_percentage"));
1593 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1596 public void actionPerformed(ActionEvent e)
1598 abovePIDColour_actionPerformed();
1601 userDefinedColour.setText(MessageManager
1602 .getString("action.user_defined"));
1603 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1606 public void actionPerformed(ActionEvent e)
1608 userDefinedColour_actionPerformed(e);
1612 .setText(MessageManager.getString("label.percentage_identity"));
1613 PIDColour.addActionListener(new java.awt.event.ActionListener()
1616 public void actionPerformed(ActionEvent e)
1618 PIDColour_actionPerformed();
1621 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1622 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1625 public void actionPerformed(ActionEvent e)
1627 BLOSUM62Colour_actionPerformed();
1630 purinePyrimidineColour.setText(MessageManager
1631 .getString("label.purine_pyrimidine"));
1632 purinePyrimidineColour
1633 .addActionListener(new java.awt.event.ActionListener()
1636 public void actionPerformed(ActionEvent e)
1638 purinePyrimidineColour_actionPerformed();
1643 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1644 * public void actionPerformed(ActionEvent e) {
1645 * covariationColour_actionPerformed(); } });
1648 conservationMenuItem.setText(MessageManager
1649 .getString("label.conservation"));
1650 conservationMenuItem
1651 .addActionListener(new java.awt.event.ActionListener()
1654 public void actionPerformed(ActionEvent e)
1656 conservationMenuItem_actionPerformed();
1662 * Check for any annotations on the underlying dataset sequences (for the
1663 * current selection group) which are not 'on the alignment'.If any are found,
1664 * enable the option to add them to the alignment. The criteria for 'on the
1665 * alignment' is finding an alignment annotation on the alignment, matched on
1666 * calcId, label and sequenceRef.
1668 * A tooltip is also constructed that displays the source (calcId) and type
1669 * (label) of the annotations that can be added.
1672 * @param forSequences
1674 protected void configureReferenceAnnotationsMenu(
1675 JMenuItem menuItem, List<SequenceI> forSequences)
1677 menuItem.setEnabled(false);
1680 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1681 * Using TreeMap means calcIds are shown in alphabetical order.
1683 Map<String, String> tipEntries = new TreeMap<String, String>();
1684 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1685 AlignmentI al = this.ap.av.getAlignment();
1686 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1687 tipEntries, candidates, al);
1688 if (!candidates.isEmpty())
1690 StringBuilder tooltip = new StringBuilder(64);
1691 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1694 * Found annotations that could be added. Enable the menu item, and
1695 * configure its tooltip and action.
1697 menuItem.setEnabled(true);
1698 for (String calcId : tipEntries.keySet())
1700 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1702 String tooltipText = JvSwingUtils.wrapTooltip(true,
1703 tooltip.toString());
1704 menuItem.setToolTipText(tooltipText);
1706 menuItem.addActionListener(new ActionListener()
1709 public void actionPerformed(ActionEvent e)
1711 addReferenceAnnotations_actionPerformed(candidates);
1718 * Add annotations to the sequences and to the alignment.
1721 * a map whose keys are sequences on the alignment, and values a list
1722 * of annotations to add to each sequence
1724 protected void addReferenceAnnotations_actionPerformed(
1725 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1727 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1728 final AlignmentI alignment = this.ap.getAlignment();
1729 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1734 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1736 if (!ap.av.getAlignment().hasSeqrep())
1738 // initialise the display flags so the user sees something happen
1739 ap.av.setDisplayReferenceSeq(true);
1740 ap.av.setColourByReferenceSeq(true);
1741 ap.av.getAlignment().setSeqrep(sequence);
1745 if (ap.av.getAlignment().getSeqrep() == sequence)
1747 ap.av.getAlignment().setSeqrep(null);
1751 ap.av.getAlignment().setSeqrep(sequence);
1757 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1759 if (sequence != null)
1761 ColumnSelection cs = ap.av.getColumnSelection();
1764 cs = new ColumnSelection();
1766 cs.hideInsertionsFor(sequence);
1767 ap.av.setColumnSelection(cs);
1771 protected void sequenceSelectionDetails_actionPerformed()
1773 createSequenceDetailsReport(ap.av.getSequenceSelection());
1776 protected void sequenceDetails_actionPerformed()
1778 createSequenceDetailsReport(new SequenceI[]
1782 public void createSequenceDetailsReport(SequenceI[] sequences)
1784 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1785 StringBuffer contents = new StringBuffer();
1786 for (SequenceI seq : sequences)
1788 contents.append("<p><h2>"
1791 "label.create_sequence_details_report_annotation_for",
1793 { seq.getDisplayId(true) }) + "</h2></p><p>");
1794 new SequenceAnnotationReport(null)
1795 .createSequenceAnnotationReport(
1801 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1802 .getSeqPanel().seqCanvas.fr
1805 contents.append("</p>");
1807 cap.setText("<html>" + contents.toString() + "</html>");
1809 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1810 "label.sequence_details_for",
1811 (sequences.length == 1 ? new Object[]
1812 { sequences[0].getDisplayId(true) } : new Object[]
1813 { MessageManager.getString("label.selection") })), 500, 400);
1817 protected void showNonconserved_actionPerformed()
1819 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1824 * call to refresh view after settings change
1828 ap.updateAnnotation();
1829 ap.paintAlignment(true);
1831 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1840 protected void clustalColour_actionPerformed()
1842 SequenceGroup sg = getGroup();
1843 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1853 protected void zappoColour_actionPerformed()
1855 getGroup().cs = new ZappoColourScheme();
1865 protected void taylorColour_actionPerformed()
1867 getGroup().cs = new TaylorColourScheme();
1877 protected void hydrophobicityColour_actionPerformed()
1879 getGroup().cs = new HydrophobicColourScheme();
1889 protected void helixColour_actionPerformed()
1891 getGroup().cs = new HelixColourScheme();
1901 protected void strandColour_actionPerformed()
1903 getGroup().cs = new StrandColourScheme();
1913 protected void turnColour_actionPerformed()
1915 getGroup().cs = new TurnColourScheme();
1925 protected void buriedColour_actionPerformed()
1927 getGroup().cs = new BuriedColourScheme();
1937 public void nucleotideMenuItem_actionPerformed()
1939 getGroup().cs = new NucleotideColourScheme();
1943 protected void purinePyrimidineColour_actionPerformed()
1945 getGroup().cs = new PurinePyrimidineColourScheme();
1950 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1951 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1959 protected void abovePIDColour_actionPerformed()
1961 SequenceGroup sg = getGroup();
1967 if (abovePIDColour.isSelected())
1969 sg.cs.setConsensus(AAFrequency.calculate(
1970 sg.getSequences(ap.av.getHiddenRepSequences()),
1971 sg.getStartRes(), sg.getEndRes() + 1));
1973 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1976 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1978 SliderPanel.showPIDSlider();
1981 // remove PIDColouring
1983 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1995 protected void userDefinedColour_actionPerformed(ActionEvent e)
1997 SequenceGroup sg = getGroup();
1999 if (e.getSource().equals(userDefinedColour))
2001 new UserDefinedColours(ap, sg);
2005 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2006 .getUserColourSchemes().get(e.getActionCommand());
2014 * Open a panel where the user can choose which types of sequence annotation
2019 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2021 // todo correct way to guard against opening a duplicate panel?
2022 new AnnotationChooser(ap);
2031 protected void PIDColour_actionPerformed()
2033 SequenceGroup sg = getGroup();
2034 sg.cs = new PIDColourScheme();
2035 sg.cs.setConsensus(AAFrequency.calculate(
2036 sg.getSequences(ap.av.getHiddenRepSequences()),
2037 sg.getStartRes(), sg.getEndRes() + 1));
2047 protected void BLOSUM62Colour_actionPerformed()
2049 SequenceGroup sg = getGroup();
2051 sg.cs = new Blosum62ColourScheme();
2053 sg.cs.setConsensus(AAFrequency.calculate(
2054 sg.getSequences(ap.av.getHiddenRepSequences()),
2055 sg.getStartRes(), sg.getEndRes() + 1));
2066 protected void noColourmenuItem_actionPerformed()
2068 getGroup().cs = null;
2078 protected void conservationMenuItem_actionPerformed()
2080 SequenceGroup sg = getGroup();
2086 if (conservationMenuItem.isSelected())
2088 // JBPNote: Conservation name shouldn't be i18n translated
2089 Conservation c = new Conservation("Group",
2090 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2091 .getHiddenRepSequences()), sg.getStartRes(),
2092 sg.getEndRes() + 1);
2095 c.verdict(false, ap.av.getConsPercGaps());
2097 sg.cs.setConservation(c);
2099 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2100 SliderPanel.showConservationSlider();
2103 // remove ConservationColouring
2105 sg.cs.setConservation(null);
2111 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2113 SequenceGroup sg = getGroup();
2119 AnnotationColourGradient acg = new AnnotationColourGradient(
2120 sequence.getAnnotation()[0], null,
2121 AnnotationColourGradient.NO_THRESHOLD);
2123 acg.setPredefinedColours(true);
2135 protected void groupName_actionPerformed()
2138 SequenceGroup sg = getGroup();
2139 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2140 sg.getDescription(), " "
2141 + MessageManager.getString("label.group_name") + " ",
2142 MessageManager.getString("label.group_description") + " ",
2143 MessageManager.getString("label.edit_group_name_description"),
2151 sg.setName(dialog.getName());
2152 sg.setDescription(dialog.getDescription());
2157 * Get selection group - adding it to the alignment if necessary.
2159 * @return sequence group to operate on
2161 SequenceGroup getGroup()
2163 SequenceGroup sg = ap.av.getSelectionGroup();
2164 // this method won't add a new group if it already exists
2167 ap.av.getAlignment().addGroup(sg);
2179 void sequenceName_actionPerformed()
2181 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2182 sequence.getDescription(),
2183 " " + MessageManager.getString("label.sequence_name")
2185 MessageManager.getString("label.sequence_description") + " ",
2187 .getString("label.edit_sequence_name_description"),
2195 if (dialog.getName() != null)
2197 if (dialog.getName().indexOf(" ") > -1)
2203 .getString("label.spaces_converted_to_backslashes"),
2205 .getString("label.no_spaces_allowed_sequence_name"),
2206 JOptionPane.WARNING_MESSAGE);
2209 sequence.setName(dialog.getName().replace(' ', '_'));
2210 ap.paintAlignment(false);
2213 sequence.setDescription(dialog.getDescription());
2215 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2226 void unGroupMenuItem_actionPerformed()
2228 SequenceGroup sg = ap.av.getSelectionGroup();
2229 ap.av.getAlignment().deleteGroup(sg);
2230 ap.av.setSelectionGroup(null);
2234 void createGroupMenuItem_actionPerformed()
2236 getGroup(); // implicitly creates group - note - should apply defaults / use
2237 // standard alignment window logic for this
2247 protected void outline_actionPerformed()
2249 SequenceGroup sg = getGroup();
2250 Color col = JColorChooser.showDialog(this,
2251 MessageManager.getString("label.select_outline_colour"),
2256 sg.setOutlineColour(col);
2268 public void showBoxes_actionPerformed()
2270 getGroup().setDisplayBoxes(showBoxes.isSelected());
2280 public void showText_actionPerformed()
2282 getGroup().setDisplayText(showText.isSelected());
2292 public void showColourText_actionPerformed()
2294 getGroup().setColourText(showColourText.isSelected());
2298 public void showLink(String url)
2302 BrowserLauncher.openURL(url);
2303 } catch (Exception ex)
2305 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2306 MessageManager.getString("label.web_browser_not_found_unix"),
2307 MessageManager.getString("label.web_browser_not_found"),
2308 JOptionPane.WARNING_MESSAGE);
2310 ex.printStackTrace();
2314 void hideSequences(boolean representGroup)
2316 SequenceGroup sg = ap.av.getSelectionGroup();
2317 if (sg == null || sg.getSize() < 1)
2319 ap.av.hideSequence(new SequenceI[]
2324 ap.av.setSelectionGroup(null);
2328 ap.av.hideRepSequences(sequence, sg);
2333 int gsize = sg.getSize();
2334 SequenceI[] hseqs = sg.getSequences().toArray(new SequenceI[gsize]);
2336 ap.av.hideSequence(hseqs);
2337 // refresh(); TODO: ? needed ?
2338 ap.av.sendSelection();
2341 public void copy_actionPerformed()
2343 ap.alignFrame.copy_actionPerformed(null);
2346 public void cut_actionPerformed()
2348 ap.alignFrame.cut_actionPerformed(null);
2351 void changeCase(ActionEvent e)
2353 Object source = e.getSource();
2354 SequenceGroup sg = ap.av.getSelectionGroup();
2358 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2360 sg.getEndRes() + 1);
2365 if (source == toggle)
2367 description = MessageManager.getString("label.toggle_case");
2368 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2370 else if (source == upperCase)
2372 description = MessageManager.getString("label.to_upper_case");
2373 caseChange = ChangeCaseCommand.TO_UPPER;
2377 description = MessageManager.getString("label.to_lower_case");
2378 caseChange = ChangeCaseCommand.TO_LOWER;
2381 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2382 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2383 startEnd, caseChange);
2385 ap.alignFrame.addHistoryItem(caseCommand);
2387 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2393 public void outputText_actionPerformed(ActionEvent e)
2395 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2396 cap.setForInput(null);
2397 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2398 "label.alignment_output_command", new Object[]
2399 { e.getActionCommand() }), 600, 500);
2401 String[] omitHidden = null;
2403 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2404 // or we simply trust the user wants
2405 // wysiwig behaviour
2407 cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
2411 public void pdbFromFile_actionPerformed()
2413 JalviewFileChooser chooser = new JalviewFileChooser(
2414 Cache.getProperty("LAST_DIRECTORY"));
2415 chooser.setFileView(new jalview.io.JalviewFileView());
2416 chooser.setDialogTitle(MessageManager.formatMessage(
2417 "label.select_pdb_file_for", new Object[]
2418 { sequence.getDisplayId(false) }));
2419 chooser.setToolTipText(MessageManager.formatMessage(
2420 "label.load_pdb_file_associate_with_sequence", new Object[]
2421 { sequence.getDisplayId(false) }));
2423 int value = chooser.showOpenDialog(null);
2425 if (value == JalviewFileChooser.APPROVE_OPTION)
2427 String choice = chooser.getSelectedFile().getPath();
2428 Cache.setProperty("LAST_DIRECTORY", choice);
2429 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2430 AppletFormatAdapter.FILE, sequence, true,
2437 public void enterPDB_actionPerformed()
2439 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2440 MessageManager.getString("label.enter_pdb_id"),
2441 MessageManager.getString("label.enter_pdb_id"),
2442 JOptionPane.QUESTION_MESSAGE);
2444 if (id != null && id.length() > 0)
2446 PDBEntry entry = new PDBEntry();
2447 entry.setId(id.toUpperCase());
2448 sequence.getDatasetSequence().addPDBId(entry);
2452 public void discoverPDB_actionPerformed()
2455 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2457 : ap.av.getSequenceSelection());
2458 Thread discpdb = new Thread(new Runnable()
2464 new DBRefFetcher(sequences, ap.alignFrame)
2465 .fetchDBRefs(false);
2472 public void sequenceFeature_actionPerformed()
2474 SequenceGroup sg = ap.av.getSelectionGroup();
2480 int rsize = 0, gSize = sg.getSize();
2481 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2482 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2484 for (int i = 0; i < gSize; i++)
2486 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2487 int end = sg.findEndRes(sg.getSequenceAt(i));
2490 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2491 features[rsize] = new SequenceFeature(null, null, null, start, end,
2496 rseqs = new SequenceI[rsize];
2497 tfeatures = new SequenceFeature[rsize];
2498 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2499 System.arraycopy(features, 0, tfeatures, 0, rsize);
2500 features = tfeatures;
2502 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2503 features, true, ap))
2505 ap.alignFrame.setShowSeqFeatures(true);
2506 ap.highlightSearchResults(null);
2510 public void textColour_actionPerformed()
2512 SequenceGroup sg = getGroup();
2515 new TextColourChooser().chooseColour(ap, sg);
2519 public void colourByStructure(String pdbid)
2521 Annotation[] anots = ap.av.getStructureSelectionManager()
2522 .colourSequenceFromStructure(sequence, pdbid);
2524 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2525 "Coloured by " + pdbid, anots);
2527 ap.av.getAlignment().addAnnotation(an);
2528 an.createSequenceMapping(sequence, 0, true);
2529 // an.adjustForAlignment();
2530 ap.av.getAlignment().setAnnotationIndex(an, 0);
2532 ap.adjustAnnotationHeight();
2534 sequence.addAlignmentAnnotation(an);
2538 public void editSequence_actionPerformed(ActionEvent actionEvent)
2540 SequenceGroup sg = ap.av.getSelectionGroup();
2544 if (sequence == null)
2546 sequence = sg.getSequenceAt(0);
2549 EditNameDialog dialog = new EditNameDialog(
2550 sequence.getSequenceAsString(sg.getStartRes(),
2551 sg.getEndRes() + 1), null,
2552 MessageManager.getString("label.edit_sequence"), null,
2553 MessageManager.getString("label.edit_sequence"),
2558 EditCommand editCommand = new EditCommand(
2559 MessageManager.getString("label.edit_sequences"),
2560 Action.REPLACE, dialog.getName().replace(' ',
2561 ap.av.getGapCharacter()),
2562 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2563 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2565 ap.alignFrame.addHistoryItem(editCommand);
2567 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()