Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix server issues #61

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clock.time
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Last updated at 09:04 on 2024-05-02
Last updated at 14:21 on 2023-11-06
147 changes: 83 additions & 64 deletions navigation/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import requests

import altair as alt
import pandas as pd
Expand Down Expand Up @@ -210,33 +211,42 @@ def aio_page():

# Run Promoter Finder
if st.button(f"🧬 :blue[**Step 1.5**] Extract {prom_term}", help='(~5sec/gene)'):
with st.spinner('Please wait...'):
with colprom1:
response = requests.get(
'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&term=nos2[Gene%20Name]+AND+human[Organism]&retmode=json&rettype=xml')

pbar = st.progress(0,
text='**:blue[Extract sequence...] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
for i, gene_id in enumerate(gene_ids):
pbar.progress(i / len(gene_ids),
text=f'**:blue[Extract sequence... {gene_id}] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
result_promoter_output = NCBIdna(gene_id, prom_term, upstream, downstream,
species,
all_slice_forms=True if all_variants else False).find_sequences()
if not str(result_promoter_output).startswith('P'):
pbar.progress((i + 1) / len(gene_ids),
ncbi_status = True if response.status_code == 200 else False

if ncbi_status is True:
with st.spinner('Please wait...'):
with colprom1:

pbar = st.progress(0,
text='**:blue[Extract sequence...] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
for i, gene_id in enumerate(gene_ids):
pbar.progress(i / len(gene_ids),
text=f'**:blue[Extract sequence... {gene_id}] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
st.toast(f"{prom_term} **{gene_id}** from **{species}** extracted", icon='🧬')
result_promoter_output = NCBIdna(gene_id, prom_term, upstream, downstream,
species,
all_slice_forms=True if all_variants else False).find_sequences()
if not str(result_promoter_output).startswith('P'):
pbar.progress((i + 1) / len(gene_ids),
text=f'**:blue[Extract sequence... {gene_id}] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
st.toast(f"{prom_term} **{gene_id}** from **{species}** extracted", icon='🧬')

result_promoter.append(result_promoter_output)
else:
st.error(result_promoter_output)
continue
result_promoter.append(result_promoter_output)
else:
st.error(result_promoter_output)
continue

result_promoter_text = "\n".join(result_promoter)
result_promoter_text = "\n".join(result_promoter)

st.session_state['result_promoter_text'] = result_promoter_text
st.session_state['result_promoter_text'] = result_promoter_text

st.success(f"{prom_term} extraction complete !")
st.toast(f"{prom_term} extraction complete !", icon='😊')
st.success(f"{prom_term} extraction complete !")
st.toast(f"{prom_term} extraction complete !", icon='😊')

elif ncbi_status is False:
st.warning("⚠ NCBI servers are under maintenance or have an error")

with tab2:
# Advance mode extraction
Expand Down Expand Up @@ -346,65 +356,74 @@ def aio_page():
downstream_entry = max(updown_slide)

if st.button("🧬 :blue[**Step 1.4**] Extract sequences", help="(~5sec/seq)", key='Advance'):
with colprom1:
st.session_state['upstream'] = upstream_entry
upstream = int(upstream_entry)
downstream = int(downstream_entry)
pbar = st.progress(0,
text='**:blue[Extract sequence...] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
for i, gene_info in enumerate(data_dff.itertuples(index=False)):
gene_id = gene_info.Gene
if gene_id.isdigit() or gene_id.startswith('XM_') or gene_id.startswith(
'NM_') or gene_id.startswith('XR_') or gene_id.startswith('NR_'):
for search_type in search_types:
if getattr(gene_info, f'{search_type}'):
prom_term = search_type.capitalize()

pbar.progress((i + 1) / len(data_dff),
text=f'**:blue[Extract sequence... {prom_term} **{gene_id}** from **{species}**] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')

result_promoter_output = NCBIdna(gene_id, prom_term, upstream,
downstream).find_sequences()

if not result_promoter_output.startswith('P'):
st.toast(f'{prom_term} **{gene_id}** from **{species}** extracted',
icon='🧬')
result_promoter.append(result_promoter_output)
pass

else:
st.error(result_promoter_output)
continue
response = requests.get(
'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&term=nos2[Gene%20Name]+AND+human[Organism]&retmode=json&rettype=xml')

else:
for species in species_list:
ncbi_status = True if response.status_code == 200 else False

if ncbi_status is True:
with colprom1:
st.session_state['upstream'] = upstream_entry
upstream = int(upstream_entry)
downstream = int(downstream_entry)
pbar = st.progress(0,
text='**:blue[Extract sequence...] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
for i, gene_info in enumerate(data_dff.itertuples(index=False)):
gene_id = gene_info.Gene
if gene_id.isdigit() or gene_id.startswith('XM_') or gene_id.startswith(
'NM_') or gene_id.startswith('XR_') or gene_id.startswith('NR_'):
for search_type in search_types:
if getattr(gene_info, f'{species}') and getattr(gene_info,
f'{search_type}'):
if getattr(gene_info, f'{search_type}'):
prom_term = search_type.capitalize()

pbar.progress((i + 1) / len(data_dff),
text=f'**:blue[Extract sequence... {prom_term} **{gene_id}** from **{species.capitalize()}**] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')
text=f'**:blue[Extract sequence... {prom_term} **{gene_id}** from **{species}**] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')

result_promoter_output = NCBIdna(gene_id, prom_term, upstream,
downstream,
species).find_sequences()
downstream).find_sequences()

if not result_promoter_output.startswith('P'):
st.toast(
f'{prom_term} **{gene_id}** from **{species.capitalize()}** extracted',
icon='🧬')
st.toast(f'{prom_term} **{gene_id}** from **{species}** extracted',
icon='🧬')
result_promoter.append(result_promoter_output)
pass

else:
st.error(result_promoter_output)
continue

result_promoter_text = "\n".join(result_promoter)
st.session_state['result_promoter_text'] = result_promoter_text
st.success(f"{prom_term} extraction complete !")
st.toast(f"{prom_term} extraction complete !", icon='😊')
else:
for species in species_list:
for search_type in search_types:
if getattr(gene_info, f'{species}') and getattr(gene_info,
f'{search_type}'):
prom_term = search_type.capitalize()

pbar.progress((i + 1) / len(data_dff),
text=f'**:blue[Extract sequence... {prom_term} **{gene_id}** from **{species.capitalize()}**] ⚠️:red[PLEASE WAIT UNTIL END WITHOUT CHANGING ANYTHING]**')

result_promoter_output = NCBIdna(gene_id, prom_term, upstream,
downstream,
species).find_sequences()

if not result_promoter_output.startswith('P'):
st.toast(
f'{prom_term} **{gene_id}** from **{species.capitalize()}** extracted',
icon='🧬')
result_promoter.append(result_promoter_output)
pass

else:
st.error(result_promoter_output)
continue

result_promoter_text = "\n".join(result_promoter)
st.session_state['result_promoter_text'] = result_promoter_text
st.success(f"{prom_term} extraction complete !")
st.toast(f"{prom_term} extraction complete !", icon='😊')

elif ncbi_status is False:
st.warning("⚠ NCBI servers are under maintenance or have an error")

# Promoter output state
st.divider()
Expand Down