-
Notifications
You must be signed in to change notification settings - Fork 1
/
Multiplex_Analysis_Web_Apps.py
194 lines (167 loc) · 8.95 KB
/
Multiplex_Analysis_Web_Apps.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import streamlit as st
import os
from streamlit_extras.app_logo import add_logo
import streamlit_session_state_management
import nidap_dashboard_lib as ndl # Useful functions for dashboards connected to NIDAP
import streamlit_utils
import numpy as np
import subprocess
import platform_io
import install_missing_packages
install_missing_packages.live_package_installation()
# Note if any of the following imports having " # slow" are not commented out, there is a delay in running the forking test
from pages2 import data_import_and_export
from pages2 import datafile_format_unifier
from pages2 import open_file
from pages2 import robust_scatter_plotter
from pages2 import multiaxial_gating
from pages2 import thresholded_phenotyping # slow due to things ultimately importing umap
from pages2 import adaptive_phenotyping
from pages2 import Pheno_Cluster_a # "slow" for forking test initialization
from pages2 import Pheno_Cluster_b # "slow" for forking test initialization
from pages2 import Tool_parameter_selection
from pages2 import Run_workflow
from pages2 import Display_individual_ROI_heatmaps
from pages2 import Display_average_heatmaps
from pages2 import Display_average_heatmaps_per_annotation
from pages2 import Display_ROI_P_values_overlaid_on_slides
from pages2 import Neighborhood_Profiles # slow due to things ultimately importing umap
from pages2 import UMAP_Analyzer # slow due to things ultimately importing umap
from pages2 import Clusters_Analyzer # slow due to things ultimately importing umap
from pages2 import memory_analyzer
from pages2 import radial_bins_plots
from pages2 import radial_profiles_analysis
from pages2 import preprocessing
from pages2 import results_transfer
# from pages2 import forking_test
def welcome_page():
# Markdown text
intro_markdown = ndl.read_markdown_file('markdown/MAWA_WelcomePage.md')
st.markdown(intro_markdown, unsafe_allow_html=True)
def platform_is_nidap():
'''
Check if the Streamlit application is operating on NIDAP
'''
return np.any(['nidap.nih.gov' in x for x in subprocess.run('conda config --show channels', shell=True, capture_output=True).stdout.decode().split('\n')[1:-1]])
def check_for_platform(session_state):
'''
Set the platform parameters based on the platform the Streamlit app is running on
'''
# Initialize the platform object
if 'platform' not in session_state:
session_state['platform'] = platform_io.Platform(platform=('nidap' if platform_is_nidap() else 'local'))
return session_state
def main():
st.set_page_config(layout="wide")
# Use the new st.naviation()/st.Page() API to create a multi-page app
pg = st.navigation({
'Home 🏠':
[
st.Page(welcome_page, title="Welcome", url_path='home')
],
'File Handling 🗄️':
[
st.Page(data_import_and_export.main, title="Data Import and Export", url_path='data_import_and_export'),
st.Page(datafile_format_unifier.main, title="Datafile Unification", url_path='datafile_unification'),
st.Page(open_file.main, title="Open File", url_path='open_file')
],
'Coordinate Scatter Plotter 🌟':
[
st.Page(robust_scatter_plotter.main, title="Coordinate Scatter Plotter", url_path='coordinate_scatter_plotter')
],
'Phenotyping 🧬':
[
st.Page(multiaxial_gating.main, title="Using Raw Intensities", url_path='using_raw_intensities'),
st.Page(thresholded_phenotyping.main, title="Using Thresholded Intensities", url_path='using_thresholded_intensities'),
st.Page(adaptive_phenotyping.main, title="Adaptive Phenotyping", url_path='adaptive_phenotyping')
],
'Phenotype Clustering Workflow ✨':
[
st.Page(Pheno_Cluster_a.main, title="Unsupervised Phenotype Clustering", url_path='unsupervised_phenotype_clustering'),
st.Page(Pheno_Cluster_b.main, title="Differential Intensity", url_path='differential_intensity')
],
'Spatial Interaction Tool 🗺️':
[
st.Page(Tool_parameter_selection.main, title="Tool Parameter Selection", url_path='tool_parameter_selection'),
st.Page(Run_workflow.main, title="Run SIT Workflow", url_path='run_sit_workflow'),
st.Page(Display_individual_ROI_heatmaps.main, title="Display Individual ROI Heatmaps", url_path='display_individual_roi_heatmaps'),
st.Page(Display_average_heatmaps.main, title="Display Average Heatmaps", url_path='display_average_heatmaps'),
st.Page(Display_average_heatmaps_per_annotation.main, title="Display Average Heatmaps per Annotation", url_path='display_average_heatmaps_per_annotation'),
st.Page(Display_ROI_P_values_overlaid_on_slides.main, title="Display ROI P Values Overlaid on Slides", url_path='display_roi_p_values_overlaid_on_slides')
],
'Neighborhood Profiles Workflow 🌳':
[
st.Page(Neighborhood_Profiles.main, title="Neighborhood Profiles", url_path='neighborhood_profiles'),
st.Page(UMAP_Analyzer.main, title="UMAP Differences Analyzer", url_path='umap_differences_analyzer'),
st.Page(Clusters_Analyzer.main, title="Clusters Analyzer", url_path='clusters_analyzer')
],
'Radial Profiles 🌀':
[
st.Page(radial_bins_plots.main, title="Radial Bins Plots", url_path='radial_bins_plots'),
st.Page(radial_profiles_analysis.main, title="Radial Profiles Analysis", url_path='radial_profiles_analysis')
],
'Utilities 🛠️':
[
st.Page(preprocessing.main, title="Preprocessing", url_path='preprocessing'),
st.Page(memory_analyzer.main, title="Memory Analyzer", url_path='memory_analyzer'),
st.Page(results_transfer.main, title="Results Transfer", url_path='results_transfer'),
# st.Page(forking_test.main, title="Forking Test", url_path='forking_test')
]
})
# Ensure the input/output directories exist
input_path = './input'
if not os.path.exists(input_path):
os.makedirs(input_path)
output_path = './output'
if not os.path.exists(output_path):
os.makedirs(output_path)
# For widget persistence, we need always copy the session state to itself, being careful with widgets that cannot be persisted, like st.data_editor() (where we use the "__do_not_persist" suffix to avoid persisting it)
for key in st.session_state.keys():
if (not key.endswith('__do_not_persist')) and (not key.startswith('FormSubmitter:')):
st.session_state[key] = st.session_state[key]
# This is needed for the st.dataframe_editor() class (https://github.com/andrew-weisman/streamlit-dataframe-editor) but is also useful for seeing where we are and where we've been
st.session_state['current_page_name'] = pg.url_path if pg.url_path != '' else 'Home'
if 'previous_page_name' not in st.session_state:
st.session_state['previous_page_name'] = st.session_state['current_page_name']
# Add logo to sidebar
add_logo('app_images/mawa_logo-width315.png', height=250)
# Determine whether this is the first time the app has been run
if 'app_has_been_run_at_least_once' not in st.session_state:
st.session_state['app_has_been_run_at_least_once'] = True
first_app_run = True
else:
first_app_run = False
# Run session state management in the sidebar
streamlit_session_state_management.execute(first_app_run)
# Initalize session_state values for streamlit processing
if 'init' not in st.session_state:
st.session_state = ndl.init_session_state(st.session_state)
# Sidebar organization
with st.sidebar:
st.write('**:book: [Documentation](https://ncats.github.io/multiplex-analysis-web-apps/)**')
with st.expander('Advanced:'):
benchmark_button = True
if benchmark_button:
st.button('Record Benchmarking', on_click = st.session_state.bc.save_run_to_csv)
if st.button('Calculate memory used by Python session'):
streamlit_utils.write_python_session_memory_usage()
# Check the platform
st.session_state = check_for_platform(st.session_state)
# Format tooltips
tooltip_style = """
<style>
div[data-baseweb="tooltip"] {
width: 250px;
}
</style>
"""
st.markdown(tooltip_style,unsafe_allow_html=True)
# On every page, display its title
st.title(pg.title)
# Render the select page
pg.run()
# Update the previous page location
st.session_state['previous_page_name'] = st.session_state['current_page_name']
# Needed for rendering pages which use multiprocessing (https://docs.python.org/3/library/multiprocessing.html#the-spawn-and-forkserver-start-methods)
if __name__ == '__main__':
main()