ericckim03 commited on
Commit
d3204b1
·
1 Parent(s): 89ee386

Handle fasta file input seperately

Browse files
Files changed (1) hide show
  1. app.py +57 -15
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import pandas as pd
2
  import streamlit as st
3
- from tiger import tiger_exhibit, TARGET_LEN, NUCLEOTIDE_TOKENS
 
4
 
5
 
6
  @st.cache
@@ -8,25 +9,66 @@ def convert_df(df):
8
  # IMPORTANT: Cache the conversion to prevent computation on every rerun
9
  return df.to_csv().encode('utf-8')
10
 
11
-
12
  # title and instructions
13
  st.title('TIGER Cas13 Efficacy Prediction')
14
- st.session_state['userInput'] = ''
15
- st.session_state['userInput'] = st.text_input(
 
 
 
 
 
16
  label='Enter a target transcript:',
17
- # value='ATGCAGGACGCGGAGAACGTGGCGGTGCCCGAGGCGGCCGAGGAGCGCGC',
18
  placeholder='Upper or lower case')
 
 
 
 
 
 
 
 
19
  #status bar
20
- status_text = st.empty()
21
- status_bar = st.progress(0)
22
- # input is too short
23
- if len(st.session_state['userInput']) < TARGET_LEN:
24
- transcript_len = len(st.session_state['userInput'])
25
- st.write('Transcript length ({:d}) must be at least {:d} bases.'.format(transcript_len, TARGET_LEN))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  # valid input
28
- elif all([True if nt.upper() in NUCLEOTIDE_TOKENS.keys() else False for nt in st.session_state['userInput']]):
29
- on_target, off_target = tiger_exhibit(pd.DataFrame(dict(id=['ManualEntry'], seq=[st.session_state['userInput']])),
30
  status_bar, status_text)
31
  st.write('On-target predictions: ', on_target)
32
  st.download_button(label='Download', data=convert_df(on_target), file_name='on_target.csv', mime='text/csv')
@@ -37,5 +79,5 @@ elif all([True if nt.upper() in NUCLEOTIDE_TOKENS.keys() else False for nt in st
37
  st.write('We did not find any off-target effects!')
38
 
39
  # invalid input
40
- else:
41
- st.write('Nucleotides other than ACGT detected!')
 
1
  import pandas as pd
2
  import streamlit as st
3
+ import os
4
+ from tiger import tiger_exhibit, load_transcripts, TARGET_LEN, NUCLEOTIDE_TOKENS
5
 
6
 
7
  @st.cache
 
9
  # IMPORTANT: Cache the conversion to prevent computation on every rerun
10
  return df.to_csv().encode('utf-8')
11
 
 
12
  # title and instructions
13
  st.title('TIGER Cas13 Efficacy Prediction')
14
+ st.session_state["fasta_seq"] = ""
15
+ st.session_state["text_seq"] = ""
16
+ status_bar, status_text = None, None
17
+
18
+ # UserInput Form from text input
19
+ text_form = st.form("text")
20
+ text_input = text_form.text_input(
21
  label='Enter a target transcript:',
22
+ #value='ATGCAGGACGCGGAGAACGTGGCGGTGCCCGAGGCGGCCGAGGAGCGCGC',
23
  placeholder='Upper or lower case')
24
+ if text_input:
25
+ # input is too short
26
+ if len(text_input) < TARGET_LEN:
27
+ transcript_len = len(text_input)
28
+ text_form.write('Transcript length ({:d}) must be at least {:d} bases.'.format(transcript_len, TARGET_LEN))
29
+ else:
30
+ st.session_state["text_seq"] = text_input
31
+ text_calc = text_form.form_submit_button(label="calculate")
32
  #status bar
33
+ status_text_textform = text_form.empty()
34
+ status_bar_textform = text_form.progress(0)
35
+
36
+
37
+ # UserInput Form from file
38
+ fasta_form = st.form("fasta")
39
+ fasta = fasta_form.file_uploader(label="upload fasta file")
40
+ if fasta:
41
+ fname = fasta.name
42
+ st.write(fname)
43
+ with open(fname,"w") as f:
44
+ f.write(fasta.getvalue().decode("utf-8"))
45
+ transcript_tbl = load_transcripts([fname])
46
+ fasta_form.text("fasta file contents")
47
+ fasta_form.write(transcript_tbl)
48
+ seq = transcript_tbl['seq'][0]
49
+ st.session_state["fasta_seq"] = seq
50
+ fasta_calc = fasta_form.form_submit_button(label="calculate")
51
+ status_text_fastaform = fasta_form.empty()
52
+ status_bar_fastaform = fasta_form.progress(0)
53
+ #st.write(text_calc)
54
+ #st.write(fasta_calc)
55
+
56
+ #Calculation
57
+ if text_calc:
58
+ src_seq = st.session_state["text_seq"]
59
+ status_text = status_text_textform
60
+ status_bar= status_bar_textform
61
+ elif fasta_calc:
62
+ src_seq = st.session_state["fasta_seq"]
63
+ status_text = status_text_fastaform
64
+ status_bar= status_bar_fastaform
65
+ else:
66
+ src_seq = ""
67
+ #st.write(src_seq)
68
 
69
  # valid input
70
+ if src_seq and all([True if nt.upper() in NUCLEOTIDE_TOKENS.keys() else False for nt in src_seq]):
71
+ on_target, off_target = tiger_exhibit(pd.DataFrame(dict(id=['ManualEntry'], seq=[src_seq])),
72
  status_bar, status_text)
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')
 
79
  st.write('We did not find any off-target effects!')
80
 
81
  # invalid input
82
+ #else:
83
+ # st.write('Nucleotides other than ACGT detected!')