cellcharter.gr.aggregate_neighbors

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. If int, the output vector includes the cells’ features and the aggregated features of the neighbors until the layer at distance n_layers, i.e. cells | 1-hop neighbors | … | n_layers-hop. If list, 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 in anndata.AnnData.obsp where spatial connectivities are stored.

  • use_rep (Optional[str] (default: None)) – Key of the features. If None, 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 in anndata.AnnData.obs where the sample labels are stored. Must be different from None if adata contains multiple samples.

  • out_key (Optional[str] (default: 'X_cellcharter')) – Key in anndata.AnnData.obsm where the output matrix is stored if copy = False.

  • copy (bool (default: False)) – If True, return the result, otherwise save it to the adata object.

Return type:

ndarray | None

Returns:

If copy = True, returns a numpy.ndarray of the features aggregated and concatenated.

Otherwise, modifies the adata with the following key: