diff --git a/alphastats/gui/pages/04_Analysis.py b/alphastats/gui/pages/04_Analysis.py index 2bcacbba..e1a0990c 100644 --- a/alphastats/gui/pages/04_Analysis.py +++ b/alphastats/gui/pages/04_Analysis.py @@ -6,9 +6,6 @@ display_plot, do_analysis, ) -from alphastats.gui.utils.options import ( - get_statistic_options, -) from alphastats.gui.utils.ui_helper import ( StateKeys, convert_df, @@ -35,6 +32,8 @@ """ st.markdown(styl, unsafe_allow_html=True) +# TODO put everything in the session state for a given parameter set? +# or is caching functionality the way to go here? if StateKeys.DATASET not in st.session_state: st.info("Import Data first") @@ -55,12 +54,7 @@ + ["------- plots -------"] + plotting_options + ["------- statistics -------"] - + statistic_options - + [ - k - for k in get_statistic_options(st.session_state) - if k not in statistic_options - ], + + statistic_options, ) if method in plotting_options: @@ -69,14 +63,10 @@ ) show_plot = analysis_result is not None - elif ( - method - in list((options := get_statistic_options(st.session_state)).keys()) - + statistic_options - ): + elif method in statistic_options: analysis_result, *_ = do_analysis( method, - options_dict=options, + options_dict=None, ) show_df = analysis_result is not None diff --git a/alphastats/gui/utils/analysis.py b/alphastats/gui/utils/analysis.py index 78c6a5a4..89450986 100644 --- a/alphastats/gui/utils/analysis.py +++ b/alphastats/gui/utils/analysis.py @@ -40,6 +40,8 @@ class PlottingOptions(metaclass=ConstantsClass): class StatisticOptions(metaclass=ConstantsClass): DIFFERENTIAL_EXPRESSION = "Differential Expression Analysis" TUKEY_TEST = "Tukey-Test" + ANOVA = "ANOVA" + ANCOVA = "ANCOVA" class Analysis(ABC): @@ -384,3 +386,67 @@ def _do_analysis(self): group=self._parameters["group"], ) return tukey_test_analysis, None, self._parameters + + +class AnovaAnalysis(GroupCompareAnalysis): + """Widget for ANOVA analysis.""" + + def show_widget(self): + """Show the widget and gather parameters.""" + + column = st.selectbox( + "A variable from the metadata to calculate ANOVA", + options=self._dataset.metadata.columns.to_list(), + ) + protein_ids = st.selectbox( + "All ProteinIDs/or specific ProteinID to perform ANOVA", + options=["all"] + self._dataset.mat.columns.to_list(), + ) + + tukey = st.checkbox("Follow-up Tukey") + + self._parameters.update( + {"column": column, "protein_ids": protein_ids, "tukey": tukey} + ) + + def _do_analysis(self): + """Perform Anova analysis.""" + anova_analysis = self._dataset.anova( + column=self._parameters["column"], + protein_ids=self._parameters["protein_ids"], + tukey=self._parameters["tukey"], + ) + return anova_analysis, None, self._parameters + + +class AncovaAnalysis(Analysis): + """Widget for Ancova analysis.""" + + def show_widget(self): + """Show the widget and gather parameters.""" + + protein_id = st.selectbox( + "ProteinID/ProteinGroup", + options=self._dataset.mat.columns.to_list(), + ) + covar = st.selectbox( + "Name(s) of column(s) in metadata with the covariate.", + options=self._dataset.metadata.columns.to_list(), + ) # TODO: why plural if only one can be selected? + between = st.selectbox( + "Name of the column in the metadata with the between factor.", + options=self._dataset.metadata.columns.to_list(), + ) + + self._parameters.update( + {"protein_id": protein_id, "covar": covar, "between": between} + ) + + def _do_analysis(self): + """Perform ANCOVA analysis.""" + ancova_analysis = self._dataset.ancova( + protein_id=self._parameters["protein_id"], + covar=self._parameters["covar"], + between=self._parameters["between"], + ) + return ancova_analysis, None, self._parameters diff --git a/alphastats/gui/utils/analysis_helper.py b/alphastats/gui/utils/analysis_helper.py index 0952224e..aa2597f2 100644 --- a/alphastats/gui/utils/analysis_helper.py +++ b/alphastats/gui/utils/analysis_helper.py @@ -5,6 +5,8 @@ import streamlit as st from alphastats.gui.utils.analysis import ( + AncovaAnalysis, + AnovaAnalysis, ClustermapAnalysis, DifferentialExpressionAnalysis, IntensityPlot, @@ -152,6 +154,8 @@ def do_analysis( # "Dendrogram": dataet.plot_dendrogram}, # TODO this was commented out in the original code? StatisticOptions.DIFFERENTIAL_EXPRESSION: DifferentialExpressionAnalysis, StatisticOptions.TUKEY_TEST: TukeyTestAnalysis, + StatisticOptions.ANOVA: AnovaAnalysis, + StatisticOptions.ANCOVA: AncovaAnalysis, } if (analysis_class := options.get(method)) is not None: diff --git a/alphastats/gui/utils/options.py b/alphastats/gui/utils/options.py index c43567e4..47150480 100644 --- a/alphastats/gui/utils/options.py +++ b/alphastats/gui/utils/options.py @@ -1,5 +1,4 @@ from alphastats import SpectronautLoader -from alphastats.gui.utils.ui_helper import StateKeys from alphastats.loader.AlphaPeptLoader import AlphaPeptLoader from alphastats.loader.DIANNLoader import DIANNLoader from alphastats.loader.FragPipeLoader import FragPipeLoader @@ -7,46 +6,6 @@ from alphastats.loader.MaxQuantLoader import MaxQuantLoader from alphastats.loader.mzTabLoader import mzTabLoader - -def get_statistic_options(state): - dataset = state[StateKeys.DATASET] - metadata_options = dataset.metadata.columns.to_list() - statistic_options = { - "ANOVA": { - "settings": { - "column": { - "options": metadata_options, - "label": "A variable from the metadata to calculate ANOVA", - }, - "protein_ids": { - "options": ["all"] + dataset.mat.columns.to_list(), - "label": "All ProteinIDs/or specific ProteinID to perform ANOVA", - }, - "tukey": {"label": "Follow-up Tukey"}, - }, - "function": dataset.anova, - }, - "ANCOVA": { - "settings": { - "protein_id": { - "options": [None] + dataset.mat.columns.to_list(), - "label": "Color according to", - }, - "covar": { - "options": metadata_options, - "label": "Name(s) of column(s) in metadata with the covariate.", - }, - "between": { - "options": metadata_options, - "label": "Name of the column in the metadata with the between factor.", - }, - }, - "function": dataset.ancova, - }, - } - return statistic_options - - SOFTWARE_OPTIONS = { "MaxQuant": { "import_file": "Please upload proteinGroups.txt",