{ "cells": [ { "cell_type": "markdown", "id": "f2d7b3c9", "metadata": {}, "source": [ "# CARNIVAL\n", "\n", "CARNIVAL (CAusal Reasoning for Network identification using Integer VALue programming) is a method for the identification of upstream reguatory signalling pathways from downstream gene expression (GEX). Applications of CARNIVAL include the identification of drug’s modes of action and of deregulated processes in diseases (even if the molecular targets remain unknown) by deciphering the alterations of main signalling pathways as well as alternative pathways and off-target effects.\n", "\n", "
\n", " \"CARNIVAL\n", "
\n", " \n", " Figure 1: Liu A., Trairatphisan P., Gjerga E. et al. From expression footprints to causal pathways: contextualizing large signaling networks with CARNIVAL npj Systems Biology and Applications volume 5, Article number: 40 (2019) (equal contributions).\n", " \n", "
\n", "\n", "The aim of the CARNIVAL pipeline is to identify a subset of interactions from a prior knowledge network that represent potential regulated pathways linking known or potential targets of perturbation towards active transcription factors derived from GEX data. The pipeline includes a number improved functionalities comparing to the original version and consists of the following processes:\n", "\n", "- Transcription factors’ (TFs) activities and pathway scores from gene expressions can be inferred with our in-house tools (Dorothea, CollecTRI).\n", "- TFs’ activities and signed directed protein-protein interaction networks with or without the provided target of perturbations and pathway scores are then used to construct an optimization problem with CORNETO.\n", "- CORNETO is used to solve the optimization problem with any of the supported solvers (CPLEX, GUROBI, SCIPY, etc), which identifies the sub-network topology with minimised fitting error and model size.\n", "\n", "\n", "\n", "The original version of CARNIVAL was implemented in R and CPLEX. The new re-implementationo of CARNIVAL in CORNETO support a wide variety of solvers thanks to the support of both CVXPY and PICOS. It also has more flexibility since the problem is symbolically defined, and can be modified through the CORNETO API after creating the CARNIVAL problem. This gives user extra flexibility to modify the problem or to use CORNETO as a building block for other optimization problems. " ] }, { "cell_type": "code", "execution_count": 7, "id": "a1684e94", "metadata": {}, "outputs": [ { "data": { "text/html": [], "text/plain": [] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", " \n", "
Installed version:v1.0.0.dev0 (up to date)
Available backends:CVXPY v1.5.1, PICOS v2.4.17
Default backend (corneto.opt):CVXPY
Installed solvers:CLARABEL, CVXOPT, ECOS, ECOS_BB, GLPK, GLPK_MI, GUROBI, OSQP, SCIP, SCIPY, SCS
Graphviz version:v0.20.3
Repository:https://github.com/saezlab/corneto
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import corneto as cn\n", "\n", "cn.info()" ] }, { "cell_type": "markdown", "id": "86e3ce04", "metadata": {}, "source": [ "## A quick example" ] }, { "cell_type": "code", "execution_count": 8, "id": "2a193cb0", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "I1\n", "\n", "I1\n", "\n", "\n", "\n", "N1\n", "\n", "N1\n", "\n", "\n", "\n", "I1->N1\n", "\n", "\n", "\n", "\n", "\n", "M1\n", "\n", "M1\n", "\n", "\n", "\n", "N1->M1\n", "\n", "\n", "\n", "\n", "\n", "M2\n", "\n", "M2\n", "\n", "\n", "\n", "N1->M2\n", "\n", "\n", "\n", "\n", "\n", "I2\n", "\n", "I2\n", "\n", "\n", "\n", "N2\n", "\n", "N2\n", "\n", "\n", "\n", "I2->N2\n", "\n", "\n", "\n", "\n", "\n", "\n", "N2->M1\n", "\n", "\n", "\n", "\n", "\n", "\n", "N2->M2\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G = cn.Graph.from_sif_tuples(\n", " [\n", " (\"I1\", 1, \"N1\"), # I1 activates N1\n", " (\"N1\", 1, \"M1\"), # N1 activates M1\n", " (\"N1\", 1, \"M2\"), # N1 activaes M2\n", " (\"I2\", -1, \"N2\"), # I2 inhibits N2\n", " (\"N2\", -1, \"M2\"), # N2 inhibits M2\n", " (\"N2\", -1, \"M1\"), # N2 inhibits M1\n", " ]\n", ")\n", "G.plot()" ] }, { "cell_type": "code", "execution_count": 9, "id": "176d8ced", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(CORNETO) May 12 11:21:35 AM - INFO : 2/2 inputs mapped to the graph\n", "(CORNETO) May 12 11:21:35 AM - INFO : 2/2 outputs mapped to the graph\n", "(CORNETO) May 12 11:21:35 AM - INFO : Pruning the graph with size: V x E = (6, 6)...\n", "(CORNETO) May 12 11:21:35 AM - INFO : Finished. Final size: V x E = (6, 6).\n", "(CORNETO) May 12 11:21:35 AM - INFO : 2/2 inputs after pruning.\n", "(CORNETO) May 12 11:21:35 AM - INFO : 2/2 outputs after pruning.\n", "(CORNETO) May 12 11:21:35 AM - INFO : Converting into a flow graph...\n", "(CORNETO) May 12 11:21:35 AM - INFO : Creating a network flow problem...\n", "(CORNETO) May 12 11:21:35 AM - INFO : Preprocess completed.\n", "===============================================================================\n", " CVXPY \n", " v1.5.1 \n", "===============================================================================\n", "(CVXPY) May 12 11:21:35 AM: Your problem has 86 variables, 197 constraints, and 0 parameters.\n", "(CVXPY) May 12 11:21:35 AM: It is compliant with the following grammars: DCP, DQCP\n", "(CVXPY) May 12 11:21:35 AM: (If you need to solve this problem multiple times, but with different data, consider using parameters.)\n", "(CVXPY) May 12 11:21:35 AM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution.\n", "(CVXPY) May 12 11:21:35 AM: Your problem is compiled with the CPP canonicalization backend.\n", "-------------------------------------------------------------------------------\n", " Compilation \n", "-------------------------------------------------------------------------------\n", "(CVXPY) May 12 11:21:35 AM: Compiling problem (target solver=GUROBI).\n", "(CVXPY) May 12 11:21:35 AM: Reduction chain: CvxAttr2Constr -> Qp2SymbolicQp -> QpMatrixStuffing -> GUROBI\n", "(CVXPY) May 12 11:21:35 AM: Applying reduction CvxAttr2Constr\n", "(CVXPY) May 12 11:21:35 AM: Applying reduction Qp2SymbolicQp\n", "(CVXPY) May 12 11:21:35 AM: Applying reduction QpMatrixStuffing\n", "(CVXPY) May 12 11:21:35 AM: Applying reduction GUROBI\n", "(CVXPY) May 12 11:21:35 AM: Finished problem compilation (took 1.125e-01 seconds).\n", "-------------------------------------------------------------------------------\n", " Numerical solver \n", "-------------------------------------------------------------------------------\n", "(CVXPY) May 12 11:21:35 AM: Invoking solver GUROBI to obtain a solution.\n", "Set parameter QCPDual to value 1\n", "Gurobi Optimizer version 11.0.1 build v11.0.1rc0 (win64 - Windows 11.0 (22631.2))\n", "\n", "CPU model: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz, instruction set [SSE2|AVX|AVX2|AVX512]\n", "Thread count: 4 physical cores, 8 logical processors, using up to 8 threads\n", "\n", "Optimize a model with 197 rows, 86 columns and 397 nonzeros\n", "Model fingerprint: 0x86a2333f\n", "Variable types: 24 continuous, 62 integer (62 binary)\n", "Coefficient statistics:\n", " Matrix range [1e-03, 1e+01]\n", " Objective range [1e-01, 1e+00]\n", " Bounds range [1e+00, 1e+00]\n", " RHS range [1e-03, 1e+01]\n", "Found heuristic solution: objective 0.1000000\n", "Presolve removed 158 rows and 60 columns\n", "Presolve time: 0.00s\n", "Presolved: 39 rows, 26 columns, 92 nonzeros\n", "Variable types: 7 continuous, 19 integer (19 binary)\n", "Found heuristic solution: objective -0.7000000\n", "\n", "Root relaxation: objective -3.300000e+00, 20 iterations, 0.00 seconds (0.00 work units)\n", "\n", " Nodes | Current Node | Objective Bounds | Work\n", " Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time\n", "\n", "H 0 0 -3.3000000 -3.50000 6.06% - 0s\n", " 0 0 -3.30000 0 10 -3.30000 -3.30000 0.00% - 0s\n", "\n", "Explored 1 nodes (20 simplex iterations) in 0.04 seconds (0.00 work units)\n", "Thread count was 8 (of 8 available processors)\n", "\n", "Solution count 3: -3.3 -0.7 0.1 \n", "No other solutions better than -3.3\n", "\n", "Optimal solution found (tolerance 1.00e-04)\n", "Best objective -3.300000000000e+00, best bound -3.300000000000e+00, gap 0.0000%\n", "-------------------------------------------------------------------------------\n", " Summary \n", "-------------------------------------------------------------------------------\n", "(CVXPY) May 12 11:21:35 AM: Problem status: optimal\n", "(CVXPY) May 12 11:21:35 AM: Optimal value: 7.000e-01\n", "(CVXPY) May 12 11:21:35 AM: Compilation took 1.125e-01 seconds\n", "(CVXPY) May 12 11:21:35 AM: Solver (including time spent in interface) took 8.493e-02 seconds\n", "(CORNETO) May 12 11:21:35 AM - INFO : Finished in 0.32 s.\n" ] } ], "source": [ "from corneto.methods import runVanillaCarnival\n", "\n", "# These are the measurements (e.g. TF activity from Decoupler).\n", "# Positive values correspond to up-regulation and negative values\n", "# with down-regulation. The bigger the absolute value is,\n", "# the bigger the importance is\n", "measurements = {\"M1\": 1, \"M2\": 1}\n", "\n", "# Perturbations are the upstream nodes were the signal originates on,\n", "# for example, ligands or receptors.\n", "perturbations = {\"I1\": 1, \"I2\": 1}\n", "\n", "# We run the `standard` carnival problem. This interface is similar\n", "# to the old R function https://saezlab.github.io/CARNIVAL/reference/runVanillaCarnival.html\n", "P, Gf = runVanillaCarnival(perturbations, measurements, G, betaWeight=0.1)" ] }, { "cell_type": "markdown", "id": "079c99ed", "metadata": {}, "source": [ "The carnival problem has two objectives `P.objectives`:\n", "- `P.objectives[0]`: the error of fitting the measurements (Transcription Factors)\n", "- `P.objectives[1]`: the size of the network" ] }, { "cell_type": "code", "execution_count": 10, "id": "8b03e08d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We can check the error. Values larger than 0 indicate that\n", "# some TF or measurement was not selected.\n", "P.objectives[0].value" ] }, { "cell_type": "code", "execution_count": 11, "id": "00d86874", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'reaction_sends_activation_c0': Variable((14,), reaction_sends_activation_c0, boolean=True),\n", " '_flow': Variable((14,), _flow),\n", " '_flow_ipos': Variable((14,), _flow_ipos, boolean=True),\n", " 'species_inhibited_c0': Variable((10,), species_inhibited_c0, boolean=True),\n", " 'reaction_sends_inhibition_c0': Variable((14,), reaction_sends_inhibition_c0, boolean=True),\n", " 'species_activated_c0': Variable((10,), species_activated_c0, boolean=True),\n", " 'dag_layer_position_c0': Variable((10,), dag_layer_position_c0),\n", " 'flow': Variable((14,), _flow),\n", " 'edge_values_c0': Expression(AFFINE, UNKNOWN, (14,)),\n", " 'vertex_values_c0': Expression(AFFINE, UNKNOWN, (10,))}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Variables that are defined by CARNIVAL\n", "P.expr" ] }, { "cell_type": "code", "execution_count": 12, "id": "a1b0e7ec", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning: node '_pert_c0', graph '%3' size too small for label\n", "Warning: node '_meas_c0', graph '%3' size too small for label\n", "Warning: node '_pert_c0', graph '%3' size too small for label\n", "Warning: node '_meas_c0', graph '%3' size too small for label\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "I1\n", "\n", "I1\n", "\n", "\n", "\n", "N1\n", "\n", "N1\n", "\n", "\n", "\n", "I1->N1\n", "\n", "\n", "\n", "\n", "\n", "M1\n", "\n", "M1\n", "\n", "\n", "\n", "N1->M1\n", "\n", "\n", "\n", "\n", "\n", "M2\n", "\n", "M2\n", "\n", "\n", "\n", "N1->M2\n", "\n", "\n", "\n", "\n", "\n", "_meas_c0\n", "\n", "_meas_c0\n", "\n", "\n", "\n", "M1->_meas_c0\n", "\n", "\n", "\n", "\n", "\n", "M2->_meas_c0\n", "\n", "\n", "\n", "\n", "\n", "I2\n", "\n", "I2\n", "\n", "\n", "\n", "N2\n", "\n", "N2\n", "\n", "\n", "\n", "I2->N2\n", "\n", "\n", "\n", "\n", "\n", "\n", "N2->M1\n", "\n", "\n", "\n", "\n", "\n", "\n", "N2->M2\n", "\n", "\n", "\n", "\n", "\n", "\n", "_s\n", "\n", "_s\n", "\n", "\n", "\n", "_pert_c0\n", "\n", "_pert_c0\n", "\n", "\n", "\n", "_s->_pert_c0\n", "\n", "\n", "\n", "\n", "\n", "_pert_c0->I1\n", "\n", "\n", "\n", "\n", "\n", "_pert_c0->I2\n", "\n", "\n", "\n", "\n", "\n", "_t\n", "\n", "_t\n", "\n", "\n", "\n", "_meas_c0->_t\n", "\n", "\n", "\n", "\n", "\n", "e_13_target\n", "\n", "\n", "\n", "\n", "_t->e_13_target\n", "\n", "\n", "\n", "\n", "\n", "e_12_source\n", "\n", "\n", "\n", "\n", "e_12_source->_s\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Gf.plot_values(vertex_values=P.expr.vertex_values_c0, edge_values=P.expr.edge_values_c0)" ] }, { "cell_type": "code", "execution_count": 13, "id": "c8be26ab", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "I1\n", "\n", "I1\n", "\n", "\n", "\n", "N1\n", "\n", "N1\n", "\n", "\n", "\n", "I1->N1\n", "\n", "\n", "\n", "\n", "\n", "M1\n", "\n", "M1\n", "\n", "\n", "\n", "N1->M1\n", "\n", "\n", "\n", "\n", "\n", "M2\n", "\n", "M2\n", "\n", "\n", "\n", "N1->M2\n", "\n", "\n", "\n", "\n", "\n", "I2\n", "\n", "I2\n", "\n", "\n", "\n", "N2\n", "\n", "N2\n", "\n", "\n", "\n", "I2->N2\n", "\n", "\n", "\n", "\n", "\n", "\n", "N2->M1\n", "\n", "\n", "\n", "\n", "\n", "\n", "N2->M2\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G.plot(\n", " custom_edge_attr=cn.pl.edge_style(P, edge_var=\"edge_values_c0\"),\n", " custom_vertex_attr=cn.pl.vertex_style(P, Gf, vertex_var=\"vertex_values_c0\"),\n", ")" ] }, { "cell_type": "code", "execution_count": 14, "id": "a7b0d803", "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", " \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", "
Vvalue
0N2-1.0
1M21.0
2I11.0
3N10.0
4M11.0
5I21.0
6_s1.0
7_pert_c01.0
8_meas_c00.0
9_t0.0
\n", "
" ], "text/plain": [ " V value\n", "0 N2 -1.0\n", "1 M2 1.0\n", "2 I1 1.0\n", "3 N1 0.0\n", "4 M1 1.0\n", "5 I2 1.0\n", "6 _s 1.0\n", "7 _pert_c0 1.0\n", "8 _meas_c0 0.0\n", "9 _t 0.0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "from corneto.methods.carnival import get_result, get_selected_edges\n", "\n", "V, E = get_result(P, Gf)\n", "pd.DataFrame(V)" ] }, { "cell_type": "code", "execution_count": 15, "id": "7ff44c27", "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", " \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", "
Evalue
0((I1), (N1))0.0
1((N1), (M1))0.0
2((N1), (M2))0.0
3((I2), (N2))-1.0
4((N2), (M2))1.0
5((N2), (M1))1.0
6((_s), (_pert_c0))1.0
7((_pert_c0), (I1))1.0
8((_pert_c0), (I2))1.0
9((M1), (_meas_c0))1.0
10((M2), (_meas_c0))1.0
11((_meas_c0), (_t))0.0
12((), (_s))1.0
13((_t), ())0.0
\n", "
" ], "text/plain": [ " E value\n", "0 ((I1), (N1)) 0.0\n", "1 ((N1), (M1)) 0.0\n", "2 ((N1), (M2)) 0.0\n", "3 ((I2), (N2)) -1.0\n", "4 ((N2), (M2)) 1.0\n", "5 ((N2), (M1)) 1.0\n", "6 ((_s), (_pert_c0)) 1.0\n", "7 ((_pert_c0), (I1)) 1.0\n", "8 ((_pert_c0), (I2)) 1.0\n", "9 ((M1), (_meas_c0)) 1.0\n", "10 ((M2), (_meas_c0)) 1.0\n", "11 ((_meas_c0), (_t)) 0.0\n", "12 ((), (_s)) 1.0\n", "13 ((_t), ()) 0.0" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.DataFrame(E)" ] }, { "cell_type": "code", "execution_count": 16, "id": "548f868d", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "I2\n", "\n", "I2\n", "\n", "\n", "\n", "N2\n", "\n", "N2\n", "\n", "\n", "\n", "I2->N2\n", "\n", "\n", "\n", "\n", "\n", "\n", "M2\n", "\n", "M2\n", "\n", "\n", "\n", "N2->M2\n", "\n", "\n", "\n", "\n", "\n", "\n", "M1\n", "\n", "M1\n", "\n", "\n", "\n", "N2->M1\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G_sol = Gf.edge_subgraph(get_selected_edges(P, Gf))\n", "G_sol.plot()" ] }, { "cell_type": "markdown", "id": "f32c2cd7", "metadata": {}, "source": [ "## Fast carnival\n", "\n", "For larger problems, and when a fast solver is not available, we provide a heuristic version of CARNIVAL that uses a greedy algorithm to solve the problem faster. However, solutions are not optimal and the final size of the networks cannot be controlled, but provides a good approximation of the optimal solution." ] }, { "cell_type": "code", "execution_count": 17, "id": "ac0d1daa", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(4931, 13157)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from corneto.methods import fast_carnival\n", "from corneto.methods.carnival import read_dataset\n", "\n", "G, dict_data = read_dataset(\"carnival_example.zip\")\n", "G.shape" ] }, { "cell_type": "code", "execution_count": 18, "id": "0ae90239", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'EGFR': ('P', -1),\n", " 'AEBP1': ('M', -1),\n", " 'CREB3': ('M', 1),\n", " 'EGR3': ('M', -1),\n", " 'ELK1': ('M', -1),\n", " 'FOSL2': ('M', -1),\n", " 'FOXA3': ('M', 1),\n", " 'FOXE1': ('M', 1),\n", " 'HIPK2': ('M', 1),\n", " 'HOXA2': ('M', 1),\n", " 'HOXB7': ('M', -1),\n", " 'HOXD3': ('M', 1),\n", " 'KDM5C': ('M', -1),\n", " 'KDM5D': ('M', 1),\n", " 'KLF2': ('M', -1),\n", " 'NEUROD1': ('M', -1),\n", " 'NFATC4': ('M', -1),\n", " 'NFYB': ('M', -1),\n", " 'NHLH2': ('M', 1),\n", " 'PLAGL2': ('M', -1),\n", " 'RUNX2': ('M', -1),\n", " 'SIRT1': ('M', 1),\n", " 'SUPT20H': ('M', 1),\n", " 'TBX20': ('M', -1),\n", " 'TET1': ('M', 1),\n", " 'ZBTB4': ('M', -1)}" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dict_data" ] }, { "cell_type": "code", "execution_count": 19, "id": "0ad5157f", "metadata": {}, "outputs": [], "source": [ "c_inputs = {k: v[1] for k, v in dict_data.items() if v[0] == \"P\"}\n", "c_outputs = {k: v[1] for k, v in dict_data.items() if v[0] == \"M\"}" ] }, { "cell_type": "code", "execution_count": 20, "id": "437b70c6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1/1 inputs mapped to the graph\n", "16/25 outputs mapped to the graph\n", "Pruning the graph with size: V x E = (4931, 13157)...\n", "Finished. Final size: V x E = (1182, 5789).\n", "HOXB7 (L4), ZBTB4 (L4), ELK1 (L3), NFYB (L3), RUNX2 (L3), HIPK2 (L3), SIRT1 (L3), NEUROD1 (L4), AEBP1 (L3), NFATC4 (L3)\n", "L1 : 1 iters, 0.00 s.\n", "L2 : 41 iters, 0.01 s.\n", " > -EGFR -> +CRK -> +MAPK8 -> +SIRT1\n", " > -EGFR -> +CRK -> +MAPK8 -> -NFATC4\n", " > -EGFR -> -PTPN1 -> +ABL1 -> +HIPK2\n", " > -EGFR -> -PRKDC -> -MAPK8 -> -ELK1\n", " ! conflict: -EGFR/-MAPK8 != -EGFR/+MAPK8\n", " > -EGFR -> -MAP2K1 -> -MAPK1 -> -ELK1\n", " > -EGFR -> -MAP2K1 -> -MAPK1 -> -AEBP1\n", " > -EGFR -> -MAP2K1 -> -MAPK3 -> -RUNX2\n", "L3 : 316 iters, 0.11 s.\n", " > -EGFR -> -STAT1 -> +CREBBP -> ... -> -NFYB\n", " > -EGFR -> -PIK3R1 -> -RAC1 -> ... -> -NEUROD1\n", " > -EGFR -> -PTPN1 -> +ABL1 -> ... -> -ZBTB4\n", " > -EGFR -> -ERBB2 -> +CDK1 -> ... -> -HOXB7\n", "Finished (0.61 s)\n", " > Number of selected edges: 26\n", " > Total iterations: 2287\n", " > Detected loops: 255\n", " > Conflicts: 1\n", "Total error: 15\n", "Number of selected edges: 26\n" ] } ], "source": [ "Gc, selected_edges, paths, stats, errors = fast_carnival(\n", " G, c_inputs, c_outputs, restricted_search=False\n", ")" ] }, { "cell_type": "code", "execution_count": 21, "id": "5288e16b", "metadata": {}, "outputs": [], "source": [ "node_values = {}\n", "for p in paths:\n", " for k, v in p[1].items():\n", " node_values[k] = v[1]\n", "\n", "G_sol = Gc.edge_subgraph(selected_edges)\n", "\n", "V = G_sol.V\n", "vertex_values = [node_values.get(v, 0) for v in V]" ] }, { "cell_type": "code", "execution_count": 22, "id": "88af4853", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'AEBP1': 0,\n", " 'CREB3': 1,\n", " 'EGR3': 1,\n", " 'ELK1': 0,\n", " 'FOSL2': 1,\n", " 'FOXA3': 1,\n", " 'FOXE1': 1,\n", " 'HIPK2': 0,\n", " 'HOXA2': 1,\n", " 'HOXB7': 0,\n", " 'HOXD3': 1,\n", " 'KDM5C': 1,\n", " 'KDM5D': 1,\n", " 'KLF2': 1,\n", " 'NEUROD1': 0,\n", " 'NFATC4': 0,\n", " 'NFYB': 0,\n", " 'NHLH2': 1,\n", " 'PLAGL2': 1,\n", " 'RUNX2': 0,\n", " 'SIRT1': 0,\n", " 'SUPT20H': 1,\n", " 'TBX20': 1,\n", " 'TET1': 1,\n", " 'ZBTB4': 0}" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "errors" ] }, { "cell_type": "code", "execution_count": 24, "id": "8410ac74", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning: node 'EGFR', graph '%3' size too small for label\n", "Warning: node 'STAT1', graph '%3' size too small for label\n", "Warning: node 'MAPK8', graph '%3' size too small for label\n", "Warning: node 'SIRT1', graph '%3' size too small for label\n", "Warning: node 'ERBB2', graph '%3' size too small for label\n", "Warning: node 'MAP2K1', graph '%3' size too small for label\n", "Warning: node 'MAPK1', graph '%3' size too small for label\n", "Warning: node 'CREBBP', graph '%3' size too small for label\n", "Warning: node 'CSNK2A1', graph '%3' size too small for label\n", "Warning: node 'HOXB7', graph '%3' size too small for label\n", "Warning: node 'HIPK2', graph '%3' size too small for label\n", "Warning: node 'PIK3R1', graph '%3' size too small for label\n", "Warning: node 'MAPK3', graph '%3' size too small for label\n", "Warning: node 'RUNX2', graph '%3' size too small for label\n", "Warning: node 'ZBTB4', graph '%3' size too small for label\n", "Warning: node 'AEBP1', graph '%3' size too small for label\n", "Warning: node 'PTPN1', graph '%3' size too small for label\n", "Warning: node 'NFYB', graph '%3' size too small for label\n", "Warning: node 'MAP3K10', graph '%3' size too small for label\n", "Warning: node 'NFATC4', graph '%3' size too small for label\n", "Warning: node 'NEUROD1', graph '%3' size too small for label\n", "Warning: node 'EGFR', graph '%3' size too small for label\n", "Warning: node 'STAT1', graph '%3' size too small for label\n", "Warning: node 'MAPK8', graph '%3' size too small for label\n", "Warning: node 'SIRT1', graph '%3' size too small for label\n", "Warning: node 'ERBB2', graph '%3' size too small for label\n", "Warning: node 'MAP2K1', graph '%3' size too small for label\n", "Warning: node 'MAPK1', graph '%3' size too small for label\n", "Warning: node 'CREBBP', graph '%3' size too small for label\n", "Warning: node 'CSNK2A1', graph '%3' size too small for label\n", "Warning: node 'HOXB7', graph '%3' size too small for label\n", "Warning: node 'HIPK2', graph '%3' size too small for label\n", "Warning: node 'PIK3R1', graph '%3' size too small for label\n", "Warning: node 'MAPK3', graph '%3' size too small for label\n", "Warning: node 'RUNX2', graph '%3' size too small for label\n", "Warning: node 'ZBTB4', graph '%3' size too small for label\n", "Warning: node 'AEBP1', graph '%3' size too small for label\n", "Warning: node 'PTPN1', graph '%3' size too small for label\n", "Warning: node 'NFYB', graph '%3' size too small for label\n", "Warning: node 'MAP3K10', graph '%3' size too small for label\n", "Warning: node 'NFATC4', graph '%3' size too small for label\n", "Warning: node 'NEUROD1', graph '%3' size too small for label\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "EGFR\n", "\n", "EGFR\n", "\n", "\n", "\n", "STAT1\n", "\n", "STAT1\n", "\n", "\n", "\n", "EGFR->STAT1\n", "\n", "\n", "\n", "\n", "\n", "ERBB2\n", "\n", "ERBB2\n", "\n", "\n", "\n", "EGFR->ERBB2\n", "\n", "\n", "\n", "\n", "\n", "MAP2K1\n", "\n", "MAP2K1\n", "\n", "\n", "\n", "EGFR->MAP2K1\n", "\n", "\n", "\n", "\n", "\n", "PIK3R1\n", "\n", "PIK3R1\n", "\n", "\n", "\n", "EGFR->PIK3R1\n", "\n", "\n", "\n", "\n", "\n", "CRK\n", "\n", "CRK\n", "\n", "\n", "\n", "EGFR->CRK\n", "\n", "\n", "\n", "\n", "\n", "\n", "PTPN1\n", "\n", "PTPN1\n", "\n", "\n", "\n", "EGFR->PTPN1\n", "\n", "\n", "\n", "\n", "\n", "CREBBP\n", "\n", "CREBBP\n", "\n", "\n", "\n", "STAT1->CREBBP\n", "\n", "\n", "\n", "\n", "\n", "\n", "MAPK8\n", "\n", "MAPK8\n", "\n", "\n", "\n", "SIRT1\n", "\n", "SIRT1\n", "\n", "\n", "\n", "MAPK8->SIRT1\n", "\n", "\n", "\n", "\n", "\n", "NFATC4\n", "\n", "NFATC4\n", "\n", "\n", "\n", "MAPK8->NFATC4\n", "\n", "\n", "\n", "\n", "\n", "\n", "CDK1\n", "\n", "CDK1\n", "\n", "\n", "\n", "ERBB2->CDK1\n", "\n", "\n", "\n", "\n", "\n", "\n", "MAPK1\n", "\n", "MAPK1\n", "\n", "\n", "\n", "MAP2K1->MAPK1\n", "\n", "\n", "\n", "\n", "\n", "MAPK3\n", "\n", "MAPK3\n", "\n", "\n", "\n", "MAP2K1->MAPK3\n", "\n", "\n", "\n", "\n", "\n", "ELK1\n", "\n", "ELK1\n", "\n", "\n", "\n", "MAPK1->ELK1\n", "\n", "\n", "\n", "\n", "\n", "AEBP1\n", "\n", "AEBP1\n", "\n", "\n", "\n", "MAPK1->AEBP1\n", "\n", "\n", "\n", "\n", "\n", "TP53\n", "\n", "TP53\n", "\n", "\n", "\n", "CREBBP->TP53\n", "\n", "\n", "\n", "\n", "\n", "CSNK2A1\n", "\n", "CSNK2A1\n", "\n", "\n", "\n", "HOXB7\n", "\n", "HOXB7\n", "\n", "\n", "\n", "CSNK2A1->HOXB7\n", "\n", "\n", "\n", "\n", "\n", "\n", "ABL1\n", "\n", "ABL1\n", "\n", "\n", "\n", "HIPK2\n", "\n", "HIPK2\n", "\n", "\n", "\n", "ABL1->HIPK2\n", "\n", "\n", "\n", "\n", "\n", "ZBTB4\n", "\n", "ZBTB4\n", "\n", "\n", "\n", "HIPK2->ZBTB4\n", "\n", "\n", "\n", "\n", "\n", "\n", "RAC1\n", "\n", "RAC1\n", "\n", "\n", "\n", "PIK3R1->RAC1\n", "\n", "\n", "\n", "\n", "\n", "MAP3K10\n", "\n", "MAP3K10\n", "\n", "\n", "\n", "RAC1->MAP3K10\n", "\n", "\n", "\n", "\n", "\n", "RUNX2\n", "\n", "RUNX2\n", "\n", "\n", "\n", "MAPK3->RUNX2\n", "\n", "\n", "\n", "\n", "\n", "CRK->MAPK8\n", "\n", "\n", "\n", "\n", "\n", "PTPN1->ABL1\n", "\n", "\n", "\n", "\n", "\n", "\n", "NFYB\n", "\n", "NFYB\n", "\n", "\n", "\n", "TP53->NFYB\n", "\n", "\n", "\n", "\n", "\n", "\n", "CDK1->CSNK2A1\n", "\n", "\n", "\n", "\n", "\n", "NEUROD1\n", "\n", "NEUROD1\n", "\n", "\n", "\n", "MAP3K10->NEUROD1\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G_sol.plot_values(vertex_values=vertex_values)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.13" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }