今天接著單細(xì)胞文章的內(nèi)容:
跟著Cell學(xué)單細(xì)胞轉(zhuǎn)錄組分析(二):單細(xì)胞轉(zhuǎn)錄組測序文件的讀入及Seurat對(duì)象構(gòu)建
跟著Cell學(xué)單細(xì)胞轉(zhuǎn)錄組分析(三):單細(xì)胞轉(zhuǎn)錄組數(shù)據(jù)質(zhì)控(QC)及合并去除批次效應(yīng)
跟著Cell學(xué)單細(xì)胞轉(zhuǎn)錄組分析(四):單細(xì)胞轉(zhuǎn)錄組測序UMAP降維聚類
跟著Cell學(xué)單細(xì)胞轉(zhuǎn)錄組分析(五):單細(xì)胞轉(zhuǎn)錄組marker基因鑒定及細(xì)胞群注釋
前面幾期主要說了下每個(gè)階段出現(xiàn)圖的個(gè)性化修飾琳猫,后面依然如此奶浦,有需要值得單拎出來說的,我們也是會(huì)講到捎迫。
細(xì)胞分群命名完成之后晃酒,大多數(shù)研究會(huì)關(guān)注各個(gè)樣本細(xì)胞群的比例,尤其是免疫學(xué)的研究中窄绒,各群免疫細(xì)胞比例的變化是比較受關(guān)注的贝次。所以這里說說細(xì)胞群比例的計(jì)算,以及如何可視化彰导。
1蛔翅、堆疊柱狀圖
這是比較普通也是最常用的細(xì)胞比例可視化方法。這種圖在做微生物菌群的研究中非常常見位谋。具體的思路是計(jì)算各個(gè)樣本中細(xì)胞群的比例山析,形成數(shù)據(jù)框之后轉(zhuǎn)化為長數(shù)據(jù),用ggplot繪制即可掏父。
table(scedata$orig.ident)#查看各組細(xì)胞數(shù)
#BM1 BM2 BM3 GM1 GM2 GM3
#2754 747 2158 1754 1528 1983
prop.table(table(Idents(scedata)))
table(Idents(scedata), scedata$orig.ident)#各組不同細(xì)胞群細(xì)胞數(shù)
#BM1 BM2 BM3 GM1 GM2 GM3
# Endothelial 752 244 619 716 906 1084
# Fibroblast 571 135 520 651 312 286
# Immune 1220 145 539 270 149 365
# Epithelial 69 62 286 62 82 113
# Other 142 161 194 55 79 135
Cellratio <- prop.table(table(Idents(scedata), scedata$orig.ident), margin = 2)#計(jì)算各組樣本不同細(xì)胞群比例
Cellratio
#BM1 BM2 BM3 GM1 GM2 GM3
# Endothelial 0.27305737 0.32663989 0.28683967 0.40820981 0.59293194 0.54664650
# Fibroblast 0.20733479 0.18072289 0.24096386 0.37115165 0.20418848 0.14422592
# Immune 0.44299201 0.19410977 0.24976830 0.15393387 0.09751309 0.18406455
# Epithelial 0.02505447 0.08299866 0.13253012 0.03534778 0.05366492 0.05698437
# Other 0.05156137 0.21552878 0.08989805 0.03135690 0.05170157 0.06807867
Cellratio <- as.data.frame(Cellratio)
colourCount = length(unique(Cellratio$Var1))
library(ggplot2)
ggplot(Cellratio) +
geom_bar(aes(x =Var2, y= Freq, fill = Var1),stat = "identity",width = 0.7,size = 0.5,colour = '#222222')+
theme_classic() +
labs(x='Sample',y = 'Ratio')+
coord_flip()+
theme(panel.border = element_rect(fill=NA,color="black", size=0.5, linetype="solid"))
2笋轨、批量統(tǒng)計(jì)圖
很多時(shí)候,我們不僅想關(guān)注各個(gè)樣本中不同細(xì)胞群的比例赊淑,而且更想指導(dǎo)他們?cè)诓煌瑯颖局械淖兓欠窬哂酗@著性爵政。這時(shí)候,除了要計(jì)算細(xì)胞比例外陶缺,還需要進(jìn)行顯著性檢驗(yàn)钾挟。這里我們提供了一種循環(huán)的做法,可以批量完成不同樣本細(xì)胞比例的統(tǒng)計(jì)分析及可視化饱岸。
table(scedata$orig.ident)#查看各組細(xì)胞數(shù)
prop.table(table(Idents(scedata)))
table(Idents(scedata), scedata$orig.ident)#各組不同細(xì)胞群細(xì)胞數(shù)
Cellratio <- prop.table(table(Idents(scedata), scedata$orig.ident), margin = 2)#計(jì)算各組樣本不同細(xì)胞群比例
Cellratio <- data.frame(Cellratio)
library(reshape2)
cellper <- dcast(Cellratio,Var2~Var1, value.var = "Freq")#長數(shù)據(jù)轉(zhuǎn)為寬數(shù)據(jù)
rownames(cellper) <- cellper[,1]
cellper <- cellper[,-1]
###添加分組信息
sample <- c("BM1","BM2","BM3","GM1","GM2","GM3")
group <- c("BM","BM","BM","GM","GM","GM")
samples <- data.frame(sample, group)#創(chuàng)建數(shù)據(jù)框
rownames(samples)=samples$sample
cellper$sample <- samples[rownames(cellper),'sample']#R添加列
cellper$group <- samples[rownames(cellper),'group']#R添加列
###作圖展示
pplist = list()
sce_groups = c('Endothelial','Fibroblast','Immune','Epithelial','Other')
library(ggplot2)
library(dplyr)
library(ggpubr)
for(group_ in sce_groups){
cellper_ = cellper %>% select(one_of(c('sample','group',group_)))#選擇一組數(shù)據(jù)
colnames(cellper_) = c('sample','group','percent')#對(duì)選擇數(shù)據(jù)列命名
cellper_$percent = as.numeric(cellper_$percent)#數(shù)值型數(shù)據(jù)
cellper_ <- cellper_ %>% group_by(group) %>% mutate(upper = quantile(percent, 0.75),
lower = quantile(percent, 0.25),
mean = mean(percent),
median = median(percent))#上下分位數(shù)
print(group_)
print(cellper_$median)
pp1 = ggplot(cellper_,aes(x=group,y=percent)) + #ggplot作圖
geom_jitter(shape = 21,aes(fill=group),width = 0.25) +
stat_summary(fun=mean, geom="point", color="grey60") +
theme_cowplot() +
theme(axis.text = element_text(size = 10),axis.title = element_text(size = 10),legend.text = element_text(size = 10),
legend.title = element_text(size = 10),plot.title = element_text(size = 10,face = 'plain'),legend.position = 'none') +
labs(title = group_,y='Percentage') +
geom_errorbar(aes(ymin = lower, ymax = upper),col = "grey60",width = 1)
###組間t檢驗(yàn)分析
labely = max(cellper_$percent)
compare_means(percent ~ group, data = cellper_)
my_comparisons <- list( c("GM", "BM") )
pp1 = pp1 + stat_compare_means(comparisons = my_comparisons,size = 3,method = "t.test")
pplist[[group_]] = pp1
}
library(cowplot)
plot_grid(pplist[['Endothelial']],
pplist[['Fibroblast']],
pplist[['Immune']],
pplist[['Epithelial']],
pplist[['Other']])
好了掺出,以上就是我們的分享了,起到拋磚引玉的效果伶贰,還有很多其他的展示方法蛛砰,不必全都會(huì)罐栈,中意就好黍衙。
更多內(nèi)容請(qǐng)至我的個(gè)人公眾號(hào)《KS科研分享與服務(wù)》