## read the rds and integration ----
library(spacexr)
library(Seurat)
## build reference ----
<- glue("ref/E9.5.rds")
rds_fn1 <- glue("ref/E11.5.rds")
rds_fn2 <- glue("ref/E13.5.rds")
rds_fn3
.5 <- read_rds(rds_fn1)
e9.5 <- read_rds(rds_fn2)
e11.5 <- read_rds(rds_fn3)
e13
<- list(e9.5, e11.5, e13.5)
ref_lst <- merge(ref_lst[[1]], ref_lst[-1])
mrg_seu
<- mrg_seu@meta.data |> dplyr::slice_sample(by = major_trajectory, prop = 0.05) |>
samp_df ::filter(!major_trajectory %in% c("Oligodendrocytes", "T_cells", "Testis_and_adrenal",
dplyr"Mast_cells", "B_cells", "Intestine")) # exclude those of minority
<- mrg_seu[, rownames(samp_df)]
ref "RNA"]] <- JoinLayers(ref[["RNA"]])
ref[[<- ref[["RNA"]]$counts
counts <- as.factor(ref$major_trajectory)
cluster names(cluster) <- colnames(ref)
<- ref$nCount_RNA
nUMI names(nUMI) <- colnames(ref)
<- Reference(counts, cluster, nUMI, min_UMI = 35, n_max_cells = 1e5)
reference write_rds(reference, "reference_tissue.rds")
## get visium object lists ----
<- "st_seu_obj.rds"
rds_fn <- read_rds(rds_fn)
seu_lst <- lapply(1:4, \(idx) {
rctd_lst2 = names(seu_lst)[idx]
stg <- seu_lst[[stg]]
visium <- visium[["Spatial"]]$counts
counts <- GetTissueCoordinates(visium)
coords colnames(coords) <- c("x", "y")
is.na(colnames(coords))] <- NULL
coords[<- SpatialRNA(coords, counts, colSums(counts))
query write_rds(query, glue("rctd_query_obj_{stg}.rds"))
<- create.RCTD(query, reference, max_cores = 16)
RCTD <- run.RCTD(RCTD, doublet_mode = "doublet")
RCTD return(RCTD)
})write_rds(rctd_lst2, "rctd_res_lst.rds")
12 Deconvolution
12.1 Deconvolution of ST data
A single-nucleus RNA sequencing dataset for mice, GSE186069
, was retrieved along with its associated annotations. Cells from embryonic stages E9.5, E11.5, and E13.5 were selected and merged. Deconvolution was performed using the RCTD
function implemented in the spacexr
package (v2.2.1).
For the whole embryo, due to the large number of cells (n = 691,652), 5% of the total cells were randomly sampled, and rare cell types (fewer than 35 cells) were excluded. The remaining data served as the reference, with the ‘major_trajectory’ column in the metadata used as labels. In the liver region, cell type frequencies were ranked in descending order, and minority cell types (proportion < 2%) were excluded from further analysis. Reference construction involved a 20% random sampling of the majority cell types with detailed annotations from the celltype_update
column.