RCy3 2.18.0
This vignette will show you how to import a data.frame of node attributes into Cytoscape as Node Table columns. The same approach works for edge and network attriubutes.
if(!"RCy3" %in% installed.packages()){
install.packages("BiocManager")
BiocManager::install("RCy3")
}
library(RCy3)
The whole point of RCy3 is to connect with Cytoscape. You will need to install and launch Cytoscape:
cytoscapePing()
When importing data, you are actually performing a merge function of sorts, appending columns to nodes (or edges) that are present in the referenced network. Data that do not match elements in the network are effectively discarded upon import.
So, in order to demonstrate data import, we first need to have a network. This command will import network files in any of the supported formats (e.g., SIF, GML, XGMML, etc).
sif <- system.file("extdata","galFiltered.sif",package="RCy3")
importNetworkFromFile(sif)
You should now see a network with just over 300 nodes. If you look at the Node Table, you’ll see that there are no attributes other than node names. Let’s fix that…
You can import data into Cytoscape from any data.frame in R as long as it contains row.names (or an arbitrary column) that match a Node Table column in Cytoscape. In this example, we are starting with a network with yeast identifiers in the “name” column. We also have a CSV file with gene expression data values keyed by yeast identifiers here:
csv <- system.file("extdata","galExpData.csv", package="RCy3")
data <- read.csv(csv, stringsAsFactors = FALSE)
Note: there may be times where your network and data identifers are of different types. This calls for identifier mapping. RCy3 provides a function to perform ID mapping in Cytoscape:
?mapTableColumn
Check out the Identifier mapping vignette for detailed examples.
Now we have a data.frame that includes our identifiers in a column called “name”, plus a bunch of data columns. Knowing our key columns, we can now perform the import:
loadTableData(data,data.key.column="name")
If you look back at the Node Table, you’ll now see that the corresponding rows of our data.frame have been imported as new columns.
Note: we relied on the default values for table (“node”) and table.key.column (“name”), but these can be specified as well. See help docs for parameter details.
?loadTableData