API

Import Squidpy as:

import squidpy as sq

Graph

gr.spatial_neighbors(adata, *[, ...])

Create a graph from spatial coordinates.

gr.spatial_neighbors_from_builder(data, *, ...)

Create a graph from spatial coordinates using an explicit builder instance.

gr.spatial_neighbors_knn(data, *[, ...])

Create a k-nearest-neighbor graph from spatial coordinates.

gr.spatial_neighbors_radius(data, *, radius)

Create a radius-based graph from spatial coordinates.

gr.spatial_neighbors_delaunay(data, *[, ...])

Create a Delaunay triangulation graph from spatial coordinates.

gr.spatial_neighbors_grid(data, *[, ...])

Create a grid-based graph from spatial coordinates.

gr.GraphMatrixT

Type variable.

gr.SpatialNeighborsResult(connectivities, ...)

Result of spatial_neighbors function.

gr.mask_graph(sdata, *, table_key, polygon_mask)

Mask the graph based on a polygon mask.

gr.nhood_enrichment(adata, *, cluster_key[, ...])

Compute neighborhood enrichment by permutation test.

gr.NhoodEnrichmentResult(zscore, counts[, ...])

Result of nhood_enrichment function.

gr.co_occurrence(adata, *, cluster_key[, ...])

Compute co-occurrence probability of clusters.

gr.centrality_scores(adata, *, cluster_key)

Compute centrality scores per cluster or cell type.

gr.interaction_matrix(adata, *, cluster_key)

Compute interaction matrix for clusters.

gr.ripley(adata, *, cluster_key[, mode, ...])

Calculate various Ripley's statistics for point processes.

gr.ligrec(adata, *, cluster_key[, ...])

Perform the permutation test as described in [Efremova et al., 2020].

gr.spatial_autocorr(adata, *[, ...])

Calculate Global Autocorrelation Statistic (Moran’s I or Geary's C).

gr.sepal(adata, *, max_neighs[, genes, ...])

Identify spatially variable genes with Sepal.

gr.calculate_niche(data, flavor[, ...])

Calculate niches (spatial clusters) based on a user-defined method in 'flavor'.

gr.calculate_niche_neighborhood(data, *, ...)

Compute spatial niches from local cell-type composition.

gr.calculate_niche_utag(data, *, resolutions)

Compute spatial niches from UTAG-style feature aggregation.

gr.calculate_niche_cellcharter(data, *[, ...])

Compute spatial niches using a CellCharter-style embedding and GMM [Varrone et al., 2023].

gr.calculate_niche_spatialleiden(data, *, ...)

Compute niche assignments using the SpatialLeiden algorithm.

Image

im.process(img, *[, layer, library_id, ...])

Process an image by applying a transformation.

im.segment(img[, layer, library_id, method, ...])

Segment an image.

im.calculate_image_features(adata, *, img[, ...])

Calculate image features for all observations in adata.

im.SegmentationModel(model)

Base class for all segmentation models.

Plotting

pl.spatial_scatter(adata, *[, shape])

Plot spatial omics data with data overlayed on top.

pl.spatial_segment(adata, *, seg_cell_id[, ...])

Plot spatial omics data with segmentation masks on top.

pl.nhood_enrichment(adata, *, cluster_key[, ...])

Plot neighborhood enrichment.

pl.nhood_enrichment_dotplot(adata, *, ...[, ...])

Dot plot of neighborhood enrichment.

pl.centrality_scores(adata, *, cluster_key)

Plot centrality scores.

pl.interaction_matrix(adata, *, cluster_key)

Plot cluster interaction matrix.

pl.ligrec(adata, *[, cluster_key, ...])

Plot the result of a receptor-ligand permutation test.

pl.ripley(adata, *, cluster_key[, mode, ...])

Plot Ripley's statistics for each cluster.

pl.co_occurrence(adata, *, cluster_key[, ...])

Plot co-occurrence probability ratio for each cluster.

pl.extract(adata, *[, obsm_key, prefix])

Create a temporary anndata.AnnData object for plotting.

pl.var_by_distance(adata, *, var, anchor_key)

Plot a variable using a smooth regression line with increasing distance to an anchor point.

Reading

read.visium(path, *[, counts_file, ...])

Read 10x Genomics Visium formatted dataset.

read.vizgen(path, *, counts_file, meta_file)

Read Vizgen formatted dataset.

read.nanostring(path, *, counts_file, meta_file)

Read Nanostring formatted dataset.

Tools

tl.sliding_window(adata, *[, library_key, ...])

Divide a tissue slice into regulary shaped spatially contiguous regions (windows).

tl.var_by_distance(adata, *, groups[, ...])

Build a design matrix consisting of distance measurements to selected anchor point(s) for each observation.

Datasets

datasets.four_i([path])

Pre-processed subset 4i dataset from Gut et al.

datasets.imc([path])

Pre-processed subset IMC dataset from Jackson et al.

datasets.seqfish([path])

Pre-processed subset seqFISH dataset from Lohoff et al.

datasets.merfish([path])

Pre-processed MERFISH dataset from Moffitt et al.

datasets.mibitof([path])

Pre-processed MIBI-TOF dataset from Hartmann et al.

datasets.slideseqv2([path])

Pre-processed SlideseqV2 dataset from Stickles et al.

datasets.sc_mouse_cortex([path])

Pre-processed scRNA-seq mouse cortex.

datasets.visium(sample_id, *[, ...])

Download Visium datasets from 10x Genomics.

datasets.visium_hne_adata([path])

Pre-processed 10x Genomics Visium H&E dataset.

datasets.visium_hne_adata_crop([path])

Pre-processed subset 10x Genomics Visium H&E dataset.

datasets.visium_fluo_adata([path])

Pre-processed 10x Genomics Visium Fluorescent dataset.

datasets.visium_fluo_adata_crop([path])

Pre-processed subset 10x Genomics Visium Fluorescent dataset.

datasets.visium_hne_image([path])

H&E image from 10x Genomics Visium dataset.

datasets.visium_hne_image_crop([path])

Cropped H&E image from 10x Genomics Visium dataset.

datasets.visium_fluo_image_crop([path])

Cropped Fluorescent image from 10x Genomics Visium dataset.

Extensibility

See the extensibility guide for how to implement a custom graph builder.

gr.neighbors.GraphBuilder([transform, ...])

Base class for spatial graph construction strategies.

gr.neighbors.GraphBuilderCSR([transform, ...])

CSR-based graph construction strategy.

gr.neighbors.GraphMatrixT

Type variable.

gr.neighbors.GraphPostprocessor

gr.neighbors.DistanceIntervalPostprocessor(...)

gr.neighbors.PercentilePostprocessor(percentile)

gr.neighbors.TransformPostprocessor(transform)

gr.neighbors.KNNBuilder([n_neighs, ...])

Build a generic k-nearest-neighbor spatial graph.

gr.neighbors.RadiusBuilder(radius[, ...])

Build a generic radius-based spatial graph.

gr.neighbors.DelaunayBuilder([radius, ...])

Build a generic point-cloud graph from a Delaunay triangulation.

gr.neighbors.GridBuilder([n_neighs, ...])

Build a grid-based spatial graph.

Experimental

experimental.im.calculate_image_features(...)

Calculate per-cell features from segmentation masks.

experimental.tl.calculate_tiling_qc(sdata, ...)

Score cells for tile-boundary segmentation artifacts.

experimental.tl.assign_stitch_groups(sdata, ...)

Assign tile-cut cell pieces to stitch groups.

experimental.tl.make_stitched_labels(sdata, ...)

Materialise a stitched labels element from an assign_stitch_groups result.

experimental.pl.tiling_qc(sdata, *, labels_key)

Plot labels coloured by their tiling-artifact score.

experimental.im.fit_stain_reference(sdata, ...)

Fit a stain reference from an image in a SpatialData object.

experimental.im.estimate_white_point(sdata, ...)

Estimate the white point I_0 from a slide's background (non-tissue median).

experimental.im.StainFit(method[, ...])

A fitted stain reference.

Types

The public parameter bags, all TypedDicts: pass a plain dict literal or build one with the class. Every key is optional and falls back to the default shown with it.

Parameter types and their defaults.

class squidpy.types.FelzenszwalbParams[source]

Size-aware superpixel defaults for felzenszwalb segmentation.

A TypedDict: pass a plain dict with any subset of these keys.

grid_cols: int

Target superpixel grid columns.

Default: 100

grid_rows: int

Target superpixel grid rows.

Default: 100

min_size_coef: float

min_size = coef * target_area.

Default: 0.2

scale_coef: float

scale = coef * target_area.

Default: 0.25

sigma_frac: float

Blur = this * short side, clipped to [1, 5] px.

Default: 0.008

class squidpy.types.MacenkoParams[source]

Tuning knobs for Macenko stain-matrix fitting.

A TypedDict: pass a plain dict with any subset of these keys.

alpha: float

Angular percentile (deg) for the two stain directions; the extremes are taken at alpha / 100 - alpha.

Default: 1.0

beta: float

Mean-absorbance cutoff selecting tissue pixels (optical-density space).

Default: 0.15

class squidpy.types.ReinhardParams[source]

Tuning knobs for Reinhard stain normalization.

A TypedDict: pass a plain dict with any subset of these keys.

luminosity_threshold: float

Normalised Ruderman Lab-L cutoff in (0, 1]; pixels brighter than this are treated as near-white background and excluded from the fit. Follows HistomicsTK’s reinhard, so thresholds from the H&E literature transfer directly.

Default: 0.8

mask_background: bool

If True, fit channel statistics over tissue pixels only; if False, use every pixel (vanilla Reinhard).

Default: True

class squidpy.types.VahadaneParams[source]

Tuning knobs for Vahadane (sparse-NMF) stain-matrix fitting.

A TypedDict: pass a plain dict with any subset of these keys.

beta: float

Mean-absorbance cutoff selecting tissue pixels (optical-density space).

Default: 0.15

lambda1: float

L1 sparsity regularisation on the concentration factor of the NMF.

Default: 0.1

n_iter: int

Maximum NMF iterations.

Default: 200

rng: int | integer | Sequence[int] | SeedSequence | Generator | BitGenerator | None

Source of randomness for NMF initialisation tie-breaking; None draws from OS entropy.

Default: None

class squidpy.types.WekaParams[source]

Parameters for WEKA-like trainable segmentation.

A TypedDict: pass a plain dict with any subset of these keys.

edges: bool

Include edge features.

Default: True

pseudo_min_pixels: int

Minimum number of tissue pixels to seed.

Default: 50

pseudo_tissue_percentile: float

Percentile of distance-from-bg to label as tissue.

Default: 90.0

refine_bg_prob_threshold: float

Only drop pixels whose background probability exceeds this.

Default: 0.6

refine_n_samples_per_class: int

Training samples drawn per class in the refinement step.

Default: 50000

refine_with_classifier: bool

Run the second-stage background refinement.

Default: True

rf_estimators: int

Number of trees in the random forest.

Default: 100

rf_max_depth: int | None

Maximum tree depth; None for unlimited.

Default: 10

rf_max_samples: float

Fraction of samples drawn to train each tree.

Default: 0.05

rng: int | integer | Sequence[int] | SeedSequence | Generator | BitGenerator | None

Source of randomness; None draws from OS entropy.

Default: None

sigma_max: float

Largest scale in the multiscale feature bank.

Default: 16.0

sigma_min: float

Smallest scale in the multiscale feature bank.

Default: 1.0