zl程序教程

您现在的位置是:首页 >  云平台

当前栏目

seurat的 addmodule循环画图 等同于基因的叠加图 识别细胞类型 空转与单细胞得到的marker基因联合

识别循环 类型 联合 得到 画图 基因 单细胞
2023-09-14 09:09:48 时间

seurat的 addmodule循环画图 等同于基因的叠加图 识别细胞类型 空转与单细胞得到的marker基因联合

library(patchwork)
library(ggplot2)
library(ggalluvial)
library(svglite)
library(Seurat)
library(openxlsx)
library(Hmisc)
#https://www.jianshu.com/p/cef5663888ff
getwd()
path=“G:/silicosis/sicosis/silicosis_ST/overlapped_map/addmodule”
dir.create(path)
setwd(path)

load(“G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster/d_all/silicosis_ST_harmony_SCT_r0.6.rds”)

marker=read.xlsx(“G:/silicosis/sicosis/silicosis_ST/overlapped_map/Rigional and cell markers.xlsx”,
sheet = “SingleCell_markers”)
head(marker)
在这里插入图片描述

library(dplyr)
#开始循环画图

cellnames=colnames(marker) ##number=length(marker[,cellname])

for (each in cellnames) {
cellname=each
mymarker=marker[,cellname] %>% na.exclude() %>% unique() %>%
capitalize() %>% list()
number=length(mymarker[[1]])
unlist(mymarker)
在这里插入图片描述#对给定的基因集合进行打分 并画图
if(1==1){d.all=AddModuleScore(d.all,
features = mymarker,
name = “mymarker”)
#结果保存在这里
colnames(d.all@meta.data)

p1=SpatialFeaturePlot(d.all, features = “mymarker1”, slot = “scale.data”,images = “image”)+ ggtitle(paste(unlist(mymarker), collapse = “|”))
p2=SpatialFeaturePlot(d.all, features = “mymarker1”, slot = “scale.data”,images = “image.1”)
p3=SpatialFeaturePlot(d.all, features = “mymarker1”, slot = “scale.data”,images = “image.2”)+ ggtitle(paste(cellname))
p4=SpatialFeaturePlot(d.all, features = “mymarker1”, 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§
dev.off()}
}
在这里插入图片描述

#下面的代码是为了测试
if(1==1){#
names(d.all)

SpatialFeaturePlot(d.all, features = “mymarker1”, slot = “scale.data”)+
ggtitle(paste(unlist(mymarker), collapse = “|”))

#https://ggplot2-book.org/polishing.html?q=title#themes
SpatialFeaturePlot(d.all, features = “mymarker1”, slot = “scale.data”)+
theme(plot.title =element_text(paste(unlist(mymarker), collapse = “|”)) )

SpatialFeaturePlot(d.all, features = “mymarker1”, slot = “scale.data”)+
labs(title = paste(unlist(mymarker), collapse = “|”),
colour=“Cylinders”)

}
在这里插入图片描述