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.commands.ChangeCaseCommand;
28 import jalview.commands.EditCommand;
29 import jalview.commands.EditCommand.Action;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.Annotation;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.DBRefEntry;
35 import jalview.datamodel.PDBEntry;
36 import jalview.datamodel.Sequence;
37 import jalview.datamodel.SequenceFeature;
38 import jalview.datamodel.SequenceGroup;
39 import jalview.datamodel.SequenceI;
40 import jalview.io.FormatAdapter;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.schemes.AnnotationColourGradient;
43 import jalview.schemes.Blosum62ColourScheme;
44 import jalview.schemes.BuriedColourScheme;
45 import jalview.schemes.ClustalxColourScheme;
46 import jalview.schemes.HelixColourScheme;
47 import jalview.schemes.HydrophobicColourScheme;
48 import jalview.schemes.NucleotideColourScheme;
49 import jalview.schemes.PIDColourScheme;
50 import jalview.schemes.PurinePyrimidineColourScheme;
51 import jalview.schemes.ResidueProperties;
52 import jalview.schemes.StrandColourScheme;
53 import jalview.schemes.TaylorColourScheme;
54 import jalview.schemes.TurnColourScheme;
55 import jalview.schemes.UserColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.GroupUrlLink;
58 import jalview.util.GroupUrlLink.UrlStringTooLongException;
59 import jalview.util.MessageManager;
60 import jalview.util.UrlLink;
62 import java.awt.Color;
63 import java.awt.event.ActionEvent;
64 import java.awt.event.ActionListener;
65 import java.util.Arrays;
66 import java.util.Collections;
67 import java.util.Hashtable;
68 import java.util.LinkedHashMap;
69 import java.util.List;
71 import java.util.TreeMap;
72 import java.util.Vector;
74 import javax.swing.ButtonGroup;
75 import javax.swing.JCheckBoxMenuItem;
76 import javax.swing.JColorChooser;
77 import javax.swing.JMenu;
78 import javax.swing.JMenuItem;
79 import javax.swing.JOptionPane;
80 import javax.swing.JPopupMenu;
81 import javax.swing.JRadioButtonMenuItem;
87 * @version $Revision: 1.118 $
89 public class PopupMenu extends JPopupMenu
91 private static final String ALL_ANNOTATIONS = "All";
93 private static final String COMMA = ",";
95 JMenu groupMenu = new JMenu();
97 JMenuItem groupName = new JMenuItem();
99 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
113 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
115 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
117 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
125 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
127 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
129 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
133 JMenu sequenceMenu = new JMenu();
135 JMenuItem sequenceName = new JMenuItem();
137 JMenuItem sequenceDetails = new JMenuItem();
139 JMenuItem sequenceSelDetails = new JMenuItem();
141 JMenuItem makeReferenceSeq = new JMenuItem();
143 JMenuItem chooseAnnotations = new JMenuItem();
147 JMenuItem createGroupMenuItem = new JMenuItem();
149 JMenuItem unGroupMenuItem = new JMenuItem();
151 JMenuItem outline = new JMenuItem();
153 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
155 JMenu colourMenu = new JMenu();
157 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
159 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
163 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
165 JMenu editMenu = new JMenu();
167 JMenuItem cut = new JMenuItem();
169 JMenuItem copy = new JMenuItem();
171 JMenuItem upperCase = new JMenuItem();
173 JMenuItem lowerCase = new JMenuItem();
175 JMenuItem toggle = new JMenuItem();
177 JMenu pdbMenu = new JMenu();
179 JMenuItem pdbFromFile = new JMenuItem();
181 JMenuItem enterPDB = new JMenuItem();
183 JMenuItem discoverPDB = new JMenuItem();
185 JMenu outputMenu = new JMenu();
187 JMenu seqShowAnnotationsMenu = new JMenu();
189 JMenu seqHideAnnotationsMenu = new JMenu();
191 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
192 MessageManager.getString("label.add_reference_annotations"));
194 JMenu groupShowAnnotationsMenu = new JMenu();
196 JMenu groupHideAnnotationsMenu = new JMenu();
198 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
199 MessageManager.getString("label.add_reference_annotations"));
201 JMenuItem sequenceFeature = new JMenuItem();
203 JMenuItem textColour = new JMenuItem();
205 JMenu jMenu1 = new JMenu();
207 JMenuItem proteinStructureMenu = new JMenuItem();
209 JMenu rnaStructureMenu = new JMenu();
211 JMenuItem editSequence = new JMenuItem();
213 JMenu groupLinksMenu;
215 JMenuItem hideInsertions = new JMenuItem();
218 * Creates a new PopupMenu object.
225 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
227 this(ap, seq, links, null);
237 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
238 Vector links, Vector groupLinks)
240 // /////////////////////////////////////////////////////////
241 // If this is activated from the sequence panel, the user may want to
242 // edit or annotate a particular residue. Therefore display the residue menu
244 // If from the IDPanel, we must display the sequence menu
245 // ////////////////////////////////////////////////////////
249 ButtonGroup colours = new ButtonGroup();
250 colours.add(noColourmenuItem);
251 colours.add(clustalColour);
252 colours.add(zappoColour);
253 colours.add(taylorColour);
254 colours.add(hydrophobicityColour);
255 colours.add(helixColour);
256 colours.add(strandColour);
257 colours.add(turnColour);
258 colours.add(buriedColour);
259 colours.add(abovePIDColour);
260 colours.add(userDefinedColour);
261 colours.add(PIDColour);
262 colours.add(BLOSUM62Colour);
263 colours.add(purinePyrimidineColour);
264 colours.add(RNAInteractionColour);
266 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
268 JMenuItem item = new JMenuItem(
269 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
271 item.addActionListener(new java.awt.event.ActionListener()
274 public void actionPerformed(ActionEvent e)
276 outputText_actionPerformed(e);
280 outputMenu.add(item);
284 * Build menus for annotation types that may be shown or hidden, and for
285 * 'reference annotations' that may be added to the alignment. First for the
286 * currently selected sequence (if there is one):
288 final List<SequenceI> selectedSequence = (seq == null ? Collections
289 .<SequenceI> emptyList() : Arrays.asList(seq));
290 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
291 seqHideAnnotationsMenu, selectedSequence);
292 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
296 * And repeat for the current selection group (if there is one):
298 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
299 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
301 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
302 groupHideAnnotationsMenu, selectedGroup);
303 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
309 } catch (Exception e)
317 sequenceMenu.setText(sequence.getName());
318 if (seq == ap.av.getAlignment().getSeqrep())
320 makeReferenceSeq.setText("Unmark representative");
322 makeReferenceSeq.setText("Mark as representative");
325 if (ap.av.getAlignment().isNucleotide() == false)
327 remove(rnaStructureMenu);
330 if (ap.av.getAlignment().isNucleotide() == true)
332 AlignmentAnnotation[] aa = ap.av.getAlignment()
333 .getAlignmentAnnotation();
334 for (int i = 0; aa != null && i < aa.length; i++)
336 if (aa[i].isValidStruc() && aa[i].sequenceRef == null)
338 final String rnastruc = aa[i].getRNAStruc();
339 final String structureLine = aa[i].label + " (alignment)";
340 menuItem = new JMenuItem();
341 menuItem.setText(MessageManager.formatMessage(
342 "label.2d_rna_structure_line", new Object[]
344 menuItem.addActionListener(new java.awt.event.ActionListener()
347 public void actionPerformed(ActionEvent e)
349 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
350 rnastruc, seq.getName(), ap);
351 System.out.println("end");
354 rnaStructureMenu.add(menuItem);
359 if (seq.getAnnotation() != null)
361 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
362 for (int i = 0; i < seqAnno.length; i++)
364 if (seqAnno[i].isValidStruc())
366 final String rnastruc = seqAnno[i].getRNAStruc();
368 // TODO: make rnastrucF a bit more nice
369 menuItem = new JMenuItem();
370 menuItem.setText(MessageManager.formatMessage(
371 "label.2d_rna_sequence_name", new Object[]
373 menuItem.addActionListener(new java.awt.event.ActionListener()
376 public void actionPerformed(ActionEvent e)
378 // TODO: VARNA does'nt print gaps in the sequence
380 new AppVarna(seq.getName() + " structure", seq, seq
381 .getSequenceAsString(), rnastruc, seq.getName(),
385 rnaStructureMenu.add(menuItem);
391 menuItem = new JMenuItem(
392 MessageManager.getString("action.hide_sequences"));
393 menuItem.addActionListener(new java.awt.event.ActionListener()
396 public void actionPerformed(ActionEvent e)
398 hideSequences(false);
403 if (ap.av.getSelectionGroup() != null
404 && ap.av.getSelectionGroup().getSize() > 1)
406 menuItem = new JMenuItem(MessageManager.formatMessage(
407 "label.represent_group_with", new Object[]
409 menuItem.addActionListener(new java.awt.event.ActionListener()
412 public void actionPerformed(ActionEvent e)
417 sequenceMenu.add(menuItem);
420 if (ap.av.hasHiddenRows())
422 final int index = ap.av.getAlignment().findIndex(seq);
424 if (ap.av.adjustForHiddenSeqs(index)
425 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
427 menuItem = new JMenuItem(
428 MessageManager.getString("action.reveal_sequences"));
429 menuItem.addActionListener(new ActionListener()
432 public void actionPerformed(ActionEvent e)
434 ap.av.showSequence(index);
435 if (ap.overviewPanel != null)
437 ap.overviewPanel.updateOverviewImage();
445 // for the case when no sequences are even visible
446 if (ap.av.hasHiddenRows())
449 menuItem = new JMenuItem(
450 MessageManager.getString("action.reveal_all"));
451 menuItem.addActionListener(new ActionListener()
454 public void actionPerformed(ActionEvent e)
456 ap.av.showAllHiddenSeqs();
457 if (ap.overviewPanel != null)
459 ap.overviewPanel.updateOverviewImage();
469 SequenceGroup sg = ap.av.getSelectionGroup();
470 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
471 .getGroups().contains(sg) : false;
473 if (sg != null && sg.getSize() > 0)
475 groupName.setText(MessageManager.formatMessage("label.name_param",
478 groupName.setText(MessageManager
479 .getString("label.edit_name_and_description_current_group"));
481 if (sg.cs instanceof ZappoColourScheme)
483 zappoColour.setSelected(true);
485 else if (sg.cs instanceof TaylorColourScheme)
487 taylorColour.setSelected(true);
489 else if (sg.cs instanceof PIDColourScheme)
491 PIDColour.setSelected(true);
493 else if (sg.cs instanceof Blosum62ColourScheme)
495 BLOSUM62Colour.setSelected(true);
497 else if (sg.cs instanceof UserColourScheme)
499 userDefinedColour.setSelected(true);
501 else if (sg.cs instanceof HydrophobicColourScheme)
503 hydrophobicityColour.setSelected(true);
505 else if (sg.cs instanceof HelixColourScheme)
507 helixColour.setSelected(true);
509 else if (sg.cs instanceof StrandColourScheme)
511 strandColour.setSelected(true);
513 else if (sg.cs instanceof TurnColourScheme)
515 turnColour.setSelected(true);
517 else if (sg.cs instanceof BuriedColourScheme)
519 buriedColour.setSelected(true);
521 else if (sg.cs instanceof ClustalxColourScheme)
523 clustalColour.setSelected(true);
525 else if (sg.cs instanceof PurinePyrimidineColourScheme)
527 purinePyrimidineColour.setSelected(true);
531 * else if (sg.cs instanceof CovariationColourScheme) {
532 * covariationColour.setSelected(true); }
536 noColourmenuItem.setSelected(true);
539 if (sg.cs != null && sg.cs.conservationApplied())
541 conservationMenuItem.setSelected(true);
543 displayNonconserved.setSelected(sg.getShowNonconserved());
544 showText.setSelected(sg.getDisplayText());
545 showColourText.setSelected(sg.getColourText());
546 showBoxes.setSelected(sg.getDisplayBoxes());
547 // add any groupURLs to the groupURL submenu and make it visible
548 if (groupLinks != null && groupLinks.size() > 0)
550 buildGroupURLMenu(sg, groupLinks);
552 // Add a 'show all structures' for the current selection
553 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
554 SequenceI sqass = null;
555 for (SequenceI sq : ap.av.getSequenceSelection())
557 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
558 if (pes != null && pes.size() > 0)
560 reppdb.put(pes.get(0).getId(), pes.get(0));
561 for (PDBEntry pe : pes)
563 pdbe.put(pe.getId(), pe);
573 final PDBEntry[] pe = pdbe.values().toArray(
574 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
575 new PDBEntry[reppdb.size()]);
576 final JMenuItem gpdbview, rpdbview;
581 groupMenu.setVisible(false);
582 editMenu.setVisible(false);
587 createGroupMenuItem.setVisible(true);
588 unGroupMenuItem.setVisible(false);
589 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
593 createGroupMenuItem.setVisible(false);
594 unGroupMenuItem.setVisible(true);
595 jMenu1.setText(MessageManager.getString("action.edit_group"));
600 sequenceMenu.setVisible(false);
601 proteinStructureMenu.setVisible(false);
602 rnaStructureMenu.setVisible(false);
605 if (links != null && links.size() > 0)
608 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
609 Vector linkset = new Vector();
610 for (int i = 0; i < links.size(); i++)
612 String link = links.elementAt(i).toString();
613 UrlLink urlLink = null;
616 urlLink = new UrlLink(link);
617 } catch (Exception foo)
619 jalview.bin.Cache.log.error("Exception for URLLink '" + link
624 if (!urlLink.isValid())
626 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
629 final String label = urlLink.getLabel();
630 if (seq != null && urlLink.isDynamic())
633 // collect matching db-refs
634 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
635 seq.getDBRef(), new String[]
636 { urlLink.getTarget() });
637 // collect id string too
638 String id = seq.getName();
639 String descr = seq.getDescription();
640 if (descr != null && descr.length() < 1)
647 for (int r = 0; r < dbr.length; r++)
649 if (id != null && dbr[r].getAccessionId().equals(id))
651 // suppress duplicate link creation for the bare sequence ID
652 // string with this link
655 // create Bare ID link for this RUL
656 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
660 for (int u = 0; u < urls.length; u += 2)
662 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
664 linkset.addElement(urls[u] + "|" + urls[u + 1]);
665 addshowLink(linkMenu, label + "|" + urls[u],
674 // create Bare ID link for this RUL
675 String[] urls = urlLink.makeUrls(id, true);
678 for (int u = 0; u < urls.length; u += 2)
680 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
682 linkset.addElement(urls[u] + "|" + urls[u + 1]);
683 addshowLink(linkMenu, label, urls[u + 1]);
688 // Create urls from description but only for URL links which are regex
690 if (descr != null && urlLink.getRegexReplace() != null)
692 // create link for this URL from description where regex matches
693 String[] urls = urlLink.makeUrls(descr, true);
696 for (int u = 0; u < urls.length; u += 2)
698 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
700 linkset.addElement(urls[u] + "|" + urls[u + 1]);
701 addshowLink(linkMenu, label, urls[u + 1]);
709 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
711 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
712 // Add a non-dynamic link
713 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
717 if (sequence != null)
719 sequenceMenu.add(linkMenu);
729 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
730 * "All" is added first, followed by a separator. Then add any annotation
731 * types associated with the current selection. Separate menus are built for
732 * the selected sequence group (if any), and the selected sequence.
734 * Some annotation rows are always rendered together - these can be identified
735 * by a common graphGroup property > -1. Only one of each group will be marked
736 * as visible (to avoid duplication of the display). For such groups we add a
737 * composite type name, e.g.
739 * IUPredWS (Long), IUPredWS (Short)
743 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
744 List<SequenceI> forSequences)
746 showMenu.removeAll();
747 hideMenu.removeAll();
749 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
750 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
751 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
753 showMenu.addSeparator();
754 hideMenu.addSeparator();
756 final AlignmentAnnotation[] annotations = ap.getAlignment()
757 .getAlignmentAnnotation();
760 * Find shown/hidden annotations types, distinguished by source (calcId),
761 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
762 * the insertion order, which is the order of the annotations on the
765 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
766 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
767 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
769 AlignmentAnnotationUtils.asList(annotations),
772 for (String calcId : hiddenTypes.keySet())
774 for (List<String> type : hiddenTypes.get(calcId))
776 addAnnotationTypeToShowHide(showMenu, forSequences,
777 calcId, type, false, true);
780 // grey out 'show annotations' if none are hidden
781 showMenu.setEnabled(!hiddenTypes.isEmpty());
783 for (String calcId : shownTypes.keySet())
785 for (List<String> type : shownTypes.get(calcId))
787 addAnnotationTypeToShowHide(hideMenu, forSequences,
788 calcId, type, false, false);
791 // grey out 'hide annotations' if none are shown
792 hideMenu.setEnabled(!shownTypes.isEmpty());
796 * Returns a list of sequences - either the current selection group (if there
797 * is one), else the specified single sequence.
802 protected List<SequenceI> getSequenceScope(SequenceI seq)
804 List<SequenceI> forSequences = null;
805 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
806 if (selectionGroup != null && selectionGroup.getSize() > 0)
808 forSequences = selectionGroup.getSequences();
812 forSequences = seq == null ? Collections.<SequenceI> emptyList()
813 : Arrays.asList(seq);
819 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
822 * @param showOrHideMenu
824 * @param forSequences
825 * the sequences whose annotations may be shown or hidden
830 * if true this is a special label meaning 'All'
831 * @param actionIsShow
832 * if true, the select menu item action is to show the annotation
835 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
836 final List<SequenceI> forSequences, String calcId,
837 final List<String> types, final boolean allTypes,
838 final boolean actionIsShow)
840 String label = types.toString(); // [a, b, c]
841 label = label.substring(1, label.length() - 1); // a, b, c
842 final JMenuItem item = new JMenuItem(label);
843 item.setToolTipText(calcId);
844 item.addActionListener(new java.awt.event.ActionListener()
847 public void actionPerformed(ActionEvent e)
849 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(), types,
850 forSequences, allTypes, actionIsShow);
854 showOrHideMenu.add(item);
857 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
860 // TODO: usability: thread off the generation of group url content so root
862 // sequence only URLs
863 // ID/regex match URLs
864 groupLinksMenu = new JMenu(
865 MessageManager.getString("action.group_link"));
866 JMenu[] linkMenus = new JMenu[]
867 { null, new JMenu(MessageManager.getString("action.ids")),
868 new JMenu(MessageManager.getString("action.sequences")),
869 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
876 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
877 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
878 Hashtable commonDbrefs = new Hashtable();
879 for (int sq = 0; sq < seqs.length; sq++)
882 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
883 .findPosition(sg.getEndRes());
884 // just collect ids from dataset sequence
885 // TODO: check if IDs collected from selecton group intersects with the
886 // current selection, too
887 SequenceI sqi = seqs[sq];
888 while (sqi.getDatasetSequence() != null)
890 sqi = sqi.getDatasetSequence();
892 DBRefEntry[] dbr = sqi.getDBRef();
893 if (dbr != null && dbr.length > 0)
895 for (int d = 0; d < dbr.length; d++)
897 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
898 Object[] sarray = (Object[]) commonDbrefs.get(src);
901 sarray = new Object[2];
902 sarray[0] = new int[]
904 sarray[1] = new String[seqs.length];
906 commonDbrefs.put(src, sarray);
909 if (((String[]) sarray[1])[sq] == null)
912 || (dbr[d].getMap().locateMappedRange(start, end) != null))
914 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
915 ((int[]) sarray[0])[0]++;
921 // now create group links for all distinct ID/sequence sets.
922 boolean addMenu = false; // indicates if there are any group links to give
924 for (int i = 0; i < groupLinks.size(); i++)
926 String link = groupLinks.elementAt(i).toString();
927 GroupUrlLink urlLink = null;
930 urlLink = new GroupUrlLink(link);
931 } catch (Exception foo)
933 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
938 if (!urlLink.isValid())
940 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
943 final String label = urlLink.getLabel();
944 boolean usingNames = false;
945 // Now see which parts of the group apply for this URL
946 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
947 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
948 String[] seqstr, ids; // input to makeUrl
951 int numinput = ((int[]) idset[0])[0];
952 String[] allids = ((String[]) idset[1]);
953 seqstr = new String[numinput];
954 ids = new String[numinput];
955 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
957 if (allids[sq] != null)
959 ids[idcount] = allids[sq];
960 seqstr[idcount++] = idandseqs[1][sq];
966 // just use the id/seq set
967 seqstr = idandseqs[1];
971 // and try and make the groupURL!
973 Object[] urlset = null;
976 urlset = urlLink.makeUrlStubs(ids, seqstr,
977 "FromJalview" + System.currentTimeMillis(), false);
978 } catch (UrlStringTooLongException e)
983 int type = urlLink.getGroupURLType() & 3;
984 // first two bits ofurlLink type bitfield are sequenceids and sequences
985 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
986 addshowLink(linkMenus[type], label
987 + (((type & 1) == 1) ? ("("
988 + (usingNames ? "Names" : ltarget) + ")") : ""),
995 groupLinksMenu = new JMenu(
996 MessageManager.getString("action.group_link"));
997 for (int m = 0; m < linkMenus.length; m++)
999 if (linkMenus[m] != null
1000 && linkMenus[m].getMenuComponentCount() > 0)
1002 groupLinksMenu.add(linkMenus[m]);
1006 groupMenu.add(groupLinksMenu);
1011 * add a show URL menu item to the given linkMenu
1015 * - menu label string
1019 private void addshowLink(JMenu linkMenu, String label, final String url)
1021 JMenuItem item = new JMenuItem(label);
1022 item.setToolTipText(MessageManager.formatMessage(
1023 "label.open_url_param", new Object[]
1025 item.addActionListener(new java.awt.event.ActionListener()
1028 public void actionPerformed(ActionEvent e)
1030 new Thread(new Runnable()
1047 * add a late bound groupURL item to the given linkMenu
1051 * - menu label string
1052 * @param urlgenerator
1053 * GroupURLLink used to generate URL
1055 * Object array returned from the makeUrlStubs function.
1057 private void addshowLink(JMenu linkMenu, String label,
1058 final GroupUrlLink urlgenerator, final Object[] urlstub)
1060 JMenuItem item = new JMenuItem(label);
1061 item.setToolTipText(MessageManager.formatMessage(
1062 "label.open_url_seqs_param",
1064 { urlgenerator.getUrl_prefix(),
1065 urlgenerator.getNumberInvolved(urlstub) }));
1066 // TODO: put in info about what is being sent.
1067 item.addActionListener(new java.awt.event.ActionListener()
1070 public void actionPerformed(ActionEvent e)
1072 new Thread(new Runnable()
1080 showLink(urlgenerator.constructFrom(urlstub));
1081 } catch (UrlStringTooLongException e)
1099 private void jbInit() throws Exception
1101 groupMenu.setText(MessageManager.getString("label.group"));
1102 groupMenu.setText(MessageManager.getString("label.selection"));
1103 groupName.setText(MessageManager.getString("label.name"));
1104 groupName.addActionListener(new java.awt.event.ActionListener()
1107 public void actionPerformed(ActionEvent e)
1109 groupName_actionPerformed();
1112 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1113 sequenceName.setText(MessageManager
1114 .getString("label.edit_name_description"));
1115 sequenceName.addActionListener(new java.awt.event.ActionListener()
1118 public void actionPerformed(ActionEvent e)
1120 sequenceName_actionPerformed();
1123 chooseAnnotations.setText(MessageManager
1124 .getString("label.choose_annotations") + "...");
1125 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 chooseAnnotations_actionPerformed(e);
1133 sequenceDetails.setText(MessageManager
1134 .getString("label.sequence_details") + "...");
1135 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1138 public void actionPerformed(ActionEvent e)
1140 sequenceDetails_actionPerformed();
1143 sequenceSelDetails.setText(MessageManager
1144 .getString("label.sequence_details") + "...");
1146 .addActionListener(new java.awt.event.ActionListener()
1149 public void actionPerformed(ActionEvent e)
1151 sequenceSelectionDetails_actionPerformed();
1154 PIDColour.setFocusPainted(false);
1156 .setText(MessageManager.getString("action.remove_group"));
1157 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1160 public void actionPerformed(ActionEvent e)
1162 unGroupMenuItem_actionPerformed();
1165 createGroupMenuItem.setText(MessageManager
1166 .getString("action.create_group"));
1168 .addActionListener(new java.awt.event.ActionListener()
1171 public void actionPerformed(ActionEvent e)
1173 createGroupMenuItem_actionPerformed();
1177 outline.setText(MessageManager.getString("action.border_colour"));
1178 outline.addActionListener(new java.awt.event.ActionListener()
1181 public void actionPerformed(ActionEvent e)
1183 outline_actionPerformed();
1187 .setText(MessageManager.getString("label.nucleotide"));
1188 nucleotideMenuItem.addActionListener(new ActionListener()
1191 public void actionPerformed(ActionEvent e)
1193 nucleotideMenuItem_actionPerformed();
1196 colourMenu.setText(MessageManager.getString("label.group_colour"));
1197 showBoxes.setText(MessageManager.getString("action.boxes"));
1198 showBoxes.setState(true);
1199 showBoxes.addActionListener(new ActionListener()
1202 public void actionPerformed(ActionEvent e)
1204 showBoxes_actionPerformed();
1207 showText.setText(MessageManager.getString("action.text"));
1208 showText.setState(true);
1209 showText.addActionListener(new ActionListener()
1212 public void actionPerformed(ActionEvent e)
1214 showText_actionPerformed();
1217 showColourText.setText(MessageManager.getString("label.colour_text"));
1218 showColourText.addActionListener(new ActionListener()
1221 public void actionPerformed(ActionEvent e)
1223 showColourText_actionPerformed();
1226 displayNonconserved.setText(MessageManager
1227 .getString("label.show_non_conversed"));
1228 displayNonconserved.setState(true);
1229 displayNonconserved.addActionListener(new ActionListener()
1232 public void actionPerformed(ActionEvent e)
1234 showNonconserved_actionPerformed();
1237 editMenu.setText(MessageManager.getString("action.edit"));
1238 cut.setText(MessageManager.getString("action.cut"));
1239 cut.addActionListener(new ActionListener()
1242 public void actionPerformed(ActionEvent e)
1244 cut_actionPerformed();
1247 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1248 upperCase.addActionListener(new ActionListener()
1251 public void actionPerformed(ActionEvent e)
1256 copy.setText(MessageManager.getString("action.copy"));
1257 copy.addActionListener(new ActionListener()
1260 public void actionPerformed(ActionEvent e)
1262 copy_actionPerformed();
1265 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1266 lowerCase.addActionListener(new ActionListener()
1269 public void actionPerformed(ActionEvent e)
1274 toggle.setText(MessageManager.getString("label.toggle_case"));
1275 toggle.addActionListener(new ActionListener()
1278 public void actionPerformed(ActionEvent e)
1283 pdbMenu.setText(MessageManager
1284 .getString("label.associate_structure_with_sequence"));
1285 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1286 pdbFromFile.addActionListener(new ActionListener()
1289 public void actionPerformed(ActionEvent e)
1291 pdbFromFile_actionPerformed();
1295 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1296 enterPDB.addActionListener(new ActionListener()
1299 public void actionPerformed(ActionEvent e)
1301 enterPDB_actionPerformed();
1304 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1305 discoverPDB.addActionListener(new ActionListener()
1308 public void actionPerformed(ActionEvent e)
1310 discoverPDB_actionPerformed();
1313 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1315 seqShowAnnotationsMenu.setText(MessageManager
1316 .getString("label.show_annotations"));
1317 seqHideAnnotationsMenu.setText(MessageManager
1318 .getString("label.hide_annotations"));
1319 groupShowAnnotationsMenu.setText(MessageManager
1320 .getString("label.show_annotations"));
1321 groupHideAnnotationsMenu.setText(MessageManager
1322 .getString("label.hide_annotations"));
1323 sequenceFeature.setText(MessageManager
1324 .getString("label.create_sequence_feature"));
1325 sequenceFeature.addActionListener(new ActionListener()
1328 public void actionPerformed(ActionEvent e)
1330 sequenceFeature_actionPerformed();
1333 textColour.setText(MessageManager.getString("label.text_colour"));
1334 textColour.addActionListener(new ActionListener()
1337 public void actionPerformed(ActionEvent e)
1339 textColour_actionPerformed();
1342 jMenu1.setText(MessageManager.getString("label.group"));
1343 proteinStructureMenu.setText(MessageManager
1344 .getString("label.view_protein_structure"));
1345 proteinStructureMenu.addActionListener(new ActionListener()
1348 public void actionPerformed(ActionEvent actionEvent)
1350 SequenceI[] selectedSeqs = new SequenceI[]
1352 if (ap.av.getSelectionGroup() != null)
1354 selectedSeqs = ap.av.getSequenceSelection();
1356 new StructureChooser(selectedSeqs, sequence, ap);
1360 rnaStructureMenu.setText(MessageManager
1361 .getString("label.view_rna_structure"));
1363 // colStructureMenu.setText("Colour By Structure");
1364 editSequence.setText(MessageManager.getString("label.edit_sequence")
1366 editSequence.addActionListener(new ActionListener()
1369 public void actionPerformed(ActionEvent actionEvent)
1371 editSequence_actionPerformed(actionEvent);
1374 makeReferenceSeq.setText(MessageManager
1375 .getString("label.mark_as_representative"));
1376 makeReferenceSeq.addActionListener(new ActionListener()
1380 public void actionPerformed(ActionEvent actionEvent)
1382 makeReferenceSeq_actionPerformed(actionEvent);
1386 hideInsertions.setText(MessageManager.getString("label.hide_insertions"));
1387 hideInsertions.addActionListener(new ActionListener()
1391 public void actionPerformed(ActionEvent e)
1393 hideInsertions_actionPerformed(e);
1397 * annotationMenuItem.setText("By Annotation");
1398 * annotationMenuItem.addActionListener(new ActionListener() { public void
1399 * actionPerformed(ActionEvent actionEvent) {
1400 * annotationMenuItem_actionPerformed(actionEvent); } });
1402 groupMenu.add(sequenceSelDetails);
1405 add(rnaStructureMenu);
1406 add(proteinStructureMenu);
1409 add(hideInsertions);
1411 // annotations configuration panel suppressed for now
1412 // groupMenu.add(chooseAnnotations);
1415 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1416 * (if a selection group is in force).
1418 sequenceMenu.add(seqShowAnnotationsMenu);
1419 sequenceMenu.add(seqHideAnnotationsMenu);
1420 sequenceMenu.add(seqAddReferenceAnnotations);
1421 groupMenu.add(groupShowAnnotationsMenu);
1422 groupMenu.add(groupHideAnnotationsMenu);
1423 groupMenu.add(groupAddReferenceAnnotations);
1424 groupMenu.add(editMenu);
1425 groupMenu.add(outputMenu);
1426 groupMenu.add(sequenceFeature);
1427 groupMenu.add(createGroupMenuItem);
1428 groupMenu.add(unGroupMenuItem);
1429 groupMenu.add(jMenu1);
1430 sequenceMenu.add(sequenceName);
1431 sequenceMenu.add(sequenceDetails);
1432 sequenceMenu.add(makeReferenceSeq);
1433 colourMenu.add(textColour);
1434 colourMenu.add(noColourmenuItem);
1435 colourMenu.add(clustalColour);
1436 colourMenu.add(BLOSUM62Colour);
1437 colourMenu.add(PIDColour);
1438 colourMenu.add(zappoColour);
1439 colourMenu.add(taylorColour);
1440 colourMenu.add(hydrophobicityColour);
1441 colourMenu.add(helixColour);
1442 colourMenu.add(strandColour);
1443 colourMenu.add(turnColour);
1444 colourMenu.add(buriedColour);
1445 colourMenu.add(nucleotideMenuItem);
1446 if (ap.getAlignment().isNucleotide())
1448 // JBPNote - commented since the colourscheme isn't functional
1449 colourMenu.add(purinePyrimidineColour);
1451 colourMenu.add(userDefinedColour);
1453 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1455 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1456 .getUserColourSchemes().keys();
1458 while (userColours.hasMoreElements())
1460 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1461 item.addActionListener(new ActionListener()
1464 public void actionPerformed(ActionEvent evt)
1466 userDefinedColour_actionPerformed(evt);
1469 colourMenu.add(item);
1473 colourMenu.addSeparator();
1474 colourMenu.add(abovePIDColour);
1475 colourMenu.add(conservationMenuItem);
1478 editMenu.add(editSequence);
1479 editMenu.add(upperCase);
1480 editMenu.add(lowerCase);
1481 editMenu.add(toggle);
1482 pdbMenu.add(pdbFromFile);
1483 // JBPNote: These shouldn't be added here - should appear in a generic
1484 // 'apply web service to this sequence menu'
1485 // pdbMenu.add(RNAFold);
1486 // pdbMenu.add(ContraFold);
1487 pdbMenu.add(enterPDB);
1488 pdbMenu.add(discoverPDB);
1489 jMenu1.add(groupName);
1490 jMenu1.add(colourMenu);
1491 jMenu1.add(showBoxes);
1492 jMenu1.add(showText);
1493 jMenu1.add(showColourText);
1494 jMenu1.add(outline);
1495 jMenu1.add(displayNonconserved);
1496 noColourmenuItem.setText(MessageManager.getString("label.none"));
1497 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1500 public void actionPerformed(ActionEvent e)
1502 noColourmenuItem_actionPerformed();
1506 clustalColour.setText(MessageManager
1507 .getString("label.clustalx_colours"));
1508 clustalColour.addActionListener(new java.awt.event.ActionListener()
1511 public void actionPerformed(ActionEvent e)
1513 clustalColour_actionPerformed();
1516 zappoColour.setText(MessageManager.getString("label.zappo"));
1517 zappoColour.addActionListener(new java.awt.event.ActionListener()
1520 public void actionPerformed(ActionEvent e)
1522 zappoColour_actionPerformed();
1525 taylorColour.setText(MessageManager.getString("label.taylor"));
1526 taylorColour.addActionListener(new java.awt.event.ActionListener()
1529 public void actionPerformed(ActionEvent e)
1531 taylorColour_actionPerformed();
1534 hydrophobicityColour.setText(MessageManager
1535 .getString("label.hydrophobicity"));
1536 hydrophobicityColour
1537 .addActionListener(new java.awt.event.ActionListener()
1540 public void actionPerformed(ActionEvent e)
1542 hydrophobicityColour_actionPerformed();
1545 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1546 helixColour.addActionListener(new java.awt.event.ActionListener()
1549 public void actionPerformed(ActionEvent e)
1551 helixColour_actionPerformed();
1554 strandColour.setText(MessageManager
1555 .getString("label.strand_propensity"));
1556 strandColour.addActionListener(new java.awt.event.ActionListener()
1559 public void actionPerformed(ActionEvent e)
1561 strandColour_actionPerformed();
1564 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1565 turnColour.addActionListener(new java.awt.event.ActionListener()
1568 public void actionPerformed(ActionEvent e)
1570 turnColour_actionPerformed();
1573 buriedColour.setText(MessageManager.getString("label.buried_index"));
1574 buriedColour.addActionListener(new java.awt.event.ActionListener()
1577 public void actionPerformed(ActionEvent e)
1579 buriedColour_actionPerformed();
1582 abovePIDColour.setText(MessageManager
1583 .getString("label.above_identity_percentage"));
1584 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1587 public void actionPerformed(ActionEvent e)
1589 abovePIDColour_actionPerformed();
1592 userDefinedColour.setText(MessageManager
1593 .getString("action.user_defined"));
1594 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1597 public void actionPerformed(ActionEvent e)
1599 userDefinedColour_actionPerformed(e);
1603 .setText(MessageManager.getString("label.percentage_identity"));
1604 PIDColour.addActionListener(new java.awt.event.ActionListener()
1607 public void actionPerformed(ActionEvent e)
1609 PIDColour_actionPerformed();
1612 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1613 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1616 public void actionPerformed(ActionEvent e)
1618 BLOSUM62Colour_actionPerformed();
1621 purinePyrimidineColour.setText(MessageManager
1622 .getString("label.purine_pyrimidine"));
1623 purinePyrimidineColour
1624 .addActionListener(new java.awt.event.ActionListener()
1627 public void actionPerformed(ActionEvent e)
1629 purinePyrimidineColour_actionPerformed();
1634 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1635 * public void actionPerformed(ActionEvent e) {
1636 * covariationColour_actionPerformed(); } });
1639 conservationMenuItem.setText(MessageManager
1640 .getString("label.conservation"));
1641 conservationMenuItem
1642 .addActionListener(new java.awt.event.ActionListener()
1645 public void actionPerformed(ActionEvent e)
1647 conservationMenuItem_actionPerformed();
1653 * Check for any annotations on the underlying dataset sequences (for the
1654 * current selection group) which are not 'on the alignment'.If any are found,
1655 * enable the option to add them to the alignment. The criteria for 'on the
1656 * alignment' is finding an alignment annotation on the alignment, matched on
1657 * calcId, label and sequenceRef.
1659 * A tooltip is also constructed that displays the source (calcId) and type
1660 * (label) of the annotations that can be added.
1663 * @param forSequences
1665 protected void configureReferenceAnnotationsMenu(
1666 JMenuItem menuItem, List<SequenceI> forSequences)
1668 menuItem.setEnabled(false);
1671 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1672 * Using TreeMap means calcIds are shown in alphabetical order.
1674 Map<String, String> tipEntries = new TreeMap<String, String>();
1675 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1676 AlignmentI al = this.ap.av.getAlignment();
1677 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1678 tipEntries, candidates, al);
1679 if (!candidates.isEmpty())
1681 StringBuilder tooltip = new StringBuilder(64);
1682 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1685 * Found annotations that could be added. Enable the menu item, and
1686 * configure its tooltip and action.
1688 menuItem.setEnabled(true);
1689 for (String calcId : tipEntries.keySet())
1691 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1693 String tooltipText = JvSwingUtils.wrapTooltip(true,
1694 tooltip.toString());
1695 menuItem.setToolTipText(tooltipText);
1697 menuItem.addActionListener(new ActionListener()
1700 public void actionPerformed(ActionEvent e)
1702 addReferenceAnnotations_actionPerformed(candidates);
1709 * Add annotations to the sequences and to the alignment.
1712 * a map whose keys are sequences on the alignment, and values a list
1713 * of annotations to add to each sequence
1715 protected void addReferenceAnnotations_actionPerformed(
1716 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1718 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1719 final AlignmentI alignment = this.ap.getAlignment();
1720 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1725 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1727 if (!ap.av.getAlignment().hasSeqrep())
1729 // initialise the display flags so the user sees something happen
1730 ap.av.setDisplayReferenceSeq(true);
1731 ap.av.setColourByReferenceSeq(true);
1732 ap.av.getAlignment().setSeqrep(sequence);
1736 if (ap.av.getAlignment().getSeqrep() == sequence)
1738 ap.av.getAlignment().setSeqrep(null);
1742 ap.av.getAlignment().setSeqrep(sequence);
1748 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1750 if (sequence != null)
1752 ColumnSelection cs = ap.av.getColumnSelection();
1755 cs = new ColumnSelection();
1757 cs.hideInsertionsFor(sequence);
1758 ap.av.setColumnSelection(cs);
1762 protected void sequenceSelectionDetails_actionPerformed()
1764 createSequenceDetailsReport(ap.av.getSequenceSelection());
1767 protected void sequenceDetails_actionPerformed()
1769 createSequenceDetailsReport(new SequenceI[]
1773 public void createSequenceDetailsReport(SequenceI[] sequences)
1775 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1776 StringBuffer contents = new StringBuffer();
1777 for (SequenceI seq : sequences)
1779 contents.append("<p><h2>"
1782 "label.create_sequence_details_report_annotation_for",
1784 { seq.getDisplayId(true) }) + "</h2></p><p>");
1785 new SequenceAnnotationReport(null)
1786 .createSequenceAnnotationReport(
1792 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1793 .getSeqPanel().seqCanvas.fr
1796 contents.append("</p>");
1798 cap.setText("<html>" + contents.toString() + "</html>");
1800 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1801 "label.sequence_details_for",
1802 (sequences.length == 1 ? new Object[]
1803 { sequences[0].getDisplayId(true) } : new Object[]
1804 { MessageManager.getString("label.selection") })), 500, 400);
1808 protected void showNonconserved_actionPerformed()
1810 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1815 * call to refresh view after settings change
1819 ap.updateAnnotation();
1820 ap.paintAlignment(true);
1822 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1831 protected void clustalColour_actionPerformed()
1833 SequenceGroup sg = getGroup();
1834 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1844 protected void zappoColour_actionPerformed()
1846 getGroup().cs = new ZappoColourScheme();
1856 protected void taylorColour_actionPerformed()
1858 getGroup().cs = new TaylorColourScheme();
1868 protected void hydrophobicityColour_actionPerformed()
1870 getGroup().cs = new HydrophobicColourScheme();
1880 protected void helixColour_actionPerformed()
1882 getGroup().cs = new HelixColourScheme();
1892 protected void strandColour_actionPerformed()
1894 getGroup().cs = new StrandColourScheme();
1904 protected void turnColour_actionPerformed()
1906 getGroup().cs = new TurnColourScheme();
1916 protected void buriedColour_actionPerformed()
1918 getGroup().cs = new BuriedColourScheme();
1928 public void nucleotideMenuItem_actionPerformed()
1930 getGroup().cs = new NucleotideColourScheme();
1934 protected void purinePyrimidineColour_actionPerformed()
1936 getGroup().cs = new PurinePyrimidineColourScheme();
1941 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1942 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1950 protected void abovePIDColour_actionPerformed()
1952 SequenceGroup sg = getGroup();
1958 if (abovePIDColour.isSelected())
1960 sg.cs.setConsensus(AAFrequency.calculate(
1961 sg.getSequences(ap.av.getHiddenRepSequences()),
1962 sg.getStartRes(), sg.getEndRes() + 1));
1964 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1967 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1969 SliderPanel.showPIDSlider();
1972 // remove PIDColouring
1974 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1986 protected void userDefinedColour_actionPerformed(ActionEvent e)
1988 SequenceGroup sg = getGroup();
1990 if (e.getSource().equals(userDefinedColour))
1992 new UserDefinedColours(ap, sg);
1996 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1997 .getUserColourSchemes().get(e.getActionCommand());
2005 * Open a panel where the user can choose which types of sequence annotation
2010 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2012 // todo correct way to guard against opening a duplicate panel?
2013 new AnnotationChooser(ap);
2022 protected void PIDColour_actionPerformed()
2024 SequenceGroup sg = getGroup();
2025 sg.cs = new PIDColourScheme();
2026 sg.cs.setConsensus(AAFrequency.calculate(
2027 sg.getSequences(ap.av.getHiddenRepSequences()),
2028 sg.getStartRes(), sg.getEndRes() + 1));
2038 protected void BLOSUM62Colour_actionPerformed()
2040 SequenceGroup sg = getGroup();
2042 sg.cs = new Blosum62ColourScheme();
2044 sg.cs.setConsensus(AAFrequency.calculate(
2045 sg.getSequences(ap.av.getHiddenRepSequences()),
2046 sg.getStartRes(), sg.getEndRes() + 1));
2057 protected void noColourmenuItem_actionPerformed()
2059 getGroup().cs = null;
2069 protected void conservationMenuItem_actionPerformed()
2071 SequenceGroup sg = getGroup();
2077 if (conservationMenuItem.isSelected())
2079 // JBPNote: Conservation name shouldn't be i18n translated
2080 Conservation c = new Conservation("Group",
2081 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2082 .getHiddenRepSequences()), sg.getStartRes(),
2083 sg.getEndRes() + 1);
2086 c.verdict(false, ap.av.getConsPercGaps());
2088 sg.cs.setConservation(c);
2090 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2091 SliderPanel.showConservationSlider();
2094 // remove ConservationColouring
2096 sg.cs.setConservation(null);
2102 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2104 SequenceGroup sg = getGroup();
2110 AnnotationColourGradient acg = new AnnotationColourGradient(
2111 sequence.getAnnotation()[0], null,
2112 AnnotationColourGradient.NO_THRESHOLD);
2114 acg.setPredefinedColours(true);
2126 protected void groupName_actionPerformed()
2129 SequenceGroup sg = getGroup();
2130 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2131 sg.getDescription(), " "
2132 + MessageManager.getString("label.group_name") + " ",
2133 MessageManager.getString("label.group_description") + " ",
2134 MessageManager.getString("label.edit_group_name_description"),
2142 sg.setName(dialog.getName());
2143 sg.setDescription(dialog.getDescription());
2148 * Get selection group - adding it to the alignment if necessary.
2150 * @return sequence group to operate on
2152 SequenceGroup getGroup()
2154 SequenceGroup sg = ap.av.getSelectionGroup();
2155 // this method won't add a new group if it already exists
2158 ap.av.getAlignment().addGroup(sg);
2170 void sequenceName_actionPerformed()
2172 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2173 sequence.getDescription(),
2174 " " + MessageManager.getString("label.sequence_name")
2176 MessageManager.getString("label.sequence_description") + " ",
2178 .getString("label.edit_sequence_name_description"),
2186 if (dialog.getName() != null)
2188 if (dialog.getName().indexOf(" ") > -1)
2194 .getString("label.spaces_converted_to_backslashes"),
2196 .getString("label.no_spaces_allowed_sequence_name"),
2197 JOptionPane.WARNING_MESSAGE);
2200 sequence.setName(dialog.getName().replace(' ', '_'));
2201 ap.paintAlignment(false);
2204 sequence.setDescription(dialog.getDescription());
2206 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2217 void unGroupMenuItem_actionPerformed()
2219 SequenceGroup sg = ap.av.getSelectionGroup();
2220 ap.av.getAlignment().deleteGroup(sg);
2221 ap.av.setSelectionGroup(null);
2225 void createGroupMenuItem_actionPerformed()
2227 getGroup(); // implicitly creates group - note - should apply defaults / use
2228 // standard alignment window logic for this
2238 protected void outline_actionPerformed()
2240 SequenceGroup sg = getGroup();
2241 Color col = JColorChooser.showDialog(this,
2242 MessageManager.getString("label.select_outline_colour"),
2247 sg.setOutlineColour(col);
2259 public void showBoxes_actionPerformed()
2261 getGroup().setDisplayBoxes(showBoxes.isSelected());
2271 public void showText_actionPerformed()
2273 getGroup().setDisplayText(showText.isSelected());
2283 public void showColourText_actionPerformed()
2285 getGroup().setColourText(showColourText.isSelected());
2289 public void showLink(String url)
2293 jalview.util.BrowserLauncher.openURL(url);
2294 } catch (Exception ex)
2296 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2297 MessageManager.getString("label.web_browser_not_found_unix"),
2298 MessageManager.getString("label.web_browser_not_found"),
2299 JOptionPane.WARNING_MESSAGE);
2301 ex.printStackTrace();
2305 void hideSequences(boolean representGroup)
2307 SequenceGroup sg = ap.av.getSelectionGroup();
2308 if (sg == null || sg.getSize() < 1)
2310 ap.av.hideSequence(new SequenceI[]
2315 ap.av.setSelectionGroup(null);
2319 ap.av.hideRepSequences(sequence, sg);
2324 int gsize = sg.getSize();
2325 SequenceI[] hseqs = sg.getSequences().toArray(new SequenceI[gsize]);
2327 ap.av.hideSequence(hseqs);
2328 // refresh(); TODO: ? needed ?
2329 ap.av.sendSelection();
2332 public void copy_actionPerformed()
2334 ap.alignFrame.copy_actionPerformed(null);
2337 public void cut_actionPerformed()
2339 ap.alignFrame.cut_actionPerformed(null);
2342 void changeCase(ActionEvent e)
2344 Object source = e.getSource();
2345 SequenceGroup sg = ap.av.getSelectionGroup();
2349 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2351 sg.getEndRes() + 1);
2356 if (source == toggle)
2358 description = MessageManager.getString("label.toggle_case");
2359 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2361 else if (source == upperCase)
2363 description = MessageManager.getString("label.to_upper_case");
2364 caseChange = ChangeCaseCommand.TO_UPPER;
2368 description = MessageManager.getString("label.to_lower_case");
2369 caseChange = ChangeCaseCommand.TO_LOWER;
2372 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2373 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2374 startEnd, caseChange);
2376 ap.alignFrame.addHistoryItem(caseCommand);
2378 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2384 public void outputText_actionPerformed(ActionEvent e)
2386 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2387 cap.setForInput(null);
2388 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2389 "label.alignment_output_command", new Object[]
2390 { e.getActionCommand() }), 600, 500);
2392 String[] omitHidden = null;
2394 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2395 // or we simply trust the user wants
2396 // wysiwig behaviour
2398 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2402 public void pdbFromFile_actionPerformed()
2404 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2405 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2406 chooser.setFileView(new jalview.io.JalviewFileView());
2407 chooser.setDialogTitle(MessageManager.formatMessage(
2408 "label.select_pdb_file_for", new Object[]
2409 { sequence.getDisplayId(false) }));
2410 chooser.setToolTipText(MessageManager.formatMessage(
2411 "label.load_pdb_file_associate_with_sequence", new Object[]
2412 { sequence.getDisplayId(false) }));
2414 int value = chooser.showOpenDialog(null);
2416 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2418 String choice = chooser.getSelectedFile().getPath();
2419 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2420 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2421 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2428 public void enterPDB_actionPerformed()
2430 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2431 MessageManager.getString("label.enter_pdb_id"),
2432 MessageManager.getString("label.enter_pdb_id"),
2433 JOptionPane.QUESTION_MESSAGE);
2435 if (id != null && id.length() > 0)
2437 PDBEntry entry = new PDBEntry();
2438 entry.setId(id.toUpperCase());
2439 sequence.getDatasetSequence().addPDBId(entry);
2443 public void discoverPDB_actionPerformed()
2446 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2448 : ap.av.getSequenceSelection());
2449 Thread discpdb = new Thread(new Runnable()
2455 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2456 .fetchDBRefs(false);
2463 public void sequenceFeature_actionPerformed()
2465 SequenceGroup sg = ap.av.getSelectionGroup();
2471 int rsize = 0, gSize = sg.getSize();
2472 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2473 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2475 for (int i = 0; i < gSize; i++)
2477 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2478 int end = sg.findEndRes(sg.getSequenceAt(i));
2481 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2482 features[rsize] = new SequenceFeature(null, null, null, start, end,
2487 rseqs = new SequenceI[rsize];
2488 tfeatures = new SequenceFeature[rsize];
2489 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2490 System.arraycopy(features, 0, tfeatures, 0, rsize);
2491 features = tfeatures;
2493 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2494 features, true, ap))
2496 ap.alignFrame.setShowSeqFeatures(true);
2497 ap.highlightSearchResults(null);
2501 public void textColour_actionPerformed()
2503 SequenceGroup sg = getGroup();
2506 new TextColourChooser().chooseColour(ap, sg);
2510 public void colourByStructure(String pdbid)
2512 Annotation[] anots = ap.av.getStructureSelectionManager()
2513 .colourSequenceFromStructure(sequence, pdbid);
2515 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2516 "Coloured by " + pdbid, anots);
2518 ap.av.getAlignment().addAnnotation(an);
2519 an.createSequenceMapping(sequence, 0, true);
2520 // an.adjustForAlignment();
2521 ap.av.getAlignment().setAnnotationIndex(an, 0);
2523 ap.adjustAnnotationHeight();
2525 sequence.addAlignmentAnnotation(an);
2529 public void editSequence_actionPerformed(ActionEvent actionEvent)
2531 SequenceGroup sg = ap.av.getSelectionGroup();
2535 if (sequence == null)
2537 sequence = sg.getSequenceAt(0);
2540 EditNameDialog dialog = new EditNameDialog(
2541 sequence.getSequenceAsString(sg.getStartRes(),
2542 sg.getEndRes() + 1), null,
2543 MessageManager.getString("label.edit_sequence"), null,
2544 MessageManager.getString("label.edit_sequence"),
2549 EditCommand editCommand = new EditCommand(
2550 MessageManager.getString("label.edit_sequences"),
2551 Action.REPLACE, dialog.getName().replace(' ',
2552 ap.av.getGapCharacter()),
2553 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2554 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2556 ap.alignFrame.addHistoryItem(editCommand);
2558 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()