scirpy.tl.group_abundance

scirpy.tl.group_abundance#

scirpy.tl.group_abundance(adata, groupby, target_col='has_ir', *, fraction=None, sort='count')#

Summarizes the number/fraction of cells of a certain category by a certain group.

Ignores NaN values.

Parameters:
  • adata (Union[AnnData, MuData]) – AnnData object to work on.

  • groupby (str) – Group by this column from obs. E.g, sample, or group.

  • target_col (str (default: 'has_ir')) – Caregorical variable from obs according to which the abundance/fractions will be computed. This defaults to “has_ir”, simply counting the number of cells with a detected IR by group.

  • fraction (Union[str, bool, None] (default: None)) – If True, compute fractions of abundances relative to the groupby column rather than reporting abosolute numbers. Alternatively, a column name can be provided according to that the values will be normalized.

  • sort (Union[Literal['count', 'alphabetical'], Sequence[str]] (default: 'count')) – How to arrange the dataframe columns. Default is by the category count (“count”). Other options are “alphabetical” or to provide a list of column names. By providing an explicit list, the DataFrame can also be subsetted to specific categories.

Return type:

DataFrame

Returns:

Returns a data frame with the number (or fraction) of cells per group.