Skip to content
  • faq
  • tools
  • coding

Cytoscape: How to use the API with R?ΒΆ

Question

As you have Cytoscape available in the Research Environment, can I always use it via an API using R?

Answer

Yes, the Cytoscape API is also functioning within our Research Environment. However, this requires some setting up, so please carefully follow the steps below for R/3.6.1.

1) Start up Cytoscape (Before you start up Rstudio)

Open the terminal and start up cytoscape by typing:

/tools/apps/cytoscape/3.7.1/Cytoscape_v3.7.1/cytoscape.sh

2) Start up Rstudio

Open a new terminal and start up Rstudio by typing:

module load R/3.6.1
rstudio

3) Load the correct environment in R

R will require various packages to be loaded into your environment. Please add this to your R script, and run:

install.packages("BiocManager") # This has a variable time to initiate the install   
library(BiocManager)   
BiocManager::install("RCy3")   
library(RCy3)   
library(igraph)

4) Basic checks

To run some basic checks to see if it worked, please run the following in R:

cytoscapePing()          # This should confirm the connection.   
cytoscapeVersionInfo()   # This will provide session and version info
cytoscape.base.url <- "http://localhost:1234/v1"                    # Sets the default page  
RCy3::cyrestGET(base.url = cytoscape.base.url)                      # Provides detailed session info. If this (or similar) output  
                                                                    # is not equal to your session, you may need to start over again.  
print(paste("Cytoscape Base URL: ",cytoscape.base.url, sep = ""))   

5) Test functionality

To test whether your connection works, we are using an example provided by Cytoscape.

Please run the following lines in R:

### Test network generation - Example from website.
nodes <- data.frame(id=c("node 0","node 1","node 2","node 3"),
                    group=c("A","A","B","B"), # categorical strings
                    score=as.integer(c(20,10,15,5)), # integers
                    stringsAsFactors=FALSE)
edges <- data.frame(source=c("node 0","node 0","node 0","node 2"),
                    target=c("node 1","node 2","node 3","node 3"),
                    interaction=c("inhibits","interacts","activates","interacts"),  # optional
                    weight=c(5.1,3.0,5.2,9.9), # numeric
                    stringsAsFactors=FALSE)

createNetworkFromDataFrames(nodes,edges, title="my first network", collection="DataFrame Example")

This should result in Cytoscape constructing the network.

If the above is all fine, you are now set to use the Cytoscape API within our Research Environment!

Last updated

This page was last updated on the 18 Dec 2020.


Last update: November 17, 2023