cellcharter.gr.aggregate_neighbors#
- cellcharter.gr.aggregate_neighbors(adata, n_layers, aggregations='mean', connectivity_key=None, use_rep=None, sample_key=None, out_key='X_cellcharter', copy=False)#
Aggregate the features from each neighborhood layers and concatenate them, and optionally with the cells’ features, into a single vector.
- Parameters:
adata (
AnnData
) – Annotated data object.n_layers (
Union
[int
,list
]) – Which neighborhood layers to aggregate from. Ifint
, the output vector includes the cells’ features and the aggregated features of the neighbors until the layer at distancen_layers
, i.e. cells | 1-hop neighbors | … |n_layers
-hop. Iflist
, every element corresponds to the distances at which the neighbors’ features will be aggregated and concatenated. For example, [0, 1, 3] corresponds to cells|1-hop neighbors|3-hop neighbors.aggregations (
Union
[str
,list
,None
] (default:'mean'
)) – Which functions to use to aggregate the neighbors features. Default:`mean
.connectivity_key (
Optional
[str
] (default:None
)) – Key inanndata.AnnData.obsp
where spatial connectivities are stored.use_rep (
Optional
[str
] (default:None
)) – Key of the features. IfNone
, adata.X is used. Else, the key is used to access the field in the AnnData .obsm mapping.sample_key (
Optional
[str
] (default:None
)) – Key inanndata.AnnData.obs
where the sample labels are stored. Must be different fromNone
if adata contains multiple samples.out_key (
Optional
[str
] (default:'X_cellcharter'
)) – Key inanndata.AnnData.obsm
where the output matrix is stored ifcopy = False
.copy (
bool
(default:False
)) – IfTrue
, return the result, otherwise save it to theadata
object.
- Return type:
- Returns:
If
copy = True
, returns anumpy.ndarray
of the features aggregated and concatenated.- Otherwise, modifies the
adata
with the following key: anndata.AnnData.obsm
['{{out_key}}']
- the above mentionednumpy.ndarray
.
- Otherwise, modifies the