5_addmodule空转spatial空转打分模块inflammatory炎症评分空转炎症评分 addmodule seurat
5_addmodule空转spatial空转打分模块inflammatory炎症评分 addmodule seurat
library(Hmisc)
load("G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster/d_all/silicosis_ST_harmony_SCT_r0.6.rds")
inflammatory_gene=read.xlsx("G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster/HALLMARK_INFLAMMATORY_RESPONSE.xlsx")
head(inflammatory_gene)
inflammatory_gene=capitalize(tolower(inflammatory_gene$gene_symbol)) %>% list()
inflammatory_gene
#对给定的基因集合进行打分
d.all=AddModuleScore(d.all,
features = inflammatory_gene,
name = "inflammatory_gene")
#结果保存在这里
colnames(d.all@meta.data)
#默认的slot为"SCT"中的 data slot
DefaultAssay(d.all)
d.all@assays$SCT@counts[1:19,1:3]
d.all@assays$SCT@data[1:19,1:3]
d.all@assays$SCT@scale.data[1:19,1:3]
SpatialFeaturePlot(d.all,features = "inflammatory_gene1", slot = "scale.data")+
ggtitle(paste(inflammatory_gene[[1]], collapse = "|"))
getwd()
setwd("G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster")
myfeaturename="inflammatory_gene1"
cellname="d.all"
mymarker=inflammatory_gene
number=length(unlist(mymarker))
p1=SpatialFeaturePlot(d.all, features = myfeaturename, slot = "scale.data",images = "image")+ ggtitle(paste(unlist(mymarker), collapse = "|"))
p2=SpatialFeaturePlot(d.all, features = myfeaturename, slot = "scale.data",images = "image.1")
p3=SpatialFeaturePlot(d.all, features = myfeaturename, slot = "scale.data",images = "image.2")+ ggtitle(paste(cellname))
p4=SpatialFeaturePlot(d.all, features = myfeaturename, slot = "scale.data",images = "image.3")
jpeg(paste0(cellname,"_","total_",length(unlist(mymarker)),"_",paste0(min(number),"-",max(number)),
paste(unlist(mymarker)[1:15],collapse = "_"),"_.jpeg"), #只取前15个
height = 12, width = 12, units = 'in', res=600)
p=ggpubr::ggarrange(p1,p2,p3,p4,ncol = 2,nrow =2)
print(p)
dev.off()