If you use Jupyetr Notebook with cyREST, you can script your workflow. And in some cases, you may want to embed the result in the notebook. There are two ways to do it:
Second option is more appropreate for relatively large networks because users can zoom-in/out to see the detail. In this section, you will learn how to use interactive network visualization widget in py2cytoscape.
In [1]:
# Package to render networks in Cytoscape.js
from py2cytoscape import cytoscapejs as cyjs
# And standard JSON utility
import json
In [2]:
# Load network JSON file into this notebook session
yeast_network = json.load(open('sample_data/yeast.json')) # Simple yeast PPI network
kegg_pathway = json.load(open('sample_data/kegg_cancer.cyjs')) # KEGG Pathway
In [3]:
# And Visual Style file in Cytoscape.js format.
vs_collection = json.load(open('sample_data/kegg_style.json'))
# Create map from Title to Style
def add_to_map(key, value, target):
target[key] = value
styles = {}
map( lambda(x): add_to_map(x["title"], x["style"], styles), vs_collection)
# Display available style names
print(json.dumps(styles.keys(), indent=4))
There are several options for visualization:
Here is the simplest example: just pass Cytoscape.js object
In [4]:
cyjs.render(yeast_network)
In [5]:
# With custom Style, background color, and layout
cyjs.render(yeast_network, style=styles["default black"], background="black", layout_algorithm="circle")
In [6]:
# With CSS-style Background - with gradient
cyjs.render(yeast_network, style="default2", background="radial-gradient(#FFFFFF 15%, #EEEEEE 105%)", layout_algorithm="breadthfirst")
In [7]:
# And you can reproduce more complex styles created with Cytoscape 3!
cyjs.render(kegg_pathway, style=styles["KEGG Style"])