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, final Sequence seq, final Vector links,
165 final Vector groupLinks)
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 if(ap.av.alignment.isNucleotide()==false){
258 structureMenu.remove(viewStructureMenu);
260 // structureMenu.remove(colStructureMenu);
263 if(ap.av.alignment.isNucleotide()==true){
264 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
265 String rnastruc=new String();
266 for(int i=0; i<aa.length;i++){
267 if(aa[i]._rnasecstr != null){
268 rnastruc=aa[i].getRNAStruc();
273 SequenceGroup a = aa[0].groupRef;
275 //TODO: make rnastrucF a bit more nice
276 final String rnastrucF=rnastruc;
277 menuItem = new JMenuItem();
278 menuItem.setText("RNA structure");
279 menuItem.addActionListener(new java.awt.event.ActionListener()
281 public void actionPerformed(ActionEvent e)
283 System.out.println("Call Varna "+seq.getSequenceAsString()+" "+seq.getName());
284 //TODO: VARNA does'nt print gaps in the sequence
285 new AppVarna(seq.getSequenceAsString(),rnastrucF,seq.getName(),ap);
288 viewStructureMenu.add(menuItem);
291 menuItem = new JMenuItem("Hide Sequences");
292 menuItem.addActionListener(new java.awt.event.ActionListener()
294 public void actionPerformed(ActionEvent e)
296 hideSequences(false);
301 if (ap.av.getSelectionGroup() != null
302 && ap.av.getSelectionGroup().getSize() > 1)
304 menuItem = new JMenuItem("Represent Group with " + seq.getName());
305 menuItem.addActionListener(new java.awt.event.ActionListener()
307 public void actionPerformed(ActionEvent e)
312 sequenceMenu.add(menuItem);
315 if (ap.av.hasHiddenRows)
317 final int index = ap.av.alignment.findIndex(seq);
319 if (ap.av.adjustForHiddenSeqs(index)
320 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
322 menuItem = new JMenuItem("Reveal Sequences");
323 menuItem.addActionListener(new ActionListener()
325 public void actionPerformed(ActionEvent e)
327 ap.av.showSequence(index);
328 if (ap.overviewPanel != null)
330 ap.overviewPanel.updateOverviewImage();
337 menuItem = new JMenuItem("Reveal All");
338 menuItem.addActionListener(new ActionListener()
340 public void actionPerformed(ActionEvent e)
342 ap.av.showAllHiddenSeqs();
343 if (ap.overviewPanel != null)
345 ap.overviewPanel.updateOverviewImage();
355 SequenceGroup sg = ap.av.getSelectionGroup();
359 groupName.setText("Name: "+sg.getName());
360 groupName.setText("Edit name and description of current group.");
362 if (sg.cs instanceof ZappoColourScheme)
364 zappoColour.setSelected(true);
366 else if (sg.cs instanceof TaylorColourScheme)
368 taylorColour.setSelected(true);
370 else if (sg.cs instanceof PIDColourScheme)
372 PIDColour.setSelected(true);
374 else if (sg.cs instanceof Blosum62ColourScheme)
376 BLOSUM62Colour.setSelected(true);
378 else if (sg.cs instanceof UserColourScheme)
380 userDefinedColour.setSelected(true);
382 else if (sg.cs instanceof HydrophobicColourScheme)
384 hydrophobicityColour.setSelected(true);
386 else if (sg.cs instanceof HelixColourScheme)
388 helixColour.setSelected(true);
390 else if (sg.cs instanceof StrandColourScheme)
392 strandColour.setSelected(true);
394 else if (sg.cs instanceof TurnColourScheme)
396 turnColour.setSelected(true);
398 else if (sg.cs instanceof BuriedColourScheme)
400 buriedColour.setSelected(true);
402 else if (sg.cs instanceof ClustalxColourScheme)
404 clustalColour.setSelected(true);
406 else if (sg.cs instanceof PurinePyrimidineColourScheme)
408 purinePyrimidineColour.setSelected(true);
410 /* else if (sg.cs instanceof CovariationColourScheme)
412 covariationColour.setSelected(true);
416 noColourmenuItem.setSelected(true);
419 if (sg.cs != null && sg.cs.conservationApplied())
421 conservationMenuItem.setSelected(true);
423 displayNonconserved.setSelected(sg.getShowNonconserved());
424 showText.setSelected(sg.getDisplayText());
425 showColourText.setSelected(sg.getColourText());
426 showBoxes.setSelected(sg.getDisplayBoxes());
427 // add any groupURLs to the groupURL submenu and make it visible
428 if (groupLinks != null && groupLinks.size() > 0)
430 buildGroupURLMenu(sg, groupLinks);
432 // Add a 'show all structures' for the current selection
433 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
434 for (SequenceI sq: ap.av.getSequenceSelection())
436 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
438 for (PDBEntry pe: pes)
440 pdbe.put(pe.getId(), pe);
446 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
447 final JMenuItem gpdbview;
448 structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
449 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
450 gpdbview.addActionListener(new ActionListener()
454 public void actionPerformed(ActionEvent e)
456 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
463 groupMenu.setVisible(false);
464 editMenu.setVisible(false);
467 if (!ap.av.alignment.getGroups().contains(sg))
469 unGroupMenuItem.setVisible(false);
474 sequenceMenu.setVisible(false);
475 structureMenu.setVisible(false);
478 if (links != null && links.size() > 0)
481 JMenu linkMenu = new JMenu("Link");
482 Vector linkset = new Vector();
483 for (int i = 0; i < links.size(); i++)
485 String link = links.elementAt(i).toString();
486 UrlLink urlLink = null;
489 urlLink = new UrlLink(link);
490 } catch (Exception foo)
492 jalview.bin.Cache.log.error("Exception for URLLink '" + link
497 if (!urlLink.isValid())
499 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
502 final String label = urlLink.getLabel();
503 if (urlLink.isDynamic())
506 // collect matching db-refs
507 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
508 seq.getDBRef(), new String[]
509 { urlLink.getTarget() });
510 // collect id string too
511 String id = seq.getName();
512 String descr = seq.getDescription();
513 if (descr != null && descr.length() < 1)
520 for (int r = 0; r < dbr.length; r++)
522 if (id != null && dbr[r].getAccessionId().equals(id))
524 // suppress duplicate link creation for the bare sequence ID
525 // string with this link
528 // create Bare ID link for this RUL
529 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
533 for (int u = 0; u < urls.length; u += 2)
535 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
537 linkset.addElement(urls[u] + "|" + urls[u + 1]);
538 addshowLink(linkMenu, label + "|" + urls[u],
547 // create Bare ID link for this RUL
548 String[] urls = urlLink.makeUrls(id, true);
551 for (int u = 0; u < urls.length; u += 2)
553 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
555 linkset.addElement(urls[u] + "|" + urls[u + 1]);
556 addshowLink(linkMenu, label, urls[u + 1]);
561 // Create urls from description but only for URL links which are regex
563 if (descr != null && urlLink.getRegexReplace() != null)
565 // create link for this URL from description where regex matches
566 String[] urls = urlLink.makeUrls(descr, true);
569 for (int u = 0; u < urls.length; u += 2)
571 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
573 linkset.addElement(urls[u] + "|" + urls[u + 1]);
574 addshowLink(linkMenu, label, urls[u + 1]);
582 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
584 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
585 // Add a non-dynamic link
586 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
590 if (sequence != null)
592 sequenceMenu.add(linkMenu);
601 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
604 // TODO: usability: thread off the generation of group url content so root
606 // sequence only URLs
607 // ID/regex match URLs
608 groupLinksMenu = new JMenu("Group Link");
609 JMenu[] linkMenus = new JMenu[]
610 { null, new JMenu("IDS"), new JMenu("Sequences"),
611 new JMenu("IDS and Sequences") }; // three types of url that might be
613 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
614 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
615 Hashtable commonDbrefs = new Hashtable();
616 for (int sq = 0; sq < seqs.length; sq++)
619 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
620 .findPosition(sg.getEndRes());
621 // just collect ids from dataset sequence
622 // TODO: check if IDs collected from selecton group intersects with the
623 // current selection, too
624 SequenceI sqi = seqs[sq];
625 while (sqi.getDatasetSequence() != null)
627 sqi = sqi.getDatasetSequence();
629 DBRefEntry[] dbr = sqi.getDBRef();
630 if (dbr != null && dbr.length > 0)
632 for (int d = 0; d < dbr.length; d++)
634 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
635 Object[] sarray = (Object[]) commonDbrefs.get(src);
638 sarray = new Object[2];
639 sarray[0] = new int[]
641 sarray[1] = new String[seqs.length];
643 commonDbrefs.put(src, sarray);
646 if (((String[]) sarray[1])[sq] == null)
649 || (dbr[d].getMap().locateMappedRange(start, end) != null))
651 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
652 ((int[]) sarray[0])[0]++;
658 // now create group links for all distinct ID/sequence sets.
659 boolean addMenu = false; // indicates if there are any group links to give
661 for (int i = 0; i < groupLinks.size(); i++)
663 String link = groupLinks.elementAt(i).toString();
664 GroupUrlLink urlLink = null;
667 urlLink = new GroupUrlLink(link);
668 } catch (Exception foo)
670 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
675 if (!urlLink.isValid())
677 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
680 final String label = urlLink.getLabel();
681 boolean usingNames = false;
682 // Now see which parts of the group apply for this URL
683 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
684 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
685 String[] seqstr, ids; // input to makeUrl
688 int numinput = ((int[]) idset[0])[0];
689 String[] allids = ((String[]) idset[1]);
690 seqstr = new String[numinput];
691 ids = new String[numinput];
692 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
694 if (allids[sq] != null)
696 ids[idcount] = allids[sq];
697 seqstr[idcount++] = idandseqs[1][sq];
703 // just use the id/seq set
704 seqstr = idandseqs[1];
708 // and try and make the groupURL!
710 Object[] urlset = null;
713 urlset = urlLink.makeUrlStubs(ids, seqstr,
714 "FromJalview" + System.currentTimeMillis(), false);
715 } catch (UrlStringTooLongException e)
720 int type = urlLink.getGroupURLType() & 3;
721 // System.out.println(urlLink.getGroupURLType()
722 // +" "+((String[])urlset[3])[0]);
723 // first two bits ofurlLink type bitfield are sequenceids and sequences
724 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
725 addshowLink(linkMenus[type], label
726 + (((type & 1) == 1) ? ("("
727 + (usingNames ? "Names" : ltarget) + ")") : ""),
734 groupLinksMenu = new JMenu("Group Links");
735 for (int m = 0; m < linkMenus.length; m++)
737 if (linkMenus[m] != null
738 && linkMenus[m].getMenuComponentCount() > 0)
740 groupLinksMenu.add(linkMenus[m]);
744 groupMenu.add(groupLinksMenu);
749 * add a show URL menu item to the given linkMenu
753 * - menu label string
757 private void addshowLink(JMenu linkMenu, String label, final String url)
759 JMenuItem item = new JMenuItem(label);
760 item.setToolTipText("open URL: " + url);
761 item.addActionListener(new java.awt.event.ActionListener()
763 public void actionPerformed(ActionEvent e)
765 new Thread(new Runnable()
781 * add a late bound groupURL item to the given linkMenu
785 * - menu label string
786 * @param urlgenerator
787 * GroupURLLink used to generate URL
789 * Object array returned from the makeUrlStubs function.
791 private void addshowLink(JMenu linkMenu, String label,
792 final GroupUrlLink urlgenerator, final Object[] urlstub)
794 JMenuItem item = new JMenuItem(label);
795 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
796 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
805 item.addActionListener(new java.awt.event.ActionListener()
807 public void actionPerformed(ActionEvent e)
809 new Thread(new Runnable()
816 showLink(urlgenerator.constructFrom(urlstub));
817 } catch (UrlStringTooLongException e)
835 private void jbInit() throws Exception
837 groupMenu.setText("Group");
838 groupMenu.setText("Selection");
839 groupName.setText("Name");
840 groupName.addActionListener(new java.awt.event.ActionListener()
842 public void actionPerformed(ActionEvent e)
844 groupName_actionPerformed();
847 sequenceMenu.setText("Sequence");
848 sequenceName.setText("Edit Name/Description");
849 sequenceName.addActionListener(new java.awt.event.ActionListener()
851 public void actionPerformed(ActionEvent e)
853 sequenceName_actionPerformed();
856 PIDColour.setFocusPainted(false);
857 unGroupMenuItem.setText("Remove Group");
858 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
860 public void actionPerformed(ActionEvent e)
862 unGroupMenuItem_actionPerformed();
866 outline.setText("Border colour");
867 outline.addActionListener(new java.awt.event.ActionListener()
869 public void actionPerformed(ActionEvent e)
871 outline_actionPerformed();
874 nucleotideMenuItem.setText("Nucleotide");
875 nucleotideMenuItem.addActionListener(new ActionListener()
877 public void actionPerformed(ActionEvent e)
879 nucleotideMenuItem_actionPerformed();
882 colourMenu.setText("Group Colour");
883 showBoxes.setText("Boxes");
884 showBoxes.setState(true);
885 showBoxes.addActionListener(new ActionListener()
887 public void actionPerformed(ActionEvent e)
889 showBoxes_actionPerformed();
892 showText.setText("Text");
893 showText.setState(true);
894 showText.addActionListener(new ActionListener()
896 public void actionPerformed(ActionEvent e)
898 showText_actionPerformed();
901 showColourText.setText("Colour Text");
902 showColourText.addActionListener(new ActionListener()
904 public void actionPerformed(ActionEvent e)
906 showColourText_actionPerformed();
909 displayNonconserved.setText("Show Nonconserved");
910 displayNonconserved.setState(true);
911 displayNonconserved.addActionListener(new ActionListener()
913 public void actionPerformed(ActionEvent e)
915 showNonconserved_actionPerformed();
918 editMenu.setText("Edit");
920 cut.addActionListener(new ActionListener()
922 public void actionPerformed(ActionEvent e)
924 cut_actionPerformed();
927 upperCase.setText("To Upper Case");
928 upperCase.addActionListener(new ActionListener()
930 public void actionPerformed(ActionEvent e)
935 copy.setText("Copy");
936 copy.addActionListener(new ActionListener()
938 public void actionPerformed(ActionEvent e)
940 copy_actionPerformed();
943 lowerCase.setText("To Lower Case");
944 lowerCase.addActionListener(new ActionListener()
946 public void actionPerformed(ActionEvent e)
951 toggle.setText("Toggle Case");
952 toggle.addActionListener(new ActionListener()
954 public void actionPerformed(ActionEvent e)
959 pdbMenu.setText("Associate Structure with Sequence");
960 pdbFromFile.setText("From File");
961 pdbFromFile.addActionListener(new ActionListener()
963 public void actionPerformed(ActionEvent e)
965 pdbFromFile_actionPerformed();
968 enterPDB.setText("Enter PDB Id");
969 enterPDB.addActionListener(new ActionListener()
971 public void actionPerformed(ActionEvent e)
973 enterPDB_actionPerformed();
976 discoverPDB.setText("Discover PDB ids");
977 discoverPDB.addActionListener(new ActionListener()
979 public void actionPerformed(ActionEvent e)
981 discoverPDB_actionPerformed();
984 outputMenu.setText("Output to Textbox...");
985 sequenceFeature.setText("Create Sequence Feature");
986 sequenceFeature.addActionListener(new ActionListener()
988 public void actionPerformed(ActionEvent e)
990 sequenceFeature_actionPerformed();
993 textColour.setText("Text Colour");
994 textColour.addActionListener(new ActionListener()
996 public void actionPerformed(ActionEvent e)
998 textColour_actionPerformed();
1001 jMenu1.setText("Group");
1002 structureMenu.setText("Structure");
1003 viewStructureMenu.setText("View Structure");
1004 // colStructureMenu.setText("Colour By Structure");
1005 editSequence.setText("Edit Sequence...");
1006 editSequence.addActionListener(new ActionListener()
1008 public void actionPerformed(ActionEvent actionEvent)
1010 editSequence_actionPerformed(actionEvent);
1014 * annotationMenuItem.setText("By Annotation");
1015 * annotationMenuItem.addActionListener(new ActionListener() { public void
1016 * actionPerformed(ActionEvent actionEvent) {
1017 * annotationMenuItem_actionPerformed(actionEvent); } });
1023 this.add(structureMenu);
1024 groupMenu.add(editMenu);
1025 groupMenu.add(outputMenu);
1026 groupMenu.add(sequenceFeature);
1027 groupMenu.add(jMenu1);
1028 sequenceMenu.add(sequenceName);
1029 colourMenu.add(textColour);
1030 colourMenu.add(noColourmenuItem);
1031 colourMenu.add(clustalColour);
1032 colourMenu.add(BLOSUM62Colour);
1033 colourMenu.add(PIDColour);
1034 colourMenu.add(zappoColour);
1035 colourMenu.add(taylorColour);
1036 colourMenu.add(hydrophobicityColour);
1037 colourMenu.add(helixColour);
1038 colourMenu.add(strandColour);
1039 colourMenu.add(turnColour);
1040 colourMenu.add(buriedColour);
1041 colourMenu.add(nucleotideMenuItem);
1042 colourMenu.add(purinePyrimidineColour);
1043 //colourMenu.add(covariationColour);
1044 colourMenu.add(userDefinedColour);
1046 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1048 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1049 .getUserColourSchemes().keys();
1051 while (userColours.hasMoreElements())
1053 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1054 item.addActionListener(new ActionListener()
1056 public void actionPerformed(ActionEvent evt)
1058 userDefinedColour_actionPerformed(evt);
1061 colourMenu.add(item);
1065 colourMenu.addSeparator();
1066 colourMenu.add(abovePIDColour);
1067 colourMenu.add(conservationMenuItem);
1068 // colourMenu.add(annotationMenuItem);
1071 editMenu.add(editSequence);
1072 editMenu.add(upperCase);
1073 editMenu.add(lowerCase);
1074 editMenu.add(toggle);
1075 pdbMenu.add(pdbFromFile);
1076 pdbMenu.add(enterPDB);
1077 pdbMenu.add(discoverPDB);
1078 jMenu1.add(groupName);
1079 jMenu1.add(unGroupMenuItem);
1080 jMenu1.add(colourMenu);
1081 jMenu1.add(showBoxes);
1082 jMenu1.add(showText);
1083 jMenu1.add(showColourText);
1084 jMenu1.add(outline);
1085 jMenu1.add(displayNonconserved);
1086 structureMenu.add(pdbMenu);
1087 structureMenu.add(viewStructureMenu);
1088 // structureMenu.add(colStructureMenu);
1089 noColourmenuItem.setText("None");
1090 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1092 public void actionPerformed(ActionEvent e)
1094 noColourmenuItem_actionPerformed();
1098 clustalColour.setText("Clustalx colours");
1099 clustalColour.addActionListener(new java.awt.event.ActionListener()
1101 public void actionPerformed(ActionEvent e)
1103 clustalColour_actionPerformed();
1106 zappoColour.setText("Zappo");
1107 zappoColour.addActionListener(new java.awt.event.ActionListener()
1109 public void actionPerformed(ActionEvent e)
1111 zappoColour_actionPerformed();
1114 taylorColour.setText("Taylor");
1115 taylorColour.addActionListener(new java.awt.event.ActionListener()
1117 public void actionPerformed(ActionEvent e)
1119 taylorColour_actionPerformed();
1122 hydrophobicityColour.setText("Hydrophobicity");
1123 hydrophobicityColour
1124 .addActionListener(new java.awt.event.ActionListener()
1126 public void actionPerformed(ActionEvent e)
1128 hydrophobicityColour_actionPerformed();
1131 helixColour.setText("Helix propensity");
1132 helixColour.addActionListener(new java.awt.event.ActionListener()
1134 public void actionPerformed(ActionEvent e)
1136 helixColour_actionPerformed();
1139 strandColour.setText("Strand propensity");
1140 strandColour.addActionListener(new java.awt.event.ActionListener()
1142 public void actionPerformed(ActionEvent e)
1144 strandColour_actionPerformed();
1147 turnColour.setText("Turn propensity");
1148 turnColour.addActionListener(new java.awt.event.ActionListener()
1150 public void actionPerformed(ActionEvent e)
1152 turnColour_actionPerformed();
1155 buriedColour.setText("Buried Index");
1156 buriedColour.addActionListener(new java.awt.event.ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 buriedColour_actionPerformed();
1163 abovePIDColour.setText("Above % Identity");
1164 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1166 public void actionPerformed(ActionEvent e)
1168 abovePIDColour_actionPerformed();
1171 userDefinedColour.setText("User Defined...");
1172 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1174 public void actionPerformed(ActionEvent e)
1176 userDefinedColour_actionPerformed(e);
1179 PIDColour.setText("Percentage Identity");
1180 PIDColour.addActionListener(new java.awt.event.ActionListener()
1182 public void actionPerformed(ActionEvent e)
1184 PIDColour_actionPerformed();
1187 BLOSUM62Colour.setText("BLOSUM62");
1188 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1190 public void actionPerformed(ActionEvent e)
1192 BLOSUM62Colour_actionPerformed();
1195 purinePyrimidineColour.setText("Purine/Pyrimidine");
1196 purinePyrimidineColour.addActionListener(new java.awt.event.ActionListener()
1198 public void actionPerformed(ActionEvent e)
1200 purinePyrimidineColour_actionPerformed();
1204 covariationColour.addActionListener(new java.awt.event.ActionListener()
1206 public void actionPerformed(ActionEvent e)
1208 covariationColour_actionPerformed();
1212 conservationMenuItem.setText("Conservation");
1213 conservationMenuItem
1214 .addActionListener(new java.awt.event.ActionListener()
1216 public void actionPerformed(ActionEvent e)
1218 conservationMenuItem_actionPerformed();
1223 protected void showNonconserved_actionPerformed()
1225 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1230 * call to refresh view after settings change
1234 ap.updateAnnotation();
1235 ap.paintAlignment(true);
1237 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1246 protected void clustalColour_actionPerformed()
1248 SequenceGroup sg = getGroup();
1249 sg.cs = new ClustalxColourScheme(
1250 sg.getSequences(ap.av.hiddenRepSequences),
1251 ap.av.alignment.getWidth());
1261 protected void zappoColour_actionPerformed()
1263 getGroup().cs = new ZappoColourScheme();
1273 protected void taylorColour_actionPerformed()
1275 getGroup().cs = new TaylorColourScheme();
1285 protected void hydrophobicityColour_actionPerformed()
1287 getGroup().cs = new HydrophobicColourScheme();
1297 protected void helixColour_actionPerformed()
1299 getGroup().cs = new HelixColourScheme();
1309 protected void strandColour_actionPerformed()
1311 getGroup().cs = new StrandColourScheme();
1321 protected void turnColour_actionPerformed()
1323 getGroup().cs = new TurnColourScheme();
1333 protected void buriedColour_actionPerformed()
1335 getGroup().cs = new BuriedColourScheme();
1345 public void nucleotideMenuItem_actionPerformed()
1347 getGroup().cs = new NucleotideColourScheme();
1351 protected void purinePyrimidineColour_actionPerformed()
1353 getGroup().cs = new PurinePyrimidineColourScheme();
1357 protected void covariationColour_actionPerformed()
1359 getGroup().cs = new CovariationColourScheme(sequence.getAnnotation()[0]);
1369 protected void abovePIDColour_actionPerformed()
1371 SequenceGroup sg = getGroup();
1377 if (abovePIDColour.isSelected())
1379 sg.cs.setConsensus(AAFrequency.calculate(
1380 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1381 sg.getEndRes() + 1));
1383 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1386 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1388 SliderPanel.showPIDSlider();
1391 // remove PIDColouring
1393 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1405 protected void userDefinedColour_actionPerformed(ActionEvent e)
1407 SequenceGroup sg = getGroup();
1409 if (e.getActionCommand().equals("User Defined..."))
1411 new UserDefinedColours(ap, sg);
1415 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1416 .getUserColourSchemes().get(e.getActionCommand());
1429 protected void PIDColour_actionPerformed()
1431 SequenceGroup sg = getGroup();
1432 sg.cs = new PIDColourScheme();
1433 sg.cs.setConsensus(AAFrequency.calculate(
1434 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1435 sg.getEndRes() + 1));
1445 protected void BLOSUM62Colour_actionPerformed()
1447 SequenceGroup sg = getGroup();
1449 sg.cs = new Blosum62ColourScheme();
1451 sg.cs.setConsensus(AAFrequency.calculate(
1452 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1453 sg.getEndRes() + 1));
1464 protected void noColourmenuItem_actionPerformed()
1466 getGroup().cs = null;
1476 protected void conservationMenuItem_actionPerformed()
1478 SequenceGroup sg = getGroup();
1484 if (conservationMenuItem.isSelected())
1486 Conservation c = new Conservation("Group",
1487 ResidueProperties.propHash, 3,
1488 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1489 sg.getEndRes() + 1);
1492 c.verdict(false, ap.av.ConsPercGaps);
1494 sg.cs.setConservation(c);
1496 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1497 SliderPanel.showConservationSlider();
1500 // remove ConservationColouring
1502 sg.cs.setConservation(null);
1508 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1510 SequenceGroup sg = getGroup();
1516 AnnotationColourGradient acg = new AnnotationColourGradient(
1517 sequence.getAnnotation()[0], null,
1518 AnnotationColourGradient.NO_THRESHOLD);
1520 acg.predefinedColours = true;
1532 protected void groupName_actionPerformed()
1535 SequenceGroup sg = getGroup();
1536 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1537 sg.getDescription(), " Group Name ",
1538 "Group Description ", "Edit Group Name/Description",
1546 sg.setName(dialog.getName());
1547 sg.setDescription(dialog.getDescription());
1552 * Get selection group - adding it to the alignment if necessary.
1554 * @return sequence group to operate on
1556 SequenceGroup getGroup()
1558 SequenceGroup sg = ap.av.getSelectionGroup();
1559 // this method won't add a new group if it already exists
1562 ap.av.alignment.addGroup(sg);
1574 void sequenceName_actionPerformed()
1576 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1577 sequence.getDescription(), " Sequence Name ",
1578 "Sequence Description ", "Edit Sequence Name/Description",
1586 if (dialog.getName() != null)
1588 if (dialog.getName().indexOf(" ") > -1)
1590 JOptionPane.showMessageDialog(ap,
1591 "Spaces have been converted to \"_\"",
1592 "No spaces allowed in Sequence Name",
1593 JOptionPane.WARNING_MESSAGE);
1596 sequence.setName(dialog.getName().replace(' ', '_'));
1597 ap.paintAlignment(false);
1600 sequence.setDescription(dialog.getDescription());
1602 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1613 void unGroupMenuItem_actionPerformed()
1615 SequenceGroup sg = ap.av.getSelectionGroup();
1616 ap.av.alignment.deleteGroup(sg);
1617 ap.av.setSelectionGroup(null);
1627 protected void outline_actionPerformed()
1629 SequenceGroup sg = getGroup();
1630 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1635 sg.setOutlineColour(col);
1647 public void showBoxes_actionPerformed()
1649 getGroup().setDisplayBoxes(showBoxes.isSelected());
1659 public void showText_actionPerformed()
1661 getGroup().setDisplayText(showText.isSelected());
1671 public void showColourText_actionPerformed()
1673 getGroup().setColourText(showColourText.isSelected());
1677 public void showLink(String url)
1681 jalview.util.BrowserLauncher.openURL(url);
1682 } catch (Exception ex)
1685 .showInternalMessageDialog(
1687 "Unixers: Couldn't find default web browser."
1688 + "\nAdd the full path to your browser in Preferences.",
1689 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1691 ex.printStackTrace();
1695 void hideSequences(boolean representGroup)
1697 SequenceGroup sg = ap.av.getSelectionGroup();
1698 if (sg == null || sg.getSize() < 1)
1700 ap.av.hideSequence(new SequenceI[]
1705 ap.av.setSelectionGroup(null);
1709 ap.av.hideRepSequences(sequence, sg);
1714 int gsize = sg.getSize();
1717 hseqs = new SequenceI[gsize];
1720 for (int i = 0; i < gsize; i++)
1722 hseqs[index++] = sg.getSequenceAt(i);
1725 ap.av.hideSequence(hseqs);
1726 // refresh(); TODO: ? needed ?
1727 ap.av.sendSelection();
1730 public void copy_actionPerformed()
1732 ap.alignFrame.copy_actionPerformed(null);
1735 public void cut_actionPerformed()
1737 ap.alignFrame.cut_actionPerformed(null);
1740 void changeCase(ActionEvent e)
1742 Object source = e.getSource();
1743 SequenceGroup sg = ap.av.getSelectionGroup();
1747 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1748 sg.getEndRes() + 1);
1753 if (source == toggle)
1755 description = "Toggle Case";
1756 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1758 else if (source == upperCase)
1760 description = "To Upper Case";
1761 caseChange = ChangeCaseCommand.TO_UPPER;
1765 description = "To Lower Case";
1766 caseChange = ChangeCaseCommand.TO_LOWER;
1769 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1770 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1773 ap.alignFrame.addHistoryItem(caseCommand);
1775 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1781 public void outputText_actionPerformed(ActionEvent e)
1783 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1784 cap.setForInput(null);
1785 Desktop.addInternalFrame(cap,
1786 "Alignment output - " + e.getActionCommand(), 600, 500);
1788 String[] omitHidden = null;
1790 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1791 // or we simply trust the user wants
1792 // wysiwig behaviour
1793 SequenceGroup sg = ap.av.getSelectionGroup();
1794 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1795 omitHidden = ap.av.getViewAsString(true);
1796 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1797 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1800 for (int i = 0; i < nala.length; i++)
1802 AlignmentAnnotation na = nala[i];
1803 oal.addAnnotation(na);
1806 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1807 oal, omitHidden, csel, sg));
1811 public void pdbFromFile_actionPerformed()
1813 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1814 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1815 chooser.setFileView(new jalview.io.JalviewFileView());
1816 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1817 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1819 int value = chooser.showOpenDialog(null);
1821 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1823 String choice = chooser.getSelectedFile().getPath();
1824 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1825 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1830 public void enterPDB_actionPerformed()
1832 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1833 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1835 if (id != null && id.length() > 0)
1837 PDBEntry entry = new PDBEntry();
1838 entry.setId(id.toUpperCase());
1839 sequence.getDatasetSequence().addPDBId(entry);
1843 public void discoverPDB_actionPerformed()
1846 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1848 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1849 Thread discpdb = new Thread(new Runnable()
1854 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1855 .fetchDBRefs(false);
1862 public void sequenceFeature_actionPerformed()
1864 SequenceGroup sg = ap.av.getSelectionGroup();
1870 int rsize = 0, gSize = sg.getSize();
1871 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1872 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1874 for (int i = 0; i < gSize; i++)
1876 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1877 int end = sg.findEndRes(sg.getSequenceAt(i));
1880 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1881 features[rsize] = new SequenceFeature(null, null, null, start, end,
1886 rseqs = new SequenceI[rsize];
1887 tfeatures = new SequenceFeature[rsize];
1888 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1889 System.arraycopy(features, 0, tfeatures, 0, rsize);
1890 features = tfeatures;
1892 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1893 features, true, ap))
1895 ap.alignFrame.setShowSeqFeatures(true);
1896 ap.highlightSearchResults(null);
1900 public void textColour_actionPerformed()
1902 SequenceGroup sg = getGroup();
1905 new TextColourChooser().chooseColour(ap, sg);
1909 public void colourByStructure(String pdbid)
1911 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1914 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1915 "Coloured by " + pdbid, anots);
1917 ap.av.alignment.addAnnotation(an);
1918 an.createSequenceMapping(sequence, 0, true);
1919 // an.adjustForAlignment();
1920 ap.av.alignment.setAnnotationIndex(an, 0);
1922 ap.adjustAnnotationHeight();
1924 sequence.addAlignmentAnnotation(an);
1928 public void editSequence_actionPerformed(ActionEvent actionEvent)
1930 SequenceGroup sg = ap.av.getSelectionGroup();
1934 if (sequence == null)
1935 sequence = (Sequence) sg.getSequenceAt(0);
1937 EditNameDialog dialog = new EditNameDialog(
1938 sequence.getSequenceAsString(sg.getStartRes(),
1939 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1940 "Edit Sequence", ap.alignFrame);
1944 EditCommand editCommand = new EditCommand("Edit Sequences",
1945 EditCommand.REPLACE, dialog.getName().replace(' ',
1946 ap.av.getGapCharacter()),
1947 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1948 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1950 ap.alignFrame.addHistoryItem(editCommand);
1952 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()