acore.enrichment_analysis package#
Enrichment Analysis Module. Contains different functions to perform enrichment analysis.
Most things in this module are covered in https://www.youtube.com/watch?v=2NC1QOXmc5o by Lars Juhl Jensen.
- run_site_regulation_enrichment(regulation_data: DataFrame, annotation: DataFrame, identifier: str = 'identifier', groups: list[str] = ('group1', 'group2'), annotation_col: str = 'annotation', rejected_col: str = 'rejected', group_col: str = 'group', method: str = 'fisher', regex: str = '(\\w+~.+)_\\w\\d+\\-\\w+', correction: str = 'fdr_bh', remove_duplicates: bool = False) DataFrame[EnrichmentAnalysisSchema][source]#
This function runs a simple enrichment analysis for significantly regulated protein sites in a dataset.
- Parameters:
regulation_data – pandas.DataFrame resulting from differential regulation analysis.
annotation – pandas.DataFrame with annotations for features (columns: ‘annotation’, ‘identifier’ (feature identifiers), and ‘source’).
identifier (str) – name of the column from annotation containing feature identifiers.
groups (list) – column names from regulation_data containing group identifiers.
annotation_col (str) – name of the column from annotation containing annotation terms.
rejected_col (str) – name of the column from regulation_data containing boolean for rejected null hypothesis.
group_col (str) – column name for new column in annotation dataframe determining if feature belongs to foreground or background.
method (str) – method used to compute enrichment (only ‘fisher’ is supported currently).
regex (str) – how to extract the annotated identifier from the site identifier
- Returns:
pandas.DataFrame with columns: ‘terms’, ‘identifiers’, ‘foreground’, ‘background’, foreground_pop, background_pop, ‘pvalue’, ‘padj’ and ‘rejected’.
- Raises:
ValueError – if regulation_data is None or empty.
Example:
result = run_site_regulation_enrichment(regulation_data, annotation, identifier='identifier', groups=['group1', 'group2'], annotation_col='annotation', rejected_col='rejected', group_col='group', method='fisher', match="(\\w+~.+)_\\w\\d+\\-\\w+" )
- run_up_down_regulation_enrichment(regulation_data: DataFrame, annotation: DataFrame, identifier: str = 'identifier', groups: list[str] = ('group1', 'group2'), annotation_col: str = 'annotation', pval_col: str = 'pval', group_col: str = 'group', log2fc_col: str = 'log2FC', method: str = 'fisher', min_detected_in_set: int = 2, correction: str = 'fdr_bh', correction_alpha: float = 0.05, lfc_cutoff: float = 1) DataFrame[EnrichmentAnalysisSchema][source]#
This function runs a simple enrichment analysis for significantly regulated proteins distinguishing between up- and down-regulated.
- Parameters:
regulation_data (pandas.DataFrame) – pandas.DataFrame resulting from differential regulation analysis (CKG’s regulation table).
annotation (pandas.DataFrame) – pandas.DataFrame with annotations for features (columns: ‘annotation’, ‘identifier’ (feature identifiers), and ‘source’).
identifier (str) – name of the column from annotation containing feature identifiers.
column names from regulation_data containing group identifiers. See pandas.DataFrame.groupby for more information.
annotation_col (str) – name of the column from annotation containing annotation terms.
rejected_col (str) – name of the column from regulation_data containing boolean for rejected null hypothesis.
group_col (str) – column name for new column in annotation dataframe determining if feature belongs to foreground or background.
method (str) – method used to compute enrichment (only ‘fisher’ is supported currently).
correction (str) – method to be used for multiple-testing correction
alpha (float) – adjusted p-value cutoff to define significance
lfc_cutoff (float) – log fold-change cutoff to define practical significance
- Returns:
DataFrame adhering to EnrichmentAnalysisSchema
- Return type:
DataFrame[EnrichmentAnalysisSchema]
Example:
result = run_up_down_regulation_enrichment( regulation_data, annotation, identifier='identifier', groups=['group1', 'group2'], annotation_col='annotation', rejected_col='rejected', group_col='group', method='fisher', correction='fdr_bh', alpha=0.05, lfc_cutoff=1, )
- run_fisher(group1: list[int], group2: list[int], alternative: str = 'two-sided') tuple[float, float][source]#
Run fisher’s exact test on two groups using scipy.stats.fisher_exact.
Example:
# annotated not-annotated # group1 a b # group2 c d odds, pvalue = stats.fisher_exact(group1=[a, b], group2 =[c, d] )
- run_kolmogorov_smirnov(dist1: list[float], dist2: list[float], alternative: str = 'two-sided') tuple[float, float][source]#
Compute the Kolmogorov-Smirnov statistic on 2 samples. See scipy.stats.ks_2samp
- Parameters:
dist1 (list) – sequence of 1-D ndarray (first distribution to compare) drawn from a continuous distribution
dist2 (list) – sequence of 1-D ndarray (second distribution to compare) drawn from a continuous distribution
alternative (str) – defines the alternative hypothesis (default is ‘two-sided’): * ‘two-sided’ * ‘less’ * ‘greater’
- Returns:
statistic float and KS statistic pvalue float Two-tailed p-value.
Example:
result = run_kolmogorov_smirnov(dist1, dist2, alternative='two-sided')