Penny Wang commited on
Commit
d071d08
·
unverified ·
1 Parent(s): a490963

Add interactive oncology network visualization

Browse files

This script generates an interactive oncology network visualization using Gradio and Pyvis, depicting cancer types, detection stages, and treatment pathways.

Files changed (1) hide show
  1. roadmap_visual.py +101 -0
roadmap_visual.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pyvis.network import Network
3
+
4
+ def generate_roadmap_graph():
5
+ # Initialize Gephi-style network
6
+ net = Network(height="600px", width="100%", bgcolor="#222222", font_color="white", directed=True)
7
+
8
+ # CANCER TYPES (Source AICR: https://www.aicr.org/cancer-survival/cancer-type/?gad_source=1&gad_campaignid=22658424638&gbraid=0AAAAAD7w6z5hHTX4za7nDWOtKRdbNMRuV&gclid=CjwKCAjwyYPOBhBxEiwAgpT8P2G1tNaVGtsO1_pPa7LEQPodGeLjikzeUSjNNIEc88kTudSWEn3OtBoCabkQAvD_BwE)
9
+ # Blue Nodes
10
+ aicr_list = [
11
+ "Bladder", "Breast", "Cervical", "Colorectal", "Endometrial",
12
+ "Esophageal", "Gallbladder", "Kidney", "Liver", "Lung",
13
+ "Mouth, Pharynx, Larynx", "Nasopharyngeal", "Ovarian",
14
+ "Pancreatic", "Prostate", "Skin", "Stomach"
15
+ ]
16
+
17
+ for i, name in enumerate(aicr_list):
18
+ net.add_node(i, label=name, color="#3399ff", size=25, shape="dot",
19
+ title=f"AICR Type: {name}")
20
+
21
+ # DETECTION STAGES
22
+ # Diamond nodes represent diagnostic journey
23
+ stages = {
24
+ 100: "Stage 0-1 (Localized)",
25
+ 101: "Stage 2-3 (Regional)",
26
+ 102: "Stage 4 (Advanced/Metastatic)"
27
+ }
28
+ for node_id, label in stages.items():
29
+ # Green for early detection, Red for late
30
+ color = "#99ff66" if node_id == 100 else "#ff6666"
31
+ net.add_node(node_id, label=label, color=color, size=35, shape="diamond")
32
+
33
+ # TREATMENTS & COST CATEGORIES
34
+ # Triangle nodes representing the economic and clinical response
35
+ treatments = {
36
+ 200: "Curative Surgery",
37
+ 201: "Standard Chemotherapy",
38
+ 202: "Precision Immunotherapy",
39
+ 203: "Palliative/Supportive Care"
40
+ }
41
+
42
+ costs = {
43
+ 200: "High Initial Cost (Lower Long-term)",
44
+ 201: "Recurring Moderate-High Cost",
45
+ 202: "Very High Cost (Advanced Care)",
46
+ 203: "Supportive Maintenance Cost"
47
+ }
48
+
49
+ for node_id, label in treatments.items():
50
+ net.add_node(node_id, label=label, color="#ffcc00", size=30, shape="triangle",
51
+ title=f"Cost Category: {costs[node_id]}")
52
+
53
+ # CONNECTIONS Here
54
+ # Connect every Cancer Type to the "Localized" Stage to show the starting point
55
+ for i in range(len(aicr_list)):
56
+ net.add_edge(i, 100, color="grey", alpha=0.3)
57
+ net.add_edge(i, 101, color="grey", alpha=0.3)
58
+ net.add_edge(i, 102, color="grey", alpha=0.3)
59
+
60
+ # Logic-based clinical pathways
61
+ # Stage 0-1 -> Surgery (High survival)
62
+ net.add_edge(100, 200, weight=5, color="#00ffcc", title="Primary Curative Route")
63
+
64
+ # Stage 2-3 -> Chemo/Surgery
65
+ net.add_edge(101, 201, weight=5, color="#ffcc00")
66
+
67
+ # Stage 4 -> Immunotherapy/Palliative (Highest cost burden)
68
+ net.add_edge(102, 202, weight=5, color="#ffcc00")
69
+ net.add_edge(102, 203, weight=5, color="#ffcc00")
70
+
71
+ # Gephi-style Bouncy Physics
72
+ net.set_options("""
73
+ var options = {
74
+ "physics": {
75
+ "forceAtlas2Based": {
76
+ "gravitationalConstant": -80,
77
+ "springLength": 100,
78
+ "springConstant": 0.05
79
+ },
80
+ "solver": "forceAtlas2Based"
81
+ }
82
+ }
83
+ """)
84
+
85
+ net.save_graph("roadmap.html")
86
+ with open("roadmap.html", 'r', encoding='utf-8') as f:
87
+ return f.read()
88
+
89
+ # Gradio Tab Component
90
+ with gr.Blocks() as roadmap_page:
91
+ gr.Markdown("## 🌐 Oncology Interaction Network")
92
+ gr.Markdown("An interactive visualization of the AICR cancer types, their progression stages, and the resulting treatment/cost pathways.")
93
+
94
+ gr.HTML(value=generate_roadmap_graph())
95
+
96
+ gr.Markdown("""
97
+ ### 📈 Improvements & Future Iterations
98
+ * **Demographic Gaps:** Future nodes could visualize specific survival disparities in men vs women and different age demographics.
99
+ * **Cost-Stage Correlation:** Visualizing how economic burden shifts from "one-time" surgical costs in early stages to "continuous" high-cost in metastatic stages.
100
+ * **Inclusive Data:** Ensuring rare types like Nasopharyngeal have the same depth of data as common types like Lung or Skin.
101
+ """)