SpatialDE.tissue_segmentation

SpatialDE.tissue_segmentation(adata, layer=None, genes=None, sizefactors=None, spatial_key='spatial', params=TissueSegmentationParameters(), labels=None, rng=np.random.default_rng(), copy=False)

Segment a spatial transcriptomics dataset into distinct spatial regions.

Uses a hidden Markov random field (HMRF) model with a Poisson likelihood. A Dirichlet process prior allows to automatically determine the number of distinct regions in the dataset.

Parameters:
  • adata (AnnData) – The annotated data matrix.

  • layer (Optional[str]) – Name of the AnnData object layer to use. By default adata.X is used.

  • genes (Optional[List[str]]) – List of genes to base the segmentation on. Defaults to all genes.

  • sizefactors (Optional[ndarray]) – Scaling factors for the observations. Defaults to total read counts.

  • spatial_key (str) – Key in adata.obsm where the spatial coordinates are stored.

  • params (TissueSegmentationParameters) – Parameters for the algorithm, e.g. prior distributions, spatial smoothness, etc.

  • labels (Union[ndarray, Tensor, None]) – Initial label for each observation. Defaults to a random initialization.

  • rng (Generator) – Random number generator.

  • copy – Whether to return a copy of adata with results or write the results into adata in-place.

Return type:

Tuple[TissueSegmentation, Optional[AnnData]]

Returns:

A tuple. The first element is a TissueSegmentation, the second is None if copy == False or an AnnData object. Region labels will be in adata.obs["segmentation_labels"] and region probabilities in adata.obsm["segmentation_class_probabilities"].