| import gradio as gr |
| import plotly.graph_objects as go |
| import pandas as pd |
| import json |
|
|
| |
| |
| |
|
|
| NETWORKS = { |
| "Asthma Th2": { |
| "nodes": 40, "edges": 49, "fi": 63.3, "lambda2": 0.028, "eps_z": -0.32, |
| "bridges": 24, "bridges_pct": 49, "pre_fragile": 15, "solid": 3, "triangles": 7, |
| "archetype": "Fragile (bridge-dominated)", |
| "description": "Alarmin-driven Th2 pathway → JAK/STAT → effectors (IgE/mast cell, eosinophils, NF-κB). Near-disconnected architecture with 49% bridges.", |
| "liquefaction": {"edges": 2, "target_fi": 81, "efficiency": "3.5×", "targets": "IL4R—TYK2, JAK1—STAT6"}, |
| "drugs": [ |
| {"name": "Tezepelumab", "target": "TSLP—CRLF2", "edges": 1, "af": 1, "pct": 100, "note": "Most upstream AF — phenotype-independent"}, |
| {"name": "Mepolizumab", "target": "IL5—IL5RA", "edges": 1, "af": 1, "pct": 100, "note": "Optimal for eosinophilic (BEC > 300)"}, |
| {"name": "Omalizumab", "target": "IgE—FcεRI", "edges": 1, "af": 1, "pct": 100, "note": "Optimal for allergic (high IgE)"}, |
| {"name": "Dupilumab", "target": "IL4R complex", "edges": 4, "af": 2, "pct": 50, "note": "Broad coverage, partial redundancy"}, |
| {"name": "Benralizumab", "target": "IL5RA—CSF2RB", "edges": 2, "af": 0, "pct": 0, "note": "Both edges protected — needs ADCC mechanism"}, |
| ], |
| "biomarkers": "BEC (eosinophils), FeNO, total IgE, ± TSLP" |
| }, |
| "IPF": { |
| "nodes": 28, "edges": 40, "fi": 67.5, "lambda2": 0.252, "eps_z": 0.23, |
| "bridges": 6, "bridges_pct": 15, "pre_fragile": 11, "solid": 2, "triangles": 8, |
| "archetype": "Fragile (triangular sparsity)", |
| "description": "TGF-β/SMAD canonical + non-canonical, RTK pathways (PDGF/FGF/VEGF), RAS-MAPK, PI3K-AKT. Well-connected but minimal triangular protection.", |
| "liquefaction": {"edges": 2, "target_fi": 92, "efficiency": "5.0×", "targets": "SMAD2—SMAD3, PIK3CA—SRC"}, |
| "drugs": [ |
| {"name": "Nintedanib", "target": "PDGFR/FGFR/VEGFR", "edges": 12, "af": 8, "pct": 67, "note": "Structural carpet-bombing — 5 edges in top 15 criticality"}, |
| {"name": "Pirfenidone", "target": "TGF-β/SMAD3", "edges": 2, "af": 1, "pct": 50, "note": "1 AF upstream + 1 protected SMAD edge"}, |
| {"name": "Pamrevlumab", "target": "SMAD4—CTGF", "edges": 1, "af": 1, "pct": 100, "note": "⚠ AF but terminal dead-end — Phase 3 FAILED"}, |
| ], |
| "biomarkers": "No validated biomarker for drug selection — TCGE fills this gap" |
| }, |
| "NSCLC": { |
| "nodes": 26, "edges": 44, "fi": 50.0, "lambda2": 0.369, "eps_z": -0.60, |
| "bridges": 6, "bridges_pct": 14, "pre_fragile": 17, "solid": 5, "triangles": 12, |
| "archetype": "Resilient (triangular redundancy)", |
| "description": "5 RTK drivers (EGFR, ALK, ROS1, MET, RET), RAS-MAPK, PI3K-AKT, immune checkpoint (PD-L1/PD-1), VEGF. Highest connectivity and redundancy.", |
| "liquefaction": {"edges": 2, "target_fi": 81, "efficiency": "4.5×", "targets": "SHC1—GRB2, EGFR—MET"}, |
| "drugs": [ |
| {"name": "Osimertinib", "target": "EGFR complex", "edges": 5, "af": 0, "pct": 0, "note": "⚠ ALL EGFR edges triangulated → resistance predicted"}, |
| {"name": "Sotorasib", "target": "KRAS targets", "edges": 3, "af": 1, "pct": 33, "note": "Only KRAS—PIK3CA is AF (#1 criticality)"}, |
| {"name": "Alectinib", "target": "ALK complex", "edges": 4, "af": 2, "pct": 50, "note": "Better structural profile than osimertinib"}, |
| {"name": "Capmatinib", "target": "MET complex", "edges": 4, "af": 0, "pct": 0, "note": "⚠ MET as triangulated as EGFR"}, |
| {"name": "Pembrolizumab", "target": "PD-L1—PD-1", "edges": 1, "af": 1, "pct": 100, "note": "Immune axis — AF, orthogonal to RTK resistance"}, |
| {"name": "Bevacizumab", "target": "VEGFA—KDR", "edges": 1, "af": 1, "pct": 100, "note": "Anti-angiogenic — AF, peripheral"}, |
| ], |
| "biomarkers": "EGFR/ALK/KRAS/ROS1/RET mutation panel, PD-L1 expression" |
| }, |
| "Cystic Fibrosis": { |
| "nodes": 39, "edges": 45, "fi": 80.0, "lambda2": 0.087, "eps_z": 0.18, |
| "bridges": 11, "bridges_pct": 24, "pre_fragile": 9, "solid": 0, "triangles": 3, |
| "archetype": "Hyper-fragile (hub-spoke)", |
| "description": "CFTR dysfunction → β-catenin degradation → NF-κB activation → TLR4/TLR5 innate immunity → cytokine cascade → Pseudomonas interaction. Zero solid edges.", |
| "liquefaction": {"edges": 2, "target_fi": 93, "efficiency": "2.0×", "targets": "CFTR—CTNNB1, CTNNB1—GSK3B"}, |
| "drugs": [ |
| {"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)"}, |
| ], |
| "biomarkers": "Sweat chloride, CFTR mutation status (F508del)" |
| }, |
| "COPD": { |
| "nodes": 39, "edges": 49, "fi": 93.9, "lambda2": 0.178, "eps_z": -0.07, |
| "bridges": 14, "bridges_pct": 29, "pre_fragile": 3, "solid": 0, "triangles": 1, |
| "archetype": "Ultra-fragile (linear cascades)", |
| "description": "Oxidative stress → NF-κB → neutrophilic inflammation → protease/anti-protease → NLRP3 inflammasome → mucus → corticosteroid resistance → remodeling. Single triangle.", |
| "liquefaction": {"edges": 1, "target_fi": 100, "efficiency": "5.0×", "targets": "MAPK14—NFKB1"}, |
| "drugs": [ |
| {"name": "Corticosteroids", "target": "HDAC2—GR—NF-κB", "edges": 2, "af": 2, "pct": 100, "note": "⚠ Both AF but ROS sabotages HDAC2 upstream — resistance explained"}, |
| {"name": "Roflumilast", "target": "PDE4B—PRKAR1A", "edges": 1, "af": 1, "pct": 100, "note": "Single AF edge — no cascade, explains modest efficacy"}, |
| ], |
| "biomarkers": "BEC (eosinophilic vs neutrophilic phenotype), AAT levels" |
| }, |
| } |
|
|
| GRADIENT_ORDER = ["NSCLC", "Asthma Th2", "IPF", "Cystic Fibrosis", "COPD"] |
| COLORS = {"NSCLC": "#1D4ED8", "Asthma Th2": "#0D9488", "IPF": "#D97706", "Cystic Fibrosis": "#7C3AED", "COPD": "#DC2626"} |
|
|
| |
| |
| |
|
|
| def get_overview(): |
| """Generate the gradient comparison chart + table.""" |
| |
| fig = go.Figure() |
| for name in GRADIENT_ORDER: |
| n = NETWORKS[name] |
| fig.add_trace(go.Bar( |
| x=[name], y=[n["fi"]], |
| marker_color=COLORS[name], |
| text=[f'{n["fi"]}%'], textposition='outside', |
| name=name, showlegend=False |
| )) |
| fig.update_layout( |
| title="Fragility Index Gradient Across Respiratory Diseases", |
| yaxis_title="Fragility Index (%)", |
| yaxis_range=[0, 105], |
| template="plotly_white", |
| height=400, |
| font=dict(family="Inter, sans-serif"), |
| margin=dict(t=60, b=40), |
| ) |
| |
| responses = { |
| "NSCLC": "Systematic resistance", |
| "Asthma Th2": "One biologic suffices", |
| "IPF": "Slows, doesn't stop", |
| "Cystic Fibrosis": "Trikafta transforms", |
| "COPD": "Treatment-refractory" |
| } |
| fig.update_xaxes(ticktext=[f"{n}<br><sub>{responses[n]}</sub>" for n in GRADIENT_ORDER], |
| tickvals=GRADIENT_ORDER) |
|
|
| |
| rows = [] |
| for name in GRADIENT_ORDER: |
| n = NETWORKS[name] |
| rows.append({ |
| "Disease": name, |
| "N / E": f'{n["nodes"]} / {n["edges"]}', |
| "FI (%)": n["fi"], |
| "λ₂": n["lambda2"], |
| "Bridges": f'{n["bridges"]} ({n["bridges_pct"]}%)', |
| "Solid": n["solid"], |
| "Archetype": n["archetype"].split(" (")[0], |
| "Drugs": len(n["drugs"]), |
| }) |
| df = pd.DataFrame(rows) |
| return fig, df |
|
|
| def get_network_detail(disease_name): |
| """Generate detailed analysis for a single network.""" |
| if disease_name not in NETWORKS: |
| return "Select a disease", "", "", "" |
|
|
| n = NETWORKS[disease_name] |
|
|
| |
| metrics = f"""## {disease_name} — Structural Profile |
| |
| | Metric | Value | |
| |--------|-------| |
| | Nodes / Edges | {n['nodes']} / {n['edges']} | |
| | Fragility Index | **{n['fi']}%** | |
| | Algebraic connectivity (λ₂) | {n['lambda2']} | |
| | Spectral entropy position (EPS_z) | {n['eps_z']:+.2f} | |
| | Bridges | {n['bridges']} ({n['bridges_pct']}%) | |
| | Pre-fragile edges | {n['pre_fragile']} | |
| | Solid edges | {n['solid']} | |
| | Triangles | {n['triangles']} | |
| | **Archetype** | **{n['archetype']}** | |
| |
| ### Description |
| {n['description']} |
| |
| ### Relevant Biomarkers |
| {n['biomarkers']} |
| |
| ### Liquefaction |
| {n['liquefaction']['edges']} targeted edge(s) → FI = {n['liquefaction']['target_fi']}% ({n['liquefaction']['efficiency']} more efficient than random) |
| Targets: **{n['liquefaction']['targets']}** |
| """ |
|
|
| |
| drug_rows = [] |
| for d in n["drugs"]: |
| af_color = "🟢" if d["pct"] == 100 else "🟡" if d["pct"] > 0 else "🔴" |
| drug_rows.append({ |
| "Drug": d["name"], |
| "Target": d["target"], |
| "Edges": d["edges"], |
| "AF": d["af"], |
| "AF %": f'{af_color} {d["pct"]}%', |
| "Structural Assessment": d["note"], |
| }) |
| drug_df = pd.DataFrame(drug_rows) |
|
|
| |
| fig = go.Figure() |
| for d in n["drugs"]: |
| color = "#059669" if d["pct"] == 100 else "#D97706" if d["pct"] > 0 else "#DC2626" |
| fig.add_trace(go.Bar( |
| x=[d["name"]], y=[d["pct"]], |
| marker_color=color, |
| text=[f'{d["pct"]}%'], textposition='outside', |
| showlegend=False |
| )) |
| fig.update_layout( |
| title=f"Drug Structural Profiles — {disease_name}", |
| yaxis_title="Always-Fragile Targets (%)", |
| yaxis_range=[0, 115], |
| template="plotly_white", |
| height=350, |
| font=dict(family="Inter, sans-serif"), |
| margin=dict(t=60, b=40), |
| ) |
|
|
| return metrics, drug_df, fig |
|
|
| |
| |
| |
|
|
| HEADER_MD = """ |
| # 🫁 Structural Network Medicine — Pneumology |
| |
| **Why some drugs work, others don't — and topology explains the difference.** |
| |
| This explorer presents structural fragility analyses of 5 respiratory disease signaling networks, |
| covering 21 approved drugs. Each drug's molecular targets are mapped to the network topology to determine |
| whether they hit structurally irreplaceable interactions (always-fragile) or redundant ones (solidified). |
| |
| The **Fragility Index (FI)** = fraction of always-fragile edges. Higher FI → more vulnerable network → monotherapy more likely to work. |
| |
| > 🔬 Full analysis engine: [cognitive-engineering.dev](https://cognitive-engineering.dev) |
| > 📄 Method: [Zenodo 10.5281/zenodo.19045028](https://doi.org/10.5281/zenodo.19045028) |
| """ |
|
|
| FOOTER_MD = """ |
| --- |
| ### Want to analyze YOUR network? |
| |
| This explorer shows pre-computed results for 5 respiratory diseases. |
| To run structural analysis on your own signaling network: |
| |
| 👉 **[cognitive-engineering.dev](https://cognitive-engineering.dev)** — upload a network, get FI + criticality + liquefaction in minutes. |
| |
| 📧 hello@cognitive-engineering.dev |
| |
| *© 2026 Cognitive Engineering — Switzerland* |
| """ |
|
|
| with gr.Blocks( |
| title="Structural Network Medicine", |
| theme=gr.themes.Soft(primary_hue="teal", neutral_hue="slate"), |
| css="footer {display: none !important;}" |
| ) as app: |
|
|
| gr.Markdown(HEADER_MD) |
|
|
| with gr.Tab("📊 FI Gradient"): |
| gr.Markdown("### The Structural Gradient Across Respiratory Diseases") |
| gr.Markdown("NSCLC (50%) → Asthma (63%) → IPF (68%) → CF (80%) → COPD (94%)") |
| overview_chart = gr.Plot() |
| overview_table = gr.Dataframe() |
| app.load(fn=get_overview, outputs=[overview_chart, overview_table]) |
|
|
| with gr.Tab("🔬 Disease Explorer"): |
| gr.Markdown("### Select a disease to explore its structural profile and drug mapping") |
| disease_dropdown = gr.Dropdown( |
| choices=list(NETWORKS.keys()), |
| value="Asthma Th2", |
| label="Disease Network" |
| ) |
| detail_md = gr.Markdown() |
| drug_table = gr.Dataframe(label="Drug Structural Profiles") |
| drug_chart = gr.Plot() |
|
|
| disease_dropdown.change( |
| fn=get_network_detail, |
| inputs=[disease_dropdown], |
| outputs=[detail_md, drug_table, drug_chart] |
| ) |
| app.load( |
| fn=lambda: get_network_detail("Asthma Th2"), |
| outputs=[detail_md, drug_table, drug_chart] |
| ) |
|
|
| with gr.Tab("💊 Drug Comparison"): |
| gr.Markdown("### All 21 drugs ranked by structural efficacy") |
| def get_all_drugs(): |
| rows = [] |
| for disease, n in NETWORKS.items(): |
| for d in n["drugs"]: |
| emoji = "🟢" if d["pct"] == 100 else "🟡" if d["pct"] > 0 else "🔴" |
| rows.append({ |
| "Disease": disease, |
| "Drug": d["name"], |
| "Edges targeted": d["edges"], |
| "Always-fragile": d["af"], |
| "AF %": d["pct"], |
| "Profile": emoji, |
| "Assessment": d["note"], |
| }) |
| df = pd.DataFrame(rows).sort_values("AF %", ascending=False) |
| return df |
| all_drugs = gr.Dataframe() |
| app.load(fn=get_all_drugs, outputs=[all_drugs]) |
|
|
| with gr.Tab("ℹ️ About"): |
| gr.Markdown(""" |
| ### About This Project |
| |
| **Structural Network Medicine** applies the Theory of Emergent Global Constraints (TCGE) to disease |
| signaling networks. For each molecular interaction in a pathway, we compute the number of triangular |
| bypass routes (tri(e)). An interaction with tri(e) = 0 is **always-fragile** — blocking it permanently |
| cuts the signal with no structural compensation possible. |
| |
| **The Fragility Index (FI)** is the fraction of always-fragile edges in the network. It predicts |
| the therapeutic response class: |
| |
| | FI Range | Archetype | Clinical Pattern | Example | |
| |----------|-----------|-----------------|---------| |
| | > 90% | Ultra-fragile | Treatment-refractory | COPD | |
| | ≥ 80% | Hyper-fragile | Structural restoration transforms outcome | CF + Trikafta | |
| | 60-70% | Fragile | Monotherapy works | Asthma, IPF | |
| | ≈ 50% | Resilient | Combination required | NSCLC | |
| |
| ### Platform |
| The full analysis engine (GraphCoherence) is available at [cognitive-engineering.dev](https://cognitive-engineering.dev). |
| Upload any signaling network in JSON format to get: FI, edge criticality ranking, spectral analysis, |
| bridge detection, and structural liquefaction simulation. |
| |
| ### Publications |
| - Venti DM (2026). "Protein regulatory architectures segregate into two topological regimes." |
| *Under review, Communications Biology.* [Zenodo DOI: 10.5281/zenodo.19045028](https://doi.org/10.5281/zenodo.19045028) |
| - Venti DM (2026). "Triangular solidification: local motif redundancy drives a sharp structural |
| transition in complex networks." [Zenodo DOI: 10.5281/zenodo.19163066](https://doi.org/10.5281/zenodo.19163066) |
| |
| ### Contact |
| David Martin — Cognitive Engineering, Switzerland |
| 📧 hello@cognitive-engineering.dev |
| 🌐 [cognitive-engineering.dev](https://cognitive-engineering.dev) |
| """) |
|
|
| gr.Markdown(FOOTER_MD) |
|
|
| if __name__ == "__main__": |
| app.launch() |
|
|