Load the library and the data
library(SpaGene)
load("BreastCancer/bc_raw.rds")
Find spatially variable genes and patterns
bc_spagene<-SpaGene(count,location)
# the most signifiant spatially variable genes
head(bc_spagene$spagene_res[order(bc_spagene$spagene_res$adjp),])
## score zval pval adjp
## COL12A1 8.48 -16.17570 3.741996e-59 5.534038e-55
## FN1 8.52 -16.06389 2.284824e-58 1.689513e-54
## COL3A1 8.72 -15.50484 1.608692e-54 7.930316e-51
## COL1A2 8.88 -15.05759 1.538985e-51 5.690014e-48
## B2M 9.16 -14.27491 1.568364e-46 3.865755e-43
## COL1A1 9.16 -14.27491 1.568364e-46 3.865755e-43
pattern<-FindPattern(bc_spagene)
PlotPattern(pattern,location)

Top five genes falling into each pattern
top5<-apply(pattern$genepattern,2,function(x){names(x)[order(x,decreasing=T)][1:5]})
library(pheatmap)
pheatmap(pattern$genepattern[rownames(pattern$genepattern)%in%top5,])

Identify colocalized ligand-receptor pairs
load("LRpair_human.rds")
bc_lr<-SpaGene_LR(count,location,LRpair=LRpair)
# the most signficant colocalized LR pairs
head(bc_lr[order(bc_lr$adj),])
## score comm zval pval adjp
## COL1A2_ITGA11 28.36 18 -10.176989 1.256075e-24 2.348861e-21
## FN1_SDC2 28.68 19 -9.034053 8.271455e-20 7.733810e-17
## COL1A1_ITGA11 28.88 16 -8.319718 4.408658e-17 2.748063e-14
## FN1_CD44 28.92 18 -8.176851 1.456795e-16 6.810516e-14
## COL1A2_ITGB1 29.12 20 -7.462516 4.244301e-14 1.587369e-11
## COL1A1_ITGB1 29.16 15 -7.319648 1.243107e-13 3.320871e-11
Plot the ligand-receptor pair FN1-CD44
plotLR(count,location,LRpair=c("FN1","CD44"),alpha.min=0.5)
