rapids_singlecell.gr.neighbors.GridBuilder#

class rapids_singlecell.gr.neighbors.GridBuilder(n_neighs=6, n_rings=1, delaunay=False, transform=None, set_diag=False)[source]#

Build a lattice graph whose distances count shortest directed grid hops.

Parameters:
n_neighs int (default: 6)

Number of nearest other observations. Must be smaller than the number of observations in each library when using a kNN base graph.

n_rings int (default: 1)

Number of grid hops to include. Distances count shortest directed hops.

delaunay bool (default: False)

Use Delaunay edges as the grid base instead of kNN edges filtered to distances below 1.3 times the per-library median.

transform str | None (default: None)

Connectivity transform: None, "spectral" (normalization by column degrees), or "cosine" (similarity between connectivity rows). Applied after pruning and adding the requested diagonal; distances are unchanged.

set_diag bool (default: False)

Whether to set connectivity self-loops before transforming the graph. Distance diagonals are zero; cosine can create connectivity self-loops even when this is False.

Methods table#

build(coords)

Validate coords and build the (adjacency, distances) graphs.

build_graph(coords[, codes])

Build the n_rings-hop grid graphs, independently within each library of codes.

combine(mats, ixs)

Stack per-library graphs block-diagonally, in the original observation order ixs.

postprocessors()

Return processing steps for the raw adjacency and distances.

uns_params()

Return graph parameters to store in adata.uns.

Methods#

build(coords)[source]#

Validate coords and build the (adjacency, distances) graphs.

Return type:

tuple[csr_matrix, csr_matrix]

build_graph(coords, codes=None)[source]#

Build the n_rings-hop grid graphs, independently within each library of codes.

combine(mats, ixs)[source]#

Stack per-library graphs block-diagonally, in the original observation order ixs.

Return type:

tuple[csr_matrix, csr_matrix]

postprocessors()[source]#

Return processing steps for the raw adjacency and distances.

Return type:

Sequence[Callable[[csr_matrix, csr_matrix], tuple[csr_matrix, csr_matrix]]]

Returns:

Sequence of callables Steps applied in order to the connectivity and distance matrices.

uns_params()[source]#

Return graph parameters to store in adata.uns.

Return type:

dict[str, Any]

Returns:

dict Serializable graph-construction parameters.