Easy Graph Initialization¶
The CytoscapeWidget accepts an optional graph parameter, using this we can pass the graph’s data and initialise a graph. We can pass data as:
A json file (wither the filename or the json object itself)
A networkx graph
A pandas Dataframe
A neo4j graph
A ipycytoscape Graph
[1]:
import ipycytoscape
[2]:
# 1. a cytoscape graph from json file
json_from_filename = ipycytoscape.CytoscapeWidget("concentricData.json")
json_from_filename
[3]:
# 1. a cytoscape graph from json object
import json
with open("concentricData.json") as fi:
json_file = json.load(fi)
json_from_object = ipycytoscape.CytoscapeWidget(json_file)
json_from_object
[4]:
# A networkx graph
import networkx as nx
G = nx.complete_graph(5)
graph_from_nx = ipycytoscape.CytoscapeWidget(G)
graph_from_nx
[5]:
# A pandas Dataframe
import pandas as pd
graphFrame = pd.read_csv("https://raw.githubusercontent.com/nextstrain/ncov/fe5a7ed1f92af63d6d1d43d0307e4b2620108aaa/data/metadata.tsv", sep = '\t')
ipycytoscape.CytoscapeWidget(graphFrame[:30], groupby_cols=['country'], attribute_list=['age', 'virus'])
[ ]:
# NBVAL_SKIP
# A neo4j graph
from py2neo import Graph, Node, Relationship
g = graph = Graph("bolt://132.249.238.185:7687", user="reader", password="demo")
ipycytoscape.CytoscapeWidget(g)
[ ]:
# A ipycytoscape graph
ipycytoscape.CytoscapeWidget(json_from_object.graph)
[ ]: