<- c("fs", "futile.logger", "configr", "stringr", "ggpubr", "ggthemes",
pkgs "vroom", "jhtools", "glue", "openxlsx", "ggsci", "patchwork", "cowplot",
"tidyverse", "dplyr", "SingleCellExperiment", "survminer", "survival")
suppressMessages(conflicted::conflict_scout())
for (pkg in pkgs){
suppressPackageStartupMessages(library(pkg, character.only = T))
}<- "./results/sup_figure11" %>% checkdir
res_dir <- "./data" %>% checkdir
dat_dir <- "./config" %>% checkdir
config_dir
#colors config
<- glue::glue("{config_dir}/configs.yaml")
config_fn <- jhtools::show_me_the_colors(config_fn, "cell_type_new")
ctype10_cols <- jhtools::show_me_the_colors(config_fn, "meta_color")
meta_cols <- jhtools::show_me_the_colors(config_fn, "meta_merge")
meta_merge_cols
#read in coldata
<- readr::read_csv(glue::glue("{dat_dir}/sce_coldata.csv"))
coldat <- readr::read_csv(glue::glue("{dat_dir}/metadata_sinfo.csv"))
sinfo <- readr::read_rds(glue::glue("{dat_dir}/sample_chemo_type_list.rds"))
sample_chemo_type_list <- readr::read_rds(glue::glue("{dat_dir}/metadata.rds"))
metadata <- readr::read_rds(glue::glue("{dat_dir}/pos_cell_list_10percent.rds"))
pos_cells10 <- readr::read_rds(glue::glue("{dat_dir}/compcounts_censored_assay.rds")) assay_cc
sup_figure11
sup_figure11abc
#correlation plot function
<- function(cld, cell_pairs2, big_type, meta_colors){
DNmac_posOther_correlation_func <- cld %>% dplyr::filter(sample_id %in% sample_chemo_type_list$no_chemo_all) %>%
cld_nochemo_dn_noBT ::filter(meta_cluster != "MC-tumor-core") %>%
dplyr::filter(cell_type11 == "DN-mp") %>%
dplyrgroup_by(meta_merge, sample_id) %>% summarise(np = n())
<- cld %>% dplyr::filter(sample_id %in% sample_chemo_type_list$no_chemo_all) %>%
cld_nochemo_total1_noBT ::filter(meta_cluster != "MC-tumor-core") %>%
dplyr::filter(cell_type11 %in% c("Other-mp", "DN-mp")) %>%
dplyrgroup_by(meta_merge, sample_id) %>% summarise(nt = n())
<- left_join(cld_nochemo_total1_noBT, cld_nochemo_dn_noBT, by = c("meta_merge", "sample_id")) %>%
cld_nochemo_dn_noBT replace_na(list(np = 0)) %>% dplyr::mutate(prop = np/nt) %>% dplyr::select(-c(nt, np)) %>% ungroup()
<- cld %>% dplyr::filter(sample_id %in% sample_chemo_type_list$no_chemo_all) %>%
cld_nochemo_pos2_noBT ::filter(meta_cluster != "MC-tumor-core") %>%
dplyr::filter(cell_id %in% pos_cells10[[cell_pairs2]]) %>%
dplyrgroup_by(meta_merge, sample_id) %>% summarise(np = n())
<- cld %>% dplyr::filter(sample_id %in% sample_chemo_type_list$no_chemo_all) %>%
cld_nochemo_total2_noBT ::filter(meta_cluster != "MC-tumor-core") %>%
dplyr::filter(cell_type11 %in% big_type) %>%
dplyrgroup_by(meta_merge, sample_id) %>% summarise(nt = n())
<- left_join(cld_nochemo_total2_noBT, cld_nochemo_pos2_noBT, by = c("meta_merge", "sample_id")) %>%
cld_nochemo_pos2_noBT replace_na(list(np = 0)) %>% dplyr::mutate(prop = np/nt) %>% dplyr::select(-c(nt, np)) %>% ungroup()
<- inner_join(cld_nochemo_dn_noBT, cld_nochemo_pos2_noBT, by = c("meta_merge", "sample_id"))
cld_nochemo_com $meta_merge <- factor(cld_nochemo_com$meta_merge, levels = c(c("MC-others", "MC-stroma-macro", "MC-tumor-frontline")))
cld_nochemo_com
<- ggscatter(cld_nochemo_com, x = "prop.x", y = "prop.y",
p color = "meta_merge", palette = meta_colors, size = .4,
add = "reg.line", conf.int = TRUE, star.plot.lwd = .1,
cor.coef.size = .01) + xlim(0,1) +
ylim(0,1) + xlab(glue::glue("DN-Mp")) + ylab(cell_pairs2) +
stat_cor(aes(color = meta_merge), label.x = 0.15, label.y = c(0.46,0.48,0.5), size = 2) +
theme(axis.title.y = element_text(size = 6),
axis.text.y = element_text(size = 6),
axis.title.x = element_text(size = 6),
axis.text.x = element_text(size = 6),
legend.text = element_text(size = 2),
legend.title = element_text(size = 2),
legend.key.size = unit(0.1, 'cm'))
return(p)
}
<- coldat %>%
coldat ::mutate(meta_merge = case_when(meta_cluster %notin%
dplyrc("MC-tumor-frontline", "MC-stroma-macro", "MC-tumor-core") ~ "MC-others",
TRUE ~ meta_cluster)) %>%
::mutate(cell_type11 = case_when(cell_type_new %in%
dplyrc("HLA-DR+CD163- mp", "HLA-DR+CD163+ mp", "HLA-DR-CD163+ mp") ~ "Other-mp",
%in% c("HLA-DR-CD163- mp") ~ "DN-mp",
cell_type_new TRUE ~ cell_type_new))
<- "CD8+ T cell"
big_type
#a
<- "LAG_3_pos_CD8T"
cp2 <- DNmac_posOther_correlation_func(cld = coldat, cell_pairs2 = cp2,
pa big_type = big_type, meta_colors = meta_merge_cols)
<- pa + scale_y_continuous(limits=c(0,0.5), oob = scales::rescale_none) +
pa theme(legend.position = "none")
ggsave(glue::glue("{res_dir}/sfig11a_DN_mac_cor_with_LAG3CD8T.pdf"), pa, width = 4, height = 4)
#b
<- "PD1_pos_CD8T"
cp2 <- DNmac_posOther_correlation_func(cld = coldat, cell_pairs2 = cp2,
pb big_type = big_type, meta_colors = meta_merge_cols)
<- pb + scale_y_continuous(limits=c(0,0.5), oob = scales::rescale_none) +
pb theme(legend.position = "none")
ggsave(glue::glue("{res_dir}/sfig11b_DN_mac_cor_with_PD1CD8T.pdf"), pb, width = 4, height = 4)
#c
<- "Vista_pos_CD8T"
cp2 <- DNmac_posOther_correlation_func(cld = coldat, cell_pairs2 = cp2,
pc big_type = big_type, meta_colors = meta_merge_cols)
<- pc + scale_y_continuous(limits=c(0,0.5), oob = scales::rescale_none) +
pc theme(legend.position = "none")
ggsave(glue::glue("{res_dir}/sfig11c_DN_mac_cor_with_VistaCD8T.pdf"), pc, width = 4, height = 4)
| pb | pc pa
sup_figure11d
<- as.data.frame(t(assay_cc))
comcc_t $cell_id <- rownames(comcc_t)
comcc_t<- left_join(coldat, comcc_t, by = "cell_id") %>%
cld_df ::select(sample_id, cell_id, a_smooth:CD25)
dplyr
<- readr::read_rds(glue::glue("{dat_dir}/distance_rds/TB_list_closecell_dist_k1_CD8T_to_Macrophage_DN.rds"))
list_closecell_distance
<- do.call("rbind", list_closecell_distance)
df_closecell_distance <- left_join(df_closecell_distance, cld_df, by = c("from_cell" = "cell_id")) %>%
df_closecell_distance ::filter(sample_id %in% sample_chemo_type_list$no_chemo_all)
dplyr
<- df_closecell_distance %>% dplyr::mutate(group = case_when(distance < median(distance) ~ "near",
df_closecell_distance TRUE ~ "far"))
<- df_closecell_distance %>% group_by(to_cell) %>%
df_new_group ::summarise(group_all = paste(group, collapse = ";")) %>%
dplyr::mutate(group_new = case_when(str_detect(group_all, "near") ~ "near",
dplyrTRUE ~ "far")) %>% dplyr::select(-group_all)
<- df_closecell_distance %>% left_join(df_new_group, by = "to_cell")
df_closecell_distance $group_new <- factor(df_closecell_distance$group_new, levels = c("near", "far"))
df_closecell_distance
<- list()
pl for (i in c("LAG_3", "PD1", "Vista", "Granzyme_B")) {
<- ggboxplot(df_closecell_distance, x = "group_new", y = i, fill = "group_new", outlier.shape = NA,
pl[[i]] palette = pal_nejm("default")(2), xlab = NULL,size = 0.2, width = .2) + theme_classic() +
scale_y_continuous(limits=c(0,1), oob = scales::rescale_none) +
stat_summary(fun.data = "mean_se", geom = "pointrange", show.legend = F,
position = position_dodge(.12), size = .025, color = "black") +
theme(strip.placement = "outside",
panel.spacing = unit(3, "points"),
strip.background = element_blank(),
strip.text = element_text(face = "bold", size = 5),
axis.text.x = element_text(size = 6, colour = "black"),
axis.text.y = element_text(size = 6, colour = "black"),
axis.title.y = element_text(size = 6),
axis.title.x = element_blank(),
axis.line.x = element_line(size = 0.4, colour = "black"),
axis.line.y = element_line(size = 0.4, colour = "black"),
axis.ticks = element_line(colour = "black"),
legend.position="none") + ylab(glue::glue("{i} intensity of CD8+ T")) +
stat_compare_means(aes(label = ..p.signif..), label.x.npc = "center", size = 1,
label.y.npc = "top", show.legend = T)
ggsave(glue::glue("{res_dir}/sfig11d_{i}_intensity_of_CD8T_to_DNmac.pdf"), pl[[i]], width = 2, height = 3)
}"LAG_3"]] | pl[["PD1"]] | pl[["Vista"]] | pl[["Granzyme_B"]] pl[[
sup_figure11e
<- coldat %>% dplyr::filter(cell_type_new == "CD8+ T cell" & meta_merge %notin% "MC-tumor-core") %>%
cd8_prop group_by(sample_id, meta_merge) %>% dplyr::mutate(nt = n()) %>%
ungroup() %>% dplyr::select(sample_id, meta_merge, nt) %>% distinct() %>%
::filter(sample_id %in% c(sample_chemo_type_list$no_chemo_no_punc, sample_chemo_type_list$chemo))
dplyr
<- c("Surgery after chemo" = "#0072B5FF", "Upfront surgery" = "#BC3C29FF")
cols
for (i in c("LAG_3_pos_CD8T", "Vista_pos_CD8T")) {
<- coldat %>% dplyr::filter(cell_type_new == "CD8+ T cell" & meta_merge %notin% "MC-tumor-core") %>%
pos_prop ::filter(cell_id %in% pos_cells10[[i]]) %>%
dplyrgroup_by(sample_id, meta_merge) %>% dplyr::mutate(np = n()) %>%
ungroup() %>% dplyr::select(sample_id, meta_merge, np) %>% distinct()
<- left_join(cd8_prop, pos_prop, by = c("sample_id", "meta_merge")) %>%
pos_prop replace_na(list(np = 0)) %>% dplyr::mutate(prop = np/nt)
<- pos_prop %>%
pos_prop_chemo ::mutate(chemo = case_when(sample_id %in% sample_chemo_type_list$no_chemo_no_punc ~ "Upfront surgery",
dplyr%in% sample_chemo_type_list$chemo ~ "Surgery after chemo"))
sample_id
$meta_merge <- factor(pos_prop_chemo$meta_merge, levels = c("MC-tumor-frontline", "MC-stroma-macro", "MC-others"))
pos_prop_chemo$chemo <- factor(pos_prop_chemo$chemo, levels = c("Upfront surgery", "Surgery after chemo"))
pos_prop_chemo
<- pos_prop_chemo %>%
stat_test group_by(meta_merge) %>% rstatix::wilcox_test(prop ~ chemo, p.adjust.method = "none")
<- stat_test %>% mutate(p.adj.signif = case_when(p >= 0.05 ~ "ns",
stat_test >= 0.01 & p < 0.05 ~ "*",
p >= 0.001 & p < 0.01 ~ "**",
p >= 0.0001 & p < 0.001 ~ "***",
p < 0.0001 ~ "****",
p TRUE ~ "ns"))
<- stat_test %>%
stat_test ::add_xy_position(x = "meta_merge", dodge = 0.9, fun = "median_iqr")
rstatix
$y.position <- 0.5
stat_test
<- ggplot(pos_prop_chemo,
pl[[i]] aes(x = meta_merge, y = prop)) +
geom_boxplot(aes(fill = chemo), width = .5, #show.legend = FALSE,
outlier.shape = NA, linewidth = .2, color = "black") +
stat_summary(aes(fill = chemo, color = chemo), fun.data = "mean_se", geom = "pointrange", show.legend = F,
position = position_dodge(.5), fatten = .2, size = .2, stroke = .5, linewidth = .2, color = "black") +
scale_fill_manual(values = cols) +
scale_colour_manual(values = cols) +
ylab(glue::glue("proportion of {i}")) +
scale_y_continuous(limits=c(0, 0.55), oob = scales::rescale_none) +
stat_pvalue_manual(stat_test, x = "meta_merge", tip.length = 0.01, hide.ns = F, label = "p.adj.signif", size = 2) +
theme_bmbdc() +
theme(title = element_text(size = 6),
axis.ticks = element_line(colour = "black"),
axis.title.y = element_text(size = 6),
axis.text.y = element_text(size = 6, colour = "black"),
axis.title.x = element_blank(),
axis.text.x = element_text(size = 6, colour = "black", angle = 20),
axis.line.x = element_line(linewidth = 0.4),
axis.line.y = element_line(linewidth = 0.4),
legend.position="top",
legend.text = element_text(size = 4),
legend.title = element_text(size = 4),
legend.key.size = unit(0.1, 'cm'))
ggsave(glue::glue("{res_dir}/sup_figure11e_{i}_prop_chemo_ornot.pdf"), pl[[i]], width = 4, height = 4)
}"LAG_3_pos_CD8T"]] | pl[["Vista_pos_CD8T"]] pl[[