单细胞多组差异分析-多组火山图

文摘   2024-10-10 23:48   江苏  

1#预处理

1#预处理.libPaths(c("/refdir/Rlib/",              "/home/data/t040413/R/x86_64-pc-linux-gnu-library/4.2",            "/usr/local/lib/R/library"))
library(Seurat)
getwd()setwd("/home/data/t040413/xiwen/")pbmc=readRDS("./immune.combined.rds")
head(pbmc@meta.data)
table(pbmc$seurat_clusters)'''#table(pbmc$stim)table(pbmc$celltype.stim)pbmc$group=pbmc$stimpbmc$orig.celltype=pbmc$celltypepbmc$celltype.group <- as.factor(paste(pbmc$celltype, pbmc$group, sep = "_"))pbmc$celltype <- pbmc$celltype.groupIdents(pbmc) <- "celltype.group"'''pbmc$celltype.group=pbmc$celltype.stimpbmc$celltype=pbmc$seurat_clustersIdents(pbmc)=pbmc$celltype.group
cellfordeg<-levels(pbmc$celltype)
data_forplot=data.frame()
for(i in 1:length(cellfordeg)){ # CELLDEG <- FindMarkers(pbmc, ident.1 = paste0(cellfordeg[i],"_PT"), ident.2 = paste0(cellfordeg[i],"_sham"), verbose = FALSE) CELLDEG$gene=rownames(CELLDEG) CELLDEG$cluster=cellfordeg[i] write.csv(CELLDEG,paste0(cellfordeg[i],"PT_VS_Sham.CSV")) data_forplot=rbind(CELLDEG,data_forplot)
}head(data_forplot)table(data_forplot$cluster)
getwd()save(data_forplot,file="data_forplot.rds")


2#加载数据

#加载数据load("/home/data/t040413/xiwen/data_forplot.rds")#request 2===========================================================----------------------------------------------------------.libPaths(c( "/home/data/t040413/R/x86_64-pc-linux-gnu-library/4.2",             "/home/data/t040413/R/yll/usr/local/lib/R/site-library",               "/refdir/Rlib/", "/usr/local/lib/R/library"))library(Seurat)
library(scRNAtoolVis)library(colourpicker)

markers_for_all_3groups=data_forplot
head(markers_for_all_3groups)getwd()

# plot

jjVolcano(diffData = markers_for_all_3groups, legend.position = c(0.93, 0.99), topGeneN=2,#top genes to be labeled in plot, default 5. cluster.order=seq(0,23,1), pSize=0.4, tile.col = c("#EE3B3B", "#FF7F00", "#CD6600", "#8B2323", "#DEB887", "#76EEC6", "#F0FFFF", "#008B8B", "#FFB90F", "#F5F5DC", "#1F1F1F", "#66CD00", "#0000FF", "#97FFFF", "#528B8B", "#9400D3", "#EE1289", "#00BFFF", "#00FF00", "#191970", "#FFFF00", "#4A708B", "#00FF7F", "#8B8B00", "#FF1493", "#FFA500", "#8B4513"))

ggsave("./1_differential_genes_indifferent_clusters.pdf",width = 20,height = 7,dpi = 900,limitsize = FALSE)


jjVolcano(diffData = markers_for_all_3groups, legend.position = c(0.93, 0.99), topGeneN=0,#top genes to be labeled in plot, default 5. cluster.order=seq(0,23,1), pSize=0.4, tile.col = c("#EE3B3B", "#FF7F00", "#CD6600", "#8B2323", "#DEB887", "#76EEC6", "#F0FFFF", "#008B8B", "#FFB90F", "#F5F5DC", "#1F1F1F", "#66CD00", "#0000FF", "#97FFFF", "#528B8B", "#9400D3", "#EE1289", "#00BFFF", "#00FF00", "#191970", "#FFFF00", "#4A708B", "#00FF7F", "#8B8B00", "#FF1493", "#FFA500", "#8B4513"))

ggsave("./1_differential_genes_indifferent_clusters_nogenes.pdf",width = 20,height = 7,dpi = 900,limitsize = FALSE)


jjVolcano(diffData = markers_for_all_3groups, legend.position = c(0.93, 0.99), topGeneN=0,#top genes to be labeled in plot, default 5. cluster.order=seq(0,23,1), pSize=0.4, tile.col = c("#EE3B3B", "#FF7F00", "#CD6600", "#8B2323", "#DEB887", "#76EEC6", "#F0FFFF", "#008B8B", "#FFB90F", "#F5F5DC", "#1F1F1F", "#66CD00", "#0000FF", "#97FFFF", "#528B8B", "#9400D3", "#EE1289", "#00BFFF", "#00FF00", "#191970", "#FFFF00", "#4A708B", "#00FF7F", "#8B8B00", "#FF1493", "#FFA500", "#8B4513"))

ggsave("./1_differential_genes_indifferent_clusters_nogenes_.pdf",width = 14,height = 7,limitsize = FALSE,dpi = 900)

jjVolcano(diffData = markers_for_all_3groups, legend.position = c(0.93, 0.99), topGeneN=0,#top genes to be labeled in plot, default 5. cluster.order=seq(0,23,1), pSize=0.4, tile.col = c("#EE3B3B", "#FF7F00", "#CD6600", "#8B2323", "#DEB887", "#76EEC6", "#F0FFFF", "#008B8B", "#FFB90F", "#F5F5DC", "#1F1F1F", "#66CD00", "#0000FF", "#97FFFF", "#528B8B", "#9400D3", "#EE1289", "#00BFFF", "#00FF00", "#191970", "#FFFF00", "#4A708B", "#00FF7F", "#8B8B00", "#FF1493", "#FFA500", "#8B4513"))

ggsave("./1_differential_genes_indifferent_clusters_nogenes___.pdf",width = 10,height = 7,limitsize = FALSE,dpi = 900)



#############################################3head(markers_for_all_3groups)openxlsx::write.xlsx(markers_for_all_3groups,file = "./differential_genes_between_three_groups.xlsx")


# change aes color typejjVolcano(diffData = markers_for_all_3groups, log2FC.cutoff = 0.5, col.type = "adjustP", topGeneN = 3)
# supply own genesmygene <- c('PD-1', 'TIM3', 'TIGHT', 'CTLA-4', 'CD244', 'CD39', 'CD73')
jjVolcano(diffData = markers_for_all_3groups,legend.position = c(0.9,0.99), myMarkers = mygene)


生信小博士
【生物信息学】R语言开始,学习生信。Seurat,单细胞测序,空间转录组。 Python,scanpy,cell2location。资料分享
 最新文章