This function performs co-embedding of both cells and genes using the CAESAR method. It integrates spatial transcriptomics data from a Seurat object (`seu`) with a spatial adjacency matrix to compute the low-dimensional co-embedding.

CAESAR.coembedding(
  seu,
  pos,
  reduction.name = "caesar",
  q = 50,
  radius.upper = 400,
  ...
)

Arguments

seu

A Seurat object containing spatial transcriptomics data.

pos

A matrix of spatial coordinates for the spots (e.g., spatial positions of cells or pixels in the image). The row names of `pos` should match the column names of `seu`.

reduction.name

A character string specifying the name of the dimensional reduction method to store in the Seurat object. Default is "caesar".

q

An integer specifying the number of dimensions for the reduced co-embeddings. Default is 50.

radius.upper

A numeric value specifying the upper limit of the search radius for the spatial adjacency matrix. Default is 400.

...

Additional arguments passed to `cellembedding_image_seurat`.

Value

The modified Seurat object with the computed cell and gene embeddings stored in the specified reduction slot.

See also

cellembedding_seurat for computing cell embeddings. add.gene.embedding for adding gene embeddings to a Seurat object.

Examples

data(toydata)

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

seu <- CAESAR.coembedding(
    seu = seu,
    pos = pos
)
#> The spatial cooridnates are 2 dimensions
#> Find the adjacency matrix by bisection method...
#> Current radius is 200.5
#> Median of neighborhoods is 0
#> Current radius is 100.75
#> Median of neighborhoods is 66
#> Current radius is 50.88
#> Median of neighborhoods is 17
#> Current radius is 50.88
#> Median of neighborhoods is 4
#> Finish variable intialization 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 2, loglik= -597637.838080, dloglik=0.999722 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 3, loglik= -572940.539154, dloglik=0.041325 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 4, loglik= -568499.782555, dloglik=0.007751 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 5, loglik= -565540.073612, dloglik=0.005206 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 6, loglik= -563772.071017, dloglik=0.003126 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 7, loglik= -562410.264678, dloglik=0.002416 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 8, loglik= -561444.596258, dloglik=0.001717 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 9, loglik= -560687.827886, dloglik=0.001348 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 10, loglik= -560078.669319, dloglik=0.001086 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 11, loglik= -559551.027816, dloglik=0.000942 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 12, loglik= -559080.371861, dloglik=0.000841 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 13, loglik= -558641.134240, dloglik=0.000786 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 14, loglik= -558221.315415, dloglik=0.000752 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 15, loglik= -557811.644397, dloglik=0.000734 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 16, loglik= -557411.172928, dloglik=0.000718 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 17, loglik= -557021.840151, dloglik=0.000698 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 18, loglik= -556649.257404, dloglik=0.000669 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 19, loglik= -556299.013839, dloglik=0.000629 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 20, loglik= -555976.468444, dloglik=0.000580 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 21, loglik= -555684.579628, dloglik=0.000525 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 22, loglik= -555423.781035, dloglik=0.000469 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 23, loglik= -555191.654830, dloglik=0.000418 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 24, loglik= -554984.272443, dloglik=0.000374 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 25, loglik= -554796.995880, dloglik=0.000337 
#> 2024-09-12 20:18:29.778866 : ***** Finish calculate CAESAR embedding, 0.064 mins elapsed.
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