单细胞数据复现-肺癌文章代码复现7

2022-06-09 21:45:08 浏览数 (3)

单细胞数据复现-肺癌文章代码复现1https://cloud.tencent.com/developer/article/1992648

单细胞数据复现-肺癌文章代码复现2https://cloud.tencent.com/developer/article/1995619

单细胞数据复现-肺癌文章代码复现3https://cloud.tencent.com/developer/article/1996043

单细胞数据复现-肺癌文章代码复现4https://cloud.tencent.com/developer/article/2006654

单细胞数据复现-肺癌文章代码复现5https://cloud.tencent.com/developer/article/2008487

单细胞数据复现-肺癌文章代码复现6https://cloud.tencent.com/developer/article/2008704

下面主要是对差异基因进行分析,也是按照以前得思路进行样本水平得选取,然后进行归一化,然后进行得markers得确定进行得差异分析。

代码语言:javascript复制
###DEGs macrophages

imm_macro <- subset(imm_anno, subset = cell_type_imm %in% c("Alveolar_Macrophages1",
                                                            "Alveolar_Macrophages2",
                                                            "Alveolar_Macrophages3",
                                                            "CD14_Macrophages1",
                                                            "CD14_Macrophages2",
                                                            "CD14_Macrophages3",
                                                            "CD14_Macrophages4",
                                                            "CD14_Macrophages5",
                                                            "Macrophages_Proliferating"))

imm_macro <- ScaleData(imm_macro)

Idents(imm_macro) <- imm_macro@meta.data$cell_type_imm

macro_markers <- FindAllMarkers(imm_macro, only.pos = T, min.pct = 0.25, min.diff.pct = 0.25)

top_macro_markers <- macro_markers %>% group_by(cluster) %>% top_n(10, wt = avg_log2FC)
##这里得画热图得函数是上几次中运用到得函数,可以展示分组和分群。
DoMultiBarHeatmap(imm_macro, features = top_macro_markers$gene, group.by = "cell_type_imm", additional.group.by = "tissue_type",additional.group.sort.by = "tissue_type", cols.use = list(tissue_type = use_colors), draw.lines = F)  
  scale_fill_viridis()
#ggsave2("HeatMap_Macro.pdf", path = "output/fig4", width = 30, height = 40, units = "cm")
ggsave2("SuppFig7B.png", path = "../results", width = 30, height = 40, units = "cm")
#ggsave2("HeatMap_Macro.emf", path = "output/fig4", width = 30, height = 40, units = "cm")

下面是T细胞得水平得差异基因得计算

代码语言:javascript复制
###DEGs T cells

imm_T <- subset(imm_anno, subset = cell_type_imm %in% c("T_conv1",
                                                        "T_conv2",
                                                        "T_reg",
                                                        "T_CD8_1",
                                                        "T_CD8_2",
                                                        "T_CD8_3",
                                                        "T_CD8_Proliferating"))

imm_T <- ScaleData(imm_T)

Idents(imm_T) <- imm_T@meta.data$cell_type_imm

markers_T <- FindAllMarkers(imm_T, only.pos = T, min.pct = 0.25, min.diff.pct = 0.25)

top_markers_T <- markers_T %>% group_by(cluster) %>% top_n(10, wt = avg_log2FC)

DoMultiBarHeatmap(imm_T, features = top_markers_T$gene, group.by = "cell_type_imm", additional.group.by = "tissue_type",additional.group.sort.by = "tissue_type", cols.use = list(tissue_type = use_colors), draw.lines = F)  
  scale_fill_viridis()
#ggsave2("HeatMap_T.pdf", path = "output/fig4", width = 30, height = 35, units = "cm")没有出来,怀疑是heatmap没有加载出来
ggsave2("SuppFig7C.png", path = "../results", width = 30, height = 35, units = "cm")
#ggsave2("HeatMap_T.emf", path = "output/fig4", width = 30, height = 35, units = "cm")
代码语言:javascript复制
##这里我感觉我没有看懂,但是这些代码基本是没有问题得,所以又做医学得友友给我评论给我讲讲看,谢谢呐
###selected hallmark signatures and M1vsM2 signatures
##一般情况下,如果recursive = FALSE,则unlist只会作用于列表的第一层
m1m2_pws <- read_lines("CLASSICAL_M1_VS_ALTERNATIVE_M2_MACROPHAGE_UP.gmt") %>%
  lapply(str_split, "\t") %>% 
  unlist(recursive = F) %>% 
  lapply(function(x) setNames(list(x[-c(1:2)]), x[1])) %>% 
  unlist(recursive = F)

##append:向向量中增加元素
m1m2_pws <- append(m1m2_pws, read_lines("CLASSICAL_M1_VS_ALTERNATIVE_M2_MACROPHAGE_DN.gmt") %>%
                     lapply(str_split, "\t") %>% 
                     unlist(recursive = F) %>% 
                     lapply(function(x) setNames(list(x[-c(1:2)]), x[1])) %>% 
                     unlist(recursive = F))

imm_anno <- AddModuleScore(object = imm_anno, features = m1m2_pws, name = c("m1up", "m1dn"), nbin = 12)

VlnPlot(imm_anno, features = c("HALLMARK_INFLAMMATORY_RESPONSE31",
                               "HALLMARK_ALLOGRAFT_REJECTION46",
                               "HALLMARK_INTERFERON_GAMMA_RESPONSE19",
                               "HALLMARK_TNFA_SIGNALING_VIA_NFKB1",
                               "m1up1", 
                               "m1dn2"), 
        group.by = "cell_type_imm", pt.size = 0, ncol = 3, idents = c("Alveolar_Macrophages1",
                                                                      "Alveolar_Macrophages2",
                                                                      "Alveolar_Macrophages3",
                                                                      "CD14_Macrophages1",
                                                                      "CD14_Macrophages2",
                                                                      "CD14_Macrophages3",
                                                                      "CD14_Macrophages4",
                                                                      "CD14_Macrophages5",
                                                                      "Macrophages_Proliferating"), cols = use_colors)
ggsave2("Fig4C.pdf", path = "../results", width = 30, height = 20, units = "cm")


###T cell signatures

T_exhausted <- read_excel("CD8_T_cells_exhausted.xlsx", skip = 1)
cytotoxicity <- c("PRF1", "IFNG", "GNLY", "NKG7", "GZMB", "GZMA", "GZMH", "KLRK1", "KLRB1", "KLRD1", "CTSW", "CST7")

T_cell_markers <- list(T_exhausted$GeneSymbol, cytotoxicity)

imm_T <- AddModuleScore(imm_T, features = T_cell_markers, name = c("exhaustion", "cytotoxicity"), nbin = 12)

VlnPlot(imm_T, features = c("cytotoxicity2", "exhaustion1"), pt.size = 0, group.by = "cell_type_imm", cols = use_colors, idents = c("T_CD8_1", "T_CD8_2", "T_CD8_3", "T_CD8_Proliferating"), ncol = 1)
ggsave2("Fig4F.pdf", path = "../results", width = 10, height = 20, units = "cm")

0 人点赞