Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
cleanup
Browse files
app.py
CHANGED
|
@@ -9,89 +9,76 @@ def convert_df(df):
|
|
| 9 |
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
| 10 |
return df.to_csv().encode('utf-8')
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
st.title('TIGER Cas13 Efficacy Prediction')
|
| 14 |
-
st.session_state[
|
| 15 |
-
st.session_state[
|
| 16 |
-
status_bar, status_text = None, None
|
| 17 |
|
|
|
|
| 18 |
with st.form(key='calc_options'):
|
| 19 |
-
c1_names = ['On
|
| 20 |
-
option = st.radio('
|
| 21 |
-
submitButton = st.form_submit_button(label='Choose
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
label='Enter a target transcript:',
|
| 27 |
#value='ATGCAGGACGCGGAGAACGTGGCGGTGCCCGAGGCGGCCGAGGAGCGCGC',
|
| 28 |
placeholder='Upper or lower case')
|
| 29 |
-
if
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
transcript_len = len(text_input)
|
| 33 |
-
text_form.write('Transcript length ({:d}) must be at least {:d} bases.'.format(transcript_len, TARGET_LEN))
|
| 34 |
else:
|
| 35 |
-
st.session_state[
|
| 36 |
-
text_calc = text_form.form_submit_button(label="calculate")
|
| 37 |
-
#status bar
|
| 38 |
-
status_text_textform = text_form.empty()
|
| 39 |
-
status_bar_textform = text_form.progress(0)
|
| 40 |
-
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
fasta_form = st.form(
|
| 44 |
-
|
| 45 |
-
if
|
| 46 |
-
if os.path.exists(
|
| 47 |
-
shutil.rmtree(
|
| 48 |
-
os.makedirs(
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
f.write(fasta.getvalue().decode("utf-8"))
|
| 54 |
transcript_tbl = load_transcripts([fpath])
|
| 55 |
-
fasta_form.text(
|
| 56 |
fasta_form.write(transcript_tbl)
|
| 57 |
seq = transcript_tbl['seq'][0]
|
| 58 |
-
st.session_state[
|
| 59 |
-
fasta_calc = fasta_form.form_submit_button(label="calculate")
|
| 60 |
-
status_text_fastaform = fasta_form.empty()
|
| 61 |
-
status_bar_fastaform = fasta_form.progress(0)
|
| 62 |
-
#st.write(text_calc)
|
| 63 |
-
#st.write(fasta_calc)
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
if
|
| 67 |
-
src_seq = st.session_state[
|
| 68 |
-
status_text =
|
| 69 |
-
status_bar=
|
| 70 |
-
elif
|
| 71 |
-
src_seq = st.session_state[
|
| 72 |
-
status_text =
|
| 73 |
-
status_bar=
|
| 74 |
else:
|
| 75 |
-
src_seq =
|
| 76 |
-
#st.write(src_seq)
|
| 77 |
|
| 78 |
# valid input
|
| 79 |
if src_seq and all([True if nt.upper() in NUCLEOTIDE_TOKENS.keys() else False for nt in src_seq]):
|
| 80 |
on_target, off_target = tiger_exhibit(pd.DataFrame(dict(id=['ManualEntry'], seq=[src_seq])),
|
| 81 |
-
|
| 82 |
-
on_target.rename(columns={
|
| 83 |
-
if len(on_target)>0:
|
| 84 |
-
if on_target.iloc[0][
|
| 85 |
-
on_target.drop([
|
| 86 |
st.write('On-target predictions: ', on_target)
|
| 87 |
st.download_button(label='Download', data=convert_df(on_target), file_name='on_target.csv', mime='text/csv')
|
| 88 |
-
if len(off_target) > 0:
|
| 89 |
-
off_target.rename(columns={
|
| 90 |
st.write('Off-target predictions: ', off_target)
|
| 91 |
st.download_button(label='Download', data=convert_df(off_target), file_name='off_target.csv', mime='text/csv')
|
| 92 |
-
|
| 93 |
st.write('We did not find any off-target effects!')
|
| 94 |
|
| 95 |
# invalid input
|
| 96 |
-
|
| 97 |
-
|
|
|
|
| 9 |
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
| 10 |
return df.to_csv().encode('utf-8')
|
| 11 |
|
| 12 |
+
|
| 13 |
+
# title and initialization
|
| 14 |
st.title('TIGER Cas13 Efficacy Prediction')
|
| 15 |
+
st.session_state['manual_seq'] = ''
|
| 16 |
+
st.session_state['fasta_seq'] = ''
|
|
|
|
| 17 |
|
| 18 |
+
# run mode selection
|
| 19 |
with st.form(key='calc_options'):
|
| 20 |
+
c1_names = ['On-target', 'On- and off-target']
|
| 21 |
+
option = st.radio('Select mode:', c1_names, index=0)
|
| 22 |
+
submitButton = st.form_submit_button(label='Choose options')
|
| 23 |
|
| 24 |
+
# text input
|
| 25 |
+
manual_entry = st.form('text')
|
| 26 |
+
manual_input = manual_entry.manual_input(
|
| 27 |
label='Enter a target transcript:',
|
| 28 |
#value='ATGCAGGACGCGGAGAACGTGGCGGTGCCCGAGGCGGCCGAGGAGCGCGC',
|
| 29 |
placeholder='Upper or lower case')
|
| 30 |
+
if manual_input:
|
| 31 |
+
if len(manual_input) < TARGET_LEN:
|
| 32 |
+
manual_entry.write('Transcript must be at least {:d} bases.'.format(TARGET_LEN))
|
|
|
|
|
|
|
| 33 |
else:
|
| 34 |
+
st.session_state['manual_seq'] = manual_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# fasta input
|
| 37 |
+
fasta_form = st.form('fasta')
|
| 38 |
+
fasta_input = fasta_form.file_uploader(label='Upload a fasta file:')
|
| 39 |
+
if fasta_input:
|
| 40 |
+
if os.path.exists('temp'):
|
| 41 |
+
shutil.rmtree('temp')
|
| 42 |
+
os.makedirs('temp')
|
| 43 |
+
st.write(fasta_input.name)
|
| 44 |
+
fpath = os.path.join('temp', fasta_input.name)
|
| 45 |
+
with open(fpath, 'w') as f:
|
| 46 |
+
f.write(fasta_input.getvalue().decode('utf-8'))
|
|
|
|
| 47 |
transcript_tbl = load_transcripts([fpath])
|
| 48 |
+
fasta_form.text('fasta file contents')
|
| 49 |
fasta_form.write(transcript_tbl)
|
| 50 |
seq = transcript_tbl['seq'][0]
|
| 51 |
+
st.session_state['fasta_seq'] = seq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# input-specific configuration
|
| 54 |
+
if manual_entry.form_submit_button(label='Calculate'):
|
| 55 |
+
src_seq = st.session_state['manual_seq']
|
| 56 |
+
status_text = manual_entry.empty()
|
| 57 |
+
status_bar = manual_entry.progress(0)
|
| 58 |
+
elif fasta_form.form_submit_button(label='Calculate'):
|
| 59 |
+
src_seq = st.session_state['fasta_seq']
|
| 60 |
+
status_text = fasta_form.empty()
|
| 61 |
+
status_bar = fasta_form.progress(0)
|
| 62 |
else:
|
| 63 |
+
src_seq = status_bar = status_text = None
|
|
|
|
| 64 |
|
| 65 |
# valid input
|
| 66 |
if src_seq and all([True if nt.upper() in NUCLEOTIDE_TOKENS.keys() else False for nt in src_seq]):
|
| 67 |
on_target, off_target = tiger_exhibit(pd.DataFrame(dict(id=['ManualEntry'], seq=[src_seq])),
|
| 68 |
+
status_bar, status_text, check_off_targets=option == 'On and Off Target')
|
| 69 |
+
on_target.rename(columns={'Guide': '23 nt guide sequence'}, inplace=True)
|
| 70 |
+
if len(on_target) > 0:
|
| 71 |
+
if on_target.iloc[0]['On-target ID'] == 0:
|
| 72 |
+
on_target.drop(['On-target ID'], axis=1, inplace=True)
|
| 73 |
st.write('On-target predictions: ', on_target)
|
| 74 |
st.download_button(label='Download', data=convert_df(on_target), file_name='on_target.csv', mime='text/csv')
|
| 75 |
+
if option == 'On and Off Target' and len(off_target) > 0:
|
| 76 |
+
off_target.rename(columns={'Guide': '23 nt guide sequence'}, inplace=True)
|
| 77 |
st.write('Off-target predictions: ', off_target)
|
| 78 |
st.download_button(label='Download', data=convert_df(off_target), file_name='off_target.csv', mime='text/csv')
|
| 79 |
+
elif option == 'On and Off Target' and len(off_target) == 0:
|
| 80 |
st.write('We did not find any off-target effects!')
|
| 81 |
|
| 82 |
# invalid input
|
| 83 |
+
else:
|
| 84 |
+
st.write('Invalid input!')
|