单细胞数据挖掘实战:文献复现(二)批量创建Seurat对象及质控
这里的MG 和 Mo/MΦ 评分定义为在给定群体中高度表达基因的平均表达水平,主要复现一下Fig. 3
一、加载R包
if(T){
if(!require(BiocManager))install.packages("BiocManager")
if(!require(Seurat))install.packages("Seurat")
if(!require(Matrix))install.packages("Matrix")
if(!require(ggplot2))install.packages("ggplot2")
if(!require(cowplot))install.packages("cowplot")
if(!require(magrittr))install.packages("magrittr")
if(!require(dplyr))install.packages("dplyr")
if(!require(purrr))install.packages("purrr")
if(!require(ggrepel))install.packages("ggrepel")
if(!require(ggpubr))install.packages("ggpubr")
}
二、添加conditon
table(seu_object$orig.ident)
#GSM4039241-F-ctrl-1 GSM4039242-F-ctrl-2 GSM4039243-F-tumor-1
# 5151 4781 4878
#GSM4039244-F-tumor-2 GSM4039245-M-ctrl-1 GSM4039246-M-ctrl-2
# 5467 4786 5218
#GSM4039247-M-tumor-1 GSM4039248-M-tumor-2
# 4091 4891
group <- c(rep("ctrl",times = 5151),
rep("ctrl",times = 4781),
rep("tumor",times = 4878),
rep("tumor",times = 5467),
rep("ctrl",times = 4786),
rep("ctrl",times = 5218),
rep("tumor",times = 4091),
rep("tumor",times = 4891))
seu_object$condition <- group
#fig3a
DimPlot(seu_object, group.by = "condition" )
1.png
三、按基因表达平均值进行打分
micro_score
col_Micro<-"#53AFE6"
col_Macro<-"#FABF00"
gene_expression_data <- GetAssayData(object = seu_object, slot = "data")
genes_micro01 <- c("Tmem119", "P2ry12", "Cx3cr1", "Olfml3", "Sparc","Gpr34")
gene_expression_data_micro <- gene_expression_data[genes_micro01, ]
seu_object$micro_score <- colMeans(gene_expression_data_micro)
# Figure 3b
#上半部分
FeaturePlot(seu_object, features = "micro_score")
2.png
macro_score
genes_macro01 <- c("Ifitm2", "S100a6", "S100a11", "Lgals3", "Isg15", "Ms4a4c", "Crip1")
gene_expression_data_macro <- gene_expression_data[genes_macro01, ]
seu_object$macro_score <- colMeans(gene_expression_data_macro)
# Feature Plots
FeaturePlot(seu_object, features = "macro_score")
3.png
Figure 3c
col_CTRL<- "#636775"
col_TUMOR<-"#F44686"
cell_types_labels <- c("MG", "Mo/MΦ")
names(cell_types_labels) <- c("Microglia", "Macrophages")
scores_data <- data.frame(micro01 = seu_object$micro_score, macro01 = seu_object$macro_score,
condition = seu_object$condition,
cell_types_3_groups = Idents(seu_object))
MG<-ggplot(scores_data[scores_data$cell_types_3_groups %in% c("MG", "Mo/MΦ"),],
aes(x=condition, y= micro01))+
geom_violin(aes(fill=condition), scale = "area", trim=F, size=0.5)+
facet_grid(.~cell_types_3_groups, labeller = labeller(cell_types_3_groups=cell_types_labels))+
xlab("")+
ylab("MG score")+
scale_fill_manual(values=c(col_CTRL, col_TUMOR))+
theme_classic(base_size=14)
MoM<-ggplot(scores_data[scores_data$cell_types_3_groups %in% c("MG", "Mo/MΦ"),],
aes(x=condition, y= macro01))+
geom_violin(aes(fill=condition), scale="area", trim=F, size=0.5)+
facet_grid(.~cell_types_3_groups, labeller = labeller(cell_types_3_groups = cell_types_labels))+
xlab("")+
ylab("MoM score")+
scale_fill_manual(values=c(col_CTRL, col_TUMOR))+
theme_classic(base_size=14)
pdf(("fig3b.pdf"), onefile = FALSE, width = 15, height = 15)
ggarrange(MG, MoM, nrow = 2, common.legend=T)
dev.off()
4.png
往期单细胞数据挖掘实战: