This vignette introduces the FAST workflow for the analysis of multiple simulated spatial transcriptomics dataset. FAST workflow is based on the PRECASTObj object created in the PRECAST R package and the workflow of FAST is similar to that of PRECAST; see (https://feiyoung.github.io/PRECAST/articles/PRECAST.BreastCancer.html) for the workflow of PRECAST. The workflow of FAST consists of three steps

  • Independent preprocessing and model setting
  • Spatial dimension reduction using FAST
  • Downstream analysis (i.e. , embedding alignment using Harmony and clustering using Louvain, visualization of clusters and embeddings, remove unwanted variation, combined differential expression analysis)
  • Except for the above downstream analyses, cell-cell interaction analysis and trajectory inference can also be performed on the basis of the embeddings obtained by FAST.

We demonstrate the use of FAST to three simulated ST data that are here, which can be downloaded to the current working path by the following command:

githubURL <- "https://github.com/feiyoung/ProFAST/blob/main/vignettes_data/simu3.rds?raw=true"
download.file(githubURL,"simu3.rds",mode='wb')

Then load to R

load("simu3.rds")

The package can be loaded with the command:

library(ProFAST) # load the package of FAST method
#> Loading required package: gtools
#> 
#> 
library(PRECAST)
#> Loading required package: parallel
#> PRECAST :  An efficient data integration method is provided for multiple spatial transcriptomics data with non-cluster-relevant effects such as the complex batch effects. It unifies spatial factor analysis simultaneously with spatial clustering and embedding alignment, requiring only partially shared cell/domain clusters across datasets. More details can be referred to Wei Liu, et al. (2023) <doi:10.1038/s41467-023-35947-w>.   Check out our Package website (https://feiyoung.github.io/PRECAST/index.html) for a more complete description of the methods and analyses
library(Seurat)
#> Warning: package 'Seurat' was built under R version 4.1.3
#> Attaching SeuratObject
#> Attaching sp

View the simulated data

First, we view the the three simulated spatial transcriptomics data with ST platform. There are 200 genes for each data batch and ~2000 spots in total

simu3 ## a list including three Seurat object with default assay: RNA
#> [[1]]
#> An object of class Seurat 
#> 200 features across 625 samples within 1 assay 
#> Active assay: RNA (200 features, 0 variable features)
#> 
#> [[2]]
#> An object of class Seurat 
#> 200 features across 400 samples within 1 assay 
#> Active assay: RNA (200 features, 0 variable features)
#> 
#> [[3]]
#> An object of class Seurat 
#> 200 features across 900 samples within 1 assay 
#> Active assay: RNA (200 features, 0 variable features)

Check the content in simu3.

head(simu3[[1]])
row.names(simu3[[1]])[1:10]

Create a PRECASTObject object

We show how to create a PRECASTObject object step by step. First, we create a Seurat list object using the count matrix and meta data of each data batch. Although simu3 is a prepared Seurat list object, we re-create a same objcet seuList to show the details.

  • Note: the spatial coordinates must be contained in the meta data and named as row and col, which benefits the identification of spaital coordinates by FAST
## Get the gene-by-spot read count matrices
countList <- lapply(simu3, function(x) x[["RNA"]]@counts)

## Check the spatial coordinates: Yes, they are named as "row" and "col"!
head(simu3[[1]]@meta.data)
#>          orig.ident nCount_RNA nFeature_RNA row col  Group
#> spot1 SeuratProject     130934          114   1   1 Layer4
#> spot2 SeuratProject       3103          116   2   1 Layer6
#> spot3 SeuratProject       8112          110   3   1 Layer6
#> spot4 SeuratProject       2637          105   4   1 Layer6
#> spot5 SeuratProject       5664          109   5   1 Layer5
#> spot6 SeuratProject       4636          107   6   1 Layer6

## Get the meta data of each spot for each data batch
metadataList <- lapply(simu3, function(x) x@meta.data)


## ensure the row.names of metadata in metaList are the same as that of colnames count matrix in countList
M <- length(countList)
for(r in 1:M){
  row.names(metadataList[[r]]) <- colnames(countList[[r]])
}


## Create the Seurat list  object

seuList <- list()
for(r in 1:M){
  seuList[[r]] <- CreateSeuratObject(counts = countList[[r]], meta.data=metadataList[[r]], project = "FASTsimu")
}

Prepare the PRECASTObject with preprocessing step.

Next, we use CreatePRECASTObject() to create a PRECASTObject object based on the Seurat list object seuList. Users are able to see https://feiyoung.github.io/PRECAST/articles/PRECAST.BreastCancer.html for what is done in this function. Since this is a simulated dataset, we used all the 200 genes by using a custom gene list customGenelist=custom_genelist). We observe that there are only 197 genes passing the filtering step.


## Create PRECASTObject
custom_genelist <- row.names(seuList[[1]])
set.seed(2023)
PRECASTObj <-  CreatePRECASTObject(seuList, customGenelist=custom_genelist)
#> Filter spots and features from Raw count data...
#>  
#> 
#> 2024-01-09 21:47:04 : ***** Filtering step for raw count data finished!, 0.005 mins elapsed.
#> Select the variable genes for each data batch...
#> CreatePRECASTObject: remove genes:gene90  gene144  gene170  with low count reads in seuList.
#> 2024-01-09 21:47:04 : ***** Gene selection finished!, 0 mins elapsed.
#> Filter spots and features from SVGs(HVGs) count data...
#> 2024-01-09 21:47:04 : ***** Filtering step for count data with variable genes finished!, 0.006 mins elapsed.

## User can retain the raw seuList by the following commond.
##  PRECASTObj <-  CreatePRECASTObject(seuList, customGenelist=row.names(seuList[[1]]), rawData.preserve = TRUE)
## check the number of genes/features after filtering step
PRECASTObj@seulist
#> [[1]]
#> An object of class Seurat 
#> 197 features across 625 samples within 1 assay 
#> Active assay: RNA (197 features, 0 variable features)
#> 
#> [[2]]
#> An object of class Seurat 
#> 197 features across 400 samples within 1 assay 
#> Active assay: RNA (197 features, 0 variable features)
#> 
#> [[3]]
#> An object of class Seurat 
#> 197 features across 900 samples within 1 assay 
#> Active assay: RNA (197 features, 0 variable features)

Fit PRECAST using simulated data

Add the model setting

Add adjacency matrix list and parameter setting of FAST. More model setting parameters can be found in model_set_FAST().


## seuList is null since the default value `rawData.preserve` is FALSE.
PRECASTObj@seuList
#> NULL

## Add adjacency matrix list for a PRECASTObj object to prepare for FAST model fitting.
PRECASTObj <- AddAdjList(PRECASTObj, platform = "ST")
#> Neighbors were identified for 625 out of 625 spots.
#> Neighbors were identified for 400 out of 400 spots.
#> Neighbors were identified for 900 out of 900 spots.

## Add a model setting in advance for a PRECASTObj object: verbose =TRUE helps outputing the information in the algorithm; 
PRECASTObj <- AddParSettingFAST(PRECASTObj, verbose=TRUE)
## Check the parameters
PRECASTObj@parameterList
#> $maxIter
#> [1] 30
#> 
#> $seed
#> [1] 1
#> 
#> $epsLogLik
#> [1] 1e-05
#> 
#> $verbose
#> [1] TRUE
#> 
#> $error_heter
#> [1] TRUE
#> 
#> $Psi_diag
#> [1] FALSE

Fit FAST

For function FAST, users can specify the number of factors q and the fitted model fit.model. The q sets the number of spatial factors to be extracted, and a lareger one means more information to be extracted but higher computaional cost. The fit.model specifies the version of FAST to be fitted. The Gaussian version (gaussian) models the log-count matrices while the Poisson verion (poisson) models the count matrices; default as poisson.

### set q= 20 here
set.seed(2023)
PRECASTObj <- FAST(PRECASTObj, q=20)
#> Warning in if (!(fit.model %in% c("poisson", "gaussian"))) stop("FAST: Check the
#> argument: fit.model! fit.model must either be 'poisson' or 'gaussian'."): the
#> condition has length > 1 and only the first element will be used
#> ******Run the Poisson version of FAST...
#> Finish variable initialization 
#> Satrt ICM step! 
#> iter = 2, ELBO= 189481969.596825, dELBO=1.088234 
#> Satrt ICM step! 
#> iter = 3, ELBO= 208013944.617564, dELBO=0.097803 
#> Satrt ICM step! 
#> iter = 4, ELBO= 208041974.387419, dELBO=0.000135 
#> Satrt ICM step! 
#> iter = 5, ELBO= 208057832.422356, dELBO=0.000076 
#> Satrt ICM step! 
#> iter = 6, ELBO= 208067869.378179, dELBO=0.000048 
#> Satrt ICM step! 
#> iter = 7, ELBO= 208074731.784015, dELBO=0.000033 
#> Satrt ICM step! 
#> iter = 8, ELBO= 208079699.135512, dELBO=0.000024 
#> Satrt ICM step! 
#> iter = 9, ELBO= 208083457.759797, dELBO=0.000018 
#> Satrt ICM step! 
#> iter = 10, ELBO= 208086403.143739, dELBO=0.000014 
#> Satrt ICM step! 
#> iter = 11, ELBO= 208088775.191483, dELBO=0.000011 
#> Satrt ICM step! 
#> iter = 12, ELBO= 208090727.539180, dELBO=0.000009
#> 2024-01-09 21:47:08 : ***** Finish FAST, 0.063 mins elapsed.
### Check the results
str(PRECASTObj@resList)
#> List of 1
#>  $ FAST:List of 7
#>   ..$ hV      :List of 3
#>   .. ..$ : num [1:625, 1:15] -2.27 -4.05 -6.52 -1.77 -1.74 ...
#>   .. .. ..- attr(*, "scaled:center")= num [1:15] -0.867 -0.848 -2.528 0.32 1.01 ...
#>   .. ..$ : num [1:400, 1:15] -9.32 -3.48 -1.82 -5.13 -7.25 ...
#>   .. .. ..- attr(*, "scaled:center")= num [1:15] -0.0347 0.7836 -0.8125 -0.9521 3.9392 ...
#>   .. ..$ : num [1:900, 1:15] 1.019 -2.055 -0.624 -5.129 -2.433 ...
#>   .. .. ..- attr(*, "scaled:center")= num [1:15] -3.627 -0.795 1.606 1.231 -3.135 ...
#>   ..$ nu      : num [1:3, 1:197] 1.037 4.191 -1.12 -0.305 -0.44 ...
#>   ..$ Psi     : num [1:15, 1:15, 1:3] 29.685 3.493 -0.744 -2.433 -0.368 ...
#>   ..$ W       : num [1:197, 1:15] 0.16046 -0.07676 -0.08422 -0.00717 -0.03362 ...
#>   ..$ Lam     : num [1:3, 1:197] 1.84 2.4 1.14 1.61 1.12 ...
#>   ..$ ELBO    : num 2.08e+08
#>   ..$ ELBO_seq: num [1:11] -2.15e+09 1.89e+08 2.08e+08 2.08e+08 2.08e+08 ...

Run gaussian version Users can also use the gaussian version by the following command:

set.seed(2023)
PRECASTObj <- FAST(PRECASTObj, q=20, fit.model='gaussian')
### Check the results
str(PRECASTObj@resList)

Evaluate the adjusted McFadden’s pseudo R-square

Next, we investigate the performance of dimension reduction by calculating the adjusted McFadden’s pseudo R-square for each data batch. The simulated true labels is in the meta.data of each component of PRECASTObj@seulist.

## Obtain the true labels
yList <- lapply(PRECASTObj@seulist, function(x) x$Group)
### Evaluate the MacR2
MacVec <- sapply(1:length(PRECASTObj@seulist), function(r) get_r2_mcfadden(PRECASTObj@resList$FAST$hV[[r]], yList[[r]]))
#> # weights:  119 (96 variable)
#> initial  value 1216.193843 
#> iter  10 value 114.780227
#> iter  20 value 92.092862
#> iter  30 value 85.341446
#> iter  40 value 82.688874
#> iter  50 value 81.299335
#> iter  60 value 79.578069
#> iter  70 value 77.914256
#> iter  80 value 77.803555
#> iter  90 value 77.775020
#> iter 100 value 77.773307
#> final  value 77.773307 
#> stopped after 100 iterations
#> # weights:  119 (96 variable)
#> initial  value 778.364060 
#> iter  10 value 116.386127
#> iter  20 value 28.870844
#> iter  30 value 7.501395
#> iter  40 value 3.686866
#> iter  50 value 1.472696
#> iter  60 value 0.878809
#> iter  70 value 0.613061
#> iter  80 value 0.417069
#> iter  90 value 0.287838
#> iter 100 value 0.159742
#> final  value 0.159742 
#> stopped after 100 iterations
#> # weights:  119 (96 variable)
#> initial  value 1751.319134 
#> iter  10 value 147.392347
#> iter  20 value 126.553241
#> iter  30 value 119.448945
#> iter  40 value 118.722384
#> iter  50 value 117.568144
#> iter  60 value 115.680333
#> iter  70 value 113.602190
#> iter  80 value 113.298580
#> iter  90 value 113.270105
#> iter 100 value 113.254185
#> final  value 113.254185 
#> stopped after 100 iterations
### output them
print(MacVec)
#> adjusted McFadden's R2 adjusted McFadden's R2 adjusted McFadden's R2 
#>              0.9348610              0.9984897              0.9343897

Embedding alignment and clustering using Harmony and Louvain

Based on the embeddings from FAST, we use Harmony to align the embeddings then followed by Louvain clustering to obtain the cluster labels. In this downstream analysis, other methods for embedding alignment and clustering can be also used. In the vignette of two sections of DLPFC Visium data, we will show another method (iSC-MEB) to jointly perform embedding alignment and spatial clustering.

PRECASTObj <- RunHarmonyLouvain(PRECASTObj, resolution = 0.4)
#> ******Use Harmony to remove batch in the embeddings from FAST...
#> Harmony 1/10
#> Harmony 2/10
#> Harmony 3/10
#> Harmony 4/10
#> Harmony 5/10
#> Harmony converged after 5 iterations
#> 2024-01-09 21:47:11 : ***** Finish Harmony correction, 0.036 mins elapsed.
#> ******Use Louvain to cluster and determine the number of clusters...
#> Warning: No assay specified, setting assay as RNA by default.
#> Warning: Keys should be one or more alphanumeric characters followed by an
#> underscore, setting key from PC to PC_
#> Warning: All keys should be one or more alphanumeric characters followed by an
#> underscore '_', setting key to PC_
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 1925
#> Number of edges: 83023
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8788
#> Number of communities: 7
#> Elapsed time: 0 seconds
#> 2024-01-09 21:47:12 : ***** Finsh Louvain clustering and find the optimal number of clusters, 0.015 mins elapsed.
ARI_vec <- sapply(1:M, function(r) mclust::adjustedRandIndex(PRECASTObj@resList$Louvain$cluster[[r]], yList[[r]]))
print(ARI_vec)
#> [1] 0.8315672 0.8625198 0.8126047

Remove unwanted variations in the log-normalized expression matrices

In the following, we remove the unwanted variations in the log-normalized expression matrices to obtain a combined log-normalized expression matrix in a Seurat object. In the context of the simulated data used in this study, housekeeping genes are not present, thus, we turn to another method to remove the unwanted variations. Specifically, we leverage the batch effect embeddings estimated through Harmony to capture and mitigate unwanted variations. Additionally, we utilize the cluster labels obtained via Louvain clustering to retain the desired biological effects.

The estimated embeddings of batch effects (batchEmbed) are in the slot PRECASTObj@resList$Harmony and cluster labels (cluster) are in the slot PRECASTObj@resList$Louvain.

str(PRECASTObj@resList$Harmony)
#> List of 2
#>  $ harmonyembed:List of 3
#>   ..$ : num [1:625, 1:15] -2.19 -4.13 -6.67 -1.75 -2.28 ...
#>   ..$ : num [1:400, 1:15] -8.96 -3.13 -1.87 -4.88 -6.04 ...
#>   ..$ : num [1:900, 1:15] 1.143 -2.349 -0.894 -5.486 -2.931 ...
#>  $ batchEmbed  :List of 3
#>   ..$ : num [1:625, 1:15] -0.24035 0.00474 -0.02522 -0.05699 0.33849 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : chr [1:625] "1" "2" "3" "4" ...
#>   .. .. ..$ : NULL
#>   ..$ : num [1:400, 1:15] -0.4123 -0.4013 -0.0554 -0.3333 -1.3548 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : chr [1:400] "626" "627" "628" "629" ...
#>   .. .. ..$ : NULL
#>   ..$ : num [1:900, 1:15] -0.0506 0.1896 0.1548 0.0342 0.3375 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : chr [1:900] "1026" "1027" "1028" "1029" ...
#>   .. .. ..$ : NULL
str(PRECASTObj@resList$Louvain)
#> List of 1
#>  $ cluster:List of 3
#>   ..$ : Factor w/ 7 levels "0","1","2","3",..: 6 2 2 2 3 2 4 1 2 5 ...
#>   .. ..- attr(*, "names")= chr [1:625] "spot1" "spot2" "spot3" "spot4" ...
#>   ..$ : Factor w/ 7 levels "0","1","2","3",..: 2 5 4 2 3 3 3 3 1 1 ...
#>   .. ..- attr(*, "names")= chr [1:400] "spot626" "spot627" "spot628" "spot629" ...
#>   ..$ : Factor w/ 7 levels "0","1","2","3",..: 6 6 6 6 4 5 5 5 6 5 ...
#>   .. ..- attr(*, "names")= chr [1:900] "spot1026" "spot1027" "spot1028" "spot1029" ...

Then, we integrate the three sections by removing the unwanted variations and setting seulist_HK=NULL and Method = "HarmonyLouvain" in the function IntegrateSRTData(). After obtaining seuInt, we will see there are three embeddings: FAST, harmony and position, in the slot seuInt@reductions. FAST are the embeddings obtained by FAST model fitting and are uncorrected embeddings that may includes the unwanted effects (i.e., batch effects); harmonyare the embeddings obtained by Harmony fitting and are aligned embeddings; and position are the spatial coordinates.

seulist_HK <- NULL
seuInt <- IntegrateSRTData(PRECASTObj, seulist_HK=seulist_HK, Method = "HarmonyLouvain", seuList_raw=NULL, covariates_use=NULL, verbose=TRUE)
#> ******Perform PCA on housekeeping gene expression matrix...
#> Only use  the results in Harmony and Louvain to remove unwanted variations...
#> 2024-01-09 21:47:12 : ***** Finish PCA, 0 mins elapsed.
#> ******Remove the unwanted variations in gene expressions using spatial linear regression...
#> Finish variable initialization 
#> iter = 2, ELBO= -506059.111341, dELBO=0.999764 
#> iter = 3, ELBO= -441635.737161, dELBO=0.127304 
#> iter = 4, ELBO= -415220.082023, dELBO=0.059813 
#> iter = 5, ELBO= -396081.727921, dELBO=0.046092 
#> iter = 6, ELBO= -384044.227949, dELBO=0.030391 
#> iter = 7, ELBO= -375892.948265, dELBO=0.021225 
#> iter = 8, ELBO= -370736.090977, dELBO=0.013719 
#> iter = 9, ELBO= -367314.756584, dELBO=0.009228 
#> iter = 10, ELBO= -365042.010765, dELBO=0.006187 
#> iter = 11, ELBO= -363428.051646, dELBO=0.004421 
#> iter = 12, ELBO= -362239.146930, dELBO=0.003271 
#> iter = 13, ELBO= -361317.545283, dELBO=0.002544 
#> iter = 14, ELBO= -360585.560598, dELBO=0.002026 
#> iter = 15, ELBO= -359989.346188, dELBO=0.001653 
#> iter = 16, ELBO= -359497.531867, dELBO=0.001366 
#> iter = 17, ELBO= -359086.408375, dELBO=0.001144 
#> iter = 18, ELBO= -358739.978436, dELBO=0.000965 
#> iter = 19, ELBO= -358445.622555, dELBO=0.000821 
#> iter = 20, ELBO= -358194.067552, dELBO=0.000702 
#> iter = 21, ELBO= -357977.844218, dELBO=0.000604 
#> iter = 22, ELBO= -357791.173993, dELBO=0.000521 
#> iter = 23, ELBO= -357629.328675, dELBO=0.000452 
#> iter = 24, ELBO= -357488.521436, dELBO=0.000394 
#> iter = 25, ELBO= -357365.610813, dELBO=0.000344 
#> iter = 26, ELBO= -357258.018654, dELBO=0.000301 
#> iter = 27, ELBO= -357163.581148, dELBO=0.000264 
#> iter = 28, ELBO= -357080.491309, dELBO=0.000233 
#> iter = 29, ELBO= -357007.218099, dELBO=0.000205 
#> iter = 30, ELBO= -356942.466750, dELBO=0.000181
#> 2024-01-09 21:47:18 : ***** Finish unwanted variation removal, 0.091 mins elapsed.
#> ******Sort the results into a Seurat object...
#> 2024-01-09 21:47:18 : ***** Finish results arrangement, 0.002 mins elapsed.
seuInt
#> An object of class Seurat 
#> 197 features across 1925 samples within 1 assay 
#> Active assay: RNA (197 features, 0 variable features)
#>  3 dimensional reductions calculated: FAST, harmony, position

Visualization

First, user can choose a beautiful color schema using chooseColors() in the R package PRECAST.

cols_cluster <- chooseColors(palettes_name = "Nature 10", n_colors = 7, plot_colors = TRUE)

Then, we plot the spatial scatter plot for clusters using the function SpaPlot() in the R package PRECAST.

p12 <- SpaPlot(seuInt, item = "cluster", batch = NULL, point_size = 1, cols = cols_cluster, combine = TRUE)
p12

Users can re-plot the above figures for specific need by returning a ggplot list object. For example, we plot the spatial heatmap using a common legend by using the function drawFigs() in the R package PRECAST.

pList <- SpaPlot(seuInt, item = "cluster", title_name= 'Section',batch = NULL, point_size = 1, cols = cols_cluster, combine = FALSE)
drawFigs(pList, layout.dim = c(1, 3), common.legend = TRUE, legend.position = "right", align = "hv")

We use the function AddUMAP() in the R package PRECAST to obtain the three-dimensional components of UMAP using the aligned embeddings in the reduction harmony.

seuInt <- AddUMAP(seuInt, n_comp=3, reduction = 'harmony', assay = 'RNA')
seuInt
#> An object of class Seurat 
#> 197 features across 1925 samples within 1 assay 
#> Active assay: RNA (197 features, 0 variable features)
#>  4 dimensional reductions calculated: FAST, harmony, position, UMAP3

We plot the spatial tNSE RGB plot to illustrate the performance in extracting features.

p13 <- SpaPlot(seuInt, batch = NULL, item = "RGB_UMAP", point_size = 1, combine = FALSE, text_size = 15)
drawFigs(p13, layout.dim = c(1, 3), common.legend = TRUE, legend.position = "right", align = "hv")

We use the function AddUTSNE() in the R package PRECAST to obtain the two-dimensional components of UMAP using the aligned embeddings in the reduction harmony, and plot the tSNE plot based on the extracted features to check the performance of integration.

seuInt <- AddTSNE(seuInt, n_comp = 2, reduction = 'harmony', assay = 'RNA')
p1 <- dimPlot(seuInt, item = "cluster", point_size = 0.5, font_family = "serif", cols = cols_cluster,
    border_col = "gray10",  legend_pos = "right")  # Times New Roman
p2 <- dimPlot(seuInt, item = "batch", point_size = 0.5, font_family = "serif", legend_pos = "right")

drawFigs(list(p1, p2), layout.dim = c(1, 2), legend.position = "right")

Combined differential epxression analysis

Finally, we condut the combined differential expression analysis using the integrated log-normalized expression matrix saved in the seuInt object. The function FindAllMarkers() in the Seurat R package is ued to achieve this analysis.

dat_deg <- FindAllMarkers(seuInt)
#> Calculating cluster 1
#> Calculating cluster 2
#> Calculating cluster 3
#> Calculating cluster 4
#> Calculating cluster 5
#> Calculating cluster 6
#> Calculating cluster 7
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.1.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
n <- 5
dat_deg %>%
    group_by(cluster) %>%
    top_n(n = n, wt = avg_log2FC) -> top10
seuInt <- ScaleData(seuInt)
#> Centering and scaling data matrix

Plot dot plot of normalized expressions for each spatial domain identified by using the FAST embeddings.

col_here <- c("#F2E6AB", "#9C0141") 
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.1.3
p1 <- DotPlot(seuInt, features=unname(top10$gene), cols=col_here, #  idents = ident_here,
              col.min = -1, col.max = 1) + coord_flip()+ theme(axis.text.y = element_text(face = "italic"))+
  ylab("Domain") + xlab(NULL) + theme(axis.text.x = element_text(size=12, angle = 25, hjust = 1, family='serif'),
                                      axis.text.y = element_text(size=12, face= "italic", family='serif'))
p1

Session Info

sessionInfo()
#> R version 4.1.2 (2021-11-01)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 22621)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_China.936 
#> [2] LC_CTYPE=Chinese (Simplified)_China.936   
#> [3] LC_MONETARY=Chinese (Simplified)_China.936
#> [4] LC_NUMERIC=C                              
#> [5] LC_TIME=Chinese (Simplified)_China.936    
#> 
#> attached base packages:
#> [1] parallel  stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#> [1] ggplot2_3.4.1      dplyr_1.0.9        sp_1.5-0           SeuratObject_4.1.0
#> [5] Seurat_4.1.1       PRECAST_1.6.2      ProFAST_1.3        gtools_3.9.2.2    
#> 
#> loaded via a namespace (and not attached):
#>   [1] rappdirs_0.3.3              scattermore_0.8            
#>   [3] ggthemes_4.2.4              GiRaF_1.0.1                
#>   [5] ragg_1.2.2                  tidyr_1.2.0                
#>   [7] bit64_4.0.5                 knitr_1.37                 
#>   [9] irlba_2.3.5                 DelayedArray_0.20.0        
#>  [11] data.table_1.14.2           rpart_4.1.16               
#>  [13] KEGGREST_1.34.0             RCurl_1.98-1.6             
#>  [15] generics_0.1.2              BiocGenerics_0.40.0        
#>  [17] org.Mm.eg.db_3.14.0         ScaledMatrix_1.2.0         
#>  [19] cowplot_1.1.1               RSQLite_2.2.10             
#>  [21] RANN_2.6.1                  future_1.26.1              
#>  [23] bit_4.0.4                   spatstat.data_3.0-0        
#>  [25] xml2_1.3.3                  httpuv_1.6.5               
#>  [27] SummarizedExperiment_1.24.0 assertthat_0.2.1           
#>  [29] viridis_0.6.2               xfun_0.29                  
#>  [31] hms_1.1.1                   jquerylib_0.1.4            
#>  [33] evaluate_0.15               promises_1.2.0.1           
#>  [35] fansi_1.0.4                 progress_1.2.2             
#>  [37] dbplyr_2.1.1                igraph_1.3.5               
#>  [39] DBI_1.1.2                   htmlwidgets_1.5.4          
#>  [41] spatstat.geom_2.4-0         stats4_4.1.2               
#>  [43] purrr_0.3.4                 ellipsis_0.3.2             
#>  [45] RSpectra_0.16-1             ggpubr_0.4.0               
#>  [47] backports_1.4.1             DR.SC_3.4                  
#>  [49] insight_0.17.0              biomaRt_2.50.3             
#>  [51] deldir_1.0-6                sparseMatrixStats_1.6.0    
#>  [53] MatrixGenerics_1.6.0        vctrs_0.6.1                
#>  [55] SingleCellExperiment_1.16.0 Biobase_2.54.0             
#>  [57] ROCR_1.0-11                 abind_1.4-5                
#>  [59] cachem_1.0.6                withr_2.5.0                
#>  [61] progressr_0.10.1            sctransform_0.3.3          
#>  [63] prettyunits_1.1.1           mclust_5.4.10              
#>  [65] goftest_1.2-3               cluster_2.1.2              
#>  [67] lazyeval_0.2.2              crayon_1.5.1               
#>  [69] pkgconfig_2.0.3             labeling_0.4.2             
#>  [71] GenomeInfoDb_1.30.1         nlme_3.1-155               
#>  [73] vipor_0.4.5                 nnet_7.3-17                
#>  [75] rlang_1.1.0                 globals_0.15.0             
#>  [77] lifecycle_1.0.3             miniUI_0.1.1.1             
#>  [79] filelock_1.0.2              BiocFileCache_2.2.1        
#>  [81] rsvd_1.0.5                  rprojroot_2.0.3            
#>  [83] polyclip_1.10-0             matrixStats_0.62.0         
#>  [85] lmtest_0.9-40               Matrix_1.4-0               
#>  [87] carData_3.0-5               zoo_1.8-10                 
#>  [89] beeswarm_0.4.0              ggridges_0.5.3             
#>  [91] png_0.1-7                   viridisLite_0.4.1          
#>  [93] bitops_1.0-7                KernSmooth_2.23-20         
#>  [95] Biostrings_2.62.0           blob_1.2.2                 
#>  [97] DelayedMatrixStats_1.16.0   stringr_1.4.0              
#>  [99] parallelly_1.32.0           spatstat.random_2.2-0      
#> [101] rstatix_0.7.0               S4Vectors_0.32.3           
#> [103] ggsignif_0.6.3              beachmat_2.10.0            
#> [105] scales_1.2.1                memoise_2.0.1              
#> [107] magrittr_2.0.3              plyr_1.8.7                 
#> [109] ica_1.0-2                   zlibbioc_1.40.0            
#> [111] compiler_4.1.2              RColorBrewer_1.1-3         
#> [113] fitdistrplus_1.1-8          cli_3.2.0                  
#> [115] XVector_0.34.0              listenv_0.8.0              
#> [117] patchwork_1.1.1             pbapply_1.5-0              
#> [119] MASS_7.3-55                 mgcv_1.8-39                
#> [121] tidyselect_1.1.2            stringi_1.7.6              
#> [123] textshaping_0.3.6           highr_0.9                  
#> [125] yaml_2.3.6                  BiocSingular_1.10.0        
#> [127] ggrepel_0.9.1               grid_4.1.2                 
#> [129] sass_0.4.1                  tools_4.1.2                
#> [131] future.apply_1.9.0          rstudioapi_0.13            
#> [133] gridExtra_2.3               farver_2.1.1               
#> [135] Rtsne_0.16                  digest_0.6.29              
#> [137] rgeos_0.5-9                 FNN_1.1.3.1                
#> [139] shiny_1.7.1                 Rcpp_1.0.10                
#> [141] GenomicRanges_1.46.1        car_3.0-12                 
#> [143] broom_0.7.12                scuttle_1.4.0              
#> [145] performance_0.8.0           later_1.3.0                
#> [147] harmony_0.1.0               RcppAnnoy_0.0.19           
#> [149] org.Hs.eg.db_3.14.0         httr_1.4.3                 
#> [151] AnnotationDbi_1.56.2        colorspace_2.1-0           
#> [153] XML_3.99-0.9                fs_1.5.2                   
#> [155] tensor_1.5                  reticulate_1.25            
#> [157] IRanges_2.28.0              splines_4.1.2              
#> [159] uwot_0.1.11                 spatstat.utils_3.0-1       
#> [161] pkgdown_2.0.6               scater_1.25.1              
#> [163] plotly_4.10.0               systemfonts_1.0.4          
#> [165] xtable_1.8-4                jsonlite_1.8.0             
#> [167] R6_2.5.1                    pillar_1.9.0               
#> [169] htmltools_0.5.2             mime_0.12                  
#> [171] glue_1.6.2                  fastmap_1.1.0              
#> [173] BiocParallel_1.28.3         BiocNeighbors_1.12.0       
#> [175] codetools_0.2-18            utf8_1.2.3                 
#> [177] lattice_0.20-45             bslib_0.3.1                
#> [179] spatstat.sparse_2.1-1       tibble_3.2.1               
#> [181] curl_4.3.2                  ggbeeswarm_0.6.0           
#> [183] leiden_0.4.2                limma_3.50.1               
#> [185] survival_3.2-13             CompQuadForm_1.4.3         
#> [187] rmarkdown_2.11              desc_1.4.0                 
#> [189] munsell_0.5.0               GenomeInfoDbData_1.2.7     
#> [191] reshape2_1.4.4              gtable_0.3.3               
#> [193] spatstat.core_2.4-4