Load the library and the data
library(SpaGene)
load("mob/mob_raw.rds")
Find spatially variable genes and patterns
mob_spagene<-SpaGene(count,location)
# the most signifiant spatially variable genes
head(mob_spagene$spagene_res[order(mob_spagene$spagene_res$adjp),])
## score zval pval adjp
## Fabp7 7.538462 -18.94082 2.628353e-80 4.262663e-76
## Mcf2l 8.038462 -17.52315 4.769929e-69 3.867936e-65
## Igfbp5 8.461538 -16.32357 3.354493e-60 1.813439e-56
## Omp 8.500000 -16.21452 1.990813e-59 8.071750e-56
## Apoe 8.769231 -15.45116 3.705045e-54 1.201768e-50
## Nr2f2 8.846154 -15.23305 1.066947e-52 2.471963e-49
pattern<-FindPattern(mob_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.rds")
mob_lr<-SpaGene_LR(count,location,LRpair=LRpair)
# the most signficant colocalized LR pairs
head(mob_lr[order(mob_lr$adj),])
## score comm zval pval adjp
## Igfbp5_Cav1 28.00000 25 -12.165406 2.375400e-34 3.135528e-31
## Apoe_Lrp6 28.73077 22 -9.403844 2.630265e-21 1.735975e-18
## Apoe_Abca1 28.92308 24 -8.677117 2.029633e-18 8.930387e-16
## Igfbp4_Lrp6 29.23077 21 -7.514354 2.859622e-14 9.436753e-12
## Apoe_Scarb1 29.38462 19 -6.932973 2.060434e-12 5.439545e-10
## Apoe_Sdc4 29.46154 20 -6.642282 1.544313e-11 3.397488e-09
Plot the ligand-receptor pair Apoe-Lrp6
plotLR(count,location,LRpair=c("Apoe","Lrp6"),alpha.min=0.5)
