diff --git a/alphastats/DataSet_Preprocess.py b/alphastats/DataSet_Preprocess.py index 1b7338ed..acc014f8 100644 --- a/alphastats/DataSet_Preprocess.py +++ b/alphastats/DataSet_Preprocess.py @@ -9,11 +9,11 @@ import streamlit as st from sklearn.experimental import enable_iterative_imputer # noqa -from alphastats.keys import Cols +from alphastats.keys import Cols, ConstantsClass from alphastats.utils import ignore_warning -class PreprocessingStateKeys: +class PreprocessingStateKeys(metaclass=ConstantsClass): """Keys for accessing the dictionary holding the information about preprocessing.""" # TODO disentangle these keys from the human-readably display strings diff --git a/alphastats/gui/pages/04_Analysis.py b/alphastats/gui/pages/04_Analysis.py index e1a0990c..75e8bc33 100644 --- a/alphastats/gui/pages/04_Analysis.py +++ b/alphastats/gui/pages/04_Analysis.py @@ -4,7 +4,7 @@ from alphastats.gui.utils.analysis_helper import ( display_df, display_plot, - do_analysis, + gather_parameters_and_do_analysis, ) from alphastats.gui.utils.ui_helper import ( StateKeys, @@ -51,29 +51,28 @@ method = st.selectbox( "Analysis", options=["" - group = st.selectbox( - "Grouping variable", - options=[default_option] + dataset.metadata.columns.to_list(), - ) - - if group != default_option: - unique_values = dataset.metadata[group].unique().tolist() - - group1 = st.selectbox("Group 1", options=unique_values) - - group2 = st.selectbox("Group 2", options=list(reversed(unique_values))) - - chosen_parameter_dict.update( - {"column": group, "group1": group1, "group2": group2} - ) - - if group1 == group2: - st.error( - "Group 1 and Group 2 can not be the same please select different group." - ) + return None, None, None else: - group1 = st.multiselect( - "Group 1 samples:", - options=dataset.metadata[Cols.SAMPLE].to_list(), - ) - - group2 = st.multiselect( - "Group 2 samples:", - options=list(reversed(dataset.metadata[Cols.SAMPLE].to_list())), - ) - - intersection_list = list(set(group1).intersection(set(group2))) - - if len(intersection_list) > 0: - st.warning( - "Group 1 and Group 2 contain same samples: " + str(intersection_list) - ) - - chosen_parameter_dict.update({"group1": group1, "group2": group2}) - - return chosen_parameter_dict + raise ValueError(f"Analysis method {analysis_name} not found.") diff --git a/alphastats/gui/utils/ui_helper.py b/alphastats/gui/utils/ui_helper.py index 23387c49..0db3bf51 100644 --- a/alphastats/gui/utils/ui_helper.py +++ b/alphastats/gui/utils/ui_helper.py @@ -6,6 +6,7 @@ from alphastats import __version__ from alphastats.gui.utils.preprocessing_helper import PREPROCESSING_STEPS +from alphastats.keys import ConstantsClass # TODO add logo above the options when issue is closed # https://github.com/streamlit/streamlit/issues/4984 @@ -101,7 +102,7 @@ def init_session_state() -> None: st.session_state[StateKeys.LLM_INTEGRATION] = {} -class StateKeys: +class StateKeys(metaclass=ConstantsClass): ## 02_Data Import # on 1st run ORGANISM = "organism" # TODO this is essentially a constant diff --git a/alphastats/keys.py b/alphastats/keys.py index f6b82429..4583cf03 100644 --- a/alphastats/keys.py +++ b/alphastats/keys.py @@ -1,11 +1,24 @@ """String constants for accessing columns.""" -class Cols: +class ConstantsClass(type): + """A metaclass for classes that should only contain string constants.""" + + def __setattr__(self, name, value): + raise TypeError("Constants class cannot be modified") + + def get_values(cls): + """Get all user-defined string values of the class.""" + return [ + value + for key, value in cls.__dict__.items() + if not key.startswith("__") and isinstance(value, str) + ] + + +class Cols(metaclass=ConstantsClass): """String constants for accessing columns of the main dataframe in DataSet.""" INDEX = "index_" - GENE_NAMES = "gene_names_" - SAMPLE = "sample_"