library(SPER)
##  Other necessary libraries
library(Seurat)
if (!require("ggpubr")) install.packages("ggpubr")
library(ggpubr)

Example: adult mouse brain spatial transciptomics dataset

Dataset

####  Spatial transcriptomics data
head(ST_expression_data)

####  Coordinates & Distance matrix
head(ST_coordinates)
spot_dist <- as.matrix(dist(ST_coordinates))
round_dist_mat <- ceiling(spot_dist / 120) * 120
round_dist_mat[which(round_dist_mat > 1800)] <- 1800
gg_gene("Grp",
        ST_expression_data,
        coord = ST_coordinates,
        title.anno = "Gene")
####  spatial compositional data
head(spatial_comp_data)
p1 <- gg_gene("L2.3.IT",
              spatial_comp_data,
              coord = ST_coordinates,
              title.anno = "Compositional")
p2 <- gg_gene("L4",
              spatial_comp_data,
              coord = ST_coordinates,
              title.anno = "Compositional")
p3 <- gg_gene("L5.IT",
              spatial_comp_data,
              coord = ST_coordinates,
              title.anno = "Compositional")
p4 <- gg_gene("L6.IT",
              spatial_comp_data,
              coord = ST_coordinates,
              title.anno = "Compositional")
ggarrange(p1, p2, p3, p4)

SPER:

res <- SPER(dist.mat = round_dist_mat,
            dist.list = (0:15)*120,
            ST.mat = ST_expression_data,
            CoDa.data = spatial_comp_data)
res[["L2.3.IT"]][1:10, 1:10]
# custom_weights <- c(rep(1/5, 5), rep(0, 11))
custom_weights <- c(0, 0, rep(1/3, 3), rep(0, 11))
SPER_res <- weightSPER(res,
                       custom_weights)
head(SPER_res)

Find potential paracrine signals by SPER scores

##  Provided cell-type-specific gene sets: P values are unnecessary, as long as it includes 'Gene' and 'Type'
marker_gene <- read.table("~/Desktop/Dropbox_NYU/Dropbox/SPER/SPER_public_data/Data/Marker_gene.txt", 
                          sep = "\t",
                          check.names = F)

##  Ligand-receptor pair dataset: gene1 is the ligand and gene2 is the receptor
LRP_data <- read.table("~/Desktop/Dropbox_NYU/Dropbox/SPER/SPER_public_data/Data/Mouse_LRP_data.txt", 
                       sep = "\t",
                       check.names = F)
##  Expression fraction data: showing genes' expression prevalence in each cell types
example_expr_frac <- read.table("~/Desktop/Dropbox_NYU/Dropbox/SPER/SPER_public_data/Data/Expr_frac_matrix.txt",
                                sep = "\t",
                                check.names = F)
# example_expr_frac <- example_expr_frac[rownames(SPER_res),]
head(example_expr_frac)
L5_IT_signals <- findSPERsignals(target.cell = "L5.IT",
                                 score.mat = SPER_res,
                                 expr.frac.mat = example_expr_frac,
                                 marker.gene = marker_gene,
                                 LRP.data = LRP_data)
L5_IT_signals

Visualization:

##  The Allen Mouse Brain Atlas: WHOLE CORTEX & HIPPOCAMPUS - 10X GENOMICS
allen_reference <- readRDS("~/Desktop/Dropbox_NYU/Dropbox/SPER/SPER_public_data/allen_reference_SCT.rds")
allen_reference <- SetIdent(allen_reference,
                            value = "subclass")
plotSPER(cell.type = "L5.IT",
         gene.id = "Grp",
         coord = ST_coordinates,
         ST.data = ST_expression_data,
         CoDa.data = spatial_comp_data,
         reference.data = allen_reference,
         SPER.data = res,
         dist.list = (0:15)*120,
         save.plots = F)


tsinghua-ZTX/SPER documentation built on June 7, 2024, 5:30 a.m.