supercat666 commited on
Commit
ba43ebe
1 Parent(s): 4a895c3

fixed bugs

Browse files
Files changed (2) hide show
  1. app.py +7 -7
  2. cas9on.py +12 -8
app.py CHANGED
@@ -125,8 +125,9 @@ if selected_model == 'Cas9':
125
  st.session_state['on_target_results'] = sorted_predictions
126
 
127
  if 'on_target_results' in st.session_state and st.session_state['on_target_results']:
 
128
  df = pd.DataFrame(st.session_state['on_target_results'],
129
- columns=["Gene ID", "Start Pos", "End Pos", "Strand", "gRNA", "Prediction"])
130
 
131
  # Now create a Plotly plot with the sorted_predictions
132
  fig = go.Figure()
@@ -134,8 +135,7 @@ if selected_model == 'Cas9':
134
  # Iterate over the sorted predictions to create the plot
135
  for i, prediction in enumerate(sorted_predictions, start=1):
136
  # Extract data for plotting
137
- chrom, start, end, strand, gRNA, pred_score = prediction
138
- # Strand is not used in this plot, but you could use it to determine marker symbol, for example
139
  fig.add_trace(go.Scatter(
140
  x=[start, end],
141
  y=[i, i], # Y-values are just the rank of the prediction
@@ -144,7 +144,7 @@ if selected_model == 'Cas9':
144
  text=[f"Rank: {i}", ""], # Text at the start position only
145
  hoverinfo='text',
146
  hovertext=[
147
- f"Rank: {i}<br>Target: {gRNA}<br>Cutsite: {start}<br>On Target Score: {pred_score}",
148
  ""
149
  ],
150
  ))
@@ -155,7 +155,7 @@ if selected_model == 'Cas9':
155
  xaxis_title='Genomic Position',
156
  yaxis_title='Rank',
157
  yaxis=dict(showticklabels=False)
158
- # We hide the y-axis labels since the rank is indicated in the hovertext
159
  )
160
 
161
  # Display the plot
@@ -364,10 +364,10 @@ elif selected_model == 'Cas12':
364
  bed_file_path = f"{gene_symbol}_crispr_targets.bed"
365
 
366
  # Generate GenBank file
367
- cas12.generate_genbank_file_from_df(df, gene_sequence, gene_symbol, genbank_file_path)
368
 
369
  # Generate BED file
370
- cas12.create_bed_file_from_df(df, bed_file_path)
371
 
372
  st.write('Top on-target predictions:')
373
  st.dataframe(df)
 
125
  st.session_state['on_target_results'] = sorted_predictions
126
 
127
  if 'on_target_results' in st.session_state and st.session_state['on_target_results']:
128
+ # Include "Target" in the DataFrame's columns
129
  df = pd.DataFrame(st.session_state['on_target_results'],
130
+ columns=["Gene ID", "Start Pos", "End Pos", "Strand", "Target", "gRNA", "Prediction"])
131
 
132
  # Now create a Plotly plot with the sorted_predictions
133
  fig = go.Figure()
 
135
  # Iterate over the sorted predictions to create the plot
136
  for i, prediction in enumerate(sorted_predictions, start=1):
137
  # Extract data for plotting
138
+ chrom, start, end, strand, target, gRNA, pred_score = prediction # Adjusted to include the target sequence
 
139
  fig.add_trace(go.Scatter(
140
  x=[start, end],
141
  y=[i, i], # Y-values are just the rank of the prediction
 
144
  text=[f"Rank: {i}", ""], # Text at the start position only
145
  hoverinfo='text',
146
  hovertext=[
147
+ 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}",
148
  ""
149
  ],
150
  ))
 
155
  xaxis_title='Genomic Position',
156
  yaxis_title='Rank',
157
  yaxis=dict(showticklabels=False)
158
+ # Hide the y-axis labels since the rank is indicated in the hovertext
159
  )
160
 
161
  # Display the plot
 
364
  bed_file_path = f"{gene_symbol}_crispr_targets.bed"
365
 
366
  # Generate GenBank file
367
+ cas12.generate_genbank_file_from_data(df, gene_sequence, gene_symbol, genbank_file_path)
368
 
369
  # Generate BED file
370
+ cas12.generate_bed_file_from_data(df, bed_file_path)
371
 
372
  st.write('Top on-target predictions:')
373
  st.dataframe(df)
cas9on.py CHANGED
@@ -98,7 +98,8 @@ def find_crispr_targets(sequence, chr, start, strand, pam="NGG", target_length=2
98
  target_seq = sequence[i - target_length:i + 3]
99
  tar_start = start + i - target_length
100
  tar_end = start + i + 3
101
- targets.append([target_seq, chr, tar_start, tar_end, strand])
 
102
 
103
  return targets
104
 
@@ -125,13 +126,16 @@ def process_gene(gene_symbol, model_path):
125
  # Return both the data and the fetched sequence
126
  return all_data, gene_sequence
127
 
128
- def create_genbank_features(gRNAs, predictions):
129
  features = []
130
- for gRNA, prediction in zip(gRNAs, predictions):
131
- location = FeatureLocation(start=gRNA[2], end=gRNA[3], strand=gRNA[4])
 
 
132
  feature = SeqFeature(location=location, type="misc_feature", qualifiers={
133
- 'label': gRNA[0], # Target sequence as label
134
- 'note': f"Prediction: {prediction}" # Prediction score in note
 
135
  })
136
  features.append(feature)
137
  return features
@@ -162,7 +166,7 @@ def create_bed_file_from_df(df, output_path):
162
  chrom = row["Gene ID"]
163
  start = int(row["Start Pos"])
164
  end = int(row["End Pos"])
165
- strand = '+' if int(row["Strand"]) > 0 else '-'
166
  gRNA = row["gRNA"]
167
- score = row["Prediction"]
168
  bed_file.write(f"{chrom}\t{start}\t{end}\t{gRNA}\t{score}\t{strand}\n")
 
98
  target_seq = sequence[i - target_length:i + 3]
99
  tar_start = start + i - target_length
100
  tar_end = start + i + 3
101
+ gRNA = sequence[i - target_length:i]
102
+ targets.append([target_seq, gRNA, chr, str(tar_start), str(tar_end), str(strand)])
103
 
104
  return targets
105
 
 
126
  # Return both the data and the fetched sequence
127
  return all_data, gene_sequence
128
 
129
+ def create_genbank_features(formatted_data):
130
  features = []
131
+ for data in formatted_data:
132
+ # Strand conversion to Biopython's convention
133
+ strand = 1 if data[3] == '+' else -1
134
+ location = FeatureLocation(start=int(data[1]), end=int(data[2]), strand=strand)
135
  feature = SeqFeature(location=location, type="misc_feature", qualifiers={
136
+ 'label': data[5], # Use gRNA as the label
137
+ 'target': data[4], # Include the target sequence
138
+ 'note': f"Prediction: {data[6]}" # Include the prediction score
139
  })
140
  features.append(feature)
141
  return features
 
166
  chrom = row["Gene ID"]
167
  start = int(row["Start Pos"])
168
  end = int(row["End Pos"])
169
+ strand = '+' if row["Strand"] == '+' else '-'
170
  gRNA = row["gRNA"]
171
+ score = str(row["Prediction"]) # Ensure score is converted to string if not already
172
  bed_file.write(f"{chrom}\t{start}\t{end}\t{gRNA}\t{score}\t{strand}\n")