<- c("fs", "futile.logger", "configr", "stringr", "ggpubr", "ggthemes",
pkgs "jhtools", "glue", "ggsci", "patchwork", "tidyverse", "dplyr", "Seurat",
"paletteer", "cowplot", "ComplexHeatmap", "circlize", "parallel")
for (pkg in pkgs) {
suppressPackageStartupMessages(library(pkg, character.only = T))
}<- "collabrators"
project <- "wangwenjie"
dataset <- "mouse"
species <- glue("~/projects/{project}/analysis/{dataset}/{species}/figures/fig4")
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 <- jhtools::show_me_the_colors(config_fn = yaml_fn, "stage")[c("E9.5", "E11.5", "E13.5")]
stg_cols
<- 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))
<- theme_classic(base_size = 8) + theme(legend.key.size = unit(3, 'mm')) +
my_theme2 theme(axis.line = element_blank(), axis.text = element_blank(), plot.title = element_text(hjust = .5),
axis.ticks = element_blank(), axis.title = element_blank(),
panel.grid = element_blank(), panel.border = element_rect(linewidth = .5, fill = NA))
# fig4a: mouse regulon activity of scenic -----
write_csv(mouseobj_full_frame, "../rds/fig4a_tf_mouseobj_full_frame.csv")
<-
csv_fn1 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig4a_tf_mouseobj_full_frame.csv"
<- read_csv(csv_fn1)
mouseobj_full_frame <- c("HNF4A(+)", "NEUROD2(+)", "GATA4(+)") |> stringr::str_to_sentence()
setis ::mclapply(setis, function(seti){
parallel<- mouseobj_full_frame |>
p ::filter(name == {{seti}}) |>
dplyrggplot(aes(x = imagecol, y = imagerow, color = value)) +
geom_point(size = 0.1) +
scale_color_viridis_c() +
+
my_theme1 facet_wrap(~ tissue, ncol = 3) +
coord_fixed() +
ggtitle(seti) +
::DarkTheme() + NoGrid() + NoAxes()
Seuratggsave(glue("./fig4a_mouse_tf_{seti}_v250322.pdf"), width = 7, height = 3)
mc.cores = 3)
},
# fig4b: human regulon activity of scenic -----
<- c("HNF4A(+)", "NEUROD2(+)", "GATA4(+)")
setis <-
csv_fn2 "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig4b_tf_humanobj_full_frame.csv"
= read_csv(csv_fn2)
humanobj_full_frame ::mclapply(setis, function(seti){
parallel<- humanobj_full_frame |>
p ::filter(name == {{seti}}) |>
dplyrggplot(aes(x = imagecol, y = imagerow, color = value)) +
geom_point(size = 0.01) +
scale_color_viridis_c() +
+
my_theme1 facet_wrap(~ tissue, nrow = 1) +
coord_fixed() +
ggtitle(seti) +
::DarkTheme() + NoGrid() + NoAxes()
Seuratggsave(glue("./fig4b_human_tf_{seti}_v250322.pdf"), width = 7, height = 3, unit = "in")
mc.cores = 3)
},
# fig4g-i: co-occurrence of regulons and metabolic pathway scores, in mouse -----
<- tibble(tf = "Hnf4a", metabolic = c("Purine metabolism", "Pyrimidine metabolism"))
tbl1 <- tibble(tf = "Sox2", metabolic = c("Alanine, aspartate and glutamate metabolism", "Sphingolipid metabolism"))
tbl2 <- tibble(tf = "Gata4", metabolic = c("Biosynthesis of unsaturated fatty acids", "Citrate cycle (TCA cycle)"))
tbl3 <- bind_rows(tbl1, tbl2, tbl3)
comp_df
<- "~/projects/collabrators/analysis/wangwenjie/mouse/figures/rds/fig4gi_obj_lst_v2.rds"
rds_fn3 <- read_rds(rds_fn3)
obj_lst <- obj_lst[["E115"]]
obj1 = Seurat::GetTissueCoordinates(obj1) |> .[colnames(obj1), ] |> tibble() |>
cord_df mutate(x = imagecol, y = -1 * imagerow)
<- cbind(cord_df, obj1@meta.data)
cord1
<- lapply(1:nrow(comp_df), \(idx) {
plst3 <- comp_df[["tf"]][idx] |> as.character() |> gsub(" / ", "_", x = .)
feat1 <- comp_df[["metabolic"]][idx] |> as.character() |> gsub(" / ", "_", x = .)
feat2 <- cord1 |> dplyr::select(all_of(c("x", "y", feat1, feat2))) |>
df4p ::rename("feat1" = feat1, "feat2" = feat2) |>
dplyrmutate(top = case_when((feat1 > quantile(.$feat1, .85)) & (feat2 > quantile(.$feat2, .85)) ~ "top 15%",
TRUE ~ "no"))
<- ggplot2::ggplot() + ggplot2::geom_point(
sp1 data = df4p, aes(x = x, y = y, color = feat1), show.legend = F,
alpha = 1, size = .2
+ labs(color = feat1) +
) scale_color_continuous(low = "gray90", high = "#ff808f") +
+ coord_fixed() +
my_theme2 labs(title = feat1, color = "")
<- ggplot2::ggplot() + ggplot2::geom_point(
sp2 data = df4p, aes(x = x, y = y, color = feat2), show.legend = F,
alpha = 1, size = .2) + labs(color = feat1, color = "") +
::scale_color_paletteer_c("pals::kovesi.linear_bgy_10_95_c74") +
paletteer+ coord_fixed() +
my_theme2 labs(title = glue("{feat2}"))
<- ggplot2::ggplot() +
p ::geom_point(
ggplot2data = df4p, aes(x = x, y = y, color = feat1), show.legend = F,
alpha = .5, size = .2
+ labs(color = feat1) +
) scale_color_continuous(low = "gray90", high = "#ff808f") +
+ coord_fixed() + labs(color = "tf") +
my_theme2 ::new_scale_color() +
ggnewscale::geom_point(
ggplot2data = df4p, aes(color = feat2, x = x, y = y), show.legend = F,
alpha = .5, size = .2) +
::scale_color_paletteer_c("pals::kovesi.linear_bgy_10_95_c74") +
paletteer+ coord_fixed() + labs(color = "metabolic") +
my_theme2 ::new_scale_color() +
ggnewscalegeom_point(data = dplyr::filter(df4p, top == "top 15%"),
mapping = aes(x = x, y = y, color = top),
size = .3, color = "#f20020") + coord_fixed()
<- p +
p1 ::new_scale_fill() +
ggnewscale::stat_density_2d_filled(
ggplot2data = df4p |> dplyr::filter(top == "top 15%"),
mapping = aes(fill = ..ndensity.., #alpha = ..ndensity..,
x = x, y = y), alpha = .5,
geom = "raster", contour = F, show.legend = T
+
) ::scale_fill_gradientn(colors = c("white", "#F19E62FF", "yellow")) +
ggplot2coord_fixed() + theme(legend.position = "right")
= p1 +
p2 ::new_scale_fill() +
ggnewscalegeom_density_2d(
aes(x = x, y = y),
data = df4p |> dplyr::filter(top == "top 15%"),
contour_var = "ndensity", alpha = .8,
show.legend = T, linewidth = .2
+
) coord_fixed() + labs(title = "intersection of top 15%") +
theme(plot.title = element_text(hjust = .5))
+ sp2 + p2 + patchwork::plot_layout(ncol = 3, width = c(1, 1, 1))
sp1
})pdf(glue("fig4gi_e115_tf_mz_co_expr.pdf"), width = 8, height = 3)
print(plst3)
dev.off()
16 Figure 4
16.1 Figure 4 | Species-specific metabolic features across different mammals
16.1.1
code: