File size: 24,814 Bytes
bcd1195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6c08a8f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2026-06-09 13:29:16.828 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
      "2026-06-09 13:29:16.829 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
      "2026-06-09 13:29:16.830 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
      "2026-06-09 13:29:16.830 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
      "2026-06-09 13:29:16.831 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Base directory: /home/lippincm/gene-process-dependencies/9.webapp\n",
      "Repo root: /home/lippincm/gene-process-dependencies\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import pathlib\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import streamlit as st\n",
    "from app_utils import latent_load_data, load_model_data, single_load_data\n",
    "from sklearn.decomposition import PCA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "328325ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2026-06-09 13:29:16.839 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
      "2026-06-09 13:29:16.840 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Base directory: /home/lippincm/gene-process-dependencies/9.webapp\n",
      "Repo root: /home/lippincm/gene-process-dependencies\n"
     ]
    }
   ],
   "source": [
    "_base_reactome, _base_corum, _base_drug = latent_load_data()\n",
    "ALL_DISEASES = sorted(_base_reactome[\"OncotreePrimaryDisease\"].unique().tolist())\n",
    "ALL_MODEL_IDS = sorted(_base_reactome[\"ModelID\"].unique().tolist())\n",
    "# Go up one level to repo root, then into data/\n",
    "BASE_DIR = pathlib.Path().resolve()\n",
    "REPO_ROOT = BASE_DIR.parent\n",
    "REPO_ROOT = BASE_DIR.parent  # goes up from 9.webapp/ to repo root\n",
    "print(f\"Base directory: {BASE_DIR}\")\n",
    "print(f\"Repo root: {REPO_ROOT}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "37924565",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1150, 18444)\n"
     ]
    }
   ],
   "source": [
    "combined_df = single_load_data()\n",
    "data_directory = BASE_DIR / \"data\"\n",
    "dependency_file = data_directory / \"CRISPRGeneEffect.parquet\"\n",
    "gene_dict_file = data_directory / \"CRISPR_gene_dictionary.parquet\"\n",
    "cancer_type_input_file = BASE_DIR / \"data\" / \"Model.parquet\"\n",
    "dependency_df, gene_dict_df = load_model_data(dependency_file, gene_dict_file)\n",
    "dependency_df = dependency_df.set_index(\"ModelID\")\n",
    "cancer_type_input_file = pathlib.Path(f\"{BASE_DIR}/data/Model.parquet\")\n",
    "cancer_type_df = pd.read_parquet(cancer_type_input_file)\n",
    "reactome_matrix, corum_matrix, drug_matrix = latent_load_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ef7365a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "4f84dac0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ModelID</th>\n",
       "      <th>OncotreePrimaryDisease</th>\n",
       "      <th>latent_score</th>\n",
       "      <th>gsea_es_score</th>\n",
       "      <th>pathway_score</th>\n",
       "      <th>feature</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ACH-000001</td>\n",
       "      <td>Ovarian Epithelial Tumor</td>\n",
       "      <td>0.392860</td>\n",
       "      <td>0.824315</td>\n",
       "      <td>0.392860</td>\n",
       "      <td>Inactivation, Recovery And Regulation Of Photo...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ACH-000001</td>\n",
       "      <td>Ovarian Epithelial Tumor</td>\n",
       "      <td>0.763630</td>\n",
       "      <td>0.880116</td>\n",
       "      <td>0.763630</td>\n",
       "      <td>Elastic Fibre Formation R-HSA-1566948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ACH-000001</td>\n",
       "      <td>Ovarian Epithelial Tumor</td>\n",
       "      <td>0.435531</td>\n",
       "      <td>0.839506</td>\n",
       "      <td>0.435531</td>\n",
       "      <td>Mismatch Repair (MMR) Directed By MSH2:MSH6 (M...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ACH-000001</td>\n",
       "      <td>Ovarian Epithelial Tumor</td>\n",
       "      <td>0.531491</td>\n",
       "      <td>-0.733375</td>\n",
       "      <td>0.531491</td>\n",
       "      <td>Processive Synthesis On Lagging Strand R-HSA-6...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ACH-000001</td>\n",
       "      <td>Ovarian Epithelial Tumor</td>\n",
       "      <td>0.267750</td>\n",
       "      <td>0.864257</td>\n",
       "      <td>0.267750</td>\n",
       "      <td>Mismatch Repair (MMR) Directed By MSH2:MSH3 (M...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169777</th>\n",
       "      <td>ACH-003012</td>\n",
       "      <td>Non-Small Cell Lung Cancer</td>\n",
       "      <td>0.505296</td>\n",
       "      <td>0.938271</td>\n",
       "      <td>0.505296</td>\n",
       "      <td>Kinase maturation complex 1 (human)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169778</th>\n",
       "      <td>ACH-003012</td>\n",
       "      <td>Non-Small Cell Lung Cancer</td>\n",
       "      <td>0.282634</td>\n",
       "      <td>0.808217</td>\n",
       "      <td>0.282634</td>\n",
       "      <td>immunoproteasome (mouse)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169779</th>\n",
       "      <td>ACH-003012</td>\n",
       "      <td>Non-Small Cell Lung Cancer</td>\n",
       "      <td>0.073697</td>\n",
       "      <td>0.748024</td>\n",
       "      <td>0.073697</td>\n",
       "      <td>ALL-1 supercomplex (human)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169780</th>\n",
       "      <td>ACH-003012</td>\n",
       "      <td>Non-Small Cell Lung Cancer</td>\n",
       "      <td>0.032945</td>\n",
       "      <td>0.739678</td>\n",
       "      <td>0.032945</td>\n",
       "      <td>Emerin complex 32 (human)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169781</th>\n",
       "      <td>ACH-003012</td>\n",
       "      <td>Non-Small Cell Lung Cancer</td>\n",
       "      <td>0.283263</td>\n",
       "      <td>0.815085</td>\n",
       "      <td>0.283263</td>\n",
       "      <td>Ikaros complex (mouse)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>169782 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           ModelID      OncotreePrimaryDisease  latent_score  gsea_es_score  \\\n",
       "0       ACH-000001    Ovarian Epithelial Tumor      0.392860       0.824315   \n",
       "1       ACH-000001    Ovarian Epithelial Tumor      0.763630       0.880116   \n",
       "2       ACH-000001    Ovarian Epithelial Tumor      0.435531       0.839506   \n",
       "3       ACH-000001    Ovarian Epithelial Tumor      0.531491      -0.733375   \n",
       "4       ACH-000001    Ovarian Epithelial Tumor      0.267750       0.864257   \n",
       "...            ...                         ...           ...            ...   \n",
       "169777  ACH-003012  Non-Small Cell Lung Cancer      0.505296       0.938271   \n",
       "169778  ACH-003012  Non-Small Cell Lung Cancer      0.282634       0.808217   \n",
       "169779  ACH-003012  Non-Small Cell Lung Cancer      0.073697       0.748024   \n",
       "169780  ACH-003012  Non-Small Cell Lung Cancer      0.032945       0.739678   \n",
       "169781  ACH-003012  Non-Small Cell Lung Cancer      0.283263       0.815085   \n",
       "\n",
       "        pathway_score                                            feature  \n",
       "0            0.392860  Inactivation, Recovery And Regulation Of Photo...  \n",
       "1            0.763630              Elastic Fibre Formation R-HSA-1566948  \n",
       "2            0.435531  Mismatch Repair (MMR) Directed By MSH2:MSH6 (M...  \n",
       "3            0.531491  Processive Synthesis On Lagging Strand R-HSA-6...  \n",
       "4            0.267750  Mismatch Repair (MMR) Directed By MSH2:MSH3 (M...  \n",
       "...               ...                                                ...  \n",
       "169777       0.505296                Kinase maturation complex 1 (human)  \n",
       "169778       0.282634                           immunoproteasome (mouse)  \n",
       "169779       0.073697                         ALL-1 supercomplex (human)  \n",
       "169780       0.032945                          Emerin complex 32 (human)  \n",
       "169781       0.283263                             Ikaros complex (mouse)  \n",
       "\n",
       "[169782 rows x 6 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corum_matrix_path = (\n",
    "    REPO_ROOT / \"5.drug-dependency\" / \"results\" / \"all_corum_results.parquet\"\n",
    ")\n",
    "corum_matrix = pd.read_parquet(corum_matrix_path)\n",
    "corum_matrix[\"feature\"] = corum_matrix[\"reactome_pathway\"]\n",
    "corum_matrix = corum_matrix.drop(\n",
    "    columns=[\"model\", \"latent_dim_total\", \"init\", \"seed\", \"z\", \"reactome_pathway\"]\n",
    ")\n",
    "meta_cols = [\"ModelID\", \"OncotreePrimaryDisease\"]\n",
    "\n",
    "corum_meta = corum_matrix[meta_cols].drop_duplicates()\n",
    "\n",
    "# corum_matrix = corum_matrix.pivot(index=\"ModelID\", columns=\"feature\", values=\"latent_score\")\n",
    "# corum_matrix = corum_matrix.merge(corum_meta, on=\"ModelID\", how=\"left\")\n",
    "# print(corum_matrix.isna().sum().sum())\n",
    "# corum_matrix.drop(columns=['gsea_es_score',\"pathway_score\",\"OncotreePrimaryDisease\"], inplace=True)\n",
    "# corum_matrix.pivot(index=\"ModelID\", columns=\"feature\", values=\"latent_score\")\n",
    "corum_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "0f7fe22e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Inactivation, Recovery And Regulation Of Phototransduction Cascade R-HSA-2514859\n",
      "Elastic Fibre Formation R-HSA-1566948\n",
      "Mismatch Repair (MMR) Directed By MSH2:MSH6 (MutSalpha) R-HSA-5358565\n",
      "Processive Synthesis On Lagging Strand R-HSA-69183\n",
      "Mismatch Repair (MMR) Directed By MSH2:MSH3 (MutSbeta) R-HSA-5358606\n",
      "Phototransduction Cascade R-HSA-2514856\n",
      "RNA polymerase II complex, chromatin structure modifying (human)\n",
      "Integrator-RNAPII complex (human)\n",
      "Parvulin-associated pre-rRNP complex (mouse)\n",
      "PCAF complex (human)\n",
      "DNA synthesome complex (17 subunits) (human)\n",
      "CTF18-cohesion-RFC-POLH complex (human)\n",
      "FCP1-associated protein complex (human)\n",
      "CF IIAm complex (Cleavage factor IIAm complex) (human)\n",
      "BRM-SIN3A-HDAC complex (human)\n",
      "TNF-alpha/NF-kappa B signaling complex 6 (human)\n",
      "TNF-alpha/NF-kappa B signaling complex (CHUK, BTRC, NFKB2, PPP6C, REL, CUL1, IKBKE, SAPS2, SAPS1, ANKRD28, RELA, SKP1) (human)\n",
      "E2F-6 complex (human)\n",
      "BRD4 complex (human)\n",
      "RC complex (Replication competent complex) (human)\n",
      "PBAF complex (Polybromo- and BAF containing complex) (human)\n",
      "Emerin complex 24 (human)\n",
      "DSS1 complex (human)\n",
      "TFIIH transcription factor complex (human)\n",
      "Prefoldin complex (human)\n",
      "Gata1-Fog1-MeCP1 complex (mouse)\n",
      "URI complex (Unconventional prefoldin RPB5 Interactor) (human)\n",
      "BRM-SIN3A complex (human)\n",
      "RSmad complex (human)\n",
      "MLL1-WDR5 complex (human)\n",
      "12S U11 snRNP (human)\n",
      "BRAFT complex (human)\n",
      "FA complex (Fanconi anemia complex) (human)\n",
      "SMN complex (human)\n",
      "p400-associated complex (human)\n",
      "GCN5-TRRAP histone acetyltransferase complex (human)\n",
      "Anaphase-promoting complex (human)\n",
      "BAF complex (human)\n",
      "UTX-MLL2/3 complex (human)\n",
      "Rnase/Mrp complex (human)\n",
      "NCOR2 complex (human)\n",
      "NUMAC complex (nucleosomal methylation activator complex) (human)\n",
      "PA700 complex (human)\n",
      "Cell cycle kinase complex CDC2 (human)\n",
      "CDC5L core complex (human)\n",
      "SRCAP-associated chromatin remodeling complex (human)\n",
      "5S-DNA-TFIIIA-TFIIIC2-TFIIIB subcomplex (human)\n",
      "Respiratory chain complex I, mitochondrial (mouse)\n",
      "TRAP complex (human)\n",
      "TNF-alpha/NF-kappa B signaling complex 5 (human)\n",
      "HCF-1 complex (human)\n",
      "SMN-PolII-RHA complex (human)\n",
      "DAB complex (human)\n",
      "mRNA decay complex (UPF1, UPF2, UPF3B, DCP2, XRN1, XRN2, EXOSC2, EXOSC4, EXOSC10, PARN) (human)\n",
      "TFTC-type histone acetyl transferase complex (human)\n",
      "BLM complex II (human)\n",
      "ARC-L complex (human)\n",
      "RNA polymerase II (RNAPII) (human)\n",
      "PA28gamma-20S proteasome (human)\n",
      "BRG1-SIN3A complex (human)\n",
      "5S-DNA-TFIIIA-TFIIIC2 subcomplex (human)\n",
      "LSm1-7 complex (human)\n",
      "NCOR1 complex (human)\n",
      "PA28-20S proteasome (human)\n",
      "TFTC complex (TATA-binding protein-free TAF-II-containing complex) (human)\n",
      "PC2 complex (human)\n",
      "SNF2h-cohesin-NuRD complex (human)\n",
      "Respiratory chain complex I (early intermediate NDUFAF1 assembly), mitochondrial (human)\n",
      "RC complex during G2/M-phase of cell cycle (human)\n",
      "Polycystin-1 multiprotein complex (ACTN1, CDH1, SRC, JUP, VCL, CTNNB1, PXN, BCAR1, PKD1, PTK2, TLN1) (human)\n",
      "Anti-HDAC2 complex (human)\n",
      "p300-CBP-p270-SWI/SNF complex (human)\n",
      "Ubiquitin E3 ligase (CSN1, CSN8, HRT1, SKP1, SKP2, CUL1, CUL2, CUL3) (human)\n",
      "TFIID complex (mouse)\n",
      "TFIID complex (human)\n",
      "TNF-alpha/NF-kappa B signaling complex (SEC16A, CHUK, IKBKB, NFKB2, REL, IKBKG, MAP3K14, RELA, FBXW7, USP2) (human)\n",
      "NAT complex (human)\n",
      "EBAFb complex (human)\n",
      "Nop56p-associated pre-rRNA complex (human)\n",
      "DA complex (human)\n",
      "HDAC1-associated core complex cII (human)\n",
      "BRCA1-RNA polymerase II complex (human)\n",
      "p97/VCP-VIMP-DERL1-DERL2-HRD1-SEL1L complex (human)\n",
      "INO80 chromatin remodeling complex (human)\n",
      "ARC complex (human)\n",
      "DRIP complex (human)\n",
      "WINAC complex (human)\n",
      "SIN3-ING1b complex II (human)\n",
      "ING2 complex (human)\n",
      "SIN3-SAP25 complex (human)\n",
      "COP9 signalosome complex (human)\n",
      "Integrator complex (human)\n",
      "CtBP complex (human)\n",
      "ESR1-CDK7-CCNH-MNAT1-MTA1-HDAC2 complex (human)\n",
      "26S proteasome (human)\n",
      "ESCRT-III complex (human)\n",
      "SIN3-ING1b complex I (human)\n",
      "HDAC2-asscociated core complex (human)\n",
      "CHUK-NFKB2-REL-IKBKG-SPAG9-NFKB1-NFKBIE-COPB2-TNIP1-NFKBIA-RELA-TNIP2 complex (human)\n",
      "SWI-SNF chromatin remodeling-related-BRCA1 complex (human)\n",
      "STAGA complex (SPT3-TAF9-GCN5 acetyltransferase complex) (human)\n",
      "Cytochrome c oxidase (EC 1.9.3.1), mitochondrial (mouse)\n",
      "NuA4/Tip60-HAT complex B (human)\n",
      "LARC complex (LCR-associated remodeling complex) (human)\n",
      "MeCP1 complex (human)\n",
      "HES1 promoter-Notch enhancer complex (human)\n",
      "NuA4/Tip60-HAT complex A (human)\n",
      "Exosome (human)\n",
      "18S U11/U12 snRNP (human)\n",
      "Conserved oligomeric Golgi (COG) complex (human)\n",
      "Emerin complex 25 (human)\n",
      "TNF-alpha/Nf-kappa B signaling complex (RPL6, RPL30, RPS13, CHUK, DDX3X, NFKB2, NFKBIB, REL, IKBKG, NFKB1, MAP3K8, RELB, GLG1, NFKBIA, RELA, TNIP2,  GTF2I) (human)\n",
      "BRD4-RFC complex (human)\n",
      "Ubiquitin E3 ligase (AHR, ARNT, DDB1, TBL3, CUL4B, RBX1) (human)\n",
      "CRM1-RAN-PHAX-CBC complex (cap binding complex) (human)\n",
      "RNA polymerase II holoenzyme complex (human)\n",
      "BRCA1-core RNA polymerase II complex (human)\n",
      "RC complex during S-phase of cell cycle (human)\n",
      "TNF-alpha/NF-kappa B signaling complex (CHUK, KPNA3, NFKB2, NFKBIB, REL, IKBKG,  NFKB1, NFKBIE, RELB,  NFKBIA, RELA, TNIP2) (human)\n",
      "LSm2-8 complex (human)\n",
      "Toposome (human)\n",
      "ARC92-Mediator complex (human)\n",
      "CSA complex (human)\n",
      "CENP-A NAC-CAD complex (human)\n",
      "CCT complex (chaperonin containing TCP1 complex) (mouse)\n",
      "CSA-POLIIa complex (human)\n",
      "PTIP-DNA damage response complex (human)\n",
      "BRCA1-BARD1-BACH1-DNA damage complex II (human)\n",
      "cMYC-ATPase-helicase complex (human)\n",
      "Anaphase-promoting complex (mouse)\n",
      "Large Drosha complex (human)\n",
      "CRSP complex (human)\n",
      "SMCC complex (human)\n",
      "17S U2 snRNP (human)\n",
      "TRAP-SMCC mediator complex (human)\n",
      "MTA2 complex (human)\n",
      "Mediator complex (mouse)\n",
      "Anti-Sm protein complex (human)\n",
      "20S proteasome (human)\n",
      "DMAP1-associated complex (human)\n",
      "RNA polymerase II complex, incomplete (CDK8 complex), chromatin structure modifying (human)\n",
      "Cytochrome bc1-complex (EC 1.10.2.2), mitochondrial (mouse)\n",
      "RAD17-RFC-9-1-1 checkpoint supercomplex (human)\n",
      "TFIID complex, B-cell specific (human)\n",
      "CEN complex (human)\n",
      "DDB2 complex (human)\n",
      "BASC complex (BRCA1-associated genome surveillance complex) (human)\n",
      "CRSP-Mediator 2 complex (human)\n",
      "RNA polymerase II core complex (human)\n",
      "MDC1-MRN-ATM-FANCD2 complex (human)\n",
      "PCNA-CHL12-RFC2-5 complex (human)\n",
      "EBAFa complex (human)\n",
      "Condensin II (human)\n",
      "Kaiso-NCOR complex (human)\n",
      "SF3b complex (human)\n",
      "PTIP-HMT complex (human)\n",
      "Nup 107-160 subcomplex (human)\n",
      "p27-cyclinE-Cdk2 - Ubiquitin E3 ligase (SKP1A, SKP2, CUL1, CKS1B, RBX1) complex (human)\n",
      "TFIID-beta complex (human)\n",
      "PYR complex (mouse)\n",
      "Kinase maturation complex 1 (human)\n",
      "immunoproteasome (mouse)\n",
      "ALL-1 supercomplex (human)\n",
      "Emerin complex 32 (human)\n",
      "Ikaros complex (mouse)\n"
     ]
    }
   ],
   "source": [
    "for x in corum_matrix[\"feature\"].unique():\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2766b131",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97fd0a08",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fb27b941602401d91542211134fc71a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14ed27d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# get all modelids that have NA values in the corum matrix\n",
    "corum_matrix[corum_matrix.isna().any(axis=1)][\"ModelID\"].sort_values().unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "484e6f14",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6cdc8f80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1150 rows before dropping NA\n",
      "1150 rows after dropping NA\n",
      "1150 rows before dropping NA\n",
      "958 rows after dropping NA\n",
      "1150 rows before dropping NA\n",
      "958 rows after dropping NA\n",
      "1150 rows before dropping NA\n",
      "958 rows after dropping NA\n"
     ]
    }
   ],
   "source": [
    "# @st.cache_data\n",
    "\n",
    "\n",
    "def compute_pca(df, metadata_columns) -> pd.DataFrame:\n",
    "    \"\"\"Cache PCA result per disease selection.\"\"\"\n",
    "    # df.fillna(0, inplace=True)  # Fill NA with 0 for PCA, or drop rows with NA\n",
    "    print(df.shape[0], \"rows before dropping NA\")\n",
    "    df.dropna(inplace=True)  # PCA can't handle missing values, so drop rows with any NA\n",
    "    print(df.shape[0], \"rows after dropping NA\")\n",
    "    metadata_df = df[metadata_columns]\n",
    "    feat_cols = df.columns.drop(metadata_columns)\n",
    "    if \"source\" in feat_cols:\n",
    "        feat_cols = feat_cols.drop(\"source\")\n",
    "\n",
    "    pca_input = df[feat_cols].apply(pd.to_numeric, errors=\"coerce\")\n",
    "    pca = PCA(n_components=2, random_state=0)\n",
    "    pca_embedding = pca.fit_transform(pca_input)\n",
    "    metadata_df[\"PCA1\"] = pca_embedding[:, 0]\n",
    "    metadata_df[\"PCA2\"] = pca_embedding[:, 1]\n",
    "    return metadata_df\n",
    "\n",
    "\n",
    "pca_single_df = compute_pca(combined_df, [\"ModelID\", \"OncotreePrimaryDisease\"])\n",
    "# save the PCA result to a parquet file for later use in the app\n",
    "pca_single_df.to_parquet(\n",
    "    BASE_DIR / \"data\" / \"pca_embeddings_single_dependencies.parquet\"\n",
    ")\n",
    "\n",
    "pca_latent_reactome_df = compute_pca(\n",
    "    reactome_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"]\n",
    ")\n",
    "pca_latent_corum_df = compute_pca(corum_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"])\n",
    "pca_latent_drug_df = compute_pca(drug_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"])\n",
    "pca_latent_reactome_df.to_parquet(\n",
    "    BASE_DIR / \"data\" / \"pca_embeddings_latent_reactome.parquet\"\n",
    ")\n",
    "pca_latent_corum_df.to_parquet(\n",
    "    BASE_DIR / \"data\" / \"pca_embeddings_latent_corum.parquet\"\n",
    ")\n",
    "pca_latent_drug_df.to_parquet(BASE_DIR / \"data\" / \"pca_embeddings_latent_drug.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc8ccfe3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26a895e4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv (3.13.1)",
   "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.13.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}