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 viagseapyusing the list of proteins (genes) present in that cluster. The most significant term (according toenrichment_ranking_metric) is written back todata.obsunderobs_key_added.- Parameters:
- data
AnnData Input
AnnDatawith proteins as observations.- cluster_key
str(default:'leiden') Categorical column in
data.obscontaining cluster labels.- gene_name_key
str(default:'Gene_name_canonical') Column in
data.obsthat 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_setsisNone. 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 explicitgene_setspath 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
Truereturn the fullpandas.DataFrameof Enrichr results.- inplace
bool(default:True) If
True(default) annotate data in place. Otherwise a modified copy is returned.
- data
- Return type:
- Returns:
Behaviour depends on
inplaceandreturn_enrichment_res:inplace=True→ annotate data; return the resultsDataFrame if
return_enrichment_reselseNone.
inplace=False→ return either a newAnnDataor a
(adata, results)tuple.