Difference between revisions of "CytoscapeRPC"
m (→Python) |
|||
Line 159: | Line 159: | ||
# Create some edges | # Create some edges | ||
+ | # From version 1.3 onwards use: | ||
+ | # server.Cytoscape.createEdges(['a', 'a', 'b', 'd', 'd'], ['b', 'c', 'c', 'd', 'e']) | ||
server.Cytoscape.createEdgesFromVector(['a', 'a', 'b', 'd', 'd'], | server.Cytoscape.createEdgesFromVector(['a', 'a', 'b', 'd', 'd'], | ||
['b', 'c', 'c', 'd', 'e']) | ['b', 'c', 'c', 'd', 'e']) |
Revision as of 13:57, 4 February 2011
CytoscapeRPC is a Cytoscape plug-in which allows XML-RPC clients to call Cytoscape to alter and query networks.
Contents
Installation
See the install page.
Download
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'.
Requirements
- Cytoscape
- XmlRpc server packages from the Apache foundation
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".
Layouts
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.
Perl
Here we use the Frontier RPC libraries, these need to be installed separately on your system.
use strict;
use warnings;
use Frontier::RPC2;
use Frontier::Client;
# Tell Frontier where the server lives
my $url = "http://localhost:9000/Cytoscape";
my $client = Frontier::Client->new( url => $url,
debug => 0,
);
# We need a coder because of the 'intelligent' var casting in perl
my $coder = Frontier::RPC2->new;
my @args;
# Create a network to work with
my $networkID = $client->call('Cytoscape.createNetwork', 'TestNetwork');
# Lets see if the name we gave the network is still the same
push @args, $coder->string("$networkID");
my $networkTitle = $client->call('Cytoscape.getNetworkTitle', @args);
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.
<?php
require_once 'XML/RPC2/Client.php';
$options = array(
'prefix' => 'Cytoscape.'
);
$client = XML_RPC2_Client::create('http://localhost:9000/Cytoscape', $options);
$result = $client->test();
print $result;
?>
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.
Ruby
XmlRpc is part of the standard library so no additional packages have to be installed.
require "xmlrpc/client"
puts "Testing the Ruby CytoscapeRPC client."
# Create the connection to the server
server = XMLRPC::Client.new("localhost", "/Cytoscape", 9000)
# Perform test function to see if the connection works
puts server.call("Cytoscape.test")
# Create a new network
server.call("Cytoscape.createNetwork", "Cytoscape Ruby test")
R
You can call XML-RPC functions using the 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 here.) The maintainer of SSOAP just released a new XML-RPC client for R, located here. This package is not finished yet and has not been tested with CytoscapeRPC.
Scripts
Some (Python) scripts to make working with Cytoscape easier.
- LoadNetwork.py a script to load sif, noa and ede files into Cytoscape.