tacco.utils.merge_annotation¶
- merge_annotation(adata, annotation_key, mapping, result_key=None)[source]¶
Merges annotation into coarser groups, e.g. from subtypes to types.
- Parameters:
adata – An
AnnData
with annotation in .obs or .obsm. Can also be aDataFrame
, which is then treated like the .obs of anAnnData
.annotation_key – The .obs or .obsm key where the annotation and profiles are stored in adata. If the key is found in .obsm and .obs, the .obs key is used.
mapping – A mapping from coarse to a list-like of (or a single) fine annotation categories as
dict
,Series
, etc. or anything else with a .items method. The fine annotation categories which are not given coarse annotation categories are left unchanged.result_key – The where to store the resulting annotation. If the annotation_key is a .obs key, the result will be stored as .obs, if annotation_key is a .obsm key, it will be stored as .obsm. If None, do not write to adata and return the annotation instead.
- Returns:
Depending on result_key, either returns the original adata with annotation written in the corresponding .obs or .obsm key, or just the annotation as a new
Series
orDataFrame
.