From 1c94075c0d93f1a8b8a279dd4099130f0db862a1 Mon Sep 17 00:00:00 2001 From: Yihang Xin <46608109+yihangx@users.noreply.github.com> Date: Thu, 13 Jul 2023 01:20:54 -0700 Subject: [PATCH] Created using Colaboratory --- ...wikipathway-data-visualization-basic.ipynb | 2179 ++++++++++------- 1 file changed, 1350 insertions(+), 829 deletions(-) diff --git a/for-scripters/Python/wikipathway-data-visualization-basic.ipynb b/for-scripters/Python/wikipathway-data-visualization-basic.ipynb index 2216e19..a824259 100644 --- a/for-scripters/Python/wikipathway-data-visualization-basic.ipynb +++ b/for-scripters/Python/wikipathway-data-visualization-basic.ipynb @@ -1,856 +1,1377 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# WikiPathways Data Visualization Basic\n", - "## Yihang Xin, Kristina Hanspers and Alex Pico\n", - "## 2023-06-04" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "WikiPathways is a database of biological pathways maintained by and for the scientific community. Each pathway model in the database is annotated with database identfiers, which can be used for computation and data visualization.\n", - "\n", - "The following workflow describes pathway import and data visualization." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Installation\n", - "The following chunk of code installs the `py4cytoscape` module." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "%%capture\n", - "!python3 -m pip install python-igraph requests pandas networkx\n", - "!python3 -m pip install py4cytoscape" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If you are using a remote notebook environment such as Google Colab, please execute the cell below. (If you're running on your local notebook, you don't need to do that.)" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ + "cells": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: py4cytoscape in /opt/anaconda3/lib/python3.8/site-packages (0.0.11)\n", - "Requirement already satisfied: pandas in /opt/anaconda3/lib/python3.8/site-packages (from py4cytoscape) (1.1.3)\n", - "Requirement already satisfied: networkx in /opt/anaconda3/lib/python3.8/site-packages (from py4cytoscape) (2.5)\n", - "Requirement already satisfied: chardet in /opt/anaconda3/lib/python3.8/site-packages (from py4cytoscape) (3.0.4)\n", - "Requirement already satisfied: requests in /opt/anaconda3/lib/python3.8/site-packages (from py4cytoscape) (2.24.0)\n", - "Requirement already satisfied: colorbrewer in /opt/anaconda3/lib/python3.8/site-packages (from py4cytoscape) (0.2.0)\n", - "Requirement already satisfied: python-igraph in /opt/anaconda3/lib/python3.8/site-packages (from py4cytoscape) (0.8.3)\n", - "Requirement already satisfied: decorator in /opt/anaconda3/lib/python3.8/site-packages (from py4cytoscape) (4.4.2)\n", - "Requirement already satisfied: six in /opt/anaconda3/lib/python3.8/site-packages (from colorbrewer->py4cytoscape) (1.15.0)\n", - "Requirement already satisfied: python-dateutil>=2.7.3 in /opt/anaconda3/lib/python3.8/site-packages (from pandas->py4cytoscape) (2.8.1)\n", - "Requirement already satisfied: pytz>=2017.2 in /opt/anaconda3/lib/python3.8/site-packages (from pandas->py4cytoscape) (2020.1)\n", - "Requirement already satisfied: numpy>=1.15.4 in /opt/anaconda3/lib/python3.8/site-packages (from pandas->py4cytoscape) (1.19.2)\n", - "Requirement already satisfied: texttable>=1.6.2 in /opt/anaconda3/lib/python3.8/site-packages (from python-igraph->py4cytoscape) (1.6.3)\n", - "Requirement already satisfied: idna<3,>=2.5 in /opt/anaconda3/lib/python3.8/site-packages (from requests->py4cytoscape) (2.10)\n", - "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/anaconda3/lib/python3.8/site-packages (from requests->py4cytoscape) (1.25.11)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /opt/anaconda3/lib/python3.8/site-packages (from requests->py4cytoscape) (2020.6.20)\n" - ] + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] }, { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING: You are using pip version 21.0; however, version 23.1.2 is available.\n", - "You should consider upgrading via the '/opt/anaconda3/bin/python -m pip install --upgrade pip' command.\n" - ] + "cell_type": "markdown", + "metadata": { + "id": "AQmAClInPZOd" + }, + "source": [ + "# WikiPathways Data Visualization Basic\n", + "## Yihang Xin, Kristina Hanspers and Alex Pico\n", + "## 2023-06-04" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xcjshgEbPZOe" + }, + "source": [ + "WikiPathways is a database of biological pathways maintained by and for the scientific community. Each pathway model in the database is annotated with database identfiers, which can be used for computation and data visualization.\n", + "\n", + "The following workflow describes pathway import and data visualization." + ] }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "Loading Javascript client ... d837dab1-1778-481c-8dc6-42ab29ddc81c on https://jupyter-bridge.cytoscape.org\n" - ] + "cell_type": "markdown", + "metadata": { + "id": "Onr6J4XxPZOe" + }, + "source": [ + "# Installation\n", + "The following chunk of code installs the `py4cytoscape` module." + ] }, { - "data": { - "application/javascript": [ - "var Channel = \"d837dab1-1778-481c-8dc6-42ab29ddc81c\"; \n", - "\n", - "var JupyterBridge = \"https://jupyter-bridge.cytoscape.org\"; \n", - "\n", - " /*\n", - " These functions serve as a connector between a remote Jupyter server and Cytoscape.\n", - " They run in the user's browser, which also shows the Jupyter Notebook.\n", - "\n", - " A remote Jupyter Notebook call to the py4cytoscape package is forwarded to the Jupyter Bridge,\n", - " which is a standalone server. The functions in this connector execute in the Jupyter Notebook\n", - " browser, which executes on the same PC as Cytoscape. So, that's 4 components: (A) remote\n", - " Jupyter Notebook, (B) separate Jupyter Bridge server, (C) this browser-based component, and\n", - " (D) Cytoscape. (A) is on a remote server, (B) is on a different remote server, and (C) and (D)\n", - " are on the user's PC.\n", - "\n", - " (A) calls its py4cytoscape module, which forwards the request (in a JSON wrapper) to (B).\n", - " (C) picks up the request from (B), unpacks the request and forwards it to (D). (C) awaits a\n", - " reply from (D), and when it gets it, it forwards the reply (in a JSON wrapper) to (B).\n", - " (A)'s py4cytoscape module picks up the reply on (B) when it becomes available, unpacks it,\n", - " and returns it to (A).\n", - "\n", - " A Jupyter Notebook can talk to only one Cytoscape (i.e., the one on the machine running the\n", - " Jupyter Notebook browser), and Cytoscape should be called by only one Jupyter Notebook. The\n", - " Jupyter Bridge differentiates between Notebook-Cytoscape conversations via a channel UUID.\n", - " The UUID is prepended to this browser component by py4Cytoscape, and the component is\n", - " started by the Jupyter Notebook. (I wish py4Cytoscape could start the component, too, but I\n", - " haven't figured out how to do that yet, so startup code *is* required in the Jupyter\n", - " Notebook.)\n", - "\n", - " Note that for the case of a Jupyter server running on the same machine as Cytoscape, this\n", - " bridge isn't necessary because the Jupyter server's HTTP calls can easily connect to\n", - " Cytoscape over a localhost socket. So, the combination of Jupyter Bridge and this browser\n", - " component solves the problem of a Jupyter server (e.g., Google's Colab) that can't\n", - " connect to Cytoscape that sits behind a firewall.\n", - "\n", - " The request represents an HTTP call that py4cytoscape would normally make via HTTP directly\n", - " to Cytoscape via localhost when both py4cytoscape and Cytoscape are running on the same machine.\n", - " */\n", - "\n", - "const VERSION = '0.0.2'\n", - "\n", - "var showDebug; // Flag indicating whether to show Jupyter-bridge progress\n", - "if (typeof showDebug === 'undefined') {\n", - " showDebug = false\n", - "}\n", - "if (showDebug) {\n", - " alert(\"Starting Jupyter-bridge browser component\")\n", - "}\n", - "\n", - "//const JupyterBridge = 'http://127.0.0.1:5000' // for testing against local Jupyter-bridge\n", - "var JupyterBridge; // URL of Jupyter-bridge server could be defined by assignment pre-pended to this file\n", - "if (typeof JupyterBridge === 'undefined') {\n", - " JupyterBridge = 'https://jupyter-bridge.cytoscape.org' // for production\n", - "}\n", - "var Channel; // Unique constant that could be defined by assignment pre-pended to this file\n", - "if (typeof Channel === 'undefined') { // ... but if not assigned, use a debugging value\n", - " Channel = 1\n", - "}\n", - "\n", - "\n", - "var httpR = new XMLHttpRequest(); // for sending reply to Jupyter-bridge\n", - "var httpRE = new XMLHttpRequest(); // for sending backup error reply to Jupyter-bridge\n", - "var httpC = new XMLHttpRequest(); // for sending command to Cytoscape\n", - "var httpJ = new XMLHttpRequest(); // for fetching request from Jupyter-bridge\n", - "\n", - "const HTTP_OK = 200\n", - "const HTTP_SYS_ERR = 500\n", - "const HTTP_TIMEOUT = 408\n", - "const HTTP_TOO_MANY = 429\n", - "\n", - "\n", - " /* This function is useful if we want to rewrite the incoming URL to resolve just to our local one.\n", - " Doing this stops the Jupyter component from abusing this client to call out to endpoints other\n", - " than local Cytoscape. On the other hand, it makes it hard to detect when the Jupyter component\n", - " has specified a genuinely bad URL and really should get an error result. For now, we'll execute\n", - " the Jupyter-supplied URL and return the result, whatever it may be.\n", - "\n", - "const LocalCytoscape = 'http://127.0.0.1:1234'\n", - "\n", - "function parseURL(url) {\n", - " var reURLInformation = new RegExp([\n", - " '^(https?:)//', // protocol\n", - " '(([^:/?#]*)(?::([0-9]+))?)', // host (hostname and port)\n", - " '(/{0,1}[^?#]*)', // pathname\n", - " '(\\\\?[^#]*|)', // search\n", - " '(#.*|)$' // hash\n", - " ].join(''));\n", - " var match = url.match(reURLInformation);\n", - " return match && {\n", - " url: url,\n", - " protocol: match[1],\n", - " host: match[2],\n", - " hostname: match[3],\n", - " port: match[4],\n", - " pathname: match[5],\n", - " search: match[6],\n", - " hash: match[7]\n", - " }\n", - "}\n", - "*/\n", - "\n", - "function replyCytoscape(replyStatus, replyStatusText, replyText) {\n", - "\n", - " // Clean up after Jupyter bridge accepts reply\n", - " httpR.onreadystatechange = function() {\n", - " if (httpR.readyState === 4) {\n", - " if (showDebug) {\n", - " console.log(' status from queue_reply: ' + httpR.status + ', reply: ' + httpR.responseText)\n", - " }\n", - " }\n", - " }\n", - "\n", - " httpR.onerror = function() {\n", - " // Clean up after Jupyter bridge accepts backup reply\n", - " httpRE.onreadystatechange = function() {\n", - " if (httpRE.readyState === 4) {\n", - " if (showDebug) {\n", - " console.log(' status from backup queue_reply: ' + httpRE.status + ', reply: ' + httpRE.responseText)\n", - " }\n", - " }\n", - " }\n", - "\n", - " if (showDebug) {\n", - " console.log(' error from queue_reply -- could be Jupyter-Bridge server reject')\n", - " }\n", - " var errReply = {'status': HTTP_SYS_ERR, 'reason': 'Jupyter-Bridge rejected reply', 'text': 'Possibly reply is too long for Jupyter-Bridge server'}\n", - " httpRE.open('POST', jupyterBridgeURL, true)\n", - " httpRE.setRequestHeader('Content-Type', 'text/plain')\n", - " httpRE.send(JSON.stringify(errReply))\n", - " }\n", - "\n", - " var reply = {'status': replyStatus, 'reason': replyStatusText, 'text': replyText}\n", - "\n", - " // Send reply to Jupyter bridge\n", - " var jupyterBridgeURL = JupyterBridge + '/queue_reply?channel=' + Channel\n", - " if (showDebug) {\n", - " console.log('Starting queue to Jupyter bridge: ' + jupyterBridgeURL)\n", - " }\n", - " httpR.open('POST', jupyterBridgeURL, true)\n", - " httpR.setRequestHeader('Content-Type', 'text/plain')\n", - " httpR.send(JSON.stringify(reply))\n", - "}\n", - "\n", - "function callCytoscape(callSpec) {\n", - "\n", - " // Captures Cytoscape reply and sends it on\n", - " httpC.onreadystatechange = function() {\n", - " if (httpC.readyState === 4) {\n", - " if (showDebug) {\n", - " console.log(' status from CyREST: ' + httpC.status + ', statusText: ' + httpC.statusText + ', reply: ' + httpC.responseText)\n", - " }\n", - " // Note that httpC.status is 0 if the URL can't be reached *OR* there is a CORS violation.\n", - " // I wish I could tell the difference because for a CORS violation, I'd return a 404,\n", - " // which would roughly match what Python's native request package would return.\n", - " // The practical consequence is that the ultimate caller (e.g., py4cytoscape)\n", - " // returns different exceptions, depending on wither this module is doing the\n", - " // HTTP operation or the native Python requests package is. This is minor, but\n", - " // messes up tests that verify the exception type.\n", - " replyCytoscape(httpC.status, httpC.statusText, httpC.responseText)\n", - " waitOnJupyterBridge()\n", - " }\n", - " }\n", - "\n", - "// Build up request to Cytoscape, making sure host is local.\n", - "// Too heavy handed: localURL = LocalCytoscape + parseURL(callSpec.url).pathname\n", - " var localURL = callSpec.url // Try using what was passed in ... is there a security risk??\n", - "\n", - " if (showDebug) {\n", - " console.log('Command to CyREST: ' + callSpec.command + ' (' + localURL + ')')\n", - " if (callSpec.params) {\n", - " console.log(' params: ' + JSON.stringify(callSpec.params))\n", - " }\n", - " if (callSpec.headers) {\n", - " console.log(' header: ' + JSON.stringify(callSpec.headers))\n", - " }\n", - " if (callSpec.data) {\n", - " console.log(' data: ' + JSON.stringify(callSpec.data))\n", - " }\n", - " }\n", - "\n", - " if (callSpec.command === 'webbrowser') {\n", - " if (window.open(callSpec.url)) {\n", - " replyCytoscape(HTTP_OK, 'OK', '')\n", - " } else {\n", - " replyCytoscape(HTTP_SYS_ERR, 'BAD BROWSER OPEN', '')\n", - " }\n", - " waitOnJupyterBridge()\n", - " } else if (callSpec.command === 'version') {\n", - " replyCytoscape(HTTP_OK, 'OK',\n", - " JSON.stringify({\"jupyterBridgeVersion\": VERSION}))\n", - " waitOnJupyterBridge()\n", - " } else {\n", - " var joiner = '?'\n", - " for (let param in callSpec.params) {\n", - " localURL = localURL + joiner + param + '=' + encodeURIComponent(callSpec.params[param])\n", - " joiner = '&'\n", - " }\n", - "\n", - " httpC.open(callSpec.command, localURL, true)\n", - " for (let header in callSpec.headers) {\n", - " httpC.setRequestHeader(header, callSpec.headers[header])\n", - " }\n", - "\n", - " // Send request to Cytoscape ... reply goes to onreadystatechange handler\n", - " httpC.send(JSON.stringify(callSpec.data))\n", - " }\n", - "}\n", - "\n", - "function waitOnJupyterBridge() {\n", - "\n", - " // Captures request from Jupyter bridge\n", - " httpJ.onreadystatechange = function() {\n", - " if (httpJ.readyState === 4) {\n", - " if (showDebug) {\n", - " console.log(' status from dequeue_request: ' + httpJ.status + ', reply: ' + httpJ.responseText)\n", - " }\n", - " try {\n", - " if (httpJ.status == HTTP_TOO_MANY) {\n", - " // Nothing more to do ... the browser has created too many listeners,\n", - " // and it's time to stop listening because the server saw a listener\n", - " // listening on this channel before we got there.\n", - " console.log(' shutting down because of redundant reader on channel: ' + Channel)\n", - " } else {\n", - " if (httpJ.status === HTTP_TIMEOUT) {\n", - " waitOnJupyterBridge()\n", - " } else {\n", - " callCytoscape(JSON.parse(httpJ.responseText))\n", - " }\n", - " }\n", - " } catch(err) {\n", - " if (showDebug) {\n", - " console.log(' exception calling Cytoscape: ' + err)\n", - " }\n", - " // Bad responseText means something bad happened that we don't understand.\n", - " // Go wait on another request, as there's nothing to call Cytoscape with.\n", - " waitOnJupyterBridge()\n", - " }\n", - " }\n", - " }\n", - "\n", - " // Wait for request from Jupyter bridge\n", - " var jupyterBridgeURL = JupyterBridge + '/dequeue_request?channel=' + Channel\n", - " if (showDebug) {\n", - " console.log('Starting dequeue on Jupyter bridge: ' + jupyterBridgeURL)\n", - " }\n", - " httpJ.open('GET', jupyterBridgeURL, true)\n", - " httpJ.send()\n", - "}\n", - "\n", - "// This kicks off a loop that ends by calling waitOnJupyterBridge again. This first call\n", - "// ejects any dead readers before we start a read\n", - "waitOnJupyterBridge() // Wait for message from Jupyter bridge, execute it, and return reply\n", - "\n", - "if (showDebug) {\n", - " alert(\"Jupyter-bridge browser component is started on \" + JupyterBridge + ', channel ' + Channel)\n", - "}\n" + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "H2f42jilPZOf" + }, + "outputs": [], + "source": [ + "%%capture\n", + "!python3 -m pip install python-igraph requests pandas networkx\n", + "!python3 -m pip install py4cytoscape" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FFg-ZQa0PZOg" + }, + "source": [ + "If you are using a remote notebook environment such as Google Colab, please execute the cell below. (If you're running on your local notebook, you don't need to do that.)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 422 + }, + "id": "iAbEMb4BPZOh", + "outputId": "c80eca5b-db96-4618-875d-04018730ea26" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.10/dist-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.\n", + " warnings.warn(\"Setuptools is replacing distutils.\")\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: py4cytoscape in /usr/local/lib/python3.10/dist-packages (1.7.0)\n" + ], + "text/html": [ + "
Requirement already satisfied: py4cytoscape in /usr/local/lib/python3.10/dist-packages (1.7.0)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (1.5.3)\n" + ], + "text/html": [ + "
Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (1.5.3)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (3.1)\n" + ], + "text/html": [ + "
Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (3.1)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (2.27.1)\n" + ], + "text/html": [ + "
Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (2.27.1)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: python-igraph in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (0.10.5)\n" + ], + "text/html": [ + "
Requirement already satisfied: python-igraph in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (0.10.5)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: colorbrewer in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (0.2.0)\n" + ], + "text/html": [ + "
Requirement already satisfied: colorbrewer in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (0.2.0)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: chardet in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (4.0.0)\n" + ], + "text/html": [ + "
Requirement already satisfied: chardet in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (4.0.0)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (4.4.2)\n" + ], + "text/html": [ + "
Requirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (4.4.2)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: backoff in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (2.2.1)\n" + ], + "text/html": [ + "
Requirement already satisfied: backoff in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (2.2.1)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: colour in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (0.1.5)\n" + ], + "text/html": [ + "
Requirement already satisfied: colour in /usr/local/lib/python3.10/dist-packages (from py4cytoscape) (0.1.5)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from colorbrewer->py4cytoscape) (1.16.0)\n" + ], + "text/html": [ + "
Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from colorbrewer->py4cytoscape) (1.16.0)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas->py4cytoscape) (2.8.2)\n" + ], + "text/html": [ + "
Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas->py4cytoscape) (2.8.2)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->py4cytoscape) (2022.7.1)\n" + ], + "text/html": [ + "
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->py4cytoscape) (2022.7.1)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from pandas->py4cytoscape) (1.22.4)\n" + ], + "text/html": [ + "
Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from pandas->py4cytoscape) (1.22.4)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: igraph==0.10.5 in /usr/local/lib/python3.10/dist-packages (from python-igraph->py4cytoscape) (0.10.5)\n" + ], + "text/html": [ + "
Requirement already satisfied: igraph==0.10.5 in /usr/local/lib/python3.10/dist-packages (from python-igraph->py4cytoscape) (0.10.5)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: texttable>=1.6.2 in /usr/local/lib/python3.10/dist-packages (from igraph==0.10.5->python-igraph->py4cytoscape) (1.6.7)\n" + ], + "text/html": [ + "
Requirement already satisfied: texttable>=1.6.2 in /usr/local/lib/python3.10/dist-packages (from igraph==0.10.5->python-igraph->py4cytoscape) (1.6.7)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (1.26.16)\n" + ], + "text/html": [ + "
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (1.26.16)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (2023.5.7)\n" + ], + "text/html": [ + "
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (2023.5.7)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (2.0.12)\n" + ], + "text/html": [ + "
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (2.0.12)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (3.4)\n" + ], + "text/html": [ + "
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->py4cytoscape) (3.4)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "NumExpr defaulting to 2 threads.\n" + ], + "text/html": [ + "
NumExpr defaulting to 2 threads.\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Loading Javascript client ... 04b8150c-5b2d-41f4-8eef-b4b24793770a on https://jupyter-bridge.cytoscape.org\n", + "ADVICE: WHEN RUNNING UNDER COLAB, DO NOT RE-RUN THIS CELL WITHOUT MANUALLY EXECUTING Runtime | Factory Reset Runtime FROM THE COLAB MENU FIRST.\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ], + "application/javascript": [ + "var Channel = \"04b8150c-5b2d-41f4-8eef-b4b24793770a\"; \n", + "\n", + "var JupyterBridge = \"https://jupyter-bridge.cytoscape.org\"; \n", + "\n", + " /*\n", + " These functions serve as a connector between a remote Jupyter server and Cytoscape.\n", + " They run in the user's browser, which also shows the Jupyter Notebook.\n", + "\n", + " A remote Jupyter Notebook call to the py4cytoscape package is forwarded to the Jupyter Bridge,\n", + " which is a standalone server. The functions in this connector execute in the Jupyter Notebook\n", + " browser, which executes on the same PC as Cytoscape. So, that's 4 components: (A) remote\n", + " Jupyter Notebook, (B) separate Jupyter Bridge server, (C) this browser-based component, and\n", + " (D) Cytoscape. (A) is on a remote server, (B) is on a different remote server, and (C) and (D)\n", + " are on the user's PC.\n", + "\n", + " (A) calls its py4cytoscape module, which forwards the request (in a JSON wrapper) to (B).\n", + " (C) picks up the request from (B), unpacks the request and forwards it to (D). (C) awaits a\n", + " reply from (D), and when it gets it, it forwards the reply (in a JSON wrapper) to (B).\n", + " (A)'s py4cytoscape module picks up the reply on (B) when it becomes available, unpacks it,\n", + " and returns it to (A).\n", + "\n", + " A Jupyter Notebook can talk to only one Cytoscape (i.e., the one on the machine running the\n", + " Jupyter Notebook browser), and Cytoscape should be called by only one Jupyter Notebook. The\n", + " Jupyter Bridge differentiates between Notebook-Cytoscape conversations via a channel UUID.\n", + " The UUID is prepended to this browser component by py4Cytoscape, and the component is\n", + " started by the Jupyter Notebook. (I wish py4Cytoscape could start the component, too, but I\n", + " haven't figured out how to do that yet, so startup code *is* required in the Jupyter\n", + " Notebook.)\n", + "\n", + " Note that for the case of a Jupyter server running on the same machine as Cytoscape, this\n", + " bridge isn't necessary because the Jupyter server's HTTP calls can easily connect to\n", + " Cytoscape over a localhost socket. So, the combination of Jupyter Bridge and this browser\n", + " component solves the problem of a Jupyter server (e.g., Google's Colab) that can't\n", + " connect to Cytoscape that sits behind a firewall.\n", + "\n", + " The request represents an HTTP call that py4cytoscape would normally make via HTTP directly\n", + " to Cytoscape via localhost when both py4cytoscape and Cytoscape are running on the same machine.\n", + " */\n", + "\n", + "const VERSION = '0.0.2'\n", + "\n", + "var showDebug; // Flag indicating whether to show Jupyter-bridge progress\n", + "if (typeof showDebug === 'undefined') {\n", + " showDebug = false\n", + "}\n", + "if (showDebug) {\n", + " alert(\"Starting Jupyter-bridge browser component\")\n", + "}\n", + "\n", + "//const JupyterBridge = 'http://127.0.0.1:5000' // for testing against local Jupyter-bridge\n", + "var JupyterBridge; // URL of Jupyter-bridge server could be defined by assignment pre-pended to this file\n", + "if (typeof JupyterBridge === 'undefined') {\n", + " JupyterBridge = 'https://jupyter-bridge.cytoscape.org' // for production\n", + "}\n", + "var Channel; // Unique constant that could be defined by assignment pre-pended to this file\n", + "if (typeof Channel === 'undefined') { // ... but if not assigned, use a debugging value\n", + " Channel = 1\n", + "}\n", + "\n", + "\n", + "var httpR = new XMLHttpRequest(); // for sending reply to Jupyter-bridge\n", + "var httpRE = new XMLHttpRequest(); // for sending backup error reply to Jupyter-bridge\n", + "var httpC = new XMLHttpRequest(); // for sending command to Cytoscape\n", + "var httpJ = new XMLHttpRequest(); // for fetching request from Jupyter-bridge\n", + "\n", + "const HTTP_OK = 200\n", + "const HTTP_SYS_ERR = 500\n", + "const HTTP_TIMEOUT = 408\n", + "const HTTP_TOO_MANY = 429\n", + "\n", + "\n", + " /* This function is useful if we want to rewrite the incoming URL to resolve just to our local one.\n", + " Doing this stops the Jupyter component from abusing this client to call out to endpoints other\n", + " than local Cytoscape. On the other hand, it makes it hard to detect when the Jupyter component\n", + " has specified a genuinely bad URL and really should get an error result. For now, we'll execute\n", + " the Jupyter-supplied URL and return the result, whatever it may be.\n", + "\n", + "const LocalCytoscape = 'http://127.0.0.1:1234'\n", + "\n", + "function parseURL(url) {\n", + " var reURLInformation = new RegExp([\n", + " '^(https?:)//', // protocol\n", + " '(([^:/?#]*)(?::([0-9]+))?)', // host (hostname and port)\n", + " '(/{0,1}[^?#]*)', // pathname\n", + " '(\\\\?[^#]*|)', // search\n", + " '(#.*|)$' // hash\n", + " ].join(''));\n", + " var match = url.match(reURLInformation);\n", + " return match && {\n", + " url: url,\n", + " protocol: match[1],\n", + " host: match[2],\n", + " hostname: match[3],\n", + " port: match[4],\n", + " pathname: match[5],\n", + " search: match[6],\n", + " hash: match[7]\n", + " }\n", + "}\n", + "*/\n", + "\n", + "function replyCytoscape(replyStatus, replyStatusText, replyText) {\n", + "\n", + " // Clean up after Jupyter bridge accepts reply\n", + " httpR.onreadystatechange = function() {\n", + " if (httpR.readyState === 4) {\n", + " if (showDebug) {\n", + " console.log(' status from queue_reply: ' + httpR.status + ', reply: ' + httpR.responseText)\n", + " }\n", + " }\n", + " }\n", + "\n", + " httpR.onerror = function() {\n", + " // Clean up after Jupyter bridge accepts backup reply\n", + " httpRE.onreadystatechange = function() {\n", + " if (httpRE.readyState === 4) {\n", + " if (showDebug) {\n", + " console.log(' status from backup queue_reply: ' + httpRE.status + ', reply: ' + httpRE.responseText)\n", + " }\n", + " }\n", + " }\n", + "\n", + " if (showDebug) {\n", + " console.log(' error from queue_reply -- could be Jupyter-Bridge server reject')\n", + " }\n", + " var errReply = {'status': HTTP_SYS_ERR, 'reason': 'Jupyter-Bridge rejected reply', 'text': 'Possibly reply is too long for Jupyter-Bridge server'}\n", + " httpRE.open('POST', jupyterBridgeURL, true)\n", + " httpRE.setRequestHeader('Content-Type', 'text/plain')\n", + " httpRE.send(JSON.stringify(errReply))\n", + " }\n", + "\n", + " var reply = {'status': replyStatus, 'reason': replyStatusText, 'text': replyText}\n", + "\n", + " // Send reply to Jupyter bridge\n", + " var jupyterBridgeURL = JupyterBridge + '/queue_reply?channel=' + Channel\n", + " if (showDebug) {\n", + " console.log('Starting queue to Jupyter bridge: ' + jupyterBridgeURL)\n", + " }\n", + " httpR.open('POST', jupyterBridgeURL, true)\n", + " httpR.setRequestHeader('Content-Type', 'text/plain')\n", + " httpR.send(JSON.stringify(reply))\n", + "}\n", + "\n", + "function callCytoscape(callSpec) {\n", + "\n", + " // Captures Cytoscape reply and sends it on\n", + " httpC.onreadystatechange = function() {\n", + " if (httpC.readyState === 4) {\n", + " if (showDebug) {\n", + " console.log(' status from CyREST: ' + httpC.status + ', statusText: ' + httpC.statusText + ', reply: ' + httpC.responseText)\n", + " }\n", + " // Note that httpC.status is 0 if the URL can't be reached *OR* there is a CORS violation.\n", + " // I wish I could tell the difference because for a CORS violation, I'd return a 404,\n", + " // which would roughly match what Python's native request package would return.\n", + " // The practical consequence is that the ultimate caller (e.g., py4cytoscape)\n", + " // returns different exceptions, depending on wither this module is doing the\n", + " // HTTP operation or the native Python requests package is. This is minor, but\n", + " // messes up tests that verify the exception type.\n", + " replyCytoscape(httpC.status, httpC.statusText, httpC.responseText)\n", + " waitOnJupyterBridge()\n", + " }\n", + " }\n", + "\n", + "// Build up request to Cytoscape, making sure host is local.\n", + "// Too heavy handed: localURL = LocalCytoscape + parseURL(callSpec.url).pathname\n", + " var localURL = callSpec.url // Try using what was passed in ... is there a security risk??\n", + "\n", + " if (showDebug) {\n", + " console.log('Command to CyREST: ' + callSpec.command + ' (' + localURL + ')')\n", + " if (callSpec.params) {\n", + " console.log(' params: ' + JSON.stringify(callSpec.params))\n", + " }\n", + " if (callSpec.headers) {\n", + " console.log(' header: ' + JSON.stringify(callSpec.headers))\n", + " }\n", + " if (callSpec.data) {\n", + " console.log(' data: ' + JSON.stringify(callSpec.data))\n", + " }\n", + " }\n", + "\n", + " if (callSpec.command === 'webbrowser') {\n", + " if (window.open(callSpec.url)) {\n", + " replyCytoscape(HTTP_OK, 'OK', '')\n", + " } else {\n", + " replyCytoscape(HTTP_SYS_ERR, 'BAD BROWSER OPEN', '')\n", + " }\n", + " waitOnJupyterBridge()\n", + " } else if (callSpec.command === 'version') {\n", + " replyCytoscape(HTTP_OK, 'OK',\n", + " JSON.stringify({\"jupyterBridgeVersion\": VERSION}))\n", + " waitOnJupyterBridge()\n", + " } else {\n", + " var joiner = '?'\n", + " for (let param in callSpec.params) {\n", + " localURL = localURL + joiner + param + '=' + encodeURIComponent(callSpec.params[param])\n", + " joiner = '&'\n", + " }\n", + "\n", + " httpC.open(callSpec.command, localURL, true)\n", + " for (let header in callSpec.headers) {\n", + " httpC.setRequestHeader(header, callSpec.headers[header])\n", + " }\n", + "\n", + " // Send request to Cytoscape ... reply goes to onreadystatechange handler\n", + " httpC.send(JSON.stringify(callSpec.data))\n", + " }\n", + "}\n", + "\n", + "function waitOnJupyterBridge() {\n", + "\n", + " // Captures request from Jupyter bridge\n", + " httpJ.onreadystatechange = function() {\n", + " if (httpJ.readyState === 4) {\n", + " if (showDebug) {\n", + " console.log(' status from dequeue_request: ' + httpJ.status + ', reply: ' + httpJ.responseText)\n", + " }\n", + " try {\n", + " if (httpJ.status == HTTP_TOO_MANY) {\n", + " // Nothing more to do ... the browser has created too many listeners,\n", + " // and it's time to stop listening because the server saw a listener\n", + " // listening on this channel before we got there.\n", + " console.log(' shutting down because of redundant reader on channel: ' + Channel)\n", + " } else {\n", + " if (httpJ.status === HTTP_TIMEOUT) {\n", + " waitOnJupyterBridge()\n", + " } else {\n", + " callCytoscape(JSON.parse(httpJ.responseText))\n", + " }\n", + " }\n", + " } catch(err) {\n", + " if (showDebug) {\n", + " console.log(' exception calling Cytoscape: ' + err)\n", + " }\n", + " // Bad responseText means something bad happened that we don't understand.\n", + " // Go wait on another request, as there's nothing to call Cytoscape with.\n", + " waitOnJupyterBridge()\n", + " }\n", + " }\n", + " }\n", + "\n", + " // Wait for request from Jupyter bridge\n", + " var jupyterBridgeURL = JupyterBridge + '/dequeue_request?channel=' + Channel\n", + " if (showDebug) {\n", + " console.log('Starting dequeue on Jupyter bridge: ' + jupyterBridgeURL)\n", + " }\n", + " httpJ.open('GET', jupyterBridgeURL, true)\n", + " httpJ.send()\n", + "}\n", + "\n", + "// This kicks off a loop that ends by calling waitOnJupyterBridge again. This first call\n", + "// ejects any dead readers before we start a read\n", + "waitOnJupyterBridge() // Wait for message from Jupyter bridge, execute it, and return reply\n", + "\n", + "if (showDebug) {\n", + " alert(\"Jupyter-bridge browser component is started on \" + JupyterBridge + ', channel ' + Channel)\n", + "}\n" + ] + }, + "metadata": {}, + "execution_count": 2 + } ], - "text/plain": [ - "" + "source": [ + "#_PY4CYTOSCAPE = 'git+https://github.com/cytoscape/py4cytoscape@1.7.0' # optional\n", + "import requests\n", + "exec(requests.get(\"https://raw.githubusercontent.com/cytoscape/jupyter-bridge/master/client/p4c_init.py\").text)\n", + "IPython.display.Javascript(_PY4CYTOSCAPE_BROWSER_CLIENT_JS) # Start browser client" ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#_PY4CYTOSCAPE = 'git+https://github.com/cytoscape/py4cytoscape@1.7.0' # optional\n", - "import requests\n", - "exec(requests.get(\"https://raw.githubusercontent.com/cytoscape/jupyter-bridge/master/client/p4c_init.py\").text)\n", - "IPython.display.Javascript(_PY4CYTOSCAPE_BROWSER_CLIENT_JS) # Start browser client" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Prerequisites\n", - "## In addition to this package (py4cytoscape latest version 1.7.0), you will need:\n", - "\n", - "* Latest version of Cytoscape, which can be downloaded from https://cytoscape.org/download.html. Simply follow the installation instructions on screen.\n", - "* Complete installation wizard\n", - "* Launch Cytoscape\n", - "\n", - "For this notebook, you’ll also need the WikiPathways app to access the WikiPathways database from within Cytoscape: \n", - "\n", - "* Install the WikiPathways app from http://apps.cytoscape.org/apps/wikipathways\n", - "* You can also install app inside Python notebook by running \"py4cytoscape.install_app('Your App')\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Import the required package" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "import py4cytoscape as p4c\n", - "import pandas as pd\n", - "import warnings\n", - "warnings.filterwarnings(\"ignore\", category=pd.core.common.SettingWithCopyWarning)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Import Cell Cycle pathway into Cytoscape." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "[]" + "cell_type": "markdown", + "metadata": { + "id": "8eD3mDIPPZOi" + }, + "source": [ + "# Prerequisites\n", + "## In addition to this package (py4cytoscape latest version 1.7.0), you will need:\n", + "\n", + "* Latest version of Cytoscape, which can be downloaded from https://cytoscape.org/download.html. Simply follow the installation instructions on screen.\n", + "* Complete installation wizard\n", + "* Launch Cytoscape\n", + "\n", + "For this notebook, you’ll also need the WikiPathways app to access the WikiPathways database from within Cytoscape:\n", + "\n", + "* Install the WikiPathways app from http://apps.cytoscape.org/apps/wikipathways\n", + "* You can also install app inside Python notebook by running \"py4cytoscape.install_app('Your App')\"" ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "cmd_list = ['wikipathways','import-as-pathway','id=WP179']\n", - "cmd = \" \".join(cmd_list)\n", - "p4c.commands.commands_get(cmd) " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The data we will be using for this workflow (E-GEOD-68086.csv) is from a study investigating the RNA-seq signatures of platelets from patients with various types of cancer, in an effort to develop a platelet-based diagnostic (Best et el., 2015). The data was downloaded from Expression Atlas." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_W3wZ-MfPZOj" + }, + "source": [ + "# Import the required package" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "XVuA9lM_PZOj" + }, + "outputs": [], + "source": [ + "import py4cytoscape as p4c\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4zxy_l45PZOk" + }, + "source": [ + "## Import Cell Cycle pathway into Cytoscape." + ] + }, { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Gene IDGene Name'breast carcinoma' vs 'normal' .foldChange'breast carcinoma' vs 'normal'.pValue'colorectal carcinoma' vs 'normal' .foldChange'colorectal carcinoma' vs 'normal'.pValue'glioblastoma' vs 'normal' .foldChange'glioblastoma' vs 'normal'.pValue'hepatobiliary carcinoma' vs 'normal' .foldChange'hepatobiliary carcinoma' vs 'normal'.pValue'non-small cell lung carcinoma' vs 'normal' .foldChange'non-small cell lung carcinoma' vs 'normal'.pValue'pancreatic adenocarcinoma' vs 'normal' .foldChange'pancreatic adenocarcinoma' vs 'normal'.pValue
0ENSG00000000003TSPAN6-1.28.524371e-03-0.71.886303e-01-1.60.000273-0.90.144043-2.13.970000e-07-2.41.140000e-05
1ENSG00000000005TNMD-2.41.890000e-04-3.19.370000e-07-2.50.000044-1.00.193911-2.18.710000e-05-3.23.300000e-06
2ENSG00000000419DPM1-1.03.210000e-05-1.14.870000e-05-0.90.002806-0.30.410319-0.84.849082e-03-1.03.360000e-04
3ENSG00000000457SCYL3-2.02.440000e-10-2.04.980000e-10-1.30.000105-1.60.000035-2.21.810000e-11-3.03.780000e-18
4ENSG00000000460C1orf1120.15.262086e-01-0.17.400732e-01-0.50.0160920.20.366367-0.91.150000e-05-0.32.105133e-01
\n", - "
" + "cell_type": "code", + "execution_count": 4, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dqJzZfz-PZOk", + "outputId": "1d7c6d6d-fff6-4c75-affd-c82a12595cd3" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[]" + ] + }, + "metadata": {}, + "execution_count": 4 + } ], - "text/plain": [ - " Gene ID Gene Name 'breast carcinoma' vs 'normal' .foldChange \\\n", - "0 ENSG00000000003 TSPAN6 -1.2 \n", - "1 ENSG00000000005 TNMD -2.4 \n", - "2 ENSG00000000419 DPM1 -1.0 \n", - "3 ENSG00000000457 SCYL3 -2.0 \n", - "4 ENSG00000000460 C1orf112 0.1 \n", - "\n", - " 'breast carcinoma' vs 'normal'.pValue \\\n", - "0 8.524371e-03 \n", - "1 1.890000e-04 \n", - "2 3.210000e-05 \n", - "3 2.440000e-10 \n", - "4 5.262086e-01 \n", - "\n", - " 'colorectal carcinoma' vs 'normal' .foldChange \\\n", - "0 -0.7 \n", - "1 -3.1 \n", - "2 -1.1 \n", - "3 -2.0 \n", - "4 -0.1 \n", - "\n", - " 'colorectal carcinoma' vs 'normal'.pValue \\\n", - "0 1.886303e-01 \n", - "1 9.370000e-07 \n", - "2 4.870000e-05 \n", - "3 4.980000e-10 \n", - "4 7.400732e-01 \n", - "\n", - " 'glioblastoma' vs 'normal' .foldChange 'glioblastoma' vs 'normal'.pValue \\\n", - "0 -1.6 0.000273 \n", - "1 -2.5 0.000044 \n", - "2 -0.9 0.002806 \n", - "3 -1.3 0.000105 \n", - "4 -0.5 0.016092 \n", - "\n", - " 'hepatobiliary carcinoma' vs 'normal' .foldChange \\\n", - "0 -0.9 \n", - "1 -1.0 \n", - "2 -0.3 \n", - "3 -1.6 \n", - "4 0.2 \n", - "\n", - " 'hepatobiliary carcinoma' vs 'normal'.pValue \\\n", - "0 0.144043 \n", - "1 0.193911 \n", - "2 0.410319 \n", - "3 0.000035 \n", - "4 0.366367 \n", - "\n", - " 'non-small cell lung carcinoma' vs 'normal' .foldChange \\\n", - "0 -2.1 \n", - "1 -2.1 \n", - "2 -0.8 \n", - "3 -2.2 \n", - "4 -0.9 \n", - "\n", - " 'non-small cell lung carcinoma' vs 'normal'.pValue \\\n", - "0 3.970000e-07 \n", - "1 8.710000e-05 \n", - "2 4.849082e-03 \n", - "3 1.810000e-11 \n", - "4 1.150000e-05 \n", - "\n", - " 'pancreatic adenocarcinoma' vs 'normal' .foldChange \\\n", - "0 -2.4 \n", - "1 -3.2 \n", - "2 -1.0 \n", - "3 -3.0 \n", - "4 -0.3 \n", - "\n", - " 'pancreatic adenocarcinoma' vs 'normal'.pValue \n", - "0 1.140000e-05 \n", - "1 3.300000e-06 \n", - "2 3.360000e-04 \n", - "3 3.780000e-18 \n", - "4 2.105133e-01 " + "source": [ + "cmd_list = ['wikipathways','import-as-pathway','id=WP179']\n", + "cmd = \" \".join(cmd_list)\n", + "p4c.commands.commands_get(cmd)" ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = pd.read_csv(\"https://cytoscape.github.io/cytoscape-tutorials/protocols/data/E-GEOD-68086.csv\")\n", - "df.head()" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "'Success: Data loaded in defaultnode table'" + "cell_type": "markdown", + "metadata": { + "id": "pRDuhmx-PZOk" + }, + "source": [ + "The data we will be using for this workflow (E-GEOD-68086.csv) is from a study investigating the RNA-seq signatures of platelets from patients with various types of cancer, in an effort to develop a platelet-based diagnostic (Best et el., 2015). The data was downloaded from Expression Atlas." ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "p4c.load_table_data(df, data_key_column=\"Gene ID\", table_key_column=\"Ensembl\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Data Visualization: Node Fill Color" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We now have the data in Cytoscape, linked to the pathway, and ready to map to visual properties of the nodes in the network. For this workflow, we will choose data from one of the cancer types, \"breast carcinoma\", and visualize the fold change as Node Fill Color." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "''" + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 319 + }, + "id": "yFpEX0l0PZOk", + "outputId": "a13840d0-ccb4-4289-da9e-24bfaf256a97" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " Gene ID Gene Name 'breast carcinoma' vs 'normal' .foldChange \\\n", + "0 ENSG00000000003 TSPAN6 -1.2 \n", + "1 ENSG00000000005 TNMD -2.4 \n", + "2 ENSG00000000419 DPM1 -1.0 \n", + "3 ENSG00000000457 SCYL3 -2.0 \n", + "4 ENSG00000000460 C1orf112 0.1 \n", + "\n", + " 'breast carcinoma' vs 'normal'.pValue \\\n", + "0 8.524371e-03 \n", + "1 1.890000e-04 \n", + "2 3.210000e-05 \n", + "3 2.440000e-10 \n", + "4 5.262086e-01 \n", + "\n", + " 'colorectal carcinoma' vs 'normal' .foldChange \\\n", + "0 -0.7 \n", + "1 -3.1 \n", + "2 -1.1 \n", + "3 -2.0 \n", + "4 -0.1 \n", + "\n", + " 'colorectal carcinoma' vs 'normal'.pValue \\\n", + "0 1.886303e-01 \n", + "1 9.370000e-07 \n", + "2 4.870000e-05 \n", + "3 4.980000e-10 \n", + "4 7.400732e-01 \n", + "\n", + " 'glioblastoma' vs 'normal' .foldChange 'glioblastoma' vs 'normal'.pValue \\\n", + "0 -1.6 0.000273 \n", + "1 -2.5 0.000044 \n", + "2 -0.9 0.002806 \n", + "3 -1.3 0.000105 \n", + "4 -0.5 0.016092 \n", + "\n", + " 'hepatobiliary carcinoma' vs 'normal' .foldChange \\\n", + "0 -0.9 \n", + "1 -1.0 \n", + "2 -0.3 \n", + "3 -1.6 \n", + "4 0.2 \n", + "\n", + " 'hepatobiliary carcinoma' vs 'normal'.pValue \\\n", + "0 0.144043 \n", + "1 0.193911 \n", + "2 0.410319 \n", + "3 0.000035 \n", + "4 0.366367 \n", + "\n", + " 'non-small cell lung carcinoma' vs 'normal' .foldChange \\\n", + "0 -2.1 \n", + "1 -2.1 \n", + "2 -0.8 \n", + "3 -2.2 \n", + "4 -0.9 \n", + "\n", + " 'non-small cell lung carcinoma' vs 'normal'.pValue \\\n", + "0 3.970000e-07 \n", + "1 8.710000e-05 \n", + "2 4.849082e-03 \n", + "3 1.810000e-11 \n", + "4 1.150000e-05 \n", + "\n", + " 'pancreatic adenocarcinoma' vs 'normal' .foldChange \\\n", + "0 -2.4 \n", + "1 -3.2 \n", + "2 -1.0 \n", + "3 -3.0 \n", + "4 -0.3 \n", + "\n", + " 'pancreatic adenocarcinoma' vs 'normal'.pValue \n", + "0 1.140000e-05 \n", + "1 3.300000e-06 \n", + "2 3.360000e-04 \n", + "3 3.780000e-18 \n", + "4 2.105133e-01 " + ], + "text/html": [ + "\n", + "\n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Gene IDGene Name'breast carcinoma' vs 'normal' .foldChange'breast carcinoma' vs 'normal'.pValue'colorectal carcinoma' vs 'normal' .foldChange'colorectal carcinoma' vs 'normal'.pValue'glioblastoma' vs 'normal' .foldChange'glioblastoma' vs 'normal'.pValue'hepatobiliary carcinoma' vs 'normal' .foldChange'hepatobiliary carcinoma' vs 'normal'.pValue'non-small cell lung carcinoma' vs 'normal' .foldChange'non-small cell lung carcinoma' vs 'normal'.pValue'pancreatic adenocarcinoma' vs 'normal' .foldChange'pancreatic adenocarcinoma' vs 'normal'.pValue
0ENSG00000000003TSPAN6-1.28.524371e-03-0.71.886303e-01-1.60.000273-0.90.144043-2.13.970000e-07-2.41.140000e-05
1ENSG00000000005TNMD-2.41.890000e-04-3.19.370000e-07-2.50.000044-1.00.193911-2.18.710000e-05-3.23.300000e-06
2ENSG00000000419DPM1-1.03.210000e-05-1.14.870000e-05-0.90.002806-0.30.410319-0.84.849082e-03-1.03.360000e-04
3ENSG00000000457SCYL3-2.02.440000e-10-2.04.980000e-10-1.30.000105-1.60.000035-2.21.810000e-11-3.03.780000e-18
4ENSG00000000460C1orf1120.15.262086e-01-0.17.400732e-01-0.50.0160920.20.366367-0.91.150000e-05-0.32.105133e-01
\n", + "
\n", + " \n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + "\n", + "\n", + "\n", + " \n", + "\n", + " \n", + " \n", + "\n", + " \n", + "
\n", + "
\n" + ] + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "df = pd.read_csv(\"https://cytoscape.github.io/cytoscape-tutorials/protocols/data/E-GEOD-68086.csv\")\n", + "df.head()" ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "p4c.set_node_color_mapping(**p4c.gen_node_color_map(\"'breast carcinoma' vs 'normal' .foldChange\", p4c.palette_color_brewer_d_RdBu(), style_name=\"WikiPathways\"))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Data Visualization: Node Border Width\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We also have a significance measure for the fold change, which we can add to our visualization. For this, we will use both Node Border Width and Node Border Size to visualize the p value.\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "''" + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 139 + }, + "id": "vx1dsd4SPZOl", + "outputId": "c211ad16-3851-4341-f28b-57645da12115" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.10/dist-packages/py4cytoscape/tables.py:485: SettingWithCopyWarning: \n", + "A value is trying to be set on a copy of a slice from a DataFrame.\n", + "Try using .loc[row_indexer,col_indexer] = value instead\n", + "\n", + "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", + " data_subset[col] = col_val\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'Success: Data loaded in defaultnode table'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "p4c.load_table_data(df, data_key_column=\"Gene ID\", table_key_column=\"Ensembl\")" ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "p4c.set_node_border_width_mapping(\"'breast carcinoma' vs 'normal'.pValue\",table_column_values=['0', '0.05'], widths=[5, 5], mapping_type='c', style_name='WikiPathways')" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "''" + "cell_type": "markdown", + "metadata": { + "id": "g3J1mZ7fPZOl" + }, + "source": [ + "## Data Visualization: Node Fill Color" ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "p4c.set_node_border_color_default(\"#5A5A5A\", style_name='WikiPathways')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Data Visualization: Node Border Color" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": { + "id": "K7J6jibpPZOl" + }, + "source": [ + "We now have the data in Cytoscape, linked to the pathway, and ready to map to visual properties of the nodes in the network. For this workflow, we will choose data from one of the cancer types, \"breast carcinoma\", and visualize the fold change as Node Fill Color." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "id": "CAyQmEkWPZOl", + "outputId": "2d8d2103-2045-4cd9-d72e-3186eb9eef89" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "''" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "p4c.set_node_color_mapping(**p4c.gen_node_color_map(\"'breast carcinoma' vs 'normal' .foldChange\", p4c.palette_color_brewer_d_RdBu(), style_name=\"WikiPathways\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SfSuVy6OPZOl" + }, + "source": [ + "## Data Visualization: Node Border Width\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ijte9hYCPZOl" + }, + "source": [ + "We also have a significance measure for the fold change, which we can add to our visualization. For this, we will use both Node Border Width and Node Border Size to visualize the p value.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "id": "Dmh3t5YfPZOm", + "outputId": "8f2de882-7763-4fd4-eb29-9ff3a2c25ed5" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "''" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 12 + } + ], + "source": [ + "p4c.set_node_border_width_mapping(\"'breast carcinoma' vs 'normal'.pValue\",table_column_values=['0', '0.05'], widths=[5, 5, 1, 1], mapping_type='c', style_name='WikiPathways')" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "id": "gO3ssHh2PZOm", + "outputId": "36292a95-e65a-4ba2-f268-dd585cfbf998" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "''" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 13 + } + ], + "source": [ + "p4c.set_node_border_color_default(\"#5A5A5A\", style_name='WikiPathways')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XQCq8JbZPZOm" + }, + "source": [ + "## Data Visualization: Node Border Color" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "id": "EiSLF1fYPZOm", + "outputId": "ce1f99cc-c24b-43e2-da43-12dc48eb0207" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "''" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "p4c.set_node_border_color_mapping(\"'breast carcinoma' vs 'normal'.pValue\", ['0', '0.05', '0.05'], ['#FC0FC0', '#FC0FC0', '#5A5A5A'], 'c', style_name='WikiPathways')" + ] + }, { - "data": { - "text/plain": [ - "''" + "cell_type": "markdown", + "metadata": { + "id": "mLjmgleSPZOm" + }, + "source": [ + "We now have our example data visualized on the pathway, with fold change represented as a gradient node fill color and significance as node border color/width.\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CLPLyGi7PZOm" + }, + "source": [ + "## Saving and Exporting Data Visualization" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "0HMyu6OjPZOn" + }, + "outputs": [], + "source": [ + "# Save as session\n", + "# p4c.session.save_session('wikipathway-data-visualization-basic')\n", + "# Export as PDF\n", + "# p4c.export_image('wikipathway-data-visualization-basic', type='PDF')\n", + "\n", + "# Note: PNG, SVG, JPEG and PS are also supported\n", + "# p4c.export_image('differentially-expressed-genes', type='PNG')\n", + "# p4c.export_image('differentially-expressed-genes', type='JPEG')\n", + "# p4c.export_image('differentially-expressed-genes', type='SVG')\n", + "# p4c.export_image('differentially-expressed-genes', type='PS')" ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" } - ], - "source": [ - "p4c.set_node_border_color_mapping(\"'breast carcinoma' vs 'normal'.pValue\", ['0', '0.05', '0.05'], ['#FC0FC0', '#FC0FC0', '#5A5A5A'], 'c', style_name='WikiPathways')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We now have our example data visualized on the pathway, with fold change represented as a gradient node fill color and significance as node border color/width.\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Saving and Exporting Data Visualization" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "# Save as session\n", - "# p4c.session.save_session('wikipathway-data-visualization-basic')\n", - "# Export as PDF\n", - "# p4c.export_image('wikipathway-data-visualization-basic', type='PDF')\n", - "\n", - "# Note: PNG, SVG, JPEG and PS are also supported\n", - "# p4c.export_image('differentially-expressed-genes', type='PNG')\n", - "# p4c.export_image('differentially-expressed-genes', type='JPEG')\n", - "# p4c.export_image('differentially-expressed-genes', type='SVG')\n", - "# p4c.export_image('differentially-expressed-genes', type='PS')" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" + ], + "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.5" + }, + "colab": { + "provenance": [], + "include_colab_link": true + } }, - "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.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file