library(SPER) ## Other necessary libraries library(Seurat) if (!require("ggpubr")) install.packages("ggpubr") library(ggpubr)
#### 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)
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]
Above results shows the SPER between L2/3 IT cell type and all genes. For example, for the 1st column, the values represents the spatial association between Grp and L2/3 IT cells at the given distance (0, 120 microns, 240 microns, etc.). Higher value means the gene is spatially more associated with the cells.
However, it will be impractical to compare the whole column between pairs. Therefore, we can apply a customized weight on the column so that we can integrate the values into one score, which is SPER score.
# 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)
## 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
To visualize our SPER results, we may need more data than what have been provided in the package. Specifically, we will need: 1) an external single-cell RNA-seq reference, which can be used as a validation to tell you gene's expression profile across cell types; 2) cell-type-specific gene list (marker gene list). As SPER detects spatial association, there is no wonder that cell-type-specific genes will be highly associated with their own cells and thus having a high SPER score. In order to remove them from our result, it would be better if we can have such a list of genes and find the difference between it and our SPER results. 3) ligand-receptor pair database (or other specified background). Since we are trying to find potential paracrine signals, they should be expected to be enriched in the ligand gene set or at least extracellular gene set. Furthermore, with the help of ligand-receptor pair information, we can evaluate the receptor's expression patterns in the target cells as a validation.
All of the above datasets are too large to be included in a package, so one can download them from the Dropbox link and run the below codes by themselves.
## 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)
spatial plot of Grp and L5/IT
Grp expression profile in scRNA reference data
SPER curve of Grp&L5/IT pair
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.