File size: 2,890 Bytes
89ffb34
89be9f9
d3204b1
 
89be9f9
 
f606ed7
 
 
 
 
cf3bd3a
 
d3204b1
 
 
 
 
 
 
592b51c
d3204b1
592b51c
d3204b1
 
 
 
 
 
 
 
89ee386
d3204b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78951dd
 
d3204b1
 
89ee386
d41b7db
 
350befe
 
 
 
 
78951dd
 
d3204b1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pandas as pd
import streamlit as st
import os
from tiger import tiger_exhibit, load_transcripts, TARGET_LEN, NUCLEOTIDE_TOKENS


@st.cache
def convert_df(df):
    # IMPORTANT: Cache the conversion to prevent computation on every rerun
    return df.to_csv().encode('utf-8')

# title and instructions
st.title('TIGER Cas13 Efficacy Prediction')
st.session_state["fasta_seq"] = ""
st.session_state["text_seq"] = ""
status_bar, status_text = None, None

# UserInput Form from text input
text_form = st.form("text")
text_input = text_form.text_input(
    label='Enter a target transcript:',
    #value='ATGCAGGACGCGGAGAACGTGGCGGTGCCCGAGGCGGCCGAGGAGCGCGC',
    placeholder='Upper or lower case')
if text_input:
    # input is too short
    if len(text_input) < TARGET_LEN:
        transcript_len = len(text_input)
        text_form.write('Transcript length ({:d}) must be at least {:d} bases.'.format(transcript_len, TARGET_LEN))
    else:
        st.session_state["text_seq"] = text_input
text_calc = text_form.form_submit_button(label="calculate")
#status bar
status_text_textform = text_form.empty()
status_bar_textform = text_form.progress(0)


# UserInput Form from file
fasta_form = st.form("fasta")
fasta = fasta_form.file_uploader(label="upload fasta file") 
if fasta:
    fname = fasta.name 
    st.write(fname)
    with open(fname,"w") as f:
        f.write(fasta.getvalue().decode("utf-8"))
    transcript_tbl = load_transcripts([fname])
    fasta_form.text("fasta file contents")
    fasta_form.write(transcript_tbl)
    seq = transcript_tbl['seq'][0]
    st.session_state["fasta_seq"] = seq
fasta_calc = fasta_form.form_submit_button(label="calculate")
status_text_fastaform = fasta_form.empty()
status_bar_fastaform = fasta_form.progress(0)
#st.write(text_calc)
#st.write(fasta_calc)

#Calculation
if text_calc:
    src_seq = st.session_state["text_seq"]
    status_text = status_text_textform
    status_bar= status_bar_textform
elif fasta_calc:
    src_seq = st.session_state["fasta_seq"]
    status_text = status_text_fastaform
    status_bar= status_bar_fastaform
else:
    src_seq = ""
#st.write(src_seq)

# valid input
if src_seq and all([True if nt.upper() in NUCLEOTIDE_TOKENS.keys() else False for nt in src_seq]):
    on_target, off_target = tiger_exhibit(pd.DataFrame(dict(id=['ManualEntry'], seq=[src_seq])),
            status_bar, status_text)
    st.write('On-target predictions: ', on_target)
    st.download_button(label='Download', data=convert_df(on_target), file_name='on_target.csv', mime='text/csv')
    if len(off_target) > 0:
        st.write('Off-target predictions: ', off_target)
        st.download_button(label='Download', data=convert_df(off_target), file_name='off_target.csv', mime='text/csv')
    else:
        st.write('We did not find any off-target effects!')

# invalid input
#else:
#    st.write('Nucleotides other than ACGT detected!')