Networks
e.g., PPIs or pathways
Tables
e.g., data or annotations
Visual Styles
Other tutorials are available at: tutorials.cytoscape.org
Networks offer us a useful way to represent our biological data. But how do we seamlessly translate our data from R into Cytoscape?
In order to control Cytoscape from R/Python you need either:
RCy3 - a bioconductor package
#R
if(!"RCy3" %in% installed.packages()){
install.packages("BiocManager")
BiocManager::install("RCy3")
}
library(RCy3)
py4cytoscape - a pip package
#Python
pip install requests pandas colorbrewer chardet decorator
pip install py4cytoscape
import py4cytoscape as py4
RCy3::cytoscapePing()
py4.cytoscape_ping()
[1] "You are connected to Cytoscape!"
You can install apps in Cytoscape directly from R/Python.
installApp("stringApp")
py4.install_app("stringApp")
[1] "App stringApp installed"
Depending on what apps you have installed there is different functionality available.
To see all the functions available open the interactive Swagger docs:
cyrestAPI() # CyREST API
commandsAPI() # Commands API
py4.cyrest_api() # CyREST API
py4.commands_api() # Commands API
Create a Cytoscape network from data frames
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)
import pandas as pd
nodes = pd.DataFrame(data={'id': ["node 0", "node 1", "node 2", "node 3"],
'group': ["A","A","B","B"],
'age': [20,10,15,5]})
edges = pd.DataFrame(data={'source': ["node 0", "node 0", "node 0", "node 2"],
'target': ["node 1", "node 2", "node 3", "node 3"],
'interaction': ["inhibits","interacts","activates","interacts"],
'weight': [5.1,3.0,5.2,9.9]})
id | group | score |
---|---|---|
node 0 | A | 20 |
node 1 | A | 10 |
node 2 | B | 15 |
node 3 | B | 5 |
source | target | interaction | weight |
---|---|---|---|
node 0 | node 1 | inhibits | 5.1 |
node 0 | node 2 | interacts | 3.0 |
node 0 | node 3 | activates | 5.2 |
node 2 | node 3 | interacts | 9.9 |
createNetworkFromDataFrames(nodes, edges, title="my first network",
collection="DataFrame Example")
py4.create_network_from_data_frames(nodes, edges, title="my first network",
collection="DataFrame Example")
Remember: all networks we make are created in Cytoscape so get an image of the resulting network and include it in your current analysis if desired.
exportImage("my_first_network", type = "png")
py4.export_image("my_first_network", type = "png")
With the new support for notebooks, you can also display exported images inline with notebooks, both offline and online, e.g., Jupyter/Colab.
notebookExportShowImage("my_first_network", type = "png")
py4.notebook_export_show_image("my_first_network", type = "png")
Questions and Discussion