In this jupyter-notebook, I'll show you the R workflow of Anne as the sample.
You can understand the basic workflow by reading this, but the RCy3's documentation is really useful and you can know much more about this.
The documentation : https://www.bioconductor.org/packages/release/bioc/html/RCy3.html
In [7]:
library(RCy3)
library(igraph)
In [8]:
# Load Data
gal.table <- read.table('sampleData/galFiltered.sif',stringsAsFactors=FALSE)
head(gal.table)
In [9]:
# create graph class
g <- new ('graphNEL', edgemode='directed')
# Get NodesVec
gal.table.nodevec <- unique(c(gal.table[[1]], gal.table[[3]]))
# add nodes to graph
for(node in gal.table.nodevec){
g <- graph::addNode(node, g)
}
# get EdgeList
gal.table.fromvec = gal.table[[1]]
gal.table.tovec = gal.table[[3]]
for (index in 1:length(gal.table.fromvec)){
g <- graph::addEdge (gal.table.fromvec[[index]] ,gal.table.tovec[[index]], g)
}
# show it in cytescape
cw <- CytoscapeWindow('vignette', , graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')
Then, you can get this image in cytoscape.
In this example of workflow, by executing the following steps, you can load annotation data and merge it.
Now, we use the data file 'galFiltered.sif' that is the yeast data. So, we will try to add annotation data to this.
In [10]:
# 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 in cytescape
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')
In [13]:
# add attribute:"edgeType" and the type:"STRING"
edgeDataDefaults(g, attr = "edgeType") <- "undefined"
attr(edgeDataDefaults(g, attr = "edgeType"), "class") <- "STRING"
# get EdgeList and type
gal.table.fromvec <- gal.table[,1]
gal.table.type <- gal.table[,2]
gal.table.tovec <- gal.table[,3]
# add attribute value to the network
for (index in 1:length(gal.table.fromvec)){
edgeData(g, gal.table.fromvec[[index]] ,gal.table.tovec[[index]], "edgeType") <- gal.table.type[[index]]
}
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')
First, we have to set attributes to edges. Then, we can select edges based on attributes.
selectEdges(obj, edge.names, preserve.current.selection=TRUE)
In [14]:
# clear selection
clearSelection (cw)
In [16]:
# selection Edges
vec = c()
for (index in 1:length(gal.table.type)){
if(gal.table.type[[index]] == 'pp'){
vec = c(vec, paste(gal.table.fromvec[[index]], '(pp)', gal.table.tovec[[index]]))
}
}
selectEdges (cw, vec)
Then, you can get the output,like the follwoing image, in cytoscape.
In [9]:
# The code is only this!!
# TODO : this methods have some error. I can't do anything with this method.
hideSelectedEdges (cw)
In [18]:
# get attributes data
gal.node.attrs <- read.table('sampleData/galFiltered_node.attrs',stringsAsFactors=FALSE, skip=1)
head(gal.node.attrs)
In [19]:
g <- initNodeAttribute (graph=g, attribute.name='moleculeType', attribute.type='char', default.value='undefined')
# get EdgeAttrs
gal.node = gal.node.attrs[[1]]
gal.attrs = gal.node.attrs[[3]]
for (index in 1:length(gal.node)){
nodeData (g, gal.node, 'moleculeType') <- as.character(gal.attrs[[index]])
}
cw <- setGraph (cw, g)
displayGraph (cw)
In [20]:
# clear selection
clearSelection (cw)
In [21]:
vac = c()
for (index in 1:length(gal.node)){
if(gal.attrs[[index]] == '1'){
vec = c(vec, gal.node[[index]])
}
}
selectNodes(cw, vec)
Then, you can get the output,like the follwoing image, in cytoscape.
In [22]:
# TODO : There are some error in this method. I can't do anything by this.
hideSelectedNodes(cw)
We use two method in this section. 'getLayoutNames' let us know available layoutNames and we can apply one of them by 'layoutNetwork' method.
getLayoutNames(obj)
obj : a CytoscapeConnectionClass object.
layoutNetwork(obj, layout.name= grid )
obj a CytoscapeWindowClass object. layout.name a string, one of the values returned by getLayoutNames, ’grid’ by default.
In [23]:
# get available layout names
getLayoutNames(cw)
In [24]:
# execute layout that you want
layoutNetwork(cw, layout.name= 'isom')
Then, you can get the output,like the follwoing image, in cytoscape.
In [25]:
# execute layout that you want
layoutNetwork(cw, layout.name= 'kamada-kawai')
Then, you can get the output,like the follwoing image, in cytoscape.
By default, Cytoscape displays nodes as pale red circles circles, edges as blue undecorated lines, selected nodes as yellow and selected edges as red. RCy3 provides an easy way to change these defaults. More interestingly, RCy3 provides easy programmatic access to the vizmapper, by means of which the size, shape and color of nodes and edges is determined by the data attributes you have attached to those nodes and edges.
There are so many methods to do this.
At this point I do every bit of the visual style manually, but it is always the same.
That is because I do not know how to transfer a visual style from one session to the next yet.
It would be great if that was automated (I do it manually for one network and then it is automatic for the following ones that have the same exact attributes)'