In this section, you can learn how to apply layout that you want to get to your network.
In cytoscape, layout networks is in two dimensions. First one is to apply layout algorithms. A variety of layout algorithms are available, including cyclic, tree, force-directed, edge-weight, and yFiles Organic layouts. Second, you can also use Manual Layout tools similar to other graphics application user interface.
In the following workflow, you can see how to apply layout algorithms programatically and save it.
In [2]:
# import library
library(RCy3)
library(igraph)
# first, delete existing windows to save memory:
deleteAllWindows(CytoscapeConnection())
# Load Data
gal.table <- read.table('../sampleData/galFiltered.sif',stringsAsFactors=FALSE)
# 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')
First, let's begin to get the list of available layout. We can get it by using the following method.
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)
In [3]:
# get available layout names
getLayoutNames(cw)
Now, you get the available layout methods. By following method, you can apply method that you want.
layoutNetwork(obj, layout.name= grid )
In [4]:
# execute layout that you want
layoutNetwork(cw, layout.name= 'force-directed')
In [5]:
# This code is for save and show the network image.
file.name <- paste (getwd (), 'resultImage' ,'saveImageToShowLayoutExample' , sep= '/' )
image.type <- 'png'
resource.uri <- paste(cw@uri,
pluginVersion(cw), "networks", as.character(cw@window.id),
paste0("views/first.", image.type),
sep="/")
request.res <- GET(resource.uri, write_disk(paste0(file.name,".", image.type), overwrite = TRUE))
In [8]:
# TODO : I don't know why this method is not available. So I have to find it.
saveLayout (cw, layout2 , timestamp.in.filename=TRUE)