= Control Cytoscape from R Console = == Introduction == [[https://wiki.nbic.nl/index.php/CytoscapeRPC|CytoscapeRPC]] is a plugin for Cytoscape to use Cytoscape as a RPC server. You can call Cytoscape functions from variety of languages including Perl, Python, Ruby, and R. In this tutorial, you learn how to use Cytoscape from R console. == Setup == You need to install the following plugins/packages. === Cytoscape Plugin === Just copy the following jar files to Cytoscape plugin directory. * [[https://wiki.nbic.nl/index.php/CytoscapeRPC|CytoscapeRPC Plugin 0.95 or later]]. * [[http://www.ecoficial.com/apachemirror/ws/xmlrpc/|Apache XML RPC library]] * Required files are in '''lib''' directory: xmlrpc-common-3.1.3.jar, xmlrpc-server-3.1.3.jar, ws-commons-util-1.0.2.jar === R Packages === * XML-RPC package [[attachment:XMLRPC_0.2-mod.zip]] (Bug fix version by Paul Shannon. BSD License) * [[http://igraph.sourceforge.net/|igraph]] graph utility package == Tutorial == === Start Cytoscape RPC === 1. Start Cytoscape. If you want to see the all messages (including Exceptions from CytoscapeRPC plugin), start Cytoscape from command line (by executing '''''cytoscape.sh''''' or '''''cytoscape.bat''''') 1. Select '''''Plugins-->CytoscapeRPC-->Activate RPC''''' 1. Modify port number if necessary. Default port is 9000. === Start R === 1. Start R console 1. Load required libraries {{{ > library(igraph) > library(XMLRPC) }}} 1. Test RPC Plugin. {{{ > testResponse = xml.rpc('http://localhost:9000', 'Cytoscape.test') > testResponse [1] "It works!" }}} === Create Network with igraph and Visualize It in Cytoscape === 1. Create an empty network. {{{ > networkID = xml.rpc('http://localhost:9000', 'Cytoscape.createNetwork', 'R-Cytoscape Test') > networkID [1] "2" > networkTitle = xml.rpc('http://localhost:9000', 'Cytoscape.getNetworkTitle', networkID) > networkTitle [1] "R-Cytoscape Test" }}} 1. Generate a scale-free graph according to the Barabasi-Albert model {{{ > g1 <- barabasi.game(200) > g1 Vertices: 200 Edges: 199 Directed: TRUE Edges: [0] 1 -> 0 [1] 2 -> 0 [2] 3 -> 1 . . . }}} 1. Create Cytoscape network from the generated graph {{{ > edgelist1 <- get.edgelist(g1) > edgelist1 [,1] [,2] [1,] 1 0 [2,] 2 0 [3,] 3 1 . . . > edgeIDs <- xml.rpc('http://localhost:9000', 'Cytoscape.createEdgesFromVector', edgelist1[,1], edgelist1[,2]) }}} 1. In the Cytoscape window, you can see one red node. Actually, it's a graph with 200 nodes without any visual properties. After applying layout and vizmap, you can see something like this: {{attachment:igraph1.png}} (to be continued...)