2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import java.awt.event.*;
28 import jalview.analysis.*;
29 import jalview.commands.*;
30 import jalview.datamodel.*;
32 import jalview.schemes.*;
33 import jalview.util.GroupUrlLink;
34 import jalview.util.GroupUrlLink.UrlStringTooLongException;
35 import jalview.util.UrlLink;
41 * @version $Revision: 1.118 $
43 public class PopupMenu extends JPopupMenu
45 JMenu groupMenu = new JMenu();
47 JMenuItem groupName = new JMenuItem();
49 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
51 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
53 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
55 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
57 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
59 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
61 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
63 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
65 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
67 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
69 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
71 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
73 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
75 //protected JRadioButtonMenuItem covariationColour = new JRadioButtonMenuItem();
77 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
79 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
83 JMenu sequenceMenu = new JMenu();
85 JMenuItem sequenceName = new JMenuItem();
89 JMenuItem unGroupMenuItem = new JMenuItem();
91 JMenuItem outline = new JMenuItem();
93 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
95 JMenu colourMenu = new JMenu();
97 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
99 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
101 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
103 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
105 JMenu editMenu = new JMenu();
107 JMenuItem cut = new JMenuItem();
109 JMenuItem copy = new JMenuItem();
111 JMenuItem upperCase = new JMenuItem();
113 JMenuItem lowerCase = new JMenuItem();
115 JMenuItem toggle = new JMenuItem();
117 JMenu pdbMenu = new JMenu();
119 JMenuItem pdbFromFile = new JMenuItem();
121 JMenuItem enterPDB = new JMenuItem();
123 JMenuItem discoverPDB = new JMenuItem();
125 JMenu outputMenu = new JMenu();
127 JMenuItem sequenceFeature = new JMenuItem();
129 JMenuItem textColour = new JMenuItem();
131 JMenu jMenu1 = new JMenu();
133 JMenu structureMenu = new JMenu();
135 JMenu viewStructureMenu = new JMenu();
137 // JMenu colStructureMenu = new JMenu();
138 JMenuItem editSequence = new JMenuItem();
140 // JMenuItem annotationMenuItem = new JMenuItem();
142 JMenu groupLinksMenu;
145 * Creates a new PopupMenu object.
152 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
154 this(ap, seq, links, null);
164 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links,
167 // /////////////////////////////////////////////////////////
168 // If this is activated from the sequence panel, the user may want to
169 // edit or annotate a particular residue. Therefore display the residue menu
171 // If from the IDPanel, we must display the sequence menu
172 // ////////////////////////////////////////////////////////
176 ButtonGroup colours = new ButtonGroup();
177 colours.add(noColourmenuItem);
178 colours.add(clustalColour);
179 colours.add(zappoColour);
180 colours.add(taylorColour);
181 colours.add(hydrophobicityColour);
182 colours.add(helixColour);
183 colours.add(strandColour);
184 colours.add(turnColour);
185 colours.add(buriedColour);
186 colours.add(abovePIDColour);
187 colours.add(userDefinedColour);
188 colours.add(PIDColour);
189 colours.add(BLOSUM62Colour);
190 colours.add(purinePyrimidineColour);
191 //colours.add(covariationColour);
193 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
195 JMenuItem item = new JMenuItem(
196 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
198 item.addActionListener(new java.awt.event.ActionListener()
200 public void actionPerformed(ActionEvent e)
202 outputText_actionPerformed(e);
206 outputMenu.add(item);
212 } catch (Exception e)
219 sequenceMenu.setText(sequence.getName());
222 if (seq.getDatasetSequence().getPDBId() != null
223 && seq.getDatasetSequence().getPDBId().size() > 0)
225 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
228 while (e.hasMoreElements())
230 final PDBEntry pdb = (PDBEntry) e.nextElement();
232 menuItem = new JMenuItem();
233 menuItem.setText(pdb.getId());
234 menuItem.addActionListener(new java.awt.event.ActionListener()
236 public void actionPerformed(ActionEvent e)
238 // TODO re JAL-860: optionally open dialog or provide a menu entry allowing user to open just one structure per sequence
239 new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[] { pdb })[0], null, ap);
240 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
244 viewStructureMenu.add(menuItem);
247 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
248 * menuItem.addActionListener(new java.awt.event.ActionListener() {
249 * public void actionPerformed(ActionEvent e) {
250 * colourByStructure(pdb.getId()); } });
251 * colStructureMenu.add(menuItem);
257 //TODO: Something to check if it's an RNA
258 //like: if(seq.getAnnotation()[0].annotations[0].secondaryStructure == 'S')
259 final SequenceI seqI = seq.getDatasetSequence();
261 menuItem = new JMenuItem();
262 menuItem.setText("RNA structure");
263 menuItem.addActionListener(new java.awt.event.ActionListener()
265 public void actionPerformed(ActionEvent e)
267 System.out.println("Call Varna "+seqI.getSequenceAsString());
268 new AppVarna(seqI.getSequenceAsString());
272 viewStructureMenu.add(menuItem);
274 //JAN structureMenu.remove(viewStructureMenu);
275 // structureMenu.remove(colStructureMenu);
278 menuItem = new JMenuItem("Hide Sequences");
279 menuItem.addActionListener(new java.awt.event.ActionListener()
281 public void actionPerformed(ActionEvent e)
283 hideSequences(false);
288 if (ap.av.getSelectionGroup() != null
289 && ap.av.getSelectionGroup().getSize() > 1)
291 menuItem = new JMenuItem("Represent Group with " + seq.getName());
292 menuItem.addActionListener(new java.awt.event.ActionListener()
294 public void actionPerformed(ActionEvent e)
299 sequenceMenu.add(menuItem);
302 if (ap.av.hasHiddenRows)
304 final int index = ap.av.alignment.findIndex(seq);
306 if (ap.av.adjustForHiddenSeqs(index)
307 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
309 menuItem = new JMenuItem("Reveal Sequences");
310 menuItem.addActionListener(new ActionListener()
312 public void actionPerformed(ActionEvent e)
314 ap.av.showSequence(index);
315 if (ap.overviewPanel != null)
317 ap.overviewPanel.updateOverviewImage();
324 menuItem = new JMenuItem("Reveal All");
325 menuItem.addActionListener(new ActionListener()
327 public void actionPerformed(ActionEvent e)
329 ap.av.showAllHiddenSeqs();
330 if (ap.overviewPanel != null)
332 ap.overviewPanel.updateOverviewImage();
342 SequenceGroup sg = ap.av.getSelectionGroup();
346 groupName.setText("Name: "+sg.getName());
347 groupName.setText("Edit name and description of current group.");
349 if (sg.cs instanceof ZappoColourScheme)
351 zappoColour.setSelected(true);
353 else if (sg.cs instanceof TaylorColourScheme)
355 taylorColour.setSelected(true);
357 else if (sg.cs instanceof PIDColourScheme)
359 PIDColour.setSelected(true);
361 else if (sg.cs instanceof Blosum62ColourScheme)
363 BLOSUM62Colour.setSelected(true);
365 else if (sg.cs instanceof UserColourScheme)
367 userDefinedColour.setSelected(true);
369 else if (sg.cs instanceof HydrophobicColourScheme)
371 hydrophobicityColour.setSelected(true);
373 else if (sg.cs instanceof HelixColourScheme)
375 helixColour.setSelected(true);
377 else if (sg.cs instanceof StrandColourScheme)
379 strandColour.setSelected(true);
381 else if (sg.cs instanceof TurnColourScheme)
383 turnColour.setSelected(true);
385 else if (sg.cs instanceof BuriedColourScheme)
387 buriedColour.setSelected(true);
389 else if (sg.cs instanceof ClustalxColourScheme)
391 clustalColour.setSelected(true);
393 else if (sg.cs instanceof PurinePyrimidineColourScheme)
395 purinePyrimidineColour.setSelected(true);
397 /* else if (sg.cs instanceof CovariationColourScheme)
399 covariationColour.setSelected(true);
403 noColourmenuItem.setSelected(true);
406 if (sg.cs != null && sg.cs.conservationApplied())
408 conservationMenuItem.setSelected(true);
410 displayNonconserved.setSelected(sg.getShowNonconserved());
411 showText.setSelected(sg.getDisplayText());
412 showColourText.setSelected(sg.getColourText());
413 showBoxes.setSelected(sg.getDisplayBoxes());
414 // add any groupURLs to the groupURL submenu and make it visible
415 if (groupLinks != null && groupLinks.size() > 0)
417 buildGroupURLMenu(sg, groupLinks);
419 // Add a 'show all structures' for the current selection
420 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
421 for (SequenceI sq: ap.av.getSequenceSelection())
423 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
425 for (PDBEntry pe: pes)
427 pdbe.put(pe.getId(), pe);
433 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
434 final JMenuItem gpdbview;
435 structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
436 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
437 gpdbview.addActionListener(new ActionListener()
441 public void actionPerformed(ActionEvent e)
443 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
450 groupMenu.setVisible(false);
451 editMenu.setVisible(false);
454 if (!ap.av.alignment.getGroups().contains(sg))
456 unGroupMenuItem.setVisible(false);
461 sequenceMenu.setVisible(false);
462 structureMenu.setVisible(false);
465 if (links != null && links.size() > 0)
468 JMenu linkMenu = new JMenu("Link");
469 Vector linkset = new Vector();
470 for (int i = 0; i < links.size(); i++)
472 String link = links.elementAt(i).toString();
473 UrlLink urlLink = null;
476 urlLink = new UrlLink(link);
477 } catch (Exception foo)
479 jalview.bin.Cache.log.error("Exception for URLLink '" + link
484 if (!urlLink.isValid())
486 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
489 final String label = urlLink.getLabel();
490 if (urlLink.isDynamic())
493 // collect matching db-refs
494 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
495 seq.getDBRef(), new String[]
496 { urlLink.getTarget() });
497 // collect id string too
498 String id = seq.getName();
499 String descr = seq.getDescription();
500 if (descr != null && descr.length() < 1)
507 for (int r = 0; r < dbr.length; r++)
509 if (id != null && dbr[r].getAccessionId().equals(id))
511 // suppress duplicate link creation for the bare sequence ID
512 // string with this link
515 // create Bare ID link for this RUL
516 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
520 for (int u = 0; u < urls.length; u += 2)
522 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
524 linkset.addElement(urls[u] + "|" + urls[u + 1]);
525 addshowLink(linkMenu, label + "|" + urls[u],
534 // create Bare ID link for this RUL
535 String[] urls = urlLink.makeUrls(id, true);
538 for (int u = 0; u < urls.length; u += 2)
540 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
542 linkset.addElement(urls[u] + "|" + urls[u + 1]);
543 addshowLink(linkMenu, label, urls[u + 1]);
548 // Create urls from description but only for URL links which are regex
550 if (descr != null && urlLink.getRegexReplace() != null)
552 // create link for this URL from description where regex matches
553 String[] urls = urlLink.makeUrls(descr, true);
556 for (int u = 0; u < urls.length; u += 2)
558 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
560 linkset.addElement(urls[u] + "|" + urls[u + 1]);
561 addshowLink(linkMenu, label, urls[u + 1]);
569 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
571 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
572 // Add a non-dynamic link
573 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
577 if (sequence != null)
579 sequenceMenu.add(linkMenu);
588 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
591 // TODO: usability: thread off the generation of group url content so root
593 // sequence only URLs
594 // ID/regex match URLs
595 groupLinksMenu = new JMenu("Group Link");
596 JMenu[] linkMenus = new JMenu[]
597 { null, new JMenu("IDS"), new JMenu("Sequences"),
598 new JMenu("IDS and Sequences") }; // three types of url that might be
600 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
601 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
602 Hashtable commonDbrefs = new Hashtable();
603 for (int sq = 0; sq < seqs.length; sq++)
606 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
607 .findPosition(sg.getEndRes());
608 // just collect ids from dataset sequence
609 // TODO: check if IDs collected from selecton group intersects with the
610 // current selection, too
611 SequenceI sqi = seqs[sq];
612 while (sqi.getDatasetSequence() != null)
614 sqi = sqi.getDatasetSequence();
616 DBRefEntry[] dbr = sqi.getDBRef();
617 if (dbr != null && dbr.length > 0)
619 for (int d = 0; d < dbr.length; d++)
621 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
622 Object[] sarray = (Object[]) commonDbrefs.get(src);
625 sarray = new Object[2];
626 sarray[0] = new int[]
628 sarray[1] = new String[seqs.length];
630 commonDbrefs.put(src, sarray);
633 if (((String[]) sarray[1])[sq] == null)
636 || (dbr[d].getMap().locateMappedRange(start, end) != null))
638 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
639 ((int[]) sarray[0])[0]++;
645 // now create group links for all distinct ID/sequence sets.
646 boolean addMenu = false; // indicates if there are any group links to give
648 for (int i = 0; i < groupLinks.size(); i++)
650 String link = groupLinks.elementAt(i).toString();
651 GroupUrlLink urlLink = null;
654 urlLink = new GroupUrlLink(link);
655 } catch (Exception foo)
657 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
662 if (!urlLink.isValid())
664 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
667 final String label = urlLink.getLabel();
668 boolean usingNames = false;
669 // Now see which parts of the group apply for this URL
670 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
671 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
672 String[] seqstr, ids; // input to makeUrl
675 int numinput = ((int[]) idset[0])[0];
676 String[] allids = ((String[]) idset[1]);
677 seqstr = new String[numinput];
678 ids = new String[numinput];
679 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
681 if (allids[sq] != null)
683 ids[idcount] = allids[sq];
684 seqstr[idcount++] = idandseqs[1][sq];
690 // just use the id/seq set
691 seqstr = idandseqs[1];
695 // and try and make the groupURL!
697 Object[] urlset = null;
700 urlset = urlLink.makeUrlStubs(ids, seqstr,
701 "FromJalview" + System.currentTimeMillis(), false);
702 } catch (UrlStringTooLongException e)
707 int type = urlLink.getGroupURLType() & 3;
708 // System.out.println(urlLink.getGroupURLType()
709 // +" "+((String[])urlset[3])[0]);
710 // first two bits ofurlLink type bitfield are sequenceids and sequences
711 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
712 addshowLink(linkMenus[type], label
713 + (((type & 1) == 1) ? ("("
714 + (usingNames ? "Names" : ltarget) + ")") : ""),
721 groupLinksMenu = new JMenu("Group Links");
722 for (int m = 0; m < linkMenus.length; m++)
724 if (linkMenus[m] != null
725 && linkMenus[m].getMenuComponentCount() > 0)
727 groupLinksMenu.add(linkMenus[m]);
731 groupMenu.add(groupLinksMenu);
736 * add a show URL menu item to the given linkMenu
740 * - menu label string
744 private void addshowLink(JMenu linkMenu, String label, final String url)
746 JMenuItem item = new JMenuItem(label);
747 item.setToolTipText("open URL: " + url);
748 item.addActionListener(new java.awt.event.ActionListener()
750 public void actionPerformed(ActionEvent e)
752 new Thread(new Runnable()
768 * add a late bound groupURL item to the given linkMenu
772 * - menu label string
773 * @param urlgenerator
774 * GroupURLLink used to generate URL
776 * Object array returned from the makeUrlStubs function.
778 private void addshowLink(JMenu linkMenu, String label,
779 final GroupUrlLink urlgenerator, final Object[] urlstub)
781 JMenuItem item = new JMenuItem(label);
782 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
783 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
792 item.addActionListener(new java.awt.event.ActionListener()
794 public void actionPerformed(ActionEvent e)
796 new Thread(new Runnable()
803 showLink(urlgenerator.constructFrom(urlstub));
804 } catch (UrlStringTooLongException e)
822 private void jbInit() throws Exception
824 groupMenu.setText("Group");
825 groupMenu.setText("Selection");
826 groupName.setText("Name");
827 groupName.addActionListener(new java.awt.event.ActionListener()
829 public void actionPerformed(ActionEvent e)
831 groupName_actionPerformed();
834 sequenceMenu.setText("Sequence");
835 sequenceName.setText("Edit Name/Description");
836 sequenceName.addActionListener(new java.awt.event.ActionListener()
838 public void actionPerformed(ActionEvent e)
840 sequenceName_actionPerformed();
843 PIDColour.setFocusPainted(false);
844 unGroupMenuItem.setText("Remove Group");
845 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
847 public void actionPerformed(ActionEvent e)
849 unGroupMenuItem_actionPerformed();
853 outline.setText("Border colour");
854 outline.addActionListener(new java.awt.event.ActionListener()
856 public void actionPerformed(ActionEvent e)
858 outline_actionPerformed();
861 nucleotideMenuItem.setText("Nucleotide");
862 nucleotideMenuItem.addActionListener(new ActionListener()
864 public void actionPerformed(ActionEvent e)
866 nucleotideMenuItem_actionPerformed();
869 colourMenu.setText("Group Colour");
870 showBoxes.setText("Boxes");
871 showBoxes.setState(true);
872 showBoxes.addActionListener(new ActionListener()
874 public void actionPerformed(ActionEvent e)
876 showBoxes_actionPerformed();
879 showText.setText("Text");
880 showText.setState(true);
881 showText.addActionListener(new ActionListener()
883 public void actionPerformed(ActionEvent e)
885 showText_actionPerformed();
888 showColourText.setText("Colour Text");
889 showColourText.addActionListener(new ActionListener()
891 public void actionPerformed(ActionEvent e)
893 showColourText_actionPerformed();
896 displayNonconserved.setText("Show Nonconserved");
897 displayNonconserved.setState(true);
898 displayNonconserved.addActionListener(new ActionListener()
900 public void actionPerformed(ActionEvent e)
902 showNonconserved_actionPerformed();
905 editMenu.setText("Edit");
907 cut.addActionListener(new ActionListener()
909 public void actionPerformed(ActionEvent e)
911 cut_actionPerformed();
914 upperCase.setText("To Upper Case");
915 upperCase.addActionListener(new ActionListener()
917 public void actionPerformed(ActionEvent e)
922 copy.setText("Copy");
923 copy.addActionListener(new ActionListener()
925 public void actionPerformed(ActionEvent e)
927 copy_actionPerformed();
930 lowerCase.setText("To Lower Case");
931 lowerCase.addActionListener(new ActionListener()
933 public void actionPerformed(ActionEvent e)
938 toggle.setText("Toggle Case");
939 toggle.addActionListener(new ActionListener()
941 public void actionPerformed(ActionEvent e)
946 pdbMenu.setText("Associate Structure with Sequence");
947 pdbFromFile.setText("From File");
948 pdbFromFile.addActionListener(new ActionListener()
950 public void actionPerformed(ActionEvent e)
952 pdbFromFile_actionPerformed();
955 enterPDB.setText("Enter PDB Id");
956 enterPDB.addActionListener(new ActionListener()
958 public void actionPerformed(ActionEvent e)
960 enterPDB_actionPerformed();
963 discoverPDB.setText("Discover PDB ids");
964 discoverPDB.addActionListener(new ActionListener()
966 public void actionPerformed(ActionEvent e)
968 discoverPDB_actionPerformed();
971 outputMenu.setText("Output to Textbox...");
972 sequenceFeature.setText("Create Sequence Feature");
973 sequenceFeature.addActionListener(new ActionListener()
975 public void actionPerformed(ActionEvent e)
977 sequenceFeature_actionPerformed();
980 textColour.setText("Text Colour");
981 textColour.addActionListener(new ActionListener()
983 public void actionPerformed(ActionEvent e)
985 textColour_actionPerformed();
988 jMenu1.setText("Group");
989 structureMenu.setText("Structure");
990 viewStructureMenu.setText("View Structure");
991 // colStructureMenu.setText("Colour By Structure");
992 editSequence.setText("Edit Sequence...");
993 editSequence.addActionListener(new ActionListener()
995 public void actionPerformed(ActionEvent actionEvent)
997 editSequence_actionPerformed(actionEvent);
1001 * annotationMenuItem.setText("By Annotation");
1002 * annotationMenuItem.addActionListener(new ActionListener() { public void
1003 * actionPerformed(ActionEvent actionEvent) {
1004 * annotationMenuItem_actionPerformed(actionEvent); } });
1010 this.add(structureMenu);
1011 groupMenu.add(editMenu);
1012 groupMenu.add(outputMenu);
1013 groupMenu.add(sequenceFeature);
1014 groupMenu.add(jMenu1);
1015 sequenceMenu.add(sequenceName);
1016 colourMenu.add(textColour);
1017 colourMenu.add(noColourmenuItem);
1018 colourMenu.add(clustalColour);
1019 colourMenu.add(BLOSUM62Colour);
1020 colourMenu.add(PIDColour);
1021 colourMenu.add(zappoColour);
1022 colourMenu.add(taylorColour);
1023 colourMenu.add(hydrophobicityColour);
1024 colourMenu.add(helixColour);
1025 colourMenu.add(strandColour);
1026 colourMenu.add(turnColour);
1027 colourMenu.add(buriedColour);
1028 colourMenu.add(nucleotideMenuItem);
1029 colourMenu.add(purinePyrimidineColour);
1030 //colourMenu.add(covariationColour);
1031 colourMenu.add(userDefinedColour);
1033 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1035 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1036 .getUserColourSchemes().keys();
1038 while (userColours.hasMoreElements())
1040 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1041 item.addActionListener(new ActionListener()
1043 public void actionPerformed(ActionEvent evt)
1045 userDefinedColour_actionPerformed(evt);
1048 colourMenu.add(item);
1052 colourMenu.addSeparator();
1053 colourMenu.add(abovePIDColour);
1054 colourMenu.add(conservationMenuItem);
1055 // colourMenu.add(annotationMenuItem);
1058 editMenu.add(editSequence);
1059 editMenu.add(upperCase);
1060 editMenu.add(lowerCase);
1061 editMenu.add(toggle);
1062 pdbMenu.add(pdbFromFile);
1063 pdbMenu.add(enterPDB);
1064 pdbMenu.add(discoverPDB);
1065 jMenu1.add(groupName);
1066 jMenu1.add(unGroupMenuItem);
1067 jMenu1.add(colourMenu);
1068 jMenu1.add(showBoxes);
1069 jMenu1.add(showText);
1070 jMenu1.add(showColourText);
1071 jMenu1.add(outline);
1072 jMenu1.add(displayNonconserved);
1073 structureMenu.add(pdbMenu);
1074 structureMenu.add(viewStructureMenu);
1075 // structureMenu.add(colStructureMenu);
1076 noColourmenuItem.setText("None");
1077 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1079 public void actionPerformed(ActionEvent e)
1081 noColourmenuItem_actionPerformed();
1085 clustalColour.setText("Clustalx colours");
1086 clustalColour.addActionListener(new java.awt.event.ActionListener()
1088 public void actionPerformed(ActionEvent e)
1090 clustalColour_actionPerformed();
1093 zappoColour.setText("Zappo");
1094 zappoColour.addActionListener(new java.awt.event.ActionListener()
1096 public void actionPerformed(ActionEvent e)
1098 zappoColour_actionPerformed();
1101 taylorColour.setText("Taylor");
1102 taylorColour.addActionListener(new java.awt.event.ActionListener()
1104 public void actionPerformed(ActionEvent e)
1106 taylorColour_actionPerformed();
1109 hydrophobicityColour.setText("Hydrophobicity");
1110 hydrophobicityColour
1111 .addActionListener(new java.awt.event.ActionListener()
1113 public void actionPerformed(ActionEvent e)
1115 hydrophobicityColour_actionPerformed();
1118 helixColour.setText("Helix propensity");
1119 helixColour.addActionListener(new java.awt.event.ActionListener()
1121 public void actionPerformed(ActionEvent e)
1123 helixColour_actionPerformed();
1126 strandColour.setText("Strand propensity");
1127 strandColour.addActionListener(new java.awt.event.ActionListener()
1129 public void actionPerformed(ActionEvent e)
1131 strandColour_actionPerformed();
1134 turnColour.setText("Turn propensity");
1135 turnColour.addActionListener(new java.awt.event.ActionListener()
1137 public void actionPerformed(ActionEvent e)
1139 turnColour_actionPerformed();
1142 buriedColour.setText("Buried Index");
1143 buriedColour.addActionListener(new java.awt.event.ActionListener()
1145 public void actionPerformed(ActionEvent e)
1147 buriedColour_actionPerformed();
1150 abovePIDColour.setText("Above % Identity");
1151 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1153 public void actionPerformed(ActionEvent e)
1155 abovePIDColour_actionPerformed();
1158 userDefinedColour.setText("User Defined...");
1159 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1161 public void actionPerformed(ActionEvent e)
1163 userDefinedColour_actionPerformed(e);
1166 PIDColour.setText("Percentage Identity");
1167 PIDColour.addActionListener(new java.awt.event.ActionListener()
1169 public void actionPerformed(ActionEvent e)
1171 PIDColour_actionPerformed();
1174 BLOSUM62Colour.setText("BLOSUM62");
1175 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1177 public void actionPerformed(ActionEvent e)
1179 BLOSUM62Colour_actionPerformed();
1182 purinePyrimidineColour.setText("Purine/Pyrimidine");
1183 purinePyrimidineColour.addActionListener(new java.awt.event.ActionListener()
1185 public void actionPerformed(ActionEvent e)
1187 purinePyrimidineColour_actionPerformed();
1191 covariationColour.addActionListener(new java.awt.event.ActionListener()
1193 public void actionPerformed(ActionEvent e)
1195 covariationColour_actionPerformed();
1199 conservationMenuItem.setText("Conservation");
1200 conservationMenuItem
1201 .addActionListener(new java.awt.event.ActionListener()
1203 public void actionPerformed(ActionEvent e)
1205 conservationMenuItem_actionPerformed();
1210 protected void showNonconserved_actionPerformed()
1212 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1217 * call to refresh view after settings change
1221 ap.updateAnnotation();
1222 ap.paintAlignment(true);
1224 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1233 protected void clustalColour_actionPerformed()
1235 SequenceGroup sg = getGroup();
1236 sg.cs = new ClustalxColourScheme(
1237 sg.getSequences(ap.av.hiddenRepSequences),
1238 ap.av.alignment.getWidth());
1248 protected void zappoColour_actionPerformed()
1250 getGroup().cs = new ZappoColourScheme();
1260 protected void taylorColour_actionPerformed()
1262 getGroup().cs = new TaylorColourScheme();
1272 protected void hydrophobicityColour_actionPerformed()
1274 getGroup().cs = new HydrophobicColourScheme();
1284 protected void helixColour_actionPerformed()
1286 getGroup().cs = new HelixColourScheme();
1296 protected void strandColour_actionPerformed()
1298 getGroup().cs = new StrandColourScheme();
1308 protected void turnColour_actionPerformed()
1310 getGroup().cs = new TurnColourScheme();
1320 protected void buriedColour_actionPerformed()
1322 getGroup().cs = new BuriedColourScheme();
1332 public void nucleotideMenuItem_actionPerformed()
1334 getGroup().cs = new NucleotideColourScheme();
1338 protected void purinePyrimidineColour_actionPerformed()
1340 getGroup().cs = new PurinePyrimidineColourScheme();
1344 protected void covariationColour_actionPerformed()
1346 getGroup().cs = new CovariationColourScheme(sequence.getAnnotation()[0]);
1356 protected void abovePIDColour_actionPerformed()
1358 SequenceGroup sg = getGroup();
1364 if (abovePIDColour.isSelected())
1366 sg.cs.setConsensus(AAFrequency.calculate(
1367 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1368 sg.getEndRes() + 1));
1370 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1373 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1375 SliderPanel.showPIDSlider();
1378 // remove PIDColouring
1380 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1392 protected void userDefinedColour_actionPerformed(ActionEvent e)
1394 SequenceGroup sg = getGroup();
1396 if (e.getActionCommand().equals("User Defined..."))
1398 new UserDefinedColours(ap, sg);
1402 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1403 .getUserColourSchemes().get(e.getActionCommand());
1416 protected void PIDColour_actionPerformed()
1418 SequenceGroup sg = getGroup();
1419 sg.cs = new PIDColourScheme();
1420 sg.cs.setConsensus(AAFrequency.calculate(
1421 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1422 sg.getEndRes() + 1));
1432 protected void BLOSUM62Colour_actionPerformed()
1434 SequenceGroup sg = getGroup();
1436 sg.cs = new Blosum62ColourScheme();
1438 sg.cs.setConsensus(AAFrequency.calculate(
1439 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1440 sg.getEndRes() + 1));
1451 protected void noColourmenuItem_actionPerformed()
1453 getGroup().cs = null;
1463 protected void conservationMenuItem_actionPerformed()
1465 SequenceGroup sg = getGroup();
1471 if (conservationMenuItem.isSelected())
1473 Conservation c = new Conservation("Group",
1474 ResidueProperties.propHash, 3,
1475 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1476 sg.getEndRes() + 1);
1479 c.verdict(false, ap.av.ConsPercGaps);
1481 sg.cs.setConservation(c);
1483 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1484 SliderPanel.showConservationSlider();
1487 // remove ConservationColouring
1489 sg.cs.setConservation(null);
1495 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1497 SequenceGroup sg = getGroup();
1503 AnnotationColourGradient acg = new AnnotationColourGradient(
1504 sequence.getAnnotation()[0], null,
1505 AnnotationColourGradient.NO_THRESHOLD);
1507 acg.predefinedColours = true;
1519 protected void groupName_actionPerformed()
1522 SequenceGroup sg = getGroup();
1523 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1524 sg.getDescription(), " Group Name ",
1525 "Group Description ", "Edit Group Name/Description",
1533 sg.setName(dialog.getName());
1534 sg.setDescription(dialog.getDescription());
1539 * Get selection group - adding it to the alignment if necessary.
1541 * @return sequence group to operate on
1543 SequenceGroup getGroup()
1545 SequenceGroup sg = ap.av.getSelectionGroup();
1546 // this method won't add a new group if it already exists
1549 ap.av.alignment.addGroup(sg);
1561 void sequenceName_actionPerformed()
1563 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1564 sequence.getDescription(), " Sequence Name ",
1565 "Sequence Description ", "Edit Sequence Name/Description",
1573 if (dialog.getName() != null)
1575 if (dialog.getName().indexOf(" ") > -1)
1577 JOptionPane.showMessageDialog(ap,
1578 "Spaces have been converted to \"_\"",
1579 "No spaces allowed in Sequence Name",
1580 JOptionPane.WARNING_MESSAGE);
1583 sequence.setName(dialog.getName().replace(' ', '_'));
1584 ap.paintAlignment(false);
1587 sequence.setDescription(dialog.getDescription());
1589 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1600 void unGroupMenuItem_actionPerformed()
1602 SequenceGroup sg = ap.av.getSelectionGroup();
1603 ap.av.alignment.deleteGroup(sg);
1604 ap.av.setSelectionGroup(null);
1614 protected void outline_actionPerformed()
1616 SequenceGroup sg = getGroup();
1617 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1622 sg.setOutlineColour(col);
1634 public void showBoxes_actionPerformed()
1636 getGroup().setDisplayBoxes(showBoxes.isSelected());
1646 public void showText_actionPerformed()
1648 getGroup().setDisplayText(showText.isSelected());
1658 public void showColourText_actionPerformed()
1660 getGroup().setColourText(showColourText.isSelected());
1664 public void showLink(String url)
1668 jalview.util.BrowserLauncher.openURL(url);
1669 } catch (Exception ex)
1672 .showInternalMessageDialog(
1674 "Unixers: Couldn't find default web browser."
1675 + "\nAdd the full path to your browser in Preferences.",
1676 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1678 ex.printStackTrace();
1682 void hideSequences(boolean representGroup)
1684 SequenceGroup sg = ap.av.getSelectionGroup();
1685 if (sg == null || sg.getSize() < 1)
1687 ap.av.hideSequence(new SequenceI[]
1692 ap.av.setSelectionGroup(null);
1696 ap.av.hideRepSequences(sequence, sg);
1701 int gsize = sg.getSize();
1704 hseqs = new SequenceI[gsize];
1707 for (int i = 0; i < gsize; i++)
1709 hseqs[index++] = sg.getSequenceAt(i);
1712 ap.av.hideSequence(hseqs);
1713 // refresh(); TODO: ? needed ?
1714 ap.av.sendSelection();
1717 public void copy_actionPerformed()
1719 ap.alignFrame.copy_actionPerformed(null);
1722 public void cut_actionPerformed()
1724 ap.alignFrame.cut_actionPerformed(null);
1727 void changeCase(ActionEvent e)
1729 Object source = e.getSource();
1730 SequenceGroup sg = ap.av.getSelectionGroup();
1734 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1735 sg.getEndRes() + 1);
1740 if (source == toggle)
1742 description = "Toggle Case";
1743 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1745 else if (source == upperCase)
1747 description = "To Upper Case";
1748 caseChange = ChangeCaseCommand.TO_UPPER;
1752 description = "To Lower Case";
1753 caseChange = ChangeCaseCommand.TO_LOWER;
1756 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1757 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1760 ap.alignFrame.addHistoryItem(caseCommand);
1762 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1768 public void outputText_actionPerformed(ActionEvent e)
1770 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1771 cap.setForInput(null);
1772 Desktop.addInternalFrame(cap,
1773 "Alignment output - " + e.getActionCommand(), 600, 500);
1775 String[] omitHidden = null;
1777 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1778 // or we simply trust the user wants
1779 // wysiwig behaviour
1780 SequenceGroup sg = ap.av.getSelectionGroup();
1781 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1782 omitHidden = ap.av.getViewAsString(true);
1783 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1784 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1787 for (int i = 0; i < nala.length; i++)
1789 AlignmentAnnotation na = nala[i];
1790 oal.addAnnotation(na);
1793 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1794 oal, omitHidden, csel, sg));
1798 public void pdbFromFile_actionPerformed()
1800 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1801 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1802 chooser.setFileView(new jalview.io.JalviewFileView());
1803 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1804 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1806 int value = chooser.showOpenDialog(null);
1808 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1810 String choice = chooser.getSelectedFile().getPath();
1811 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1812 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1817 public void enterPDB_actionPerformed()
1819 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1820 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1822 if (id != null && id.length() > 0)
1824 PDBEntry entry = new PDBEntry();
1825 entry.setId(id.toUpperCase());
1826 sequence.getDatasetSequence().addPDBId(entry);
1830 public void discoverPDB_actionPerformed()
1833 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1835 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1836 Thread discpdb = new Thread(new Runnable()
1841 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1842 .fetchDBRefs(false);
1849 public void sequenceFeature_actionPerformed()
1851 SequenceGroup sg = ap.av.getSelectionGroup();
1857 int rsize = 0, gSize = sg.getSize();
1858 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1859 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1861 for (int i = 0; i < gSize; i++)
1863 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1864 int end = sg.findEndRes(sg.getSequenceAt(i));
1867 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1868 features[rsize] = new SequenceFeature(null, null, null, start, end,
1873 rseqs = new SequenceI[rsize];
1874 tfeatures = new SequenceFeature[rsize];
1875 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1876 System.arraycopy(features, 0, tfeatures, 0, rsize);
1877 features = tfeatures;
1879 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1880 features, true, ap))
1882 ap.alignFrame.setShowSeqFeatures(true);
1883 ap.highlightSearchResults(null);
1887 public void textColour_actionPerformed()
1889 SequenceGroup sg = getGroup();
1892 new TextColourChooser().chooseColour(ap, sg);
1896 public void colourByStructure(String pdbid)
1898 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1901 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1902 "Coloured by " + pdbid, anots);
1904 ap.av.alignment.addAnnotation(an);
1905 an.createSequenceMapping(sequence, 0, true);
1906 // an.adjustForAlignment();
1907 ap.av.alignment.setAnnotationIndex(an, 0);
1909 ap.adjustAnnotationHeight();
1911 sequence.addAlignmentAnnotation(an);
1915 public void editSequence_actionPerformed(ActionEvent actionEvent)
1917 SequenceGroup sg = ap.av.getSelectionGroup();
1921 if (sequence == null)
1922 sequence = (Sequence) sg.getSequenceAt(0);
1924 EditNameDialog dialog = new EditNameDialog(
1925 sequence.getSequenceAsString(sg.getStartRes(),
1926 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1927 "Edit Sequence", ap.alignFrame);
1931 EditCommand editCommand = new EditCommand("Edit Sequences",
1932 EditCommand.REPLACE, dialog.getName().replace(' ',
1933 ap.av.getGapCharacter()),
1934 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1935 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1937 ap.alignFrame.addHistoryItem(editCommand);
1939 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()