zl程序教程

您现在的位置是:首页 >  其他

当前栏目

从findallmarkers函数得到的marker基因表格批量画dotplot气泡图 批量dotplot 批量出图

批量 函数 表格 得到 基因 气泡 marker
2023-09-14 09:09:48 时间

rm(list=ls())
library(CellChat)
###从findallmarkers函数得到的marker基因表格批量画dotplot气泡图
library(patchwork)
library(ggplot2)
library(ggalluvial)
library(svglite)
library(Seurat)
library(openxlsx)

library(harmony)
options(stringsAsFactors = FALSE)

getwd()
path = “G:/silicosis/sicosis/yll/all_SingleCell_markers_dotplot-combined”
dir.create(path,recursive = TRUE)
setwd(path)
getwd()
library(clusterProfiler)
library(org.Mm.eg.db)
k <- keys(org.Mm.eg.db, keytype = “ENTREZID”)
gene.list <- select(org.Mm.eg.db, keys = k, columns = c(“SYMBOL”, “ENSEMBL”), keytype = “ENTREZID”)## 11223 7

cluster_gene_stat = read.xlsx(“G:/silicosis/需求/矽肺-数据分析结果-0324/YLL/combined_cluster_markers.xlsx”)## 4937 35
head(cluster_gene_stat)
#######一定要注意列名!!!!搞错了后面一步怎么都做不出来
在这里插入图片描述

dim(cluster_gene_stat)
在这里插入图片描述

cluster_marker = list()
在这里插入图片描述

#一定要注意列名!!!!搞错了后面一步怎么都做不出来
for(i in unique(cluster_gene_statKaTeX parse error: Expected '}', got '#' at position 12: cluster)){ #̲按照p0.05值、flodch…cluster==i &cluster_gene_statKaTeX parse error: Expected 'EOF', got '&' at position 22: …adj<0.00000001 &̲cluster_gene_st…avg_log2FC>1.5, “gene”]
}
head(cluster_marker)
unlist(lapply(cluster_marker, length))
cluster_marker[[8]]
在这里插入图片描述

load(file = “G:/silicosis/sicosis/silicosis-1122-merge/silicosis_cluster_merge.rds”)
head(cluster_marker[[1]])

getwd()

#批量做气泡图 Dotplot 记得修改allmerge的名字如果是其他数据的话
for (j in 1:length(cluster_marker)) {#一定要记得是向量 而不是一个数 for j in(1:11) 一定记得加括号!!!!!!!!!!!!
#j=1
times=(length(cluster_marker[[j]])+10)/10
times

if (floor(times)>=2 ){
try(for (i in seq(1,190,10)) { #使用循环出图 画图 以最多的基因数目为准!!!!!!!!!!!!!!!!!!1
#i=1
if ((i+9)>(10*floor(times))) {next}
# print(cluster_marker[[j]][i:(i+9)])
jpeg(paste0(“cluster_”,j,"",unique(cluster_gene_stat$cluster)[j],
paste0(unlist(strsplit(cluster_marker[[j]][i:(i+9)], " "))[seq(1,10,1)],
seq='
',collapse = “”) , “.jpeg”),
height = 9, width = 18, units = ‘in’, res=300)
p=DotPlot(All.merge,
features = cluster_marker[[j]][i:(i+9)])
print§
dev.off()
print(paste0(“cluster_”,j))#;print(cluster_marker[[j]][i:(i+9)])
} ,silent = TRUE)

} else{ #条件一定记得加括号! !!!!!!!!!!!!!!!11!!!!!!!!!!!
print(paste0(“cluster_”,j))#; print(cluster_marker[[j]][1:(1+9)])
jpeg(paste0(“cluster_”,j,"",unique(cluster_gene_stat$cluster)[j],
paste0(unlist(strsplit(cluster_marker[[j]][1:(1+9)], " "))[seq(1,10,1)],seq='
',collapse = “”),
“.jpeg”),
height = 9, width = 18, units = ‘in’, res=300)
p=DotPlot(All.merge,features = cluster_marker[[j]][1:(1+9)])
print§
dev.off()
}
}

DotPlot(All.merge,features = cluster_marker[[7]][1:10])

for (i in length(cluster_marker)) { #使用循环出图 画图
#i=1

jpeg(paste0(paste0(unlist(strsplit(top_features_moransi[i:(i+2)], " “))[seq(1,3,1)],seq=‘_’,collapse = “”),”.jpeg"),height = 12, width = 12, units = ‘in’, res=700)
p=SpatialFeaturePlot(d.all_moransi,
features = top_features_moransi[i:(i+2)],
ncol = 2,alpha = c(0.1,1))
print§
dev.off()
print(i)
}

结果 示例图样图
在这里插入图片描述