forked from OpenMS/streamlit-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
145 lines (114 loc) Β· 4.53 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
Main page for the OpenMS Template App.
This module sets up and displays the Streamlit app for the OpenMS Template App.
It includes:
- Setting the app title.
- Displaying a description.
- Providing a download button for the Windows version of the app.
Usage:
Run this script to launch the OpenMS Template App.
Note:
- If run in local mode, the CAPTCHA control is not applied.
- If not in local mode, CAPTCHA control is applied to verify the user.
Returns:
None
"""
import sys
import streamlit as st
from pathlib import Path
from src.captcha_ import captcha_control
from src.common import page_setup, save_params
from st_pages import Page, show_pages
params = page_setup(page="main")
def flashdeconvPages():
show_pages([
Page("app.py", "FLASHViewer", "π "),
Page("pages/FLASHDeconvWorkflow.py", "Workflow", "βοΈ"),
Page("pages/FileUpload.py", "File Upload", "π"),
Page("pages/SequenceInput.py", "Sequence Input", "π§΅"),
Page("pages/LayoutManager.py", "Layout Manager", "ποΈ"),
Page("pages/FLASHDeconvViewer.py", "Viewer", "π"),
Page("pages/FLASHDeconvDownload.py", "Download", "β¬οΈ"),
])
def flashtagPages():
show_pages([
Page("app.py", "FLASHViewer", "π "),
Page("pages/FLASHTaggerWorkflow.py", "Workflow", "βοΈ"),
Page("pages/FileUploadTagger.py", "File Upload", "π"),
Page("pages/LayoutManagerTagger.py", "Layout Manager", "ποΈ"),
Page("pages/FLASHTaggerViewer.py", "Viewer", "π"),
Page("pages/FLASHTaggerDownload.py", "Download", "β¬οΈ"),
])
def flashquantPages():
show_pages([
Page("app.py", "FLASHViewer", "π "),
Page("pages/FileUpload_FLASHQuant.py", "File Upload", "π"),
Page("pages/FLASHQuantViewer.py", "Viewer", "π"),
])
page_names_to_funcs = {
"FLASHTagger": flashtagPages,
"FLASHDeconv": flashdeconvPages,
"FLASHQuant": flashquantPages,
}
def onToolChange():
if 'changed_tool_name' in st.session_state:
match st.session_state.changed_tool_name:
case 'FLASHDeconv':
st.session_state['tool_index'] = 0
case 'FLASHTagger':
st.session_state['tool_index'] = 1
case 'FLASHQuant':
st.session_state['tool_index'] = 2
st.rerun() # reload the page to sync the change
def main():
"""
Display main page content.
"""
# sidebar to toggle between tools
if 'tool_index' not in st.session_state:
page_names_to_funcs['FLASHDeconv']()
st.session_state['tool_index'] = 0
# main content
st.markdown('#### FLASHViewer visualizes outputs from FLASH\* tools.')
st.info("""
**π‘ How to run FLASHViewer**
1. Go to the **βοΈ Workflow** page through the sidebar and run your analysis.\
OR, go to the **π File Upload** page through the sidebar and upload FLASHDeconv output files (\*_annotated.mzML & \*_deconv.mzML)
2. Click the **π Viewer** page on the sidebar to view the results in detail.
**\***Download of results is supported.only for FLASHDeconv
""")
# when entered into other page, key is resetting (emptied) - thus set the value with index
st.selectbox("Choose a tool", ['FLASHDeconv', 'FLASHTagger', 'FLASHQuant'], index=st.session_state.tool_index,
on_change=onToolChange(), key='changed_tool_name')
page_names_to_funcs[st.session_state.changed_tool_name]()
if Path("OpenMS-App.zip").exists():
st.text("")
st.text("")
st.markdown("""
Download the latest version for Windows by clicking the button below.
""")
with open("OpenMS-App.zip", "rb") as file:
st.download_button(
label="Download for Windows",
data=file,
file_name="OpenMS-App.zip",
mime="archive/zip",
type="primary",
)
save_params(params)
# Check if the script is run in local mode (e.g., "streamlit run app.py local")
if "local" in sys.argv:
# In local mode, run the main function without applying captcha
main()
# If not in local mode, assume it's hosted/online mode
else:
show_pages([
Page("app.py", "FLASHViewer", "π "),
])
# WORK LIKE MULTIPAGE APP
if "controllo" not in st.session_state or st.session_state["controllo"] is False:
# Apply captcha control to verify the user
captcha_control()
else:
# Run the main function
main()