CognitiveEngineering commited on
Commit
2de6cd8
·
verified ·
1 Parent(s): 780f2d0

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +334 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import plotly.graph_objects as go
3
+ import pandas as pd
4
+ import json
5
+
6
+ # ═══════════════════════════════════════════════════════════════
7
+ # PRE-COMPUTED NETWORK DATA (from GraphCoherence analyses)
8
+ # ═══════════════════════════════════════════════════════════════
9
+
10
+ NETWORKS = {
11
+ "Asthma Th2": {
12
+ "nodes": 40, "edges": 49, "fi": 63.3, "lambda2": 0.028, "eps_z": -0.32,
13
+ "bridges": 24, "bridges_pct": 49, "pre_fragile": 15, "solid": 3, "triangles": 7,
14
+ "archetype": "Fragile (bridge-dominated)",
15
+ "description": "Alarmin-driven Th2 pathway → JAK/STAT → effectors (IgE/mast cell, eosinophils, NF-κB). Near-disconnected architecture with 49% bridges.",
16
+ "liquefaction": {"edges": 2, "target_fi": 81, "efficiency": "3.5×", "targets": "IL4R—TYK2, JAK1—STAT6"},
17
+ "drugs": [
18
+ {"name": "Tezepelumab", "target": "TSLP—CRLF2", "edges": 1, "af": 1, "pct": 100, "note": "Most upstream AF — phenotype-independent"},
19
+ {"name": "Mepolizumab", "target": "IL5—IL5RA", "edges": 1, "af": 1, "pct": 100, "note": "Optimal for eosinophilic (BEC > 300)"},
20
+ {"name": "Omalizumab", "target": "IgE—FcεRI", "edges": 1, "af": 1, "pct": 100, "note": "Optimal for allergic (high IgE)"},
21
+ {"name": "Dupilumab", "target": "IL4R complex", "edges": 4, "af": 2, "pct": 50, "note": "Broad coverage, partial redundancy"},
22
+ {"name": "Benralizumab", "target": "IL5RA—CSF2RB", "edges": 2, "af": 0, "pct": 0, "note": "Both edges protected — needs ADCC mechanism"},
23
+ ],
24
+ "biomarkers": "BEC (eosinophils), FeNO, total IgE, ± TSLP"
25
+ },
26
+ "IPF": {
27
+ "nodes": 28, "edges": 40, "fi": 67.5, "lambda2": 0.252, "eps_z": 0.23,
28
+ "bridges": 6, "bridges_pct": 15, "pre_fragile": 11, "solid": 2, "triangles": 8,
29
+ "archetype": "Fragile (triangular sparsity)",
30
+ "description": "TGF-β/SMAD canonical + non-canonical, RTK pathways (PDGF/FGF/VEGF), RAS-MAPK, PI3K-AKT. Well-connected but minimal triangular protection.",
31
+ "liquefaction": {"edges": 2, "target_fi": 92, "efficiency": "5.0×", "targets": "SMAD2—SMAD3, PIK3CA—SRC"},
32
+ "drugs": [
33
+ {"name": "Nintedanib", "target": "PDGFR/FGFR/VEGFR", "edges": 12, "af": 8, "pct": 67, "note": "Structural carpet-bombing — 5 edges in top 15 criticality"},
34
+ {"name": "Pirfenidone", "target": "TGF-β/SMAD3", "edges": 2, "af": 1, "pct": 50, "note": "1 AF upstream + 1 protected SMAD edge"},
35
+ {"name": "Pamrevlumab", "target": "SMAD4—CTGF", "edges": 1, "af": 1, "pct": 100, "note": "⚠ AF but terminal dead-end — Phase 3 FAILED"},
36
+ ],
37
+ "biomarkers": "No validated biomarker for drug selection — TCGE fills this gap"
38
+ },
39
+ "NSCLC": {
40
+ "nodes": 26, "edges": 44, "fi": 50.0, "lambda2": 0.369, "eps_z": -0.60,
41
+ "bridges": 6, "bridges_pct": 14, "pre_fragile": 17, "solid": 5, "triangles": 12,
42
+ "archetype": "Resilient (triangular redundancy)",
43
+ "description": "5 RTK drivers (EGFR, ALK, ROS1, MET, RET), RAS-MAPK, PI3K-AKT, immune checkpoint (PD-L1/PD-1), VEGF. Highest connectivity and redundancy.",
44
+ "liquefaction": {"edges": 2, "target_fi": 81, "efficiency": "4.5×", "targets": "SHC1—GRB2, EGFR—MET"},
45
+ "drugs": [
46
+ {"name": "Osimertinib", "target": "EGFR complex", "edges": 5, "af": 0, "pct": 0, "note": "⚠ ALL EGFR edges triangulated → resistance predicted"},
47
+ {"name": "Sotorasib", "target": "KRAS targets", "edges": 3, "af": 1, "pct": 33, "note": "Only KRAS—PIK3CA is AF (#1 criticality)"},
48
+ {"name": "Alectinib", "target": "ALK complex", "edges": 4, "af": 2, "pct": 50, "note": "Better structural profile than osimertinib"},
49
+ {"name": "Capmatinib", "target": "MET complex", "edges": 4, "af": 0, "pct": 0, "note": "⚠ MET as triangulated as EGFR"},
50
+ {"name": "Pembrolizumab", "target": "PD-L1—PD-1", "edges": 1, "af": 1, "pct": 100, "note": "Immune axis — AF, orthogonal to RTK resistance"},
51
+ {"name": "Bevacizumab", "target": "VEGFA—KDR", "edges": 1, "af": 1, "pct": 100, "note": "Anti-angiogenic — AF, peripheral"},
52
+ ],
53
+ "biomarkers": "EGFR/ALK/KRAS/ROS1/RET mutation panel, PD-L1 expression"
54
+ },
55
+ "Cystic Fibrosis": {
56
+ "nodes": 39, "edges": 45, "fi": 80.0, "lambda2": 0.087, "eps_z": 0.18,
57
+ "bridges": 11, "bridges_pct": 24, "pre_fragile": 9, "solid": 0, "triangles": 3,
58
+ "archetype": "Hyper-fragile (hub-spoke)",
59
+ "description": "CFTR dysfunction → β-catenin degradation → NF-κB activation → TLR4/TLR5 innate immunity → cytokine cascade → Pseudomonas interaction. Zero solid edges.",
60
+ "liquefaction": {"edges": 2, "target_fi": 93, "efficiency": "2.0×", "targets": "CFTR—CTNNB1, CTNNB1—GSK3B"},
61
+ "drugs": [
62
+ {"name": "Trikafta", "target": "CFTR restoration", "edges": 3, "af_note": "2/3 AF", "af": 2, "pct": 67, "note": "Anti-liquefaction — restores the only protective triangle (CFTR/CTNNB1/SRC)"},
63
+ ],
64
+ "biomarkers": "Sweat chloride, CFTR mutation status (F508del)"
65
+ },
66
+ "COPD": {
67
+ "nodes": 39, "edges": 49, "fi": 93.9, "lambda2": 0.178, "eps_z": -0.07,
68
+ "bridges": 14, "bridges_pct": 29, "pre_fragile": 3, "solid": 0, "triangles": 1,
69
+ "archetype": "Ultra-fragile (linear cascades)",
70
+ "description": "Oxidative stress → NF-κB → neutrophilic inflammation → protease/anti-protease → NLRP3 inflammasome → mucus → corticosteroid resistance → remodeling. Single triangle.",
71
+ "liquefaction": {"edges": 1, "target_fi": 100, "efficiency": "5.0×", "targets": "MAPK14—NFKB1"},
72
+ "drugs": [
73
+ {"name": "Corticosteroids", "target": "HDAC2—GR—NF-κB", "edges": 2, "af": 2, "pct": 100, "note": "⚠ Both AF but ROS sabotages HDAC2 upstream — resistance explained"},
74
+ {"name": "Roflumilast", "target": "PDE4B—PRKAR1A", "edges": 1, "af": 1, "pct": 100, "note": "Single AF edge — no cascade, explains modest efficacy"},
75
+ ],
76
+ "biomarkers": "BEC (eosinophilic vs neutrophilic phenotype), AAT levels"
77
+ },
78
+ }
79
+
80
+ GRADIENT_ORDER = ["NSCLC", "Asthma Th2", "IPF", "Cystic Fibrosis", "COPD"]
81
+ COLORS = {"NSCLC": "#1D4ED8", "Asthma Th2": "#0D9488", "IPF": "#D97706", "Cystic Fibrosis": "#7C3AED", "COPD": "#DC2626"}
82
+
83
+ # ═══════════════════════════════════════════════════════════════
84
+ # APP FUNCTIONS
85
+ # ═══════════════════════════════════════════════════════════════
86
+
87
+ def get_overview():
88
+ """Generate the gradient comparison chart + table."""
89
+ # Bar chart
90
+ fig = go.Figure()
91
+ for name in GRADIENT_ORDER:
92
+ n = NETWORKS[name]
93
+ fig.add_trace(go.Bar(
94
+ x=[name], y=[n["fi"]],
95
+ marker_color=COLORS[name],
96
+ text=[f'{n["fi"]}%'], textposition='outside',
97
+ name=name, showlegend=False
98
+ ))
99
+ fig.update_layout(
100
+ title="Fragility Index Gradient Across Respiratory Diseases",
101
+ yaxis_title="Fragility Index (%)",
102
+ yaxis_range=[0, 105],
103
+ template="plotly_white",
104
+ height=400,
105
+ font=dict(family="Inter, sans-serif"),
106
+ margin=dict(t=60, b=40),
107
+ )
108
+ # Response labels
109
+ responses = {
110
+ "NSCLC": "Systematic resistance",
111
+ "Asthma Th2": "One biologic suffices",
112
+ "IPF": "Slows, doesn't stop",
113
+ "Cystic Fibrosis": "Trikafta transforms",
114
+ "COPD": "Treatment-refractory"
115
+ }
116
+ fig.update_xaxes(ticktext=[f"{n}<br><sub>{responses[n]}</sub>" for n in GRADIENT_ORDER],
117
+ tickvals=GRADIENT_ORDER)
118
+
119
+ # Summary table
120
+ rows = []
121
+ for name in GRADIENT_ORDER:
122
+ n = NETWORKS[name]
123
+ rows.append({
124
+ "Disease": name,
125
+ "N / E": f'{n["nodes"]} / {n["edges"]}',
126
+ "FI (%)": n["fi"],
127
+ "λ₂": n["lambda2"],
128
+ "Bridges": f'{n["bridges"]} ({n["bridges_pct"]}%)',
129
+ "Solid": n["solid"],
130
+ "Archetype": n["archetype"].split(" (")[0],
131
+ "Drugs": len(n["drugs"]),
132
+ })
133
+ df = pd.DataFrame(rows)
134
+ return fig, df
135
+
136
+ def get_network_detail(disease_name):
137
+ """Generate detailed analysis for a single network."""
138
+ if disease_name not in NETWORKS:
139
+ return "Select a disease", "", "", ""
140
+
141
+ n = NETWORKS[disease_name]
142
+
143
+ # Metrics summary
144
+ metrics = f"""## {disease_name} — Structural Profile
145
+
146
+ | Metric | Value |
147
+ |--------|-------|
148
+ | Nodes / Edges | {n['nodes']} / {n['edges']} |
149
+ | Fragility Index | **{n['fi']}%** |
150
+ | Algebraic connectivity (λ₂) | {n['lambda2']} |
151
+ | Spectral entropy position (EPS_z) | {n['eps_z']:+.2f} |
152
+ | Bridges | {n['bridges']} ({n['bridges_pct']}%) |
153
+ | Pre-fragile edges | {n['pre_fragile']} |
154
+ | Solid edges | {n['solid']} |
155
+ | Triangles | {n['triangles']} |
156
+ | **Archetype** | **{n['archetype']}** |
157
+
158
+ ### Description
159
+ {n['description']}
160
+
161
+ ### Relevant Biomarkers
162
+ {n['biomarkers']}
163
+
164
+ ### Liquefaction
165
+ {n['liquefaction']['edges']} targeted edge(s) → FI = {n['liquefaction']['target_fi']}% ({n['liquefaction']['efficiency']} more efficient than random)
166
+ Targets: **{n['liquefaction']['targets']}**
167
+ """
168
+
169
+ # Drug table
170
+ drug_rows = []
171
+ for d in n["drugs"]:
172
+ af_color = "🟢" if d["pct"] == 100 else "🟡" if d["pct"] > 0 else "🔴"
173
+ drug_rows.append({
174
+ "Drug": d["name"],
175
+ "Target": d["target"],
176
+ "Edges": d["edges"],
177
+ "AF": d["af"],
178
+ "AF %": f'{af_color} {d["pct"]}%',
179
+ "Structural Assessment": d["note"],
180
+ })
181
+ drug_df = pd.DataFrame(drug_rows)
182
+
183
+ # Drug AF chart
184
+ fig = go.Figure()
185
+ for d in n["drugs"]:
186
+ color = "#059669" if d["pct"] == 100 else "#D97706" if d["pct"] > 0 else "#DC2626"
187
+ fig.add_trace(go.Bar(
188
+ x=[d["name"]], y=[d["pct"]],
189
+ marker_color=color,
190
+ text=[f'{d["pct"]}%'], textposition='outside',
191
+ showlegend=False
192
+ ))
193
+ fig.update_layout(
194
+ title=f"Drug Structural Profiles — {disease_name}",
195
+ yaxis_title="Always-Fragile Targets (%)",
196
+ yaxis_range=[0, 115],
197
+ template="plotly_white",
198
+ height=350,
199
+ font=dict(family="Inter, sans-serif"),
200
+ margin=dict(t=60, b=40),
201
+ )
202
+
203
+ return metrics, drug_df, fig
204
+
205
+ # ═══════════════════════════════════════════════════════════════
206
+ # GRADIO INTERFACE
207
+ # ═══════════════════════════════════════════════════════════════
208
+
209
+ HEADER_MD = """
210
+ # 🫁 Structural Network Medicine — Pneumology
211
+
212
+ **Why some drugs work, others don't — and topology explains the difference.**
213
+
214
+ This explorer presents structural fragility analyses of 5 respiratory disease signaling networks,
215
+ covering 21 approved drugs. Each drug's molecular targets are mapped to the network topology to determine
216
+ whether they hit structurally irreplaceable interactions (always-fragile) or redundant ones (solidified).
217
+
218
+ The **Fragility Index (FI)** = fraction of always-fragile edges. Higher FI → more vulnerable network → monotherapy more likely to work.
219
+
220
+ > 🔬 Full analysis engine: [cognitive-engineering.dev](https://cognitive-engineering.dev)
221
+ > 📄 Method: [Zenodo 10.5281/zenodo.19045028](https://doi.org/10.5281/zenodo.19045028)
222
+ """
223
+
224
+ FOOTER_MD = """
225
+ ---
226
+ ### Want to analyze YOUR network?
227
+
228
+ This explorer shows pre-computed results for 5 respiratory diseases.
229
+ To run structural analysis on your own signaling network:
230
+
231
+ 👉 **[cognitive-engineering.dev](https://cognitive-engineering.dev)** — upload a network, get FI + criticality + liquefaction in minutes.
232
+
233
+ 📧 hello@cognitive-engineering.dev
234
+
235
+ *© 2026 Cognitive Engineering — Switzerland*
236
+ """
237
+
238
+ with gr.Blocks(
239
+ title="Structural Network Medicine",
240
+ theme=gr.themes.Soft(primary_hue="teal", neutral_hue="slate"),
241
+ css="footer {display: none !important;}"
242
+ ) as app:
243
+
244
+ gr.Markdown(HEADER_MD)
245
+
246
+ with gr.Tab("📊 FI Gradient"):
247
+ gr.Markdown("### The Structural Gradient Across Respiratory Diseases")
248
+ gr.Markdown("NSCLC (50%) → Asthma (63%) → IPF (68%) → CF (80%) → COPD (94%)")
249
+ overview_chart = gr.Plot()
250
+ overview_table = gr.Dataframe()
251
+ app.load(fn=get_overview, outputs=[overview_chart, overview_table])
252
+
253
+ with gr.Tab("🔬 Disease Explorer"):
254
+ gr.Markdown("### Select a disease to explore its structural profile and drug mapping")
255
+ disease_dropdown = gr.Dropdown(
256
+ choices=list(NETWORKS.keys()),
257
+ value="Asthma Th2",
258
+ label="Disease Network"
259
+ )
260
+ detail_md = gr.Markdown()
261
+ drug_table = gr.Dataframe(label="Drug Structural Profiles")
262
+ drug_chart = gr.Plot()
263
+
264
+ disease_dropdown.change(
265
+ fn=get_network_detail,
266
+ inputs=[disease_dropdown],
267
+ outputs=[detail_md, drug_table, drug_chart]
268
+ )
269
+ app.load(
270
+ fn=lambda: get_network_detail("Asthma Th2"),
271
+ outputs=[detail_md, drug_table, drug_chart]
272
+ )
273
+
274
+ with gr.Tab("💊 Drug Comparison"):
275
+ gr.Markdown("### All 21 drugs ranked by structural efficacy")
276
+ def get_all_drugs():
277
+ rows = []
278
+ for disease, n in NETWORKS.items():
279
+ for d in n["drugs"]:
280
+ emoji = "🟢" if d["pct"] == 100 else "🟡" if d["pct"] > 0 else "🔴"
281
+ rows.append({
282
+ "Disease": disease,
283
+ "Drug": d["name"],
284
+ "Edges targeted": d["edges"],
285
+ "Always-fragile": d["af"],
286
+ "AF %": d["pct"],
287
+ "Profile": emoji,
288
+ "Assessment": d["note"],
289
+ })
290
+ df = pd.DataFrame(rows).sort_values("AF %", ascending=False)
291
+ return df
292
+ all_drugs = gr.Dataframe()
293
+ app.load(fn=get_all_drugs, outputs=[all_drugs])
294
+
295
+ with gr.Tab("ℹ️ About"):
296
+ gr.Markdown("""
297
+ ### About This Project
298
+
299
+ **Structural Network Medicine** applies the Theory of Emergent Global Constraints (TCGE) to disease
300
+ signaling networks. For each molecular interaction in a pathway, we compute the number of triangular
301
+ bypass routes (tri(e)). An interaction with tri(e) = 0 is **always-fragile** — blocking it permanently
302
+ cuts the signal with no structural compensation possible.
303
+
304
+ **The Fragility Index (FI)** is the fraction of always-fragile edges in the network. It predicts
305
+ the therapeutic response class:
306
+
307
+ | FI Range | Archetype | Clinical Pattern | Example |
308
+ |----------|-----------|-----------------|---------|
309
+ | > 90% | Ultra-fragile | Treatment-refractory | COPD |
310
+ | ≥ 80% | Hyper-fragile | Structural restoration transforms outcome | CF + Trikafta |
311
+ | 60-70% | Fragile | Monotherapy works | Asthma, IPF |
312
+ | ≈ 50% | Resilient | Combination required | NSCLC |
313
+
314
+ ### Platform
315
+ The full analysis engine (GraphCoherence) is available at [cognitive-engineering.dev](https://cognitive-engineering.dev).
316
+ Upload any signaling network in JSON format to get: FI, edge criticality ranking, spectral analysis,
317
+ bridge detection, and structural liquefaction simulation.
318
+
319
+ ### Publications
320
+ - Venti DM (2026). "Protein regulatory architectures segregate into two topological regimes."
321
+ *Under review, Communications Biology.* [Zenodo DOI: 10.5281/zenodo.19045028](https://doi.org/10.5281/zenodo.19045028)
322
+ - Venti DM (2026). "Triangular solidification: local motif redundancy drives a sharp structural
323
+ transition in complex networks." [Zenodo DOI: 10.5281/zenodo.19163066](https://doi.org/10.5281/zenodo.19163066)
324
+
325
+ ### Contact
326
+ David Martin — Cognitive Engineering, Switzerland
327
+ 📧 hello@cognitive-engineering.dev
328
+ 🌐 [cognitive-engineering.dev](https://cognitive-engineering.dev)
329
+ """)
330
+
331
+ gr.Markdown(FOOTER_MD)
332
+
333
+ if __name__ == "__main__":
334
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==4.44.1
2
+ plotly==5.24.1
3
+ pandas==2.2.3