NurseCitizenDeveloper commited on
Commit
f2163ea
Β·
1 Parent(s): 8e2a92e

Feature: Add Pharmacogenomics module with BNF interaction styling

Browse files
Files changed (1) hide show
  1. app.py +89 -41
app.py CHANGED
@@ -37,19 +37,40 @@ st.markdown("""
37
  """)
38
 
39
  # Sidebar controls
40
- st.sidebar.header("Patient & Gene Settings")
41
-
42
- # 1. Expanded Gene Selection
43
- gene_options = {
44
- "INS (Diabetes)": "INS",
45
- "SCN9A (Pain Sensitivity)": "SCN9A",
46
- "MMP9 (Wound Healing)": "MMP9",
47
- "HBB (Sickle Cell/Thalassemia)": "HBB",
48
- "BRCA1 (Breast Cancer)": "BRCA1",
49
- "LDLR (Hypercholesterolemia)": "LDLR"
50
- }
51
- gene_label = st.sidebar.selectbox("Select Gene of Interest", list(gene_options.keys()))
52
- gene_sym = gene_options[gene_label]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  # 2. Tissue Context Selector (UBERON Ontology)
55
  tissue_options = {
@@ -60,7 +81,10 @@ tissue_options = {
60
  "Brain": "UBERON:0000955",
61
  "Lung": "UBERON:0002048"
62
  }
63
- tissue_label = st.sidebar.selectbox("Select Tissue Context", list(tissue_options.keys()))
 
 
 
64
  ontology_term = tissue_options[tissue_label]
65
 
66
  mutation_intensity = st.sidebar.slider("Mutation Impact (Simulation)", 0.0, 1.0, 0.5, help="Simulate the severity of the regulatory disruption.")
@@ -72,9 +96,7 @@ if not HAS_ALPHAGENOME:
72
  st.error("AlphaGenome library not installed. Please check requirements.txt")
73
  elif not api_key:
74
  st.warning("⚠️ No API Key found! Showing MOCK data.")
75
- # ... mock logic omitted for brevity, keeping existing fallbacks if needed or defaulting to warning ...
76
- # For this full update, we assume user has key as established.
77
- # Re-implementing a simple mock fallback for safety:
78
  def get_mock_tracks(gene, mutation_factor):
79
  x = np.linspace(0, 100, 500)
80
  base_signal = np.exp(-((x - 50)**2) / 20)
@@ -99,20 +121,18 @@ else:
99
  model = dna_client.create(api_key)
100
 
101
  # Real Coordinates (16384bp centered)
102
- # INS: 11:2160000 -> 2151808-2168192
103
- # SCN9A: 2:166200000 -> 166191808-166208192
104
- # MMP9: 20:46015000 -> 46006808-46023192
105
- # HBB: 11:5227000 (approx) -> 5218808-5235192
106
- # BRCA1: 17:43063000 (approx) -> 43054808-43071192
107
- # LDLR: 19:11113000 (approx) -> 11104808-11121192
108
-
109
  gene_coords = {
110
  "INS": {"chr": "chr11", "start": 2151808, "end": 2168192, "pos": 2160000},
111
  "SCN9A": {"chr": "chr2", "start": 166191808, "end": 166208192, "pos": 166200000},
112
  "MMP9": {"chr": "chr20", "start": 46006808, "end": 46023192, "pos": 46015000},
113
  "HBB": {"chr": "chr11", "start": 5218808, "end": 5235192, "pos": 5227000},
114
  "BRCA1": {"chr": "chr17", "start": 43054808, "end": 43071192, "pos": 43063000},
115
- "LDLR": {"chr": "chr19", "start": 11104808, "end": 11121192, "pos": 11113000}
 
 
 
 
 
116
  }
117
 
118
  coords = gene_coords.get(gene_sym, gene_coords["INS"])
@@ -137,24 +157,52 @@ else:
137
  col1, col2 = st.columns([1, 2])
138
  with col1:
139
  st.subheader("Analysis Context")
 
 
 
140
  st.markdown(f"**Gene**: `{gene_sym}`")
141
  st.markdown(f"**Tissue**: `{tissue_label}`")
142
- st.markdown(f"**Locus**: `{coords['chr']}:{coords['start']}-{coords['end']}`")
143
 
144
- # Educational Content - Clinical Implications
145
- with st.expander("πŸ‘©β€βš•οΈ Nursing Implications", expanded=True):
146
- if gene_sym == "INS":
147
- st.write("Disruption here affects **Insulin production**. Reduced expression can lead to hyperglycemia and T1D/MODY mechanisms.")
148
- elif gene_sym == "SCN9A":
149
- st.write("Controls sodium channels in pain neurons. Over-expression can cause **chronic pain**; under-expression leads to **pain insensitivity**.")
150
- elif gene_sym == "MMP9":
151
- st.write("Key enzyme in wound remodeling. Poor regulation leads to **chronic non-healing wounds**.")
152
- elif gene_sym == "HBB":
153
- st.write("Encodes Beta-Globin. Regulatory variants can cause **Beta-Thalassemia** even if the protein code is normal.")
154
- elif gene_sym == "BRCA1":
155
- st.write("Tumor suppressor. Loss of expression increases risk of **Breast/Ovarian Cancer**.")
156
- elif gene_sym == "LDLR":
157
- st.write("Removes LDL cholesterol. Lower expression leads to **Familial Hypercholesterolemia** and early heart disease.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  with col2:
160
  st.subheader(f"AlphaGenome Tracks ({tissue_label})")
@@ -168,7 +216,7 @@ else:
168
  colors={'REF': 'dimgrey', 'ALT': '#ff4b4b'}, # Streamlit red
169
  ),
170
  ],
171
- interval=outputs.reference.rna_seq.interval.resize(2**14), # Zoom in slightly
172
  annotations=[plot_components.VariantAnnotation([variant], alpha=0.8)],
173
  )
174
  st.pyplot(fig)
 
37
  """)
38
 
39
  # Sidebar controls
40
+ st.sidebar.header("Analysis Settings")
41
+
42
+ # 1. Mode Selector
43
+ analysis_mode = st.sidebar.radio("Select Analysis Mode", ["Disease Risk (Pathology)", "Drug Response (Pharmacogenomics)"])
44
+
45
+ gene_sym = "INS" # Default
46
+ gene_label = "INS"
47
+ drug_label = None
48
+
49
+ if analysis_mode == "Disease Risk (Pathology)":
50
+ # Disease Gene Selection
51
+ gene_options = {
52
+ "INS (Diabetes)": "INS",
53
+ "SCN9A (Pain Sensitivity)": "SCN9A",
54
+ "MMP9 (Wound Healing)": "MMP9",
55
+ "HBB (Sickle Cell/Thalassemia)": "HBB",
56
+ "BRCA1 (Breast Cancer)": "BRCA1",
57
+ "LDLR (Hypercholesterolemia)": "LDLR"
58
+ }
59
+ gene_label = st.sidebar.selectbox("Select Gene of Interest", list(gene_options.keys()))
60
+ gene_sym = gene_options[gene_label]
61
+
62
+ else:
63
+ # Pharmacogenomics Drug Selection
64
+ st.sidebar.markdown("### πŸ’Š Drug Selection")
65
+ drug_options = {
66
+ "Warfarin (Anticoagulant)": {"gene": "CYP2C9", "action": "Metabolism"},
67
+ "Clopidogrel (Antiplatelet)": {"gene": "CYP2C19", "action": "Bioactivation"},
68
+ "Simvastatin (Statin)": {"gene": "SLCO1B1", "action": "Transport"}
69
+ }
70
+ drug_label = st.sidebar.selectbox("Select Medication", list(drug_options.keys()))
71
+ gene_sym = drug_options[drug_label]["gene"]
72
+ st.sidebar.info(f"Analyzing Gene: **{gene_sym}** ({drug_options[drug_label]['action']})")
73
+
74
 
75
  # 2. Tissue Context Selector (UBERON Ontology)
76
  tissue_options = {
 
81
  "Brain": "UBERON:0000955",
82
  "Lung": "UBERON:0002048"
83
  }
84
+
85
+ # Auto-select Liver for PGx if possible, but allow change
86
+ default_tissue_index = 1 if analysis_mode == "Drug Response (Pharmacogenomics)" else 0
87
+ tissue_label = st.sidebar.selectbox("Select Tissue Context", list(tissue_options.keys()), index=default_tissue_index)
88
  ontology_term = tissue_options[tissue_label]
89
 
90
  mutation_intensity = st.sidebar.slider("Mutation Impact (Simulation)", 0.0, 1.0, 0.5, help="Simulate the severity of the regulatory disruption.")
 
96
  st.error("AlphaGenome library not installed. Please check requirements.txt")
97
  elif not api_key:
98
  st.warning("⚠️ No API Key found! Showing MOCK data.")
99
+
 
 
100
  def get_mock_tracks(gene, mutation_factor):
101
  x = np.linspace(0, 100, 500)
102
  base_signal = np.exp(-((x - 50)**2) / 20)
 
121
  model = dna_client.create(api_key)
122
 
123
  # Real Coordinates (16384bp centered)
 
 
 
 
 
 
 
124
  gene_coords = {
125
  "INS": {"chr": "chr11", "start": 2151808, "end": 2168192, "pos": 2160000},
126
  "SCN9A": {"chr": "chr2", "start": 166191808, "end": 166208192, "pos": 166200000},
127
  "MMP9": {"chr": "chr20", "start": 46006808, "end": 46023192, "pos": 46015000},
128
  "HBB": {"chr": "chr11", "start": 5218808, "end": 5235192, "pos": 5227000},
129
  "BRCA1": {"chr": "chr17", "start": 43054808, "end": 43071192, "pos": 43063000},
130
+ "LDLR": {"chr": "chr19", "start": 11104808, "end": 11121192, "pos": 11113000},
131
+ # PGx Genes (using dummy coords on valid chromosomes for demo, waiting for specific locus research)
132
+ # Using approximate loci for 16384bp window
133
+ "CYP2C9": {"chr": "chr10", "start": 94981200, "end": 94997584, "pos": 94989392},
134
+ "CYP2C19": {"chr": "chr10", "start": 94775000, "end": 94791384, "pos": 94783192},
135
+ "SLCO1B1": {"chr": "chr12", "start": 21132000, "end": 21148384, "pos": 21140192},
136
  }
137
 
138
  coords = gene_coords.get(gene_sym, gene_coords["INS"])
 
157
  col1, col2 = st.columns([1, 2])
158
  with col1:
159
  st.subheader("Analysis Context")
160
+ if analysis_mode == "Drug Response (Pharmacogenomics)":
161
+ st.markdown(f"**Drug**: `{drug_label.split('(')[0]}`")
162
+
163
  st.markdown(f"**Gene**: `{gene_sym}`")
164
  st.markdown(f"**Tissue**: `{tissue_label}`")
 
165
 
166
+ if analysis_mode == "Disease Risk (Pathology)":
167
+ # Educational Content - Clinical Implications
168
+ with st.expander("πŸ‘©β€βš•οΈ Nursing Implications", expanded=True):
169
+ if gene_sym == "INS":
170
+ st.write("Disruption here affects **Insulin production**. Reduced expression can lead to hyperglycemia and T1D/MODY mechanisms.")
171
+ elif gene_sym == "SCN9A":
172
+ st.write("Controls sodium channels in pain neurons. Over-expression can cause **chronic pain**; under-expression leads to **pain insensitivity**.")
173
+ elif gene_sym == "MMP9":
174
+ st.write("Key enzyme in wound remodeling. Poor regulation leads to **chronic non-healing wounds**.")
175
+ elif gene_sym == "HBB":
176
+ st.write("Encodes Beta-Globin. Regulatory variants can cause **Beta-Thalassemia** even if the protein code is normal.")
177
+ elif gene_sym == "BRCA1":
178
+ st.write("Tumor suppressor. Loss of expression increases risk of **Breast/Ovarian Cancer**.")
179
+ elif gene_sym == "LDLR":
180
+ st.write("Removes LDL cholesterol. Lower expression leads to **Familial Hypercholesterolemia** and early heart disease.")
181
+
182
+ else:
183
+ # PHARMACOGENOMICS ALERTS
184
+ st.divider()
185
+ st.caption("πŸ’Š CLINICAL DECISION SUPPORT")
186
+
187
+ if mutation_intensity > 0.6:
188
+ st.error("⚠️ **ADVERSE DRUG REACTION RISK**")
189
+ if gene_sym == "CYP2C9": # Warfarin
190
+ st.markdown("**Phenotype**: Poor Metabolizer")
191
+ st.markdown("**Risk**: Drug accumulation. High bleed risk.")
192
+ st.markdown("πŸ‘‰ **Action**: Consider **50% dose reduction** or switch anticoagulant.")
193
+ elif gene_sym == "CYP2C19": # Clopidogrel
194
+ st.markdown("**Phenotype**: Poor Metabolizer (No Activation)")
195
+ st.markdown("**Risk**: Therapeutic failure. Clot risk remains.")
196
+ st.markdown("πŸ‘‰ **Action**: **CONTRAINDICATED**. Switch to Ticagrelor.")
197
+ elif gene_sym == "SLCO1B1": # Simvastatin
198
+ st.markdown("**Phenotype**: Poor Transporter Function")
199
+ st.markdown("**Risk**: High systemic levels. Risk of myopathy.")
200
+ st.markdown("πŸ‘‰ **Action**: Max dose **20mg** or switch statin.")
201
+ else:
202
+ st.success("βœ… **STANDARD DOSING**")
203
+ st.markdown("**Phenotype**: Normal Metabolizer")
204
+ st.markdown("No significant regulatory disruption detected.")
205
+
206
 
207
  with col2:
208
  st.subheader(f"AlphaGenome Tracks ({tissue_label})")
 
216
  colors={'REF': 'dimgrey', 'ALT': '#ff4b4b'}, # Streamlit red
217
  ),
218
  ],
219
+ interval=outputs.reference.rna_seq.interval.resize(2**14),
220
  annotations=[plot_components.VariantAnnotation([variant], alpha=0.8)],
221
  )
222
  st.pyplot(fig)