Differences between revisions 5 and 10 (spanning 5 versions)
Revision 5 as of 2008-05-12 16:48:18
Size: 5664
Editor: cabernet
Comment:
Revision 10 as of 2008-05-13 23:04:23
Size: 5789
Editor: cabernet
Comment:
Deletions are marked like this. Additions are marked like this.
Line 16: Line 16:
 1. Get a handler to the cytoPanel west, which is the control panel  (1) Get a handler to the cytoPanel west, which is the control panel
{{{
Line 18: Line 19:
}}}
Line 19: Line 21:
 1.#2 Create a JPanel object (a class extends JPanel, say, MyPanel).
 
 (2) Create a JPanel object (a class extends JPanel, say, MyPanel).
{{{
Line 22: Line 24:
}}}
Line 23: Line 26:
 1.#3 Add it to the control panel.  (3) Add it to the control panel.
{{{
Line 25: Line 29:
}}}
Line 30: Line 35:
ImageIcon icon = new ImageIcon(getClass().getResource("/tiger.jpg")); MyPluginToolBarAction toolbarAction = new MyPluginToolBarAction(icon, this); The toolbarAction must extend the class cytoscape.util.CytoscapeAction and its method isInToolBar()returns true. {{{
ImageIcon icon = new ImageIcon(getClass().getResource("/tiger.jpg"));
MyPluginToolBarAction toolbarAction = new MyPluginToolBarAction(icon, this);
}}}

The toolbarAction must extend the class cytoscape.util.CytoscapeAction and its method isInToolBar()returns true.
Line 33: Line 43:
{{{
Line 34: Line 45:
}}}
Line 46: Line 58:
{{{
//create a network without a view CyNetwork
yNetwork = Cytoscape.createNetwork("network1", false);
Line 47: Line 62:
//create a network without a view CyNetwork cyNetwork = Cytoscape.createNetwork("network1", false); CyNode node0 = Cytoscape.getCyNode("rain", true);
CyNode node1 = Cytoscape.getCyNode("rainbow", true);
CyNode node2 = Cytoscape.getCyNode("rabbit", true);
CyNode node3 = Cytoscape.getCyNode("yellow", true);
Line 49: Line 67:
CyNode node0 = Cytoscape.getCyNode("rain", true); CyNode node1 = Cytoscape.getCyNode("rainbow", true); CyNode node2 = Cytoscape.getCyNode("rabbit", true); CyNode node3 = Cytoscape.getCyNode("yellow", true); cyNetwork.addNode(node0);
cyNetwork.addNode(node1);
cyNetwork.addNode(node2);
cyNetwork.addNode(node3);
Line 51: Line 72:
cyNetwork.addNode(node0); cyNetwork.addNode(node1); cyNetwork.addNode(node2); cyNetwork.addNode(node3); CyEdge edge0 = Cytoscape.getCyEdge(node0, node1, Semantics.INTERACTION, "pp", true);
CyEdge edge1 = Cytoscape.getCyEdge(node0, node2, Semantics.INTERACTION, "pp", true);
CyEdge edge2 = Cytoscape.getCyEdge(node0, node3, Semantics.INTERACTION, "pp", true);
Line 53: Line 76:
CyEdge edge0 = Cytoscape.getCyEdge(node0, node1, Semantics.INTERACTION, "pp", true); CyEdge edge1 = Cytoscape.getCyEdge(node0, node2, Semantics.INTERACTION, "pp", true); CyEdge edge2 = Cytoscape.getCyEdge(node0, node3, Semantics.INTERACTION, "pp", true); cyNetwork.addEdge(edge0); cyNetwork.addEdge(edge1); cyNetwork.addEdge(edge2);
cyNetwork.addEdge(edge0);
cyNetwork.addEdge(edge1);
cyNetwork.addEdge(edge2);
}}}
Line 56: Line 81:
{{{
Line 58: Line 83:

The following statement will destroy a network. Cytoscape.destroyNetwork(cyNetwork);
}}}
The following statement will destroy a network.
{{{
Cytoscape.destroyNetwork(cyNetwork);
}}}
Line 63: Line 90:

// Create a view for the network CyNetworkView cyView = Cytoscape.createNetworkView(cyNetwork, "MyNetwork");

If a node is hidden, the node and all of its incident edges will be hidden. // hide a node cyNetwork.hideNode(node1.getRootGraphIndex());
{{{
// Create a view for the network CyNetworkView
cyView = Cytoscape.createNetworkView(cyNetwork, "MyNetwork");
}}}
If a node is hidden, the node and all of its incident edges will be hidden.
{{{
// hide a node
cyNetwork.hideNode(node1.getRootGraphIndex());
}}}
Line 69: Line 100:
{{{
Line 71: Line 102:
}}}

TableOfContents([2])

Cytoscape developer's tutorial

This tutorial will show some code snippets about how to use Cytoscape APIs on plugin development. Each feature is included in a sample plugin, which can serve as a starting point or template for new plugin developers. The code snippets can also be used as reference for experienced developers.

Cytoscape plugin is usually packaged in a jar file and deployed to the plugins directory of Cytoscape. When Cytoscape starts up and initializes, its plugin manager will look up all the plugins in plugins directory. A plugin should have following three components.

  1. A class, which extends CytoscapePlugin. This is the entry point to Cytoscape.

  2. A manifest file, explicitly list the class, which extended CytoscapePlugin class

  3. A plugin.props file, which list the information about the plugin, such as plugin name, author, release date and more. Although this file is not absolutely required, it is recommended to have one, since plugin manager will need the information to handle the plugin properly. See the page at http://www.cytoscape.org/cgi-bin/moin.cgi/Cytoscape_Plugin_Tutorial for detail about the definition of a plugin.props.

If plugin developer will share and publish their plugins, they are encouraged to submit their plugins to Cytoscape plugin website at http://cytoscape.org/plugins/index.php .

How to add a tabbed Panel to Control panel?

It takes three steps to add a tabbed panel to the control panel.

  • (1) Get a handler to the cytoPanel west, which is the control panel

CytoPanelImp ctrlPanel = (CytoPanelImp) Cytoscape.getDesktop().getCytoPanel(SwingConstants.WEST);
  • (2) Create a JPanel object (a class extends JPanel, say, MyPanel).

MyPanel myPanel = new MyPanel();
  • (3) Add it to the control panel.

ctrlPanel.add("myPanel", myPanel);

Download a sample plugin, here.

How to add an image icon (menu item) to the toolbar?

  • (1) Create a toolbarAction

ImageIcon icon = new ImageIcon(getClass().getResource("/tiger.jpg"));
MyPluginToolBarAction toolbarAction = new MyPluginToolBarAction(icon, this); 

The toolbarAction must extend the class cytoscape.util.CytoscapeAction and its method isInToolBar()returns true.

  • (2) Add the action to Cytoscape toolbar

Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) toolbarAction);

Download a sample plugin, here.

How to create a submenu?

Same as adding an image icon to the toolbar, the difference is that its method “isInMenuBar()” in CytoscapeAction should return true.

Download a sample plugin, here.

How to create, modify, and destroy a network, nodes, and edges?

A general procedure to create a network is, first create a bunch of CyNodes using the Cytoscape.getCyNode() method, then create edges using those nodes with Cytoscape.getCyEdge() method. Then call Cytoscape.createNetwork() with the list of nodes and edges just created.

The following snippet of code will create network with three nodes and three edges. The name of the network is “network1”.

//create a network without a view CyNetwork 
yNetwork = Cytoscape.createNetwork("network1", false);

CyNode node0 = Cytoscape.getCyNode("rain", true); 
CyNode node1 = Cytoscape.getCyNode("rainbow", true); 
CyNode node2 = Cytoscape.getCyNode("rabbit", true); 
CyNode node3 = Cytoscape.getCyNode("yellow", true);

cyNetwork.addNode(node0); 
cyNetwork.addNode(node1); 
cyNetwork.addNode(node2); 
cyNetwork.addNode(node3);

CyEdge edge0 = Cytoscape.getCyEdge(node0, node1, Semantics.INTERACTION, "pp", true); 
CyEdge edge1 = Cytoscape.getCyEdge(node0, node2, Semantics.INTERACTION, "pp", true); 
CyEdge edge2 = Cytoscape.getCyEdge(node0, node3, Semantics.INTERACTION, "pp", true); 

cyNetwork.addEdge(edge0); 
cyNetwork.addEdge(edge1); 
cyNetwork.addEdge(edge2);

To remove a node, we use the RootGraphIndex of the Node as follows. Note that when we remove a node, we have the option to remove it from the invisible rootGrpah or just hide it from current network.

cyNetwork.removeNode(node1.getRootGraphIndex(), true);

The following statement will destroy a network.

Cytoscape.destroyNetwork(cyNetwork);

How to create, modify, and destroy a network view?

A network may or may not have a view. If we already have a network, we can create a view with the following statement.

// Create a view for the network CyNetworkView 
cyView = Cytoscape.createNetworkView(cyNetwork, "MyNetwork");

If a node is hidden, the node and all of its incident edges will be hidden.

// hide a node 
cyNetwork.hideNode(node1.getRootGraphIndex());

The following statement will destroy a network view.

Cytoscape.destroyNetworkView(cyView);

How to determine which nodes are currently selected on a network?

How to handle events from a network (and discuss each event type)?

How to change the background color of a view?

How to zoom a network view?

How to load attribute data?

How to remove attributes?

How to use a web service client?

How to write a web service client?

How to use the VizMapper programmatically?

How to apply a continuous color gradient to nodes according to their degree?

How to load a visual properties file?

How to write a layout algorithm?

How to customize node graphics?

How to write a Group Viewer?

How to add components to the node view, edge view, and attribute browser context menus?

How to save/restore plugin states?

How to use Cytoscape task monitor to show the progress of my job?

plugin_developer_tutorial (last edited 2011-09-06 18:52:37 by merlot)

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