Spaces:
Sleeping
Sleeping
Commit
•
cf2d407
1
Parent(s):
dd4858e
fix genbank
Browse files
app.py
CHANGED
@@ -96,50 +96,33 @@ if selected_model == 'Cas9':
|
|
96 |
if target_selection == 'on-target':
|
97 |
# Gene symbol entry
|
98 |
gene_symbol = st.text_input('Enter a Gene Symbol:', key='gene_symbol')
|
99 |
-
|
100 |
# Prediction button
|
101 |
predict_button = st.button('Predict on-target')
|
102 |
-
|
103 |
# Process predictions
|
104 |
if predict_button and gene_symbol:
|
105 |
predictions, gene_sequence = cas9on.process_gene(gene_symbol, cas9on_path)
|
106 |
sorted_predictions = sorted(predictions, key=lambda x: x[-1], reverse=True)[:10]
|
107 |
st.session_state['on_target_results'] = sorted_predictions
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
# Pass the gene_sequence to the function
|
114 |
-
genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
|
115 |
-
cas9on.generate_genbank_file_from_df(df, gene_sequence, gene_symbol, genbank_file_path)
|
116 |
-
st.write('Top on-target predictions:')
|
117 |
-
st.dataframe(df)
|
118 |
-
|
119 |
-
# Initialize GenomeViz
|
120 |
-
gv = GenomeViz()
|
121 |
-
genome_size = max(
|
122 |
-
df["End Pos"]) # Assuming the max end position approximates the genome size for visualization purposes
|
123 |
-
track = gv.add_feature_track("CRISPR Targets", genome_size)
|
124 |
-
|
125 |
-
for _, row in df.iterrows():
|
126 |
-
start, end, strand = row["Start Pos"], row["End Pos"], row["Strand"]
|
127 |
-
label = row["gRNA"]
|
128 |
-
track.add_feature(start, end, strand, label=label)
|
129 |
-
|
130 |
-
# Save and display the visualization
|
131 |
-
fig = gv.plotfig()
|
132 |
-
st.pyplot(fig)
|
133 |
-
|
134 |
-
# After the GenomeViz plot, include the download button
|
135 |
-
with open(genbank_file_path, "rb") as file:
|
136 |
-
btn = st.download_button(
|
137 |
-
label="Download GenBank file",
|
138 |
-
data=file,
|
139 |
-
file_name=genbank_file_path,
|
140 |
-
mime="application/octet-stream"
|
141 |
-
)
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
os.remove(genbank_file_path)
|
144 |
|
145 |
elif target_selection == 'off-target':
|
|
|
96 |
if target_selection == 'on-target':
|
97 |
# Gene symbol entry
|
98 |
gene_symbol = st.text_input('Enter a Gene Symbol:', key='gene_symbol')
|
|
|
99 |
# Prediction button
|
100 |
predict_button = st.button('Predict on-target')
|
|
|
101 |
# Process predictions
|
102 |
if predict_button and gene_symbol:
|
103 |
predictions, gene_sequence = cas9on.process_gene(gene_symbol, cas9on_path)
|
104 |
sorted_predictions = sorted(predictions, key=lambda x: x[-1], reverse=True)[:10]
|
105 |
st.session_state['on_target_results'] = sorted_predictions
|
106 |
|
107 |
+
if 'on_target_results' in st.session_state and st.session_state['on_target_results']:
|
108 |
+
df = pd.DataFrame(st.session_state['on_target_results'],
|
109 |
+
columns=["Gene ID", "Start Pos", "End Pos", "Strand", "gRNA", "Prediction"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
+
# Make sure gene_sequence is defined before this point
|
112 |
+
if gene_sequence: # Add a check to ensure gene_sequence is not empty
|
113 |
+
genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
|
114 |
+
cas9on.generate_genbank_file_from_df(df, gene_sequence, gene_symbol, genbank_file_path)
|
115 |
+
st.write('Top on-target predictions:')
|
116 |
+
st.dataframe(df)
|
117 |
+
|
118 |
+
# Add a download button for the GenBank file
|
119 |
+
with open(genbank_file_path, "rb") as file:
|
120 |
+
st.download_button(
|
121 |
+
label="Download GenBank File",
|
122 |
+
data=file,
|
123 |
+
file_name=genbank_file_path,
|
124 |
+
mime="text/x-genbank"
|
125 |
+
)
|
126 |
os.remove(genbank_file_path)
|
127 |
|
128 |
elif target_selection == 'off-target':
|