Spaces:
Sleeping
Sleeping
Erva Ulusoy
commited on
Commit
·
905dc47
1
Parent(s):
51aa819
add errors for possible input exceptions
Browse files- Domain2GO.py +32 -13
Domain2GO.py
CHANGED
@@ -13,6 +13,8 @@ from run_domain2go_app import *
|
|
13 |
def convert_df(df):
|
14 |
return df.to_csv(index=False).encode('utf-8')
|
15 |
|
|
|
|
|
16 |
|
17 |
with st.sidebar:
|
18 |
st.title("Domain2GO: Mutual Annotation-Based Prediction of Protein Domain Functions")
|
@@ -28,12 +30,24 @@ with st.sidebar:
|
|
28 |
if input_type == 'Enter a sequence':
|
29 |
st.button('Use example sequence', on_click=click_button)
|
30 |
if st.session_state.example_seq_button:
|
31 |
-
|
32 |
value='>sp|O18783|PLMN_NOTEU\n'
|
33 |
'MEYGKVIFLFLLFLKSGQGESLENYIKTEGASLSNSQKKQFVASSTEECEALCEKETEFVCRSFEHYNKEQKCVIMSENSKTSSVERKRDVVLFEKRIYLSDCKSGNGRNYRGTLSKTKSGITCQKWSDLSPHVPNYAPSKYPDAGLEKNYCRNPDDDVKGPWCYTTNPDIRYEYCDVPECEDECMHCSGENYRGTISKTESGIECQPWDSQEPHSHEYIPSKFPSKDLKENYCRNPDGEPRPWCFTSNPEKRWEFCNIPRCSSPPPPPGPMLQCLKGRGENYRGKIAVTKSGHTCQRWNKQTPHKHNRTPENFPCRGLDENYCRNPDGELEPWCYTTNPDVRQEYCAIPSCGTSSPHTDRVEQSPVIQECYEGKGENYRGTTSTTISGKKCQAWSSMTPHQHKKTPDNFPNADLIRNYCRNPDGDKSPWCYTMDPTVRWEFCNLEKCSGTGSTVLNAQTTRVPSVDTTSHPESDCMYGSGKDYRGKRSTTVTGTLCQAWTAQEPHRHTIFTPDTYPRAGLEENYCRNPDGDPNGPWCYTTNPKKLFDYCDIPQCVSPSSFDCGKPRVEPQKCPGRIVGGCYAQPHSWPWQISLRTRFGEHFCGGTLIAPQWVLTAAHCLERSQWPGAYKVILGLHREVNPESYSQEIGVSRLFKGPLAADIALLKLNRPAAINDKVIPACLPSQDFMVPDRTLCHVTGWGDTQGTSPRGLLKQASLPVIDNRVCNRHEYLNGRVKSTELCAGHLVGRGDSCQGDSGGPLICFEDDKYVLQGVTSWGLGCARPNKPGVYVRVSRYISWIEDVMKNN')
|
34 |
else:
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
else:
|
38 |
protein_input = st.file_uploader('Choose a file', type=['.fasta', '.fas', '.fa', '.fna', '.ffn', '.faa', '.mpfa', '.frn', '.txt'])
|
39 |
css='''
|
@@ -52,26 +66,29 @@ with st.sidebar:
|
|
52 |
except UnicodeDecodeError:
|
53 |
protein_input_stringio = StringIO(bytes_data.decode("utf-16"))
|
54 |
|
55 |
-
fasta_sequences = SeqIO.parse(protein_input_stringio, 'fasta')
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
57 |
st.error('Please upload a file containing only one sequence.')
|
58 |
-
|
59 |
-
|
|
|
|
|
60 |
|
61 |
st.session_state['email'] = st.text_input('Enter your email for InterProScan query**')
|
62 |
|
63 |
-
# prevent user from clicking submit button if email or sequence is empty
|
64 |
-
submitted = False
|
65 |
-
|
66 |
-
|
67 |
with st.sidebar:
|
68 |
if st.button('Predict functions'):
|
69 |
-
if 'email' in st.session_state and 'sequence' in st.session_state and '@' in st.session_state.email:
|
70 |
submitted = True
|
71 |
st.session_state.disabled = True
|
72 |
else:
|
73 |
with st.sidebar:
|
74 |
-
st.warning('Please enter your email and protein sequence first. If you have already entered your email and protein sequence, please check that your email is valid.')
|
75 |
|
76 |
with st.sidebar:
|
77 |
c = st.container()
|
@@ -134,6 +151,8 @@ else:
|
|
134 |
pred_result_text = pred_results[0]
|
135 |
if pred_result_text == 'Function predictions found.':
|
136 |
st.success('Function predictions generated.')
|
|
|
|
|
137 |
st.session_state['pred_df'] = pred_results[1]
|
138 |
elif pred_result_text == 'No predictions made for domains found in sequence.':
|
139 |
st.warning(pred_result_text)
|
|
|
13 |
def convert_df(df):
|
14 |
return df.to_csv(index=False).encode('utf-8')
|
15 |
|
16 |
+
# prevent user from clicking submit button if email or sequence is empty
|
17 |
+
submitted = False
|
18 |
|
19 |
with st.sidebar:
|
20 |
st.title("Domain2GO: Mutual Annotation-Based Prediction of Protein Domain Functions")
|
|
|
30 |
if input_type == 'Enter a sequence':
|
31 |
st.button('Use example sequence', on_click=click_button)
|
32 |
if st.session_state.example_seq_button:
|
33 |
+
sequence_text_input = st.text_area('Enter a protein sequence in FASTA format*',
|
34 |
value='>sp|O18783|PLMN_NOTEU\n'
|
35 |
'MEYGKVIFLFLLFLKSGQGESLENYIKTEGASLSNSQKKQFVASSTEECEALCEKETEFVCRSFEHYNKEQKCVIMSENSKTSSVERKRDVVLFEKRIYLSDCKSGNGRNYRGTLSKTKSGITCQKWSDLSPHVPNYAPSKYPDAGLEKNYCRNPDDDVKGPWCYTTNPDIRYEYCDVPECEDECMHCSGENYRGTISKTESGIECQPWDSQEPHSHEYIPSKFPSKDLKENYCRNPDGEPRPWCFTSNPEKRWEFCNIPRCSSPPPPPGPMLQCLKGRGENYRGKIAVTKSGHTCQRWNKQTPHKHNRTPENFPCRGLDENYCRNPDGELEPWCYTTNPDVRQEYCAIPSCGTSSPHTDRVEQSPVIQECYEGKGENYRGTTSTTISGKKCQAWSSMTPHQHKKTPDNFPNADLIRNYCRNPDGDKSPWCYTMDPTVRWEFCNLEKCSGTGSTVLNAQTTRVPSVDTTSHPESDCMYGSGKDYRGKRSTTVTGTLCQAWTAQEPHRHTIFTPDTYPRAGLEENYCRNPDGDPNGPWCYTTNPKKLFDYCDIPQCVSPSSFDCGKPRVEPQKCPGRIVGGCYAQPHSWPWQISLRTRFGEHFCGGTLIAPQWVLTAAHCLERSQWPGAYKVILGLHREVNPESYSQEIGVSRLFKGPLAADIALLKLNRPAAINDKVIPACLPSQDFMVPDRTLCHVTGWGDTQGTSPRGLLKQASLPVIDNRVCNRHEYLNGRVKSTELCAGHLVGRGDSCQGDSGGPLICFEDDKYVLQGVTSWGLGCARPNKPGVYVRVSRYISWIEDVMKNN')
|
36 |
else:
|
37 |
+
sequence_text_input = st.text_area('Enter a protein sequence in FASTA format*')
|
38 |
+
|
39 |
+
fasta_sequences = list(SeqIO.parse(StringIO(sequence_text_input), 'fasta'))
|
40 |
+
|
41 |
+
if len(fasta_sequences) > 1:
|
42 |
+
st.error('Please enter only one sequence.')
|
43 |
+
fasta_sequences = None
|
44 |
+
elif sequence_text_input and len(fasta_sequences) == 0:
|
45 |
+
st.error('Please enter a sequence.')
|
46 |
+
fasta_sequences = None
|
47 |
+
elif len(fasta_sequences) == 1:
|
48 |
+
st.session_state['sequence'] = str(fasta_sequences[0].seq)
|
49 |
+
st.session_state['name'] = fasta_sequences[0].id
|
50 |
+
|
51 |
else:
|
52 |
protein_input = st.file_uploader('Choose a file', type=['.fasta', '.fas', '.fa', '.fna', '.ffn', '.faa', '.mpfa', '.frn', '.txt'])
|
53 |
css='''
|
|
|
66 |
except UnicodeDecodeError:
|
67 |
protein_input_stringio = StringIO(bytes_data.decode("utf-16"))
|
68 |
|
69 |
+
fasta_sequences = list(SeqIO.parse(protein_input_stringio, 'fasta'))
|
70 |
+
|
71 |
+
if len(fasta_sequences) == 0:
|
72 |
+
st.error('Please upload a file containing a sequence.')
|
73 |
+
fasta_sequences = None
|
74 |
+
|
75 |
+
elif len(fasta_sequences) > 1:
|
76 |
st.error('Please upload a file containing only one sequence.')
|
77 |
+
fasta_sequences = None
|
78 |
+
|
79 |
+
elif len(fasta_sequences) == 1:
|
80 |
+
st.session_state['name'], st.session_state['sequence'] = fasta_sequences[0].id, str(fasta_sequences[0].seq)
|
81 |
|
82 |
st.session_state['email'] = st.text_input('Enter your email for InterProScan query**')
|
83 |
|
|
|
|
|
|
|
|
|
84 |
with st.sidebar:
|
85 |
if st.button('Predict functions'):
|
86 |
+
if 'email' in st.session_state and 'sequence' in st.session_state and '@' in st.session_state.email and fasta_sequences:
|
87 |
submitted = True
|
88 |
st.session_state.disabled = True
|
89 |
else:
|
90 |
with st.sidebar:
|
91 |
+
st.warning('Please enter your email and protein sequence first. If you have already entered your email and protein sequence, please check that your email is valid, your sequence is in FASTA format, and that you have entered only one sequence.')
|
92 |
|
93 |
with st.sidebar:
|
94 |
c = st.container()
|
|
|
151 |
pred_result_text = pred_results[0]
|
152 |
if pred_result_text == 'Function predictions found.':
|
153 |
st.success('Function predictions generated.')
|
154 |
+
if more_than_one_seq_error:
|
155 |
+
st.warning(more_than_one_seq_error)
|
156 |
st.session_state['pred_df'] = pred_results[1]
|
157 |
elif pred_result_text == 'No predictions made for domains found in sequence.':
|
158 |
st.warning(pred_result_text)
|