bioalpha.singlecell.preprocessing.combine_keys

bioalpha.singlecell.preprocessing.combine_keys(adata: AnnData, keys: Sequence[str], key_added: str | None = None, combine_fn: Callable[[Sequence[str]], str] | None = None, inplace=True, copy=False) Series | AnnData | None

Combine keys in adata.obs. This implementation using pandas.DataFrame.apply.

Parameters:
  • adata (AnnData) – The annotated data matrix of shape n_obs x n_vars. Rows correspond to cells and columns to genes.

  • keys (Sequence[str]) – Keys to be combined. All of keys must be in adata.obs.

  • key_added (Optional[str], default = None) – Key to be saved if inplace = True. If None, automatically set to "combine(', '.join(keys))"

  • combine_fn (Optional[(Sequence[str]) -> str], default = None.) – Combine function. default is "-".join.

  • inplace (bool, default = True) – Whether to update adata or return series of combined keys.

  • copy (bool, default = False) – Whether to modify copied input object. Not compatible with inplace = False.

Returns:

  • combined_keys (Series) – If inplace = False

  • adata (AnnData) – If copy=True it returns or else adds fields to adata:

    • .obsm[key_added] The combined keys.