NurseCitizenDeveloper commited on
Commit
8e2a92e
·
1 Parent(s): 62292d6

Enhance: Add genes, tissue selector types, and clinical education

Browse files
Files changed (1) hide show
  1. app.py +73 -37
app.py CHANGED
@@ -38,7 +38,31 @@ st.markdown("""
38
 
39
  # Sidebar controls
40
  st.sidebar.header("Patient & Gene Settings")
41
- gene_choice = st.sidebar.selectbox("Select Gene of Interest", ["INS (Insulin - Diabetes)", "SCN9A (Pain Sensitivity)", "MMP9 (Wound Healing)"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  mutation_intensity = st.sidebar.slider("Mutation Impact (Simulation)", 0.0, 1.0, 0.5, help="Simulate the severity of the regulatory disruption.")
43
 
44
  # Setup API
@@ -47,32 +71,24 @@ api_key = st.secrets.get("ALPHAGENOME_API_KEY")
47
  if not HAS_ALPHAGENOME:
48
  st.error("AlphaGenome library not installed. Please check requirements.txt")
49
  elif not api_key:
50
- st.warning("⚠️ No API Key found! Please add `ALPHAGENOME_API_KEY` to your secrets to see real data. Showing MOCK data for now.")
51
-
52
- # MOCK FALLBACK
 
53
  def get_mock_tracks(gene, mutation_factor):
54
  x = np.linspace(0, 100, 500)
55
  base_signal = np.exp(-((x - 50)**2) / 20)
56
  mutated_signal = base_signal * (1 - mutation_factor * 0.8)
57
  return x, base_signal, mutated_signal
58
-
59
  col1, col2 = st.columns([1, 2])
60
  with col1:
61
- st.subheader("Variant details (MOCK)")
62
- st.info(f"Analyzing Regulatory Region for **{gene_choice.split(' ')[0]}**")
63
- st.write("Variant Type: **Non-Coding / Regulatory**")
64
- if mutation_intensity > 0.7:
65
- st.error("⚠️ HIGH RISK: Significant reduction in gene expression predicted.")
66
- else:
67
- st.success("✅ LOW RISK: Benign variant predicted.")
68
-
69
  with col2:
70
- st.subheader("AlphaGenome Predicted Activity (MOCK)")
71
- x, normal, mutant = get_mock_tracks(gene_choice, mutation_intensity)
72
  fig, ax = plt.subplots(figsize=(10, 5))
73
- ax.plot(x, normal, label="Healthy Control", color='green')
74
- ax.plot(x, mutant, label="Patient Variant", color='red', linestyle='--')
75
- ax.legend()
76
  st.pyplot(fig)
77
 
78
  else:
@@ -82,46 +98,66 @@ else:
82
  # Initialize Client
83
  model = dna_client.create(api_key)
84
 
85
- # Define coordinates for demo genes - AlphaGenome only supports specific lengths:
86
- # 16384, 131072, 524288, 1048576 - using 16384bp intervals
 
 
 
 
 
 
87
  gene_coords = {
88
- "INS": {"chr": "chr11", "start": 2151808, "end": 2168192, "pos": 2160000}, # 16384bp
89
- "SCN9A": {"chr": "chr2", "start": 166191808, "end": 166208192, "pos": 166200000}, # 16384bp
90
- "MMP9": {"chr": "chr20", "start": 46006808, "end": 46023192, "pos": 46015000} # 16384bp
 
 
 
91
  }
92
 
93
- gene_sym = gene_choice.split(' ')[0]
94
  coords = gene_coords.get(gene_sym, gene_coords["INS"])
95
 
96
  try:
97
- with st.spinner("Querying Google DeepMind TPUs..."):
98
  interval = genome.Interval(chromosome=coords["chr"], start=coords["start"], end=coords["end"])
99
- # Create a dummy variant at the center
100
  variant = genome.Variant(
101
  chromosome=coords["chr"],
102
  position=coords["pos"],
103
  reference_bases='A',
104
- alternate_bases='C' # simple mutation
105
  )
106
 
107
- # Predict
108
  outputs = model.predict_variant(
109
  interval=interval,
110
  variant=variant,
111
- ontology_terms=['UBERON:0000178'], # blood tissue - generic for nursing context
112
  requested_outputs=[dna_client.OutputType.RNA_SEQ],
113
  )
114
 
115
  col1, col2 = st.columns([1, 2])
116
  with col1:
117
- st.subheader("Real Analysis")
118
- st.markdown(f"**Gene**: {gene_sym}")
119
- st.markdown(f"**Locus**: {coords['chr']}:{coords['start']}-{coords['end']}")
120
- st.success("Prediction successful!")
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  with col2:
123
- st.subheader("AlphaGenome Tracks")
124
- # Use plot_components from the library
125
  fig = plot_components.plot(
126
  [
127
  plot_components.OverlaidTracks(
@@ -129,10 +165,10 @@ else:
129
  'REF': outputs.reference.rna_seq,
130
  'ALT': outputs.alternate.rna_seq,
131
  },
132
- colors={'REF': 'dimgrey', 'ALT': 'red'},
133
  ),
134
  ],
135
- interval=outputs.reference.rna_seq.interval.resize(2**15),
136
  annotations=[plot_components.VariantAnnotation([variant], alpha=0.8)],
137
  )
138
  st.pyplot(fig)
 
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 = {
56
+ "Blood (General)": "UBERON:0000178",
57
+ "Liver": "UBERON:0002107",
58
+ "Skin": "UBERON:0002097",
59
+ "Breast": "UBERON:0000310",
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.")
67
 
68
  # Setup API
 
71
  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)
81
  mutated_signal = base_signal * (1 - mutation_factor * 0.8)
82
  return x, base_signal, mutated_signal
83
+
84
  col1, col2 = st.columns([1, 2])
85
  with col1:
86
+ st.info(f"Mock Analysis for {gene_sym}")
 
 
 
 
 
 
 
87
  with col2:
88
+ x, normal, mutant = get_mock_tracks(gene_sym, mutation_intensity)
 
89
  fig, ax = plt.subplots(figsize=(10, 5))
90
+ ax.plot(x, normal, label="Ref", color='green')
91
+ ax.plot(x, mutant, label="Alt", color='red', linestyle='--')
 
92
  st.pyplot(fig)
93
 
94
  else:
 
98
  # Initialize Client
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"])
119
 
120
  try:
121
+ with st.spinner(f"Querying AlphaGenome (Target: {tissue_label})..."):
122
  interval = genome.Interval(chromosome=coords["chr"], start=coords["start"], end=coords["end"])
 
123
  variant = genome.Variant(
124
  chromosome=coords["chr"],
125
  position=coords["pos"],
126
  reference_bases='A',
127
+ alternate_bases='C'
128
  )
129
 
 
130
  outputs = model.predict_variant(
131
  interval=interval,
132
  variant=variant,
133
+ ontology_terms=[ontology_term],
134
  requested_outputs=[dna_client.OutputType.RNA_SEQ],
135
  )
136
 
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})")
 
161
  fig = plot_components.plot(
162
  [
163
  plot_components.OverlaidTracks(
 
165
  'REF': outputs.reference.rna_seq,
166
  'ALT': outputs.alternate.rna_seq,
167
  },
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)