Differences between revisions 3 and 4
Revision 3 as of 2008-05-12 16:18:34
Size: 2431
Editor: cabernet
Comment:
Revision 4 as of 2008-05-12 16:35:11
Size: 4840
Editor: cabernet
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:

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.
 1. A class, which extends CytoscapePlugin. This is the entry point to Cytoscape.
 1. A manifest file, explicitly list the class, which extended CytoscapePlugin class
 1. 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.
Line 16: Line 15:
== 1. How to add a tabbed Panel to Control panel? == == How to add a tabbed Panel to Control panel? ==
Line 18: Line 17:
(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 20: Line 19:

(2)
Create a JPanel object (a class extends JPanel, say, MyPanel)
MyPanel myPanel = new MyPanel();
 

 (3) Add it to the control panel.
 1. Create a JPanel object (a class extends JPanel, say, MyPanel)
MyPanel myPanel = new MyPanel();
 1. Add it to the control panel.
Line 30: Line 27:
== 2. How to add an image icon (menu item) to the toolbar? == == How to add an image icon (menu item) to the toolbar? ==
Line 41: Line 38:
== 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.
Line 42: Line 41:
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? ==

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?

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