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].getRNAStruc() != null){
268 rnastruc=aa[i].getRNAStruc();
273 AlignmentAnnotation a[] = seq.getAnnotation();
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
286 new AppVarna(seq.getSequenceAsString(),rnastrucF,seq.getName(),ap);
289 viewStructureMenu.add(menuItem);
292 menuItem = new JMenuItem("Hide Sequences");
293 menuItem.addActionListener(new java.awt.event.ActionListener()
295 public void actionPerformed(ActionEvent e)
297 hideSequences(false);
302 if (ap.av.getSelectionGroup() != null
303 && ap.av.getSelectionGroup().getSize() > 1)
305 menuItem = new JMenuItem("Represent Group with " + seq.getName());
306 menuItem.addActionListener(new java.awt.event.ActionListener()
308 public void actionPerformed(ActionEvent e)
313 sequenceMenu.add(menuItem);
316 if (ap.av.hasHiddenRows)
318 final int index = ap.av.alignment.findIndex(seq);
320 if (ap.av.adjustForHiddenSeqs(index)
321 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
323 menuItem = new JMenuItem("Reveal Sequences");
324 menuItem.addActionListener(new ActionListener()
326 public void actionPerformed(ActionEvent e)
328 ap.av.showSequence(index);
329 if (ap.overviewPanel != null)
331 ap.overviewPanel.updateOverviewImage();
338 menuItem = new JMenuItem("Reveal All");
339 menuItem.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent e)
343 ap.av.showAllHiddenSeqs();
344 if (ap.overviewPanel != null)
346 ap.overviewPanel.updateOverviewImage();
356 SequenceGroup sg = ap.av.getSelectionGroup();
360 groupName.setText("Name: "+sg.getName());
361 groupName.setText("Edit name and description of current group.");
363 if (sg.cs instanceof ZappoColourScheme)
365 zappoColour.setSelected(true);
367 else if (sg.cs instanceof TaylorColourScheme)
369 taylorColour.setSelected(true);
371 else if (sg.cs instanceof PIDColourScheme)
373 PIDColour.setSelected(true);
375 else if (sg.cs instanceof Blosum62ColourScheme)
377 BLOSUM62Colour.setSelected(true);
379 else if (sg.cs instanceof UserColourScheme)
381 userDefinedColour.setSelected(true);
383 else if (sg.cs instanceof HydrophobicColourScheme)
385 hydrophobicityColour.setSelected(true);
387 else if (sg.cs instanceof HelixColourScheme)
389 helixColour.setSelected(true);
391 else if (sg.cs instanceof StrandColourScheme)
393 strandColour.setSelected(true);
395 else if (sg.cs instanceof TurnColourScheme)
397 turnColour.setSelected(true);
399 else if (sg.cs instanceof BuriedColourScheme)
401 buriedColour.setSelected(true);
403 else if (sg.cs instanceof ClustalxColourScheme)
405 clustalColour.setSelected(true);
407 else if (sg.cs instanceof PurinePyrimidineColourScheme)
409 purinePyrimidineColour.setSelected(true);
411 /* else if (sg.cs instanceof CovariationColourScheme)
413 covariationColour.setSelected(true);
417 noColourmenuItem.setSelected(true);
420 if (sg.cs != null && sg.cs.conservationApplied())
422 conservationMenuItem.setSelected(true);
424 displayNonconserved.setSelected(sg.getShowNonconserved());
425 showText.setSelected(sg.getDisplayText());
426 showColourText.setSelected(sg.getColourText());
427 showBoxes.setSelected(sg.getDisplayBoxes());
428 // add any groupURLs to the groupURL submenu and make it visible
429 if (groupLinks != null && groupLinks.size() > 0)
431 buildGroupURLMenu(sg, groupLinks);
433 // Add a 'show all structures' for the current selection
434 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
435 for (SequenceI sq: ap.av.getSequenceSelection())
437 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
439 for (PDBEntry pe: pes)
441 pdbe.put(pe.getId(), pe);
447 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
448 final JMenuItem gpdbview;
449 structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
450 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
451 gpdbview.addActionListener(new ActionListener()
455 public void actionPerformed(ActionEvent e)
457 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
464 groupMenu.setVisible(false);
465 editMenu.setVisible(false);
468 if (!ap.av.alignment.getGroups().contains(sg))
470 unGroupMenuItem.setVisible(false);
475 sequenceMenu.setVisible(false);
476 structureMenu.setVisible(false);
479 if (links != null && links.size() > 0)
482 JMenu linkMenu = new JMenu("Link");
483 Vector linkset = new Vector();
484 for (int i = 0; i < links.size(); i++)
486 String link = links.elementAt(i).toString();
487 UrlLink urlLink = null;
490 urlLink = new UrlLink(link);
491 } catch (Exception foo)
493 jalview.bin.Cache.log.error("Exception for URLLink '" + link
498 if (!urlLink.isValid())
500 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
503 final String label = urlLink.getLabel();
504 if (urlLink.isDynamic())
507 // collect matching db-refs
508 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
509 seq.getDBRef(), new String[]
510 { urlLink.getTarget() });
511 // collect id string too
512 String id = seq.getName();
513 String descr = seq.getDescription();
514 if (descr != null && descr.length() < 1)
521 for (int r = 0; r < dbr.length; r++)
523 if (id != null && dbr[r].getAccessionId().equals(id))
525 // suppress duplicate link creation for the bare sequence ID
526 // string with this link
529 // create Bare ID link for this RUL
530 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
534 for (int u = 0; u < urls.length; u += 2)
536 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
538 linkset.addElement(urls[u] + "|" + urls[u + 1]);
539 addshowLink(linkMenu, label + "|" + urls[u],
548 // create Bare ID link for this RUL
549 String[] urls = urlLink.makeUrls(id, true);
552 for (int u = 0; u < urls.length; u += 2)
554 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
556 linkset.addElement(urls[u] + "|" + urls[u + 1]);
557 addshowLink(linkMenu, label, urls[u + 1]);
562 // Create urls from description but only for URL links which are regex
564 if (descr != null && urlLink.getRegexReplace() != null)
566 // create link for this URL from description where regex matches
567 String[] urls = urlLink.makeUrls(descr, true);
570 for (int u = 0; u < urls.length; u += 2)
572 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
574 linkset.addElement(urls[u] + "|" + urls[u + 1]);
575 addshowLink(linkMenu, label, urls[u + 1]);
583 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
585 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
586 // Add a non-dynamic link
587 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
591 if (sequence != null)
593 sequenceMenu.add(linkMenu);
602 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
605 // TODO: usability: thread off the generation of group url content so root
607 // sequence only URLs
608 // ID/regex match URLs
609 groupLinksMenu = new JMenu("Group Link");
610 JMenu[] linkMenus = new JMenu[]
611 { null, new JMenu("IDS"), new JMenu("Sequences"),
612 new JMenu("IDS and Sequences") }; // three types of url that might be
614 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
615 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
616 Hashtable commonDbrefs = new Hashtable();
617 for (int sq = 0; sq < seqs.length; sq++)
620 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
621 .findPosition(sg.getEndRes());
622 // just collect ids from dataset sequence
623 // TODO: check if IDs collected from selecton group intersects with the
624 // current selection, too
625 SequenceI sqi = seqs[sq];
626 while (sqi.getDatasetSequence() != null)
628 sqi = sqi.getDatasetSequence();
630 DBRefEntry[] dbr = sqi.getDBRef();
631 if (dbr != null && dbr.length > 0)
633 for (int d = 0; d < dbr.length; d++)
635 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
636 Object[] sarray = (Object[]) commonDbrefs.get(src);
639 sarray = new Object[2];
640 sarray[0] = new int[]
642 sarray[1] = new String[seqs.length];
644 commonDbrefs.put(src, sarray);
647 if (((String[]) sarray[1])[sq] == null)
650 || (dbr[d].getMap().locateMappedRange(start, end) != null))
652 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
653 ((int[]) sarray[0])[0]++;
659 // now create group links for all distinct ID/sequence sets.
660 boolean addMenu = false; // indicates if there are any group links to give
662 for (int i = 0; i < groupLinks.size(); i++)
664 String link = groupLinks.elementAt(i).toString();
665 GroupUrlLink urlLink = null;
668 urlLink = new GroupUrlLink(link);
669 } catch (Exception foo)
671 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
676 if (!urlLink.isValid())
678 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
681 final String label = urlLink.getLabel();
682 boolean usingNames = false;
683 // Now see which parts of the group apply for this URL
684 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
685 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
686 String[] seqstr, ids; // input to makeUrl
689 int numinput = ((int[]) idset[0])[0];
690 String[] allids = ((String[]) idset[1]);
691 seqstr = new String[numinput];
692 ids = new String[numinput];
693 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
695 if (allids[sq] != null)
697 ids[idcount] = allids[sq];
698 seqstr[idcount++] = idandseqs[1][sq];
704 // just use the id/seq set
705 seqstr = idandseqs[1];
709 // and try and make the groupURL!
711 Object[] urlset = null;
714 urlset = urlLink.makeUrlStubs(ids, seqstr,
715 "FromJalview" + System.currentTimeMillis(), false);
716 } catch (UrlStringTooLongException e)
721 int type = urlLink.getGroupURLType() & 3;
722 // System.out.println(urlLink.getGroupURLType()
723 // +" "+((String[])urlset[3])[0]);
724 // first two bits ofurlLink type bitfield are sequenceids and sequences
725 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
726 addshowLink(linkMenus[type], label
727 + (((type & 1) == 1) ? ("("
728 + (usingNames ? "Names" : ltarget) + ")") : ""),
735 groupLinksMenu = new JMenu("Group Links");
736 for (int m = 0; m < linkMenus.length; m++)
738 if (linkMenus[m] != null
739 && linkMenus[m].getMenuComponentCount() > 0)
741 groupLinksMenu.add(linkMenus[m]);
745 groupMenu.add(groupLinksMenu);
750 * add a show URL menu item to the given linkMenu
754 * - menu label string
758 private void addshowLink(JMenu linkMenu, String label, final String url)
760 JMenuItem item = new JMenuItem(label);
761 item.setToolTipText("open URL: " + url);
762 item.addActionListener(new java.awt.event.ActionListener()
764 public void actionPerformed(ActionEvent e)
766 new Thread(new Runnable()
782 * add a late bound groupURL item to the given linkMenu
786 * - menu label string
787 * @param urlgenerator
788 * GroupURLLink used to generate URL
790 * Object array returned from the makeUrlStubs function.
792 private void addshowLink(JMenu linkMenu, String label,
793 final GroupUrlLink urlgenerator, final Object[] urlstub)
795 JMenuItem item = new JMenuItem(label);
796 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
797 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
806 item.addActionListener(new java.awt.event.ActionListener()
808 public void actionPerformed(ActionEvent e)
810 new Thread(new Runnable()
817 showLink(urlgenerator.constructFrom(urlstub));
818 } catch (UrlStringTooLongException e)
836 private void jbInit() throws Exception
838 groupMenu.setText("Group");
839 groupMenu.setText("Selection");
840 groupName.setText("Name");
841 groupName.addActionListener(new java.awt.event.ActionListener()
843 public void actionPerformed(ActionEvent e)
845 groupName_actionPerformed();
848 sequenceMenu.setText("Sequence");
849 sequenceName.setText("Edit Name/Description");
850 sequenceName.addActionListener(new java.awt.event.ActionListener()
852 public void actionPerformed(ActionEvent e)
854 sequenceName_actionPerformed();
857 PIDColour.setFocusPainted(false);
858 unGroupMenuItem.setText("Remove Group");
859 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
861 public void actionPerformed(ActionEvent e)
863 unGroupMenuItem_actionPerformed();
867 outline.setText("Border colour");
868 outline.addActionListener(new java.awt.event.ActionListener()
870 public void actionPerformed(ActionEvent e)
872 outline_actionPerformed();
875 nucleotideMenuItem.setText("Nucleotide");
876 nucleotideMenuItem.addActionListener(new ActionListener()
878 public void actionPerformed(ActionEvent e)
880 nucleotideMenuItem_actionPerformed();
883 colourMenu.setText("Group Colour");
884 showBoxes.setText("Boxes");
885 showBoxes.setState(true);
886 showBoxes.addActionListener(new ActionListener()
888 public void actionPerformed(ActionEvent e)
890 showBoxes_actionPerformed();
893 showText.setText("Text");
894 showText.setState(true);
895 showText.addActionListener(new ActionListener()
897 public void actionPerformed(ActionEvent e)
899 showText_actionPerformed();
902 showColourText.setText("Colour Text");
903 showColourText.addActionListener(new ActionListener()
905 public void actionPerformed(ActionEvent e)
907 showColourText_actionPerformed();
910 displayNonconserved.setText("Show Nonconserved");
911 displayNonconserved.setState(true);
912 displayNonconserved.addActionListener(new ActionListener()
914 public void actionPerformed(ActionEvent e)
916 showNonconserved_actionPerformed();
919 editMenu.setText("Edit");
921 cut.addActionListener(new ActionListener()
923 public void actionPerformed(ActionEvent e)
925 cut_actionPerformed();
928 upperCase.setText("To Upper Case");
929 upperCase.addActionListener(new ActionListener()
931 public void actionPerformed(ActionEvent e)
936 copy.setText("Copy");
937 copy.addActionListener(new ActionListener()
939 public void actionPerformed(ActionEvent e)
941 copy_actionPerformed();
944 lowerCase.setText("To Lower Case");
945 lowerCase.addActionListener(new ActionListener()
947 public void actionPerformed(ActionEvent e)
952 toggle.setText("Toggle Case");
953 toggle.addActionListener(new ActionListener()
955 public void actionPerformed(ActionEvent e)
960 pdbMenu.setText("Associate Structure with Sequence");
961 pdbFromFile.setText("From File");
962 pdbFromFile.addActionListener(new ActionListener()
964 public void actionPerformed(ActionEvent e)
966 pdbFromFile_actionPerformed();
969 enterPDB.setText("Enter PDB Id");
970 enterPDB.addActionListener(new ActionListener()
972 public void actionPerformed(ActionEvent e)
974 enterPDB_actionPerformed();
977 discoverPDB.setText("Discover PDB ids");
978 discoverPDB.addActionListener(new ActionListener()
980 public void actionPerformed(ActionEvent e)
982 discoverPDB_actionPerformed();
985 outputMenu.setText("Output to Textbox...");
986 sequenceFeature.setText("Create Sequence Feature");
987 sequenceFeature.addActionListener(new ActionListener()
989 public void actionPerformed(ActionEvent e)
991 sequenceFeature_actionPerformed();
994 textColour.setText("Text Colour");
995 textColour.addActionListener(new ActionListener()
997 public void actionPerformed(ActionEvent e)
999 textColour_actionPerformed();
1002 jMenu1.setText("Group");
1003 structureMenu.setText("Structure");
1004 viewStructureMenu.setText("View Structure");
1005 // colStructureMenu.setText("Colour By Structure");
1006 editSequence.setText("Edit Sequence...");
1007 editSequence.addActionListener(new ActionListener()
1009 public void actionPerformed(ActionEvent actionEvent)
1011 editSequence_actionPerformed(actionEvent);
1015 * annotationMenuItem.setText("By Annotation");
1016 * annotationMenuItem.addActionListener(new ActionListener() { public void
1017 * actionPerformed(ActionEvent actionEvent) {
1018 * annotationMenuItem_actionPerformed(actionEvent); } });
1024 this.add(structureMenu);
1025 groupMenu.add(editMenu);
1026 groupMenu.add(outputMenu);
1027 groupMenu.add(sequenceFeature);
1028 groupMenu.add(jMenu1);
1029 sequenceMenu.add(sequenceName);
1030 colourMenu.add(textColour);
1031 colourMenu.add(noColourmenuItem);
1032 colourMenu.add(clustalColour);
1033 colourMenu.add(BLOSUM62Colour);
1034 colourMenu.add(PIDColour);
1035 colourMenu.add(zappoColour);
1036 colourMenu.add(taylorColour);
1037 colourMenu.add(hydrophobicityColour);
1038 colourMenu.add(helixColour);
1039 colourMenu.add(strandColour);
1040 colourMenu.add(turnColour);
1041 colourMenu.add(buriedColour);
1042 colourMenu.add(nucleotideMenuItem);
1043 colourMenu.add(purinePyrimidineColour);
1044 //colourMenu.add(covariationColour);
1045 colourMenu.add(userDefinedColour);
1047 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1049 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1050 .getUserColourSchemes().keys();
1052 while (userColours.hasMoreElements())
1054 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1055 item.addActionListener(new ActionListener()
1057 public void actionPerformed(ActionEvent evt)
1059 userDefinedColour_actionPerformed(evt);
1062 colourMenu.add(item);
1066 colourMenu.addSeparator();
1067 colourMenu.add(abovePIDColour);
1068 colourMenu.add(conservationMenuItem);
1069 // colourMenu.add(annotationMenuItem);
1072 editMenu.add(editSequence);
1073 editMenu.add(upperCase);
1074 editMenu.add(lowerCase);
1075 editMenu.add(toggle);
1076 pdbMenu.add(pdbFromFile);
1077 pdbMenu.add(enterPDB);
1078 pdbMenu.add(discoverPDB);
1079 jMenu1.add(groupName);
1080 jMenu1.add(unGroupMenuItem);
1081 jMenu1.add(colourMenu);
1082 jMenu1.add(showBoxes);
1083 jMenu1.add(showText);
1084 jMenu1.add(showColourText);
1085 jMenu1.add(outline);
1086 jMenu1.add(displayNonconserved);
1087 structureMenu.add(pdbMenu);
1088 structureMenu.add(viewStructureMenu);
1089 // structureMenu.add(colStructureMenu);
1090 noColourmenuItem.setText("None");
1091 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1093 public void actionPerformed(ActionEvent e)
1095 noColourmenuItem_actionPerformed();
1099 clustalColour.setText("Clustalx colours");
1100 clustalColour.addActionListener(new java.awt.event.ActionListener()
1102 public void actionPerformed(ActionEvent e)
1104 clustalColour_actionPerformed();
1107 zappoColour.setText("Zappo");
1108 zappoColour.addActionListener(new java.awt.event.ActionListener()
1110 public void actionPerformed(ActionEvent e)
1112 zappoColour_actionPerformed();
1115 taylorColour.setText("Taylor");
1116 taylorColour.addActionListener(new java.awt.event.ActionListener()
1118 public void actionPerformed(ActionEvent e)
1120 taylorColour_actionPerformed();
1123 hydrophobicityColour.setText("Hydrophobicity");
1124 hydrophobicityColour
1125 .addActionListener(new java.awt.event.ActionListener()
1127 public void actionPerformed(ActionEvent e)
1129 hydrophobicityColour_actionPerformed();
1132 helixColour.setText("Helix propensity");
1133 helixColour.addActionListener(new java.awt.event.ActionListener()
1135 public void actionPerformed(ActionEvent e)
1137 helixColour_actionPerformed();
1140 strandColour.setText("Strand propensity");
1141 strandColour.addActionListener(new java.awt.event.ActionListener()
1143 public void actionPerformed(ActionEvent e)
1145 strandColour_actionPerformed();
1148 turnColour.setText("Turn propensity");
1149 turnColour.addActionListener(new java.awt.event.ActionListener()
1151 public void actionPerformed(ActionEvent e)
1153 turnColour_actionPerformed();
1156 buriedColour.setText("Buried Index");
1157 buriedColour.addActionListener(new java.awt.event.ActionListener()
1159 public void actionPerformed(ActionEvent e)
1161 buriedColour_actionPerformed();
1164 abovePIDColour.setText("Above % Identity");
1165 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1167 public void actionPerformed(ActionEvent e)
1169 abovePIDColour_actionPerformed();
1172 userDefinedColour.setText("User Defined...");
1173 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1175 public void actionPerformed(ActionEvent e)
1177 userDefinedColour_actionPerformed(e);
1180 PIDColour.setText("Percentage Identity");
1181 PIDColour.addActionListener(new java.awt.event.ActionListener()
1183 public void actionPerformed(ActionEvent e)
1185 PIDColour_actionPerformed();
1188 BLOSUM62Colour.setText("BLOSUM62");
1189 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1191 public void actionPerformed(ActionEvent e)
1193 BLOSUM62Colour_actionPerformed();
1196 purinePyrimidineColour.setText("Purine/Pyrimidine");
1197 purinePyrimidineColour.addActionListener(new java.awt.event.ActionListener()
1199 public void actionPerformed(ActionEvent e)
1201 purinePyrimidineColour_actionPerformed();
1205 covariationColour.addActionListener(new java.awt.event.ActionListener()
1207 public void actionPerformed(ActionEvent e)
1209 covariationColour_actionPerformed();
1213 conservationMenuItem.setText("Conservation");
1214 conservationMenuItem
1215 .addActionListener(new java.awt.event.ActionListener()
1217 public void actionPerformed(ActionEvent e)
1219 conservationMenuItem_actionPerformed();
1224 protected void showNonconserved_actionPerformed()
1226 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1231 * call to refresh view after settings change
1235 ap.updateAnnotation();
1236 ap.paintAlignment(true);
1238 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1247 protected void clustalColour_actionPerformed()
1249 SequenceGroup sg = getGroup();
1250 sg.cs = new ClustalxColourScheme(
1251 sg.getSequences(ap.av.hiddenRepSequences),
1252 ap.av.alignment.getWidth());
1262 protected void zappoColour_actionPerformed()
1264 getGroup().cs = new ZappoColourScheme();
1274 protected void taylorColour_actionPerformed()
1276 getGroup().cs = new TaylorColourScheme();
1286 protected void hydrophobicityColour_actionPerformed()
1288 getGroup().cs = new HydrophobicColourScheme();
1298 protected void helixColour_actionPerformed()
1300 getGroup().cs = new HelixColourScheme();
1310 protected void strandColour_actionPerformed()
1312 getGroup().cs = new StrandColourScheme();
1322 protected void turnColour_actionPerformed()
1324 getGroup().cs = new TurnColourScheme();
1334 protected void buriedColour_actionPerformed()
1336 getGroup().cs = new BuriedColourScheme();
1346 public void nucleotideMenuItem_actionPerformed()
1348 getGroup().cs = new NucleotideColourScheme();
1352 protected void purinePyrimidineColour_actionPerformed()
1354 getGroup().cs = new PurinePyrimidineColourScheme();
1358 protected void covariationColour_actionPerformed()
1360 getGroup().cs = new CovariationColourScheme(sequence.getAnnotation()[0]);
1370 protected void abovePIDColour_actionPerformed()
1372 SequenceGroup sg = getGroup();
1378 if (abovePIDColour.isSelected())
1380 sg.cs.setConsensus(AAFrequency.calculate(
1381 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1382 sg.getEndRes() + 1));
1384 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1387 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1389 SliderPanel.showPIDSlider();
1392 // remove PIDColouring
1394 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1406 protected void userDefinedColour_actionPerformed(ActionEvent e)
1408 SequenceGroup sg = getGroup();
1410 if (e.getActionCommand().equals("User Defined..."))
1412 new UserDefinedColours(ap, sg);
1416 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1417 .getUserColourSchemes().get(e.getActionCommand());
1430 protected void PIDColour_actionPerformed()
1432 SequenceGroup sg = getGroup();
1433 sg.cs = new PIDColourScheme();
1434 sg.cs.setConsensus(AAFrequency.calculate(
1435 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1436 sg.getEndRes() + 1));
1446 protected void BLOSUM62Colour_actionPerformed()
1448 SequenceGroup sg = getGroup();
1450 sg.cs = new Blosum62ColourScheme();
1452 sg.cs.setConsensus(AAFrequency.calculate(
1453 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1454 sg.getEndRes() + 1));
1465 protected void noColourmenuItem_actionPerformed()
1467 getGroup().cs = null;
1477 protected void conservationMenuItem_actionPerformed()
1479 SequenceGroup sg = getGroup();
1485 if (conservationMenuItem.isSelected())
1487 Conservation c = new Conservation("Group",
1488 ResidueProperties.propHash, 3,
1489 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1490 sg.getEndRes() + 1);
1493 c.verdict(false, ap.av.ConsPercGaps);
1495 sg.cs.setConservation(c);
1497 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1498 SliderPanel.showConservationSlider();
1501 // remove ConservationColouring
1503 sg.cs.setConservation(null);
1509 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1511 SequenceGroup sg = getGroup();
1517 AnnotationColourGradient acg = new AnnotationColourGradient(
1518 sequence.getAnnotation()[0], null,
1519 AnnotationColourGradient.NO_THRESHOLD);
1521 acg.predefinedColours = true;
1533 protected void groupName_actionPerformed()
1536 SequenceGroup sg = getGroup();
1537 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1538 sg.getDescription(), " Group Name ",
1539 "Group Description ", "Edit Group Name/Description",
1547 sg.setName(dialog.getName());
1548 sg.setDescription(dialog.getDescription());
1553 * Get selection group - adding it to the alignment if necessary.
1555 * @return sequence group to operate on
1557 SequenceGroup getGroup()
1559 SequenceGroup sg = ap.av.getSelectionGroup();
1560 // this method won't add a new group if it already exists
1563 ap.av.alignment.addGroup(sg);
1575 void sequenceName_actionPerformed()
1577 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1578 sequence.getDescription(), " Sequence Name ",
1579 "Sequence Description ", "Edit Sequence Name/Description",
1587 if (dialog.getName() != null)
1589 if (dialog.getName().indexOf(" ") > -1)
1591 JOptionPane.showMessageDialog(ap,
1592 "Spaces have been converted to \"_\"",
1593 "No spaces allowed in Sequence Name",
1594 JOptionPane.WARNING_MESSAGE);
1597 sequence.setName(dialog.getName().replace(' ', '_'));
1598 ap.paintAlignment(false);
1601 sequence.setDescription(dialog.getDescription());
1603 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1614 void unGroupMenuItem_actionPerformed()
1616 SequenceGroup sg = ap.av.getSelectionGroup();
1617 ap.av.alignment.deleteGroup(sg);
1618 ap.av.setSelectionGroup(null);
1628 protected void outline_actionPerformed()
1630 SequenceGroup sg = getGroup();
1631 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1636 sg.setOutlineColour(col);
1648 public void showBoxes_actionPerformed()
1650 getGroup().setDisplayBoxes(showBoxes.isSelected());
1660 public void showText_actionPerformed()
1662 getGroup().setDisplayText(showText.isSelected());
1672 public void showColourText_actionPerformed()
1674 getGroup().setColourText(showColourText.isSelected());
1678 public void showLink(String url)
1682 jalview.util.BrowserLauncher.openURL(url);
1683 } catch (Exception ex)
1686 .showInternalMessageDialog(
1688 "Unixers: Couldn't find default web browser."
1689 + "\nAdd the full path to your browser in Preferences.",
1690 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1692 ex.printStackTrace();
1696 void hideSequences(boolean representGroup)
1698 SequenceGroup sg = ap.av.getSelectionGroup();
1699 if (sg == null || sg.getSize() < 1)
1701 ap.av.hideSequence(new SequenceI[]
1706 ap.av.setSelectionGroup(null);
1710 ap.av.hideRepSequences(sequence, sg);
1715 int gsize = sg.getSize();
1718 hseqs = new SequenceI[gsize];
1721 for (int i = 0; i < gsize; i++)
1723 hseqs[index++] = sg.getSequenceAt(i);
1726 ap.av.hideSequence(hseqs);
1727 // refresh(); TODO: ? needed ?
1728 ap.av.sendSelection();
1731 public void copy_actionPerformed()
1733 ap.alignFrame.copy_actionPerformed(null);
1736 public void cut_actionPerformed()
1738 ap.alignFrame.cut_actionPerformed(null);
1741 void changeCase(ActionEvent e)
1743 Object source = e.getSource();
1744 SequenceGroup sg = ap.av.getSelectionGroup();
1748 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1749 sg.getEndRes() + 1);
1754 if (source == toggle)
1756 description = "Toggle Case";
1757 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1759 else if (source == upperCase)
1761 description = "To Upper Case";
1762 caseChange = ChangeCaseCommand.TO_UPPER;
1766 description = "To Lower Case";
1767 caseChange = ChangeCaseCommand.TO_LOWER;
1770 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1771 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1774 ap.alignFrame.addHistoryItem(caseCommand);
1776 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1782 public void outputText_actionPerformed(ActionEvent e)
1784 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1785 cap.setForInput(null);
1786 Desktop.addInternalFrame(cap,
1787 "Alignment output - " + e.getActionCommand(), 600, 500);
1789 String[] omitHidden = null;
1791 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1792 // or we simply trust the user wants
1793 // wysiwig behaviour
1794 SequenceGroup sg = ap.av.getSelectionGroup();
1795 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1796 omitHidden = ap.av.getViewAsString(true);
1797 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1798 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1801 for (int i = 0; i < nala.length; i++)
1803 AlignmentAnnotation na = nala[i];
1804 oal.addAnnotation(na);
1807 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1808 oal, omitHidden, csel, sg));
1812 public void pdbFromFile_actionPerformed()
1814 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1815 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1816 chooser.setFileView(new jalview.io.JalviewFileView());
1817 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1818 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1820 int value = chooser.showOpenDialog(null);
1822 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1824 String choice = chooser.getSelectedFile().getPath();
1825 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1826 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1831 public void enterPDB_actionPerformed()
1833 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1834 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1836 if (id != null && id.length() > 0)
1838 PDBEntry entry = new PDBEntry();
1839 entry.setId(id.toUpperCase());
1840 sequence.getDatasetSequence().addPDBId(entry);
1844 public void discoverPDB_actionPerformed()
1847 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1849 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1850 Thread discpdb = new Thread(new Runnable()
1855 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1856 .fetchDBRefs(false);
1863 public void sequenceFeature_actionPerformed()
1865 SequenceGroup sg = ap.av.getSelectionGroup();
1871 int rsize = 0, gSize = sg.getSize();
1872 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1873 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1875 for (int i = 0; i < gSize; i++)
1877 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1878 int end = sg.findEndRes(sg.getSequenceAt(i));
1881 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1882 features[rsize] = new SequenceFeature(null, null, null, start, end,
1887 rseqs = new SequenceI[rsize];
1888 tfeatures = new SequenceFeature[rsize];
1889 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1890 System.arraycopy(features, 0, tfeatures, 0, rsize);
1891 features = tfeatures;
1893 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1894 features, true, ap))
1896 ap.alignFrame.setShowSeqFeatures(true);
1897 ap.highlightSearchResults(null);
1901 public void textColour_actionPerformed()
1903 SequenceGroup sg = getGroup();
1906 new TextColourChooser().chooseColour(ap, sg);
1910 public void colourByStructure(String pdbid)
1912 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1915 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1916 "Coloured by " + pdbid, anots);
1918 ap.av.alignment.addAnnotation(an);
1919 an.createSequenceMapping(sequence, 0, true);
1920 // an.adjustForAlignment();
1921 ap.av.alignment.setAnnotationIndex(an, 0);
1923 ap.adjustAnnotationHeight();
1925 sequence.addAlignmentAnnotation(an);
1929 public void editSequence_actionPerformed(ActionEvent actionEvent)
1931 SequenceGroup sg = ap.av.getSelectionGroup();
1935 if (sequence == null)
1936 sequence = (Sequence) sg.getSequenceAt(0);
1938 EditNameDialog dialog = new EditNameDialog(
1939 sequence.getSequenceAsString(sg.getStartRes(),
1940 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1941 "Edit Sequence", ap.alignFrame);
1945 EditCommand editCommand = new EditCommand("Edit Sequences",
1946 EditCommand.REPLACE, dialog.getName().replace(' ',
1947 ap.av.getGapCharacter()),
1948 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1949 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1951 ap.alignFrame.addHistoryItem(editCommand);
1953 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()