Load the library and the data
library(SpaGene)
load("HDST/CN24_D1_unmodgtf_filtered_red_ut_HDST_final_clean.rds")
Find spatially variable genes and patterns
hdst_sv<-SpaGene_sparse(sp_count,location)
# the most signifiant spatially variable genes
head(hdst_sv$spagene_res[order(hdst_sv$spagene_res$adjp),],10)
## score zval pval adjp
## mt-Rnr2 14.01820 -67.56722 0.000000e+00 0.000000e+00
## mt-Rnr1 14.33820 -46.04062 0.000000e+00 0.000000e+00
## Ptgds 444.95500 -30.74712 6.681083e-208 9.384694e-205
## CT010467.1 44.97687 -26.56462 8.704286e-156 9.169966e-153
## Gphn 14.67430 -23.43138 1.023413e-121 8.625321e-119
## Cdk8 45.09453 -22.53987 8.440865e-113 5.928301e-110
## mt-Tm 156.92063 -22.21707 1.174485e-109 7.070403e-107
## mt-Th 157.08562 -19.38009 5.682459e-84 2.993235e-81
## Camk1d 14.76844 -17.09848 7.615995e-66 3.565978e-63
## Gm42418 14.77555 -16.62023 2.487073e-62 1.048053e-59
pattern<-FindPattern(hdst_sv)
PlotPattern(pattern,location,pt.size = 0.05)

Top 5 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,])
