supercat666 commited on
Commit
e7225c8
1 Parent(s): 7274bd3

fixed bugs

Browse files
Files changed (1) hide show
  1. app.py +51 -30
app.py CHANGED
@@ -136,35 +136,46 @@ if selected_model == 'Cas9':
136
  # Now create a Plotly plot with the sorted_predictions
137
  fig = go.Figure()
138
 
139
- # Set y values based on strand information
140
- strand_y_values = {'1': 1, '-1': -1}
 
 
141
 
142
  # Iterate over the sorted predictions to create the plot
143
  for i, prediction in enumerate(sorted_predictions, start=1):
144
  # Extract data for plotting
145
- chrom, start, end, strand, target, gRNA, pred_score = prediction # Adjusted to include the target sequence
146
- # Assign y value based on strand
147
- y_value = strand_y_values[str(strand)] # Convert strand to string for dict lookup
148
  fig.add_trace(go.Scatter(
149
  x=[start, end],
150
- y=[y_value] * len(start), # Assign all points the same y value based on strand
151
  mode='lines+markers+text',
152
  name=f"gRNA: {gRNA}",
153
- text=f"Rank: {i}", # Place text at the first point
154
  hoverinfo='text',
155
- 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}",
 
 
 
156
  ))
 
 
 
 
 
157
 
158
  # Update the layout of the plot
159
  fig.update_layout(
160
- title='CRISPR Targets by Strand',
161
  xaxis_title='Genomic Position',
 
162
  yaxis=dict(
163
- title='Strand',
164
- tickmode='array',
165
- tickvals=[1, -1],
166
- ticktext=['+ Strand', '- Strand']
167
- )
 
168
  )
169
 
170
  # Display the plot
@@ -351,35 +362,46 @@ elif selected_model == 'Cas12':
351
  # Now create a Plotly plot with the sorted_predictions
352
  fig = go.Figure()
353
 
354
- # Set y values based on strand information
355
- strand_y_values = {'1': 1, '-1': -1}
 
 
356
 
357
  # Iterate over the sorted predictions to create the plot
358
  for i, prediction in enumerate(sorted_predictions, start=1):
359
  # Extract data for plotting
360
- chrom, start, end, strand, target, gRNA, pred_score = prediction # Adjusted to include the target sequence
361
- # Assign y value based on strand
362
- y_value = strand_y_values[str(strand)] # Convert strand to string for dict lookup
363
  fig.add_trace(go.Scatter(
364
  x=[start, end],
365
- y=[y_value] * len(start), # Assign all points the same y value based on strand
366
  mode='lines+markers+text',
367
  name=f"gRNA: {gRNA}",
368
- text=f"Rank: {i}", # Place text at the first point
369
  hoverinfo='text',
370
- 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}",
 
 
 
371
  ))
 
 
 
 
 
372
 
373
  # Update the layout of the plot
374
  fig.update_layout(
375
- title='CRISPR Targets by Strand',
376
  xaxis_title='Genomic Position',
 
377
  yaxis=dict(
378
- title='Strand',
379
- tickmode='array',
380
- tickvals=[1, -1],
381
- ticktext=['+ Strand', '- Strand']
382
- )
 
383
  )
384
 
385
  # Display the plot
@@ -417,8 +439,7 @@ elif selected_model == 'Cas12':
417
  st.download_button(label="Download CSV File", data=file, file_name=csv_file_path,
418
  mime="text/csv")
419
 
420
- # Clean up old files after download buttons are created
421
- clean_up_old_files(gene_symbol)
422
 
423
  elif selected_model == 'Cas13d':
424
  ENTRY_METHODS = dict(
 
136
  # Now create a Plotly plot with the sorted_predictions
137
  fig = go.Figure()
138
 
139
+ # Variables to help spread gRNAs on the y-axis based on their strand
140
+ y_positive_strand = 10
141
+ y_negative_strand = -10
142
+ strand_offset = 1 # This will space out each subsequent guide on the same strand
143
 
144
  # Iterate over the sorted predictions to create the plot
145
  for i, prediction in enumerate(sorted_predictions, start=1):
146
  # Extract data for plotting
147
+ chrom, start, end, strand, target, gRNA, pred_score = prediction
148
+ y_value = y_positive_strand if strand == 1 else y_negative_strand
 
149
  fig.add_trace(go.Scatter(
150
  x=[start, end],
151
+ y=[y_value, y_value], # Assign all points the same y value based on strand
152
  mode='lines+markers+text',
153
  name=f"gRNA: {gRNA}",
154
+ text=[f"Rank: {i}", ""], # Text at the start position only
155
  hoverinfo='text',
156
+ hovertext=[
157
+ f"Rank: {i}<br>Target: {target}<br>gRNA: {gRNA}<br>Cutsite: {start}<br>On Target Score: {pred_score:.4f}",
158
+ ""
159
+ ],
160
  ))
161
+ # Update the y-value for the next guide on the same strand
162
+ if strand == 1:
163
+ y_positive_strand += strand_offset
164
+ else:
165
+ y_negative_strand -= strand_offset
166
 
167
  # Update the layout of the plot
168
  fig.update_layout(
169
+ title='Top 10 gRNA Sequences by Prediction Score',
170
  xaxis_title='Genomic Position',
171
+ yaxis_title='Strand',
172
  yaxis=dict(
173
+ showgrid=True, # Show horizontal gridlines for clarity
174
+ zeroline=True, # Show a line at y=0
175
+ zerolinecolor='Black',
176
+ zerolinewidth=2,
177
+ ),
178
+ showlegend=False # Hide the legend if it's not necessary
179
  )
180
 
181
  # Display the plot
 
362
  # Now create a Plotly plot with the sorted_predictions
363
  fig = go.Figure()
364
 
365
+ # Variables to help spread gRNAs on the y-axis based on their strand
366
+ y_positive_strand = 10
367
+ y_negative_strand = -10
368
+ strand_offset = 1 # This will space out each subsequent guide on the same strand
369
 
370
  # Iterate over the sorted predictions to create the plot
371
  for i, prediction in enumerate(sorted_predictions, start=1):
372
  # Extract data for plotting
373
+ chrom, start, end, strand, target, gRNA, pred_score = prediction
374
+ y_value = y_positive_strand if strand == 1 else y_negative_strand
 
375
  fig.add_trace(go.Scatter(
376
  x=[start, end],
377
+ y=[y_value, y_value], # Assign all points the same y value based on strand
378
  mode='lines+markers+text',
379
  name=f"gRNA: {gRNA}",
380
+ text=[f"Rank: {i}", ""], # Text at the start position only
381
  hoverinfo='text',
382
+ hovertext=[
383
+ f"Rank: {i}<br>Target: {target}<br>gRNA: {gRNA}<br>Cutsite: {start}<br>On Target Score: {pred_score:.4f}",
384
+ ""
385
+ ],
386
  ))
387
+ # Update the y-value for the next guide on the same strand
388
+ if strand == 1:
389
+ y_positive_strand += strand_offset
390
+ else:
391
+ y_negative_strand -= strand_offset
392
 
393
  # Update the layout of the plot
394
  fig.update_layout(
395
+ title='Top 10 gRNA Sequences by Prediction Score',
396
  xaxis_title='Genomic Position',
397
+ yaxis_title='Strand',
398
  yaxis=dict(
399
+ showgrid=True, # Show horizontal gridlines for clarity
400
+ zeroline=True, # Show a line at y=0
401
+ zerolinecolor='Black',
402
+ zerolinewidth=2,
403
+ ),
404
+ showlegend=False # Hide the legend if it's not necessary
405
  )
406
 
407
  # Display the plot
 
439
  st.download_button(label="Download CSV File", data=file, file_name=csv_file_path,
440
  mime="text/csv")
441
 
442
+
 
443
 
444
  elif selected_model == 'Cas13d':
445
  ENTRY_METHODS = dict(