前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >单细胞数据复现-肺癌文章代码复现6

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

原创
作者头像
小胡子刺猬的生信学习123
发布2022-05-23 10:33:46
5360
发布2022-05-23 10:33:46
举报
文章被收录于专栏:文献分享及代码学习

单细胞数据复现-肺癌文章代码复现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")

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • R package及 环境颜色配置加载
  • 数据加载
  • 根据cell_type的类型,确定后续分析的水平因子
  • 淋巴细胞和骨髓细胞分析
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档