Probably, You want to input data to Cytoscape by R. In this section, you will learn how to input each kind of data file/URL and how to import annotation data and merge it into Network data.
Import Fixed-Format Network Files/URL
Import Annotation Data and merge it into Network data
In Cytoscape, there are several available file types. The following file formats are available.
Further information about Network Formats : http://wiki.cytoscape.org/Cytoscape_User_Manual/Network_Formats
In [1]:
# import library
library(RCy3)
library(igraph)
# import utility
source("../../utility/import.R")
# first, delete existing windows to save memory:
deleteAllWindows(CytoscapeConnection())
# create graph class
g <- new ('graphNEL', edgemode='directed')
edgeDataDefaults(g, attr = "edgeType") <- "undefined"
attr(edgeDataDefaults(g, attr = "edgeType"), "class") <- "STRING"
# Load Data
gal.matrix <- sifDataToMatrix('../sampleData/galFiltered.sif')
# Get NodesVec
gal.table.nodevec <- unique(c(gal.matrix[,1], gal.matrix[,3]))
# add nodes to graph
for(node in gal.table.nodevec){
g <- graph::addNode(node, g)
}
# get EdgeList and type
gal.table.fromvec <- gal.matrix[,1]
gal.table.type <- gal.matrix[,2]
gal.table.tovec <- gal.matrix[,3]
for (index in 1:length(gal.table.fromvec)){
g <- graph::addEdge (gal.table.fromvec[[index]] ,gal.table.tovec[[index]], g)
edgeData(g, gal.table.fromvec[[index]] ,gal.table.tovec[[index]], "edgeType") <- gal.table.type[[index]]
}
# show it in cytescape
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')
In Cytoscape, there are several available file types. The following file formats are available.
Further Network Formats : http://wiki.cytoscape.org/Cytoscape_User_Manual/Network_Formats
By using following code, you can import data from url. As you can see below, you can import data from local file.
In [2]:
# import library
library(RCy3)
library(igraph)
# import utility
source("../../utility/import.R")
# first, delete existing windows to save memory:
deleteAllWindows(CytoscapeConnection())
In [5]:
# Next, you prepare network list.
network_files = list(
# Local file in this example data directory
# filepath,
# SIF file on a web server
'http://chianti.ucsd.edu/cytoscape-data/galFiltered.sif',
'file:///Your/local/directory/cyrest-examples/notebooks/cookbook/R-cookbook',
'file:///Your/local/directory/cyrest-examples/notebooks/cookbook/sampleData/galFiltered.gml'
# And of course, you can add as many files as you need...
)
res.cw <- createFrom(network_files)
In some case, we want to load another network table, for example, an edge attribute table and a node attribute table and merge it into network data.
In this example of workflow, by executing the following steps, you can load annotation data and merge it.
In [21]:
# import library
library(RCy3)
library(igraph)
# import utility
source("../../utility/import.R")
# first, delete existing windows to save memory:
deleteAllWindows(CytoscapeConnection())
# create graph class
g <- new ('graphNEL', edgemode='directed')
edgeDataDefaults(g, attr = "edgeType") <- "undefined"
attr(edgeDataDefaults(g, attr = "edgeType"), "class") <- "STRING"
# Load Data
gal.matrix <- sifDataToMatrix('../sampleData/galFiltered.sif')
# Get NodesVec
gal.table.nodevec <- unique(c(gal.matrix[,1], gal.matrix[,3]))
# add nodes to graph
for(node in gal.table.nodevec){
g <- graph::addNode(node, g)
}
# get EdgeList and type
gal.table.fromvec <- gal.matrix[,1]
gal.table.type <- gal.matrix[,2]
gal.table.tovec <- gal.matrix[,3]
for (index in 1:length(gal.table.fromvec)){
g <- graph::addEdge (gal.table.fromvec[[index]] ,gal.table.tovec[[index]], g)
edgeData(g, gal.table.fromvec[[index]] ,gal.table.tovec[[index]], "edgeType") <- gal.table.type[[index]]
}
# show it in cytescape
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')
In [25]:
# Second, import annotation data from database(in R, we can use bioconductor as database).
# import library to access database
library(org.Sc.sgd.db)
# import Data
# DESCRIPTION data
descriptions <- select(org.Sc.sgd.db, keys=getAllNodes(cw), columns="DESCRIPTION")
df.descriptions <- data.frame(descriptions)
# GENENAME data
gene.names <- select(org.Sc.sgd.db, keys=getAllNodes(cw), columns="GENENAME")
df.gene.names <- data.frame(gene.names)
# GO data
go <- select(org.Sc.sgd.db, keys=getAllNodes(cw), columns="GO")
df.go <- data.frame(go)
# Finally, merge the above two data table and push it to Cytoscape.
# set DESCRIPTION as attribute data
nodeDataDefaults(g, attr = "DESCRIPTION") <- "undefined"
attr(nodeDataDefaults(g, attr = "DESCRIPTION"), "class") <- "STRING"
# set GENENAME as attribute data
nodeDataDefaults(g, attr = "name") <- "undefined"
attr(nodeDataDefaults(g, attr = "name"), "class") <- "STRING"
# set GO as attribute data
#nodeDataDefaults(g, attr = "go") <- "undefined"
#attr(nodeDataDefaults(g, attr = "go"), "class") <- "LIST"
# marge DESCRIPTION attribute.
for (index in 1:length(df.descriptions$DESCRIPTION)){
nodeData(g, df.descriptions$ORF[[index]], "DESCRIPTION") <- df.descriptions$DESCRIPTION[[index]]
}
# marge GENENAME attribute.
for (index in 1:length(df.gene.names$GENENAME)){
nodeData(g, df.gene.names$ORF[[index]], "name") <- df.gene.names$GENENAME[[index]]
}
# marge GO attribute.
#for (index in 1:length(df.gene.names$GENENAME)){
# nodeData(g, df.gene.names$ORF[[index]], "name") <- df.gene.names$GENENAME[[index]]
#}
# show it.
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')
In [ ]: