{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Test NetworkX methods" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipycytoscape\n", "import ipywidgets as widgets\n", "import networkx as nx" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj = ipycytoscape.CytoscapeWidget()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "button = widgets.Button(description=\"nx graph\")\n", "output = widgets.Output()\n", "\n", "# Generates a NX graph every time you click the button\n", "def on_button_clicked(b):\n", " with output:\n", " cytoscapeobj.graph.add_graph_from_networkx(nx.complete_graph(5))\n", "\n", "button.on_click(on_button_clicked)\n", "widgets.HBox([button, cytoscapeobj])\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Manipulate a graph using NetworkX\n", "\n", "nx_graph = nx.complete_graph(7)\n", "\n", "# Using its algorithms\n", "nx.shortest_path(nx_graph, 1, 5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create a new NX graph without using a button\n", "\n", "cytoscapeobj.graph.add_graph_from_networkx(nx_graph)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Manipulate the NX graph using cytoscape\n", "\n", "cytoscapeobj.set_layout(name='grid', nodeSpacing=10, edgeLengthVal=10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj.graph.add_graph_from_networkx(nx.complete_graph(5))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj.graph" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.8.2" } }, "nbformat": 4, "nbformat_minor": 4 }