Skip to content

Commit

Permalink
seperate file lists for workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
axelwalter committed Sep 27, 2023
1 parent 5a05d4d commit 9b301a6
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 207 deletions.
3 changes: 2 additions & 1 deletion assets/default-params.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"selected-mzML-files": [],
"image-format": "svg",
"2D-map-intensity-cutoff": 5000,

"eic_selected_mzML": [],
"eic_mz_unit": "ppm",
"eic_tolerance_ppm": 10,
"eic_tolerance_da": 0.2,
Expand All @@ -11,6 +11,7 @@
"eic_combine": false,
"eic_peak_width": 20,

"umetaflow_selected_mzML": [],
"ffm_mass_error": 10.0,
"ffm_noise": 100.0,
"ffm_peak_width": 10.0,
Expand Down
5 changes: 0 additions & 5 deletions pages/0_📁_File_Upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

st.title("File Upload")

if "selected-mzML-files" not in st.session_state:
st.session_state["selected-mzML-files"] = params["selected-mzML-files"]

tabs = ["File Upload", "Example Data"]
if st.session_state.location == "local":
tabs.append("Files from local folder")
Expand Down Expand Up @@ -61,12 +58,10 @@
c1, c2 = st.columns(2)
if c2.button("Remove **selected**", type="primary", disabled=not any(to_remove)):
remove_selected_mzML_files(to_remove)
save_params(params)
st.experimental_rerun()

if c1.button("⚠️ Remove **all**", disabled=not any(mzML_dir.iterdir())):
remove_all_mzML_files()
save_params(params)
st.experimental_rerun()

save_params(params)
48 changes: 26 additions & 22 deletions pages/2_🔍_Extracted_Ion_Chromatograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

with st.expander("📖 Help"):
st.markdown(HELP)

default_df = pd.DataFrame({"name": [""], "mz": [np.nan], "RT (seconds)": [np.nan], "peak width (seconds)": [np.nan]})

if "workspace" in st.session_state:
Expand All @@ -28,13 +28,11 @@
# Load a default example df
df = default_df

with st.expander("Settings", expanded=True):
st.markdown("**Table with metabolites for chromatogram extraction**")
with st.expander("**Mass table with metabolites for chromatogram extraction**", True):
c1, c2 = st.columns(2)
# Uploader for XIC input table
c1.file_uploader("Upload XIC input table", type="tsv", label_visibility="collapsed",
key="xic-table-uploader", accept_multiple_files=False, on_change=upload_xic_table, args=[df])

key="xic-table-uploader", accept_multiple_files=False, on_change=upload_xic_table, args=[df])
# def update_mass_table()
edited = st.data_editor(df, use_container_width=True, num_rows="dynamic")

Expand All @@ -44,6 +42,7 @@
edited.to_csv(sep="\t", index=False).encode("utf-8"),
"XIC-input-table.tsv",
)

st.markdown("**Calculate mass and add to table**")
c1, c2, c3 = st.columns(3)
name = c1.text_input(
Expand Down Expand Up @@ -72,6 +71,10 @@
else:
st.warning("Invalid formula.")

with st.form("eic_form"):
st.multiselect("mzML files", [f.stem for f in Path(st.session_state.workspace, "mzML-files").glob("*.mzML")],
params["eic_selected_mzML"], key="eic_selected_mzML")

# Retention time settings
st.markdown("**Parameters for chromatogram extraction**")
c1, c2, c3 = st.columns(3)
Expand All @@ -94,27 +97,28 @@
"mass tolerance Da", 0.01, 10.0, params["eic_tolerance_da"], 0.05, key="eic_tolerance_da"
)

mzML_files = [str(Path(st.session_state.workspace,
"mzML-files", f+".mzML")) for f in st.session_state["selected-mzML-files"]]

results_dir = Path(st.session_state.workspace,
"extracted-ion-chromatograms")

v_space(1)
_, c2, _ = st.columns(3)
if c2.button("Extract chromatograms", type="primary"):
if not mzML_files:
st.warning("Upload/select some mzML files first!")
else:
extract_chromatograms(results_dir,
mzML_files,
edited,
st.session_state["eic_mz_unit"],
st.session_state["eic_tolerance_ppm"],
st.session_state["eic_tolerance_da"],
st.session_state["eic_time_unit"],
st.session_state["eic_peak_width"],
st.session_state["eic_baseline"])
submitted = c2.form_submit_button("Extract chromatograms", type="primary")

if submitted:
mzML_files = [str(Path(st.session_state.workspace,
"mzML-files", f+".mzML")) for f in st.session_state["eic_selected_mzML"]]
if not mzML_files:
st.warning("Upload/select some mzML files first!")
else:
extract_chromatograms(results_dir,
mzML_files,
edited,
st.session_state["eic_mz_unit"],
st.session_state["eic_tolerance_ppm"],
st.session_state["eic_tolerance_da"],
st.session_state["eic_time_unit"],
st.session_state["eic_peak_width"],
st.session_state["eic_baseline"])


# Display summary table
Expand Down Expand Up @@ -207,4 +211,4 @@
"xic-meta-data.tsv",
)

save_params(params)
save_params(params)
Loading

0 comments on commit 9b301a6

Please sign in to comment.