supercat666 commited on
Commit
743d44b
1 Parent(s): 4e09368
Files changed (1) hide show
  1. app.py +31 -42
app.py CHANGED
@@ -190,77 +190,66 @@ if selected_model == 'Cas9':
190
  # Initialize Plotly figure
191
  fig = go.Figure()
192
 
193
- # Constants for the appearance
194
- EXON_HEIGHT = 0.05 # How 'tall' the exon markers should appear
195
- CDS_HEIGHT = 0.05 # How 'tall' the CDS markers should appear
196
- Y_POS = -0.1 # Position on the Y axis to place these markers
197
 
198
- # Plot Exons as small markers on the X-axis
 
 
 
199
  for exon in st.session_state['exons']:
200
  exon_start, exon_end = exon['start'], exon['end']
201
- # Using bars for better control over width and position
202
- fig.add_trace(go.Bar(
203
- x=[(exon_start + exon_end) / 2], # Position at the center of the exon
204
- y=[EXON_HEIGHT],
205
- width=[exon_end - exon_start], # Width of the bar is the exon length
206
- base=[Y_POS],
207
- marker_color='purple',
208
  name='Exon'
209
  ))
210
 
211
- # Plot CDS in a similar manner
212
  for cds in st.session_state['cds']:
213
  cds_start, cds_end = cds['start'], cds['end']
214
- fig.add_trace(go.Bar(
215
- x=[(cds_start + cds_end) / 2], # Position at the center of the CDS
216
- y=[CDS_HEIGHT],
217
- width=[cds_end - cds_start], # Width of the bar is the CDS length
218
- base=[Y_POS - EXON_HEIGHT], # Slightly offset from the exons
219
- marker_color='blue',
220
  name='CDS'
221
  ))
222
 
223
- # Plot gRNAs using triangles to indicate direction
224
- # Initialize the y position for the positive and negative strands
225
- positive_strand_y = 0.1
226
- negative_strand_y = -0.1
227
- offset = 0.05 # Use an offset to spread gRNA sequences vertically
228
 
229
- # Iterate over the sorted predictions to create the plot
230
  for i, prediction in enumerate(st.session_state['on_target_results'], start=1):
231
  chrom, start, end, strand, target, gRNA, pred_score = prediction
232
-
233
  midpoint = (int(start) + int(end)) / 2
234
- y_value = i * 0.1 if strand == '1' else -i * 0.1 # Adjust multiplier for spacing
 
 
235
 
236
  fig.add_trace(go.Scatter(
237
  x=[midpoint],
238
  y=[y_value],
239
  mode='markers+text',
240
  marker=dict(symbol='triangle-up' if strand == '1' else 'triangle-down', size=12),
241
- text=f"Rank: {i}", # Adjust based on your data
242
  hoverinfo='text',
243
  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}",
244
  ))
245
 
246
- # Update the layout of the plot for better clarity and interactivity
247
  fig.update_layout(
248
  title='Top 10 gRNA Sequences by Prediction Score',
249
  xaxis_title='Genomic Position',
250
  yaxis_title='Strand',
251
- showlegend=False, # Toggle based on preference
252
- xaxis=dict(
253
- showspikes=True, # Show spike line for X-axis
254
- spikemode='across',
255
- spikesnap='cursor',
256
- spikethickness=1,
257
- spikecolor='grey',
258
- showline=True,
259
- showgrid=True,
260
- tickformat='.2f', # Adjust based on the precision you need
261
- ),
262
- hovermode='x',
263
- hoverdistance=100, # Adjust for best hover interaction
264
  )
265
 
266
  # Display the plot
 
190
  # Initialize Plotly figure
191
  fig = go.Figure()
192
 
193
+ # Adjust these constants for appearance
194
+ LINE_WIDTH = 2 # Width of EXON and CDS lines
195
+ EXON_OPACITY = 0.5 # Make exon lines semi-transparent
 
196
 
197
+ # Ensure EXON and CDS are drawn at the same Y position on the X-axis
198
+ EXON_CDS_Y_POS = 0 # Directly on the X-axis
199
+
200
+ # Draw EXONs
201
  for exon in st.session_state['exons']:
202
  exon_start, exon_end = exon['start'], exon['end']
203
+ fig.add_trace(go.Scatter(
204
+ x=[exon_start, exon_end],
205
+ y=[EXON_CDS_Y_POS, EXON_CDS_Y_POS],
206
+ mode='lines',
207
+ line=dict(color='purple', width=LINE_WIDTH, opacity=EXON_OPACITY),
 
 
208
  name='Exon'
209
  ))
210
 
211
+ # Draw CDSs
212
  for cds in st.session_state['cds']:
213
  cds_start, cds_end = cds['start'], cds['end']
214
+ fig.add_trace(go.Scatter(
215
+ x=[cds_start, cds_end],
216
+ y=[EXON_CDS_Y_POS, EXON_CDS_Y_POS],
217
+ mode='lines',
218
+ line=dict(color='blue', width=LINE_WIDTH + 1), # Slightly thicker than EXON
 
219
  name='CDS'
220
  ))
221
 
222
+ # Adjust hover interaction and strand plotting
223
+ MAX_STRAND_Y = 0.5 # Maximum Y value for positive strand
224
+ MIN_STRAND_Y = -0.5 # Minimum Y value for negative strand
 
 
225
 
226
+ # Iterate over sorted predictions to create the plot
227
  for i, prediction in enumerate(st.session_state['on_target_results'], start=1):
228
  chrom, start, end, strand, target, gRNA, pred_score = prediction
 
229
  midpoint = (int(start) + int(end)) / 2
230
+
231
+ # Position based on strand, but within a fixed range
232
+ y_value = MAX_STRAND_Y if strand == '1' else MIN_STRAND_Y
233
 
234
  fig.add_trace(go.Scatter(
235
  x=[midpoint],
236
  y=[y_value],
237
  mode='markers+text',
238
  marker=dict(symbol='triangle-up' if strand == '1' else 'triangle-down', size=12),
239
+ text=f"Rank: {i}", # Text label
240
  hoverinfo='text',
241
  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}",
242
  ))
243
 
244
+ # Update layout for clarity and interaction
245
  fig.update_layout(
246
  title='Top 10 gRNA Sequences by Prediction Score',
247
  xaxis_title='Genomic Position',
248
  yaxis_title='Strand',
249
+ yaxis=dict(range=[MIN_STRAND_Y - 0.1, MAX_STRAND_Y + 0.1]), # Fix y-axis range
250
+ showlegend=False,
251
+ hovermode='closest', # Adjust hover mode
252
+ hoverdistance=20, # Reduce hover distance to improve accuracy
 
 
 
 
 
 
 
 
 
253
  )
254
 
255
  # Display the plot