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 show you how to perform a shortest path calculation using RBGL on a network in Cytoscape. RBGL is a Biocondutor package that offers an array of analytical functions for graphs.

Installation

if(!"RCy3" %in% installed.packages()){
    install.packages("BiocManager")
    BiocManager::install("RCy3")
}
if(!"RBGL" %in% installed.packages()){
    install.packages("BiocManager")
    BiocManager::install("RBGL")
}
library(RCy3)
library(RBGL)

Required Software

The whole point of RCy3 is to connect with Cytoscape. You will need to install and launch Cytoscape:

cytoscapePing()

Shortest Path with RBGL

Convert a sample Cytoscape network to a graph object (after removing a multiedge).

openSession()
selectEdges("YPL248C (pp) YML051W","name")
deleteSelectedEdges()
g <- createGraphFromNetwork()

Identify start and finish nodes (styling is optional).

start <- "YNL216W"  #RAP1
finish <- "YER040W"  #GLN3
setNodeBorderWidthBypass(c(start,finish), 20)
setNodeBorderColorBypass(start,"#00CC33")
setNodeBorderColorBypass(finish,"#CC00CC")

Perform shortest path calculation.

shortest <- sp.between(g, start, finish)
shortest$`YNL216W:YER040W`$length 
shortest.path <- shortest$`YNL216W:YER040W`$path_detail

Visualize results in Cytoscape.

selectNodes(shortest.path, "name")
setNodeBorderWidthBypass(shortest.path, 20)
createSubnetwork()
LS0tCnRpdGxlOiAiU2hvcnRlc3QgUGF0aCB3aXRoIFJCR0wiCmF1dGhvcjogImJ5IEFsZXhhbmRlciBQaWNvIgpkYXRlOiAiYHIgU3lzLkRhdGUoKWAiCm91dHB1dDoKICBodG1sX25vdGVib29rOgogICAgdG9jX2Zsb2F0OiB5ZXMKICAgIGNvZGVfZm9sZGluZzogbm9uZQogIGh0bWxfZG9jdW1lbnQ6CiAgICBkZl9wcmludDogcGFnZWQKcGFja2FnZTogUkN5MwotLS0KYGBge3IsIGVjaG8gPSBGQUxTRX0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KAogIGV2YWw9RkFMU0UKKQpgYGAKCipUaGUgUiBtYXJrZG93biBpcyBhdmFpbG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