partipy.compute_meta_enrichment

partipy.compute_meta_enrichment#

partipy.compute_meta_enrichment(adata, meta_col, datatype='automatic', result_filters=None)#

Compute the enrichment of metadata categories across archetypes.

This function estimates how enriched each metadata category is within each archetype using a weighted average approach. Weights are based on each cell’s contribution to each archetype (adata.uns["AA_cell_weights"]). It supports both categorical and continuous metadata.

Steps for categorical data:
  1. One-hot encode the metadata column from adata.obs[meta_col].

  2. Normalize the metadata so that the sum for each category equals 1 (column-wise).

  3. Compute weighted enrichment using cell weights.

  4. Normalize the resulting enrichment scores across metadata categories for each archetype (row-wise).

Steps for continuous data:
  1. Compute the weighted average of the metadata per archetype.

Parameters:
  • adata (anndata.AnnData) – AnnData object with categorical metadata in adata.obs[meta_col] and archetype weights stored in adata.uns["AA_cell_weights"].

  • meta_col (str) – The name of the categorical metadata column in adata.obs to use for enrichment analysis.

  • datatype (str, default automatic) – Specifies how to interpret the metadata column: - “automatic”: infers type based on column dtype. - “categorical”: treats the column as categorical and one-hot encodes it. - “continuous”: treats the column as numeric and computes weighted averages.

  • result_filters (Mapping[str, Any] | None, default None) – Filters applied to ArchetypeConfig entries to select the optimization configuration whose weights should be used.

Return type:

DataFrame

Returns:

pd.DataFrame A DataFrame of shape (n_archetypes, n_categories) for categorical data or (n_archetypes, 1) for continuous data, containing normalized enrichment scores or weighted averages respectively.