This notebook assembles the WGCNA module perturbation figure (Figure 6) from pre-generated panel RDS files.
Panels: - A: CTRL consensus network dendrogram with module colors - B: Delta kWithin boxplot (connectivity change per module) with GO annotations - C: Hub gene connectivity scatter plot (CTRL vs Inv4m)
suppressPackageStartupMessages({
library(tidyverse)
library(here)
library(cowplot)
library(patchwork)
})
# Load project paths
source(here("scripts", "utils", "setup_paths.R"))
paths <- setup_project_paths("inversion_paper")
# Pipeline run directory
run_dir <- here("results/inversion_paper/field_perturbation/run_20251231_201332")
# Panel paths
panel_paths <- list(
A = file.path(run_dir, "04_consensus_networks/ctrl/dendrogram_plot.rds"),
B = file.path(run_dir, "06_preservation/delta_kWithin_boxplot_annotated.rds"),
C = file.path(run_dir, "07_module_annotation/hub_connectivity_plot.rds")
)
# Verify all panels exist
for (panel in names(panel_paths)) {
if (!file.exists(panel_paths[[panel]])) {
stop(paste("Panel", panel, "not found:", panel_paths[[panel]]))
}
}
cat("All panel files found.\n")
## All panel files found.
p_A <- readRDS(panel_paths$A)
p_B <- readRDS(panel_paths$B)
p_C <- readRDS(panel_paths$C)
cat("Panels loaded successfully.\n")
## Panels loaded successfully.
print(p_A)
print(p_B)
print(p_C)
# Bottom row: B and C side by side
bottom_row <- plot_grid(
p_B,
p_C,
ncol = 2,
labels = c("B", "C"),
label_size = 35,
rel_widths = c(1, 1)
)
# Combined: A on top, B+C below
fig_combined <- plot_grid(
p_A,
bottom_row,
ncol = 1,
labels = c("A", ""),
label_size = 35,
rel_heights = c(0.3, 0.7)
)
ggsave(
file.path(paths$figures, "WGCNA_module_perturbation.png"),
fig_combined,
width = 14, height = 12,
dpi = 300
)
ggsave(
file.path(paths$figures, "WGCNA_module_perturbation.pdf"),
fig_combined,
width = 14, height = 12
)
print(fig_combined)
sessionInfo()
## R version 4.5.2 (2025-10-31)
## Platform: aarch64-apple-darwin20
## Running under: macOS Tahoe 26.2
##
## Matrix products: default
## BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
##
## locale:
## [1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] patchwork_1.3.2 cowplot_1.2.0 here_1.0.2 lubridate_1.9.4
## [5] forcats_1.0.1 stringr_1.6.0 dplyr_1.1.4 purrr_1.2.0
## [9] readr_2.1.6 tidyr_1.3.2 tibble_3.3.0 ggplot2_4.0.1
## [13] tidyverse_2.0.0
##
## loaded via a namespace (and not attached):
## [1] yulab.utils_0.2.3 rappdirs_0.3.3 sass_0.4.10 generics_0.1.4
## [5] ggplotify_0.1.3 stringi_1.8.7 hms_1.1.4 digest_0.6.39
## [9] magrittr_2.0.4 evaluate_1.0.5 grid_4.5.2 timechange_0.3.0
## [13] RColorBrewer_1.1-3 fastmap_1.2.0 rprojroot_2.1.1 jsonlite_2.0.0
## [17] ggrepel_0.9.6 scales_1.4.0 textshaping_1.0.4 jquerylib_0.1.4
## [21] cli_3.6.5 rlang_1.1.6 withr_3.0.2 cachem_1.1.0
## [25] yaml_2.3.12 otel_0.2.0 tools_4.5.2 tzdb_0.5.0
## [29] vctrs_0.6.5 R6_2.6.1 gridGraphics_0.5-1 lifecycle_1.0.4
## [33] fs_1.6.6 ragg_1.5.0 pkgconfig_2.0.3 pillar_1.11.1
## [37] bslib_0.9.0 gtable_0.3.6 Rcpp_1.1.0 glue_1.8.0
## [41] systemfonts_1.3.1 xfun_0.55 tidyselect_1.2.1 knitr_1.51
## [45] dichromat_2.0-0.1 farver_2.1.2 htmltools_0.5.9 labeling_0.4.3
## [49] rmarkdown_2.30 compiler_4.5.2 S7_0.2.1