Other useful methods


In this section, you can learn useful methods but not in other sections.

Table of contents

  • Select

    • edges
    • nodes
  • Hide

    • edges
    • nodes
  • Clear Selection

Network Data Preparation


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


In [31]:
# import library
library(RCy3)
library(igraph)

# import utility
source("../../utility/import.R")

# first, delete existing windows to save memory:
deleteAllWindows(CytoscapeConnection())

# create graph class
g <- new ('graphNEL', edgemode='directed')

edgeDataDefaults(g, attr = "edgeType") <- "undefined"
attr(edgeDataDefaults(g, attr = "edgeType"), "class") <- "STRING"

# Load Data
gal.matrix <- sifDataToMatrix('../sampleData/galFiltered.sif')

# Get NodesVec
gal.table.nodevec <- unique(c(gal.matrix[,1], gal.matrix[,3]))

# add nodes to graph
for(node in gal.table.nodevec){
    g <- graph::addNode(node, g)
}

# get EdgeList and type
gal.table.fromvec <- gal.matrix[,1]
gal.table.type <- gal.matrix[,2]
gal.table.tovec <-  gal.matrix[,3]

for (index in 1:length(gal.table.fromvec)){
    g <- graph::addEdge (gal.table.fromvec[[index]] ,gal.table.tovec[[index]], g)
    edgeData(g, gal.table.fromvec[[index]] ,gal.table.tovec[[index]], "edgeType") <- gal.table.type[[index]]
}

# 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’Warning message:
:  使われていないコネクション 4 (../sampleData/galFiltered.sif) を閉じます 
[1] "label"
[1] "edgeType"

Select


You may want to select edges and nodes. By using following methods, you can select edges and nodes and if you would like to select them by attribution, you should read and try this examples.

Select edges


Method : selectEdges

Usage

selectEdges(obj, edge.names, preserve.current.selection=TRUE)

Arguments

  • obj : a CytoscapeWindowClass object.
  • edge.names : a list of strings, the names of edges to select.
  • preserve.current.selection : a logical object.

In [32]:
# Select edge by selecting edge directly
# The name format is "geneA (relation) geneB".
selectEdges(cw, paste(gal.table.fromvec[[1]], " (",gal.table.type[[1]], ") ",gal.table.tovec[[1]], sep=""))

# The following code is for showing the result network image.
file.name <- paste (getwd (), 'resultImage' , 'showImageSelectOneEdge' , 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 [33]:
# Select edges by attribution.
vec = c()
for (index in 1:length(gal.table.fromvec)){
    if(gal.table.type[[index]] == 'pp'){
        vec = c(vec, paste(gal.table.fromvec[[index]], " (",gal.table.type[[index]], ") ", gal.table.tovec[[index]],sep=""))
    }
}
selectEdges (cw, vec)

# The following code is for showing the result network image.
file.name <- paste (getwd (), 'resultImage' ,'showImageSelectEdgeByAttribution' , 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))

Select nodes


method : selectNodes

Usage

selectNodes(obj, node.names, preserve.current.selection=TRUE)

Arguments

  • obj : a CytoscapeWindowClass object.
  • node.names : a list of strings, the names of nodes to select.
  • preserve.current.selection : a logical object.

In [37]:
# select node by its name
selectNodes(cw, "YKR026C")

# The following code is for showing the result network image.
file.name <- paste (getwd(), 'resultImage' , 'showImageSelectOneNode' , 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 [38]:
# get attributes data
gal.node.attrs <- read.table('../sampleData/galFiltered_node.attrs',stringsAsFactors=FALSE, skip=1)
head(gal.node.attrs)


V1V2V3
YKR026C= 1
YGL122C= 1
YMR146C= 1
YDR429C= 1
YFL017C= 1
YOL123W= 1

In [39]:
vac = c()
for (index in 1:length(gal.node.attrs)){
    if(gal.node.attrs[[index,3]] == 1){
        vec = c(vec, gal.node.attrs[[index,1]])
    }
}

# select Nodes by attribution
selectNodes(cw, vec)

# The following code is for showing the result network image.
file.name <- paste (getwd (), 'resultImage' , 'showImageSelectNodesByAttribution' , 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))

Hide


Hide edges


If you want to hide edges, you can use this method. To use this method and hide edges that you want to hide, you should select which edges you want to hide.

Method : hideSelectedEdges

Usage

hideSelectedEdges(obj)

Arguments

obj a CytoscapeWindowClass object.


In [27]:
# Hide selected nodes
hideSelectedEdges(cw)


NULL

Hide nodes


Method : hideSelectedNodes

Usage

hideSelectedNodes(obj)

Arguments

obj : a CytoscapeWindowClass object.


In [28]:
# Hide selected nodes
hideSelectedNodes(cw)


not yet implemented

Clear selection

If any nodes are selected in the current Cytocape window and you want to clear selection, following method will be useful.

Usage

clearSelection(obj)

Arguments

  • obj : a CytoscapeWindowClass object.

In [29]:
# clear Selection
clearSelection (cw)