This function computes and adds gene embeddings to a Seurat object based on a provided adjacency matrix of spatial information and an existing cell embedding. It allows for the integration of gene-level information into the dimensional reduction of the Seurat object.

add.gene.embedding(seu, adjm, reduction.name = "caesar", assay = NULL)

Arguments

seu

A Seurat object. The Seurat object should contain pre-computed cell embeddings for dimensional reduction and expression data for genes.

adjm

A spatial adjacency matrix that represents relationships between cells or spots in the spatial transcriptomic data. This matrix is used to calculate the gene embeddings.

reduction.name

A character string specifying the name of the dimensional reduction method used for the cell embeddings (e.g., "ncfm", "caesar", etc.). The computed gene embeddings will be added to this slot. Default is "caesar".

assay

A character string specifying which assay to use from the Seurat object. If NULL, the function will use the default assay set in the Seurat object.

Value

The modified Seurat object with the computed gene embeddings added to the specified dimensional reduction (`reduction.name`).

Examples

data(toydata)

seu <- toydata$seu
pos <- toydata$pos

adjm <- ProFAST::AddAdj(as.matrix(pos), radius.upper = 200)
#> The spatial cooridnates are 2 dimensions
#> Find the adjacency matrix by bisection method...
#> Current radius is 100.5
#> Median of neighborhoods is 0
#> Current radius is 50.75
#> Median of neighborhoods is 17
#> Current radius is 50.75
#> Median of neighborhoods is 4
seu <- add.gene.embedding(
    seu = seu,
    adjm = adjm,
    reduction.name = "caesar",
    assay = "RNA"
)
print(seu)
#> An object of class Seurat 
#> 302 features across 3000 samples within 1 assay 
#> Active assay: RNA (302 features, 302 variable features)
#>  2 dimensional reductions calculated: caesar, pos