{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Reading and Writing Boolean-Based Models" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Cell Collective](https://cellcollective.org) supports reading models in [SBML qual](http://www.colomoto.org/formats/sbml-qual.html) file format and exporting them into SBML qual, Boolean Expressions, Truth Tables, Interaction Matrix and GML Expressions.\n", "\n", "**ccapi** also ships with some test models.\n", "\n", "Let's try importing the [Signal Transduction in Fibroblasts](https://research.cellcollective.org/?dashboard=true#1557:1/signal-transduction-in-fibroblasts/1) model.\n", "\n", "![](../data/images/signal-transduction-in-fibroblasts.png)\n", "\n", "Begin by importing the ccapi module into your workspace." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ccapi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, let’s try creating a client object in order to interact with services provided by [Cell Collective](https://cellcollective.org)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "client = ccapi.Client()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Authenticate your client using a ***password flow type authentication*** scheme.\n", "\n", "**NOTE**: *Before you can authenticate using ccapi, you must first register an application of the appropriate type on [Cell Collective](https://cellcollective.org). If you do not require a user context, it is read only.*" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "client.auth(email = \"test@cellcollective.org\", password = \"test\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also view user details of your authenticated client as follows:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "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", " ID\n", " \n", " \n", " 10887\n", "
\n", " \n", " Name\n", " \n", " \n", " Achilles Test\n", "
\n", " \n", " Memory Address\n", " \n", " \n", " 0x07f08117ef588\n", "
\n", " \n", " First Name\n", " \n", " \n", " Achilles\n", "
\n", " \n", " Last Name\n", " \n", " \n", " Test\n", "
\n", " \n", " Email Address\n", " \n", " \n", " test@cellcollective.org\n", "
\n", " \n", " Institution\n", " \n", " \n", " University of Nebraska-Lincoln\n", "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "user = client.me()\n", "user" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### SBML" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The [Systems Biology Markup Language](http://sbml.org/Main_Page) is an XML-based standard format for distributing models. Reading SBML files is as easy as using the `read` function provided by the client object.\n", "\n", "**ccapi** comes shipped with test models for testing purposes." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "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", " ID\n", " \n", " \n", " 90999\n", "
\n", " \n", " Name\n", " \n", " \n", " Unnamed Model\n", "
\n", " \n", " Memory Address\n", " \n", " \n", " 0x07f08117ef128\n", "
\n", " \n", " Number of Versions\n", " \n", " \n", " 1\n", "
\n", " \n", " Versions\n", " \n", " \n", " [<BooleanModel 90999 at 0x07f08101a8898>]\n", "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model = ccapi.load_model(\"fibroblasts\", client = client)\n", "model.save()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cell Collective has a native support for reading and writing in SBML qual." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "scrolled": true }, "outputs": [ { "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", " ID\n", " \n", " \n", " 90999\n", "
\n", " \n", " Version\n", " \n", " \n", " 1\n", "
\n", " \n", " Name\n", " \n", " \n", " \n", "
\n", " \n", " Memory Address\n", " \n", " \n", " 0x07f08101a8898\n", "
\n", " \n", " Number of Components\n", " \n", " \n", " 139\n", "
\n", " \n", " Components\n", " \n", " \n", " ExtPump, alpha_1213L, alpha_iL, alpha_sL, alpha_qL, IL1_TNF, ECM, Stress, EGF, Palpha_iR, Cbp, EGFR, PIP2_45, TAK1, Ga_1213, Ras, alpha_qR, ARF, PTPPEST, Talin, p38, Raf, Akt, PLC_g, Mekk4, PLD, p115RhoGEF, Graf, AC, TAO_12, PKC_primed, ASK1, PAK, IP3, DAG, Raf_Loc, Erk, Tiam, PIP2_34, RhoK, Cas, PTPa, Crk, MKK3, Shc, SHP2, Mekk2, cAMP, Sos, Gbg_1213, Raf_Rest, PI4K, PKC, alpha_sR, Csk, Sek1, MLK1, PDE4, PLA2, Ral, RasGRF_GRP, AND_34, PTP1b, DOCK180, NIK, Pix_Cool, B_Parvin, RKIP, WASP, MKK6, Cdc42, MKK7, PIP3_345, GRK, MLK3, Actin, Fak, Ca, B_Arrestin, Gbg_q, alpha_1213R, CaM, Arp_23, Gas, Gbg_i, Palpha_qR, RGS, p120RasGAP, Mekk1, PDK1, PA, Trafs, PKA, RalGDS, SAPK, Gab1, IP3R1, AA, PI3K, p90RSK, PLC_B, p190RhoGAP, Grb2, MLCP, RalBP1, Mekk3, PTEN, PIP_4, Myosin, Gai, Palpha_sR, ILK, Integrins, Mek, CaMKK, Vinc, Nck, IL1_TNFR, RhoGDI, MKPs, MLK2, Rac, DGK, PI5K, alpha_iR, Src, Palpha_1213R, Tab_12, Tpl2, Gaq, Rho, MLCK, PP2A, CaMK, Rap1, Raf_DeP, GCK, Trx, Gbg_s\n", "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boolean = model.default_version\n", "boolean" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Visualize a Boolean Model using the `draw` function provided." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Writing Models" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Boolean-Based Models can be exported into the following formats.\n", "\n", "1. SBML\n", "2. Boolean Expressions\n", "3. Truth Tables\n", "4. Interaction Matrix\n", "5. GML\n", "\n", "Exporting Boolean-Based Models can be done using **ccapi** using the `Boolean.write` function with the file type as the parameter. By default, `Boolean.write` exports a model into SBML qual format. A list of other formats can be found from `ccapi.constant.BOOLEAN_MODEL_EXPORT_TYPE`. You can also pass the path to where it should be downloaded." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['sbml', 'tt', 'expr', 'matrix', 'gml']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from ccapi._compat import iterkeys\n", "list(iterkeys(ccapi.constant.BOOLEAN_MODEL_EXPORT_TYPE))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### SBML" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the `sbml` type to download a `BooleanModel` into an SBML qual file format." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "'_data/model/boolean/90999/1.sbml'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boolean.write(\"_data/model/boolean/%s/%s.sbml\" % (boolean.id, boolean.version), type = \"sbml\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Boolean Expressions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the type `expr` to export a `BooleanModel` containing Boolean Expressions for all components." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'_data/model/boolean/90999/1.expr.zip'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boolean.write(\"_data/model/boolean/%s/%s.expr.zip\" % (boolean.id, boolean.version), type = \"expr\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Truth Tables" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the type `tt` to export a `BooleanModel` containing Truth Tables." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'_data/model/boolean/90999/1.tt.zip'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boolean.write(\"_data/model/boolean/%s/%s.tt.zip\" % (boolean.id, boolean.version), type = \"tt\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Interaction Matrix" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the type `matrix` to export a `BooleanModel` containing Interaction Matrices." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'_data/model/boolean/90999/1.matrix.zip'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boolean.write(\"_data/model/boolean/%s/%s.matrix.zip\" % (boolean.id, boolean.version), type = \"matrix\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### GML" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the type `gml` to export a `BooleanModel` containing GML." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'_data/model/boolean/90999/1.gml.zip'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boolean.write(\"_data/model/boolean/%s/%s.gml.zip\" % (boolean.id, boolean.version), type = \"gml\")" ] } ], "metadata": { "file_extension": ".py", "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.6.9" }, "mimetype": "text/x-python", "name": "python", "npconvert_exporter": "python", "pygments_lexer": "ipython3", "version": 3 }, "nbformat": 4, "nbformat_minor": 2 }