scmorph.pp.neighbors

Contents

scmorph.pp.neighbors#

scmorph.pp.neighbors(adata, n_neighbors=15, n_pcs=None, use_rep='X_pca', copy=False, **kwargs)[source]#

Compute a neighborhood graph of observations using the PCA representation.

This function wraps the higher-level function neighbors() ([Wolf et al., 2018].)

Parameters:
adata AnnData

AnnData object

n_neighbors int (default: 15)

The size of local neighborhood (in terms of number of neighboring data points) used for manifold approximation. Larger values result in more global views of the manifold, while smaller values result in more local data being preserved. In general values should be in the range 2 to 100. If knn is True, number of nearest neighbors to be searched. If knn is False, a Gaussian kernel width is set to the distance of the n_neighbors neighbor.

n_pcs int | None (default: None)

Use this many PCs. If n_pcs==0 use .X if use_rep is not None.

use_rep str (default: 'X_pca')

Use the indicated representation. ‘X’ or any key for .obsm is valid. If None, the representation is chosen automatically: For .n_vars < N_PCS, .X is used, otherwise X_pca is used. If X_pca is not present, it`s computed with default parameters or n_pcs if present.

copy bool (default: False)

Return a copy instead of writing to adata.

kwargs Any

Additional arguments passed to neighbors().

Return type:

AnnData | None

Returns:

Returns None if copy=False, else returns an AnnData object. Sets the following fields:

adata.obsp['distances' | key_added+'_distances']scipy.sparse.csr_matrix (dtype float)

Distance matrix of the nearest neighbors search. Each row (cell) has n_neighbors-1 non-zero entries. These are the distances to their n_neighbors-1 nearest neighbors (excluding the cell itself).

adata.obsp['connectivities' | key_added+'_connectivities']scipy.sparse._csr.csr_matrix (dtype float)

Weighted adjacency matrix of the neighborhood graph of data points. Weights should be interpreted as connectivities.

adata.uns['neighbors' | key_added]dict

neighbors parameters.