Skip to content

Commit

Permalink
PoC for library filter advanced options
Browse files Browse the repository at this point in the history
  • Loading branch information
jfy133 committed Jul 10, 2023
1 parent 3eb8d58 commit f0088d8
Showing 1 changed file with 97 additions and 28 deletions.
125 changes: 97 additions & 28 deletions AMDirT/viewer/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import zipfile
import json
import os
import urllib.request ## TODO REMOVE: JUST FOR DEMO!
from AMDirT import __version__
from AMDirT.core import (
prepare_bibtex_file,
Expand All @@ -17,11 +18,10 @@
prepare_taxprofiler_table,
is_merge_size_zero,
get_amdir_tags,
get_libraries
get_libraries,
)



st.set_page_config(
page_title="AMDirT viewer",
page_icon="https://raw.githubusercontent.com/SPAAM-community/AncientMetagenomeDir/master/assets/images/logos/spaam-AncientMetagenomeDir_logo_mini.png",
Expand All @@ -30,6 +30,29 @@

supported_archives = ["ENA", "SRA"]

enum_url_strandtype = urllib.request.urlopen(
"https://github.com/SPAAM-community/AncientMetagenomeDir/raw/master/assets/enums/strand_type.json"
).read()
enum_url_polymerase = urllib.request.urlopen(
"https://github.com/SPAAM-community/AncientMetagenomeDir/raw/master/assets/enums/library_polymerase.json"
).read()
enum_url_librarytreatment = urllib.request.urlopen(
"https://github.com/SPAAM-community/AncientMetagenomeDir/raw/master/assets/enums/library_treatment.json"
).read()
enum_url_instrumentmodel = urllib.request.urlopen(
"https://github.com/SPAAM-community/AncientMetagenomeDir/raw/master/assets/enums/instrument_model.json"
).read()
enum_url_librarylayout = urllib.request.urlopen(
"https://github.com/SPAAM-community/AncientMetagenomeDir/raw/master/assets/enums/library_layout.json"
).read()
enum_url_librarystrategy = urllib.request.urlopen(
"https://github.com/SPAAM-community/AncientMetagenomeDir/raw/master/assets/enums/library_strategy.json"
).read()
enum_url_filetype = urllib.request.urlopen(
"https://github.com/SPAAM-community/AncientMetagenomeDir/raw/master/assets/enums/file_type.json"
).read()


if "compute" not in st.session_state:
st.session_state.compute = False
if "force_validation" not in st.session_state:
Expand Down Expand Up @@ -136,6 +159,53 @@ def parse_args():
data_return_mode="filtered",
update_mode="selection_changed",
)

## Library filter buttons

filter_placeholder = st.empty()

with st.expander(
"**Advanced Library Filters (Optional) [CURRENTLY DOES NOTHING]**",
expanded=False,
):
(
select_strandtype,
select_polymerase,
select_librarytreatment,
select_librarystrategy,
select_librarylayout,
select_instrumentmodel,
select_filetype,
) = st.columns(7)

with select_strandtype:
st.selectbox("**Strand Type**", json.loads(enum_url_strandtype)["enum"])
with select_polymerase:
st.multiselect(
"**Library Polymerase**",
json.loads(enum_url_polymerase)["enum"],
)
with select_librarytreatment:
st.multiselect(
"**Library Treatment**",
json.loads(enum_url_librarytreatment)["enum"],
)
with select_librarystrategy:
st.multiselect(
"**Library Strategy**",
json.loads(enum_url_librarystrategy)["enum"],
)
with select_librarylayout:
st.selectbox(
"**Library Layout**", json.loads(enum_url_librarylayout)["enum"]
)
with select_instrumentmodel:
st.multiselect(
"**Platform**", json.loads(enum_url_instrumentmodel)["enum"]
)
with select_filetype:
st.multiselect("**File Type**", json.loads(enum_url_filetype)["enum"])

if st.form_submit_button("Validate selection", type="primary"):
if len(df_mod["selected_rows"]) == 0:
st.error(
Expand All @@ -160,17 +230,16 @@ def parse_args():
placeholder = st.empty()

with placeholder.container():

(
button_libraries,
button_fastq,
button_samplesheet_eager,
button_fastq,
button_samplesheet_eager,
button_samplesheet_mag,
button_samplesheet_taxprofiler,
button_samplesheet_taxprofiler,
button_samplesheet_ameta,
button_bibtex
button_bibtex,
) = st.columns(7)

if st.session_state.force_validation:
# Calculate the fastq file size of the selected libraries
acc_table = prepare_accession_table(
Expand Down Expand Up @@ -207,9 +276,8 @@ def parse_args():
libraries=library,
samples=pd.DataFrame(df_mod["selected_rows"]),
supported_archives=supported_archives,
).drop(
col_drop, axis=1
)
.drop(col_drop, axis=1)
.to_csv(sep="\t", index=False)
.encode("utf-8"),
file_name="AncientMetagenomeDir_filtered_libraries.csv",
Expand All @@ -228,7 +296,7 @@ def parse_args():
library,
st.session_state.table_name,
supported_archives,
)["df"]['archive_accession']
)["df"]["archive_accession"]
.to_csv(sep="\t", header=False, index=False)
.encode("utf-8"),
file_name="AncientMetagenomeDir_nf_core_fetchngs_input_table.tsv",
Expand Down Expand Up @@ -279,27 +347,24 @@ def parse_args():
## NF-CORE/MAG TABLE ##
#######################
mag_table_single, mag_table_paired = prepare_mag_table(
pd.DataFrame(df_mod["selected_rows"]),
library,
st.session_state.table_name,
supported_archives,
)
pd.DataFrame(df_mod["selected_rows"]),
library,
st.session_state.table_name,
supported_archives,
)
zip_file = zipfile.ZipFile(
'ancientMetagenomeDir_mag_input.zip', mode='w')
"ancientMetagenomeDir_mag_input.zip", mode="w"
)
if not mag_table_single.empty:
mag_table_single.to_csv(
"nf_core_mag_input_single_table.csv", index=False
)
zip_file.write(
'nf_core_mag_input_single_table.csv'
)
)
zip_file.write("nf_core_mag_input_single_table.csv")
if not mag_table_paired.empty:
mag_table_paired.to_csv(
"nf_core_mag_input_paired_table.csv", index=False
)
zip_file.write(
'nf_core_mag_input_paired_table.csv'
)
)
zip_file.write("nf_core_mag_input_paired_table.csv")
zip_file.close()
with open("ancientMetagenomeDir_mag_input.zip", "rb") as zip_file:
with button_samplesheet_mag:
Expand Down Expand Up @@ -353,9 +418,13 @@ def parse_args():
data=prepare_bibtex_file(pd.DataFrame(df_mod["selected_rows"])),
file_name="AncientMetagenomeDir_bibliography.bib",
)

st.markdown("ℹ️ _By default all download scripts/inputs include ALL libraries of the selected samples. \n Review the AncientMetagenomeDir library table prior using any other table, to ensure usage of relevant libraries!_")
st.markdown("⚠️ _We provide no warranty to the accuracy of the generated input sheets._")

st.markdown(
"ℹ️ _By default all download scripts/inputs include ALL libraries of the selected samples. \n Review the AncientMetagenomeDir library table prior using any other table, to ensure usage of relevant libraries!_"
)
st.markdown(
"⚠️ _We provide no warranty to the accuracy of the generated input sheets._"
)

if st.button("Start New Selection", type="primary"):
st.session_state.compute = False
Expand Down

0 comments on commit f0088d8

Please sign in to comment.