grassp.tl.calculate_cluster_enrichment

grassp.tl.calculate_cluster_enrichment#

calculate_cluster_enrichment(data, cluster_key='leiden', gene_name_key='Gene_name_canonical', gene_sets=None, obs_key_added='Cell_compartment', enrichment_ranking_metric='Adjusted P-value Bonferroni', enrichment_threshold=0.05, species='hsap', deduplicate_terms=True, return_enrichment_res=True, inplace=True)[source]#

Gene-set enrichment for each cluster.

For every category in data.obs[cluster_key] the function performs an Enrichr analysis via gseapy using the list of proteins (genes) present in that cluster. The most significant term (according to enrichment_ranking_metric) is written back to data.obs under obs_key_added.

Parameters:
data AnnData

Input AnnData with proteins as observations.

cluster_key str (default: 'leiden')

Categorical column in data.obs containing cluster labels.

gene_name_key str (default: 'Gene_name_canonical')

Column in data.obs that holds gene symbols – required by gseapy.

gene_sets str | None (default: None)

Path to a Gene set database to use for enrichment analysis in .gmt format If None, enrichment is performed against the uniprot subcellular compartment annotations. We have found that this is a good default and tends to be less noisy than GO CC.

obs_key_added str (default: 'Cell_compartment')

Name of the column that will store the top enriched term per cluster.

enrichment_ranking_metric Literal['Adjusted P-value', 'Adjusted P-value Bonferroni', 'P-value', 'Odds Ratio', 'Combined Score'] (default: 'Adjusted P-value Bonferroni')

Column used to rank results within each cluster. Valid options are "Adjusted P-value", "P-value", "Odds Ratio" and "Combined Score".

enrichment_threshold float (default: 0.05)

Threshold for the enrichment ranking metric. Only terms with a ranking metric value less than or equal to this threshold are considered.

species Literal['hsap', 'mmus', 'scer'] (default: 'hsap')

Species code used to pick the default gene-set file when gene_sets is None. One of "hsap" (human, consolidated_goterms_human.gmt), "mmus" (mouse, consolidated_goterms_mouse.gmt), or "scer" (yeast, consolidated_goterms_yeast.gmt). Default "hsap". Ignored when an explicit gene_sets path is provided.

deduplicate_terms bool (default: True)

If True (default), collapse gene sets with identical membership to a single term (keeping the first-seen name) before enrichment.

return_enrichment_res bool (default: True)

If True return the full pandas.DataFrame of Enrichr results.

inplace bool (default: True)

If True (default) annotate data in place. Otherwise a modified copy is returned.

Return type:

Union[AnnData, DataFrame, None]

Returns:

Behaviour depends on inplace and return_enrichment_res:

  • inplace=True → annotate data; return the results

    DataFrame if return_enrichment_res else None.

  • inplace=False → return either a new AnnData

    or a (adata, results) tuple.