gwaybio commited on
Commit
bcd1195
·
verified ·
1 Parent(s): 77d940e

initial deploy

Browse files
.hfignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ *.egg-info/
5
+ .DS_Store
.ruff_cache/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Automatically created by ruff.
2
+ *
.ruff_cache/0.15.18/7559825374925841955 ADDED
Binary file (132 Bytes). View file
 
.ruff_cache/CACHEDIR.TAG ADDED
@@ -0,0 +1 @@
 
 
1
+ Signature: 8a477f597d28d172789f06886806bc55
.streamlit/config.toml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [server]
2
+ fileWatcherType = "none"
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
6
+
7
+ COPY pyproject.toml uv.lock ./
8
+ RUN uv sync --frozen --no-dev
9
+
10
+ COPY . .
11
+
12
+ EXPOSE 7860
13
+
14
+ CMD ["uv", "run", "streamlit", "run", "app.py", \
15
+ "--server.address", "0.0.0.0", \
16
+ "--server.port", "7860", \
17
+ "--server.headless", "true", \
18
+ "--server.fileWatcherType", "none"]
README.md CHANGED
@@ -1,10 +1,91 @@
1
  ---
2
- title: Gene Dependency Explorer
3
- emoji: 👁
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: docker
7
- pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Gene Process Dependency Explorer
3
+ emoji: 🧬
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: docker
7
+ app_port: 7860
8
+ pinned: true
9
+ license: bsd-3-clause
10
  ---
11
 
12
+ # Gene Process Dependency Explorer
13
+
14
+ An interactive Streamlit dashboard for exploring gene process dependencies across cancer types, built on [DepMap](https://depmap.org) data and latent representations learned by a Beta Variational Autoencoder (BVAE).
15
+
16
+ This app accompanies the paper:
17
+
18
+ > **Discovering multivariate gene vulnerability patterns in cancer using latent representations of gene dependencies**
19
+ > WayScience · [GitHub](https://github.com/WayScience/gene_dependency_representations)
20
+
21
+ ---
22
+
23
+ ## What the app shows
24
+
25
+ The dashboard has six tabs:
26
+
27
+ | Tab | Description |
28
+ | :-- | :---------- |
29
+ | **Welcome** | Overview and links |
30
+ | **Single dependency plots** | PCA of raw CRISPR gene dependency scores across all cell lines; filter by cancer type |
31
+ | **Latent plots** | PCA of VAE latent representations for Reactome, CORUM, and Drug subsets |
32
+ | **Spider plots** | Radar charts of biological process dependency profiles per cell line or cancer type |
33
+ | **Top scores** | Heatmaps and bar charts of highest-scoring processes by cancer type and model ID |
34
+ | **Data table** | Searchable table of all cell lines and their primary diseases |
35
+
36
+ ---
37
+
38
+ ## Running locally
39
+
40
+ The webapp is self-contained with its own [`uv`](https://docs.astral.sh/uv/)-managed environment.
41
+
42
+ ### Prerequisites
43
+
44
+ ```sh
45
+ curl -LsSf https://astral.sh/uv/install.sh | sh
46
+ ```
47
+
48
+ ### Start the app
49
+
50
+ ```sh
51
+ cd 9.webapp
52
+ uv run streamlit run app.py
53
+ ```
54
+
55
+ `uv` creates and populates the virtual environment automatically on first run. The app will be available at `http://localhost:8501`.
56
+
57
+ ### Deploy headless (e.g. on a server)
58
+
59
+ ```sh
60
+ cd 9.webapp
61
+ PORT=8501 uv run streamlit run app.py \
62
+ --server.address 0.0.0.0 \
63
+ --server.headless true \
64
+ --server.port "$PORT" \
65
+ --server.fileWatcherType none
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Data
71
+
72
+ All data files are committed to the repository — no external downloads needed to run the app.
73
+
74
+ | File | Size | Description |
75
+ | :--- | ---: | :---------- |
76
+ | `data/Model.parquet` | 188 KB | DepMap cell line metadata |
77
+ | `data/pca_embeddings_single_dependencies.parquet` | 34 KB | Pre-computed PCA of raw gene dependency scores |
78
+ | `data/pca_embeddings_latent_reactome.parquet` | 27 KB | Pre-computed PCA of Reactome latent scores |
79
+ | `data/pca_embeddings_latent_corum.parquet` | 27 KB | Pre-computed PCA of CORUM latent scores |
80
+ | `data/pca_embeddings_latent_drug.parquet` | 27 KB | Pre-computed PCA of drug latent scores |
81
+ | `data/all_reactome_results.parquet` | 1.7 MB | Full Reactome latent scores (spider + heatmap tabs) |
82
+ | `data/all_corum_results.parquet` | 1.7 MB | Full CORUM latent scores |
83
+ | `data/all_drug_results.parquet` | 4.1 MB | Full drug latent scores |
84
+
85
+ Raw DepMap files (`CRISPRGeneEffect.parquet` etc.) are **not** required by the webapp and are gitignored. Download them via [`0.data-download/`](../0.data-download/) if you need to re-run the full analysis pipeline.
86
+
87
+ ---
88
+
89
+ ## Repository structure
90
+
91
+ This webapp lives in `9.webapp/` within the larger [gene_dependency_representations](https://github.com/WayScience/gene_dependency_representations) repository, which contains the full analysis pipeline from data download through VAE training to result generation.
app.py ADDED
@@ -0,0 +1,790 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Gene Process Dependency Explorer
3
+ """
4
+
5
+ import pathlib
6
+ import textwrap
7
+
8
+ import matplotlib.pyplot as plt
9
+ import pandas as pd
10
+ import plotly.express as px
11
+ import plotly.graph_objects as go
12
+ import streamlit as st
13
+ from app_utils import (
14
+ latent_load_data,
15
+ make_radar,
16
+ spider_load_data,
17
+ )
18
+
19
+ BASE_DIR = pathlib.Path(__file__).parent
20
+
21
+ # ── Page config ───────────────────────────────────────────────────────────────
22
+ st.set_page_config(
23
+ page_title="Gene Process Dependency Explorer",
24
+ page_icon="🧬",
25
+ layout="wide",
26
+ initial_sidebar_state="collapsed",
27
+ )
28
+
29
+ # ── Styling ───────────────────────────────────────────────────────────────────
30
+ st.markdown(
31
+ """
32
+ <style>
33
+ @import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans:wght@300;400;600&display=swap');
34
+
35
+ html, body, [class*="css"] { font-family: 'IBM Plex Sans', sans-serif; }
36
+ .stApp { background: #0d1117; color: #e6edf3; }
37
+
38
+ .metric-card {
39
+ background: #161b22;
40
+ border: 1px solid #30363d;
41
+ border-radius: 8px;
42
+ padding: 16px 20px;
43
+ margin-bottom: 8px;
44
+ }
45
+ .metric-label { font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: 1px; }
46
+ .metric-value { font-size: 28px; font-weight: 600; color: #58a6ff; font-family: 'IBM Plex Mono', monospace; }
47
+
48
+ .control-panel {
49
+ background: #161b22;
50
+ border: 1px solid #21262d;
51
+ border-radius: 8px;
52
+ padding: 16px 20px;
53
+ margin-bottom: 20px;
54
+ }
55
+ .control-label {
56
+ font-size: 11px;
57
+ color: #8b949e;
58
+ font-family: 'IBM Plex Mono', monospace;
59
+ text-transform: uppercase;
60
+ letter-spacing: 0.5px;
61
+ margin-bottom: 4px;
62
+ }
63
+
64
+ h1, h2, h3 { font-family: 'IBM Plex Mono', monospace !important; }
65
+ h1 { color: #58a6ff !important; font-size: 1.6rem !important; }
66
+ h2 { color: #79c0ff !important; font-size: 1.1rem !important; }
67
+ h3 { color: #cdd9e5 !important; font-size: 0.95rem !important; }
68
+
69
+ .section-tag {
70
+ display: inline-block;
71
+ background: #1f2937;
72
+ border: 1px solid #30363d;
73
+ border-radius: 4px;
74
+ padding: 2px 8px;
75
+ font-size: 11px;
76
+ font-family: 'IBM Plex Mono', monospace;
77
+ color: #8b949e;
78
+ margin-bottom: 12px;
79
+ }
80
+
81
+ .stTabs [data-baseweb="tab-list"] { gap: 8px; }
82
+ .stTabs [data-baseweb="tab"] {
83
+ background: #161b22;
84
+ border: 1px solid #30363d;
85
+ border-radius: 6px;
86
+ color: #8b949e;
87
+ font-family: 'IBM Plex Mono', monospace;
88
+ font-size: 12px;
89
+ padding: 6px 16px;
90
+ }
91
+ .stTabs [aria-selected="true"] {
92
+ background: #1f6feb !important;
93
+ border-color: #1f6feb !important;
94
+ color: #ffffff !important;
95
+ }
96
+ </style>
97
+ """,
98
+ unsafe_allow_html=True,
99
+ )
100
+
101
+ # ── Header ────────────────────────────────────────────────────────────────────
102
+ st.markdown("# Gene Process Dependency Explorer")
103
+ st.markdown(
104
+ '<span class="section-tag">DepMap · BioBombe · WayScience</span>',
105
+ unsafe_allow_html=True,
106
+ )
107
+
108
+ # ── Load only the tiny model metadata file at startup (188 KB) ────────────────
109
+ _model_meta = pd.read_parquet(
110
+ BASE_DIR / "data" / "Model.parquet",
111
+ columns=["ModelID", "OncotreePrimaryDisease"],
112
+ )
113
+ ALL_DISEASES = sorted(_model_meta["OncotreePrimaryDisease"].dropna().unique().tolist())
114
+ ALL_MODEL_IDS = sorted(_model_meta["ModelID"].dropna().unique().tolist())
115
+ DEFAULT_MODEL_IDS = ["ACH-000323", "ACH-002083", "ACH-002228"]
116
+ single_gene_pca_df = pd.read_parquet(
117
+ BASE_DIR / "data" / "pca_embeddings_single_dependencies.parquet"
118
+ )
119
+ latent_reactome_pca_df = pd.read_parquet(
120
+ BASE_DIR / "data" / "pca_embeddings_latent_reactome.parquet"
121
+ )
122
+ latent_corum_pca_df = pd.read_parquet(
123
+ BASE_DIR / "data" / "pca_embeddings_latent_corum.parquet"
124
+ )
125
+ latent_drug_pca_df = pd.read_parquet(
126
+ BASE_DIR / "data" / "pca_embeddings_latent_drug.parquet"
127
+ )
128
+ # ── Tabs ──────────────────────────────────────────────────────────────────────
129
+ (
130
+ tab_welcome,
131
+ tab_single,
132
+ tab_latent,
133
+ tab_spider,
134
+ tab_scores,
135
+ tab_table,
136
+ ) = st.tabs(
137
+ [
138
+ "📖 Welcome",
139
+ "📍 Single dependency plots",
140
+ "📍 Latent plots",
141
+ "🕷 Spider plots",
142
+ "📊 Top scores",
143
+ "📋 Data table",
144
+ ]
145
+ )
146
+
147
+
148
+ # ── Helpers ───────────────────────────────────────────────────────────────────
149
+ def disease_controls(key_prefix: str, default_all: bool = True) -> list[str]:
150
+ """Render an All / None button pair + multiselect for disease filtering."""
151
+ st.markdown(
152
+ '<div class="control-label">Primary diseases</div>', unsafe_allow_html=True
153
+ )
154
+ ca, cn = st.columns(2)
155
+ if ca.button("All", key=f"{key_prefix}_dis_all", use_container_width=True):
156
+ st.session_state[f"{key_prefix}_diseases"] = ALL_DISEASES
157
+ if cn.button("None", key=f"{key_prefix}_dis_none", use_container_width=True):
158
+ st.session_state[f"{key_prefix}_diseases"] = []
159
+ return st.multiselect(
160
+ "Primary diseases",
161
+ ALL_DISEASES,
162
+ default=st.session_state.get(
163
+ f"{key_prefix}_diseases", ALL_DISEASES if default_all else []
164
+ ),
165
+ label_visibility="collapsed",
166
+ key=f"{key_prefix}_diseases",
167
+ )
168
+
169
+
170
+ def model_id_controls(key_prefix: str) -> list[str]:
171
+ """Render All / None / Default buttons + multiselect for ModelID filtering."""
172
+ st.markdown('<div class="control-label">Model IDs</div>', unsafe_allow_html=True)
173
+ ca, cn, cd = st.columns(3)
174
+ if ca.button("All", key=f"{key_prefix}_mod_all", use_container_width=True):
175
+ st.session_state[f"{key_prefix}_model_ids"] = ALL_MODEL_IDS
176
+ if cn.button("None", key=f"{key_prefix}_mod_none", use_container_width=True):
177
+ st.session_state[f"{key_prefix}_model_ids"] = []
178
+ if cd.button("Default", key=f"{key_prefix}_mod_default", use_container_width=True):
179
+ st.session_state[f"{key_prefix}_model_ids"] = DEFAULT_MODEL_IDS
180
+ return st.multiselect(
181
+ "Model IDs",
182
+ ALL_MODEL_IDS,
183
+ default=st.session_state.get(f"{key_prefix}_model_ids", DEFAULT_MODEL_IDS),
184
+ label_visibility="collapsed",
185
+ key=f"{key_prefix}_model_ids",
186
+ )
187
+
188
+
189
+ # ────────────────────────────────────────────────────────────────────────────
190
+ # TAB 0 — Intro text
191
+ # ────────────────────────────────────────────────────────────────────────────
192
+ with tab_welcome:
193
+ st.markdown("## Welcome to the Gene Process Dependency Explorer")
194
+ st.markdown(
195
+ "This app allows you to explore gene process dependencies across different cancer types and model IDs."
196
+ )
197
+ st.markdown(
198
+ "We are visualizing latent representations of gene dependencies learned by a compression model trained on DepMap data, with biological processes as features."
199
+ )
200
+ st.markdown(
201
+ "For more details on the data and methods, please see our github repository: https://github.com/WayScience/gene-process-dependencies"
202
+ )
203
+ st.markdown(
204
+ "For more information about the group, please visit the WayScience website: https://wayscience.com"
205
+ )
206
+ st.markdown("---")
207
+ # ─────────────────────────────────────────────────────────────────────────────
208
+ # TAB 1 — Single dependency plots
209
+ # ─────────────────────────────────────────────────────────────────────────────
210
+ with tab_single:
211
+ st.markdown("### Latent Space PCA — single dependency")
212
+ st.markdown(
213
+ "PCA projection of raw gene dependency scores. "
214
+ "Each point is a cancer cell line; colour encodes primary disease."
215
+ )
216
+
217
+ with st.container():
218
+ st.markdown('<div class="control-panel">', unsafe_allow_html=True)
219
+ selected_diseases_single = disease_controls("single")
220
+ st.markdown("</div>", unsafe_allow_html=True)
221
+
222
+ cancer_types = single_gene_pca_df["OncotreePrimaryDisease"].unique()
223
+ color_map = (
224
+ px.colors.qualitative.Plotly
225
+ + px.colors.qualitative.Light24
226
+ + px.colors.qualitative.Dark24
227
+ )
228
+ highlight_color_map = {
229
+ c: color_map[i % len(color_map)] for i, c in enumerate(cancer_types)
230
+ }
231
+
232
+ traces = []
233
+ for cancer in cancer_types:
234
+ df_sub = single_gene_pca_df[
235
+ single_gene_pca_df["OncotreePrimaryDisease"] == cancer
236
+ ]
237
+ is_selected = cancer in selected_diseases_single
238
+ traces.append(
239
+ go.Scatter(
240
+ x=df_sub["PCA1"],
241
+ y=df_sub["PCA2"],
242
+ mode="markers",
243
+ name=cancer,
244
+ marker=dict(
245
+ size=7,
246
+ color=highlight_color_map[cancer] if is_selected else "#3d444d",
247
+ opacity=1.0 if is_selected else 0.3,
248
+ ),
249
+ text=[f"{cancer} | {m}" for m in df_sub["ModelID"]],
250
+ hoverinfo="text" if is_selected else "skip",
251
+ showlegend=is_selected,
252
+ )
253
+ )
254
+
255
+ # Render grayed traces behind colored ones
256
+ traces.sort(key=lambda t: t.name in selected_diseases_single, reverse=True)
257
+
258
+ fig_single = go.Figure(data=traces)
259
+ fig_single.update_layout(
260
+ paper_bgcolor="#0d1117",
261
+ plot_bgcolor="#0d1117",
262
+ font=dict(color="#e6edf3"),
263
+ xaxis=dict(gridcolor="#21262d"),
264
+ yaxis=dict(gridcolor="#21262d"),
265
+ legend=dict(bgcolor="#161b22", bordercolor="#30363d", borderwidth=1),
266
+ height=1200,
267
+ margin=dict(l=40, r=40, t=40, b=40),
268
+ width=800,
269
+ )
270
+ st.plotly_chart(fig_single, use_container_width=True)
271
+
272
+ # ─────────────────────────────────────────────────────────────────────────────
273
+ # TAB 2 — Latent plots
274
+ # ─────────────────────────────────────────────────────────────────────────────
275
+ with tab_latent:
276
+ st.markdown("### Latent Space PCA Projections")
277
+ st.markdown(
278
+ "PCA projection of latent representations learned by the selected compression model. "
279
+ "Each point is a cancer cell line; clusters indicate similar gene dependency profiles."
280
+ )
281
+
282
+ with st.container():
283
+ st.markdown('<div class="control-panel">', unsafe_allow_html=True)
284
+ selected_diseases_latent = disease_controls("latent")
285
+ st.markdown("</div>", unsafe_allow_html=True)
286
+
287
+ for title, pca_df in [
288
+ ("Reactome", latent_reactome_pca_df),
289
+ ("CORUM", latent_corum_pca_df),
290
+ ("Drug", latent_drug_pca_df),
291
+ ]:
292
+ st.markdown(f"#### PCA: {title} Subset")
293
+
294
+ cancer_types = pca_df["OncotreePrimaryDisease"].unique()
295
+ color_map = (
296
+ px.colors.qualitative.Plotly
297
+ + px.colors.qualitative.Light24
298
+ + px.colors.qualitative.Dark24
299
+ )
300
+ highlight_color_map = {
301
+ c: color_map[i % len(color_map)] for i, c in enumerate(cancer_types)
302
+ }
303
+
304
+ traces = []
305
+ for cancer in cancer_types:
306
+ df_sub = pca_df[pca_df["OncotreePrimaryDisease"] == cancer]
307
+ is_selected = cancer in selected_diseases_latent
308
+ traces.append(
309
+ go.Scatter(
310
+ x=df_sub["PCA1"],
311
+ y=df_sub["PCA2"],
312
+ mode="markers",
313
+ name=cancer,
314
+ marker=dict(
315
+ size=7,
316
+ color=highlight_color_map[cancer] if is_selected else "#3d444d",
317
+ opacity=1.0 if is_selected else 0.3,
318
+ ),
319
+ text=[f"{cancer} | {m}" for m in df_sub["ModelID"]],
320
+ hoverinfo="text" if is_selected else "skip",
321
+ showlegend=is_selected,
322
+ )
323
+ )
324
+
325
+ traces.sort(key=lambda t: t.name in selected_diseases_latent, reverse=True)
326
+
327
+ fig = go.Figure(data=traces)
328
+ fig.update_layout(
329
+ paper_bgcolor="#0d1117",
330
+ plot_bgcolor="#0d1117",
331
+ font=dict(color="#e6edf3"),
332
+ xaxis=dict(gridcolor="#21262d"),
333
+ yaxis=dict(gridcolor="#21262d"),
334
+ legend=dict(bgcolor="#161b22", bordercolor="#30363d", borderwidth=1),
335
+ height=600,
336
+ margin=dict(l=40, r=40, t=40, b=40),
337
+ )
338
+ st.plotly_chart(fig, use_container_width=True)
339
+
340
+
341
+ # ─────────────────────────────────────────────────────────────────────────────
342
+ # TAB 3 — Spider plots
343
+ # ─────────────────────────────────────────────────────────────────────────────
344
+ with tab_spider:
345
+ st.markdown("### Biological Process Dependency Profiles — Spider Plots")
346
+ st.markdown(
347
+ "Mean dependency score per biological process category for selected cell lines. "
348
+ "Negative scores indicate stronger dependencies (essential genes)."
349
+ )
350
+
351
+ with st.container():
352
+ st.markdown('<div class="control-panel">', unsafe_allow_html=True)
353
+ sp_c1, sp_c2, sp_c3 = st.columns(3)
354
+
355
+ with sp_c1:
356
+ spider_filter_mode = st.radio(
357
+ "Filter by",
358
+ ["Model IDs", "Cancer Types"],
359
+ horizontal=True,
360
+ key="spider_filter_mode",
361
+ )
362
+
363
+ with sp_c2:
364
+ if spider_filter_mode == "Model IDs":
365
+ st.markdown(
366
+ '<div class="control-label">Model IDs (max 10)</div>',
367
+ unsafe_allow_html=True,
368
+ )
369
+ spider_model_ids = st.multiselect(
370
+ "Model IDs",
371
+ ALL_MODEL_IDS,
372
+ default=st.session_state.get("spider_model_ids", DEFAULT_MODEL_IDS),
373
+ max_selections=10,
374
+ label_visibility="collapsed",
375
+ key="spider_model_ids",
376
+ )
377
+ else:
378
+ st.markdown(
379
+ '<div class="control-label">Cancer Types (max 5)</div>',
380
+ unsafe_allow_html=True,
381
+ )
382
+ spider_cancer_types = st.multiselect(
383
+ "Cancer Types",
384
+ ALL_DISEASES,
385
+ default=st.session_state.get(
386
+ "spider_cancer_types", ALL_DISEASES[:2]
387
+ ),
388
+ max_selections=5,
389
+ label_visibility="collapsed",
390
+ key="spider_cancer_types",
391
+ )
392
+ st.markdown(
393
+ '<div class="control-label">Aggregation</div>',
394
+ unsafe_allow_html=True,
395
+ )
396
+ spider_agg = st.radio(
397
+ "Aggregation",
398
+ ["Mean", "Min", "Max"],
399
+ horizontal=True,
400
+ key="spider_agg",
401
+ label_visibility="collapsed",
402
+ )
403
+
404
+ with sp_c3:
405
+ st.markdown(
406
+ '<div class="control-label">Process limit</div>', unsafe_allow_html=True
407
+ )
408
+ limit_processes = st.toggle(
409
+ "Limit axes", value=False, key="spider_limit_toggle"
410
+ )
411
+ if limit_processes:
412
+ max_processes = st.slider(
413
+ "Max processes per plot",
414
+ min_value=3,
415
+ max_value=50,
416
+ value=20,
417
+ step=1,
418
+ key="spider_max_proc",
419
+ label_visibility="collapsed",
420
+ )
421
+ else:
422
+ max_processes = None
423
+ st.markdown("</div>", unsafe_allow_html=True)
424
+
425
+ dfs, global_max, feature_colnames = spider_load_data()
426
+
427
+ if spider_filter_mode == "Model IDs":
428
+ selected_ids = spider_model_ids
429
+ id_col = "ModelID"
430
+ else:
431
+ selected_ids = (
432
+ spider_cancer_types
433
+ if "spider_cancer_types" in st.session_state or True
434
+ else []
435
+ )
436
+ id_col = "OncotreePrimaryDisease"
437
+ agg_func = {"Mean": "mean", "Min": "min", "Max": "max"}[spider_agg]
438
+
439
+ if len(selected_ids) == 0:
440
+ st.warning(
441
+ "Please select at least one model ID or cancer type to display the plots."
442
+ )
443
+ else:
444
+ fig_spider, axes = plt.subplots(
445
+ 3, 1, figsize=(18, 12), subplot_kw=dict(polar=True)
446
+ )
447
+
448
+ for ax, (title, df) in zip(axes, dfs.items()):
449
+ cols = feature_colnames[title]
450
+ if spider_filter_mode == "Cancer Types":
451
+ df_filtered = df[df["OncotreePrimaryDisease"].isin(selected_ids)].copy()
452
+
453
+ # cols from feature_colnames[title] is the correct feature column list
454
+ feature_cols = list(cols) if not isinstance(cols, list) else cols
455
+ st.write("feature_colnames:", feature_colnames)
456
+
457
+ df_agg = (
458
+ df_filtered.groupby("OncotreePrimaryDisease")[feature_cols]
459
+ .agg(agg_func)
460
+ .reset_index()
461
+ .rename(columns={"OncotreePrimaryDisease": "ModelID"})
462
+ )
463
+
464
+ # Melt to long format — use a fixed string for var_name
465
+ df_long = df_agg.melt(
466
+ id_vars="ModelID",
467
+ value_vars=feature_cols,
468
+ var_name="feature", # fixed string, not cols
469
+ value_name="agg_score",
470
+ )
471
+
472
+ make_radar(
473
+ ax,
474
+ df_long,
475
+ "feature", # must match var_name above
476
+ f"{title} ({spider_agg})",
477
+ global_max,
478
+ score_col="agg_score",
479
+ model_ids=selected_ids,
480
+ max_processes=max_processes,
481
+ )
482
+ else:
483
+ df_filtered = df[df["ModelID"].isin(selected_ids)].copy()
484
+ make_radar(
485
+ ax,
486
+ df_filtered,
487
+ cols,
488
+ title,
489
+ global_max,
490
+ model_ids=selected_ids,
491
+ max_processes=max_processes,
492
+ )
493
+
494
+ handles, labels = axes[0].get_legend_handles_labels()
495
+ fig_spider.legend(
496
+ handles,
497
+ labels,
498
+ loc="lower center",
499
+ ncol=3,
500
+ fontsize=12,
501
+ frameon=False,
502
+ bbox_to_anchor=(0.5, -0.05),
503
+ )
504
+ plt.tight_layout(rect=[0, 0, 1, 0.95])
505
+ st.pyplot(fig_spider)
506
+
507
+ # ─────────────────────────────────────────────────────────────────────────────
508
+ # TAB 4 — Top scores
509
+ # ─────────────────────────────────────────────────────────────────────────────
510
+ with tab_scores:
511
+ st.markdown("### Top Dependency Scores")
512
+ st.markdown(
513
+ "Highest-scoring biological processes across cancer types and individual cell lines."
514
+ )
515
+
516
+ reactome_matrix, corum_matrix, drug_matrix = latent_load_data()
517
+ all_matrices = {
518
+ "Reactome": reactome_matrix,
519
+ "CORUM": corum_matrix,
520
+ "Drug": drug_matrix,
521
+ }
522
+
523
+ with st.container():
524
+ st.markdown('<div class="control-panel">', unsafe_allow_html=True)
525
+ ctl1, ctl2, ctl3, ctl4, ctl5 = st.columns(5)
526
+ with ctl1:
527
+ selected_diseases_scores = disease_controls("scores")
528
+ with ctl2:
529
+ scores_dataset = st.selectbox(
530
+ "Dataset",
531
+ options=["Reactome", "CORUM", "Drug"],
532
+ key="scores_dataset",
533
+ )
534
+ with ctl3:
535
+ top_n_scores = st.slider(
536
+ "Top N processes",
537
+ min_value=3,
538
+ max_value=50,
539
+ value=15,
540
+ step=1,
541
+ key="scores_top_n",
542
+ )
543
+ with ctl4:
544
+ top_m_types = st.slider(
545
+ "Top M cancer types",
546
+ min_value=1,
547
+ max_value=len(selected_diseases_scores),
548
+ value=8,
549
+ step=1,
550
+ key="scores_top_m",
551
+ )
552
+ with ctl5:
553
+ top_i_models = st.slider(
554
+ "Top I model IDs",
555
+ min_value=1,
556
+ max_value=30,
557
+ value=8,
558
+ step=1,
559
+ key="scores_top_i",
560
+ )
561
+ st.markdown("</div>", unsafe_allow_html=True)
562
+
563
+ score_df = all_matrices[scores_dataset].copy()
564
+ score_df = score_df[
565
+ score_df["OncotreePrimaryDisease"].isin(selected_diseases_scores)
566
+ ]
567
+ meta_cols = ["ModelID", "OncotreePrimaryDisease"]
568
+ score_cols = [c for c in score_df.columns if c not in meta_cols]
569
+
570
+ # ── Heatmap: cancer types ─────────────────────────────────────────
571
+ st.markdown("---")
572
+ st.markdown("#### By cancer type")
573
+ st.markdown(
574
+ "Mean dependency score per process averaged across all cell lines in each cancer type. "
575
+ "Top N processes by max mean score across shown cancer types."
576
+ )
577
+
578
+ disease_means = (
579
+ score_df.groupby("OncotreePrimaryDisease")[score_cols].mean().reset_index()
580
+ )
581
+ disease_means["_max"] = disease_means[score_cols].max(axis=1)
582
+ top_diseases = disease_means.nlargest(top_m_types, "_max")[
583
+ "OncotreePrimaryDisease"
584
+ ].tolist()
585
+ disease_means = disease_means[
586
+ disease_means["OncotreePrimaryDisease"].isin(top_diseases)
587
+ ].drop(columns=["_max"])
588
+ top_processes = (
589
+ disease_means[score_cols].max(axis=0).nlargest(top_n_scores).index.tolist()
590
+ )
591
+ heatmap_disease = disease_means.set_index("OncotreePrimaryDisease")[top_processes]
592
+
593
+ fig_disease = go.Figure(
594
+ go.Heatmap(
595
+ z=heatmap_disease.values,
596
+ x=[
597
+ textwrap.shorten(p, width=30, placeholder="…")
598
+ for p in heatmap_disease.columns
599
+ ],
600
+ y=heatmap_disease.index.tolist(),
601
+ colorscale="Blues",
602
+ hovertemplate="Disease: %{y}<br>Process: %{x}<br>Score: %{z:.3f}<extra></extra>",
603
+ colorbar=dict(title="Mean score", thickness=14, len=0.6),
604
+ )
605
+ )
606
+ fig_disease.update_layout(
607
+ height=max(300, top_m_types * 36 + 120),
608
+ margin=dict(l=20, r=20, t=30, b=120),
609
+ paper_bgcolor="#0d1117",
610
+ plot_bgcolor="#0d1117",
611
+ font=dict(color="#e6edf3", size=11),
612
+ xaxis=dict(tickangle=-40, gridcolor="#21262d"),
613
+ yaxis=dict(gridcolor="#21262d"),
614
+ )
615
+ st.plotly_chart(fig_disease, use_container_width=True)
616
+
617
+ # ── Heatmap: model IDs ────────────────────────────────────────────
618
+ st.markdown("---")
619
+ st.markdown("#### By model ID")
620
+ st.markdown(
621
+ "Raw dependency score per process for individual cell lines ranked by peak score."
622
+ )
623
+
624
+ score_df["_max"] = score_df[score_cols].max(axis=1)
625
+ top_models = score_df.nlargest(top_i_models, "_max")["ModelID"].tolist()
626
+ score_df = score_df.drop(columns=["_max"])
627
+ model_df = score_df[score_df["ModelID"].isin(top_models)].set_index("ModelID")[
628
+ top_processes
629
+ ]
630
+
631
+ fig_model = go.Figure(
632
+ go.Heatmap(
633
+ z=model_df.values,
634
+ x=[
635
+ textwrap.shorten(p, width=30, placeholder="…") for p in model_df.columns
636
+ ],
637
+ y=model_df.index.tolist(),
638
+ colorscale="Purples",
639
+ hovertemplate="Model: %{y}<br>Process: %{x}<br>Score: %{z:.3f}<extra></extra>",
640
+ colorbar=dict(title="Score", thickness=14, len=0.6),
641
+ )
642
+ )
643
+ fig_model.update_layout(
644
+ height=max(300, top_i_models * 36 + 120),
645
+ margin=dict(l=20, r=20, t=30, b=120),
646
+ paper_bgcolor="#0d1117",
647
+ plot_bgcolor="#0d1117",
648
+ font=dict(color="#e6edf3", size=11),
649
+ xaxis=dict(tickangle=-40, gridcolor="#21262d"),
650
+ yaxis=dict(gridcolor="#21262d"),
651
+ )
652
+ st.plotly_chart(fig_model, use_container_width=True)
653
+
654
+ # ── Bar charts ────────────────────────────────────────────────────
655
+ st.markdown("---")
656
+ st.markdown("#### Overall top processes")
657
+ st.markdown("Global mean score per process across all filtered cell lines, ranked.")
658
+
659
+ overall_means = score_df[score_cols].mean().nlargest(top_n_scores).reset_index()
660
+ overall_means.columns = ["Process", "Mean Score"]
661
+ overall_means["Process"] = overall_means["Process"].apply(
662
+ lambda p: textwrap.shorten(p, width=40, placeholder="…")
663
+ )
664
+
665
+ bar1, bar2 = st.columns(2)
666
+
667
+ _bar_layout = dict(
668
+ margin=dict(l=10, r=10, t=40, b=20),
669
+ paper_bgcolor="#0d1117",
670
+ plot_bgcolor="#0d1117",
671
+ font=dict(color="#e6edf3", size=11),
672
+ yaxis=dict(autorange="reversed", gridcolor="#21262d"),
673
+ xaxis=dict(gridcolor="#21262d"),
674
+ coloraxis_showscale=False,
675
+ showlegend=False,
676
+ )
677
+
678
+ with bar1:
679
+ fig_bar_all = px.bar(
680
+ overall_means,
681
+ x="Mean Score",
682
+ y="Process",
683
+ orientation="h",
684
+ title="Top processes — all cell lines",
685
+ color="Mean Score",
686
+ color_continuous_scale="Blues",
687
+ )
688
+ fig_bar_all.update_layout(
689
+ height=max(300, top_n_scores * 24 + 80), **_bar_layout
690
+ )
691
+ st.plotly_chart(fig_bar_all, use_container_width=True)
692
+
693
+ with bar2:
694
+ top_disease_means = (
695
+ score_df[score_df["OncotreePrimaryDisease"].isin(top_diseases)][score_cols]
696
+ .mean()
697
+ .nlargest(top_n_scores)
698
+ .reset_index()
699
+ )
700
+ top_disease_means.columns = ["Process", "Mean Score"]
701
+ top_disease_means["Process"] = top_disease_means["Process"].apply(
702
+ lambda p: textwrap.shorten(p, width=40, placeholder="…")
703
+ )
704
+ fig_bar_top = px.bar(
705
+ top_disease_means,
706
+ x="Mean Score",
707
+ y="Process",
708
+ orientation="h",
709
+ title=f"Top processes — top {top_m_types} cancer types",
710
+ color="Mean Score",
711
+ color_continuous_scale="Purples",
712
+ )
713
+ fig_bar_top.update_layout(
714
+ height=max(300, top_n_scores * 24 + 80), **_bar_layout
715
+ )
716
+ st.plotly_chart(fig_bar_top, use_container_width=True)
717
+
718
+
719
+ # ─────────────────────────────────────────────────────────────────────────────
720
+ # TAB 5 — Data table
721
+ # ─────────────────────────────────────────────────────────────────────────────
722
+ with tab_table:
723
+ st.markdown("### Cancer Types & Primary Diseases")
724
+ st.markdown("Summary of all cancer types and their associated primary diseases.")
725
+
726
+ with st.container():
727
+ st.markdown('<div class="control-panel">', unsafe_allow_html=True)
728
+ selected_diseases_table = disease_controls("table")
729
+ st.markdown("</div>", unsafe_allow_html=True)
730
+
731
+ reactome_matrix, _, _ = latent_load_data()
732
+ full_df = reactome_matrix[
733
+ reactome_matrix["OncotreePrimaryDisease"].isin(selected_diseases_table)
734
+ ]
735
+
736
+ summary = (
737
+ full_df.groupby(["OncotreePrimaryDisease", "ModelID"], dropna=False)
738
+ .size()
739
+ .reset_index(name="_n")
740
+ .drop(columns=["_n"])
741
+ .drop_duplicates()
742
+ .rename(columns={"OncotreePrimaryDisease": "Primary Disease"})
743
+ .sort_values(["Primary Disease", "ModelID"])
744
+ )
745
+
746
+ m1, m2 = st.columns(2)
747
+ m1.markdown(
748
+ f'<div class="metric-card"><div class="metric-label">Primary diseases</div><div class="metric-value">{summary["Primary Disease"].nunique()}</div></div>',
749
+ unsafe_allow_html=True,
750
+ )
751
+ m2.markdown(
752
+ f'<div class="metric-card"><div class="metric-label">Total cell lines</div><div class="metric-value">{int(summary["ModelID"].nunique())}</div></div>',
753
+ unsafe_allow_html=True,
754
+ )
755
+ st.markdown("")
756
+
757
+ sc1, sc2 = st.columns([3, 1])
758
+ with sc1:
759
+ sort_by = st.selectbox(
760
+ "Sort by", options=summary.columns.tolist(), index=0, key="table_sort_col"
761
+ )
762
+ with sc2:
763
+ sort_asc = st.radio(
764
+ "Order",
765
+ ["Ascending", "Descending"],
766
+ index=0,
767
+ horizontal=True,
768
+ key="table_sort_dir",
769
+ )
770
+
771
+ summary = summary.sort_values(sort_by, ascending=(sort_asc == "Ascending"))
772
+
773
+ st.dataframe(
774
+ summary.reset_index(drop=True),
775
+ use_container_width=True,
776
+ height=560,
777
+ column_config={
778
+ "Primary Disease": st.column_config.TextColumn(width="large"),
779
+ "ModelID": st.column_config.TextColumn("Model ID", width="large"),
780
+ },
781
+ hide_index=True,
782
+ )
783
+
784
+ st.download_button(
785
+ label="⬇ Download as CSV",
786
+ data=summary.to_csv(index=False).encode("utf-8"),
787
+ file_name="cancer_types_diseases.csv",
788
+ mime="text/csv",
789
+ key="table_download",
790
+ )
app_utils.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import colorsys
2
+ import pathlib
3
+ import random
4
+ import textwrap
5
+
6
+ import numpy as np
7
+ import pandas as pd
8
+ import streamlit as st
9
+
10
+ BASE_DIR = pathlib.Path(__file__).parent
11
+ DATA_DIR = BASE_DIR / "data"
12
+
13
+
14
+ @st.cache_data
15
+ def latent_load_data():
16
+ reactome_dims = DATA_DIR / "all_reactome_results.parquet"
17
+ corum_dims = DATA_DIR / "all_corum_results.parquet"
18
+ drug_dims = DATA_DIR / "all_drug_results.parquet"
19
+
20
+ reactome_df = pd.read_parquet(reactome_dims)
21
+ corum_df = pd.read_parquet(corum_dims)
22
+ drug_df = pd.read_parquet(drug_dims)
23
+
24
+ reactome_df["feature"] = reactome_df["reactome_pathway"]
25
+ reactome_df = reactome_df.drop(
26
+ columns=["model", "latent_dim_total", "init", "seed", "z", "reactome_pathway"]
27
+ )
28
+
29
+ corum_df["feature"] = corum_df["reactome_pathway"]
30
+ corum_df = corum_df.drop(
31
+ columns=["model", "latent_dim_total", "init", "seed", "z", "reactome_pathway"]
32
+ )
33
+
34
+ drug_df["feature"] = drug_df["name"]
35
+ drug_df = drug_df.drop(
36
+ columns=["model", "latent_dim_total", "init", "seed", "z", "name"]
37
+ )
38
+
39
+ meta_cols = ["ModelID", "OncotreePrimaryDisease"]
40
+ reactome_meta = reactome_df[meta_cols].drop_duplicates()
41
+ corum_meta = corum_df[meta_cols].drop_duplicates()
42
+ drug_meta = drug_df[meta_cols].drop_duplicates()
43
+
44
+ reactome_matrix = reactome_df.pivot(
45
+ index="ModelID", columns="feature", values="latent_score"
46
+ )
47
+ corum_matrix = corum_df.pivot(
48
+ index="ModelID", columns="feature", values="latent_score"
49
+ )
50
+ drug_matrix = drug_df.pivot(
51
+ index="ModelID", columns="feature", values="latent_score"
52
+ )
53
+
54
+ reactome_matrix = reactome_matrix.merge(reactome_meta, on="ModelID", how="left")
55
+ corum_matrix = corum_matrix.merge(corum_meta, on="ModelID", how="left")
56
+ drug_matrix = drug_matrix.merge(drug_meta, on="ModelID", how="left")
57
+
58
+ return reactome_matrix, corum_matrix, drug_matrix
59
+
60
+
61
+ @st.cache_data
62
+ def spider_load_data():
63
+ files = {
64
+ "Reactome Pathways": DATA_DIR / "all_reactome_results.parquet",
65
+ "CORUM Complexes": DATA_DIR / "all_corum_results.parquet",
66
+ "Drug Responses": DATA_DIR / "all_drug_results.parquet",
67
+ }
68
+ feature_colnames = {
69
+ "Reactome Pathways": "reactome_pathway",
70
+ "CORUM Complexes": "reactome_pathway",
71
+ "Drug Responses": "name",
72
+ }
73
+ score_col = "pathway_score"
74
+
75
+ global_max = 0
76
+ dfs = {}
77
+ for name, file in files.items():
78
+ df = pd.read_parquet(file)
79
+ dfs[name] = df
80
+ if df[score_col].max() > global_max:
81
+ global_max = df[score_col].max()
82
+
83
+ return dfs, global_max, feature_colnames
84
+
85
+
86
+ def clean_label(x: str) -> str:
87
+ if "Polymerase Switching" in x:
88
+ return "Polymerase Switching"
89
+ if "Negative Regulation Of MET" in x or "Negative Regulation of MET" in x:
90
+ return "Negative MET Regulation"
91
+ return truncate_label(x)
92
+
93
+
94
+ def truncate_label(
95
+ label: str,
96
+ max_chars_per_line: int = 22,
97
+ max_total_words: int = 4,
98
+ max_lines: int = 2,
99
+ ) -> str:
100
+ words = label.split()
101
+ short = " ".join(words[:max_total_words])
102
+ lines = textwrap.wrap(short, width=max_chars_per_line)
103
+ if len(lines) > max_lines:
104
+ lines = lines[:max_lines]
105
+ wrapped = "\n".join(lines)
106
+ if len(words) > max_total_words or (
107
+ len(lines) >= max_lines
108
+ and len(lines) < len(textwrap.wrap(short, width=max_chars_per_line))
109
+ ):
110
+ wrapped += "..."
111
+ return wrapped
112
+
113
+
114
+ def place_labels_polar(ax, angles, labels, radius: float) -> None:
115
+ for angle, label in zip(angles[:-1], labels):
116
+ if 0 <= angle <= np.pi / 2 or 3 * np.pi / 2 <= angle <= 2 * np.pi:
117
+ ha = "left"
118
+ else:
119
+ ha = "right"
120
+ ax.text(
121
+ angle, radius, label, fontsize=9, color="black", ha=ha, va="center", wrap=True
122
+ )
123
+
124
+
125
+ def generate_random_palette(num_colors, seed=12):
126
+ random.seed(seed)
127
+ colors = []
128
+ for _ in range(num_colors):
129
+ h = random.random()
130
+ lightness = random.uniform(0.2, 0.8)
131
+ s = random.uniform(0.5, 1.0)
132
+ colors.append(colorsys.hls_to_rgb(h, lightness, s))
133
+ return colors
134
+
135
+
136
+ def generate_model_color_map(model_ids, seed=12):
137
+ colors = generate_random_palette(len(model_ids), seed)
138
+ return {model_id: color for model_id, color in zip(model_ids, colors)}
139
+
140
+
141
+ def make_radar(
142
+ ax,
143
+ df: pd.DataFrame,
144
+ feature_col: str,
145
+ title: str,
146
+ global_max: float,
147
+ score_col: str = "pathway_score",
148
+ model_ids: list = ["ACH-000323", "ACH-002083", "ACH-002228"],
149
+ num_circles: int = 5,
150
+ max_processes: int = None,
151
+ ) -> None:
152
+ if model_ids == ["ACH-000323", "ACH-002083", "ACH-002228"]:
153
+ model_colors = {
154
+ "ACH-000323": "#00FFFF",
155
+ "ACH-002083": "#FF69B4",
156
+ "ACH-002228": "#800080",
157
+ }
158
+ else:
159
+ model_colors = generate_model_color_map(model_ids, seed=12)
160
+
161
+ top_by_model = (
162
+ df.groupby("ModelID", group_keys=False)
163
+ .apply(lambda x: x.nlargest(5, score_col))
164
+ .reset_index(drop=True)
165
+ )
166
+ top_features = top_by_model[feature_col].drop_duplicates().tolist()
167
+ if max_processes is not None:
168
+ top_features = top_features[:max_processes]
169
+ n_vars = len(top_features)
170
+ labels = [clean_label(x) for x in top_features]
171
+
172
+ angles = np.linspace(0, 2 * np.pi, n_vars, endpoint=False).tolist()
173
+ angles += [angles[0]]
174
+
175
+ circle_levels = np.linspace(0, global_max, num_circles + 1)[1:]
176
+ for r in circle_levels:
177
+ ax.plot(
178
+ angles, [r] * (n_vars + 1), color="grey", linestyle="--", linewidth=1, zorder=0
179
+ )
180
+
181
+ for mid in model_ids:
182
+ subset = df[df["ModelID"] == mid]
183
+ merged = pd.DataFrame({feature_col: top_features}).merge(
184
+ subset[[feature_col, score_col]], on=feature_col, how="left"
185
+ )
186
+ values = merged[score_col].fillna(0).tolist()
187
+ values += [values[0]]
188
+ ax.plot(angles, values, color=model_colors[mid], linewidth=3, label=mid)
189
+ ax.scatter(
190
+ angles, values, color=model_colors[mid], s=30, edgecolor="black", zorder=5
191
+ )
192
+
193
+ ax.set_ylim(0, global_max * 1.25)
194
+ ax.set_xticks([])
195
+ ax.set_yticks([])
196
+ ax.set_aspect("equal")
197
+ place_labels_polar(ax, angles, labels, global_max * 1.4)
198
+ ax.set_title(title, fontsize=18, pad=30, fontweight="bold", y=1)
data/Model.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e18aaaceb0f2b4d013cf6ed6da351a63cdc0ccba89967d8f146ce03793b7b0c0
3
+ size 192916
data/all_corum_results.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:019448878b257d1c3f1afe282730fceac7b329d63f8008d327c9d7e3b6a470a1
3
+ size 1739705
data/all_drug_results.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d10b2c538245ae0e5df8ca2b57236741a0576d0624082c5383fd8323e375f8c
3
+ size 4275240
data/all_reactome_results.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c9a24692feeec0c607dcb24b59049481d5a8f70c6edc3fdfa4e54b84d83579c
3
+ size 7107699
data/pca_embeddings_latent_corum.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea55d89c2344f42b991c75b304e8c7979f5fc12614626c62b9e4da094c573d01
3
+ size 27185
data/pca_embeddings_latent_drug.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:743e0bd874634a435595a9a47a41e6287e640da12d43724a5fd9b5ad7500e980
3
+ size 27185
data/pca_embeddings_latent_reactome.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:578278837ff1802c869e8ab84c642d692004edaa8dce144d89d49a0ef99d66b8
3
+ size 27185
data/pca_embeddings_single_dependencies.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52f2a39dbbeb503163175267b61db8b64da0def08bc821b920382b90e16eb7a9
3
+ size 34741
gene_dependency_webapp.egg-info/PKG-INFO ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: gene-dependency-webapp
3
+ Version: 0.1.0
4
+ Summary: Interactive Streamlit webapp for exploring gene dependency plots
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: streamlit
7
+ Requires-Dist: plotly
8
+ Requires-Dist: pandas
9
+ Requires-Dist: numpy
10
+ Requires-Dist: scikit-learn
11
+ Requires-Dist: pyarrow
12
+ Requires-Dist: umap-learn
13
+ Requires-Dist: matplotlib>=3.10.9
14
+ Requires-Dist: ipykernel>=7.2.0
15
+ Requires-Dist: ipywidgets>=8.1.8
gene_dependency_webapp.egg-info/SOURCES.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ app.py
2
+ app_utils.py
3
+ pyproject.toml
4
+ gene_dependency_webapp.egg-info/PKG-INFO
5
+ gene_dependency_webapp.egg-info/SOURCES.txt
6
+ gene_dependency_webapp.egg-info/dependency_links.txt
7
+ gene_dependency_webapp.egg-info/requires.txt
8
+ gene_dependency_webapp.egg-info/top_level.txt
gene_dependency_webapp.egg-info/dependency_links.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
gene_dependency_webapp.egg-info/requires.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ plotly
3
+ pandas
4
+ numpy
5
+ scikit-learn
6
+ pyarrow
7
+ umap-learn
8
+ matplotlib>=3.10.9
9
+ ipykernel>=7.2.0
10
+ ipywidgets>=8.1.8
gene_dependency_webapp.egg-info/top_level.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ app
2
+ app_utils
preprocessing.ipynb ADDED
@@ -0,0 +1,634 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "6c08a8f0",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "2026-06-09 13:29:16.828 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
14
+ "2026-06-09 13:29:16.829 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
15
+ "2026-06-09 13:29:16.830 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
16
+ "2026-06-09 13:29:16.830 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
17
+ "2026-06-09 13:29:16.831 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n"
18
+ ]
19
+ },
20
+ {
21
+ "name": "stdout",
22
+ "output_type": "stream",
23
+ "text": [
24
+ "Base directory: /home/lippincm/gene-process-dependencies/9.webapp\n",
25
+ "Repo root: /home/lippincm/gene-process-dependencies\n"
26
+ ]
27
+ }
28
+ ],
29
+ "source": [
30
+ "import os\n",
31
+ "import pathlib\n",
32
+ "\n",
33
+ "import numpy as np\n",
34
+ "import pandas as pd\n",
35
+ "import streamlit as st\n",
36
+ "from app_utils import latent_load_data, load_model_data, single_load_data\n",
37
+ "from sklearn.decomposition import PCA"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": 3,
43
+ "id": "328325ad",
44
+ "metadata": {},
45
+ "outputs": [
46
+ {
47
+ "name": "stderr",
48
+ "output_type": "stream",
49
+ "text": [
50
+ "2026-06-09 13:29:16.839 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
51
+ "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"
52
+ ]
53
+ },
54
+ {
55
+ "name": "stdout",
56
+ "output_type": "stream",
57
+ "text": [
58
+ "Base directory: /home/lippincm/gene-process-dependencies/9.webapp\n",
59
+ "Repo root: /home/lippincm/gene-process-dependencies\n"
60
+ ]
61
+ }
62
+ ],
63
+ "source": [
64
+ "_base_reactome, _base_corum, _base_drug = latent_load_data()\n",
65
+ "ALL_DISEASES = sorted(_base_reactome[\"OncotreePrimaryDisease\"].unique().tolist())\n",
66
+ "ALL_MODEL_IDS = sorted(_base_reactome[\"ModelID\"].unique().tolist())\n",
67
+ "# Go up one level to repo root, then into data/\n",
68
+ "BASE_DIR = pathlib.Path().resolve()\n",
69
+ "REPO_ROOT = BASE_DIR.parent\n",
70
+ "REPO_ROOT = BASE_DIR.parent # goes up from 9.webapp/ to repo root\n",
71
+ "print(f\"Base directory: {BASE_DIR}\")\n",
72
+ "print(f\"Repo root: {REPO_ROOT}\")"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 46,
78
+ "id": "37924565",
79
+ "metadata": {},
80
+ "outputs": [
81
+ {
82
+ "name": "stdout",
83
+ "output_type": "stream",
84
+ "text": [
85
+ "(1150, 18444)\n"
86
+ ]
87
+ }
88
+ ],
89
+ "source": [
90
+ "combined_df = single_load_data()\n",
91
+ "data_directory = BASE_DIR / \"data\"\n",
92
+ "dependency_file = data_directory / \"CRISPRGeneEffect.parquet\"\n",
93
+ "gene_dict_file = data_directory / \"CRISPR_gene_dictionary.parquet\"\n",
94
+ "cancer_type_input_file = BASE_DIR / \"data\" / \"Model.parquet\"\n",
95
+ "dependency_df, gene_dict_df = load_model_data(dependency_file, gene_dict_file)\n",
96
+ "dependency_df = dependency_df.set_index(\"ModelID\")\n",
97
+ "cancer_type_input_file = pathlib.Path(f\"{BASE_DIR}/data/Model.parquet\")\n",
98
+ "cancer_type_df = pd.read_parquet(cancer_type_input_file)\n",
99
+ "reactome_matrix, corum_matrix, drug_matrix = latent_load_data()"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "execution_count": null,
105
+ "id": "0ef7365a",
106
+ "metadata": {},
107
+ "outputs": [],
108
+ "source": []
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 63,
113
+ "id": "4f84dac0",
114
+ "metadata": {},
115
+ "outputs": [
116
+ {
117
+ "data": {
118
+ "text/html": [
119
+ "<div>\n",
120
+ "<style scoped>\n",
121
+ " .dataframe tbody tr th:only-of-type {\n",
122
+ " vertical-align: middle;\n",
123
+ " }\n",
124
+ "\n",
125
+ " .dataframe tbody tr th {\n",
126
+ " vertical-align: top;\n",
127
+ " }\n",
128
+ "\n",
129
+ " .dataframe thead th {\n",
130
+ " text-align: right;\n",
131
+ " }\n",
132
+ "</style>\n",
133
+ "<table border=\"1\" class=\"dataframe\">\n",
134
+ " <thead>\n",
135
+ " <tr style=\"text-align: right;\">\n",
136
+ " <th></th>\n",
137
+ " <th>ModelID</th>\n",
138
+ " <th>OncotreePrimaryDisease</th>\n",
139
+ " <th>latent_score</th>\n",
140
+ " <th>gsea_es_score</th>\n",
141
+ " <th>pathway_score</th>\n",
142
+ " <th>feature</th>\n",
143
+ " </tr>\n",
144
+ " </thead>\n",
145
+ " <tbody>\n",
146
+ " <tr>\n",
147
+ " <th>0</th>\n",
148
+ " <td>ACH-000001</td>\n",
149
+ " <td>Ovarian Epithelial Tumor</td>\n",
150
+ " <td>0.392860</td>\n",
151
+ " <td>0.824315</td>\n",
152
+ " <td>0.392860</td>\n",
153
+ " <td>Inactivation, Recovery And Regulation Of Photo...</td>\n",
154
+ " </tr>\n",
155
+ " <tr>\n",
156
+ " <th>1</th>\n",
157
+ " <td>ACH-000001</td>\n",
158
+ " <td>Ovarian Epithelial Tumor</td>\n",
159
+ " <td>0.763630</td>\n",
160
+ " <td>0.880116</td>\n",
161
+ " <td>0.763630</td>\n",
162
+ " <td>Elastic Fibre Formation R-HSA-1566948</td>\n",
163
+ " </tr>\n",
164
+ " <tr>\n",
165
+ " <th>2</th>\n",
166
+ " <td>ACH-000001</td>\n",
167
+ " <td>Ovarian Epithelial Tumor</td>\n",
168
+ " <td>0.435531</td>\n",
169
+ " <td>0.839506</td>\n",
170
+ " <td>0.435531</td>\n",
171
+ " <td>Mismatch Repair (MMR) Directed By MSH2:MSH6 (M...</td>\n",
172
+ " </tr>\n",
173
+ " <tr>\n",
174
+ " <th>3</th>\n",
175
+ " <td>ACH-000001</td>\n",
176
+ " <td>Ovarian Epithelial Tumor</td>\n",
177
+ " <td>0.531491</td>\n",
178
+ " <td>-0.733375</td>\n",
179
+ " <td>0.531491</td>\n",
180
+ " <td>Processive Synthesis On Lagging Strand R-HSA-6...</td>\n",
181
+ " </tr>\n",
182
+ " <tr>\n",
183
+ " <th>4</th>\n",
184
+ " <td>ACH-000001</td>\n",
185
+ " <td>Ovarian Epithelial Tumor</td>\n",
186
+ " <td>0.267750</td>\n",
187
+ " <td>0.864257</td>\n",
188
+ " <td>0.267750</td>\n",
189
+ " <td>Mismatch Repair (MMR) Directed By MSH2:MSH3 (M...</td>\n",
190
+ " </tr>\n",
191
+ " <tr>\n",
192
+ " <th>...</th>\n",
193
+ " <td>...</td>\n",
194
+ " <td>...</td>\n",
195
+ " <td>...</td>\n",
196
+ " <td>...</td>\n",
197
+ " <td>...</td>\n",
198
+ " <td>...</td>\n",
199
+ " </tr>\n",
200
+ " <tr>\n",
201
+ " <th>169777</th>\n",
202
+ " <td>ACH-003012</td>\n",
203
+ " <td>Non-Small Cell Lung Cancer</td>\n",
204
+ " <td>0.505296</td>\n",
205
+ " <td>0.938271</td>\n",
206
+ " <td>0.505296</td>\n",
207
+ " <td>Kinase maturation complex 1 (human)</td>\n",
208
+ " </tr>\n",
209
+ " <tr>\n",
210
+ " <th>169778</th>\n",
211
+ " <td>ACH-003012</td>\n",
212
+ " <td>Non-Small Cell Lung Cancer</td>\n",
213
+ " <td>0.282634</td>\n",
214
+ " <td>0.808217</td>\n",
215
+ " <td>0.282634</td>\n",
216
+ " <td>immunoproteasome (mouse)</td>\n",
217
+ " </tr>\n",
218
+ " <tr>\n",
219
+ " <th>169779</th>\n",
220
+ " <td>ACH-003012</td>\n",
221
+ " <td>Non-Small Cell Lung Cancer</td>\n",
222
+ " <td>0.073697</td>\n",
223
+ " <td>0.748024</td>\n",
224
+ " <td>0.073697</td>\n",
225
+ " <td>ALL-1 supercomplex (human)</td>\n",
226
+ " </tr>\n",
227
+ " <tr>\n",
228
+ " <th>169780</th>\n",
229
+ " <td>ACH-003012</td>\n",
230
+ " <td>Non-Small Cell Lung Cancer</td>\n",
231
+ " <td>0.032945</td>\n",
232
+ " <td>0.739678</td>\n",
233
+ " <td>0.032945</td>\n",
234
+ " <td>Emerin complex 32 (human)</td>\n",
235
+ " </tr>\n",
236
+ " <tr>\n",
237
+ " <th>169781</th>\n",
238
+ " <td>ACH-003012</td>\n",
239
+ " <td>Non-Small Cell Lung Cancer</td>\n",
240
+ " <td>0.283263</td>\n",
241
+ " <td>0.815085</td>\n",
242
+ " <td>0.283263</td>\n",
243
+ " <td>Ikaros complex (mouse)</td>\n",
244
+ " </tr>\n",
245
+ " </tbody>\n",
246
+ "</table>\n",
247
+ "<p>169782 rows × 6 columns</p>\n",
248
+ "</div>"
249
+ ],
250
+ "text/plain": [
251
+ " ModelID OncotreePrimaryDisease latent_score gsea_es_score \\\n",
252
+ "0 ACH-000001 Ovarian Epithelial Tumor 0.392860 0.824315 \n",
253
+ "1 ACH-000001 Ovarian Epithelial Tumor 0.763630 0.880116 \n",
254
+ "2 ACH-000001 Ovarian Epithelial Tumor 0.435531 0.839506 \n",
255
+ "3 ACH-000001 Ovarian Epithelial Tumor 0.531491 -0.733375 \n",
256
+ "4 ACH-000001 Ovarian Epithelial Tumor 0.267750 0.864257 \n",
257
+ "... ... ... ... ... \n",
258
+ "169777 ACH-003012 Non-Small Cell Lung Cancer 0.505296 0.938271 \n",
259
+ "169778 ACH-003012 Non-Small Cell Lung Cancer 0.282634 0.808217 \n",
260
+ "169779 ACH-003012 Non-Small Cell Lung Cancer 0.073697 0.748024 \n",
261
+ "169780 ACH-003012 Non-Small Cell Lung Cancer 0.032945 0.739678 \n",
262
+ "169781 ACH-003012 Non-Small Cell Lung Cancer 0.283263 0.815085 \n",
263
+ "\n",
264
+ " pathway_score feature \n",
265
+ "0 0.392860 Inactivation, Recovery And Regulation Of Photo... \n",
266
+ "1 0.763630 Elastic Fibre Formation R-HSA-1566948 \n",
267
+ "2 0.435531 Mismatch Repair (MMR) Directed By MSH2:MSH6 (M... \n",
268
+ "3 0.531491 Processive Synthesis On Lagging Strand R-HSA-6... \n",
269
+ "4 0.267750 Mismatch Repair (MMR) Directed By MSH2:MSH3 (M... \n",
270
+ "... ... ... \n",
271
+ "169777 0.505296 Kinase maturation complex 1 (human) \n",
272
+ "169778 0.282634 immunoproteasome (mouse) \n",
273
+ "169779 0.073697 ALL-1 supercomplex (human) \n",
274
+ "169780 0.032945 Emerin complex 32 (human) \n",
275
+ "169781 0.283263 Ikaros complex (mouse) \n",
276
+ "\n",
277
+ "[169782 rows x 6 columns]"
278
+ ]
279
+ },
280
+ "execution_count": 63,
281
+ "metadata": {},
282
+ "output_type": "execute_result"
283
+ }
284
+ ],
285
+ "source": [
286
+ "corum_matrix_path = (\n",
287
+ " REPO_ROOT / \"5.drug-dependency\" / \"results\" / \"all_corum_results.parquet\"\n",
288
+ ")\n",
289
+ "corum_matrix = pd.read_parquet(corum_matrix_path)\n",
290
+ "corum_matrix[\"feature\"] = corum_matrix[\"reactome_pathway\"]\n",
291
+ "corum_matrix = corum_matrix.drop(\n",
292
+ " columns=[\"model\", \"latent_dim_total\", \"init\", \"seed\", \"z\", \"reactome_pathway\"]\n",
293
+ ")\n",
294
+ "meta_cols = [\"ModelID\", \"OncotreePrimaryDisease\"]\n",
295
+ "\n",
296
+ "corum_meta = corum_matrix[meta_cols].drop_duplicates()\n",
297
+ "\n",
298
+ "# corum_matrix = corum_matrix.pivot(index=\"ModelID\", columns=\"feature\", values=\"latent_score\")\n",
299
+ "# corum_matrix = corum_matrix.merge(corum_meta, on=\"ModelID\", how=\"left\")\n",
300
+ "# print(corum_matrix.isna().sum().sum())\n",
301
+ "# corum_matrix.drop(columns=['gsea_es_score',\"pathway_score\",\"OncotreePrimaryDisease\"], inplace=True)\n",
302
+ "# corum_matrix.pivot(index=\"ModelID\", columns=\"feature\", values=\"latent_score\")\n",
303
+ "corum_matrix"
304
+ ]
305
+ },
306
+ {
307
+ "cell_type": "code",
308
+ "execution_count": 61,
309
+ "id": "0f7fe22e",
310
+ "metadata": {},
311
+ "outputs": [
312
+ {
313
+ "name": "stdout",
314
+ "output_type": "stream",
315
+ "text": [
316
+ "Inactivation, Recovery And Regulation Of Phototransduction Cascade R-HSA-2514859\n",
317
+ "Elastic Fibre Formation R-HSA-1566948\n",
318
+ "Mismatch Repair (MMR) Directed By MSH2:MSH6 (MutSalpha) R-HSA-5358565\n",
319
+ "Processive Synthesis On Lagging Strand R-HSA-69183\n",
320
+ "Mismatch Repair (MMR) Directed By MSH2:MSH3 (MutSbeta) R-HSA-5358606\n",
321
+ "Phototransduction Cascade R-HSA-2514856\n",
322
+ "RNA polymerase II complex, chromatin structure modifying (human)\n",
323
+ "Integrator-RNAPII complex (human)\n",
324
+ "Parvulin-associated pre-rRNP complex (mouse)\n",
325
+ "PCAF complex (human)\n",
326
+ "DNA synthesome complex (17 subunits) (human)\n",
327
+ "CTF18-cohesion-RFC-POLH complex (human)\n",
328
+ "FCP1-associated protein complex (human)\n",
329
+ "CF IIAm complex (Cleavage factor IIAm complex) (human)\n",
330
+ "BRM-SIN3A-HDAC complex (human)\n",
331
+ "TNF-alpha/NF-kappa B signaling complex 6 (human)\n",
332
+ "TNF-alpha/NF-kappa B signaling complex (CHUK, BTRC, NFKB2, PPP6C, REL, CUL1, IKBKE, SAPS2, SAPS1, ANKRD28, RELA, SKP1) (human)\n",
333
+ "E2F-6 complex (human)\n",
334
+ "BRD4 complex (human)\n",
335
+ "RC complex (Replication competent complex) (human)\n",
336
+ "PBAF complex (Polybromo- and BAF containing complex) (human)\n",
337
+ "Emerin complex 24 (human)\n",
338
+ "DSS1 complex (human)\n",
339
+ "TFIIH transcription factor complex (human)\n",
340
+ "Prefoldin complex (human)\n",
341
+ "Gata1-Fog1-MeCP1 complex (mouse)\n",
342
+ "URI complex (Unconventional prefoldin RPB5 Interactor) (human)\n",
343
+ "BRM-SIN3A complex (human)\n",
344
+ "RSmad complex (human)\n",
345
+ "MLL1-WDR5 complex (human)\n",
346
+ "12S U11 snRNP (human)\n",
347
+ "BRAFT complex (human)\n",
348
+ "FA complex (Fanconi anemia complex) (human)\n",
349
+ "SMN complex (human)\n",
350
+ "p400-associated complex (human)\n",
351
+ "GCN5-TRRAP histone acetyltransferase complex (human)\n",
352
+ "Anaphase-promoting complex (human)\n",
353
+ "BAF complex (human)\n",
354
+ "UTX-MLL2/3 complex (human)\n",
355
+ "Rnase/Mrp complex (human)\n",
356
+ "NCOR2 complex (human)\n",
357
+ "NUMAC complex (nucleosomal methylation activator complex) (human)\n",
358
+ "PA700 complex (human)\n",
359
+ "Cell cycle kinase complex CDC2 (human)\n",
360
+ "CDC5L core complex (human)\n",
361
+ "SRCAP-associated chromatin remodeling complex (human)\n",
362
+ "5S-DNA-TFIIIA-TFIIIC2-TFIIIB subcomplex (human)\n",
363
+ "Respiratory chain complex I, mitochondrial (mouse)\n",
364
+ "TRAP complex (human)\n",
365
+ "TNF-alpha/NF-kappa B signaling complex 5 (human)\n",
366
+ "HCF-1 complex (human)\n",
367
+ "SMN-PolII-RHA complex (human)\n",
368
+ "DAB complex (human)\n",
369
+ "mRNA decay complex (UPF1, UPF2, UPF3B, DCP2, XRN1, XRN2, EXOSC2, EXOSC4, EXOSC10, PARN) (human)\n",
370
+ "TFTC-type histone acetyl transferase complex (human)\n",
371
+ "BLM complex II (human)\n",
372
+ "ARC-L complex (human)\n",
373
+ "RNA polymerase II (RNAPII) (human)\n",
374
+ "PA28gamma-20S proteasome (human)\n",
375
+ "BRG1-SIN3A complex (human)\n",
376
+ "5S-DNA-TFIIIA-TFIIIC2 subcomplex (human)\n",
377
+ "LSm1-7 complex (human)\n",
378
+ "NCOR1 complex (human)\n",
379
+ "PA28-20S proteasome (human)\n",
380
+ "TFTC complex (TATA-binding protein-free TAF-II-containing complex) (human)\n",
381
+ "PC2 complex (human)\n",
382
+ "SNF2h-cohesin-NuRD complex (human)\n",
383
+ "Respiratory chain complex I (early intermediate NDUFAF1 assembly), mitochondrial (human)\n",
384
+ "RC complex during G2/M-phase of cell cycle (human)\n",
385
+ "Polycystin-1 multiprotein complex (ACTN1, CDH1, SRC, JUP, VCL, CTNNB1, PXN, BCAR1, PKD1, PTK2, TLN1) (human)\n",
386
+ "Anti-HDAC2 complex (human)\n",
387
+ "p300-CBP-p270-SWI/SNF complex (human)\n",
388
+ "Ubiquitin E3 ligase (CSN1, CSN8, HRT1, SKP1, SKP2, CUL1, CUL2, CUL3) (human)\n",
389
+ "TFIID complex (mouse)\n",
390
+ "TFIID complex (human)\n",
391
+ "TNF-alpha/NF-kappa B signaling complex (SEC16A, CHUK, IKBKB, NFKB2, REL, IKBKG, MAP3K14, RELA, FBXW7, USP2) (human)\n",
392
+ "NAT complex (human)\n",
393
+ "EBAFb complex (human)\n",
394
+ "Nop56p-associated pre-rRNA complex (human)\n",
395
+ "DA complex (human)\n",
396
+ "HDAC1-associated core complex cII (human)\n",
397
+ "BRCA1-RNA polymerase II complex (human)\n",
398
+ "p97/VCP-VIMP-DERL1-DERL2-HRD1-SEL1L complex (human)\n",
399
+ "INO80 chromatin remodeling complex (human)\n",
400
+ "ARC complex (human)\n",
401
+ "DRIP complex (human)\n",
402
+ "WINAC complex (human)\n",
403
+ "SIN3-ING1b complex II (human)\n",
404
+ "ING2 complex (human)\n",
405
+ "SIN3-SAP25 complex (human)\n",
406
+ "COP9 signalosome complex (human)\n",
407
+ "Integrator complex (human)\n",
408
+ "CtBP complex (human)\n",
409
+ "ESR1-CDK7-CCNH-MNAT1-MTA1-HDAC2 complex (human)\n",
410
+ "26S proteasome (human)\n",
411
+ "ESCRT-III complex (human)\n",
412
+ "SIN3-ING1b complex I (human)\n",
413
+ "HDAC2-asscociated core complex (human)\n",
414
+ "CHUK-NFKB2-REL-IKBKG-SPAG9-NFKB1-NFKBIE-COPB2-TNIP1-NFKBIA-RELA-TNIP2 complex (human)\n",
415
+ "SWI-SNF chromatin remodeling-related-BRCA1 complex (human)\n",
416
+ "STAGA complex (SPT3-TAF9-GCN5 acetyltransferase complex) (human)\n",
417
+ "Cytochrome c oxidase (EC 1.9.3.1), mitochondrial (mouse)\n",
418
+ "NuA4/Tip60-HAT complex B (human)\n",
419
+ "LARC complex (LCR-associated remodeling complex) (human)\n",
420
+ "MeCP1 complex (human)\n",
421
+ "HES1 promoter-Notch enhancer complex (human)\n",
422
+ "NuA4/Tip60-HAT complex A (human)\n",
423
+ "Exosome (human)\n",
424
+ "18S U11/U12 snRNP (human)\n",
425
+ "Conserved oligomeric Golgi (COG) complex (human)\n",
426
+ "Emerin complex 25 (human)\n",
427
+ "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",
428
+ "BRD4-RFC complex (human)\n",
429
+ "Ubiquitin E3 ligase (AHR, ARNT, DDB1, TBL3, CUL4B, RBX1) (human)\n",
430
+ "CRM1-RAN-PHAX-CBC complex (cap binding complex) (human)\n",
431
+ "RNA polymerase II holoenzyme complex (human)\n",
432
+ "BRCA1-core RNA polymerase II complex (human)\n",
433
+ "RC complex during S-phase of cell cycle (human)\n",
434
+ "TNF-alpha/NF-kappa B signaling complex (CHUK, KPNA3, NFKB2, NFKBIB, REL, IKBKG, NFKB1, NFKBIE, RELB, NFKBIA, RELA, TNIP2) (human)\n",
435
+ "LSm2-8 complex (human)\n",
436
+ "Toposome (human)\n",
437
+ "ARC92-Mediator complex (human)\n",
438
+ "CSA complex (human)\n",
439
+ "CENP-A NAC-CAD complex (human)\n",
440
+ "CCT complex (chaperonin containing TCP1 complex) (mouse)\n",
441
+ "CSA-POLIIa complex (human)\n",
442
+ "PTIP-DNA damage response complex (human)\n",
443
+ "BRCA1-BARD1-BACH1-DNA damage complex II (human)\n",
444
+ "cMYC-ATPase-helicase complex (human)\n",
445
+ "Anaphase-promoting complex (mouse)\n",
446
+ "Large Drosha complex (human)\n",
447
+ "CRSP complex (human)\n",
448
+ "SMCC complex (human)\n",
449
+ "17S U2 snRNP (human)\n",
450
+ "TRAP-SMCC mediator complex (human)\n",
451
+ "MTA2 complex (human)\n",
452
+ "Mediator complex (mouse)\n",
453
+ "Anti-Sm protein complex (human)\n",
454
+ "20S proteasome (human)\n",
455
+ "DMAP1-associated complex (human)\n",
456
+ "RNA polymerase II complex, incomplete (CDK8 complex), chromatin structure modifying (human)\n",
457
+ "Cytochrome bc1-complex (EC 1.10.2.2), mitochondrial (mouse)\n",
458
+ "RAD17-RFC-9-1-1 checkpoint supercomplex (human)\n",
459
+ "TFIID complex, B-cell specific (human)\n",
460
+ "CEN complex (human)\n",
461
+ "DDB2 complex (human)\n",
462
+ "BASC complex (BRCA1-associated genome surveillance complex) (human)\n",
463
+ "CRSP-Mediator 2 complex (human)\n",
464
+ "RNA polymerase II core complex (human)\n",
465
+ "MDC1-MRN-ATM-FANCD2 complex (human)\n",
466
+ "PCNA-CHL12-RFC2-5 complex (human)\n",
467
+ "EBAFa complex (human)\n",
468
+ "Condensin II (human)\n",
469
+ "Kaiso-NCOR complex (human)\n",
470
+ "SF3b complex (human)\n",
471
+ "PTIP-HMT complex (human)\n",
472
+ "Nup 107-160 subcomplex (human)\n",
473
+ "p27-cyclinE-Cdk2 - Ubiquitin E3 ligase (SKP1A, SKP2, CUL1, CKS1B, RBX1) complex (human)\n",
474
+ "TFIID-beta complex (human)\n",
475
+ "PYR complex (mouse)\n",
476
+ "Kinase maturation complex 1 (human)\n",
477
+ "immunoproteasome (mouse)\n",
478
+ "ALL-1 supercomplex (human)\n",
479
+ "Emerin complex 32 (human)\n",
480
+ "Ikaros complex (mouse)\n"
481
+ ]
482
+ }
483
+ ],
484
+ "source": [
485
+ "for x in corum_matrix[\"feature\"].unique():\n",
486
+ " print(x)"
487
+ ]
488
+ },
489
+ {
490
+ "cell_type": "code",
491
+ "execution_count": null,
492
+ "id": "2766b131",
493
+ "metadata": {},
494
+ "outputs": [],
495
+ "source": []
496
+ },
497
+ {
498
+ "cell_type": "code",
499
+ "execution_count": null,
500
+ "id": "97fd0a08",
501
+ "metadata": {},
502
+ "outputs": [],
503
+ "source": []
504
+ },
505
+ {
506
+ "cell_type": "code",
507
+ "execution_count": null,
508
+ "id": "7fb27b941602401d91542211134fc71a",
509
+ "metadata": {},
510
+ "outputs": [],
511
+ "source": []
512
+ },
513
+ {
514
+ "cell_type": "code",
515
+ "execution_count": null,
516
+ "id": "14ed27d8",
517
+ "metadata": {},
518
+ "outputs": [],
519
+ "source": [
520
+ "# get all modelids that have NA values in the corum matrix\n",
521
+ "corum_matrix[corum_matrix.isna().any(axis=1)][\"ModelID\"].sort_values().unique()"
522
+ ]
523
+ },
524
+ {
525
+ "cell_type": "code",
526
+ "execution_count": null,
527
+ "id": "484e6f14",
528
+ "metadata": {},
529
+ "outputs": [],
530
+ "source": []
531
+ },
532
+ {
533
+ "cell_type": "code",
534
+ "execution_count": 18,
535
+ "id": "6cdc8f80",
536
+ "metadata": {},
537
+ "outputs": [
538
+ {
539
+ "name": "stdout",
540
+ "output_type": "stream",
541
+ "text": [
542
+ "1150 rows before dropping NA\n",
543
+ "1150 rows after dropping NA\n",
544
+ "1150 rows before dropping NA\n",
545
+ "958 rows after dropping NA\n",
546
+ "1150 rows before dropping NA\n",
547
+ "958 rows after dropping NA\n",
548
+ "1150 rows before dropping NA\n",
549
+ "958 rows after dropping NA\n"
550
+ ]
551
+ }
552
+ ],
553
+ "source": [
554
+ "# @st.cache_data\n",
555
+ "\n",
556
+ "\n",
557
+ "def compute_pca(df, metadata_columns) -> pd.DataFrame:\n",
558
+ " \"\"\"Cache PCA result per disease selection.\"\"\"\n",
559
+ " # df.fillna(0, inplace=True) # Fill NA with 0 for PCA, or drop rows with NA\n",
560
+ " print(df.shape[0], \"rows before dropping NA\")\n",
561
+ " df.dropna(inplace=True) # PCA can't handle missing values, so drop rows with any NA\n",
562
+ " print(df.shape[0], \"rows after dropping NA\")\n",
563
+ " metadata_df = df[metadata_columns]\n",
564
+ " feat_cols = df.columns.drop(metadata_columns)\n",
565
+ " if \"source\" in feat_cols:\n",
566
+ " feat_cols = feat_cols.drop(\"source\")\n",
567
+ "\n",
568
+ " pca_input = df[feat_cols].apply(pd.to_numeric, errors=\"coerce\")\n",
569
+ " pca = PCA(n_components=2, random_state=0)\n",
570
+ " pca_embedding = pca.fit_transform(pca_input)\n",
571
+ " metadata_df[\"PCA1\"] = pca_embedding[:, 0]\n",
572
+ " metadata_df[\"PCA2\"] = pca_embedding[:, 1]\n",
573
+ " return metadata_df\n",
574
+ "\n",
575
+ "\n",
576
+ "pca_single_df = compute_pca(combined_df, [\"ModelID\", \"OncotreePrimaryDisease\"])\n",
577
+ "# save the PCA result to a parquet file for later use in the app\n",
578
+ "pca_single_df.to_parquet(\n",
579
+ " BASE_DIR / \"data\" / \"pca_embeddings_single_dependencies.parquet\"\n",
580
+ ")\n",
581
+ "\n",
582
+ "pca_latent_reactome_df = compute_pca(\n",
583
+ " reactome_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"]\n",
584
+ ")\n",
585
+ "pca_latent_corum_df = compute_pca(corum_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"])\n",
586
+ "pca_latent_drug_df = compute_pca(drug_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"])\n",
587
+ "pca_latent_reactome_df.to_parquet(\n",
588
+ " BASE_DIR / \"data\" / \"pca_embeddings_latent_reactome.parquet\"\n",
589
+ ")\n",
590
+ "pca_latent_corum_df.to_parquet(\n",
591
+ " BASE_DIR / \"data\" / \"pca_embeddings_latent_corum.parquet\"\n",
592
+ ")\n",
593
+ "pca_latent_drug_df.to_parquet(BASE_DIR / \"data\" / \"pca_embeddings_latent_drug.parquet\")"
594
+ ]
595
+ },
596
+ {
597
+ "cell_type": "code",
598
+ "execution_count": null,
599
+ "id": "dc8ccfe3",
600
+ "metadata": {},
601
+ "outputs": [],
602
+ "source": []
603
+ },
604
+ {
605
+ "cell_type": "code",
606
+ "execution_count": null,
607
+ "id": "26a895e4",
608
+ "metadata": {},
609
+ "outputs": [],
610
+ "source": []
611
+ }
612
+ ],
613
+ "metadata": {
614
+ "kernelspec": {
615
+ "display_name": ".venv (3.13.1)",
616
+ "language": "python",
617
+ "name": "python3"
618
+ },
619
+ "language_info": {
620
+ "codemirror_mode": {
621
+ "name": "ipython",
622
+ "version": 3
623
+ },
624
+ "file_extension": ".py",
625
+ "mimetype": "text/x-python",
626
+ "name": "python",
627
+ "nbconvert_exporter": "python",
628
+ "pygments_lexer": "ipython3",
629
+ "version": "3.13.1"
630
+ }
631
+ },
632
+ "nbformat": 4,
633
+ "nbformat_minor": 5
634
+ }
pyproject.toml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gene-dependency-webapp"
7
+ version = "0.1.0"
8
+ description = "Interactive Streamlit webapp for exploring gene dependency plots"
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "streamlit",
12
+ "plotly",
13
+ "pandas",
14
+ "pyarrow",
15
+ "matplotlib",
16
+ "numpy",
17
+ ]
18
+
19
+ [tool.setuptools]
20
+ py-modules = ["app", "app_utils"]
requirements.txt ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==6.1.0
2
+ anyio==4.13.0
3
+ asttokens==3.0.1
4
+ attrs==26.1.0
5
+ blinker==1.9.0
6
+ cachetools==7.1.4
7
+ certifi==2026.5.20
8
+ charset-normalizer==3.4.7
9
+ click==8.4.1
10
+ comm==0.2.3
11
+ contourpy==1.3.3
12
+ cycler==0.12.1
13
+ debugpy==1.8.21
14
+ decorator==5.3.1
15
+ executing==2.2.1
16
+ fonttools==4.63.0
17
+ -e file:///home/lippincm/gene-process-dependencies/9.webapp
18
+ gitdb==4.0.12
19
+ gitpython==3.1.50
20
+ h11==0.16.0
21
+ httptools==0.8.0
22
+ idna==3.18
23
+ ipykernel==7.2.0
24
+ ipython==9.14.1
25
+ ipython-pygments-lexers==1.1.1
26
+ ipywidgets==8.1.8
27
+ itsdangerous==2.2.0
28
+ jedi==0.20.0
29
+ jinja2==3.1.6
30
+ joblib==1.5.3
31
+ jsonschema==4.26.0
32
+ jsonschema-specifications==2025.9.1
33
+ jupyter-client==8.9.0
34
+ jupyter-core==5.9.1
35
+ jupyterlab-widgets==3.0.16
36
+ kiwisolver==1.5.0
37
+ llvmlite==0.47.0
38
+ markupsafe==3.0.3
39
+ matplotlib==3.10.9
40
+ matplotlib-inline==0.2.2
41
+ narwhals==2.22.0
42
+ nest-asyncio==1.6.0
43
+ numba==0.65.1
44
+ numpy==2.4.6
45
+ packaging==26.2
46
+ pandas==3.0.3
47
+ parso==0.8.7
48
+ pexpect==4.9.0
49
+ pillow==12.2.0
50
+ platformdirs==4.10.0
51
+ plotly==6.8.0
52
+ prompt-toolkit==3.0.52
53
+ protobuf==7.35.0
54
+ psutil==7.2.2
55
+ ptyprocess==0.7.0
56
+ pure-eval==0.2.3
57
+ pyarrow==24.0.0
58
+ pydeck==0.9.2
59
+ pygments==2.20.0
60
+ pynndescent==0.6.0
61
+ pyparsing==3.3.2
62
+ python-dateutil==2.9.0.post0
63
+ python-multipart==0.0.32
64
+ pyzmq==27.1.0
65
+ referencing==0.37.0
66
+ requests==2.34.2
67
+ rpds-py==2026.5.1
68
+ scikit-learn==1.9.0
69
+ scipy==1.17.1
70
+ six==1.17.0
71
+ smmap==5.0.3
72
+ stack-data==0.6.3
73
+ starlette==1.2.1
74
+ streamlit==1.58.0
75
+ tenacity==9.1.4
76
+ threadpoolctl==3.6.0
77
+ toml==0.10.2
78
+ tornado==6.5.7
79
+ tqdm==4.67.3
80
+ traitlets==5.15.1
81
+ typing-extensions==4.15.0
82
+ umap-learn==0.5.12
83
+ urllib3==2.7.0
84
+ uvicorn==0.49.0
85
+ watchdog==6.0.0
86
+ wcwidth==0.8.1
87
+ websockets==16.0
88
+ widgetsnbextension==4.0.15
uv.lock ADDED
The diff for this file is too large to render. See raw diff