API

Spacemake class

Accessing spacemake objects from python

class spacemake.Spacemake(root)

Spacemake.

Class to access spacemake processed data from python.

load_processed_adata(project_id, sample_id, run_mode_name, umi_cutoff)anndata._core.anndata.AnnData

Load spacemake processed data.

Parameters:
  • project_id (str) – project_id of the data to be loaded.
  • sample_id (str) – sample_id of the data to be loaded.
  • run_mode_name (str) – name of the run mode of the data to be loaded. Each sample can have several run_modes during sample addition, here only one option needs to be provided.
  • umi_cutoff (int) – the umi_cutoff of the data to be loaded. Each run_mode can have several umi_cutoffs provided during configuration here only one option needs to be provided.
Returns:

A spacemake processed and analyzed AnnData object, containing the results of the analysis.

Return type:

anndata.AnnData

load_raw_spatial_adata(project_id, sample_id, run_mode_name)anndata._core.anndata.AnnData

Load raw, spacemake processed data.

This function will load the raw countr matrix, created by spacemake.

Parameters:
  • project_id (str) – project_id of the raw data to be loaded.
  • sample_id (str) – sample_id of the raw data to be loaded.
  • run_mode_name (str) – name of the run mode of the raw data to be loaded. Each sample can have several run_modes during sample addition, here only one option needs to be provided.
Returns:

A spacemake processed AnnData object, containing unfiltered raw expression data, and all cells or spatial units in the dataset.

Return type:

anndata.AnnData

H&E integration module

spacemake.spatial.he_integration.align_he_spot_img(adata: anndata._core.anndata.AnnData, he_path: str) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)

Align a H&E image with a spacemake processed data, based on spot expression.

Takes an H&E image and a spacemake processed dataset, and alignes the two, trying to find the most probably position of the spatial dataset within the H&E image. This function should be used for datasets with a spot_diameter_um higher than or equal to 10 microns, such as Visium or Slide-seq.

Parameters:
  • adata (anndata.AnnData) – A spacemake processed AnnData object.
  • he_path (str) – Path to the H&E image to be aligned.
Returns:

A tuple of (original_he, aligned_he). original_he will contain the original H&E data together with the aligned spots and a blue rectangle showing the aligned region. aligned_he will contain the part of the H&E image aligned.

Return type:

(numpy.ndarray, numpy.ndarray)

spacemake.spatial.he_integration.align_he_aggregated_img(adata: anndata._core.anndata.AnnData, he_path: str, bw_threshold: int = 200, binary_top_qth_percentile: int = 30, box_size: float = 0.5) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)

align_he_aggregated_img. Align a H&E image with a spacemake processed data, based on aggregated expression.

Takes an H&E image and a spacemake processed dataset, and alignes the two, trying to find the most probably position of the spatial dataset within the H&E image. First the spatial data will be aggregated in a 500 x 500 pixel image, then the best align between the spatial expression image and the H&E will be found. This function should be used for datasets with a spot_diameter_um smaller than 10 microns, such as Visium or Slide-seq.

Parameters:
  • adata (anndata.AnnData) – A spacemake processed AnnData object.
  • he_path (str) – Path to the H&E image to be aligned.
  • bw_threshold (int) –
  • binary_top_qth_percentile (int) –
  • box_size (float) – By default not the whole aggregated image will be aligned, only the middle part (a box with 50% x 50% pixels, wrt the original size). This parameter controls the size of the aligning box.
Returns:

A tuple of (original_he, aligned_he). original_he will contain the original H&E data together with the aggregated image overlayed, together with the aligned area and the aligned_box shown as blue rectangles. aligned_he will contain the part of the H&E image aligned.

Return type:

(numpy.ndarray, numpy.ndarray)

spacemake.spatial.he_integration.attach_he_adata(adata: anndata._core.anndata.AnnData, aligned_he: numpy.ndarray, push_by_spot_diameter: bool = True, raw_aligned: bool = False)anndata._core.anndata.AnnData

Attach the aligned H&E data to a spacemake processed AnnData object.

Parameters:
  • adata (anndata.AnnData) – A spacemake processed AnnData object.
  • aligned_he (numpy.ndarray) – A spacemake aligned H&E image aligned either with the align_he_aggregated_img or the align_he_spot_img functions.
  • push_by_spot_diameter (bool) – If true the aligned image will be pushed by one spot diameter. To be used only if a spot image was aligned. Defaults to True.
  • raw_aligned (bool) – If true it is assumed that the H&E image was aligned using the raw spacemake processed AnnData. If a spot image was aligned this should be set to False. Defaults to False.
Returns:

An AnnData object with the attached H&E image. When used with scanpy’s scanpy.pl.spatial, under the spatial data the H&E image will be shown.

Return type:

anndata.AnnData

novosparc integration module

spacemake.spatial.novosparc_integration.novosparc_denovo(adata: anndata._core.anndata.AnnData, num_spatial_locations: int = 5000, num_input_cells: int = 30000, locations=None)novosparc.common._tissue.Tissue

Given an AnnData object containing single-cell data, this function will try to reconstruct a 2D tissue de-novo. By default it will use the 500 most variable genes as markers to do this reconstruction.

Parameters:
  • adata (anndata.AnnData) – A spacemake processed sample.
  • num_spatial_locations (int) – The number of spatial locations to be used for de-novo recontruction onto a circular tissue. Ignored if locations are provided. If set to None this will be equal to the number of cells in the dataset. Default: 5000.
  • num_input_cells (int) – Number of cells from the single-cell data to be used for de-novo reconstruction. If set to less than the available number of cells, the data will be downsampled. If set to None all cells are used. Default: 30000
  • locations (numpy.ndarray) – Numpy array of (x,y) coordinates (optional). Novosparc will try to reconstruct the tissue using these locations. If none provided, a circular tissue will be automatically created with num_spatial_locations number of locations.
Returns:

A novosparc.cm.Tissue object with 2D expression information.

Return type:

novosparc.cm.Tissue

spacemake.spatial.novosparc_integration.save_novosparc_res(tissue: novosparc.common._tissue.Tissue, adata_original: anndata._core.anndata.AnnData)anndata._core.anndata.AnnData

Save the result of novosparc spatial mapping.

Parameters:
  • tissue (novosparc.cm.Tissue) – A Tissue object, result of the novosparc mapping.
  • adata_original (anndata.AnnData) – The original AnnData which was mapped with novosparc, to reconstruct the Tissue. For the de-novo reconstruction, use the original AnnData object, when a single-cell dataset was mapped onto a spatial dataset, use the AnnData of the single-cell dataset.
Returns:

An AnnData object containing the spatial information in .obsm[‘spatial’], and the imputed (after mapping) expression values in .X.

Return type:

anndata.AnnData

spacemake.spatial.novosparc_integration.novosparc_mapping(sc_adata: anndata._core.anndata.AnnData, st_adata: anndata._core.anndata.AnnData)novosparc.common._tissue.Tissue

Given two AnnData objects, one single-cell and one spatial, this function will map the expression of the single-cell data onto the spatial data using shared highly variable genes as markers.

Parameters:
  • sc_adata (anndata.AnnData) – A spacemake processed single-cell sample.
  • st_adata (anndata.AnnData) – A spacemake processed spatial sample.
Returns:

A novosparc.cm.Tissue object with 2D expression information. The locations of the Tissue will be identical to the locations of the spatial sample.

Return type:

novosparc.cm.Tissue

spacemake.spatial.novosparc_integration.quantify_clusters_spatially(tissue: novosparc.common._tissue.Tissue, cluster_key: str = 'clusters')numpy.ndarray

Maps the annotated clusters obtained from the scRNA-seq analysis onto the tissue space.

Param:tissue: the novosparc tissue object containing the gene expression data, the clusters annotation and the spatial reconstruction. Assumes that the cluster annotation exists in the underlying anndata object.
Type:tissue: novosparc.cm.Tissue
Param:cluster_key: the key of the clustering to be used for deduction
Type:cluster_key: str
Returns:A numpy list of cluster names, one per each spot
Return type:numpy.ndarray