2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.analysis.AAFrequency;
\r
24 import jalview.analysis.AlignmentAnnotationUtils;
\r
25 import jalview.analysis.AlignmentUtils;
\r
26 import jalview.analysis.Conservation;
\r
27 import jalview.bin.JalviewLite;
\r
28 import jalview.commands.ChangeCaseCommand;
\r
29 import jalview.commands.EditCommand;
\r
30 import jalview.commands.EditCommand.Action;
\r
31 import jalview.datamodel.AlignmentAnnotation;
\r
32 import jalview.datamodel.AlignmentI;
\r
33 import jalview.datamodel.DBRefEntry;
\r
34 import jalview.datamodel.PDBEntry;
\r
35 import jalview.datamodel.SequenceFeature;
\r
36 import jalview.datamodel.SequenceGroup;
\r
37 import jalview.datamodel.SequenceI;
\r
38 import jalview.io.AppletFormatAdapter;
\r
39 import jalview.io.SequenceAnnotationReport;
\r
40 import jalview.schemes.Blosum62ColourScheme;
\r
41 import jalview.schemes.BuriedColourScheme;
\r
42 import jalview.schemes.ClustalxColourScheme;
\r
43 import jalview.schemes.HelixColourScheme;
\r
44 import jalview.schemes.HydrophobicColourScheme;
\r
45 import jalview.schemes.NucleotideColourScheme;
\r
46 import jalview.schemes.PIDColourScheme;
\r
47 import jalview.schemes.ResidueProperties;
\r
48 import jalview.schemes.StrandColourScheme;
\r
49 import jalview.schemes.TaylorColourScheme;
\r
50 import jalview.schemes.TurnColourScheme;
\r
51 import jalview.schemes.ZappoColourScheme;
\r
52 import jalview.util.DBRefUtils;
\r
53 import jalview.util.MessageManager;
\r
54 import jalview.util.UrlLink;
\r
56 import javax.swing.JCheckBoxMenuItem;
\r
57 import javax.swing.JFrame;
\r
58 import javax.swing.JMenu;
\r
59 import javax.swing.JMenuItem;
\r
60 import java.awt.event.ActionEvent;
\r
61 import java.awt.event.ActionListener;
\r
62 import java.awt.event.ItemEvent;
\r
63 import java.awt.event.ItemListener;
\r
64 import java.util.Arrays;
\r
65 import java.util.Collections;
\r
66 import java.util.LinkedHashMap;
\r
67 import java.util.List;
\r
68 import java.util.Map;
\r
69 import java.util.TreeMap;
\r
70 import java.util.Vector;
\r
72 import javax.swing.JPopupMenu;
\r
74 public class APopupMenu extends JPopupMenu implements
\r
75 ActionListener, ItemListener
\r
77 private static final String ALL_ANNOTATIONS = "All";
\r
79 JMenu groupMenu = new JMenu();
\r
81 JMenuItem editGroupName = new JMenuItem();
\r
83 protected JMenuItem clustalColour = new JMenuItem();
\r
85 protected JMenuItem zappoColour = new JMenuItem();
\r
87 protected JMenuItem taylorColour = new JMenuItem();
\r
89 protected JMenuItem hydrophobicityColour = new JMenuItem();
\r
91 protected JMenuItem helixColour = new JMenuItem();
\r
93 protected JMenuItem strandColour = new JMenuItem();
\r
95 protected JMenuItem turnColour = new JMenuItem();
\r
97 protected JMenuItem buriedColour = new JMenuItem();
\r
99 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
\r
101 protected JMenuItem userDefinedColour = new JMenuItem();
\r
103 protected JMenuItem PIDColour = new JMenuItem();
\r
105 protected JMenuItem BLOSUM62Colour = new JMenuItem();
\r
107 JMenuItem noColourmenuItem = new JMenuItem();
\r
109 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
\r
111 final AlignmentPanel ap;
\r
113 JMenuItem unGroupMenuItem = new JMenuItem();
\r
115 JMenuItem createGroupMenuItem = new JMenuItem();
\r
117 JMenuItem nucleotideMenuItem = new JMenuItem();
\r
119 JMenu colourMenu = new JMenu();
\r
121 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
\r
123 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
\r
125 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
\r
127 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
\r
129 JMenu seqShowAnnotationsMenu = new JMenu(
\r
130 MessageManager.getString("label.show_annotations"));
\r
132 JMenu seqHideAnnotationsMenu = new JMenu(
\r
133 MessageManager.getString("label.hide_annotations"));
\r
135 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
\r
136 MessageManager.getString("label.add_reference_annotations"));
\r
138 JMenu groupShowAnnotationsMenu = new JMenu(
\r
139 MessageManager.getString("label.show_annotations"));
\r
141 JMenu groupHideAnnotationsMenu = new JMenu(
\r
142 MessageManager.getString("label.hide_annotations"));
\r
144 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
\r
145 MessageManager.getString("label.add_reference_annotations"));
\r
147 JMenu editMenu = new JMenu(MessageManager.getString("action.edit"));
\r
149 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
\r
151 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
\r
153 JMenuItem toUpper = new JMenuItem(
\r
154 MessageManager.getString("label.to_upper_case"));
\r
156 JMenuItem toLower = new JMenuItem(
\r
157 MessageManager.getString("label.to_lower_case"));
\r
159 JMenuItem toggleCase = new JMenuItem(
\r
160 MessageManager.getString("label.toggle_case"));
\r
162 JMenu outputmenu = new JMenu();
\r
164 JMenu seqMenu = new JMenu();
\r
166 JMenuItem pdb = new JMenuItem();
\r
168 JMenuItem hideSeqs = new JMenuItem();
\r
170 JMenuItem repGroup = new JMenuItem();
\r
172 JMenuItem sequenceName = new JMenuItem(
\r
173 MessageManager.getString("label.edit_name_description"));
\r
175 JMenuItem sequenceFeature = new JMenuItem(
\r
176 MessageManager.getString("label.create_sequence_feature"));
\r
178 JMenuItem editSequence = new JMenuItem(
\r
179 MessageManager.getString("label.edit_sequence"));
\r
181 JMenuItem sequenceDetails = new JMenuItem(
\r
182 MessageManager.getString("label.sequence_details") + "...");
\r
184 JMenuItem selSeqDetails = new JMenuItem(
\r
185 MessageManager.getString("label.sequence_details") + "...");
\r
187 JMenuItem makeReferenceSeq = new JMenuItem();
\r
191 JMenuItem revealAll = new JMenuItem();
\r
193 JMenuItem revealSeq = new JMenuItem();
\r
196 * index of sequence to be revealed
\r
198 int revealSeq_index = -1;
\r
200 JMenu menu1 = new JMenu();
\r
202 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
\r
203 Vector<String> links)
\r
205 // /////////////////////////////////////////////////////////
\r
206 // If this is activated from the sequence panel, the user may want to
\r
207 // edit or annotate a particular residue. Therefore display the residue menu
\r
209 // If from the IDPanel, we must display the sequence menu
\r
210 // ////////////////////////////////////////////////////////
\r
218 } catch (Exception e)
\r
220 e.printStackTrace();
\r
223 for (int i = 0; i < AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
\r
225 JMenuItem item = new JMenuItem(
\r
226 AppletFormatAdapter.WRITEABLE_FORMATS[i]);
\r
228 item.addActionListener(this);
\r
229 outputmenu.add(item);
\r
232 buildAnnotationSubmenus();
\r
234 SequenceGroup sg = ap.av.getSelectionGroup();
\r
235 if (sg != null && sg.getSize() > 0)
\r
237 editGroupName.setLabel(MessageManager.formatMessage(
\r
238 "label.name_param", new Object[]
\r
239 { sg.getName() }));
\r
240 showText.setState(sg.getDisplayText());
\r
241 showColourText.setState(sg.getColourText());
\r
242 showBoxes.setState(sg.getDisplayBoxes());
\r
243 displayNonconserved.setState(sg.getShowNonconserved());
\r
244 if (!ap.av.getAlignment().getGroups().contains(sg))
\r
246 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
\r
247 groupMenu.remove(unGroupMenuItem);
\r
251 menu1.setLabel(MessageManager.getString("action.edit_group"));
\r
252 groupMenu.remove(createGroupMenuItem);
\r
262 if (links != null && links.size() > 0)
\r
264 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
\r
265 for (int i = 0; i < links.size(); i++)
\r
267 String link = links.elementAt(i);
\r
268 UrlLink urlLink = new UrlLink(link);
\r
269 if (!urlLink.isValid())
\r
271 System.err.println(urlLink.getInvalidMessage());
\r
274 final String target = urlLink.getTarget(); // link.substring(0,
\r
275 // link.indexOf("|"));
\r
276 final String label = urlLink.getLabel();
\r
277 if (seq != null && urlLink.isDynamic())
\r
280 // collect matching db-refs
\r
281 DBRefEntry[] dbr = DBRefUtils.selectRefs(
\r
282 seq.getDBRef(), new String[]
\r
284 // collect id string too
\r
285 String id = seq.getName();
\r
286 String descr = seq.getDescription();
\r
287 if (descr != null && descr.length() < 1)
\r
293 for (int r = 0; r < dbr.length; r++)
\r
295 if (id != null && dbr[r].getAccessionId().equals(id))
\r
297 // suppress duplicate link creation for the bare sequence ID
\r
298 // string with this link
\r
301 // create Bare ID link for this RUL
\r
302 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
\r
306 for (int u = 0; u < urls.length; u += 2)
\r
308 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
\r
315 // create Bare ID link for this RUL
\r
316 String[] urls = urlLink.makeUrls(id, true);
\r
319 for (int u = 0; u < urls.length; u += 2)
\r
321 addshowLink(linkMenu, label, urls[u + 1]);
\r
324 // addshowLink(linkMenu, target, url_pref + id + url_suff);
\r
326 // Now construct URLs from description but only try to do it for regex
\r
328 if (descr != null && urlLink.getRegexReplace() != null)
\r
330 // create link for this URL from description only if regex matches
\r
331 String[] urls = urlLink.makeUrls(descr, true);
\r
334 for (int u = 0; u < urls.length; u += 2)
\r
336 addshowLink(linkMenu, label, urls[u + 1]);
\r
343 addshowLink(linkMenu, target, urlLink.getUrl_prefix()); // link.substring(link.lastIndexOf("|")+1));
\r
346 * final String url;
\r
348 * if (link.indexOf("$SEQUENCE_ID$") > -1) { // Substitute SEQUENCE_ID
\r
349 * string and any matching database reference accessions String url_pref
\r
350 * = link.substring(link.indexOf("|") + 1,
\r
351 * link.indexOf("$SEQUENCE_ID$"));
\r
353 * String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
\r
354 * // collect matching db-refs DBRefEntry[] dbr =
\r
355 * DBRefUtils.selectRefs(seq.getDBRef(), new String[]{target}); //
\r
356 * collect id string too String id = seq.getName(); if (id.indexOf("|")
\r
357 * > -1) { id = id.substring(id.lastIndexOf("|") + 1); } if (dbr!=null)
\r
358 * { for (int r=0;r<dbr.length; r++) { if
\r
359 * (dbr[r].getAccessionId().equals(id)) { // suppress duplicate link
\r
360 * creation for the bare sequence ID string with this link id = null; }
\r
361 * addshowLink(linkMenu, dbr[r].getSource()+"|"+dbr[r].getAccessionId(),
\r
362 * target, url_pref+dbr[r].getAccessionId()+url_suff); } } if (id!=null)
\r
363 * { // create Bare ID link for this RUL addshowLink(linkMenu, target,
\r
364 * url_pref + id + url_suff); } } else { addshowLink(linkMenu, target,
\r
365 * link.substring(link.lastIndexOf("|")+1)); }
\r
368 if (linkMenu.getItemCount() > 0)
\r
372 seqMenu.add(linkMenu);
\r
380 // TODO: add group link menu entry here
\r
383 seqMenu.setLabel(seq.getName());
\r
384 if (seq == ap.av.getAlignment().getSeqrep())
\r
386 makeReferenceSeq.setLabel(MessageManager
\r
387 .getString("action.unmark_as_reference"));// Unmark
\r
388 // representative");
\r
392 makeReferenceSeq.setLabel(MessageManager
\r
393 .getString("action.set_as_reference")); // );
\r
395 repGroup.setLabel(MessageManager.formatMessage(
\r
396 "label.represent_group_with", new Object[]
\r
397 { seq.getName() }));
\r
404 if (!ap.av.hasHiddenRows())
\r
411 final int index = ap.av.getAlignment().findIndex(seq);
\r
413 if (ap.av.adjustForHiddenSeqs(index)
\r
414 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
\r
416 revealSeq_index = index;
\r
426 * Build menus for annotation types that may be shown or hidden, and for
\r
427 * 'reference annotations' that may be added to the alignment.
\r
429 private void buildAnnotationSubmenus()
\r
432 * First for the currently selected sequence (if there is one):
\r
434 final List<SequenceI> selectedSequence = (seq == null ? Collections
\r
435 .<SequenceI> emptyList() : Arrays.asList(seq));
\r
436 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
\r
437 seqHideAnnotationsMenu, selectedSequence);
\r
438 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
\r
442 * and repeat for the current selection group (if there is one):
\r
444 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
\r
445 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
\r
447 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
\r
448 groupHideAnnotationsMenu, selectedGroup);
\r
449 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
\r
454 * Determine whether or not to enable 'add reference annotations' menu item.
\r
455 * It is enable if there are any annotations, on any of the selected
\r
456 * sequences, which are not yet on the alignment (visible or not).
\r
459 * @param forSequences
\r
461 private void configureReferenceAnnotationsMenu(JMenuItem menuItem,
\r
462 List<SequenceI> forSequences)
\r
464 menuItem.setEnabled(false);
\r
467 * Temporary store to hold distinct calcId / type pairs for the tooltip.
\r
468 * Using TreeMap means calcIds are shown in alphabetical order.
\r
470 Map<String, String> tipEntries = new TreeMap<String, String>();
\r
471 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
\r
472 AlignmentI al = this.ap.av.getAlignment();
\r
473 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
\r
474 tipEntries, candidates, al);
\r
475 if (!candidates.isEmpty())
\r
477 StringBuilder tooltip = new StringBuilder(64);
\r
478 tooltip.append(MessageManager.getString("label.add_annotations_for"));
\r
481 * Found annotations that could be added. Enable the menu item, and
\r
482 * configure its action.
\r
484 menuItem.setEnabled(true);
\r
486 menuItem.addActionListener(new ActionListener()
\r
489 public void actionPerformed(ActionEvent e)
\r
491 addReferenceAnnotations_actionPerformed(candidates);
\r
498 * Add annotations to the sequences and to the alignment.
\r
500 * @param candidates
\r
501 * a map whose keys are sequences on the alignment, and values a list
\r
502 * of annotations to add to each sequence
\r
504 protected void addReferenceAnnotations_actionPerformed(
\r
505 Map<SequenceI, List<AlignmentAnnotation>> candidates)
\r
507 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
\r
508 final AlignmentI alignment = this.ap.getAlignment();
\r
509 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
\r
515 * add a show URL menu item to the given linkMenu
\r
519 * - menu label string
\r
523 private void addshowLink(JMenu linkMenu, final String target,
\r
526 addshowLink(linkMenu, target, target, url);
\r
530 * add a show URL menu item to the given linkMenu
\r
534 * - URL target window
\r
536 * - menu label string
\r
540 private void addshowLink(JMenu linkMenu, final String target,
\r
541 final String label, final String url)
\r
543 JMenuItem item = new JMenuItem(label);
\r
544 item.addActionListener(new java.awt.event.ActionListener()
\r
546 public void actionPerformed(ActionEvent e)
\r
548 ap.alignFrame.showURL(url, target);
\r
551 linkMenu.add(item);
\r
554 public void itemStateChanged(ItemEvent evt)
\r
556 if (evt.getSource() == abovePIDColour)
\r
558 abovePIDColour_itemStateChanged();
\r
560 else if (evt.getSource() == showColourText)
\r
562 showColourText_itemStateChanged();
\r
564 else if (evt.getSource() == showText)
\r
566 showText_itemStateChanged();
\r
568 else if (evt.getSource() == showBoxes)
\r
570 showBoxes_itemStateChanged();
\r
572 else if (evt.getSource() == displayNonconserved)
\r
574 this.showNonconserved_itemStateChanged();
\r
578 public void actionPerformed(ActionEvent evt)
\r
580 Object source = evt.getSource();
\r
581 if (source == clustalColour)
\r
583 clustalColour_actionPerformed();
\r
585 else if (source == zappoColour)
\r
587 zappoColour_actionPerformed();
\r
589 else if (source == taylorColour)
\r
591 taylorColour_actionPerformed();
\r
593 else if (source == hydrophobicityColour)
\r
595 hydrophobicityColour_actionPerformed();
\r
597 else if (source == helixColour)
\r
599 helixColour_actionPerformed();
\r
601 else if (source == strandColour)
\r
603 strandColour_actionPerformed();
\r
605 else if (source == turnColour)
\r
607 turnColour_actionPerformed();
\r
609 else if (source == buriedColour)
\r
611 buriedColour_actionPerformed();
\r
613 else if (source == nucleotideMenuItem)
\r
615 nucleotideMenuItem_actionPerformed();
\r
618 else if (source == userDefinedColour)
\r
620 userDefinedColour_actionPerformed();
\r
622 else if (source == PIDColour)
\r
624 PIDColour_actionPerformed();
\r
626 else if (source == BLOSUM62Colour)
\r
628 BLOSUM62Colour_actionPerformed();
\r
630 else if (source == noColourmenuItem)
\r
632 noColourmenuItem_actionPerformed();
\r
634 else if (source == conservationMenuItem)
\r
636 conservationMenuItem_itemStateChanged();
\r
638 else if (source == unGroupMenuItem)
\r
640 unGroupMenuItem_actionPerformed();
\r
643 else if (source == createGroupMenuItem)
\r
645 createGroupMenuItem_actionPerformed();
\r
648 else if (source == sequenceName)
\r
652 else if (source == makeReferenceSeq)
\r
654 makeReferenceSeq_actionPerformed();
\r
656 else if (source == sequenceDetails)
\r
658 showSequenceDetails();
\r
660 else if (source == selSeqDetails)
\r
662 showSequenceSelectionDetails();
\r
664 else if (source == pdb)
\r
668 else if (source == hideSeqs)
\r
670 hideSequences(false);
\r
672 else if (source == repGroup)
\r
674 hideSequences(true);
\r
676 else if (source == revealSeq)
\r
678 ap.av.showSequence(revealSeq_index);
\r
680 else if (source == revealAll)
\r
682 ap.av.showAllHiddenSeqs();
\r
685 else if (source == editGroupName)
\r
687 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
\r
688 getGroup().getDescription(), " Group Name",
\r
689 "Group Description", ap.alignFrame,
\r
690 "Edit Group Name / Description", 500, 100, true);
\r
694 getGroup().setName(dialog.getName().replace(' ', '_'));
\r
695 getGroup().setDescription(dialog.getDescription());
\r
699 else if (source == copy)
\r
701 ap.alignFrame.copy_actionPerformed();
\r
703 else if (source == cut)
\r
705 ap.alignFrame.cut_actionPerformed();
\r
707 else if (source == editSequence)
\r
709 SequenceGroup sg = ap.av.getSelectionGroup();
\r
715 seq = sg.getSequenceAt(0);
\r
718 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
\r
719 sg.getStartRes(), sg.getEndRes() + 1), null,
\r
720 "Edit Sequence ", null,
\r
722 ap.alignFrame, "Edit Sequence", 500, 100, true);
\r
726 EditCommand editCommand = new EditCommand(MessageManager.getString("label.edit_sequences"),
\r
727 Action.REPLACE, dialog.getName().replace(' ',
\r
728 ap.av.getGapCharacter()),
\r
729 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
\r
730 sg.getStartRes(), sg.getEndRes() + 1,
\r
731 ap.av.getAlignment());
\r
733 ap.alignFrame.addHistoryItem(editCommand);
\r
735 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
\r
740 else if (source == toUpper || source == toLower || source == toggleCase)
\r
742 SequenceGroup sg = ap.av.getSelectionGroup();
\r
745 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
\r
746 sg.getStartRes(), sg.getEndRes() + 1);
\r
748 String description;
\r
751 if (source == toggleCase)
\r
753 description = "Toggle Case";
\r
754 caseChange = ChangeCaseCommand.TOGGLE_CASE;
\r
756 else if (source == toUpper)
\r
758 description = "To Upper Case";
\r
759 caseChange = ChangeCaseCommand.TO_UPPER;
\r
763 description = "To Lower Case";
\r
764 caseChange = ChangeCaseCommand.TO_LOWER;
\r
767 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
\r
768 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
\r
769 startEnd, caseChange);
\r
771 ap.alignFrame.addHistoryItem(caseCommand);
\r
773 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
\r
778 else if (source == sequenceFeature)
\r
780 SequenceGroup sg = ap.av.getSelectionGroup();
\r
786 int rsize = 0, gSize = sg.getSize();
\r
787 SequenceI[] rseqs, seqs = new SequenceI[gSize];
\r
788 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
\r
790 for (int i = 0; i < gSize; i++)
\r
792 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
\r
793 int end = sg.findEndRes(sg.getSequenceAt(i));
\r
796 seqs[rsize] = sg.getSequenceAt(i);
\r
797 features[rsize] = new SequenceFeature(null, null, null, start,
\r
802 rseqs = new SequenceI[rsize];
\r
803 tfeatures = new SequenceFeature[rsize];
\r
804 System.arraycopy(seqs, 0, rseqs, 0, rsize);
\r
805 System.arraycopy(features, 0, tfeatures, 0, rsize);
\r
806 features = tfeatures;
\r
809 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
\r
810 features, true, ap))
\r
812 ap.alignFrame.sequenceFeatures.setState(true);
\r
813 ap.av.setShowSequenceFeatures(true);;
\r
814 ap.highlightSearchResults(null);
\r
824 void outputText(ActionEvent e)
\r
826 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
828 JFrame frame = new JFrame();
\r
830 JalviewLite.addFrame(frame, MessageManager.formatMessage(
\r
831 "label.selection_output_command", new Object[]
\r
832 { e.getActionCommand() }), 600, 500);
\r
833 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
\r
834 // now returns a full copy of sequence data
\r
835 // TODO consider using getSequenceSelection instead here
\r
837 cap.setText(new AppletFormatAdapter().formatSequences(
\r
838 e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true));
\r
842 protected void showSequenceSelectionDetails()
\r
844 createSequenceDetailsReport(ap.av.getSequenceSelection());
\r
847 protected void showSequenceDetails()
\r
849 createSequenceDetailsReport(new SequenceI[]
\r
853 public void createSequenceDetailsReport(SequenceI[] sequences)
\r
856 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
\r
858 StringBuffer contents = new StringBuffer();
\r
859 for (SequenceI seq : sequences)
\r
861 contents.append(MessageManager.formatMessage(
\r
862 "label.annotation_for_displayid", new Object[]
\r
863 { seq.getDisplayId(true) }));
\r
864 new SequenceAnnotationReport(null)
\r
865 .createSequenceAnnotationReport(
\r
871 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.getMinMax()
\r
873 contents.append("</p>");
\r
875 JFrame frame = new JFrame();
\r
877 JalviewLite.addFrame(frame, "Sequence Details for "
\r
878 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
\r
879 : "Selection"), 600, 500);
\r
880 cap.setText(MessageManager.formatMessage("label.html_content",
\r
882 { contents.toString() }));
\r
887 EditNameDialog dialog = new EditNameDialog(seq.getName(),
\r
888 seq.getDescription(), " Sequence Name",
\r
889 "Sequence Description", ap.alignFrame,
\r
890 "Edit Sequence Name / Description", 500, 100, true);
\r
894 seq.setName(dialog.getName());
\r
895 seq.setDescription(dialog.getDescription());
\r
896 ap.paintAlignment(false);
\r
902 if (seq.getPDBId() != null)
\r
904 PDBEntry entry = seq.getPDBId().firstElement();
\r
906 // if (ap.av.applet.jmolAvailable)
\r
908 new AppletJmol(entry, new SequenceI[]
\r
909 { seq }, null, ap, AppletFormatAdapter.URL);
\r
913 // new MCview.AppletPDBViewer(entry, new SequenceI[]
\r
914 // { seq }, null, ap, AppletFormatAdapter.URL);
\r
920 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
921 cap.setText(MessageManager.getString("label.paste_pdb_file"));
\r
922 cap.setPDBImport(seq);
\r
923 JFrame frame = new JFrame();
\r
925 JalviewLite.addFrame(frame, MessageManager.formatMessage(
\r
926 "label.paste_pdb_file_for_sequence", new Object[]
\r
927 { seq.getName() }), 400, 300);
\r
931 private void jbInit() throws Exception
\r
933 groupMenu.setLabel(MessageManager.getString("label.selection"));
\r
934 sequenceFeature.addActionListener(this);
\r
936 editGroupName.addActionListener(this);
\r
937 unGroupMenuItem.setLabel(MessageManager
\r
938 .getString("action.remove_group"));
\r
939 unGroupMenuItem.addActionListener(this);
\r
941 createGroupMenuItem.setLabel(MessageManager
\r
942 .getString("action.create_group"));
\r
943 createGroupMenuItem.addActionListener(this);
\r
945 nucleotideMenuItem.setLabel(MessageManager
\r
946 .getString("label.nucleotide"));
\r
947 nucleotideMenuItem.addActionListener(this);
\r
948 conservationMenuItem.addItemListener(this);
\r
949 abovePIDColour.addItemListener(this);
\r
950 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
\r
951 showBoxes.setLabel(MessageManager.getString("action.boxes"));
\r
952 showBoxes.setState(true);
\r
953 showBoxes.addItemListener(this);
\r
954 sequenceName.addActionListener(this);
\r
955 sequenceDetails.addActionListener(this);
\r
956 selSeqDetails.addActionListener(this);
\r
957 displayNonconserved.setLabel(MessageManager
\r
958 .getString("label.show_non_conversed"));
\r
959 displayNonconserved.setState(false);
\r
960 displayNonconserved.addItemListener(this);
\r
961 showText.setLabel(MessageManager.getString("action.text"));
\r
962 showText.addItemListener(this);
\r
963 showColourText.setLabel(MessageManager.getString("label.colour_text"));
\r
964 showColourText.addItemListener(this);
\r
965 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
\r
966 seqMenu.setLabel(MessageManager.getString("label.sequence"));
\r
967 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
\r
968 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
\r
969 repGroup.setLabel(MessageManager.formatMessage(
\r
970 "label.represent_group_with", new Object[]
\r
972 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
\r
973 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
\r
974 menu1.setLabel(MessageManager.getString("label.group") + ":");
\r
977 this.add(hideSeqs);
\r
978 this.add(revealSeq);
\r
979 this.add(revealAll);
\r
980 // groupMenu.add(selSeqDetails);
\r
981 groupMenu.add(groupShowAnnotationsMenu);
\r
982 groupMenu.add(groupHideAnnotationsMenu);
\r
983 groupMenu.add(groupAddReferenceAnnotations);
\r
984 groupMenu.add(editMenu);
\r
985 groupMenu.add(outputmenu);
\r
986 groupMenu.add(sequenceFeature);
\r
987 groupMenu.add(createGroupMenuItem);
\r
988 groupMenu.add(unGroupMenuItem);
\r
989 groupMenu.add(menu1);
\r
991 colourMenu.add(noColourmenuItem);
\r
992 colourMenu.add(clustalColour);
\r
993 colourMenu.add(BLOSUM62Colour);
\r
994 colourMenu.add(PIDColour);
\r
995 colourMenu.add(zappoColour);
\r
996 colourMenu.add(taylorColour);
\r
997 colourMenu.add(hydrophobicityColour);
\r
998 colourMenu.add(helixColour);
\r
999 colourMenu.add(strandColour);
\r
1000 colourMenu.add(turnColour);
\r
1001 colourMenu.add(buriedColour);
\r
1002 colourMenu.add(nucleotideMenuItem);
\r
1003 colourMenu.add(userDefinedColour);
\r
1004 colourMenu.addSeparator();
\r
1005 colourMenu.add(abovePIDColour);
\r
1006 colourMenu.add(conservationMenuItem);
\r
1008 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
\r
1009 noColourmenuItem.addActionListener(this);
\r
1011 clustalColour.setLabel(MessageManager.getString("label.clustalx_colours"));
\r
1012 clustalColour.addActionListener(this);
\r
1013 zappoColour.setLabel(MessageManager.getString("label.zappo"));
\r
1014 zappoColour.addActionListener(this);
\r
1015 taylorColour.setLabel(MessageManager.getString("label.taylor"));
\r
1016 taylorColour.addActionListener(this);
\r
1017 hydrophobicityColour.setLabel(MessageManager.getString("label.hydrophobicity"));
\r
1018 hydrophobicityColour.addActionListener(this);
\r
1019 helixColour.setLabel(MessageManager.getString("label.helix_propensity"));
\r
1020 helixColour.addActionListener(this);
\r
1021 strandColour.setLabel(MessageManager.getString("label.strand_propensity"));
\r
1022 strandColour.addActionListener(this);
\r
1023 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
\r
1024 turnColour.addActionListener(this);
\r
1025 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
\r
1026 buriedColour.addActionListener(this);
\r
1027 abovePIDColour.setLabel(MessageManager.getString("label.above_identity_percentage"));
\r
1029 userDefinedColour.setLabel(MessageManager.getString("action.user_defined"));
\r
1030 userDefinedColour.addActionListener(this);
\r
1031 PIDColour.setLabel(MessageManager.getString("action.percentage_identity"));
\r
1032 PIDColour.addActionListener(this);
\r
1033 BLOSUM62Colour.setLabel("BLOSUM62");
\r
1034 BLOSUM62Colour.addActionListener(this);
\r
1035 conservationMenuItem.setLabel(MessageManager.getString("label.conservation"));
\r
1037 editMenu.add(copy);
\r
1038 copy.addActionListener(this);
\r
1039 editMenu.add(cut);
\r
1040 cut.addActionListener(this);
\r
1042 editMenu.add(editSequence);
\r
1043 editSequence.addActionListener(this);
\r
1045 editMenu.add(toUpper);
\r
1046 toUpper.addActionListener(this);
\r
1047 editMenu.add(toLower);
\r
1048 toLower.addActionListener(this);
\r
1049 editMenu.add(toggleCase);
\r
1050 seqMenu.add(seqShowAnnotationsMenu);
\r
1051 seqMenu.add(seqHideAnnotationsMenu);
\r
1052 seqMenu.add(seqAddReferenceAnnotations);
\r
1053 seqMenu.add(sequenceName);
\r
1054 seqMenu.add(makeReferenceSeq);
\r
1055 // seqMenu.add(sequenceDetails);
\r
1057 if (!ap.av.applet.useXtrnalSviewer)
\r
1061 seqMenu.add(repGroup);
\r
1062 menu1.add(editGroupName);
\r
1063 menu1.add(colourMenu);
\r
1064 menu1.add(showBoxes);
\r
1065 menu1.add(showText);
\r
1066 menu1.add(showColourText);
\r
1067 menu1.add(displayNonconserved);
\r
1068 toggleCase.addActionListener(this);
\r
1069 pdb.addActionListener(this);
\r
1070 hideSeqs.addActionListener(this);
\r
1071 repGroup.addActionListener(this);
\r
1072 revealAll.addActionListener(this);
\r
1073 revealSeq.addActionListener(this);
\r
1074 makeReferenceSeq.addActionListener(this);
\r
1079 ap.paintAlignment(true);
\r
1082 protected void clustalColour_actionPerformed()
\r
1084 SequenceGroup sg = getGroup();
\r
1085 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
\r
1089 protected void zappoColour_actionPerformed()
\r
1091 getGroup().cs = new ZappoColourScheme();
\r
1095 protected void taylorColour_actionPerformed()
\r
1097 getGroup().cs = new TaylorColourScheme();
\r
1101 protected void hydrophobicityColour_actionPerformed()
\r
1103 getGroup().cs = new HydrophobicColourScheme();
\r
1107 protected void helixColour_actionPerformed()
\r
1109 getGroup().cs = new HelixColourScheme();
\r
1113 protected void strandColour_actionPerformed()
\r
1115 getGroup().cs = new StrandColourScheme();
\r
1119 protected void turnColour_actionPerformed()
\r
1121 getGroup().cs = new TurnColourScheme();
\r
1125 protected void buriedColour_actionPerformed()
\r
1127 getGroup().cs = new BuriedColourScheme();
\r
1131 public void nucleotideMenuItem_actionPerformed()
\r
1133 getGroup().cs = new NucleotideColourScheme();
\r
1137 protected void abovePIDColour_itemStateChanged()
\r
1139 SequenceGroup sg = getGroup();
\r
1140 if (sg.cs == null)
\r
1145 if (abovePIDColour.getState())
\r
1147 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
\r
1148 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
\r
1149 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
\r
1152 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
\r
1154 SliderPanel.showPIDSlider();
\r
1158 // remove PIDColouring
\r
1160 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
\r
1167 protected void userDefinedColour_actionPerformed()
\r
1169 new UserDefinedColours(ap, getGroup());
\r
1172 protected void PIDColour_actionPerformed()
\r
1174 SequenceGroup sg = getGroup();
\r
1175 sg.cs = new PIDColourScheme();
\r
1176 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
\r
1177 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
\r
1181 protected void BLOSUM62Colour_actionPerformed()
\r
1183 SequenceGroup sg = getGroup();
\r
1185 sg.cs = new Blosum62ColourScheme();
\r
1187 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
\r
1188 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
\r
1193 protected void noColourmenuItem_actionPerformed()
\r
1195 getGroup().cs = null;
\r
1199 protected void conservationMenuItem_itemStateChanged()
\r
1201 SequenceGroup sg = getGroup();
\r
1202 if (sg.cs == null)
\r
1207 if (conservationMenuItem.getState())
\r
1210 sg.cs.setConservation(Conservation.calculateConservation("Group",
\r
1211 ResidueProperties.propHash, 3, sg.getSequences(ap.av
\r
1212 .getHiddenRepSequences()), 0, ap.av.getAlignment()
\r
1213 .getWidth(), false, ap.av.getConsPercGaps(), false));
\r
1214 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
\r
1215 SliderPanel.showConservationSlider();
\r
1218 // remove ConservationColouring
\r
1220 sg.cs.setConservation(null);
\r
1226 SequenceGroup getGroup()
\r
1228 SequenceGroup sg = ap.av.getSelectionGroup();
\r
1230 // this method won't add a new group if it already exists
\r
1233 ap.av.getAlignment().addGroup(sg);
\r
1239 void unGroupMenuItem_actionPerformed()
\r
1241 SequenceGroup sg = ap.av.getSelectionGroup();
\r
1242 ap.av.getAlignment().deleteGroup(sg);
\r
1243 ap.av.setSelectionGroup(null);
\r
1244 ap.paintAlignment(true);
\r
1247 void createGroupMenuItem_actionPerformed()
\r
1249 getGroup(); // implicitly create group
\r
1253 public void showColourText_itemStateChanged()
\r
1255 getGroup().setColourText(showColourText.getState());
\r
1259 public void showText_itemStateChanged()
\r
1261 getGroup().setDisplayText(showText.getState());
\r
1264 public void makeReferenceSeq_actionPerformed()
\r
1266 if (!ap.av.getAlignment().hasSeqrep())
\r
1268 // initialise the display flags so the user sees something happen
\r
1269 ap.av.setDisplayReferenceSeq(true);
\r
1270 ap.av.setColourByReferenceSeq(true);
\r
1271 ap.av.getAlignment().setSeqrep(seq);
\r
1275 if (ap.av.getAlignment().getSeqrep() == seq)
\r
1277 ap.av.getAlignment().setSeqrep(null);
\r
1281 ap.av.getAlignment().setSeqrep(seq);
\r
1287 public void showNonconserved_itemStateChanged()
\r
1289 getGroup().setShowNonconserved(this.displayNonconserved.getState());
\r
1293 public void showBoxes_itemStateChanged()
\r
1295 getGroup().setDisplayBoxes(showBoxes.getState());
\r
1299 void hideSequences(boolean representGroup)
\r
1301 SequenceGroup sg = ap.av.getSelectionGroup();
\r
1302 if (sg == null || sg.getSize() < 1)
\r
1304 ap.av.hideSequence(new SequenceI[]
\r
1309 ap.av.setSelectionGroup(null);
\r
1311 if (representGroup)
\r
1313 ap.av.hideRepSequences(seq, sg);
\r
1318 int gsize = sg.getSize();
\r
1319 SequenceI[] hseqs;
\r
1321 hseqs = new SequenceI[gsize];
\r
1324 for (int i = 0; i < gsize; i++)
\r
1326 hseqs[index++] = sg.getSequenceAt(i);
\r
1329 ap.av.hideSequence(hseqs);
\r
1330 ap.av.sendSelection();
\r
1334 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
\r
1335 * "All" is added first, followed by a separator. Then add any annotation
\r
1336 * types associated with the current selection. Separate menus are built for
\r
1337 * the selected sequence group (if any), and the selected sequence.
\r
1339 * Some annotation rows are always rendered together - these can be identified
\r
1340 * by a common graphGroup property > -1. Only one of each group will be marked
\r
1341 * as visible (to avoid duplication of the display). For such groups we add a
\r
1342 * composite type name, e.g.
\r
1344 * IUPredWS (Long), IUPredWS (Short)
\r
1348 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
\r
1349 List<SequenceI> forSequences)
\r
1351 showMenu.removeAll();
\r
1352 hideMenu.removeAll();
\r
1354 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
\r
1355 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
\r
1356 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
\r
1358 showMenu.addSeparator();
\r
1359 hideMenu.addSeparator();
\r
1361 final AlignmentAnnotation[] annotations = ap.getAlignment()
\r
1362 .getAlignmentAnnotation();
\r
1365 * Find shown/hidden annotations types, distinguished by source (calcId),
\r
1366 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
\r
1367 * the insertion order, which is the order of the annotations on the
\r
1370 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
\r
1371 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
\r
1372 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
\r
1374 AlignmentAnnotationUtils.asList(annotations),
\r
1377 for (String calcId : hiddenTypes.keySet())
\r
1379 for (List<String> type : hiddenTypes.get(calcId))
\r
1381 addAnnotationTypeToShowHide(showMenu, forSequences,
\r
1382 calcId, type, false, true);
\r
1385 // grey out 'show annotations' if none are hidden
\r
1386 showMenu.setEnabled(!hiddenTypes.isEmpty());
\r
1388 for (String calcId : shownTypes.keySet())
\r
1390 for (List<String> type : shownTypes.get(calcId))
\r
1392 addAnnotationTypeToShowHide(hideMenu, forSequences,
\r
1393 calcId, type, false, false);
\r
1396 // grey out 'hide annotations' if none are shown
\r
1397 hideMenu.setEnabled(!shownTypes.isEmpty());
\r
1401 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
\r
1404 * @param showOrHideMenu
\r
1405 * the menu to add to
\r
1406 * @param forSequences
\r
1407 * the sequences whose annotations may be shown or hidden
\r
1410 * the label to add
\r
1412 * if true this is a special label meaning 'All'
\r
1413 * @param actionIsShow
\r
1414 * if true, the select menu item action is to show the annotation
\r
1417 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
\r
1418 final List<SequenceI> forSequences, String calcId,
\r
1419 final List<String> types, final boolean allTypes,
\r
1420 final boolean actionIsShow)
\r
1422 String label = types.toString(); // [a, b, c]
\r
1423 label = label.substring(1, label.length() - 1);
\r
1424 final JMenuItem item = new JMenuItem(label);
\r
1425 item.addActionListener(new java.awt.event.ActionListener()
\r
1428 public void actionPerformed(ActionEvent e)
\r
1430 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(), types,
\r
1431 forSequences, allTypes, actionIsShow);
\r
1435 showOrHideMenu.add(item);
\r