R/caesar.R
cellembedding_seurat.Rd
This function computes cell embedding using the CAESAR framework with FAST for dimensionality reduction and spatial adjacency weights. It integrates variable feature selection and spatial adjacency information to generate low-dimensional representations for cells.
cellembedding_seurat(
seu,
adjm,
assay = NULL,
slot = "data",
nfeatures = 2000,
q = 50,
reduction.name = "caesar",
var.features = NULL,
...
)
A Seurat object. The Seurat object should contain gene expression data and be preprocessed with variable features identified.
A spatial adjacency matrix representing the relationships between cells or spots in spatial transcriptomic data.
A character string specifying which assay to use from the Seurat object. If NULL, the function will use the default assay.
The data slot to use for feature extraction (e.g., "data", "counts"). Default is "data".
The number of features to select for analysis. Default is 2000.
An integer specifying the number of dimensions for the reduced embeddings. Default is 50.
A character string specifying the name for the dimensional reduction. Default is "caesar".
A vector of variable features (genes) to use for the embedding. If NULL, the function will use variable features stored in the Seurat object.
Additional arguments passed to `FAST_run`.
The modified Seurat object with the co-embedding results (cell and gene embeddings) stored in the specified dimensional reduction slot.
FAST_run
for the main FAST dimensionality reduction algorithm.
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 <- cellembedding_seurat(
seu = seu,
adjm = adjm
)
#> Finish variable intialization
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 2, loglik= -597713.932765, dloglik=0.999722
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 3, loglik= -572981.633443, dloglik=0.041378
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 4, loglik= -568540.760390, dloglik=0.007750
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 5, loglik= -565577.203830, dloglik=0.005213
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 6, loglik= -563808.620547, dloglik=0.003127
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 7, loglik= -562445.787433, dloglik=0.002417
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 8, loglik= -561479.215323, dloglik=0.001719
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 9, loglik= -560721.438599, dloglik=0.001350
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 10, loglik= -560111.513183, dloglik=0.001088
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 11, loglik= -559583.251469, dloglik=0.000943
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 12, loglik= -559112.175571, dloglik=0.000842
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 13, loglik= -558672.733365, dloglik=0.000786
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 14, loglik= -558253.012300, dloglik=0.000751
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 15, loglik= -557843.814583, dloglik=0.000733
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 16, loglik= -557444.260607, dloglik=0.000716
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 17, loglik= -557056.241772, dloglik=0.000696
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 18, loglik= -556685.140174, dloglik=0.000666
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 19, loglik= -556336.124902, dloglik=0.000627
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 20, loglik= -556014.108493, dloglik=0.000579
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 21, loglik= -555721.816223, dloglik=0.000526
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 22, loglik= -555459.782139, dloglik=0.000472
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 23, loglik= -555225.898188, dloglik=0.000421
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 24, loglik= -555016.558071, dloglik=0.000377
#> Satrt ICM and E-step!
#> Finish ICM and E-step!
#> iter = 25, loglik= -554827.351177, dloglik=0.000341
#> 2024-09-12 20:18:50.897191 : ***** Finish calculate CAESAR embedding, 0.062 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