One of the top questions is how to make ones own context menus. It does require some programming, but it should be fairly obvious how it is done. All context menus are loaded as a Plugin. What that means is that once you have built your new menus, and made them into a Java Jar file. Putting them in your Cytoscape plugins directory will have them automatically loaded next time you start Cytoscape.

Before proceeding, please read through the Concepts_Document, and dowload the reference code, which is found in the csplugins\isb\xmas\context directory in CVS. The way that a context menu works is that each menu item is added to a NetworkView, and when clicked on, is run via an abstract static class.

First look at src/csplugins/contextmenu/yeast/YeastPlugin.java. Each menu item is added via code that looks like:

   1 view.addContextMethod( "class phoebe.PNodeView",
   2 "csplugins.contextmenu.yeast.NodeAction",
   3 "openWebInfo",
   4 new Object[] { view } ,
   5 CytoscapeInit.getClassLoader() );
   6 

Breaking this down:

class phoebe.PNodeView

refers to the viewable element that will trigger this Context menu. If there are any questions, please use the discussion list to figure out which class you should be using. Generally, PNodeView, and PEdgeView should cover most Nodes and Edges. The next line

csplugins.contextmenu.yeast.NodeAction

is the class where your custom menu item is found. The third line is the name of the method that returns a menu item, in this case:

openWebInfo

The fourth line are the arguments that can be passed to the method at invocation time. The final line is needed so that the menu item can be loaded properly.

The code for NodeAction.openWebInfo is where the actuall menu item is defined:

   1 /**
   2 * This will open an web page that will give you more info.
   3 */
   4 public static JMenuItem openWebInfo ( Object[] args, PNode node ) {
   5 
   6 final PNode nv = node;
   7 
   8 JMenu web_menu = new JMenu( "Web Info" );
   9 
  10 web_menu.add( new JMenuItem( new AbstractAction( "SGD yeast only" ) {
  11 public void actionPerformed ( ActionEvent e ) {
  12 // Do this in the GUI Event Dispatch thread...
  13 SwingUtilities.invokeLater( new Runnable() {
  14 public void run() {
  15 String gene = null;
  16 if ( nv instanceof PNodeView ) {
  17 gene = ( ( PNodeView ) nv).getLabel().getText();
  18 }
  19 if ( gene == null ) {
  20 gene = ( String )nv.getClientProperty("tooltip");
  21 }
  22 OpenBrowser.openURL( "http://db.yeastgenome.org/cgi-bin/SGD/locus.pl?locus="+gene );
  23 
  24 } } ); } } ) );
  25 return web_menu;
  26 }
  27 

Simply replacing the URL with your own, is enough to add support for a new organism. Please look at the rest of this class, and use the discussion list if you have any problems.

Species_Specific_Context_Menus (last edited 2009-02-12 01:03:15 by localhost)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux