Differences between revisions 4 and 5
Revision 4 as of 2008-05-12 16:35:11
Size: 4840
Editor: cabernet
Comment:
Revision 5 as of 2008-05-12 16:48:18
Size: 5664
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 18:
 1. Create a JPanel object (a class extends JPanel, say, MyPanel)
MyPanel myPanel = new MyPanel();  
 1. Add it to the control panel.   

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

MyPanel myPanel = new MyPanel();

 1.#3 Add it to the control panel.
Line 26: Line 28:
== 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.
Line 27: Line 32:
== 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
 . (2) Add the action to Cytoscape toolbar
Line 44: Line 43:
Line 49: Line 47:
//create a network without a view
CyNetwork cyNetwork = Cytoscape.createNetwork("network1", false);
//create a network without a view CyNetwork cyNetwork = Cytoscape.createNetwork("network1", false);
Line 52: Line 49:
CyNode node0 = Cytoscape.getCyNode("rain", true);
CyNode node1 = Cytoscape.getCyNode("rainbow", true);
CyNode node2 = Cytoscape.getCyNode("rabbit", true);
CyNode node3 = Cytoscape.getCyNode("yellow", true);
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 57: Line 51:
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);
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);
Line 73: Line 59:
The following statement will destroy a network.
Cytoscape.destroyNetwork(cyNetwork);
The following statement will destroy a network. Cytoscape.destroyNetwork(cyNetwork);
Line 77: Line 62:
A network may or may not have a view. If we already have a network, we can create a view with the following statement.
Line 78: Line 64:
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");
// Create a view for the network CyNetworkView cyView = Cytoscape.createNetworkView(cyNetwork, "MyNetwork");
Line 83: Line 66:
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.   
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.
Line 92: Line 73:


== 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? ==

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);

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

MyPanel myPanel = new MyPanel();

  1. 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 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);

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