supercat666 commited on
Commit
37deaa1
1 Parent(s): ffc2377
Files changed (1) hide show
  1. app.py +38 -19
app.py CHANGED
@@ -96,30 +96,47 @@ if selected_model == 'Cas9':
96
  ('on-target', 'off-target'),
97
  key='target_selection'
98
  )
 
 
99
 
100
- if target_selection == 'on-target':
101
- # Gene symbol entry
102
- gene_symbol = st.text_input('Enter a Gene Symbol:', placeholder="e.g., FOXA1", key='gene_symbol')
103
-
104
- if 'current_gene_symbol' not in st.session_state:
105
- st.session_state['current_gene_symbol'] = ""
106
- # Function to clean up old files
107
- def clean_up_old_files(gene_symbol):
108
- genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
109
- bed_file_path = f"{gene_symbol}_crispr_targets.bed"
110
- csv_file_path = f"{gene_symbol}_crispr_predictions.csv"
111
- for path in [genbank_file_path, bed_file_path, csv_file_path]:
112
- if os.path.exists(path):
113
- os.remove(path)
114
-
115
- if st.session_state['current_gene_symbol'] and gene_symbol != st.session_state['current_gene_symbol']:
116
  clean_up_old_files(st.session_state['current_gene_symbol'])
 
 
117
 
 
118
  # Prediction button
119
  predict_button = st.button('Predict on-target')
120
 
121
  # Process predictions
122
  if predict_button and gene_symbol:
 
 
 
 
 
 
 
 
 
 
 
 
123
  with st.spinner('Predicting... Please wait'):
124
  predictions, gene_sequence = cas9on.process_gene(gene_symbol, cas9on_path)
125
  sorted_predictions = sorted(predictions, key=lambda x: x[-1], reverse=True)[:10]
@@ -192,7 +209,10 @@ if selected_model == 'Cas9':
192
  # Display the plot
193
  st.plotly_chart(fig)
194
 
195
- if gene_sequence:
 
 
 
196
  # Define file paths
197
  genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
198
  bed_file_path = f"{gene_symbol}_crispr_targets.bed"
@@ -221,8 +241,7 @@ if selected_model == 'Cas9':
221
  # Links for user guidance on using the downloaded files
222
  st.markdown(
223
  "GenBank files can be visualized using [PyGenomeViz](https://pygenomeviz.streamlit.app/). "
224
- "BED files can be used with the [UCSC Genome Browser](https://genome.ucsc.edu/cgi-bin/hgCustom)."
225
- )
226
 
227
  # # Visualize the GenBank file using pyGenomeViz
228
  # gv = GenomeViz(
 
96
  ('on-target', 'off-target'),
97
  key='target_selection'
98
  )
99
+ if 'current_gene_symbol' not in st.session_state:
100
+ st.session_state['current_gene_symbol'] = ""
101
 
102
+ # Define a function to clean up old files
103
+ def clean_up_old_files(gene_symbol):
104
+ genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
105
+ bed_file_path = f"{gene_symbol}_crispr_targets.bed"
106
+ csv_file_path = f"{gene_symbol}_crispr_predictions.csv"
107
+ for path in [genbank_file_path, bed_file_path, csv_file_path]:
108
+ if os.path.exists(path):
109
+ os.remove(path)
110
+
111
+ # Gene symbol entry
112
+ gene_symbol = st.text_input('Enter a Gene Symbol:', placeholder="e.g., FOXA1", key='gene_symbol')
113
+
114
+ # Handle gene symbol change and file cleanup
115
+ if gene_symbol != st.session_state['current_gene_symbol'] and gene_symbol:
116
+ if st.session_state['current_gene_symbol']:
117
+ # Clean up files only if a different gene symbol is entered and a previous symbol exists
118
  clean_up_old_files(st.session_state['current_gene_symbol'])
119
+ # Update the session state with the new gene symbol
120
+ st.session_state['current_gene_symbol'] = gene_symbol
121
 
122
+ if target_selection == 'on-target':
123
  # Prediction button
124
  predict_button = st.button('Predict on-target')
125
 
126
  # Process predictions
127
  if predict_button and gene_symbol:
128
+ with st.spinner('Predicting... Please wait'):
129
+ predictions, gene_sequence = cas9on.process_gene(gene_symbol, cas9on_path)
130
+ sorted_predictions = sorted(predictions, key=lambda x: x[-1], reverse=True)[:10]
131
+ st.session_state['on_target_results'] = sorted_predictions
132
+ st.session_state['gene_sequence'] = gene_sequence # Save gene sequence in session state
133
+
134
+ # Notify the user once the process is completed successfully.
135
+ st.success('Prediction completed!')
136
+ st.session_state['prediction_made'] = True
137
+
138
+ # Process predictions
139
+ if 'prediction_made' in st.session_state and st.session_state['prediction_made']:
140
  with st.spinner('Predicting... Please wait'):
141
  predictions, gene_sequence = cas9on.process_gene(gene_symbol, cas9on_path)
142
  sorted_predictions = sorted(predictions, key=lambda x: x[-1], reverse=True)[:10]
 
209
  # Display the plot
210
  st.plotly_chart(fig)
211
 
212
+ if 'gene_sequence' in st.session_state and st.session_state['gene_sequence']:
213
+ gene_symbol = st.session_state['current_gene_symbol']
214
+ gene_sequence = st.session_state['gene_sequence']
215
+
216
  # Define file paths
217
  genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
218
  bed_file_path = f"{gene_symbol}_crispr_targets.bed"
 
241
  # Links for user guidance on using the downloaded files
242
  st.markdown(
243
  "GenBank files can be visualized using [PyGenomeViz](https://pygenomeviz.streamlit.app/). "
244
+ "BED files can be used with the [UCSC Genome Browser](https://genome.ucsc.edu/cgi-bin/hgCustom).")
 
245
 
246
  # # Visualize the GenBank file using pyGenomeViz
247
  # gv = GenomeViz(