rapids_singlecell.gr.neighbors.GraphBuilder#

class rapids_singlecell.gr.neighbors.GraphBuilder[CoordT, GraphMatrixT](transform=None, set_diag=False, percentile=None, postprocessors=())[source]#

Base class for spatial graph construction strategies.

Implement build_graph() and uns_params(); build() applies the postprocessors in order. Override combine() to support libraries.

Parameters:
transform str | None (default: None)

Transform setting stored on the builder: None, "spectral", or "cosine". Subclasses or postprocessors implement its effect.

set_diag bool (default: False)

Diagonal setting stored on the builder for use by subclasses.

percentile float | None (default: None)

Distance percentile setting stored on the builder for use by subclasses or postprocessors. None disables percentile pruning.

postprocessors Sequence[Callable[[GraphMatrixT, GraphMatrixT], tuple[GraphMatrixT, GraphMatrixT]]] (default: ())

Ordered callables taking connectivity and distance matrices and returning the processed pair. Custom builders control which steps are applied.

Methods table#

build(coords)

Construct a graph and apply its postprocessors.

build_graph(coords)

Construct raw adjacency and distance matrices.

combine(mats, ixs)

Combine per-library graphs in original observation order.

postprocessors()

Return processing steps for the raw adjacency and distances.

uns_params()

Return graph parameters to store in adata.uns.

Methods#

build(coords)[source]#

Construct a graph and apply its postprocessors.

Parameters:
coords CoordT

Spatial coordinates accepted by the builder. CSR builders accept a dense array of shape (n_obs, n_dims), converted to finite float32.

Return type:

tuple[GraphMatrixT, GraphMatrixT]

Returns:

connectivities, distances Graph matrices in observation order; CSR builders return CuPy CSR.

abstractmethod build_graph(coords)[source]#

Construct raw adjacency and distance matrices.

Parameters:
coords CoordT

Coordinates in the format supported by this builder.

Return type:

tuple[GraphMatrixT, GraphMatrixT]

Returns:

connectivities, distances Raw graph matrices before postprocessing.

combine(mats, ixs)[source]#

Combine per-library graphs in original observation order.

Parameters:
mats Sequence[tuple[GraphMatrixT, GraphMatrixT]]

Connectivity/distance pairs for each library.

ixs Sequence[int]

Original observation indices in concatenated library order.

Return type:

tuple[GraphMatrixT, GraphMatrixT]

Returns:

connectivities, distances Combined matrices reordered to match the input observations.

postprocessors()[source]#

Return processing steps for the raw adjacency and distances.

Return type:

Sequence[Callable[[GraphMatrixT, GraphMatrixT], tuple[GraphMatrixT, GraphMatrixT]]]

Returns:

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

abstractmethod uns_params()[source]#

Return graph parameters to store in adata.uns.

Return type:

dict[str, Any]

Returns:

dict Serializable graph-construction parameters.