tacco.utils.split_spatial_samples

split_spatial_samples(adata, buffer_thickness, position_key=('x', 'y'), split_direction=None, split_scheme=2, sample_key=None, result_key=None, check_splits=True)[source]

Splits a dataset into separated spatial patches. The patches are selected to have approximately equal amounts of observations per patch. Between the patches a buffer layer of specified thickness is discarded to reduce the correlations between the patches. Therefore the thickness should be chosen to accomodate the largest relevant correlation length.

Parameters:
  • adata – An AnnData with annotation in .obs (and .obsm). Can also be a DataFrame which is then used in place of .obs.

  • buffer_thickness – The thickness of the buffer layer to discard between the spatial patches. The units are the same as thosed used in the specification of the position information. This should be chosen carefully, as the remaining correlation between the spatial patches depends on it.

  • position_key – The .obsm key or array-like of .obs keys with the position space coordinates.

  • split_direction – The direction(s) to use for the spatial splits. Use e.g. (‘y’,’x’) for two splits with the first in ‘y’ and the second in ‘x’ direction, or ‘z’ to always split along the ‘z’ direction. Use None instead of the name of a coordinate direction to automatically determine the direction as a flavor of direction with largest extent (first principal axis).

  • split_scheme – The specification of the strategy used for defining spatial splits. In the simplest case this is just an integer specifying the number of patches per split. It can also be a tuple to specify a different number of patches per split.

  • sample_key – The .obs key with categorical sample information: every sample is split separately. Can also be a Series containing the sample information. If None, assume a single sample.

  • result_key – The .obs key to write the split sample annotation to. If None, returns the split sample annotation as Series.

  • check_splits – Whether to warn about unusual split properties

Returns:

Depending on result_key returns either a Series containing the split sample annotation or the input adata with the split sample annotation written to adata.obs[result_key].