Skip to content

Commit

Permalink
Merge branch 'fix_merging_issues' of github.com:JeeH-K/FLASHViewer in…
Browse files Browse the repository at this point in the history
…to fix_merging_issues
  • Loading branch information
t0mdavid-m committed May 15, 2024
2 parents f8c4e82 + 0140400 commit 8da0f65
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 41 deletions.
4 changes: 1 addition & 3 deletions pages/FLASHDeconvWorkflow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import streamlit as st
from src.common import page_setup
from src.workflow.WorkflowManager import WorkflowManager
from src.Workflow import DeconvWorkflow, Workflow
import pyopenms as oms
from src.Workflow import DeconvWorkflow


# The rest of the page can, but does not have to be changed
Expand Down
4 changes: 1 addition & 3 deletions pages/FLASHTaggerWorkflow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import streamlit as st
from src.common import page_setup
from src.workflow.WorkflowManager import WorkflowManager
from src.Workflow import TagWorkflow, Workflow
import pyopenms as oms
from src.Workflow import TagWorkflow


# The rest of the page can, but does not have to be changed
Expand Down
60 changes: 38 additions & 22 deletions pages/FileUpload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from src.common import page_setup, v_space, save_params, reset_directory


input_file_types = ["deconv-mzMLs", "anno-mzMLs"]
parsed_df_types = ["deconv_dfs", "anno_dfs"]


def initializeWorkspace(input_file_types_: list, parsed_df_types_: list) -> None:
"""
Set up the required directory and session states
Expand Down Expand Up @@ -135,14 +139,45 @@ def parseUploadedFiles():
st.success('Done parsing the experiment %s!' % exp_name)


def showUploadedFilesTable() -> bool:
''' return: if showing without error '''
# for error message or list of uploaded files
deconv_files = sorted(st.session_state["deconv_dfs"].keys())
anno_files = sorted(st.session_state["anno_dfs"].keys())

# error message if files not exist
if len(deconv_files) == 0 and len(anno_files) == 0:
st.info('No mzML added yet!', icon="ℹ️")
elif len(deconv_files) == 0:
st.error("FLASHDeconv deconvolved mzML file is not added yet!")
elif len(anno_files) == 0:
st.error("FLASHDeconv annotated mzML file is not added yet!")
elif len(deconv_files) != len(anno_files):
st.error("The same number of deconvolved and annotated mzML file should be uploaded!")
else:
v_space(2)
st.session_state["experiment-df"] = getUploadedFileDF(deconv_files, anno_files)
st.markdown('**Uploaded experiments in current workspace**')
st.dataframe(st.session_state["experiment-df"]) # show table
v_space(1)
return True
return False


# for Workflow
def postprocessingAfterUpload_FD(uploaded_files: list) -> None:
initializeWorkspace(input_file_types, parsed_df_types)
handleInputFiles(uploaded_files)
parseUploadedFiles(reparse=True)
showUploadedFilesTable()


if __name__ == '__main__':

# page initialization
params = page_setup()

# make directory to store deconv and anno mzML files & initialize data storage
input_file_types = ["deconv-mzMLs", "anno-mzMLs"]
parsed_df_types = ["deconv_dfs", "anno_dfs"]
initializeWorkspace(input_file_types, parsed_df_types)

st.title("FLASHDeconv output files Upload")
Expand Down Expand Up @@ -203,26 +238,7 @@ def parseUploadedFiles():
st.session_state['progress_bar_space'] = st.container()
parseUploadedFiles()

# for error message or list of uploaded files
deconv_files = sorted(st.session_state["deconv_dfs"].keys())
anno_files = sorted(st.session_state["anno_dfs"].keys())

# error message if files not exist
if len(deconv_files) == 0 and len(anno_files) == 0:
st.info('No mzML added yet!', icon="ℹ️")
elif len(deconv_files) == 0:
st.error("FLASHDeconv deconvolved mzML file is not added yet!")
elif len(anno_files) == 0:
st.error("FLASHDeconv annotated mzML file is not added yet!")
elif len(deconv_files) != len(anno_files):
st.error("The same number of deconvolved and annotated mzML file should be uploaded!")
else:
v_space(2)
st.session_state["experiment-df"] = getUploadedFileDF(deconv_files, anno_files)
st.markdown('**Uploaded experiments in current workspace**')
st.dataframe(st.session_state["experiment-df"]) # show table
v_space(1)

if showUploadedFilesTable():
# Remove files
with st.expander("🗑️ Remove mzML files"):
to_remove = st.multiselect(
Expand Down
15 changes: 13 additions & 2 deletions pages/FileUploadTagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from pages.FileUpload import remove_selected_mzML_files


input_file_types = ["deconv-mzMLs", "anno-mzMLs", "tags-tsv", "proteins-tsv"]
parsed_df_types = ["deconv_dfs", "anno_dfs", "tag_dfs", "protein_dfs"]


def initializeWorkspace(input_file_types_: list, parsed_df_types_: list) -> None:
"""
Set up the required directory and session states
Expand Down Expand Up @@ -167,13 +171,20 @@ def content():
parsed_df_types = ["deconv_dfs", "anno_dfs", "tag_dfs", "protein_dfs"]
initializeWorkspace(input_types, parsed_df_types)


# for Workflow
def postprocessingAfterUpload_Tagger(uploaded_files: list) -> None:
initializeWorkspace(input_file_types, parsed_df_types)
handleInputFiles(uploaded_files)
parseUploadedFiles(reparse=True)
showUploadedFilesTable()


if __name__ == '__main__':

params = page_setup()

# make directory to store deconv and anno mzML files & initialize data storage
input_file_types = ["deconv-mzMLs", "anno-mzMLs", "tags-tsv", "proteins-tsv"]
parsed_df_types = ["deconv_dfs", "anno_dfs", "tag_dfs", "protein_dfs"]
initializeWorkspace(input_file_types, parsed_df_types)

st.title("File Upload")
Expand Down
43 changes: 32 additions & 11 deletions src/Workflow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import streamlit as st
import time
from .workflow.WorkflowManager import WorkflowManager
from pages.FileUploadTagger import handleInputFiles
from pages.FileUploadTagger import parseUploadedFiles
from pages.FileUploadTagger import initializeWorkspace, showUploadedFilesTable
from pages.FileUploadTagger import postprocessingAfterUpload_Tagger
from pages.FileUpload import postprocessingAfterUpload_FD

from os.path import join, splitext, basename, exists, dirname
from os import makedirs
Expand Down Expand Up @@ -182,13 +181,7 @@ def pp(self) -> None:


# make directory to store deconv and anno mzML files & initialize data storage
input_types = ["deconv-mzMLs", "anno-mzMLs", "tags-tsv", "proteins-tsv"]
parsed_df_types = ["deconv_dfs", "anno_dfs", "tag_dfs", "protein_dfs"]
initializeWorkspace(input_types, parsed_df_types)
handleInputFiles(uploaded_files)
parseUploadedFiles(reparse=True)
showUploadedFilesTable()

postprocessingAfterUpload_Tagger(uploaded_files)



Expand Down Expand Up @@ -343,7 +336,35 @@ def configure(self) -> None:
],
display_subsections=True
)



def pp(self) -> None:
st.session_state['progress_bar_space'] = st.container()

try:
in_mzMLs = self.file_manager.get_files(self.params["mzML-files"])
except:
st.error('Please select at least one mzML file.')
return

base_path = dirname(self.workflow_dir)

uploaded_files = []
for in_mzML in in_mzMLs:
current_base = splitext(basename(in_mzML))[0]
current_time = time.strftime("%Y%m%d-%H%M%S")

out_anno = join(base_path, 'anno-mzMLs', f'{current_base}_{current_time}_annotated.mzML')
out_deconv = join(base_path, 'deconv-mzMLs', f'{current_base}_{current_time}_deconv.mzML')

#uploaded_files.append(out_db)
uploaded_files.append(out_anno)
uploaded_files.append(out_deconv)

# make directory to store deconv and anno mzML files & initialize data storage
postprocessingAfterUpload_FD(uploaded_files)


def execution(self) -> None:
# Get mzML input files from self.params.
# Can be done without file manager, however, it ensures everything is correct.
Expand Down

0 comments on commit 8da0f65

Please sign in to comment.