cellrefiner.preprocessing.spatial_mapping

cellrefiner.preprocessing.spatial_mapping(ad_st, ad_sc, db, scale=None, cluster_key_sc=None, spatial_key='spatial', pca_key='X_pca', uns_key='rank_genes_groups', n_rank_gene=100, n_cell=5, device='cuda:0', enable_cupy=True, enable_lr_force=False, return_mapping=False, seed=0)[source]

Perform mapping of single-cell data to spatial transcriptomics data and spatial refinement.

Parameters:
  • ad_st (AnnData) –

    Spatial transcriptomics AnnData object.

    Must contain spatial coordinates in .obsm[spatial_key].

  • ad_sc (AnnData) – Single-cell RNA-seq AnnData object.

  • db (DataFrame) – Ligand-receptor interaction database.

  • scale (float) – Spatial scale parameter that determines the interaction distance, representing the size of spatial transcriptomics spot.

  • cluster_key_sc (str, Optional) – Key in ad_sc.obs that contains cell type annotations, used for scanpy.tl.rank_genes_groups(ad_sc, groupby=cluster_key_sc)

  • spatial_key (str, default 'spatial') – Key in ad_st.obsm that contains spatial coordinates

  • pca_key (str, default 'X_pca') –

    Key in ad_sc.obsm that contains PCA embeddings.

    If not in ad_sc.obsm, scanpy.pp.pca() will be computed.

  • uns_key (str, default 'rank_genes_groups') –

    Key in ad_sc.uns containing ranked genes results from scanpy.tl.rank_genes_groups()

    If not present, scanpy.tl.rank_genes_groups(ad_sc, groupby=cluster_key_sc) will be computed.

  • n_rank_gene (int or None, default 100) –

    Number of top-ranked genes for each cell type that will be used in spatial mapping.

    If None, all genes will be used.

  • n_cell (int, default 5) – Number of cells to map to each spatial location.

  • device (str, default 'cuda:0') – Device used by pytorch.

  • enable_lr_force (bool, default False) – Whether to enable ligand-receptor force.

  • enable_cupy (bool, default True) – Whether to enable CuPy. If CuPy is not available, will automatically fall back to CPU.

  • seed (int, default 0) – random seed

Returns:

AnnData object containing mapped cells with refined spatial coordinates.

.obsm[‘spatial’]: Refined spatial coordinates. If .obsm[‘spatial’] is present in ad_sc, then stored as .obsm[‘spatial_refined’].

Same gene expression data as input single-cell RNA-seq data

Return type:

AnnData

Examples

>>> adata_cr = spatial_mapping(adata_st,adata_sc,db_lr,scale=125,cluster_key_sc = 'cell_type')