diff --git a/AMDirT/viewer/streamlit.py b/AMDirT/viewer/streamlit.py index e4c49a0..b52d90c 100644 --- a/AMDirT/viewer/streamlit.py +++ b/AMDirT/viewer/streamlit.py @@ -7,7 +7,6 @@ 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, @@ -18,10 +17,11 @@ 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", @@ -30,29 +30,6 @@ 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: @@ -159,53 +136,6 @@ 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( @@ -230,16 +160,17 @@ 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( @@ -276,8 +207,9 @@ 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", @@ -296,7 +228,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", @@ -347,24 +279,27 @@ 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: @@ -418,13 +353,9 @@ 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