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.obspwhere 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.obswhere the sample labels are stored. Must be different fromNoneif adata contains multiple samples.out_key (
Optional[str] (default:'X_cellcharter')) – Key inanndata.AnnData.obsmwhere the output matrix is stored ifcopy = False.copy (
bool(default:False)) – IfTrue, return the result, otherwise save it to theadataobject.
- Return type:
- Returns:
If
copy = True, returns anumpy.ndarrayof the features aggregated and concatenated.- Otherwise, modifies the
adatawith the following key: anndata.AnnData.obsm['{{out_key}}']- the above mentionednumpy.ndarray.
- Otherwise, modifies the