Import


Probably, You want to input data to Cytoscape by R. In this section, you will learn how to input each kind of data file/URL and how to import annotation data and merge it into Network data.

Table of contents


  • Import Fixed-Format Network Files/URL

  • Import Annotation Data and merge it into Network data

    • upload a network table, an edge attribute table and a node attribute table.

Import data from local file.


The support file types


In Cytoscape, there are several available file types. The following file formats are available.

  • Simple interaction file(SIF or .sif format)
  • Nested network format (NNF or .nnf format)
  • Graph Markup Language (GML or .gml format)
  • XGMML (extensible graph markup and modelling language)
  • SBML
  • BioPAX
  • PSI-MI Level 1 and 2.5
  • GraphML
  • Delimited text
  • Excel Workbook (.xls, .xlsx)
  • Cytoscape.js JSON

Further information about Network Formats : http://wiki.cytoscape.org/Cytoscape_User_Manual/Network_Formats

Import data from simple interaction file.


This example is to import data from simple interaction file (SIF or .sif format).


In [1]:
# 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')


Loading required package: graph
Loading required package: httr
Warning message:
: package ‘httr’ was built under R version 3.2.5Loading required package: RJSONIO
Loading required package: RCurl
Warning message:
: package ‘RCurl’ was built under R version 3.2.4Loading required package: bitops

Attaching package: ‘igraph’

 以下のオブジェクトは ‘package:graph’ からマスクされています: 

     degree, edges, intersection, union 

 以下のオブジェクトは ‘package:stats’ からマスクされています: 

     decompose, spectrum 

 以下のオブジェクトは ‘package:base’ からマスクされています: 

     union 

Warning message:
:  使われていないコネクション 4 (../sampleData/galFiltered.sif) を閉じます Warning message:
In .local(from, to, graph): edges replaced: ‘YPL248C|YML051W’
[1] "label"
[1] "edgeType"

Import available file format's data by network URL list.


In Cytoscape, there are several available file types. The following file formats are available.

  • Simple interaction file(SIF or .sif format)
  • Nested network format (NNF or .nnf format)
  • Graph Markup Language (GML or .gml format)
  • XGMML (extensible graph markup and modelling language)
  • SBML
  • BioPAX
  • PSI-MI Level 1 and 2.5
  • GraphML
  • Delimited text
  • Excel Workbook (.xls, .xlsx)
  • Cytoscape.js JSON

Further Network Formats : http://wiki.cytoscape.org/Cytoscape_User_Manual/Network_Formats

By using following code, you can import data from url. As you can see below, you can import data from local file.


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

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

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

In [5]:
# Next, you prepare network list.
network_files = list(
    # Local file in this example data directory
    # filepath,

    # SIF file on a web server
    'http://chianti.ucsd.edu/cytoscape-data/galFiltered.sif',
    'file:///Your/local/directory/cyrest-examples/notebooks/cookbook/R-cookbook',
    'file:///Your/local/directory/cyrest-examples/notebooks/cookbook/sampleData/galFiltered.gml'
    
    # And of course, you can add as many files as you need...
)

res.cw <- createFrom(network_files)

Import Annotation Data and merge it into Network data


In some case, we want to load another network table, for example, an edge attribute table and a node attribute table and merge it into network data.

In this example of workflow, by executing the following steps, you can load annotation data and merge it.

  1. First, import network data from local file/URL to Cytoscape.
  2. Second, import annotation data from database(in R, we can use bioconductor as database).
  3. Finally, merge the above two data table and push it to Cytoscape.

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

In [25]:
# Second, import annotation data from database(in R, we can use bioconductor as database).
# import library to access database
library(org.Sc.sgd.db)

# import Data
# DESCRIPTION data
descriptions <- select(org.Sc.sgd.db, keys=getAllNodes(cw), columns="DESCRIPTION")
df.descriptions <- data.frame(descriptions)

# GENENAME data
gene.names <- select(org.Sc.sgd.db, keys=getAllNodes(cw), columns="GENENAME")
df.gene.names <- data.frame(gene.names)

# GO data
go <- select(org.Sc.sgd.db, keys=getAllNodes(cw), columns="GO")
df.go <- data.frame(go)

# Finally, merge the above two data table and push it to Cytoscape.
# set DESCRIPTION as attribute data
nodeDataDefaults(g, attr = "DESCRIPTION") <- "undefined"
attr(nodeDataDefaults(g, attr = "DESCRIPTION"), "class") <- "STRING"

# set GENENAME as attribute data
nodeDataDefaults(g, attr = "name") <- "undefined"
attr(nodeDataDefaults(g, attr = "name"), "class") <- "STRING"

# set GO as attribute data
#nodeDataDefaults(g, attr = "go") <- "undefined"
#attr(nodeDataDefaults(g, attr = "go"), "class") <- "LIST"

# marge DESCRIPTION attribute.
for (index in 1:length(df.descriptions$DESCRIPTION)){
    nodeData(g, df.descriptions$ORF[[index]], "DESCRIPTION") <- df.descriptions$DESCRIPTION[[index]]
}

# marge GENENAME attribute.
for (index in 1:length(df.gene.names$GENENAME)){
    nodeData(g, df.gene.names$ORF[[index]], "name") <- df.gene.names$GENENAME[[index]]
}

# marge GO attribute.
#for (index in 1:length(df.gene.names$GENENAME)){
#    nodeData(g, df.gene.names$ORF[[index]], "name") <- df.gene.names$GENENAME[[index]]
#}

# show it.
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')


'select()' returned 1:1 mapping between keys and columns
'select()' returned 1:1 mapping between keys and columns
'select()' returned 1:many mapping between keys and columns
[1] "DESCRIPTION"
[1] "name"
[1] "label"
[1] "edgeType"

In [ ]: