quadsv.detectors.base#

Shared base class for single-sample spatial pattern detectors.

Concrete detectors follow a three-step workflow:

  1. ConstructionDetector.__init__() takes kernel method + backend configs + kernel hyperparameters. No data is attached.

  2. Data setupDetector.setup_data() takes the input container (anndata.AnnData for DetectorIrregular, spatialdata.SpatialData for DetectorGrid), performs preprocessing (feature filtering, coordinate / obsp extraction, or rasterization), and builds the kernel.

  3. ComputationDetector.compute_qstat() and Detector.compute_rstat() take feature selections + compute-time knobs (n_jobs, chunk_size, etc.) and return per-feature results.

The base class owns the attribute contract (kernel_method_, kernel_params_, kernel_, n, _data_ready) and enforces the workflow via _require_setup(). Concrete subclasses implement _merge_kernel_defaults(), setup_data(), compute_qstat(), and compute_rstat().

Classes#

Detector

Abstract base for single-sample pattern detectors.

Module Contents#

class quadsv.detectors.base.Detector(kernel_method, **kernel_params)[source]#

Bases: abc.ABC

Abstract base for single-sample pattern detectors.

Variables:
  • kernel_method_ (str) – Kernel method name (e.g. 'matern', 'car'). Set at construction.

  • kernel_params_ (dict) – Resolved kernel parameters after backend-specific defaults are merged with user overrides. Set at construction.

  • kernel_ (Kernel or None) – Kernel object built in setup_data(). None before data setup.

  • n (int or None) – Effective number of observations after preprocessing. None before data setup.

Parameters:
  • kernel_method (str)

  • kernel_params (Any)

abstract compute_qstat(features=None, **kwargs)[source]#

Univariate Q-test across features.

Parameters:
  • features (list[str] | None)

  • kwargs (Any)

Return type:

DataFrame

abstract compute_rstat(**kwargs)[source]#

Bivariate R-test. Signature / feature selection are subclass-specific.

Parameters:

kwargs (Any)

Return type:

DataFrame

abstract setup_data(data, **kwargs)[source]#

Attach data, preprocess features, and build kernel_.

Must set kernel_, n, and self._data_ready = True before returning self.

Parameters:
  • data (Any)

  • kwargs (Any)

Return type:

Detector

kernel_: quadsv.kernels.Kernel | None = None[source]#
kernel_method_: str[source]#
kernel_params_: dict[source]#
n: int | None = None[source]#