Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 55 additions & 16 deletions content/file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
import streamlit as st
import pandas as pd

from src.common.common import page_setup, save_params, v_space, show_table, TK_AVAILABLE, tk_directory_dialog
from src.common.common import (
page_setup,
save_params,
v_space,
show_table,
TK_AVAILABLE,
tk_directory_dialog,
)
from src import fileupload

params = page_setup()

st.title("File Upload")

# Check if there are any files in the workspace
mzML_dir = Path(st.session_state.workspace, "mzML-files")
if not any(Path(mzML_dir).iterdir()):
# No files present, load example data
fileupload.load_example_mzML_files()

tabs = ["File Upload", "Example Data"]
if st.session_state.location == "local":
tabs.append("Files from local folder")
Expand Down Expand Up @@ -42,41 +55,67 @@
with st_cols[0]:
st.write("\n")
st.write("\n")
dialog_button = st.button("📁", key='local_browse', help="Browse for your local directory with MS data.", disabled=not TK_AVAILABLE)
dialog_button = st.button(
"📁",
key="local_browse",
help="Browse for your local directory with MS data.",
disabled=not TK_AVAILABLE,
)
if dialog_button:
st.session_state["local_dir"] = tk_directory_dialog("Select directory with your MS data", st.session_state["previous_dir"])
st.session_state["local_dir"] = tk_directory_dialog(
"Select directory with your MS data",
st.session_state["previous_dir"],
)
st.session_state["previous_dir"] = st.session_state["local_dir"]
with st_cols[1]:
# with st.form("local-file-upload"):
local_mzML_dir = st.text_input("path to folder with mzML files", value=st.session_state["local_dir"])
local_mzML_dir = st.text_input(
"path to folder with mzML files", value=st.session_state["local_dir"]
)
# raw string for file paths
local_mzML_dir = rf"{local_mzML_dir}"
cols = st.columns([0.65, 0.3, 0.4, 0.25], gap="small")
copy_button = cols[1].button("Copy files to workspace", type="primary", disabled=(local_mzML_dir == ""))
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.")
copy_button = cols[1].button(
"Copy files to workspace", type="primary", disabled=(local_mzML_dir == "")
)
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.",
)
if not use_copy:
st.warning(
"**Warning**: You have deselected the `Make a copy of files` option. "
"This **_assumes you know what you are doing_**. "
"This means that the original files will be used instead. "
)
st.warning(
"**Warning**: You have deselected the `Make a copy of files` option. "
"This **_assumes you know what you are doing_**. "
"This means that the original files will be used instead. "
)
if copy_button:
fileupload.copy_local_mzML_files_from_directory(local_mzML_dir, use_copy)

mzML_dir = Path(st.session_state.workspace, "mzML-files")
if any(Path(mzML_dir).iterdir()):
v_space(2)
# Display all mzML files currently in workspace
df = pd.DataFrame({"file name": [f.name for f in Path(mzML_dir).iterdir() if "external_files.txt" not in f.name]})

df = pd.DataFrame(
{
"file name": [
f.name
for f in Path(mzML_dir).iterdir()
if "external_files.txt" not in f.name
]
}
)

# Check if local files are available
external_files = Path(mzML_dir, "external_files.txt")
if external_files.exists():
with open(external_files, "r") as f_handle:
external_files = f_handle.readlines()
external_files = [f.strip() for f in external_files]
df = pd.concat([df, pd.DataFrame({"file name": external_files})], ignore_index=True)

df = pd.concat(
[df, pd.DataFrame({"file name": external_files})], ignore_index=True
)

st.markdown("##### mzML files in current workspace:")
show_table(df)
v_space(1)
Expand Down
Loading