<- c("fs", "futile.logger", "configr", "stringr", "ggpubr", "ggthemes",
pkgs "SingleCellExperiment", "BiocNeighbors", "vroom", "jhtools", "glue",
"openxlsx", "ggsci", "patchwork", "cowplot", "tidyverse", "dplyr",
"survminer", "survival")
for (pkg in pkgs){
suppressPackageStartupMessages(library(pkg, character.only = T))
}<- "./results/sup_figure8" %>% 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, "stype3")
stype3_cols <- jhtools::show_me_the_colors(config_fn, "cell_type_new")
ctype10_cols <- jhtools::show_me_the_colors(config_fn, "meta_color")
meta_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 <- readxl::read_excel(glue::glue("{dat_dir}/meta_clu.xlsx")) %>% dplyr::select(-9)
meta_clu
<- function(x){
grid.draw.ggsurvplot :::print.ggsurvplot(x, newpage = FALSE)
survminer }
sup_figure8
sup_figure8ab
<- distinct(coldat[, c("stype2", "patient_id", "sample_id", "sample_tiff_id")])
sample_to_tiff <- as.data.frame(metadata[["os_analysis"]])
meta_os <- as.data.frame(metadata[["pfs_analysis"]])
meta_pfs
# community interaction weight
<- metadata[["community_interaction_weighted"]]
df_inter_weighted
# allsurgery samples
<- left_join(df_inter_weighted, sample_to_tiff, by = "sample_tiff_id") %>%
df_inter_weighted_new_allsurgery ::filter(sample_id %in% c(sample_chemo_type_list[["chemo"]], sample_chemo_type_list[["no_chemo_no_punc"]]))
dplyr
<- df_inter_weighted_new_allsurgery %>%
df_inter_weighted_new_allsurgery ::mutate(interact_meta_bi = case_when(from_meta > to_meta ~ str_c(from_meta, "_", to_meta),
dplyrTRUE ~ str_c(to_meta, "_", from_meta)))
<- df_inter_weighted_new_allsurgery %>%
meta_nochemo_df group_by(interact_meta_bi, sample_id, patient_id) %>%
::summarise(mean_weight = mean(weight)) %>% ungroup()
dplyr
<- names(table((meta_nochemo_df$interact_meta_bi)))[table((meta_nochemo_df$interact_meta_bi)) > 1]
metas
<- meta_nochemo_df %>%
meta_nochemo_col ::filter(interact_meta_bi %in% metas) %>%
dplyrpivot_wider(id_cols = c("sample_id", "patient_id"),
names_from = interact_meta_bi,
values_from = mean_weight, values_fill = 1)
# MC-tumor-frontline_MC-stroma-macro_vs_MC-tumor-frontline_MC-immune-enriched
<- meta_nochemo_col %>% dplyr::select(sample_id, patient_id,
os_df `MC-tumor-frontline_MC-stroma-macro`,
`MC-tumor-frontline_MC-immune-enriched`) %>%
::mutate(weight_ratio = `MC-tumor-frontline_MC-stroma-macro`/`MC-tumor-frontline_MC-immune-enriched`) %>%
dplyrleft_join(sinfo, by = c("sample_id", "patient_id")) %>%
::mutate(group_median = case_when(weight_ratio >= median(weight_ratio) ~ "high",
dplyr< median(weight_ratio) ~ "low"))
weight_ratio
<- os_df %>% dplyr::select(all_of(c("sample_id", "os_state", "os_month", "group_median"))) %>% drop_na(os_month)
os_tmp #os
<- ggsurvplot(surv_fit(Surv(os_month, os_state) ~ group_median, data = os_tmp),
psurv1 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(os_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8a_os.pdf"),
plot = psurv1, width = 5, height = 5)
<- os_df %>% dplyr::select(all_of(c("sample_id", "pfs_state", "pfs_month", "group_median"))) %>% drop_na(pfs_month)
pfs_tmp #pfs
<- ggsurvplot(surv_fit(Surv(pfs_month, pfs_state) ~ group_median, data = pfs_tmp),
psurv2 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(pfs_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8a_pfs.pdf"),
plot = psurv2, width = 5, height = 5)
# MC-tumor-frontline_MC-stroma-mCAF_vs_MC-tumor-frontline_MC-immune-enriched
<- meta_nochemo_col %>% dplyr::select(sample_id, patient_id,
os_df `MC-tumor-frontline_MC-stroma-mCAF`,
`MC-tumor-frontline_MC-immune-enriched`) %>%
::mutate(weight_ratio = `MC-tumor-frontline_MC-stroma-mCAF`/`MC-tumor-frontline_MC-immune-enriched`) %>%
dplyrleft_join(sinfo, by = c("sample_id", "patient_id")) %>%
::mutate(group_median = case_when(weight_ratio >= median(weight_ratio) ~ "high",
dplyr< median(weight_ratio) ~ "low"))
weight_ratio
<- os_df %>% dplyr::select(all_of(c("sample_id", "os_state", "os_month", "group_median"))) %>% drop_na(os_month)
os_tmp #os
<- ggsurvplot(surv_fit(Surv(os_month, os_state) ~ group_median, data = os_tmp),
psurv3 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(os_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8b_os.pdf"),
plot = psurv3, width = 5, height = 5)
<- os_df %>% dplyr::select(all_of(c("sample_id", "pfs_state", "pfs_month", "group_median"))) %>% drop_na(pfs_month)
pfs_tmp #pfs
<- ggsurvplot(surv_fit(Surv(pfs_month, pfs_state) ~ group_median, data = pfs_tmp),
psurv4 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(pfs_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8b_pfs.pdf"),
plot = psurv4, width = 5, height = 5)
$plot | psurv1$plot) / (psurv4$plot | psurv3$plot) (psurv2
sup_figure8cd
# no_chemo_no_punc
<- left_join(df_inter_weighted, sample_to_tiff, by = "sample_tiff_id") %>%
df_inter_weighted_new_nochemo ::filter(sample_id %in% sample_chemo_type_list[["no_chemo_no_punc"]])
dplyr
<- df_inter_weighted_new_nochemo %>%
df_inter_weighted_new_nochemo ::mutate(interact_meta_bi = case_when(from_meta > to_meta ~ str_c(from_meta, "_", to_meta),
dplyrTRUE ~ str_c(to_meta, "_", from_meta)))
<- df_inter_weighted_new_nochemo %>%
meta_nochemo_df group_by(interact_meta_bi, sample_id, patient_id) %>%
::summarise(mean_weight = mean(weight)) %>% ungroup()
dplyr
<- names(table((meta_nochemo_df$interact_meta_bi)))[table((meta_nochemo_df$interact_meta_bi)) > 1]
metas
<- meta_nochemo_df %>%
meta_nochemo_col ::filter(interact_meta_bi %in% metas) %>%
dplyrpivot_wider(id_cols = c("sample_id", "patient_id"),
names_from = interact_meta_bi,
values_from = mean_weight, values_fill = 1)
# MC-tumor-frontline_MC-stroma-macro_vs_MC-tumor-frontline_MC-immune-enriched
<- meta_nochemo_col %>% dplyr::select(sample_id, patient_id,
os_df `MC-tumor-frontline_MC-stroma-macro`,
`MC-tumor-frontline_MC-immune-enriched`) %>%
::mutate(weight_ratio = `MC-tumor-frontline_MC-stroma-macro`/`MC-tumor-frontline_MC-immune-enriched`) %>%
dplyrleft_join(sinfo, by = c("sample_id", "patient_id")) %>%
::mutate(group_median = case_when(weight_ratio >= median(weight_ratio) ~ "high",
dplyr< median(weight_ratio) ~ "low"))
weight_ratio
<- os_df %>% dplyr::select(all_of(c("sample_id", "os_state", "os_month", "group_median"))) %>% drop_na(os_month)
os_tmp #os
<- ggsurvplot(surv_fit(Surv(os_month, os_state) ~ group_median, data = os_tmp),
psurv1 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(os_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8c_os.pdf"),
plot = psurv1, width = 5, height = 5)
<- os_df %>% dplyr::select(all_of(c("sample_id", "pfs_state", "pfs_month", "group_median"))) %>% drop_na(pfs_month)
pfs_tmp #pfs
<- ggsurvplot(surv_fit(Surv(pfs_month, pfs_state) ~ group_median, data = pfs_tmp),
psurv2 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(pfs_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8c_pfs.pdf"),
plot = psurv2, width = 5, height = 5)
# MC-tumor-frontline_MC-stroma-mCAF_vs_MC-tumor-frontline_MC-immune-enriched
<- meta_nochemo_col %>% dplyr::select(sample_id, patient_id,
os_df `MC-tumor-frontline_MC-stroma-mCAF`,
`MC-tumor-frontline_MC-immune-enriched`) %>%
::mutate(weight_ratio = `MC-tumor-frontline_MC-stroma-mCAF`/`MC-tumor-frontline_MC-immune-enriched`) %>%
dplyrleft_join(sinfo, by = c("sample_id", "patient_id")) %>%
::mutate(group_median = case_when(weight_ratio >= median(weight_ratio) ~ "high",
dplyr< median(weight_ratio) ~ "low"))
weight_ratio
<- os_df %>% dplyr::select(all_of(c("sample_id", "os_state", "os_month", "group_median"))) %>% drop_na(os_month)
os_tmp #os
<- ggsurvplot(surv_fit(Surv(os_month, os_state) ~ group_median, data = os_tmp),
psurv3 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(os_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8d_os.pdf"),
plot = psurv3, width = 5, height = 5)
<- os_df %>% dplyr::select(all_of(c("sample_id", "pfs_state", "pfs_month", "group_median"))) %>% drop_na(pfs_month)
pfs_tmp #pfs
<- ggsurvplot(surv_fit(Surv(pfs_month, pfs_state) ~ group_median, data = pfs_tmp),
psurv4 palette = c("high"="#BC3C29FF", "low"="#0072B5FF"),
legend.labs = levels(droplevels(as.factor(unlist(pfs_tmp[, "group_median"])))),
pval=T, risk.table = T)#, xlim = c(0,75))
ggsave(glue::glue("{res_dir}/sup_figure8d_pfs.pdf"),
plot = psurv4, width = 5, height = 5)
$plot | psurv1$plot) / (psurv4$plot | psurv3$plot) (psurv2