Skip to content

Commit 92a6979

Browse files
authored
Merge pull request #185 from achalbajpai/upstream-fresh-branch
feat: automatically load example data in pyOpenMS workflow
2 parents d5756dc + 78c4178 commit 92a6979

File tree

1 file changed

+57
-25
lines changed

1 file changed

+57
-25
lines changed

content/file_upload.py

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@
33
import streamlit as st
44
import pandas as pd
55

6-
from src.common.common import page_setup, save_params, v_space, show_table, TK_AVAILABLE, tk_directory_dialog
6+
from src.common.common import (
7+
page_setup,
8+
save_params,
9+
v_space,
10+
show_table,
11+
TK_AVAILABLE,
12+
tk_directory_dialog,
13+
)
714
from src import fileupload
815

916
params = page_setup()
1017

1118
st.title("File Upload")
1219

13-
tabs = ["File Upload", "Example Data"]
20+
# Check if there are any files in the workspace
21+
mzML_dir = Path(st.session_state.workspace, "mzML-files")
22+
if not any(Path(mzML_dir).iterdir()):
23+
# No files present, load example data
24+
fileupload.load_example_mzML_files()
25+
26+
tabs = ["File Upload"]
1427
if st.session_state.location == "local":
1528
tabs.append("Files from local folder")
1629

@@ -28,55 +41,74 @@
2841
else:
2942
st.warning("Select files first.")
3043

31-
# Example mzML files
32-
with tabs[1]:
33-
st.markdown("Short information text on example data.")
34-
cols = st.columns(3)
35-
if cols[1].button("Load Example Data", type="primary"):
36-
fileupload.load_example_mzML_files()
37-
3844
# Local file upload option: via directory path
3945
if st.session_state.location == "local":
40-
with tabs[2]:
46+
with tabs[1]:
4147
st_cols = st.columns([0.05, 0.95], gap="small")
4248
with st_cols[0]:
4349
st.write("\n")
4450
st.write("\n")
45-
dialog_button = st.button("📁", key='local_browse', help="Browse for your local directory with MS data.", disabled=not TK_AVAILABLE)
51+
dialog_button = st.button(
52+
"📁",
53+
key="local_browse",
54+
help="Browse for your local directory with MS data.",
55+
disabled=not TK_AVAILABLE,
56+
)
4657
if dialog_button:
47-
st.session_state["local_dir"] = tk_directory_dialog("Select directory with your MS data", st.session_state["previous_dir"])
58+
st.session_state["local_dir"] = tk_directory_dialog(
59+
"Select directory with your MS data",
60+
st.session_state["previous_dir"],
61+
)
4862
st.session_state["previous_dir"] = st.session_state["local_dir"]
4963
with st_cols[1]:
5064
# with st.form("local-file-upload"):
51-
local_mzML_dir = st.text_input("path to folder with mzML files", value=st.session_state["local_dir"])
65+
local_mzML_dir = st.text_input(
66+
"path to folder with mzML files", value=st.session_state["local_dir"]
67+
)
5268
# raw string for file paths
5369
local_mzML_dir = rf"{local_mzML_dir}"
5470
cols = st.columns([0.65, 0.3, 0.4, 0.25], gap="small")
55-
copy_button = cols[1].button("Copy files to workspace", type="primary", disabled=(local_mzML_dir == ""))
56-
use_copy = cols[2].checkbox("Make a copy of files", key="local_browse-copy_files", value=True, help="Create a copy of files in workspace.")
71+
copy_button = cols[1].button(
72+
"Copy files to workspace", type="primary", disabled=(local_mzML_dir == "")
73+
)
74+
use_copy = cols[2].checkbox(
75+
"Make a copy of files",
76+
key="local_browse-copy_files",
77+
value=True,
78+
help="Create a copy of files in workspace.",
79+
)
5780
if not use_copy:
58-
st.warning(
59-
"**Warning**: You have deselected the `Make a copy of files` option. "
60-
"This **_assumes you know what you are doing_**. "
61-
"This means that the original files will be used instead. "
62-
)
81+
st.warning(
82+
"**Warning**: You have deselected the `Make a copy of files` option. "
83+
"This **_assumes you know what you are doing_**. "
84+
"This means that the original files will be used instead. "
85+
)
6386
if copy_button:
6487
fileupload.copy_local_mzML_files_from_directory(local_mzML_dir, use_copy)
6588

66-
mzML_dir = Path(st.session_state.workspace, "mzML-files")
6789
if any(Path(mzML_dir).iterdir()):
6890
v_space(2)
6991
# Display all mzML files currently in workspace
70-
df = pd.DataFrame({"file name": [f.name for f in Path(mzML_dir).iterdir() if "external_files.txt" not in f.name]})
71-
92+
df = pd.DataFrame(
93+
{
94+
"file name": [
95+
f.name
96+
for f in Path(mzML_dir).iterdir()
97+
if "external_files.txt" not in f.name
98+
]
99+
}
100+
)
101+
72102
# Check if local files are available
73103
external_files = Path(mzML_dir, "external_files.txt")
74104
if external_files.exists():
75105
with open(external_files, "r") as f_handle:
76106
external_files = f_handle.readlines()
77107
external_files = [f.strip() for f in external_files]
78-
df = pd.concat([df, pd.DataFrame({"file name": external_files})], ignore_index=True)
79-
108+
df = pd.concat(
109+
[df, pd.DataFrame({"file name": external_files})], ignore_index=True
110+
)
111+
80112
st.markdown("##### mzML files in current workspace:")
81113
show_table(df)
82114
v_space(1)

0 commit comments

Comments
 (0)