Skip to content

Commit

Permalink
Introduce allow disconnected option to the CytoscapeViewer (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
zwelz3 authored Apr 26, 2021
1 parent cad19ce commit 684edff
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 187 deletions.
19 changes: 10 additions & 9 deletions examples/Cytoscape_Viewer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "preliminary-enzyme",
"id": "ad8c22f5",
"metadata": {},
"source": [
"# CytoscapeViewer Example\n",
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ambient-black",
"id": "16b0a0c7",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,15 +25,15 @@
},
{
"cell_type": "markdown",
"id": "varied-estimate",
"id": "021f0068",
"metadata": {},
"source": [
"Let's start by getting our graph loaded in."
]
},
{
"cell_type": "markdown",
"id": "aquatic-richardson",
"id": "c4a173f9",
"metadata": {},
"source": [
"Explain why we need a subgraph (too many nodes causes issues with cytoscape)."
Expand All @@ -42,7 +42,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "about-berlin",
"id": "2de0b9b6",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -70,6 +70,7 @@
" (film:4)\n",
" (planet:1)\n",
" (planet:2)\n",
" (planet:5)\n",
" }\n",
" }\n",
" \"\"\"\n",
Expand All @@ -80,7 +81,7 @@
},
{
"cell_type": "markdown",
"id": "neural-there",
"id": "9e7a7dc0",
"metadata": {},
"source": [
"## Now we can initiate the `CytoscapeViewer` object, which allows us to get a nice representation of an RDF or networkx graph"
Expand All @@ -89,7 +90,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "solid-shakespeare",
"id": "5f8f01cb",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -101,7 +102,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "legitimate-interest",
"id": "d3cbac63",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -110,7 +111,7 @@
},
{
"cell_type": "markdown",
"id": "annoying-michigan",
"id": "7f286413",
"metadata": {},
"source": [
"> The literal data from the RDF graph is collapsed onto the node based on the `RDF2NX`\n",
Expand Down
20 changes: 15 additions & 5 deletions examples/InteractiveViewer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "micro-contract",
"id": "e86027be",
"metadata": {},
"source": [
"## `InteractiveViewer` Example\n",
Expand All @@ -20,7 +20,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fluid-native",
"id": "28312451",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,7 +33,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "independent-hydrogen",
"id": "445b989a",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -96,15 +96,25 @@
{
"cell_type": "code",
"execution_count": null,
"id": "guided-cigarette",
"id": "ccf71ad7",
"metadata": {},
"outputs": [],
"source": [
"# Run the widget and assign the graph\n",
"iv = InteractiveViewer()\n",
"iv.graph = simple_graph\n",
"iv.rdf_graph = simple_graph\n",
"iv"
]
},
{
"cell_type": "markdown",
"id": "0e34fcee",
"metadata": {},
"source": [
"> Note: the `allow disconnected` option is disabled due to issues with async behavior of\n",
"> the underlying cytoscape widget. Track this issue within the `ipyradiant` library\n",
"> [here](https://github.com/jupyrdf/ipyradiant/issues/110)."
]
}
],
"metadata": {
Expand Down
48 changes: 9 additions & 39 deletions examples/RDF_to_NX_Custom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -268,37 +268,10 @@
"\n",
"The purpose of creating these projections is often to generate a view that is easier for\n",
"humans to interpret (or to leverage graph algorithms for LPGs). The following cells\n",
"demonstrate how the `ipyradiant` visualization widget `CytoscapeViewer` can be used\n",
"together with a simple class for checking JSON data in order to visualize and inspect an\n",
"LPG graph."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as ipyw\n",
"from IPython.display import JSON, display\n",
"\n",
"\n",
"# a simple class for visualizing JSON output for cytoscape graphs\n",
"class CombinedExample(ipyw.VBox):\n",
" def __init__(self, *args, **kwargs):\n",
" super().__init__(*args, **kwargs)\n",
" self.json_output = ipyw.Output()\n",
" self.graph_widget = kwargs[\"graph_widget\"]\n",
" self.children = [self.graph_widget, self.json_output]\n",
" self.graph_widget.cytoscape_widget.on(\"node\", \"click\", self.load_json)\n",
"\n",
" def load_json(self, node):\n",
" data = node[\"data\"]\n",
" data.pop(\"_label\", None)\n",
" data.pop(\"_attrs\", None)\n",
" with self.json_output:\n",
" self.json_output.clear_output()\n",
" display(JSON(data))"
"demonstrate how the `ipyradiant` visualization widget `InteractiveViewer` can be used\n",
"to visualize and inspect an LPG graph.\n",
"\n",
"> Note: the option to remove disconnected nodes will be enabled on ticket [#110](https://github.com/jupyrdf/ipyradiant/issues/110)"
]
},
{
Expand All @@ -307,15 +280,12 @@
"metadata": {},
"outputs": [],
"source": [
"from ipyradiant.visualization import CytoscapeViewer\n",
"\n",
"cv = CytoscapeViewer()\n",
"# specify the label key for the nx graph (default=\"label\")\n",
"cv._nx_label = \"rdfs:label\"\n",
"cv.graph = nx_graph\n",
"from ipyradiant.visualization import InteractiveViewer\n",
"\n",
"ce = CombinedExample(graph_widget=cv)\n",
"ce"
"iv = InteractiveViewer()\n",
"iv._rdf_converter = RDF2NX\n",
"iv.rdf_graph = lw.graph\n",
"iv"
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions examples/Test_CytoscapeViewer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# A Basic Test for the Cytoscape Viewer"
"# A Basic Test for the Cytoscape Viewer\n",
"\n",
"TODO:\n",
"\n",
"- Test the `allow_disconnected` flag"
]
},
{
Expand Down Expand Up @@ -121,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.7.10"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 684edff

Please sign in to comment.