SC2Spa.tl.FineMapping

SC2Spa.tl.FineMapping(adata_ref, adata_query, sparse=True, model_path=None, WD_cutoff=None, JGs=None, root='Model_SI/', name='SI', l1_reg=1e-05, l2_reg=0, dropout=0.05, epoch=500, batch_size=4096, nodes=[4096, 1024, 256, 64, 16, 4], lrr_patience=20, ES_patience=50, min_lr=1e-05, save=True, loss=<function rmse>, loss_name='rmse', NormMethod='BN', polar=True, FM=True, n_layer_cell=[1, 4], cell_radius=5, n_neighbors=1000, dis_cutoff=15, seed=2023)

Finely map single cells to spatial locations and Reconstruct ST data at single cell resolution

1. Finely map single cells to spatial locations. A model will be trained and saved to root+name+’.h5’ if model_path is None and save is True. The predicted coordinates of single cells will be saved in adata_query.obsm[‘spatial_mapping’] The predicted coordinates of beads will be saved in adata_ref.obsm[‘spatial_mapping’] Fine mapping information will be saved in adata_ref.obs[‘FM’] and adata_query.obs[‘FM’]. True if a cell/bead was mapped, otherwise False.

2. Reconstruct ST data at single cell resolution adata_query.obs[‘Dis2CloestBead’] stores the distance between a cell and the ST bead closest to it adata_query.obs[‘Recon_scST’] marks the cells that are used to reconstruct single-cell ST data adata_query.obs[‘Recon_scST_layer’] stores which reconstruction layer of cells. -1 means a cell is not assigned to any ST bead. 0 means a cell is among the closest cells to a ST bead. The greater the layer number, the further a cell is to the center of a ST bead.

Parameters

adata_ref

Reference anndata object. Gene expression matrix should be the shape of (cell, gene). Spatial information should be stored in adata_ref.obsm[‘spatial’] in np.array format

adata_query

Query anndata object. Gene expression matrix should be the shape of (cell, gene).

sparse

if gene expression is saved in sparse format

model_path

The path of a trained model. If not None, parameters for training will be ignored.

WD_cutoff

genes with Wasserstein distance lower than the cutoff will be used for mapping

JGs

List of genes used for training

root

the root path to save the model

name

the name used to save the model

l1_reg

l1 regularization factor

l2_reg

l2 regularization factor

nodes

a list that contains the numbers of the nodes of hidden layers

NormMethod

The method used for the normalization in the Fully-connected Neural Network. ‘BN’ for BatchNormalization ‘LN’ for LayerNormalization None for no normalization

lrr_patience

The patience for learning rate reduction

min_lr

minimum learning rate

ES_patience

The patience for early stopping

n_neighbors

Number of the nearest neighbors of a bead or cell. This parameter is for the KNN algorithm

dis_cutoff
Limit for the distance between a single cell and a ST bead. In the process

of fine mapping. Only the cells within the cutoff will be retained.

FM

Perform fine mapping and reconstruct ST data at single cell resolution if True

n_layer_cell

Number of cells in layers for sampling single cells for a ST bead.

cell_radius
Radius of a cell. For example, n_layer_cell=[1, 4] and cell_radius=5 means sampling 1 cell

from cells within 5 to a bead and at most 4 cells from cells between 5 and 15 to the bead. It is at most 4 cells because a cell can be sampled more than once to deal with the case that a bead has fewer cells than the user specified.

seed

seed for reconstructing the single-cell ST data