单细胞数据复现-肺癌文章代码复现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
前面通过对epi和str的细胞类群进行分析后,确定了更精确的细胞分群,准备在将imm进行分析后,整合三个的结果,进行结果的相关性分析。
R package及 环境颜色配置加载
代码语言:javascript复制### load libraries
library(Seurat)
library(dplyr)
library(reticulate)
library(sctransform)
library(cowplot)
library(ggplot2)
library(viridis)
library(tidyr)
library(magrittr)
library(reshape2)
library(readxl)
library(stringr)
library(cowplot)
library(scales)
library(readr)
library(progeny)
library(gplots)
library(tibble)
library(grid)
library(rlang)
theme_set(theme_cowplot())
use_colors <- c(
Tumor = "brown2",
Normal = "deepskyblue2",
G1 = "#46ACC8",
G2M = "#E58601",
S = "#B40F20",
Epithelial = "seagreen",
Immune = "darkgoldenrod2",
Stromal = "steelblue",
p018 = "#E2D200",
p019 = "#46ACC8",
p023 = "#E58601",
p024 = "#B40F20",
p027 = "#0B775E",
p028 = "#E1BD6D",
p029 = "#35274A",
p030 = "#F2300F",
p031 = "#7294D4",
p032 = "#5B1A18",
p033 = "#9C964A",
p034 = "#FD6467",
Alveolar_Macrophages1 = "#6bAEd6",
Alveolar_Macrophages2 = "#3182BD",
Alveolar_Macrophages3 = "#08519C",
CD14_Macrophages1= "#fff500",
CD14_Macrophages2= "#FE9929",
CD14_Macrophages3= "#EC7014",
CD14_Macrophages4= "#CC4C02",
CD14_Macrophages5= "#8C2D04",
Macrophages_Proliferating= "#E31A1C",
Monocytes= "#FA9FB5",
Myeloid_Dendritic= "#DD3497",
Plasmacytoid_Dendritic= "#7A0177",
T_conv1= "#c2e699",
T_conv2= "#78c679",
T_reg= "#006837",
T_CD8_1= "#bcbddc",
T_CD8_2= "#9e9ac8",
T_CD8_3= "#807dba",
T_CD8_Proliferating= "#6a51a3",
NK_cells= "#4a1486",
B_cells= "#969696",
Plasma= "#636363",
Mast= "#252525")
数据加载
代码语言:javascript复制#load data
#imm_anno <- readRDS("seurat_objects/imm_anno.RDS")
根据cell_type的类型,确定后续分析的水平因子
代码语言:javascript复制imm_anno@meta.data$cell_type_imm <- ordered(imm_anno@meta.data$cell_type_imm, levels = c("Alveolar_Macrophages1",
"Alveolar_Macrophages2",
"Alveolar_Macrophages3",
"CD14_Macrophages1",
"CD14_Macrophages2",
"CD14_Macrophages3",
"CD14_Macrophages4",
"CD14_Macrophages5",
"Macrophages_Proliferating",
"Monocytes",
"Myeloid_Dendritic",
"Plasmacytoid_Dendritic",
"Mast",
"T_conv1",
"T_conv2",
"T_reg",
"T_CD8_1",
"T_CD8_2",
"T_CD8_3",
"T_CD8_Proliferating",
"NK_cells",
"B_cells",
"Plasma"))
DimPlot(imm_anno, group.by = "tissue_type", cols = use_colors)
#ggsave2("DimPlot_imm_Normal_Tumor.pdf", path = "output/fig4", width = 15, height = 15, units = "cm")
#ggsave2("DimPlot_imm_Normal_Tumor.png", path = "output/fig4", width = 35, height = 15, units = "cm")
DimPlot(imm_anno, group.by = "patient_id", cols = use_colors, pt.size = 0.5)
#ggsave2("DimPlot_imm_patients.pdf", path = "output/fig4", width = 30, height = 15, units = "cm")
ggsave2("SuppFig1C_imm_patients.png", path = "../results", width = 15, height = 15, units = "cm")
DimPlot(imm_anno, group.by = "cell_type_imm", split.by = "tissue_type", cols = use_colors, pt.size = 0.5)
#ggsave2("DimPlot_imm_celltype.pdf", path = "output/fig4", width = 35, height = 15, units = "cm")
ggsave2("Fig4A_umap.png", path = "../results", width = 35, height = 15, units = "cm")
##hjust的值和 vjust仅定义在 0 和 1 之间,0 表示左对齐;1 表示右对齐
DotPlot(imm_anno, features = c("CD68", "LYZ", "FABP4", "MARCO", "LGMN", "CSF1R", "CD14", "S100A12", "FCN1", "CD1C", "FCER1A", "LILRA4", "IL3RA", "KIT", "GATA2", "CD3E", "CD4", "FOXP3", "IL2RA", "CD8A", "NKG7", "KLRD1", "MS4A1", "CD79A", "JCHAIN", "IGKC", "MKI67"), group.by = "cell_type_imm")
theme(axis.text.x = element_text(angle = 90, hjust = 1))
coord_flip()
scale_color_viridis()
ggsave2("Fig4B.pdf", path = "../results", width = 20, height = 20, units = "cm")
淋巴细胞和骨髓细胞分析
代码语言:javascript复制##subsetting
imm_lympho <- 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",
"NK_cells",
"B_cells",
"Plasma"))
imm_lympho <- ScaleData(imm_lympho)
imm_myelo <- 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",
"Monocytes",
"Myeloid_Dendritic",
"Plasmacytoid_Dendritic",
"Mast"))
imm_myelo <- ScaleData(imm_myelo)
lympho_counts <- FetchData(imm_lympho, vars = c("tissue_type", "cell_type_imm", "sample_id", "patient_id")) %>%
mutate(tissue_type = factor(tissue_type, levels = c("Tumor", "Normal")))
lympho_counts_tbl <- lympho_counts %>%
dplyr::count(cell_type_imm, patient_id, tissue_type)
write_csv(lympho_counts_tbl, path = "../results/SuppTable4.csv")
myelo_counts <- FetchData(imm_myelo, vars = c("tissue_type", "cell_type_imm", "sample_id", "patient_id")) %>%
mutate(tissue_type = factor(tissue_type, levels = c("Tumor", "Normal")))
myelo_counts_tbl <- myelo_counts %>%
dplyr::count(cell_type_imm, patient_id, tissue_type)
write_csv(myelo_counts_tbl, path = "../results/SuppTable3.csv")
ggplot(data = lympho_counts, aes(x = tissue_type, fill = cell_type_imm))
geom_bar(position = "fill")
scale_fill_manual(values = use_colors)
coord_flip()
scale_y_reverse()
ggsave2("Fig4A_barplot_lymphoid.pdf", path = "../results", width = 20, height = 5, units = "cm")
ggplot(data = myelo_counts, aes(x = tissue_type, fill = cell_type_imm))
geom_bar(position = "fill")
scale_fill_manual(values = use_colors)
coord_flip()
scale_y_reverse()
ggsave2("Fig4A_barplot_myeloid.pdf", path = "../results", width = 20, height = 5, units = "cm")
lympho_counts %>%
filter(tissue_type == "Tumor") %>%
ggplot(aes(x = sample_id, fill = cell_type_imm))
geom_bar(position = "fill")
scale_fill_manual(values = use_colors)
coord_flip()
scale_y_reverse()
ggsave2("Fig4A_barplot_lymphoid_per_patient.pdf", path = "../results", width = 30, height = 30, units = "cm")
myelo_counts %>%
filter(tissue_type == "Tumor") %>%
ggplot(aes(x = sample_id, fill = cell_type_imm))
geom_bar(position = "fill")
scale_fill_manual(values = use_colors)
coord_flip()
scale_y_reverse()
ggsave2("Fig4A_barplot_myeloid_per_patient.pdf", path = "../results", width = 30, height = 30, units = "cm")
lympho_counts %>%
filter(tissue_type == "Normal") %>%
ggplot(aes(x = sample_id, fill = cell_type_imm))
geom_bar(position = "fill")
scale_fill_manual(values = use_colors)
coord_flip()
scale_y_reverse()
ggsave2("SuppFig7A_lymphoid.pdf", path = "../results", width = 30, height = 30, units = "cm")
myelo_counts %>%
filter(tissue_type == "Normal") %>%
ggplot(aes(x = sample_id, fill = cell_type_imm))
geom_bar(position = "fill")
scale_fill_manual(values = use_colors)
coord_flip()
scale_y_reverse()
ggsave2("SuppFig7A_myeloid.pdf", path = "../results", width = 30, height = 30, units = "cm")