astirn commited on
Commit
c73ab10
·
1 Parent(s): 2fc714c

input errors

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -37,7 +37,7 @@ def progress_update(update_text, percent_complete):
37
 
38
  def initiate_run():
39
  st.session_state.running = True
40
- st.session_state.on_target = st.session_state.off_target = None
41
 
42
 
43
  def run():
@@ -59,24 +59,20 @@ def run():
59
  f.write(st.session_state.fasta_entry.getvalue().decode('utf-8'))
60
  transcripts = tiger.load_transcripts([fasta_path], enforce_unique_ids=False)
61
 
62
- # make sure all transcripts have unique identifiers
63
- if transcripts.index.has_duplicates:
64
- with TRANSCRIPT_ENTRY:
65
- st.write("Duplicate transcript ID's detected in fasta file")
66
- return
67
-
68
  # convert to upper case as used by tokenizer
69
  transcripts[tiger.SEQ_COL] = transcripts[tiger.SEQ_COL].apply(lambda s: s.upper())
70
 
71
- # check that all transcripts only contain nucleotides A, C, G, T, and wildcard N
72
- if not all(transcripts[tiger.SEQ_COL].apply(lambda s: set(s).issubset(tiger.NUCLEOTIDE_TOKENS.keys()))):
73
- with TRANSCRIPT_ENTRY:
74
- st.write('Transcript(s) must only contain upper or lower case A, C, G, and Ts')
75
 
76
- # check that all transcripts satisfy length requirements
 
 
 
 
77
  elif any(transcripts[tiger.SEQ_COL].apply(lambda s: len(s) < tiger.TARGET_LEN)):
78
- with TRANSCRIPT_ENTRY:
79
- st.write('Transcript(s) must be at least {:d} bases.'.format(tiger.TARGET_LEN))
80
 
81
  # run model if we have any transcripts
82
  elif len(transcripts) > 0:
@@ -98,6 +94,8 @@ if __name__ == '__main__':
98
  st.session_state.entry_method = ENTRY_METHODS['manual']
99
  if 'running' not in st.session_state:
100
  st.session_state.running = False
 
 
101
  if 'on_target' not in st.session_state:
102
  st.session_state.on_target = None
103
  if 'off_target' not in st.session_state:
@@ -128,7 +126,7 @@ if __name__ == '__main__':
128
  # transcript entry
129
  with TRANSCRIPT_ENTRY:
130
  st.selectbox(
131
- label='How would you like to provide transcripts of interest?',
132
  options=ENTRY_METHODS.values(),
133
  key='entry_method',
134
  disabled=st.session_state.running
@@ -155,6 +153,10 @@ if __name__ == '__main__':
155
  # results
156
  with RESULTS:
157
 
 
 
 
 
158
  # on-target results
159
  if st.session_state.on_target is not None:
160
  st.write('On-target predictions:', st.session_state.on_target)
 
37
 
38
  def initiate_run():
39
  st.session_state.running = True
40
+ st.session_state.input_error = st.session_state.on_target = st.session_state.off_target = None
41
 
42
 
43
  def run():
 
59
  f.write(st.session_state.fasta_entry.getvalue().decode('utf-8'))
60
  transcripts = tiger.load_transcripts([fasta_path], enforce_unique_ids=False)
61
 
 
 
 
 
 
 
62
  # convert to upper case as used by tokenizer
63
  transcripts[tiger.SEQ_COL] = transcripts[tiger.SEQ_COL].apply(lambda s: s.upper())
64
 
65
+ # ensure all transcripts have unique identifiers
66
+ if transcripts.index.has_duplicates:
67
+ st.session_state.input_error = "Duplicate transcript ID's detected in fasta file"
 
68
 
69
+ # ensure all transcripts only contain nucleotides A, C, G, T, and wildcard N
70
+ elif not all(transcripts[tiger.SEQ_COL].apply(lambda s: set(s).issubset(tiger.NUCLEOTIDE_TOKENS.keys()))):
71
+ st.session_state.input_error = 'Transcript(s) must only contain upper or lower case A, C, G, and Ts'
72
+
73
+ # ensure all transcripts satisfy length requirements
74
  elif any(transcripts[tiger.SEQ_COL].apply(lambda s: len(s) < tiger.TARGET_LEN)):
75
+ st.session_state.input_error = 'Transcript(s) must be at least {:d} bases.'.format(tiger.TARGET_LEN)
 
76
 
77
  # run model if we have any transcripts
78
  elif len(transcripts) > 0:
 
94
  st.session_state.entry_method = ENTRY_METHODS['manual']
95
  if 'running' not in st.session_state:
96
  st.session_state.running = False
97
+ if 'input_error' not in st.session_state:
98
+ st.session_state.input_error = None
99
  if 'on_target' not in st.session_state:
100
  st.session_state.on_target = None
101
  if 'off_target' not in st.session_state:
 
126
  # transcript entry
127
  with TRANSCRIPT_ENTRY:
128
  st.selectbox(
129
+ label='How would you like to provide transcript(s) of interest?',
130
  options=ENTRY_METHODS.values(),
131
  key='entry_method',
132
  disabled=st.session_state.running
 
153
  # results
154
  with RESULTS:
155
 
156
+ # input error
157
+ if st.session_state.input_error is not None:
158
+ st.error(st.session_state.input_error, icon="🚨")
159
+
160
  # on-target results
161
  if st.session_state.on_target is not None:
162
  st.write('On-target predictions:', st.session_state.on_target)