acore.differential_regulation.tests module#
All the tests for differential regulation. Functions used in the user facing function starting with run_.
- calc_means_between_groups(df: DataFrame, boolean_array: Series, event_names: tuple[str, str] = ('1', '0')) DataFrame[source]#
Mean comparison between groups
- calc_ttest(df: DataFrame, boolean_array: Series, variables: list[str]) DataFrame[source]#
Calculate t-test for each variable in variables between two groups defined by boolean array.
- calculate_ttest(df, condition1, condition2, paired=False, is_logged=True, non_par=False, tail='two-sided', correction='auto', r=0.707)[source]#
Calculates the t-test for the means of independent samples belonging to two different groups using scipy.stats.ttest_ind.
- Parameters:
df – pandas dataframe with groups and subjects as rows and protein identifier as column.
condition1 (str) – identifier of first group.
condition2 (str) – ientifier of second group.
is_logged (bool) – data is logged transformed
non_par (bool) – if True, normality and variance equality assumptions are checked and non-parametric test Mann Whitney U test if not passed
- Returns:
Tuple with t-statistics, two-tailed p-value, mean of first group, mean of second group and logfc.
Example:
result = calculate_ttest(df, 'group1', 'group2')
- calculate_thsd(df, column, group='group', alpha=0.05, is_logged=True)[source]#
Pairwise Tukey-HSD posthoc test using pingouin.pairwise_tukey.
- Parameters:
- Returns:
Pandas dataframe.
Example:
result = calculate_thsd(df, column='HBG2~P69892', group='group', alpha=0.05)
- calculate_pairwise_ttest(df, column, subject='subject', group='group', correction='none', is_logged=True)[source]#
Performs pairwise t-test using pingouin, as a posthoc test, and calculates fold-changes using pingouin.pairwise_ttests.
- Parameters:
df – pandas dataframe with subject and group as rows and protein identifier as column.
column (str) – column label containing the dependant variable
subject (str) – column label containing subject identifiers
group (str) – column label containing the between factor
correction (str) – method used for testing and adjustment of p-values.
- Returns:
Pandas dataframe with means, standard deviations, test-statistics, degrees of freedom and effect size columns.
Example:
result = calculate_pairwise_ttest(df, 'protein a', subject='subject', group='group', correction='none' )
- complement_posthoc(posthoc, identifier, is_logged)[source]#
Calculates fold-changes after posthoc test.
- Parameters:
posthoc – pandas dataframe from posthoc test. Should have at least columns ‘mean(group1)’ and ‘mean(group2)’.
identifier (str) – feature identifier.
- Returns:
Pandas dataframe with additional columns ‘identifier’, ‘log2FC’ and ‘FC’.
- calculate_ancova(data, column, group='group', covariates=[])[source]#
Calculates one-way ANCOVA using pingouin.
- calculate_repeated_measures_anova(df, column, subject='subject', within='group')[source]#
One-way and two-way repeated measures ANOVA using pingouin stats.
- Parameters:
df – pandas dataframe with samples as rows and protein identifier as column. Data must be in long-format for two-way repeated measures.
column (str) – column label containing the dependant variable
subject (str) – column label containing subject identifiers
within (str) – column label containing the within factor
- Returns:
Tuple with protein identifier, t-statistics and p-value.
Example:
result = calculate_repeated_measures_anova(df, 'protein a', subject='subject', within='group' )
- calculate_mixed_anova(df, column, subject='subject', within='group', between='group2')[source]#
One-way and two-way repeated measures ANOVA using pingouin stats.
- Parameters:
df – pandas dataframe with samples as rows and protein identifier as column. Data must be in long-format for two-way repeated measures.
column (str) – column label containing the dependant variable
subject (str) – column label containing subject identifiers
within (str) – column label containing the within factor
within – column label containing the between factor
- Returns:
Tuple with protein identifier, t-statistics and p-value.
Example:
result = calculate_mixed_anova(df, 'protein a', subject='subject', within='group', between='group2' )
- pairwise_ttest_with_covariates(df, column, group, covariates, is_logged)[source]#
Pairwise t-test with covariates using statsmodels.
- format_anova_table(df, aov_results, pairwise_results, pairwise_cols, group, permutations, alpha, correction)[source]#
Performs p-value correction (permutation-based and FDR) and converts pandas dataframe into final format.
- Parameters:
df – pandas dataframe with samples as rows and protein identifiers as columns (with additional columns ‘group’, ‘sample’ and ‘subject’).
aov_results (list[tuple]) – list of tuples with anova results (one tuple per feature).
pairwise_results (list[dataframes]) – list of pandas dataframes with posthoc tests results
group (str) – column with group identifiers
alpha (float) – error rate for multiple hypothesis correction
permutations (int) – number of permutations used to estimate false discovery rates
- Returns:
Pandas dataframe
- calculate_pvalue_from_tstats(tstat, dfn)[source]#
Calculate two-tailed p-values from T- or F-statistics.
tstat: T/F distribution dfn: degrees of freedrom n (values) per protein (keys),
i.e. number of obervations - number of groups (dict)