The R markdown is available from the pulldown menu for Code at the upper-right, choose “Download Rmd”, or download the Rmd from GitHub.
This vignette will demonstrate network retrieval from the STRING database, basic analysis, loading and visualization TCGA data in Cytoscape from R using the RCy3 package. Relevant subnetworks will be identified using different strategies, including network connectivity.
At the end of this vignette, you will have will be a visualization of TCGA data on a subnetwork built around highly mutated genes in the relevant cancer type.
The whole point of RCy3 is to connect with Cytoscape. You will need to install and launch Cytoscape:
For this vignette, you’ll also need the STRING app to access the STRING database from within Cytoscape:
Use Cytoscape to query the STRING database for networks of genes associated with breast cancer and ovarian cancer.
If the STRING app is not installed, no error is reported, but your network will be empty
string.cmd = 'string disease query disease="breast cancer" cutoff=0.9 species="Homo sapiens" limit=150'
commandsRun(string.cmd)Here we are using Cytoscape’s command line syntax, which can be used for any core or app automation function, and then making a GET request. Use commandsHelp to interrogate the functions and parameters available in your active Cytoscape session, including the apps you’ve installed!
Now that we’ve got a couple networks into Cytoscape, let’s see what we can do with them from R…
Now, let’s look at the tablular data associated with our STRING networks…
One of the great things about the STRING database is all the node and edge attriubtes they provide. Let’s pull some of it into R to play with…
We can retrieve any set of columns from Cytoscape and store them as an R data frame keyed by SUID. In this case, let’s retrieve the disease score column from the node table. Those will be our two parameters:
In order to reflect your exploration back onto the network, let’s generate subnetworks…
…from top quartile of ‘disease score’
top.quart <- quantile(disease.score.table[,1], 0.75)
top.nodes <- row.names(disease.score.table)[which(disease.score.table[,1]>top.quart)]
createSubnetwork(top.nodes,subnetwork.name ='top disease quartile')
#returns a Cytoscape network SUID…of connected nodes only
createSubnetwork(edges='all',subnetwork.name='top disease quartile connected') #handy way to exclude unconnected nodes!…from first neighbors of top 3 genes, using the network connectivity together with the data to direct discovery.
setCurrentNetwork(network="STRING network - ovarian cancer")
top.nodes <- row.names(disease.score.table)[tail(order(disease.score.table[,1]),3)]
selectNodes(nodes=top.nodes)
selectFirstNeighbors()
createSubnetwork('selected', subnetwork.name='top disease neighbors') # selected nodes, all connecting edges (default)…from diffusion algorithm starting with top 3 genes, using the network connectivity in a more subtle way than just first-degree neighbors.
setCurrentNetwork(network="STRING network - ovarian cancer")
selectNodes(nodes=top.nodes)
diffusionBasic() # diffusion!
createSubnetwork('selected',subnetwork.name = 'top disease diffusion')
layoutNetwork('force-directed')Pro-tip: don’t forget to setCurrentNetwork() to the correct parent network before getting table column data and making selections.
Downloaded TCGA data, preprocessed as R objects. Also available via each TCGA publication, e.g.:
load(system.file("extdata","tutorial-ovc-expr-mean-dataset.robj", package="RCy3"))
load(system.file("extdata","tutorial-ovc-mut-dataset.robj", package="RCy3"))
load(system.file("extdata","tutorial-brc-expr-mean-dataset.robj", package="RCy3"))
load(system.file("extdata","tutorial-brc-mut-dataset.robj", package="RCy3"))These datasets are similar to the data frames you normally encounter in R. For diversity, one using row.names to store corresponding gene names and the other uses the first column. Both are easy to import into Cytoscape.
str(brc.expr) # gene names in row.names of data.frame
str(brc.mut) # gene names in column named 'Hugo_Symbol'Let’s return to the Breast Cancer network…
setCurrentNetwork(network="STRING network - breast cancer")
layoutNetwork('force-directed') #uses same settings as previously set…and use the helper function from RCy3 called loadTableData
?loadTableData
loadTableData(brc.expr,table.key.column = "display name") #default data.frame key is row.names
loadTableData(brc.mut,'Hugo_Symbol',table.key.column = "display name") #specify column name if not defaultLet’s create a new style to visualize our imported data …starting with the basics, we will specify a few defaults and obvious mappings in a custom style all our own.
style.name = "dataStyle"
createVisualStyle(style.name)
setVisualStyle(style.name)
setNodeShapeDefault("ellipse", style.name) #remember to specify your style.name!
setNodeSizeDefault(60, style.name)
setNodeColorDefault("#AAAAAA", style.name)
setEdgeLineWidthDefault(2, style.name)
setEdgeOpacityDefault(50, style.name)
setNodeLabelMapping('display name', style.name)OK, now let’s update with a mapping for mutation. Here are all the same steps, but this time mapping mutation counts to both node border width and color.
setNodeBorderColorMapping('mut_count', colors = paletteColorBrewerReds, style.name=style.name)
setNodeBorderWidthMapping('mut_count', widths = c(2,8), style.name=style.name) # min and max width values are arbitrarily provided hereThis is a useful pair of visual properties to map to a single data column. See why?