supercat666 commited on
Commit
9f2ad27
1 Parent(s): 743b6b7
Files changed (1) hide show
  1. app.py +23 -42
app.py CHANGED
@@ -132,7 +132,7 @@ if selected_model == 'Cas9':
132
 
133
  # Gene symbol entry with autocomplete-like feature
134
  gene_symbol = st.selectbox('Enter a Gene Symbol:', [''] + gene_symbol_list, key='gene_symbol',
135
- format_func=lambda x: x if x else "e.g., FOXA1")
136
 
137
  # Handle gene symbol change and file cleanup
138
  if gene_symbol != st.session_state['current_gene_symbol'] and gene_symbol:
@@ -176,30 +176,25 @@ if selected_model == 'Cas9':
176
  fig = go.Figure()
177
 
178
  # Plot Exons as horizontal lines or rectangles
179
- exon_y = 0.2 # Adjust this as needed
180
  for exon in st.session_state['exons']:
181
  exon_start, exon_end = int(exon['start']), int(exon['end'])
182
- fig.add_trace(go.Scatter(
183
- x=[exon_start, exon_end],
184
- y=[exon_y, exon_y],
185
- mode='lines',
186
- line=dict(color='purple', width=10), # Adjust styling as needed
187
- name='Exon'
188
- ))
189
-
190
- # Plot CDS as horizontal lines or rectangles
191
- cds_y = 0.3 # Adjust this as needed
192
  for cds in st.session_state['cds']:
193
  cds_start, cds_end = int(cds['start']), int(cds['end'])
194
- fig.add_trace(go.Scatter(
195
- x=[cds_start, cds_end],
196
- y=[cds_y, cds_y],
197
- mode='lines',
198
- line=dict(color='blue', width=10), # Adjust styling as needed
199
- name='CDS'
200
- ))
201
 
202
- # Plot gRNAs using triangles to indicate direction
203
  # Initialize the y position for the positive and negative strands
204
  positive_strand_y = 0.1
205
  negative_strand_y = -0.1
@@ -208,41 +203,27 @@ if selected_model == 'Cas9':
208
  # Iterate over the sorted predictions to create the plot
209
  for i, prediction in enumerate(st.session_state['on_target_results'], start=1):
210
  chrom, start, end, strand, target, gRNA, pred_score = prediction
211
- start, end = int(start), int(end)
212
  midpoint = (start + end) / 2
213
-
214
- if strand == '1': # Positive strand
215
- y_value = positive_strand_y
216
- arrow_symbol = 'triangle-right'
217
- positive_strand_y += offset
218
- else: # Negative strand
219
- y_value = negative_strand_y
220
- arrow_symbol = 'triangle-left'
221
- negative_strand_y -= offset
222
 
223
  fig.add_trace(go.Scatter(
224
  x=[midpoint],
225
  y=[y_value],
226
  mode='markers+text',
227
- marker=dict(symbol=arrow_symbol, size=10),
228
- name=f"gRNA: {gRNA}",
229
- text=f"Rank: {i}",
230
  hoverinfo='text',
231
  hovertext=f"Rank: {i}<br>Chromosome: {chrom}<br>Target Sequence: {target}<br>gRNA: {gRNA}<br>Start: {start}<br>End: {end}<br>Strand: {'+' if strand == '1' else '-'}<br>Prediction Score: {pred_score:.4f}",
232
  ))
233
 
234
- # Update the layout of the plot
235
  fig.update_layout(
236
  title='Top 10 gRNA Sequences by Prediction Score',
237
  xaxis_title='Genomic Position',
238
- yaxis=dict(
239
- title='Strand',
240
- showgrid=True,
241
- zeroline=False,
242
- tickvals=[positive_strand_y, negative_strand_y, exon_y, cds_y],
243
- ticktext=['+ Strand gRNAs', '- Strand gRNAs', 'Exons', 'CDS']
244
- ),
245
- showlegend=True
246
  )
247
 
248
  # Display the plot
 
132
 
133
  # Gene symbol entry with autocomplete-like feature
134
  gene_symbol = st.selectbox('Enter a Gene Symbol:', [''] + gene_symbol_list, key='gene_symbol',
135
+ format_func=lambda x: x if x else "")
136
 
137
  # Handle gene symbol change and file cleanup
138
  if gene_symbol != st.session_state['current_gene_symbol'] and gene_symbol:
 
176
  fig = go.Figure()
177
 
178
  # Plot Exons as horizontal lines or rectangles
 
179
  for exon in st.session_state['exons']:
180
  exon_start, exon_end = int(exon['start']), int(exon['end'])
181
+ # Create a rectangle for each exon
182
+ fig.add_shape(type="rect",
183
+ x0=exon_start, y0=-1, # Start slightly below the axis for visibility
184
+ x1=exon_end, y1=1, # End slightly above the axis
185
+ line=dict(color="purple", width=2),
186
+ fillcolor="rgba(128, 0, 128, 0.3)") # Semi-transparent purple
187
+
188
+ # Plot CDS areas with similar approach but different color
 
 
189
  for cds in st.session_state['cds']:
190
  cds_start, cds_end = int(cds['start']), int(cds['end'])
191
+ fig.add_shape(type="rect",
192
+ x0=cds_start, y0=-1,
193
+ x1=cds_end, y1=1,
194
+ line=dict(color="blue", width=2),
195
+ fillcolor="rgba(0, 0, 255, 0.3)")
 
 
196
 
197
+ # Plot gRNAs using triangles to indicate direction
198
  # Initialize the y position for the positive and negative strands
199
  positive_strand_y = 0.1
200
  negative_strand_y = -0.1
 
203
  # Iterate over the sorted predictions to create the plot
204
  for i, prediction in enumerate(st.session_state['on_target_results'], start=1):
205
  chrom, start, end, strand, target, gRNA, pred_score = prediction
 
206
  midpoint = (start + end) / 2
207
+ y_value = i * 0.1 if strand == '1' else -i * 0.1 # Adjust multiplier for spacing
 
 
 
 
 
 
 
 
208
 
209
  fig.add_trace(go.Scatter(
210
  x=[midpoint],
211
  y=[y_value],
212
  mode='markers+text',
213
+ marker=dict(symbol='triangle-up' if strand == '1' else 'triangle-down', size=12),
214
+ text=f"Rank: {i}", # Adjust based on your data
 
215
  hoverinfo='text',
216
  hovertext=f"Rank: {i}<br>Chromosome: {chrom}<br>Target Sequence: {target}<br>gRNA: {gRNA}<br>Start: {start}<br>End: {end}<br>Strand: {'+' if strand == '1' else '-'}<br>Prediction Score: {pred_score:.4f}",
217
  ))
218
 
219
+ # Update the layout of the plot for better clarity and interactivity
220
  fig.update_layout(
221
  title='Top 10 gRNA Sequences by Prediction Score',
222
  xaxis_title='Genomic Position',
223
+ yaxis_title='Strand',
224
+ showlegend=False, # Toggle based on preference
225
+ xaxis=dict(showspikes=True, spikecolor="grey", spikesnap="cursor", spikemode="across"),
226
+ hovermode='closest' # Adjust for best hover interaction
 
 
 
 
227
  )
228
 
229
  # Display the plot