CytoscapeRPC

From BioAssist
Revision as of 14:44, 3 October 2011 by Tbeek (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

Installation

See the install page.

Download

The package is available through the NBIC Trac project and a tarball of release versions can be found under 'Downloads'.

Requirements

API

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".

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. For more examples see CytoscapeRPCExamples. For additional info on how to set properties of e.g. layouts see: CytoscapeProperties.

Perl

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;
  5.  
  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.                                     );
  11.  
  12. # We need a coder because of the 'intelligent' var casting in perl
  13. my $coder = Frontier::RPC2->new;
  14. my @args;
  15.  
  16. # Create a network to work with
  17. my $networkID = $client->call('Cytoscape.createNetwork', 'TestNetwork');
  18.  
  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

PHP

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

Python

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
  2.  
  3. # Connect to server: specify the location and port
  4. server = xmlrpclib.ServerProxy("http://localhost:9000")
  5.  
  6. # Test if connection works: should print 'It works!'
  7. print server.Cytoscape.test()
  8.  
  9. # Create new network
  10. networkid = server.Cytoscape.createNetwork("Cytoscape Python test")
  11.  
  12. # Create some nodes
  13. server.Cytoscape.createNodes(networkid, ['a', 'b', 'c', 'd', 'e'])
  14.  
  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'])
  20.  
  21. # Add some attributes
  22. server.Cytoscape.addNodeAttributes("type", "STRING", 
  23.         {'a':'aa', 'b':'aa', 'c':'bb', 'd':'bb', 'e':'cc'}, True)
  24.  
  25. # Create VisMapper based on these attributes
  26. server.Cytoscape.setDiscreteNodeShapeMapper(networkid, 'default', 
  27.         'type', 'diamond', {'aa':'ellipse', 'bb':'octagon', 'cc':'round_rect'}, True)
  28.  
  29. # Perform default layout (usually grid layout)
  30. server.Cytoscape.performDefaultLayout(networkid)
  31.  
  32. # Select some nodes
  33. server.Cytoscape.setSelectedNodes(networkid, ['a', 'b', 'c'], True)
  34.  
  35. # Change the colour of some nodes
  36. server.Cytoscape.setNodeFillColor(networkid, ['a', 'b', 'e'], 123, 0, 255)
  37.  
  38. # Change the shape of some other nodes
  39. server.Cytoscape.setNodeShape(networkid, ['c', 'd'], "triangle")
CytoscapeRPC python example.png

Ruby

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

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

R

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.

Scripts

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

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

Tutorials