netmap.masking.internal.get_neighborhood_expression¶
- netmap.masking.internal.get_neighborhood_expression(adata, knn_neighbours=10, required_neighbours=1, expression_threshold=0, layer='X')[source]¶
Checks if each gene is expressed in the k-nearest neighbors (kNN) of each cell.
Computes a kNN graph on adata, then for each cell counts how many neighbours express each gene above expression_threshold. Returns a binary matrix where 1 indicates the gene is expressed in at least required_neighbours neighbours.
- Parameters:
adata (anndata.AnnData) – Expression AnnData with PCA in
obsm['X_pca']. A kNN graph is computed internally viasc.pp.neighbors.knn_neighbours (int) – Number of nearest neighbours for the kNN graph. Defaults to 10.
required_neighbours (int) – Minimum number of neighbours that must express a gene for the cell to be considered in the neighbourhood. Defaults to 1.
expression_threshold (float) – Minimum value to consider a gene expressed. Defaults to 0.
layer (str) – Layer to use for expression values —
'X'or a named layer. Defaults to'X'.
- Returns:
- Binary matrix of shape
(n_cells, n_genes)where 1 means the gene is expressed in at leastrequired_neighboursneighbours.
- Return type:
scipy.sparse matrix or numpy.ndarray