Layout


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.

Table of contents

  • Get list of available layout
  • Apply layout
  • Save Layout

Network Data Preparation


To execute this examples, first, we have to import sample data.


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')


Warning message:
In .local(from, to, graph): edges replaced: ‘YPL248C|YML051W’
[1] "label"

Get list of available layout


First, let's begin to get the list of available layout. We can get it by using the following method.

Method : getLayoutNames

We use two method in this section. 'getLayoutNames' let us know available layoutNames and we can apply one of them by 'layoutNetwork' method.

Usage

getLayoutNames(obj)

Arguments

  • obj : a CytoscapeConnectionClass object.

In [3]:
# get available layout names
getLayoutNames(cw)


  1. 'attribute-circle'
  2. 'stacked-node-layout'
  3. 'degree-circle'
  4. 'circular'
  5. 'attributes-layout'
  6. 'kamada-kawai'
  7. 'force-directed'
  8. 'grid'
  9. 'hierarchical'
  10. 'fruchterman-rheingold'
  11. 'isom'
  12. 'force-directed-cl'

Apply layout


Now, you get the available layout methods. By following method, you can apply method that you want.

Method : layoutNetwork

Usage

layoutNetwork(obj, layout.name= grid )

Arguments

  • obj : a CytoscapeWindowClass object.
  • layout.name : a string, one of the values returned by getLayoutNames, ’grid’ by default.

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))

Save Layout


When you use the below method, you can save the current layout (that is, node positions) to the specified file.

Usage

saveLayout(obj, filename, timestamp.in.filename=FALSE)

Arguments

  • obj : a CytoscapeWindowClass object.
  • filename : a string.
  • timestamp.in.filename : logical

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)