Differences between revisions 4 and 10 (spanning 6 versions)
Revision 4 as of 2008-05-12 16:35:11
Size: 4840
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 4: Line 4:
Line 12: Line 11:

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 . 
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 .
Line 16: Line 14:
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 
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
{{{
Line 19: Line 19:
 1. Create a JPanel object (a class extends JPanel, say, MyPanel)
MyPanel myPanel = new MyPanel();  
 1. Add it to the control panel.   
}}}

(2) Create a JPanel object (a class extends JPanel, say, MyPanel).
{{{

MyPanel myPanel = new MyPanel();
}}}

 (3) Add it to the control panel.
{{{
Line 23: Line 29:
}}}
Line 26: Line 33:
== 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);
}}}
Line 27: Line 40:
== 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);
Line 33: Line 42:
 (2) Add the action to Cytoscape toolbar  . (2) Add the action to Cytoscape toolbar
{{{
Line 35: Line 45:
}}}
Line 44: Line 55:
Line 48: Line 58:
{{{
//create a network without a view CyNetwork
yNetwork = Cytoscape.createNetwork("network1", false);
Line 49: 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 node0 = Cytoscape.getCyNode("rain", true); 
CyNode node1 = Cytoscape.getCyNode("rainbow", true); 
CyNode node2 = Cytoscape.getCyNode("rabbit", true); 
Line 57: Line 67:
cyNetwork.addNode(node0);
cyNetwork.addNode(node1);
cyNetwork.addNode(node2);
cyNetwork.addNode(node0); 
cyNetwork.addNode(node1); 
cyNetwork.addNode(node2); 
Line 61: Line 71:
   
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);

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); 
Line 68: Line 79:
}}}
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? ==
Line 69: Line 105:
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.
Line 71: Line 106:
cyNetwork.removeNode(node1.getRootGraphIndex(), true); == How to handle events from a network (and discuss each event type)? ==
Line 73: Line 108:
The following statement will destroy a network.
Cytoscape.destroyNetwork(cyNetwork);
Line 76: Line 109:
== How to create, modify, and destroy a network view? == == How to change the background color of a view? ==
Line 78: Line 111:
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");
== How to zoom a network view? ==
Line 83: Line 113:
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.
== How to load attribute data? ==
Line 89: Line 115:
Cytoscape.destroyNetworkView(cyView); == How to remove attributes? ==
Line 91: Line 117:
== How to determine which nodes are currently selected on a network? == == 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? ==

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