|
3 | 3 | import streamlit as st |
4 | 4 | import pandas as pd |
5 | 5 |
|
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 | +) |
7 | 14 | from src import fileupload |
8 | 15 |
|
9 | 16 | params = page_setup() |
10 | 17 |
|
11 | 18 | st.title("File Upload") |
12 | 19 |
|
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"] |
14 | 27 | if st.session_state.location == "local": |
15 | 28 | tabs.append("Files from local folder") |
16 | 29 |
|
|
28 | 41 | else: |
29 | 42 | st.warning("Select files first.") |
30 | 43 |
|
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 | | - |
38 | 44 | # Local file upload option: via directory path |
39 | 45 | if st.session_state.location == "local": |
40 | | - with tabs[2]: |
| 46 | + with tabs[1]: |
41 | 47 | st_cols = st.columns([0.05, 0.95], gap="small") |
42 | 48 | with st_cols[0]: |
43 | 49 | st.write("\n") |
44 | 50 | 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 | + ) |
46 | 57 | 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 | + ) |
48 | 62 | st.session_state["previous_dir"] = st.session_state["local_dir"] |
49 | 63 | with st_cols[1]: |
50 | 64 | # 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 | + ) |
52 | 68 | # raw string for file paths |
53 | 69 | local_mzML_dir = rf"{local_mzML_dir}" |
54 | 70 | 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 | + ) |
57 | 80 | 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 | + ) |
63 | 86 | if copy_button: |
64 | 87 | fileupload.copy_local_mzML_files_from_directory(local_mzML_dir, use_copy) |
65 | 88 |
|
66 | | -mzML_dir = Path(st.session_state.workspace, "mzML-files") |
67 | 89 | if any(Path(mzML_dir).iterdir()): |
68 | 90 | v_space(2) |
69 | 91 | # 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 | + |
72 | 102 | # Check if local files are available |
73 | 103 | external_files = Path(mzML_dir, "external_files.txt") |
74 | 104 | if external_files.exists(): |
75 | 105 | with open(external_files, "r") as f_handle: |
76 | 106 | external_files = f_handle.readlines() |
77 | 107 | 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 | + |
80 | 112 | st.markdown("##### mzML files in current workspace:") |
81 | 113 | show_table(df) |
82 | 114 | v_space(1) |
|
0 commit comments