<- c("fs", "futile.logger", "configr", "stringr", "ggpubr", "ggthemes",
pkgs "jhtools", "glue", "ggsci", "patchwork", "tidyverse", "dplyr", "Seurat",
"paletteer", "cowplot", "ComplexHeatmap", "circlize")
for (pkg in pkgs) {
suppressPackageStartupMessages(library(pkg, character.only = T))
}<- "collabrators"
project <- "wangwenjie"
dataset <- "mouse"
species <- glue("~/projects/{project}/analysis/{dataset}/{species}/figures/fig3")
workdir |> fs::dir_create() |> setwd()
workdir
<- "~/projects/collabrators/code/wangwenjie/mouse/figures/configs.yaml"
yaml_fn <- jhtools::show_me_the_colors(config_fn = yaml_fn, "tissue")
cols_tissue
<- theme_classic(base_size = 8) +
my_theme1 theme(legend.key.size = unit(3, "mm"), axis.text = element_text(color = "black"),
axis.ticks = element_line(color = "black"), plot.title = element_text(hjust = .5))
## fig3a-c: human m/z tissue specific markers -----
<- read_rds("~/ref/kegg/human/hsa_mtb_pth_cpd.rds")
mtb_info <-
xlsx_fn1 glue("~/projects/collabrators/data/wangwenjie/human/metabolism/human_adjusted/DZLM2024030584-b2_DZLM2024030572/Qualitative.xlsx")
<- readxl::read_excel(xlsx_fn1, sheet = "neg-all") |>
neg_anot1 mutate(mz_id = paste0("neg-", mz)) |> dplyr::filter(KEGG %in% mtb_info$cpd_id, !is.na(Metabolites))
<- readxl::read_excel(xlsx_fn1, sheet = "pos-all") |>
pos_anot1 mutate(mz_id = paste0("pos-", mz)) |> dplyr::filter(KEGG %in% mtb_info$cpd_id, !is.na(Metabolites))
<- c("yao1", "yao2", "yao5")
samples
<- c("Forebrain", "Midbrain", "Hindbrain", "Spinal cord", "Optic vesicle",
ord_yao1 "Jaw and tooth", "Branchial arch", "Somite", "Heart", "Liver", "Gut",
"Embryo membrane")
<- c("Forebrain", "Midbrain", "Hindbrain", "Spinal cord", "Optic vesicle",
ord_yao2 "Jaw and tooth", "Branchial arch", "Somite", "Heart", "AGM", "Liver",
"Lung", "Gut", "Umbilical cord")
<- c("Forebrain","Midbrain","Hindbrain","Diencephalon","Spinal cord","Ear",
ord_yao5 "Jaw and tooth","Forelimb","Hindlimb","Cartilage","Muscle","Heart",
"Blood vessel","Liver","Gut")
<- list(yao1 = ord_yao1, yao2 = ord_yao2, yao5 = ord_yao5)
ord_lst
<-
rds_fn3 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig3ac_human_mz_dat_norm_lst.rds"
<- read_rds(rds_fn3)
dat_norm_lst for(samp in samples) {
= dat_norm_lst[[samp]]
dat_norm <- colnames(dat_norm)
lvls ## right anot ----
<- rownames(dat_norm)
nm = rbind(neg_anot1, pos_anot1) |> dplyr::filter(mz_id %in% nm) |>
tst1 ::select(all_of(c("mz_id", "Metabolites"))) |> dplyr::distinct() |>
dplyr::group_by(mz_id) |>
dplyrsummarise(meta = paste0(Metabolites, collapse = "; "))
<- which(nm %in% tst1$mz_id)
mz_idx <- tst1 |> as.data.frame() |> column_to_rownames("mz_id") |>
lab_mks |> str_wrap(., width = 30)
.[nm[mz_idx], ] <- rowAnnotation(link = anno_mark(at = mz_idx,
right_anot1 labels = lab_mks,
labels_gp = gpar(fontsize = 6),
link_width = unit(3, "mm"),
link_height = unit(.05, "mm")))
<-
top_anot11 ::HeatmapAnnotation(tissue = fct(lvls), show_legend = F,
ComplexHeatmapshow_annotation_name = F,
col = list(tissue = cols_tissue))
<- colorRamp2(c(-3, 0, 3), c("lightblue", "gray100", "#aa3333"))
col_fun2
<- ComplexHeatmap::Heatmap(as.matrix(dat_norm),
htp11 top_annotation = top_anot11,
show_column_names = T,
show_row_names = F,
row_names_gp = gpar(fontsize = 3),
name = "z-score",
show_row_dend = F,
column_names_gp = gpar(fontsize = 6),
show_column_dend = F,
column_names_side = "top", column_names_rot = 30,
right_annotation = right_anot1,
cluster_columns = F, cluster_rows = F,
col = col_fun2,
height = unit(10, "cm"), width = unit(6, "cm")
)pdf(glue("fig3ac_mz_top15_heatmap_{samp}_v250322.pdf"), width = 5, height = 5)
print(htp11)
dev.off()
}
## fig3d: human selected tissue specific spatial distribution -----
<-
rds_fn4 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/human_visium_all_gene_lst.rds"
= read_rds("../rds/human_visium_all_gene_lst.rds")
hsa_visium_lst names(hsa_visium_lst) <- c("CS12", "CS14", "CS18")
for(samp in c("CS12", "CS14", "CS18")) {
<- hsa_visium_lst[[samp]]
obj1 if(samp == "CS12") {
<- 1.8
scale_fct <- 3
plot_width <- 3
plot_height else if (samp == "CS14") {
} <- 1.3
scale_fct <- 4
plot_width <- 4
plot_height else {
} <- 1.3
scale_fct <- 8
plot_width <- 8
plot_height
}<- lapply(c("CNS", "Heart", "Liver", "Somite"), \(sel) {
plst1 $labels_plot <- case_when(obj1$labels_fig3d %in% sel ~ sel, TRUE ~ "others")
obj1::SpatialDimPlot(obj1, group.by = "labels_plot", label = F,
Seuratpt.size = scale_fct, image.alpha = 0, stroke = NA,
cols = c(cols_tissue[sel], "gray99")) &
& labs(title = sel) & Seurat::NoLegend() &
my_theme1 theme(plot.title = element_text(size = 8), plot.margin = margin(c(0, 0, 0, 0), unit = "cm")) &
::NoAxes() & coord_fixed()
Seurat
})<- plst1 |> patchwork::wrap_plots(nrow = 1)
plst1 ggsave(glue("fig3d_human_spatial_tissue_{samp}_v250322.pdf"), plst1,
width = plot_width * 4, height = plot_height, units = "cm")
}
## fig3g: changes among stages of human metabolites in liver -----
<- "/cluster/home/ztao_jh/projects/embryo/analysis/zhangjing/human/rnaseq/new_label/ren_time_point_2/neg/Liver.csv"
csv_fn1 <- read_csv(csv_fn1)
log_fc <- log_fc |>
log_fc mutate(stage = case_when(grepl("yao1", name) ~ "CS12", grepl("yao2", name) ~ "CS14", TRUE ~ "CS18")) |>
mutate(stage = fct(as.character(stage), levels = paste0("CS1", c(2, 4, 8)))) |>
::filter(!grepl("Trend7", group))
dplyr
= ggplot2::ggplot(log_fc, aes(x = stage, y = value, group = feature, color = group)) +
line1 ::geom_line() + scale_color_manual(values = unname(cols_tissue[1:6])) +
ggplot2::facet_wrap(~ group, ncol = 3) + my_theme1 +
ggplot2theme(legend.position = "none", axis.line = element_blank(),
panel.border = element_rect(fill = NA, color = "black", linewidth = .5)) +
labs(x = "", y = "Relative abundance")
ggsave("fig3g_liver_mtb_line1.pdf", line1, width = 6, height = 3)
## fig2h: moran's I changes -----
<-
csv_fn2 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig3h_human_mz_moran_trends.csv"
<- read_csv(csv_fn2)
outcsv <- function(outcsv){
draw_line <- outcsv |>
sigtissue ::select(feature, anot1) |>
dplyr::distinct() |>
dplyrgroup_by(anot1) |>
summarise(n = n()) |>
group_by(anot1) |>
::filter(anot1 != "others") |>
dplyrarrange(desc(n)) |>
pull(anot1)
|>
outcsv ::filter(anot1 != "others") |>
dplyrmutate(anot1 = factor(anot1, levels = sigtissue)) |>
ggplot(aes(x = stage, y = value, group = feature, color = anot1)) +
geom_line() + scale_color_manual(values = cols_tissue) +
facet_wrap(~anot1) +
ylab(label = "Moran's Index") +
xlab(label = "Stage") +
+
my_theme1 theme(legend.position = "none", axis.line = element_blank(),
panel.border = element_rect(linewidth = .5, fill = NA, color = "black"),
axis.text.x = element_text(angle = 90, hjust = 0.5, vjust = 0.5))
}pdf(glue("./fig3h_mz_moran_trend_tissue.pdf"))
draw_line(outcsv)
dev.off()
## fig2i: bar plot of each tissue ----
<- function(outcsv){
draw_bar |>
outcsv ::select(feature, anot1) |>
dplyr::distinct() |>
dplyrgroup_by(anot1) |>
summarise(n = n()) |>
arrange(desc(n)) |>
mutate(label = factor(anot1, levels = anot1)) |>
ggplot(aes(x = label, y = n, fill = label)) +
geom_bar(stat = "identity") +
+ scale_fill_manual(values = cols_tissue) +
my_theme1 theme(legend.position = "none",
axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
labs(x = "", y = "Metabolite Number")
}pdf(glue("./fig3i_human_mz_num_tissue.pdf"))
draw_bar(outcsv)
dev.off()
15 Figure 3
15.1 Figure 3 | Dynamic inter-organ level transcriptional networks and metabolic compartmentalization of human embryos in organogenesis
15.1.1
code: