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.
Save Images we can choose the format of the saving image in R. Now, we can save Images as pdf, png or svg.
Save Layout You can save layout as file.
Save Network
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')
Now, we can get the network in cytoscape.
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.
saveImage(obj, file.name, image.type, scale)
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 [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))
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))
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))
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)
You can write a network of the specified type to the specified file, at the specified scaling factor.
saveNetwork(obj, file.name, format= cys )
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')