Last updated: 2021-02-28

Checks: 7 0

Knit directory: liver-disease-atlas/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20201218) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 7f331d0. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/01-mouse-chronic-ccl4_cache/
    Ignored:    analysis/02-mouse-acute-apap_cache/
    Ignored:    analysis/03-mouse-acute-ccl4_cache/
    Ignored:    analysis/04-mouse-acute-ph_cache/
    Ignored:    analysis/05-mouse-acute-bdl_cache/
    Ignored:    analysis/06-mouse-acute-lps_cache/
    Ignored:    analysis/07-mouse-acute-tunicamycin_cache/
    Ignored:    analysis/08-human-diehl-nafld_cache/
    Ignored:    analysis/09-human-hampe13-nash_cache/
    Ignored:    analysis/10-human-hampe14-misc_cache/
    Ignored:    analysis/11-human-hoang-nafld_cache/
    Ignored:    analysis/12-human-ramnath-fibrosis_cache/
    Ignored:    analysis/13-meta-chronic-vs-acute_cache/
    Ignored:    analysis/14-meta-mouse-vs-human_cache/
    Ignored:    analysis/15_plot-chronic-ccl4_cache/
    Ignored:    analysis/16-plot-acute-apap_cache/
    Ignored:    code/.DS_Store
    Ignored:    code/README.html
    Ignored:    code/meta-mouse-vs-human/.DS_Store
    Ignored:    data.zip
    Ignored:    data/.DS_Store
    Ignored:    data/annotation/
    Ignored:    data/human-diehl-nafld/
    Ignored:    data/human-hampe13-nash/
    Ignored:    data/human-hampe14-misc/
    Ignored:    data/human-hoang-nafld/
    Ignored:    data/human-ramnath-fibrosis/
    Ignored:    data/meta-chronic-vs-acute/
    Ignored:    data/meta-mouse-vs-human/
    Ignored:    data/mouse-acute-apap/
    Ignored:    data/mouse-acute-bdl/
    Ignored:    data/mouse-acute-ccl4/
    Ignored:    data/mouse-acute-lps/
    Ignored:    data/mouse-acute-ph/
    Ignored:    data/mouse-acute-tunicamycin/
    Ignored:    data/mouse-chronic-ccl4/
    Ignored:    external_software/.DS_Store
    Ignored:    external_software/README.html
    Ignored:    external_software/stem/.DS_Store
    Ignored:    geo_submission/
    Ignored:    output/.DS_Store
    Ignored:    output/README.html
    Ignored:    renv/library/
    Ignored:    renv/staging/

Untracked files:
    Untracked:  figures/
    Untracked:  output/human-diehl-nafld/
    Untracked:  output/human-hampe13-nash/
    Untracked:  output/human-hampe14-misc/
    Untracked:  output/human-hoang-nafld/
    Untracked:  output/human-ramnath-fibrosis/
    Untracked:  output/meta-chronic-vs-acute/
    Untracked:  output/meta-mouse-vs-human/
    Untracked:  output/mouse-acute-apap/
    Untracked:  output/mouse-acute-bdl/
    Untracked:  output/mouse-acute-ccl4/
    Untracked:  output/mouse-acute-lps/
    Untracked:  output/mouse-acute-ph/
    Untracked:  output/mouse-acute-tunicamycin/
    Untracked:  output/mouse-chronic-ccl4/
    Untracked:  tables/

Unstaged changes:
    Modified:   .gitignore
    Deleted:    analysis/human-diehl-nafld.Rmd
    Deleted:    analysis/human-hampe13-nash.Rmd
    Deleted:    analysis/human-hampe14-misc.Rmd
    Deleted:    analysis/human-hoang-nafld.Rmd
    Deleted:    analysis/human-ramnath-fibrosis.Rmd
    Deleted:    analysis/meta-chronic-vs-acute.Rmd
    Deleted:    analysis/meta-mouse-vs-human.Rmd
    Deleted:    analysis/mouse-acute-apap.Rmd
    Deleted:    analysis/mouse-acute-bdl.Rmd
    Deleted:    analysis/mouse-acute-ccl4.Rmd
    Deleted:    analysis/mouse-acute-lps.Rmd
    Deleted:    analysis/mouse-acute-ph.Rmd
    Deleted:    analysis/mouse-acute-tunicamycin.Rmd
    Deleted:    analysis/mouse-chronic-ccl4.Rmd
    Deleted:    analysis/plot-acute-apap.Rmd
    Deleted:    analysis/plot-acute-bdl.Rmd
    Deleted:    analysis/plot-acute-ccl4.Rmd
    Deleted:    analysis/plot-acute-ph.Rmd
    Deleted:    analysis/plot-chronic-ccl4.Rmd
    Deleted:    analysis/plot-chronic-vs-acute.Rmd
    Deleted:    analysis/plot-mouse-vs-human.Rmd
    Deleted:    analysis/plot-precision-recall.Rmd
    Deleted:    analysis/plot-study-overview.Rmd
    Deleted:    analysis/save-tables.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/17-plot-acute-ccl4.Rmd) and HTML (docs/17-plot-acute-ccl4.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 7f331d0 christianholland 2021-02-28 wflow_publish("analysis/*", delete_cache = TRUE, republish = TRUE)

Introduction

Here we generate publication ready plots of the analysis of the acute CCl4 mouse model.

Libraries and sources

These libraries and sources are used for this analysis.

library(tidyverse)
library(tidylog)
library(here)

library(AachenColorPalette)
library(cowplot)
library(lemon)
library(ggpubr)
library(patchwork)

source(here("code/utils-plots.R"))

Definition of global variables that are used throughout this analysis.

# i/o
data_path <- "data/mouse-acute-ccl4"
output_path <- "output/mouse-acute-ccl4"

# graphical parameters
# fontsize
fz <- 7

# keys to annotate contrasts
key_mm <- readRDS(here("data/meta-chronic-vs-acute/contrast_annotation.rds"))

Design

design <- ggdraw() +
  draw_image(here(data_path, "exp-design.pdf"))

Histology

histology <- ggdraw() +
  draw_image(here(data_path, "histology.png"))

Liver enyzmes

df <- read_csv2(here(data_path, "liver_enzymes.csv")) %>%
  mutate(time = fct_inorder(time)) %>%
  pivot_longer(col = -c(time), names_to = "enzyme", values_to = "y") %>%
  mutate(enzyme = factor(enzyme, levels = c("ALT", "AST")))

df_summary <- df %>%
  group_by(time, enzyme) %>%
  summarise(mean_se(y)) %>%
  ungroup()

liver_enzymes <- df_summary %>%
  ggplot(aes(x = time, y = y)) +
  geom_errorbar(aes(ymin = ymin, ymax = ymax), width = 0.5) +
  geom_col() +
  facet_rep_wrap(~enzyme, scales = "free", ncol = 1) +
  labs(x = NULL, y = "U/L") +
  my_theme(grid = "y", fsize = fz) +
  stat_compare_means(
    data = df, label = "p.signif",
    ref.group = "Control", hide.ns = T
  ) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

liver_enzymes

PCA

pca_result <- readRDS(here(output_path, "pca_result.rds"))

keys <- key_mm %>%
  filter(treatment == "CCl4" & class == "Acute") %>%
  distinct(time = value, label = time_label2) %>%
  drop_na() %>%
  add_row(time = 0, label = "Control") %>%
  mutate(time = ordered(time))

pca_plot <- pca_result$coords %>%
  arrange(time) %>%
  inner_join(keys, by = "time") %>%
  mutate(label = fct_inorder(label)) %>%
  ggplot(aes(x = PC1, y = PC2, color = label, label = label)) +
  geom_point() +
  labs(
    x = paste0("PC1", " (", pca_result$var[1], "%)"),
    y = paste0("PC2", " (", pca_result$var[2], "%)"),
    color = "Time"
  ) +
  my_theme(fsize = fz) +
  theme(legend.position = "top",
        legend.box.margin = margin(10, 0, -20, 0)) +
  scale_color_manual(values = aachen_color(c(
    "blue", "purple", "violet",
    "bordeaux", "red", "orange",
    "maygreen", "green", "turquoise",
    "petrol"
  )))

pca_plot

Volcano plot

df <- readRDS(here(output_path, "limma_result.rds")) %>%
  filter(contrast_reference == "ccl4") %>%
  inner_join(key_mm, by = "contrast") %>%
  select(-contrast) %>%
  rename(contrast = time_label2) %>%
  mutate(contrast = fct_drop(contrast)) %>%
  mutate(regulation = fct_recode(regulation,
    Up = "up", Down = "down",
    n.s. = "ns"
  ))

deg_count <- df %>%
  add_count(contrast, regulation) %>%
  filter(regulation != "n.s.") %>%
  mutate(regulation = fct_drop(regulation)) %>%
  mutate(
    logFC = case_when(
      regulation == "Up" ~ 0.75 * max(logFC),
      regulation == "Down" ~ 0.75 * min(logFC)
    ),
    pval = 0.4
  ) %>%
  distinct(n, contrast, logFC, pval, regulation, value) %>%
  complete(contrast, nesting(regulation, logFC, pval), fill = list(n = 0))

main_time <- c(8,24,48)
# for main panel
volcano_main <- df %>%
  filter(value %in% main_time) %>%
  plot_volcano(nrow = 1) +
  geom_text(
    data = filter(deg_count, value %in% main_time),
    aes(y = pval, label = n), size = fz / (14 / 5),
    hjust = "inward", vjust = "inward",
    show.legend = F
  ) +
  theme(
    legend.position = "top",
    legend.box.margin = margin(-10, 0, -10, 0)
  ) +
  labs(color = "Regulation") +
  my_theme(grid = "y", fsize = fz)

# for supp panel
volcano_supp <- df %>%
  filter(!value %in% main_time) %>%
  plot_volcano(ncol = 1) +
  geom_text(
    data = filter(deg_count, !value %in% main_time),
    aes(y = pval, label = n), size = fz / (14 / 5),
    show.legend = F
  ) +
  theme(
    legend.position = "top",
    legend.box.margin = margin(-10, 0, -10, 0)
  ) +
  labs(color = "Regulation") +
  my_theme(grid = "y", fsize = fz)

volcano_main

volcano_supp

Top DEGs

df <- readRDS(here(output_path, "limma_result.rds")) %>%
  filter(contrast_reference == "ccl4") %>%
  inner_join(key_mm) %>%
  select(-class) %>%
  rename(class = time_label2)

top_genes_df <- df %>% 
  group_by(class, sign(logFC)) %>%
  slice_max(order_by = abs(statistic), n = 10, with_ties = F) %>%
  ungroup() %>% 
  nest(data = -c(class, value))

plots <- top_genes_df %>%
  mutate(p = pmap(., .f = plot_top_genes, fontsize = fz))

main_time <- c(8,24,48)

# for main panel
top_genes_main <- plots %>%
  filter(value %in% main_time) %>%
  pull(p) %>%
  wrap_plots() +
  plot_layout(nrow = 1)

# for supp panel
top_genes_supp <- plots %>%
  filter(!value %in% main_time) %>%
  pull(p) %>%
  wrap_plots() +
  plot_layout(ncol = 1)

top_genes_main

top_genes_supp

Time series cluster

stem_res <- readRDS(here(output_path, "stem_result.rds")) %>%
  filter(key == "ccl4") %>%
  filter(p <= 0.05) %>%
  mutate(profile = fct_reorder(str_c(
    "STEM ID: ",
    as.character(profile)
  ), p))

# extract meta data of profiles
profile_anno <- stem_res %>%
  group_by(key, profile, p) %>%
  mutate(y = 1.2 * abs(max(value))) %>%
  ungroup() %>%
  mutate(max_time = max(time)) %>%
  distinct(key, profile, p, size, y, max_time) %>%
  mutate(label = str_c(size, " ", "genes"))

ts_cluster <- stem_res %>%
  plot_stem_profiles(model_profile = F, nrow = 1) +
  labs(x = "Time in Hours") +
  geom_text(
    data = profile_anno, aes(x = 0, y = y, label = label),
    inherit.aes = F, size = fz / (14 / 5), hjust = "inward"
  ) +
  my_theme(grid = "no", fsize = fz) +
  scale_x_continuous(
    breaks = unique(stem_res$time),
    guide = guide_axis(n.dodge = 3)
  )

ts_cluster

Collage

Supplementary Figure 2.2

sfig2_2 <- (design + histology) /
  ((liver_enzymes | pca_plot) + plot_layout(widths = c(1,3))) /
  ((volcano_main / top_genes_main)) /
  ts_cluster +
  plot_layout(height = c(1.5, 2, 1.75, 0.75)) +
  plot_annotation(tag_levels = list(c("A", "B", "C", "D", "E", "F", "", "", "",
                                      "", "", "G"))) &
  theme(
    plot.tag = element_text(size = fz + 3, face = "bold"),
    legend.key.height = unit(11.5, "pt"),
    legend.key.width = unit(12.5, "pt")
  )

sfig2_2


ggsave(here("figures/Supplementary Figure 2.2.pdf"), sfig2_2,
  width = 21, height = 29.7, units = c("cm")
)
ggsave(here("figures/Supplementary Figure 2.2.png"), sfig2_2,
  width = 21, height = 29.7, units = c("cm")
)

Supplementary Figure 2.3

sfig2_3 <- (volcano_supp | top_genes_supp) +
  plot_annotation(tag_levels = list(c("A", "B"))) &
  theme(
    plot.tag = element_text(size = fz + 3, face = "bold"),
    legend.key.height = unit(11.5, "pt"),
    legend.key.width = unit(12.5, "pt")
  )

sfig2_3


ggsave(here("figures/Supplementary Figure 2.3.pdf"), sfig2_3,
  width = 21, height = 29.7, units = c("cm")
)
ggsave(here("figures/Supplementary Figure 2.3.png"), sfig2_3,
  width = 21, height = 29.7, units = c("cm")
)

Time spend to execute this analysis: 01:16 minutes.


sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Mojave 10.14.5
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices datasets  utils     methods   base     
#> 
#> other attached packages:
#>  [1] patchwork_1.1.1          ggpubr_0.4.0             lemon_0.4.5             
#>  [4] cowplot_1.1.0            AachenColorPalette_1.1.2 here_1.0.1              
#>  [7] tidylog_1.0.2            forcats_0.5.0            stringr_1.4.0           
#> [10] dplyr_1.0.2              purrr_0.3.4              readr_1.4.0             
#> [13] tidyr_1.1.2              tibble_3.0.4             ggplot2_3.3.2           
#> [16] tidyverse_1.3.0          workflowr_1.6.2         
#> 
#> loaded via a namespace (and not attached):
#>  [1] fs_1.5.0          lubridate_1.7.9.2 httr_1.4.2        rprojroot_2.0.2  
#>  [5] tools_4.0.2       backports_1.2.1   R6_2.5.0          DBI_1.1.0        
#>  [9] colorspace_2.0-0  withr_2.3.0       tidyselect_1.1.0  gridExtra_2.3    
#> [13] curl_4.3          compiler_4.0.2    git2r_0.27.1      cli_2.2.0        
#> [17] rvest_0.3.6       xml2_1.3.2        labeling_0.4.2    scales_1.1.1     
#> [21] digest_0.6.27     foreign_0.8-80    rmarkdown_2.6     rio_0.5.16       
#> [25] pkgconfig_2.0.3   htmltools_0.5.0   dbplyr_2.0.0      rlang_0.4.9      
#> [29] readxl_1.3.1      rstudioapi_0.13   generics_0.1.0    farver_2.0.3     
#> [33] jsonlite_1.7.2    gtools_3.8.2      zip_2.1.1         car_3.0-10       
#> [37] magrittr_2.0.1    Rcpp_1.0.5        munsell_0.5.0     fansi_0.4.1      
#> [41] abind_1.4-5       lifecycle_0.2.0   stringi_1.5.3     whisker_0.4      
#> [45] yaml_2.2.1        carData_3.0-4     plyr_1.8.6        grid_4.0.2       
#> [49] promises_1.1.1    crayon_1.3.4      lattice_0.20-41   haven_2.3.1      
#> [53] hms_0.5.3         magick_2.5.2      knitr_1.30        pillar_1.4.7     
#> [57] ggsignif_0.6.0    codetools_0.2-16  clisymbols_1.2.0  reprex_0.3.0     
#> [61] glue_1.4.2        evaluate_0.14     data.table_1.13.4 renv_0.12.3      
#> [65] modelr_0.1.8      vctrs_0.3.6       httpuv_1.5.4      cellranger_1.1.0 
#> [69] gtable_0.3.0      assertthat_0.2.1  xfun_0.19         openxlsx_4.2.3   
#> [73] broom_0.7.3       rstatix_0.6.0     later_1.1.0.1     ellipsis_0.3.1