from spidepy import build_niches, merge_niches
from spidepy.datasets import toy_spide
adata = build_niches(toy_spide(), sigma=30)
adata = merge_niches(adata, {"AB": ["A", "B"]}, sigma=30)
adata.obsm["Niche30"].columns.tolist()['AB', 'C']
Merge niche cell-type columns into groups by summing them (R mergeNiches).
Cell types not named in groups are kept as their own (singleton) niche. The group membership, composed through earlier merges so that it always resolves to the original fine cell types, is recorded in adata.uns["spiDE_niche_groups"][key] for each niche matrix.
| Name | Type | Description | Default |
|---|---|---|---|
| adata | AnnData | With niche matrices (see build_niches). |
required |
| groups | dict of str to sequence of str | Merged niche name -> cell-type columns to sum. | required |
| sigma | float or sequence of float | Bandwidths to update; None (the default) updates every obsm key starting with name (R greps ^name, so this also catches keys such as "NicheFoo"). |
None |
| name | str | Key prefix of the niche matrices. | "Niche" |
| copy | bool | Return a modified copy instead of modifying adata in place. |
False |
| Name | Type | Description |
|---|---|---|
| anndata.AnnData | adata (or its copy) with the merged niche matrices. |
build_niches : Build the niche matrices that are merged here.
['AB', 'C']