anndict.wrappers.create_label_hierarchy_adata_dict#
- anndict.wrappers.create_label_hierarchy_adata_dict(adata, col, simplification_levels)[source]#
Create a hierarchy of simplified labels based on a given column in AnnData.
This function generates multiple levels of simplified labels from a single column in
adata.obs
. Each successive level of simplification is created using the specified simplification level.- Parameters:
- adata
AnnData
Annotated data matrix containing the column to be simplified.
- col
str
Name of the column in
adata.obs
to be simplified.- simplification_levels
list
[str
] List of simplification levels to apply. Each level should be a value that can be used by the simplify_obs_column function.
- adata
- Return type:
dict
- Returns:
A
dict
mapping new column names to their corresponding simplified label mappings. The keys are the names of the new columns created for each simplification level, and the values are the mappings returned bysimplify_obs_column()
for each level.
Example
import anndict as adt print(adata.obs) > subtype > 0 cd8+ t cell > 1 cd4+ t cell > 2 venous endothelial cell > 3 arterial endothelial cell label_mapping = adt.create_label_hierarchy(adata, 'subtype', ['cell type level', 'cell class level', 'compartment level']) print(adata.obs) # New columns added > subtype subtype_cell_type_level subtype_cell_class_level subtype_compartment_level > 0 cd8+ t cell t cell lymphocyte immune > 1 cd4+ t cell t cell lymphocyte immune > 2 venous endothelial cell endothelial cell endothelial cell stromal > 3 arterial endothelial cell endothelial cell endothelial cell stromal