{
"cells": [
{
"cell_type": "markdown",
"id": "943eec30-eca9-499a-9262-e215ca349f64",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Single sample intracellular signalling network inference\n",
"\n",
"In this notebook we showcase how to use the advanced CARNIVAL implementation available in CORNETO. This implementation extends the capabilities of the original CARNIVAL method by enabling advanced modelling and injection of knowledge for hypothesis generation. We will use a dataset consisting of 6 samples of hepatic stellate cells (HSC) where three of them were activated by the cytokine Transforming growth factor (TGF-β). \n",
"\n",
"In the first part, we will show how to estimate Transcription Factor activities from gene expression data, following the [Decoupler tutorial](https://decoupler-py.readthedocs.io/en/latest/notebooks/bulk.html) for functional analysis. Then, we will use the CARNIVAL method available in CORNETO to infer a network from TFs to receptors, assuming that we don't really know which treatment was used."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "95502198-c8a0-4d71-a5e9-709bad72ec00",
"metadata": {},
"outputs": [],
"source": [
"# --- Saezlab tools ---\n",
"# https://decoupler-py.readthedocs.io/\n",
"import gzip\n",
"import os\n",
"import shutil\n",
"import tempfile\n",
"import urllib.request\n",
"\n",
"import decoupler as dc\n",
"import numpy as np\n",
"\n",
"# https://omnipathdb.org/\n",
"import omnipath as op\n",
"\n",
"# Additional packages\n",
"import pandas as pd\n",
"\n",
"# --- Additional libs ---\n",
"# Pydeseq for differential expression analysis\n",
"from pydeseq2.dds import DefaultInference, DeseqDataSet\n",
"from pydeseq2.ds import DeseqStats\n",
"\n",
"# https://saezlab.github.io/\n",
"import corneto as cn"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5bb37ac8-1631-4cae-a462-c23ff2ae8171",
"metadata": {},
"outputs": [],
"source": [
"max_time = 300\n",
"seed = 0"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "04892cd1-a822-4cfb-ba15-29c647928f92",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
GeneName
\n",
"
DDX11L1
\n",
"
WASH7P
\n",
"
MIR6859-1
\n",
"
MIR1302-11
\n",
"
MIR1302-9
\n",
"
FAM138A
\n",
"
OR4G4P
\n",
"
OR4G11P
\n",
"
OR4F5
\n",
"
RP11-34P13.7
\n",
"
...
\n",
"
MT-ND4
\n",
"
MT-TH
\n",
"
MT-TS2
\n",
"
MT-TL2
\n",
"
MT-ND5
\n",
"
MT-ND6
\n",
"
MT-TE
\n",
"
MT-CYB
\n",
"
MT-TT
\n",
"
MT-TP
\n",
"
\n",
" \n",
" \n",
"
\n",
"
25_HSCs-Ctrl1
\n",
"
0
\n",
"
9
\n",
"
10
\n",
"
1
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
33
\n",
"
...
\n",
"
93192
\n",
"
342
\n",
"
476
\n",
"
493
\n",
"
54466
\n",
"
17184
\n",
"
1302
\n",
"
54099
\n",
"
258
\n",
"
475
\n",
"
\n",
"
\n",
"
26_HSCs-Ctrl2
\n",
"
0
\n",
"
12
\n",
"
14
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
66
\n",
"
...
\n",
"
114914
\n",
"
355
\n",
"
388
\n",
"
436
\n",
"
64698
\n",
"
21106
\n",
"
1492
\n",
"
62679
\n",
"
253
\n",
"
396
\n",
"
\n",
"
\n",
"
27_HSCs-Ctrl3
\n",
"
0
\n",
"
14
\n",
"
10
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
52
\n",
"
...
\n",
"
155365
\n",
"
377
\n",
"
438
\n",
"
480
\n",
"
85650
\n",
"
31860
\n",
"
2033
\n",
"
89559
\n",
"
282
\n",
"
448
\n",
"
\n",
"
\n",
"
31_HSCs-TGFb1
\n",
"
0
\n",
"
11
\n",
"
16
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
54
\n",
"
...
\n",
"
110866
\n",
"
373
\n",
"
441
\n",
"
481
\n",
"
60325
\n",
"
19496
\n",
"
1447
\n",
"
66283
\n",
"
172
\n",
"
341
\n",
"
\n",
"
\n",
"
32_HSCs-TGFb2
\n",
"
0
\n",
"
5
\n",
"
8
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
44
\n",
"
...
\n",
"
45488
\n",
"
239
\n",
"
331
\n",
"
343
\n",
"
27442
\n",
"
9054
\n",
"
624
\n",
"
27535
\n",
"
96
\n",
"
216
\n",
"
\n",
"
\n",
"
33_HSCs-TGFb3
\n",
"
0
\n",
"
12
\n",
"
5
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
32
\n",
"
...
\n",
"
70704
\n",
"
344
\n",
"
453
\n",
"
497
\n",
"
45443
\n",
"
13796
\n",
"
1077
\n",
"
43415
\n",
"
192
\n",
"
243
\n",
"
\n",
" \n",
"
\n",
"
6 rows × 64253 columns
\n",
"
"
],
"text/plain": [
"GeneName DDX11L1 WASH7P MIR6859-1 MIR1302-11 MIR1302-9 FAM138A \\\n",
"25_HSCs-Ctrl1 0 9 10 1 0 0 \n",
"26_HSCs-Ctrl2 0 12 14 0 0 0 \n",
"27_HSCs-Ctrl3 0 14 10 0 0 0 \n",
"31_HSCs-TGFb1 0 11 16 0 0 0 \n",
"32_HSCs-TGFb2 0 5 8 0 0 0 \n",
"33_HSCs-TGFb3 0 12 5 0 0 0 \n",
"\n",
"GeneName OR4G4P OR4G11P OR4F5 RP11-34P13.7 ... MT-ND4 MT-TH \\\n",
"25_HSCs-Ctrl1 0 0 0 33 ... 93192 342 \n",
"26_HSCs-Ctrl2 0 0 0 66 ... 114914 355 \n",
"27_HSCs-Ctrl3 0 0 0 52 ... 155365 377 \n",
"31_HSCs-TGFb1 0 0 0 54 ... 110866 373 \n",
"32_HSCs-TGFb2 0 0 0 44 ... 45488 239 \n",
"33_HSCs-TGFb3 0 0 0 32 ... 70704 344 \n",
"\n",
"GeneName MT-TS2 MT-TL2 MT-ND5 MT-ND6 MT-TE MT-CYB MT-TT MT-TP \n",
"25_HSCs-Ctrl1 476 493 54466 17184 1302 54099 258 475 \n",
"26_HSCs-Ctrl2 388 436 64698 21106 1492 62679 253 396 \n",
"27_HSCs-Ctrl3 438 480 85650 31860 2033 89559 282 448 \n",
"31_HSCs-TGFb1 441 481 60325 19496 1447 66283 172 341 \n",
"32_HSCs-TGFb2 331 343 27442 9054 624 27535 96 216 \n",
"33_HSCs-TGFb3 453 497 45443 13796 1077 43415 192 243 \n",
"\n",
"[6 rows x 64253 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We need to download the dataset, available at GEO GSE151251\n",
"url = \"https://www.ncbi.nlm.nih.gov/geo/download/?acc=GSE151251&format=file&file=GSE151251%5FHSCs%5FCtrl%2Evs%2EHSCs%5FTGFb%2Ecounts%2Etsv%2Egz\"\n",
"\n",
"adata = None\n",
"with tempfile.TemporaryDirectory() as tmpdirname:\n",
" # Path for the gzipped file in the temp folder\n",
" gz_file_path = os.path.join(tmpdirname, \"counts.txt.gz\")\n",
"\n",
" # Download the file\n",
" with urllib.request.urlopen(url) as response:\n",
" with open(gz_file_path, \"wb\") as out_file:\n",
" shutil.copyfileobj(response, out_file)\n",
"\n",
" # Decompress the file\n",
" decompressed_file_path = gz_file_path[:-3] # Removing '.gz' extension\n",
" with gzip.open(gz_file_path, \"rb\") as f_in:\n",
" with open(decompressed_file_path, \"wb\") as f_out:\n",
" shutil.copyfileobj(f_in, f_out)\n",
"\n",
" adata = pd.read_csv(decompressed_file_path, index_col=2, sep=\"\\t\").iloc[:, 5:].T\n",
"\n",
"adata"
]
},
{
"cell_type": "markdown",
"id": "ed7df83c-ccf2-43ab-95d7-be55d36669be",
"metadata": {},
"source": [
"## Data preprocessing\n",
"\n",
"We will use AnnData and PyDeseq2 to pre-process the data and compute differential expression between control and tretament"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0c49ddc4-55d7-49f3-bd40-487c7535fbda",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\pablo\\miniconda3\\envs\\corneto-dev-mini\\Lib\\site-packages\\anndata\\_core\\anndata.py:1756: UserWarning: Variable names are not unique. To make them unique, call `.var_names_make_unique`.\n",
" utils.warn_names_duplicates(\"var\")\n",
"C:\\Users\\pablo\\miniconda3\\envs\\corneto-dev-mini\\Lib\\site-packages\\anndata\\utils.py:261: UserWarning: Suffix used (-[0-9]+) to deduplicate index values may make index values difficult to interpret. There values with a similar suffixes in the index. Consider using a different delimiter by passing `join={delimiter}`Example key collisions generated by the make_index_unique algorithm: ['SNORD116-1', 'SNORD116-2', 'SNORD116-3', 'SNORD116-4', 'SNORD116-5']\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/plain": [
"AnnData object with n_obs × n_vars = 6 × 64253"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from anndata import AnnData\n",
"\n",
"adata = AnnData(adata, dtype=np.float32)\n",
"adata.var_names_make_unique()\n",
"adata"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "34ee8218-6f15-4b09-a44d-150970c83c45",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
" treatment.vs.control\n",
"SRF 7.421123\n",
"MYOCD 7.372481\n",
"SMAD3 7.190940\n",
"BTG2 6.206934\n",
"TCF21 6.183177\n",
"... ...\n",
"SPI1 -5.427345\n",
"NR4A3 -5.749818\n",
"HIF3A -5.882730\n",
"NR1H4 -6.081834\n",
"IRF1 -9.395861\n",
"\n",
"[84 rows x 1 columns]"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# As measurements, we take the estimated TFs, we will filter out TFs with p-val > 0.001\n",
"significant_tfs = (\n",
" tf_acts[tf_pvals <= 0.001]\n",
" .T.dropna()\n",
" .sort_values(by=\"treatment.vs.control\", ascending=False)\n",
")\n",
"significant_tfs"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "83c01323-be92-456e-bb46-c79d5147f40a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'SRF': 7.4211225509643555,\n",
" 'MYOCD': 7.372481346130371,\n",
" 'SMAD3': 7.190939903259277,\n",
" 'BTG2': 6.206934452056885,\n",
" 'SMAD2': 5.634183883666992,\n",
" 'JUNB': 5.632753849029541,\n",
" 'HMGA2': 4.937854766845703,\n",
" 'POU3F1': 4.921204090118408,\n",
" 'RORA': 4.765202045440674,\n",
" 'SMAD4': 4.588079452514648,\n",
" 'MEF2A': 4.287934303283691,\n",
" 'FOSL1': 3.938856363296509,\n",
" 'SOX4': 3.9252400398254395,\n",
" 'NCOA1': 3.8250725269317627,\n",
" 'SFPQ': 3.7440223693847656,\n",
" 'FOSB': 3.7315196990966797,\n",
" 'SP7': 3.6977312564849854,\n",
" 'HBP1': 3.6794629096984863,\n",
" 'CREB3': 3.632990837097168,\n",
" 'ASXL1': 3.574924945831299,\n",
" 'MEIS2': 3.4930355548858643,\n",
" 'TAL1': 3.354771852493286,\n",
" 'HOXC8': 3.347809314727783,\n",
" 'DLX5': 3.3378002643585205,\n",
" 'DLX2': -3.2941677570343018,\n",
" 'CDX2': -3.2988994121551514,\n",
" 'MAFA': -3.310776472091675,\n",
" 'STAT5A': -3.430389165878296,\n",
" 'RXRB': -3.4593443870544434,\n",
" 'MSX2': -3.5386831760406494,\n",
" 'SMAD6': -3.5516138076782227,\n",
" 'CEBPA': -3.59158992767334,\n",
" 'PLAGL1': -3.6208605766296387,\n",
" 'RELA': -3.63592267036438,\n",
" 'TP53': -3.6599860191345215,\n",
" 'NKX2-1': -3.6630992889404297,\n",
" 'NFKB1': -3.842646598815918,\n",
" 'CEBPB': -3.861898422241211,\n",
" 'WWTR1': -3.9853055477142334,\n",
" 'SMAD5': -4.020087242126465,\n",
" 'VHL': -4.030272483825684,\n",
" 'CIITA': -4.151106834411621,\n",
" 'NFKBIB': -4.1750593185424805,\n",
" 'REL': -4.184780120849609,\n",
" 'PITX3': -4.216534614562988,\n",
" 'PITX1': -4.358892440795898,\n",
" 'MECP2': -4.400153160095215,\n",
" 'TGIF1': -4.501400470733643,\n",
" 'MECOM': -4.5638203620910645,\n",
" 'IRF3': -4.733184814453125,\n",
" 'RELB': -4.848578453063965,\n",
" 'NFE2L2': -4.937533378601074,\n",
" 'STAT1': -5.215514659881592,\n",
" 'HOXC6': -5.283187389373779,\n",
" 'IRF2': -5.291377544403076,\n",
" 'KLF11': -5.293704509735107,\n",
" 'SMAD7': -5.3725266456604,\n",
" 'SPI1': -5.427344799041748,\n",
" 'NR4A3': -5.749818325042725,\n",
" 'HIF3A': -5.882729530334473,\n",
" 'NR1H4': -6.081834316253662,\n",
" 'IRF1': -9.39586067199707}"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We keep only the ones in the PKN graph\n",
"measurements = significant_tfs.loc[significant_tfs.index.intersection(G.V)].to_dict()[\n",
" \"treatment.vs.control\"\n",
"]\n",
"measurements"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "8f644411-e8c8-4072-b62e-230adea6eb08",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'CDH6': 0,\n",
" 'CRLF1': 0,\n",
" 'FZD8': 0,\n",
" 'CDH2': 0,\n",
" 'INHBA': 0,\n",
" 'VDR': 0,\n",
" 'IGF1': 0,\n",
" 'EFNB2': 0,\n",
" 'ITGB3': 0,\n",
" 'TGFB1': 0,\n",
" 'IL21R': 0,\n",
" 'EGF': 0,\n",
" 'ITGA11': 0}"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We will infer the direction, so for the inputs, we use a value of 0 (=unknown direction)\n",
"inputs = {k: 0 for k in df_top_receptors.index.intersection(G.V).values}\n",
"inputs"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "7f5b695a-e965-4e3d-8f7c-55efda9b2eb1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(958, 3279)"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We prune the network from inputs (receptors) to TFs to improve the performance.\n",
"# The pruning step removes only parts of the network that cannot be reached from the pre-selected receptors\n",
"from corneto.methods.carnival import preprocess_graph\n",
"\n",
"Gp, inputs_p, measurements_p = preprocess_graph(G, inputs, measurements)\n",
"Gp.shape"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "cab88e0f-333a-463a-942a-86aefea03be4",
"metadata": {},
"outputs": [],
"source": [
"vertices = Gp.V"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "a94e21f6-14a8-4f01-804a-73b88eda11ba",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'vertex_inhibited': Variable((958,), vertex_inhibited, boolean=True),\n",
" 'edge_activating': Variable((3279,), edge_activating, boolean=True),\n",
" 'edge_inhibiting': Variable((3279,), edge_inhibiting, boolean=True),\n",
" 'vertex_activated': Variable((958,), vertex_activated, boolean=True),\n",
" 'vertex_position': Variable((958,), vertex_position),\n",
" 'vertex_values': Expression(AFFINE, UNKNOWN, (958,)),\n",
" 'edge_values': Expression(AFFINE, UNKNOWN, (3279,))}"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from corneto.methods.carnival import milp_carnival\n",
"\n",
"# We create a CARNIVAL problem\n",
"P = milp_carnival(Gp, inputs_p, measurements_p, beta_weight=0.2)\n",
"\n",
"# The CARNIVAL problem contains useful variables that we will estimate from the data\n",
"P.expr"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "3b32b7e6-e5d1-458d-9b52-cc5eb44323c7",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'APC_AXIN1_GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R2A', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'CTNNB1', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'CSNK1D', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'AKAP12', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'RARG', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'ERBB2', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n",
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'APC_AXIN1_GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R2A', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'CTNNB1', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'CSNK1D', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'AKAP12', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'RARG', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'ERBB2', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We first run CARNIVAL using all selected receptors.\n",
"# We find the value for the variables using the solver GUROBI\n",
"# (needs to be installed with a valid license, academic licenses are free)\n",
"# TimeLimit and Seed are GUROBI specific parameters\n",
"P.solve(solver=\"GUROBI\", Seed=seed)\n",
"\n",
"# We extract the selected edges\n",
"G_sol = Gp.edge_subgraph(np.flatnonzero(P.expr.edge_values.value))\n",
"\n",
"# We plot generating custom drawing attributes\n",
"values = P.expr.vertex_values.value\n",
"vertex_values = {v: values[i] for i, v in enumerate(Gp.V)}\n",
"vertex_sol_values = [vertex_values[v] for v in G_sol.V]\n",
"G_sol.plot(\n",
" custom_vertex_attr=cn.pl.create_graphviz_vertex_attributes(\n",
" G_sol.V, vertex_sol_values\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "f37de568-afd8-4c83-a4d0-9d36ed258afa",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.373496770858765\n",
"88.0\n"
]
}
],
"source": [
"# Print the values of the objectives:\n",
"# - First objective is error (non-fited TFs).\n",
"# - Second objective is number of interactions\n",
"for o in P.objectives:\n",
" print(o.value)"
]
},
{
"cell_type": "code",
"execution_count": 78,
"id": "89140b57-43da-4150-b71f-25956ccad4dd",
"metadata": {},
"outputs": [],
"source": [
"# The CARNIVAL problem can be manipulated for hypothesis exploration.\n",
"# For example, we will say that only 1 of the provided receptors has to be selected, at most.\n",
"P = milp_carnival(Gp, inputs_p, measurements_p, beta_weight=0.2)\n",
"idx_receptors = [vertices.index(k) for k in inputs_p.keys()]\n",
"protein_selected = P.expr.vertex_activated + P.expr.vertex_inhibited\n",
"P += sum(protein_selected[idx_receptors]) == 1\n",
"P.solve(solver=\"GUROBI\", TimeLimit=max_time, Seed=seed);"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "538e1d57-3c9f-4513-a89f-0138454ce23e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'CDKN1A', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'KHSRP', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'PDPK1', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MUC1', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'APC_AXIN1_GSK3B', graph '%3' size too small for label\n",
"Warning: node 'CSNK1D', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'RARB', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n",
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'CDKN1A', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'KHSRP', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'PDPK1', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MUC1', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'APC_AXIN1_GSK3B', graph '%3' size too small for label\n",
"Warning: node 'CSNK1D', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'RARB', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We extract the edges that have some signal (edge_values != 0)\n",
"# We select the sub-graph from the processed PKN\n",
"G_sol = Gp.edge_subgraph(np.flatnonzero(P.expr.edge_values.value))\n",
"\n",
"# We plot generating custom drawing attributes\n",
"values = P.expr.vertex_values.value\n",
"vertex_values = {v: values[i] for i, v in enumerate(Gp.V)}\n",
"vertex_sol_values = [vertex_values[v] for v in G_sol.V]\n",
"G_sol.plot(\n",
" custom_vertex_attr=cn.pl.create_graphviz_vertex_attributes(\n",
" G_sol.V, vertex_sol_values\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "7c0cba49-68d4-4c30-99f9-684c4f346979",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.373496770858765\n",
"88.0\n"
]
}
],
"source": [
"# Print the values of the objectives:\n",
"# - First objective is error (non-fited TFs).\n",
"# - Second objective is number of interactions\n",
"for o in P.objectives:\n",
" print(o.value)"
]
},
{
"cell_type": "markdown",
"id": "1a182f07-2ca6-4d4e-9e78-f9d655444750",
"metadata": {},
"source": [
"## Adding more knowledge\n",
"\n",
"We can add more prior knowledge to the CARNIVAL problem. For example, we are going to penalise genes that are lowly abundant, according to the average basal gene expression levels. "
]
},
{
"cell_type": "code",
"execution_count": 101,
"id": "f38f62f5-ff99-4c4c-8281-b6dc4856ba58",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
baseMean
\n",
"
log2FoldChange
\n",
"
lfcSE
\n",
"
stat
\n",
"
pvalue
\n",
"
padj
\n",
"
\n",
"
\n",
"
GeneName
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
" \n",
" \n",
"
\n",
"
TRIM17
\n",
"
53.443434
\n",
"
-0.689125
\n",
"
0.300338
\n",
"
-2.294499
\n",
"
0.021762
\n",
"
0.050210
\n",
"
\n",
"
\n",
"
NLGN3
\n",
"
32.581601
\n",
"
-0.895798
\n",
"
0.390573
\n",
"
-2.293545
\n",
"
0.021817
\n",
"
0.050307
\n",
"
\n",
"
\n",
"
RP11-1109F11.3
\n",
"
11.672715
\n",
"
-1.587070
\n",
"
0.692036
\n",
"
-2.293336
\n",
"
0.021829
\n",
"
0.050323
\n",
"
\n",
"
\n",
"
RP11-661A12.5
\n",
"
15.285895
\n",
"
-1.297808
\n",
"
0.566496
\n",
"
-2.290938
\n",
"
0.021967
\n",
"
0.050602
\n",
"
\n",
"
\n",
"
RP11-77K12.7
\n",
"
25.489581
\n",
"
-0.991542
\n",
"
0.432922
\n",
"
-2.290350
\n",
"
0.022001
\n",
"
0.050661
\n",
"
\n",
"
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
\n",
"
\n",
"
GDPD1
\n",
"
74.892252
\n",
"
0.000326
\n",
"
0.262746
\n",
"
0.001241
\n",
"
0.999010
\n",
"
0.999415
\n",
"
\n",
"
\n",
"
RP11-452K12.7
\n",
"
49.986985
\n",
"
-0.000259
\n",
"
0.302890
\n",
"
-0.000855
\n",
"
0.999317
\n",
"
0.999520
\n",
"
\n",
"
\n",
"
MIR6859-1
\n",
"
10.114621
\n",
"
0.000625
\n",
"
0.657581
\n",
"
0.000950
\n",
"
0.999242
\n",
"
0.999520
\n",
"
\n",
"
\n",
"
RP11-463C8.4
\n",
"
48.479410
\n",
"
-0.000280
\n",
"
0.305891
\n",
"
-0.000916
\n",
"
0.999269
\n",
"
0.999520
\n",
"
\n",
"
\n",
"
AIF1L
\n",
"
11.870434
\n",
"
-0.000351
\n",
"
0.619997
\n",
"
-0.000566
\n",
"
0.999549
\n",
"
0.999599
\n",
"
\n",
" \n",
"
\n",
"
3750 rows × 6 columns
\n",
"
"
],
"text/plain": [
" baseMean log2FoldChange lfcSE stat pvalue \\\n",
"GeneName \n",
"TRIM17 53.443434 -0.689125 0.300338 -2.294499 0.021762 \n",
"NLGN3 32.581601 -0.895798 0.390573 -2.293545 0.021817 \n",
"RP11-1109F11.3 11.672715 -1.587070 0.692036 -2.293336 0.021829 \n",
"RP11-661A12.5 15.285895 -1.297808 0.566496 -2.290938 0.021967 \n",
"RP11-77K12.7 25.489581 -0.991542 0.432922 -2.290350 0.022001 \n",
"... ... ... ... ... ... \n",
"GDPD1 74.892252 0.000326 0.262746 0.001241 0.999010 \n",
"RP11-452K12.7 49.986985 -0.000259 0.302890 -0.000855 0.999317 \n",
"MIR6859-1 10.114621 0.000625 0.657581 0.000950 0.999242 \n",
"RP11-463C8.4 48.479410 -0.000280 0.305891 -0.000916 0.999269 \n",
"AIF1L 11.870434 -0.000351 0.619997 -0.000566 0.999549 \n",
"\n",
" padj \n",
"GeneName \n",
"TRIM17 0.050210 \n",
"NLGN3 0.050307 \n",
"RP11-1109F11.3 0.050323 \n",
"RP11-661A12.5 0.050602 \n",
"RP11-77K12.7 0.050661 \n",
"... ... \n",
"GDPD1 0.999415 \n",
"RP11-452K12.7 0.999520 \n",
"MIR6859-1 0.999520 \n",
"RP11-463C8.4 0.999520 \n",
"AIF1L 0.999599 \n",
"\n",
"[3750 rows x 6 columns]"
]
},
"execution_count": 101,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_lowly_abundant_genes = results_df[\n",
" (results_df.baseMean <= results_df.baseMean.quantile(0.25))\n",
" & (results_df.padj >= 0.05)\n",
"]\n",
"df_lowly_abundant_genes.sort_values(by=\"padj\")"
]
},
{
"cell_type": "code",
"execution_count": 103,
"id": "fd4b32f4-aa01-488f-b6b8-52d50882a3b1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"({'CARD11',\n",
" 'DCC',\n",
" 'DLX2',\n",
" 'ERBB3',\n",
" 'FERMT3',\n",
" 'GHR',\n",
" 'HOXC8',\n",
" 'INPP5D',\n",
" 'ITGB4',\n",
" 'MAF',\n",
" 'MSX1',\n",
" 'NOXO1',\n",
" 'PARD6A',\n",
" 'PLEKHG6',\n",
" 'PSTPIP1',\n",
" 'PTPN22',\n",
" 'RPS6KA5',\n",
" 'TEC',\n",
" 'TIAM1'},\n",
" 19)"
]
},
"execution_count": 103,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lowly_abundant_genes = set(Gp.V).intersection(df_lowly_abundant_genes.index.tolist())\n",
"lowly_abundant_genes, len(lowly_abundant_genes)"
]
},
{
"cell_type": "code",
"execution_count": 104,
"id": "201455a9-04be-4558-98ff-377721cc413b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0.01, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0.01, 0. , 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0.01, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.01,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0.01, 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0.01, 0. , 0.01, 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0.01, 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. ])"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now we will add a penalty to avoid selecting lowly expressed genes\n",
"vertices = Gp.V\n",
"penalties = np.zeros(Gp.num_vertices)\n",
"penalties[[vertices.index(v) for v in lowly_abundant_genes.intersection(vertices)]] = (\n",
" 0.01\n",
")\n",
"penalties"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "25208669-b019-4ec8-afe8-4d1cda41cd14",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\pablo\\miniconda3\\envs\\corneto-dev-mini\\Lib\\site-packages\\cvxpy\\problems\\problem.py:158: UserWarning: Objective contains too many subexpressions. Consider vectorizing your CVXPY code to speed up compilation.\n",
" warnings.warn(\"Objective contains too many subexpressions. \"\n"
]
}
],
"source": [
"# Create the carnival problem\n",
"P = milp_carnival(Gp, inputs_p, measurements_p, beta_weight=0.2)\n",
"\n",
"# We penalize the inclusion of lowly expressed genes:\n",
"# protein_selected is just the sum of the binary variables vertex activated and vertex inhibited, defined in carnival.\n",
"# these variables are mutually exclusive, so the sum is at most 1, meaning that the vertex was selected, either activated (+1) or inhibited (-1)\n",
"protein_selected = P.expr.vertex_activated + P.expr.vertex_inhibited\n",
"\n",
"# We multiply the vector variable of selected proteins and the penalties to\n",
"# sum the total cost: sum (v1 * penalty1 + v2 * penalty2, + v3 ...) and we add this as an objective\n",
"penalty_vertices = protein_selected @ penalties\n",
"P.add_objectives(penalty_vertices)\n",
"\n",
"# Select only 1 receptor\n",
"protein_selected = P.expr.vertex_activated + P.expr.vertex_inhibited\n",
"# P += sum(protein_selected[idx_receptors]) == 1\n",
"\n",
"P.solve(solver=\"GUROBI\", Seed=seed, TimeLimit=max_time);"
]
},
{
"cell_type": "code",
"execution_count": 106,
"id": "a4c0f22c-748e-457e-9223-8c83f5829897",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'APC_AXIN1_GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R2A', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'CTNNB1', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'PTPRR', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'CSNK1D', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'ERBB2', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'RARB', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n",
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'APC_AXIN1_GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R2A', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'CTNNB1', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'PTPRR', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'CSNK1D', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'ERBB2', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'RARB', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 106,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G_sol = Gp.edge_subgraph(np.flatnonzero(P.expr.edge_values.value))\n",
"values = P.expr.vertex_values.value\n",
"vertex_values = {v: values[i] for i, v in enumerate(Gp.V)}\n",
"vertex_sol_values = [vertex_values[v] for v in G_sol.V]\n",
"G_sol.plot(\n",
" custom_vertex_attr=cn.pl.create_graphviz_vertex_attributes(\n",
" G_sol.V, vertex_sol_values\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 107,
"id": "897bd341-948d-4026-a17a-b0b6b6796f4d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.373496770858765\n",
"88.0\n",
"0.0\n"
]
}
],
"source": [
"# Print the values of the objectives:\n",
"for o in P.objectives:\n",
" print(o.value)"
]
},
{
"cell_type": "code",
"execution_count": 108,
"id": "16795952-fb4a-4490-b418-6439fbf5ae5d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(949, 3261)"
]
},
"execution_count": 108,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now we are going to force that only TGFB1 (active)\n",
"Gp, inputs_p, measurements_p = preprocess_graph(G, {\"TGFB1\": 1}, measurements)\n",
"Gp.shape"
]
},
{
"cell_type": "code",
"execution_count": 109,
"id": "56fab499-da46-4387-8b53-04f2a050d7b1",
"metadata": {},
"outputs": [],
"source": [
"P = milp_carnival(Gp, inputs_p, measurements_p, beta_weight=0.2)\n",
"P.solve(solver=\"GUROBI\", Seed=seed, TimeLimit=max_time);"
]
},
{
"cell_type": "code",
"execution_count": 110,
"id": "73530ad5-a8b8-41fb-b8ba-087c8ecb592a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.373496770858765\n",
"90.0\n"
]
}
],
"source": [
"# Same error but +2 edges were included to explain the TFs\n",
"for o in P.objectives:\n",
" print(o.value)"
]
},
{
"cell_type": "code",
"execution_count": 111,
"id": "170e8316-5307-48de-8ba5-5a69091ac237",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: node 'CDKN1A', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'DUSP16', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MUC1', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'AURKA', graph '%3' size too small for label\n",
"Warning: node 'LATS2', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'KHSRP', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'PIK3CA_PIK3R1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'RARG', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n",
"Warning: node 'CDKN1A', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'DUSP16', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MUC1', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'AURKA', graph '%3' size too small for label\n",
"Warning: node 'LATS2', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'KHSRP', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'PIK3CA_PIK3R1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'PPP1CA', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'RARG', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 111,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G_sol = Gp.edge_subgraph(np.flatnonzero(P.expr.edge_values.value))\n",
"values = P.expr.vertex_values.value\n",
"vertex_values = {v: values[i] for i, v in enumerate(Gp.V)}\n",
"vertex_sol_values = [vertex_values[v] for v in G_sol.V]\n",
"G_sol.plot(\n",
" custom_vertex_attr=cn.pl.create_graphviz_vertex_attributes(\n",
" G_sol.V, vertex_sol_values\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 112,
"id": "6380c9af-ef90-4bb7-8337-9b6981d5c5ea",
"metadata": {},
"outputs": [],
"source": [
"# Biasing the networks towards activatory interactions\n",
"\n",
"# Create the carnival problem with Beta = 0 (to not equally penalise all interactions)\n",
"# Gp, inputs_p, measurements_p = preprocess_graph(G, {\"TGFB1\": 0}, measurements)\n",
"Gp, inputs_p, measurements_p = preprocess_graph(G, inputs, measurements)\n",
"P = milp_carnival(Gp, inputs_p, measurements_p, beta_weight=0)\n",
"\n",
"# Bias towards activations, by penalizing only inhibitions\n",
"P.add_objectives(P.expr.edge_inhibiting.sum(), weights=0.2)\n",
"\n",
"# Much smaller penalty for activations, since we only want to penalise them\n",
"# slightly to avoid having spurious interactions. However, inhibitions are\n",
"# penalised 20x more than activations (weight 0.2 vs 0.01)\n",
"P.add_objectives(P.expr.edge_activating.sum(), weights=0.01)\n",
"\n",
"P.solve(solver=\"GUROBI\", TimeLimit=max_time, Seed=seed);"
]
},
{
"cell_type": "code",
"execution_count": 113,
"id": "b0e07155-d54f-4e4a-8ba3-a4384aef0d8a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R5C', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'PTPN7', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAP2K1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'PRKCQ', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'CTNNB1', graph '%3' size too small for label\n",
"Warning: node 'LATS2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'STAT6', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'GATA2', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'ERBB2', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'RARB', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n",
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R5C', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'PTPN7', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAP2K1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'PRKCQ', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'CTNNB1', graph '%3' size too small for label\n",
"Warning: node 'LATS2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'STAT6', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'GATA2', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'ERBB2', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'RARB', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 113,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G_sol = Gp.edge_subgraph(np.flatnonzero(P.expr.edge_values.value))\n",
"values = P.expr.vertex_values.value\n",
"vertex_values = {v: values[i] for i, v in enumerate(Gp.V)}\n",
"vertex_sol_values = [vertex_values[v] for v in G_sol.V]\n",
"G_sol.plot(\n",
" custom_vertex_attr=cn.pl.create_graphviz_vertex_attributes(\n",
" G_sol.V, vertex_sol_values\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 114,
"id": "50f2269f-5cc0-4572-be18-46887726d191",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.373496770858765\n",
"48.0\n",
"44.0\n"
]
}
],
"source": [
"# 48 inhibitory interactions and 44 activations\n",
"for o in P.objectives:\n",
" print(o.value)"
]
},
{
"cell_type": "markdown",
"id": "3249fa12-4cda-4b79-9964-21137acb480e",
"metadata": {},
"source": [
"We have explored different approaches and assumptions to recover a signalling network from TF activities and a list of potential receptors. Although changes in gene expression for signalling proteins are not always predictive of signalling cascades—hence the use of CARNIVAL as a footprint-based method to bridge the gaps between receptors and TFs—we can introduce a slight bias in the network towards signalling proteins whose gene expression has changed significantly after treatment. These changes, while indirect, may still provide valuable cues. In a manner similar to how we penalised low-abundance genes, we will now prioritize the inclusion of upregulated genes."
]
},
{
"cell_type": "code",
"execution_count": 139,
"id": "aca3c182-9eba-4e7b-bb69-e9b55cd332c3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['ABL1', 'AHR', 'AIRE', 'AP1', 'APEX1', 'AR', 'ARID1A', 'ARID3A',\n",
" 'ARID3B', 'ARID4A',\n",
" ...\n",
" 'ZNF362', 'ZNF382', 'ZNF384', 'ZNF395', 'ZNF436', 'ZNF699', 'ZNF76',\n",
" 'ZNF804A', 'ZNF91', 'ZXDC'],\n",
" dtype='object', length=655)"
]
},
"execution_count": 139,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tf_acts.columns"
]
},
{
"cell_type": "code",
"execution_count": 140,
"id": "4ec4d220-c63d-466a-a524-967b09fc19f5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"NUAK1 -40.581591\n",
"CDH6 -39.007075\n",
"FZD8 -37.421427\n",
"CDH2 -34.291273\n",
"STK38L -30.552887\n",
" ... \n",
"IL6R 21.833188\n",
"MAP3K5 21.883284\n",
"CASP1 23.060970\n",
"IL1R1 24.058471\n",
"TNFRSF1B 25.812839\n",
"Name: stat, Length: 627, dtype: float64"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Since the problem minimises error, we change sign. Upregulated genes get negative score\n",
"# so if they are selected, the error decreases. The opposite for downregulated genes\n",
"df_gene_scores = -results_df.loc[\n",
" results_df.index.intersection(Gp.V).difference(tf_acts.columns)\n",
"].stat\n",
"dict_scores = df_gene_scores.to_dict()\n",
"\n",
"df_gene_scores.sort_values()"
]
},
{
"cell_type": "code",
"execution_count": 141,
"id": "796cf5b1-25d4-4807-9679-e9bf04a4b475",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3045.9775260752576"
]
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now we will add a penalty to avoid selecting lowly expressed genes\n",
"vertices = Gp.V\n",
"scores = np.array([dict_scores.get(v, 0) for v in vertices])\n",
"np.sum(np.abs(scores))"
]
},
{
"cell_type": "code",
"execution_count": 142,
"id": "90eb8df5-a39d-4ebc-a508-6e75d90617bb",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\pablo\\miniconda3\\envs\\corneto-dev-mini\\Lib\\site-packages\\cvxpy\\problems\\problem.py:158: UserWarning: Objective contains too many subexpressions. Consider vectorizing your CVXPY code to speed up compilation.\n",
" warnings.warn(\"Objective contains too many subexpressions. \"\n"
]
}
],
"source": [
"# Create the carnival problem\n",
"P = milp_carnival(Gp, inputs_p, measurements_p, beta_weight=0.2)\n",
"vertex_selected = P.expr.vertex_activated + P.expr.vertex_inhibited\n",
"total_score = vertex_selected @ scores\n",
"P.add_objectives(total_score, weights=1e-3)\n",
"P.solve(solver=\"GUROBI\", Seed=seed, TimeLimit=max_time);"
]
},
{
"cell_type": "code",
"execution_count": 143,
"id": "bd7dcb88-bc2b-4131-b102-25dfd7d31921",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'CDKN1A', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAP2K1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MUC1', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R2A', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'RARG', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'LATS1', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n",
"Warning: node 'FBXW7', graph '%3' size too small for label\n",
"Warning: node 'CDKN1A', graph '%3' size too small for label\n",
"Warning: node 'HIPK2', graph '%3' size too small for label\n",
"Warning: node 'MAPK1', graph '%3' size too small for label\n",
"Warning: node 'NFKB2', graph '%3' size too small for label\n",
"Warning: node 'TRIP11', graph '%3' size too small for label\n",
"Warning: node 'THRA', graph '%3' size too small for label\n",
"Warning: node 'PHLPP1', graph '%3' size too small for label\n",
"Warning: node 'PRKCA', graph '%3' size too small for label\n",
"Warning: node 'MYOCD', graph '%3' size too small for label\n",
"Warning: node 'MAP2K1', graph '%3' size too small for label\n",
"Warning: node 'RORA', graph '%3' size too small for label\n",
"Warning: node 'PPP2CA', graph '%3' size too small for label\n",
"Warning: node 'TRAF2', graph '%3' size too small for label\n",
"Warning: node 'SMURF1', graph '%3' size too small for label\n",
"Warning: node 'SMAD6', graph '%3' size too small for label\n",
"Warning: node 'FOSL1', graph '%3' size too small for label\n",
"Warning: node 'MAPK14', graph '%3' size too small for label\n",
"Warning: node 'MEF2A', graph '%3' size too small for label\n",
"Warning: node 'MAPK3', graph '%3' size too small for label\n",
"Warning: node 'SMAD3', graph '%3' size too small for label\n",
"Warning: node 'SMAD4', graph '%3' size too small for label\n",
"Warning: node 'GSK3B', graph '%3' size too small for label\n",
"Warning: node 'MUC1', graph '%3' size too small for label\n",
"Warning: node 'NCOA1', graph '%3' size too small for label\n",
"Warning: node 'ASXL1', graph '%3' size too small for label\n",
"Warning: node 'MSX2', graph '%3' size too small for label\n",
"Warning: node 'NFE2L2', graph '%3' size too small for label\n",
"Warning: node 'TICAM1', graph '%3' size too small for label\n",
"Warning: node 'SMAD7', graph '%3' size too small for label\n",
"Warning: node 'STAT1', graph '%3' size too small for label\n",
"Warning: node 'TGFB1', graph '%3' size too small for label\n",
"Warning: node 'PPP2R2A', graph '%3' size too small for label\n",
"Warning: node 'NKX2-1', graph '%3' size too small for label\n",
"Warning: node 'PITX1', graph '%3' size too small for label\n",
"Warning: node 'CDON', graph '%3' size too small for label\n",
"Warning: node 'CHEK2', graph '%3' size too small for label\n",
"Warning: node 'HMGA2', graph '%3' size too small for label\n",
"Warning: node 'STAT5A', graph '%3' size too small for label\n",
"Warning: node 'MECP2', graph '%3' size too small for label\n",
"Warning: node 'NFKB1', graph '%3' size too small for label\n",
"Warning: node 'MAFA', graph '%3' size too small for label\n",
"Warning: node 'HIF3A', graph '%3' size too small for label\n",
"Warning: node 'MAP3K7', graph '%3' size too small for label\n",
"Warning: node 'NFKBIB', graph '%3' size too small for label\n",
"Warning: node 'CEBPB', graph '%3' size too small for label\n",
"Warning: node 'CUL1_RBX1_SKP1', graph '%3' size too small for label\n",
"Warning: node 'MEIS2', graph '%3' size too small for label\n",
"Warning: node 'INHBA', graph '%3' size too small for label\n",
"Warning: node 'ACVR2B', graph '%3' size too small for label\n",
"Warning: node 'SMAD2', graph '%3' size too small for label\n",
"Warning: node 'RARG', graph '%3' size too small for label\n",
"Warning: node 'RXRB', graph '%3' size too small for label\n",
"Warning: node 'CEBPA', graph '%3' size too small for label\n",
"Warning: node 'HMGA1', graph '%3' size too small for label\n",
"Warning: node 'LATS1', graph '%3' size too small for label\n",
"Warning: node 'POU3F1', graph '%3' size too small for label\n",
"Warning: node 'WWTR1', graph '%3' size too small for label\n",
"Warning: node 'SMAD5', graph '%3' size too small for label\n",
"Warning: node 'NR1H4', graph '%3' size too small for label\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 143,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G_sol = Gp.edge_subgraph(np.flatnonzero(P.expr.edge_values.value))\n",
"values = P.expr.vertex_values.value\n",
"vertex_values = {v: values[i] for i, v in enumerate(Gp.V)}\n",
"vertex_sol_values = [vertex_values[v] for v in G_sol.V]\n",
"G_sol.plot(\n",
" custom_vertex_attr=cn.pl.create_graphviz_vertex_attributes(\n",
" G_sol.V, vertex_sol_values\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 144,
"id": "aa10a36a-de26-467a-9cdd-2b4392b504c8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.373496770858765\n",
"88.0\n",
"-245.81810302737185\n"
]
}
],
"source": [
"for o in P.objectives:\n",
" print(o.value)"
]
}
],
"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.10.15"
},
"mystnb": {
"execution_mode": "off"
}
},
"nbformat": 4,
"nbformat_minor": 5
}