# List of required packages
<- c("fs", "futile.logger", "configr", "stringr", "ggpubr", "ggthemes",
pkgs "jhtools", "glue", "ggsci", "patchwork", "tidyverse", "dplyr", "Seurat",
"paletteer", "cowplot", "ComplexHeatmap", "circlize")
# Load each package silently
for (pkg in pkgs) {
suppressPackageStartupMessages(library(pkg, character.only = TRUE))
}
14 Figure 2
14.1 Figure 2| Dynamic inter-organ level transcriptional networks and metabolic compartmentalization of mouse embryos in organogenesis
14.1.1 Load Required Packages
14.1.2 Set Project Variables and Working Directory
# Define project, dataset, and species
<- "collabrators"
project <- "wangwenjie"
dataset <- "mouse"
species
# Create and set working directory
<- glue("~/projects/{project}/analysis/{dataset}/{species}/figures/fig2")
workdir |> fs::dir_create() |> setwd()
workdir
# Load YAML configuration file for colors
<- "~/projects/collabrators/code/wangwenjie/mouse/figures/configs.yaml"
yaml_fn <- jhtools::show_me_the_colors(config_fn = yaml_fn, "tissue")
cols_tissue <- jhtools::show_me_the_colors(config_fn = yaml_fn, "stage")[c("E9.5", "E11.5", "E13.5")]
stg_cols
# Define custom theme for plots
<- 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 = 0.5))
14.1.3 Figure 2a-c: Specific m/z Expression in Selected Tissues Across Stages
This section generates heatmaps showing specific m/z expression in selected mouse tissues for each developmental stage.
# Load metabolite information from KEGG
<- read_rds("~/ref/kegg/mouse/mmu_mtb_pth_cpd.rds")
mtb_info
# Load qualitative data from Excel file
<- glue("/cluster/home/jhuang/projects/collabrators/data/wangwenjie/mouse/metabolism/mouse_adjusted/DZLM2023110146_DZLM2024030584-b1-张进-王文杰-空间代谢组-项目报告/2.定性结果/Qualitative.xlsx")
xlsx_fn1 <- 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))
<- rbind(neg_anot1, pos_anot1)
anot1 <- anot1 |> dplyr::filter(KEGG %in% mtb_info$cpd_id)
anot2
# Define sample names and tissue orders for each stage
<- c("E95", "E115", "E135")
samples
<- c("Forebrain","Midbrain","Hindbrain","Spinal cord","Caudal neuropore",
ord_e95 "Branchial arch","Somite","Heart","AGM","Mesenchyme","Liver","Lung",
"Gut","Cavity")
<- c("Forebrain", "Midbrain", "Hindbrain", "Spinal cord", "Epidermis",
ord_e115 "Branchial arch", "Jaw and tooth", "Forelimb", "Hindlimb", "Somite",
"Heart", "AGM", "Liver", "Gut", "Cavity", "Embryo membrane")
<- c("Forebrain", "Midbrain", "Hindbrain", "Diencephalon", "Spinal cord",
ord_e135 "Epidermis", "Ear", "Jaw and tooth", "Hindlimb", "Cartilage", "Muscle",
"Heart", "Blood vessel", "Gonad", "Kidney", "Liver", "Lung", "Gut")
<- list(E95 = ord_e95, E115 = ord_e115, E135 = ord_e135)
ord_lst
# Load normalized data
<-
rds_fn1 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig2ac_mouse_mz_htp_dat_norm_lst.rds"
<- read_rds(rds_fn1)
dat_norm_lst
# Generate heatmaps for each sample
for(samp in samples) {
= dat_norm_lst[[samp]][, ord_lst[[samp]]]
dat_norm <- colnames(dat_norm)
lvls
# Prepare right annotation for metabolites
<- 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 = 4),
link_width = unit(5, "mm"),
link_height = unit(0.2, "mm")))
# Prepare top annotation for tissues
<-
top_anot11 ::HeatmapAnnotation(tissue = fct(lvls), show_legend = FALSE,
ComplexHeatmapshow_annotation_name = FALSE, height = unit(1, 'mm'),
width = unit(60, "mm"),
col = list(tissue = cols_tissue))
# Define color function for heatmap
<- colorRamp2(c(-3, 0, 3), c("lightblue", "gray100", "#aa3333"))
col_fun2
# Create heatmap
<- ComplexHeatmap::Heatmap(as.matrix(dat_norm),
htp11 top_annotation = top_anot11,
show_column_names = TRUE,
show_row_names = FALSE,
row_names_gp = gpar(fontsize = 2),
name = "z-score",
show_row_dend = FALSE,
column_names_gp = gpar(fontsize = 6),
show_column_dend = FALSE,
column_names_side = "top", column_names_rot = 30,
right_annotation = right_anot1,
cluster_columns = FALSE, cluster_rows = FALSE,
col = col_fun2,
height = unit(10, "cm"), width = unit(6, "cm")
)
# Save heatmap to PDF
pdf(glue("fig2ac_mz_top15_heatmap_{samp}_v2.pdf"), width = 4.5, height = 6)
print(htp11)
dev.off()
}
14.1.4 Figure 2d: Spatial Distribution of Selected Tissues
This section generates spatial plots showing the distribution of selected tissues in mouse embryos at different stages.
# Load Visium objects
<-
rds_fn4 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/mmu_visium_obj_lst.rds"
= read_rds(rds_fn4)
mmu_visium_lst
# Generate spatial plots for each stage
for(samp in c("E9.5", "E11.5", "E13.5")) {
<- mmu_visium_lst[[samp]]
obj1 <- c("CNS", "Heart", "Liver", "AGM")
sel_tissues if(samp == "E9.5") {
<- 1.6
scale_fct <- 2
plot_width <- 2
plot_height else if (samp == "E11.5") {
} <- 1.1
scale_fct <- 4
plot_width <- 4
plot_height else {
} <- 2.0
scale_fct <- 6
plot_width <- 6
plot_height 4] <- "G and K"
sel_tissues[
}<- lapply(sel_tissues, \(sel) {
plst1 $labels_plot <- case_when(obj1$labels_fig2d %in% sel ~ sel, TRUE ~ "others")
obj1::SpatialDimPlot(obj1, group.by = "labels_plot", label = FALSE,
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)
fig2d ggsave(glue("fig2d_mouse_spatial_tissue_{samp}_v250322.pdf"), fig2d,
width = plot_width * 4, height = plot_height, units = "cm")
}
14.1.5 Figure 2g: Metabolite Changes in Liver Across Stages
This section creates line plots showing changes in metabolite abundance in the liver across developmental stages.
# Load long format fold change data
<-
csv_fn1 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig2g_mouse_mz_liver_long_fc.csv"
<- read_csv(csv_fn1) |> mutate(name = fct(as.character(name), levels = paste0("E", c(9.5, 11.5, 13.5))))
long_fc
# Create line plot
= ggplot2::ggplot(long_fc, aes(x = name, 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 = 0.5)) +
labs(x = "", y = "Relative abundance")
# Save plot to PDF
ggsave("fig2g_liver_mtb_line1.pdf", line1, width = 6, height = 3)
14.1.6 Figure 2h: Moran’s I Changes Across Stages
This section generates line plots for Moran’s I trends in different tissues.
# Load Moran's I data
<-
csv_fn2 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig2h_mouse_mz_moran_trends.csv"
<- read_csv(csv_fn2)
outcsv
# Function to draw line plots for Moran's I
<- 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 = name, 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 = 0.5, fill = NA, color = "black"),
axis.text.x = element_text(angle = 90, hjust = 0.5, vjust = 0.5))
}
# Save plot to PDF
pdf(glue("./fig2h_mz_moran_trend_tissue.pdf"))
draw_line(outcsv)
dev.off()
14.1.7 Figure 2i: Bar Plot of Metabolite Counts per Tissue
This section creates a bar plot showing the number of metabolites per tissue.
# Function to draw bar plot
<- 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 = 0)) +
labs(x = "", y = "Metabolite Number")
}
# Save plot to PDF
pdf(glue("./fig2i_mouse_mz_num_tissue.pdf"))
draw_bar(outcsv)
dev.off()