spac.transformations.rename_annotations(adata, src_annotation, dest_annotation, mappings)[source]

Rename labels in a given annotation in an AnnData object based on a provided dictionary. This function modifies the adata object in-place and creates a new annotation column.

Parameters:
  • adata (anndata.AnnData) – The AnnData object.

  • src_annotation (str) – Name of the column in adata.obs containing the original labels of the source annotation.

  • dest_annotation (str) – The name of the new column to be created in the AnnData object containing the renamed labels.

  • mappings (dict) – A dictionary mapping the original annotation labels to the new labels.

Examples

>>> adata = your_anndata_object
>>> src_annotation = "phenograph"
>>> mappings = {
...     "0": "group_8",
...     "1": "group_2",
...     "2": "group_6",
...     # ...
...     "37": "group_5",
... }
>>> dest_annotation = "renamed_annotations"
>>> adata = rename_annotations(
...     adata, src_annotation, dest_annotation, mappings)