Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String constants session state #326

Merged
merged 13 commits into from
Sep 18, 2024
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"filename": "alphastats/gui/utils/ollama_utils.py",
"hashed_secret": "8ed4322e8e2790b8c928d381ce8d07cfd966e909",
"is_verified": false,
"line_number": 68,
"line_number": 70,
"is_secret": false
}
],
Expand All @@ -160,5 +160,5 @@
}
]
},
"generated_at": "2024-09-12T14:19:09Z"
"generated_at": "2024-09-17T12:01:59Z"
}
9 changes: 5 additions & 4 deletions alphastats/gui/pages/02_Import Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
sidebar_info,
empty_session_state,
init_session_state,
StateKeys,
)


Expand All @@ -27,11 +28,11 @@ def _finalize_data_loading(
dataset: DataSet,
) -> None:
"""Finalize the data loading process."""
st.session_state["loader"] = (
st.session_state[StateKeys.LOADER] = (
loader # TODO: Figure out if we even need the loader here, as the dataset has the loader as an attribute.
)
st.session_state["metadata_columns"] = metadata_columns
st.session_state["dataset"] = dataset
st.session_state[StateKeys.METADATA_COLUMNS] = metadata_columns
st.session_state[StateKeys.DATASET] = dataset

load_options()
sidebar_info()
Expand Down Expand Up @@ -64,7 +65,7 @@ def _finalize_data_loading(


st.markdown("### Import Proteomics Data")
if "dataset" in st.session_state:
if StateKeys.DATASET in st.session_state:
st.info(f"DataSet already present.")
st.page_link("pages/03_Data Overview.py", label="=> Go to data overview page..")
st.stop()
Expand Down
6 changes: 3 additions & 3 deletions alphastats/gui/pages/03_Data Overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
get_intensity_distribution_unprocessed,
display_loaded_dataset,
)
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state, StateKeys

init_session_state()
sidebar_info()

if "dataset" not in st.session_state:
if StateKeys.DATASET not in st.session_state:
st.info("Import Data first")
st.stop()

st.markdown("### DataSet Info")

display_loaded_dataset(st.session_state["dataset"])
display_loaded_dataset(st.session_state[StateKeys.DATASET])

st.markdown("## DataSet overview")

Expand Down
30 changes: 17 additions & 13 deletions alphastats/gui/pages/03_Preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
reset_preprocessing,
PREPROCESSING_STEPS,
)
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state, StateKeys

init_session_state()
sidebar_info()

if "workflow" not in st.session_state:
st.session_state["workflow"] = [
if StateKeys.WORKFLOW not in st.session_state:
st.session_state[StateKeys.WORKFLOW] = [
PREPROCESSING_STEPS.REMOVE_CONTAMINATIONS,
PREPROCESSING_STEPS.SUBSET,
PREPROCESSING_STEPS.LOG2_TRANSFORM,
Expand All @@ -27,29 +27,33 @@
c1, c2 = st.columns([1, 1])

with c2:
if "dataset" in st.session_state:
settings = configure_preprocessing(dataset=st.session_state["dataset"])
if StateKeys.DATASET in st.session_state:
settings = configure_preprocessing(dataset=st.session_state[StateKeys.DATASET])
new_workflow = update_workflow(settings)
if new_workflow != st.session_state.workflow:
st.session_state.workflow = new_workflow
if new_workflow != st.session_state[StateKeys.WORKFLOW]:
st.session_state[StateKeys.WORKFLOW] = new_workflow

with c1:
st.write("#### Flowchart of preprocessing workflow:")

selected_nodes = draw_workflow(st.session_state.workflow)
selected_nodes = draw_workflow(st.session_state[StateKeys.WORKFLOW])

if "dataset" not in st.session_state:
if StateKeys.DATASET not in st.session_state:
st.info("Import data first to configure and run preprocessing")

else:
c11, c12 = st.columns([1, 1])
if c11.button("Run preprocessing", key="_run_preprocessing"):
run_preprocessing(settings, st.session_state["dataset"])
run_preprocessing(settings, st.session_state[StateKeys.DATASET])
# TODO show more info about the preprocessing steps
display_preprocessing_info(st.session_state["dataset"].preprocessing_info)
display_preprocessing_info(
st.session_state[StateKeys.DATASET].preprocessing_info
)

if c12.button("Reset all Preprocessing steps", key="_reset_preprocessing"):
reset_preprocessing(st.session_state["dataset"])
display_preprocessing_info(st.session_state["dataset"].preprocessing_info)
reset_preprocessing(st.session_state[StateKeys.DATASET])
display_preprocessing_info(
st.session_state[StateKeys.DATASET].preprocessing_info
)

# TODO: Add comparison plot of intensity distribution before and after preprocessing
20 changes: 11 additions & 9 deletions alphastats/gui/pages/04_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
sidebar_info,
init_session_state,
convert_df,
StateKeys,
)
from alphastats.gui.utils.analysis_helper import (
get_analysis,
Expand All @@ -24,8 +25,8 @@ def select_analysis():
load_options()
method = st.selectbox(
"Analysis",
options=list(st.session_state.plotting_options.keys())
+ list(st.session_state.statistic_options.keys()),
options=list(st.session_state[StateKeys.PLOTTING_OPTIONS].keys())
+ list(st.session_state[StateKeys.STATISTIC_OPTIONS].keys()),
)
return method

Expand All @@ -50,11 +51,11 @@ def select_analysis():
st.markdown(styl, unsafe_allow_html=True)


if "plot_list" not in st.session_state:
st.session_state["plot_list"] = []
if StateKeys.PLOT_LIST not in st.session_state:
st.session_state[StateKeys.PLOT_LIST] = []


if "dataset" in st.session_state:
if StateKeys.DATASET in st.session_state:
c1, c2 = st.columns((1, 2))

plot_to_display = False
Expand All @@ -64,15 +65,16 @@ def select_analysis():
with c1:
method = select_analysis()

if method in st.session_state.plotting_options.keys():
if method in st.session_state[StateKeys.PLOTTING_OPTIONS].keys():
analysis_result = get_analysis(
method=method, options_dict=st.session_state.plotting_options
method=method, options_dict=st.session_state[StateKeys.PLOTTING_OPTIONS]
)
plot_to_display = True

elif method in st.session_state.statistic_options.keys():
elif method in st.session_state[StateKeys.STATISTIC_OPTIONS].keys():
analysis_result = get_analysis(
method=method, options_dict=st.session_state.statistic_options
method=method,
options_dict=st.session_state[StateKeys.STATISTIC_OPTIONS],
)
df_to_display = True

Expand Down
Loading
Loading