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 defaultadata.Xis 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 inadata.obsmwhere 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
adatawith results or write the results intoadatain-place.
- Return type:
Tuple[TissueSegmentation,Optional[AnnData]]- Returns:
A tuple. The first element is a
TissueSegmentation, the second isNoneifcopy == Falseor anAnnDataobject. Region labels will be inadata.obs["segmentation_labels"]and region probabilities inadata.obsm["segmentation_class_probabilities"].