Difference between revisions of "CytoscapeRPC"

From BioAssist
Jump to: navigation, search
m (Python)
Line 206: Line 206:
You can call XML-RPC functions using the [http://www.omegahat.org/SSOAP/ SSOAP] package. Unfortunately there are some problems with the XML-RPC client, email Jan Bot to get a modified SSOAP package which works with CytoscapeRPC. (For now, download it directly from [https://wiki.nbic.nl/images/9/97/SSOAP_0.5-5.tar.gz here].) The maintainer of SSOAP just released a new XML-RPC client for R, located [http://www.omegahat.org/XMLRPC/ here]. This package is not finished yet and has not been tested with CytoscapeRPC.
You can call the XML-RPC functions directly from R using the [http://www.omegahat.org/XMLRPC/ XML-RPC library] but there is also the excellent [http://www.bioconductor.org/packages/release/bioc/html/RCytoscape.html RCytoscape] package created by Paul Shannon. The later makes working with CytoscapeRPC a lot easier.

Revision as of 14:01, 4 February 2011

CytoscapeRPC is a Cytoscape plug-in which allows XML-RPC clients to call Cytoscape to alter and query networks.


See the install page.


For now the package is only available through the NBIC Gforge, the project is here and a tarball of last nights version can be found under 'SCM Repository'.



For the plugins javadoc (including all the functions that can be called over XML-RPC) see the: API page (bioinformatics.tudelft.nl).

Code details

Return values

The XML-RPC standard requires that all functions have a return value. Functions which add data or modify variables in Cytoscape normally would not return anything but due to this constraint it now returns True. When something goes wrong while executing the function (some data not available, non-existing identifiers) it returns a XML-RPC error.

Error codes

Code Name Description
1001 Not found Error code for arguments that are provided but not found in Cytoscape.
1002 Not exists Error code for Cytoscape variables that should exist but are not found.
1003 Wrong type Error code for arguments with the wrong type.
1004 Input argument mismatch Error code for when lists of arguments do not have the same length.

Helper functions

CytoscapeRPC has a number of functions which only exist to show what the possible input arguments are for other functions. These functions are listed below. See the API for more information.

Function name Output
listAttributeTypes get the names of the attribute types that can be used for nodes and edges.
getArrowShapeNames get the names of the arrows that can be used with edges.
getLayoutNames get the names of the available layouts. Note that none of the yFiles layouts are available.
getLineStyleNames get the names of the different line styles.
getNodeColorPropertyNames get the property names of nodes which can be set with the node color visual mapper.
getNodeShapeNames get the names of the shapes that a node can have.
getVisualStyleModifiables get the names of the modifiable elements of a visual style.
getVisualStyleNames get a list of visual styles that can currently be applied.
test tests if the connection is working. Should return the string "It works!".

Overwriting visual attributes

Cytoscape allows you to bypass the VizMapper to directly set node and edge visual attributes. Normally this would be done by right-clicking and choosing for the "Visual Mapping Bypass". This hack was also implemented for CytoscapeRPC: the setNodeProperty and setEdgeProperty allow you to set any visual property to a specific value.

Each visual property type (such as a color, edge type or node shape) has a string representation which can be converted to the property type itself. Use the VizMapper to find out which strings represent which types. The getVisualStyleModifiables functions returns a list of properties which can be set using this function.

Attribute types

When adding attributes to nodes or edges the attribute type (data type) needs to be specified. This can be one of the following: "BOOLEAN", "COMPLEX", "FLOATING", "INTEGER", "SIMPLE_LIST", "SIMPLE_MAP" or "STRING".


The default layouts that are available to the user are:

  • jgraph-circle
  • attribute-circle
  • jgraph-annealing
  • jgraph-radial-tree
  • jgraph-gem
  • kamada-kawai-noweight
  • hierarchical
  • IbidasGrid
  • circular
  • isom
  • jgraph-moen
  • jgraph-sugiyama
  • attributes-layout
  • grid
  • jgraph-tree
  • force-directed
  • degree-circle
  • kamada-kawai
  • fruchterman-rheingold
  • jgraph-spring

Client Code Examples

Some example programs in different languages using the CytoscapeRPC plugin. The procedure is the same for all languages: open an XML-RPC connection to the Cytoscape host and call a number of functions.


Here we use the Frontier RPC libraries, these need to be installed separately on your system.

  1. use strict;
  2. use warnings;
  3. use Frontier::RPC2;
  4. use Frontier::Client;
  6. # Tell Frontier where the server lives
  7. my $url = "http://localhost:9000/Cytoscape";
  8. my $client = Frontier::Client->new( url     => $url,
  9.                                     debug   => 0,
  10.                                     );
  12. # We need a coder because of the 'intelligent' var casting in perl
  13. my $coder = Frontier::RPC2->new;
  14. my @args;
  16. # Create a network to work with
  17. my $networkID = $client->call('Cytoscape.createNetwork', 'TestNetwork');
  19. # Lets see if the name we gave the network is still the same
  20. push @args, $coder->string("$networkID");
  21. my $networkTitle = $client->call('Cytoscape.getNetworkTitle', @args);
  22. print $networkTitle, "\n";

For a more elaborate example see CytoscapeRPCPerlExample


This code uses the PEAR XML-RPC2 package. See their documentation for more info.

  1. <?php
  2.     require_once 'XML/RPC2/Client.php';
  3.     $options = array(
  4.         'prefix' => 'Cytoscape.'
  5.     );  
  6.     $client = XML_RPC2_Client::create('http://localhost:9000/Cytoscape', $options);
  7.     $result = $client->test();
  8.     print $result;
  9. ?>


Xmlrpclib is part of the standard Python distribution so no additional packages are required. When using Ipython you can use command line completion to see which method names are available.

Code Result
  1. import xmlrpclib
  3. # Connect to server: specify the location and port
  4. server = xmlrpclib.ServerProxy("http://localhost:9000")
  6. # Test if connection works: should print 'It works!'
  7. print server.Cytoscape.test()
  9. # Create new network
  10. networkid = server.Cytoscape.createNetwork("Cytoscape Python test")
  12. # Create some nodes
  13. server.Cytoscape.createNodes(networkid, ['a', 'b', 'c', 'd', 'e'])
  15. # Create some edges
  16. # From version 1.3 onwards use: 
  17. # server.Cytoscape.createEdges(['a', 'a', 'b', 'd', 'd'], ['b', 'c', 'c', 'd', 'e'])
  18. server.Cytoscape.createEdgesFromVector(['a', 'a', 'b', 'd', 'd'], 
  19.         ['b', 'c', 'c', 'd', 'e'])
  21. # Add some attributes
  22. server.Cytoscape.addNodeAttributes("type", "STRING", 
  23.         {'a':'aa', 'b':'aa', 'c':'bb', 'd':'bb', 'e':'cc'}, True)
  25. # Create VisMapper based on these attributes
  26. server.Cytoscape.setDiscreteNodeShapeMapper(networkid, 'default', 
  27.         'type', 'diamond', {'aa':'ellipse', 'bb':'octagon', 'cc':'round_rect'}, True)
  29. # Perform default layout (usually grid layout)
  30. server.Cytoscape.performDefaultLayout(networkid)
  32. # Select some nodes
  33. server.Cytoscape.setSelectedNodes(networkid, ['a', 'b', 'c'], True)
  35. # Change the colour of some nodes
  36. server.Cytoscape.setNodeFillColor(networkid, ['a', 'b', 'e'], 123, 0, 255)
  38. # Change the shape of some other nodes
  39. server.Cytoscape.setNodeShape(networkid, ['c', 'd'], "triangle")
CytoscapeRPC python example.png


XmlRpc is part of the standard library so no additional packages have to be installed.

  1. require "xmlrpc/client"
  3. puts "Testing the Ruby CytoscapeRPC client."
  5. # Create the connection to the server
  6. server = XMLRPC::Client.new("localhost", "/Cytoscape", 9000)
  8. # Perform test function to see if the connection works
  9. puts server.call("Cytoscape.test")
  11. # Create a new network
  12. server.call("Cytoscape.createNetwork", "Cytoscape Ruby test")


You can call the XML-RPC functions directly from R using the XML-RPC library but there is also the excellent RCytoscape package created by Paul Shannon. The later makes working with CytoscapeRPC a lot easier.


Some (Python) scripts to make working with Cytoscape easier.

  • LoadNetwork.py a script to load sif, noa and ede files into Cytoscape.