-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from vaniisgh/master
add constructor to main widget
- Loading branch information
Showing
3 changed files
with
260 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "everyday-colonial", | ||
"metadata": {}, | ||
"source": [ | ||
"# Some examples of how to initialise the Graph Widget\n", | ||
"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:\n", | ||
"- A json file (wither the filename or the json object itself)\n", | ||
"- A networkx graph\n", | ||
"- A pandas Dataframe\n", | ||
"- A neo4j graph\n", | ||
"- A ipycytoscape Graph" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "nominated-closing", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipycytoscape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "waiting-brunswick", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "385ac265c37a4b35ada50b5f39c54028", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'node', 'css': {'background-c…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# 1. a cytoscape graph from json file\n", | ||
"json_from_filename = ipycytoscape.CytoscapeWidget(\"concentricData.json\")\n", | ||
"json_from_filename" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "dominant-locking", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "4c7176cff03b45c9b587e810b1bda8fe", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'node', 'css': {'background-c…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# 1. a cytoscape graph from json object\n", | ||
"\n", | ||
"import json\n", | ||
"with open(\"concentricData.json\") as fi:\n", | ||
" json_file = json.load(fi)\n", | ||
"\n", | ||
"json_from_object = ipycytoscape.CytoscapeWidget(json_file)\n", | ||
"json_from_object" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "stupid-mayor", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "3ccae77ecfac48ab90b110b0aff16960", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'node', 'css': {'background-c…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# A networkx graph\n", | ||
"import networkx as nx\n", | ||
"\n", | ||
"G = nx.complete_graph(5)\n", | ||
"graph_from_nx = ipycytoscape.CytoscapeWidget(G)\n", | ||
"graph_from_nx" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "conceptual-sunday", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "cc1f647957b140d1ba6bfbcd5d7c7132", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'node', 'css': {'background-c…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# A pandas Dataframe\n", | ||
"\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"graphFrame = pd.read_csv(\"https://raw.githubusercontent.com/nextstrain/ncov/fe5a7ed1f92af63d6d1d43d0307e4b2620108aaa/data/metadata.tsv\", sep = '\\t')\n", | ||
"ipycytoscape.CytoscapeWidget(graphFrame[:30], groupby_cols=['country'], attribute_list=['age', 'virus'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "undefined-store", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# A neo4j graph\n", | ||
"\n", | ||
"from py2neo import Graph, Node, Relationship\n", | ||
"\n", | ||
"g = graph = Graph(\"bolt://132.249.238.185:7687\", user=\"reader\", password=\"demo\")\n", | ||
"\n", | ||
"ipycytoscape.CytoscapeWidget(g)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "instrumental-aggregate", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "1b636bbf760c435a896967b2b9736884", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'node', 'css': {'background-c…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# A ipycytoscape graph\n", | ||
"ipycytoscape.CytoscapeWidget(json_from_object.graph)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters