单细胞数据挖掘实战:文献复现(五)细胞亚群并可视化

2022-08-13  本文已影响0人  生信开荒牛

单细胞数据挖掘实战:文献复现(一)批量读取数据

单细胞数据挖掘实战:文献复现(二)批量创建Seurat对象及质控

单细胞数据挖掘实战:文献复现(三)降维、聚类和细胞注释

单细胞数据挖掘实战:文献复现(四)细胞比例饼图

复现Figure 2a左边那张图

一、加载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")
}

二、数据处理

#挑选MG, Mo/MΦ,BAM三个细胞簇
Idents(sex_condition_objects[[1]]) <- sex_condition_objects[[1]]@meta.data$cell_type_selection
table(Idents(sex_condition_objects[[1]]))
#Microglia       BAM 
#     9454       500
clusters_taken_1 <- subset(sex_condition_objects[[1]], idents = c("Microglia","BAM"))

Idents(sex_condition_objects[[2]]) <- sex_condition_objects[[2]]@meta.data$cell_type_selection
table(Idents(sex_condition_objects[[2]]))
#Macrophages               Microglia         BAM 
#       2131        1658        6981         375
clusters_taken_2 <- subset(sex_condition_objects[[2]], idents = c("Microglia","Macrophages","BAM"))

Idents(sex_condition_objects[[3]]) <- sex_condition_objects[[3]]@meta.data$cell_type_selection
table(Idents(sex_condition_objects[[3]]))
#Microglia       BAM           
#     9078       619       362
clusters_taken_3 <- subset(sex_condition_objects[[3]], idents = c("Microglia","BAM"))

Idents(sex_condition_objects[[4]]) <- sex_condition_objects[[4]]@meta.data$cell_type_selection
table(Idents(sex_condition_objects[[4]]))
#Macrophages   Microglia                     BAM 
#       2301        6071         527         344 
clusters_taken_4 <- subset(sex_condition_objects[[4]], idents = c("Microglia","Macrophages","BAM"))

clusters_taken_list <-  c(clusters_taken_1,clusters_taken_2,clusters_taken_3,
                          clusters_taken_4)  
names(clusters_taken_list) <- names(sex_condition_objects)


# Normalize 
clusters_objects <- lapply(clusters_taken_list, function(cluster_sample_object) {
  cluster_sample_object <- ScaleData(cluster_sample_object)
  cluster_sample_object
})

三、画图

# f_ctrl
DimPlot(clusters_taken_list[[1]],cols = c("#0cd2ae","#52b0e6"),  group.by = "cell_type_selection")
# f_tumor
DimPlot(clusters_taken_list[[2]], cols = c("#0cd2ae","#fcc000","#52b0e6"),group.by = "cell_type_selection")
# m_ctrl
DimPlot(clusters_taken_list[[3]], cols = c("#0cd2ae","#52b0e6"),group.by = "cell_type_selection")
# m_tumor
DimPlot(clusters_taken_list[[4]], cols = c("#0cd2ae","#fcc000","#52b0e6"),group.by = "cell_type_selection")

将四幅图简单合并一下并与文献原图比较

cell_type.png

往期单细胞数据挖掘实战

单细胞数据挖掘实战:文献复现(一)批量读取数据

单细胞数据挖掘实战:文献复现(二)批量创建Seurat对象及质控

单细胞数据挖掘实战:文献复现(三)降维、聚类和细胞注释

单细胞数据挖掘实战:文献复现(四)细胞比例饼图

上一篇下一篇

猜你喜欢

热点阅读