Export


If you layout some network as you want to do, you also want to export or save that Images, Layout or Network. RCy3 can help you to export such data programatically.

In this section, you can learn how to save images, layout and network. It is very easy.

Table of contents

  • Save Images we can choose the format of the saving image in R. Now, we can save Images as pdf, png or svg.

    • pdf
    • png
    • svg
  • Save Layout You can save layout as file.

  • Save Network

    • cys

To execute example, we have to import data.


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


In [5]:
# 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"

Now, we can get the network in cytoscape.

Save Images


By using following method, you can save the network's image and choose the format of the saving image in R. Write an image of the specified type to the specified file, at the specified scaling factor.

Usage

saveImage(obj, file.name, image.type, scale)

Arguments

  • obj : a CytoscapeWindowClass object.
  • file.name : a char object. Use an explicit, full path, or this file will be written into your home directory.
  • image.type : a char object. ’jpg’ is the only image type currently supported
  • scale : a numeric object. How large (or small) to scale the image.

Note: the file is written to the file system of the computer upon which R is running, not Cytoscape – in those cases where they are different. It is saved to the working directory.

Save image as pdf



In [6]:
# TODO : I don't know why this method is not available. So I have to find it.
# print(saveImage(cw, 'sampleImage', 'pdf', 2.0))

# The following code is available
file.name <- paste (getwd (), 'resultImage' ,'saveImageTest' , sep= '/' )
image.type <- 'pdf'

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 image as png



In [8]:
# TODO : I don't know why this method is not available. So I have to find it.
# print(saveImage(cw, 'sampleImage', 'png', 2.0))

# The following code is available
file.name <- paste (getwd (), 'resultImage', 'saveImageTest' , 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 image as svg



In [7]:
# TODO : I don't know why this method is not available. So I have to find it.
# print(saveImage(cw, 'sampleImage', 'svg', 2.0))

# The following code has also bag
file.name <- paste (getwd (), 'resultImage', 'saveImageTest' , sep= '/' )
image.type <- 'svg'

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 [7]:
# TODO : I don't know why this method is not available. So I have to find it.
saveLayout (cw,  layout2 , timestamp.in.filename=TRUE)

Save Network


You can write a network of the specified type to the specified file, at the specified scaling factor.

Usage

saveNetwork(obj, file.name, format= cys )

Arguments

  • obj : a CytoscapeWindowClass object.
  • file.name : a char object.
  • format : a char object. ’cys’ is the only type currently supported

Note:the file is written to the file system of the computer upon which R is running, not Cytoscape – in those cases where they are different. It is saved to the working directory.


In [8]:
# TODO : I don't know why this method is not available. So I have to find it.
# overwrites files with the same name
saveNetwork (cw, 'sample')