Last updated: 2020-12-19

Checks: 7 0

Knit directory: meta-liver/

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 e4502df. 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:    .Rproj.user/
    Ignored:    code/.DS_Store
    Ignored:    data/.DS_Store
    Ignored:    data/annotation/
    Ignored:    data/mouse-chronic-ccl4/
    Ignored:    output/mouse-chronic-ccl4/
    Ignored:    renv/library/
    Ignored:    renv/staging/

Untracked files:
    Untracked:  code/annotation/

Unstaged changes:
    Modified:   code/utils-plots.R
    Modified:   code/utils-wrapper.R
    Modified:   renv.lock

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/mouse-chronic-ccl4.Rmd) and HTML (docs/mouse-chronic-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 e4502df christianholland 2020-12-19 Start my new project
html 7bb9aab christianholland 2020-12-18 Build site.
Rmd 261f1a4 christianholland 2020-12-18 Start my new project

Introduction

TODO

Libraries and sources

These libraries and sources are used in this analysis

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

library(edgeR)
#> Warning: package 'edgeR' was built under R version 4.0.3
#> Warning: package 'limma' was built under R version 4.0.3
library(biobroom)
#> Warning: package 'biobroom' was built under R version 4.0.3

library(AachenColorPalette)
library(cowplot)
library(lemon)

options("tidylog.display" = list(print))
source(here("code/utils-rnaseq.R"))
source(here("code/utils-wrapper.R"))
source(here("code/utils-plots.R"))

Analysis specific options

# i/o
data_path <- "data/mouse-chronic-ccl4"
output_path <- "output/mouse-chronic-ccl4"
figure_path <- "output/mouse-chronic-ccl4/figures"

# graphical parameters
# fontsize
fz <- 9

Preliminary exploratory analysis

PCA of raw data

count_matrix <- readRDS(here(data_path, "count_matrix.rds"))
meta <- readRDS(here(data_path, "meta_data.rds"))

stopifnot(colnames(count_matrix) == meta$sample)

# remove constant expressed genes and transform to log2 scale
preprocessed_count_matrix <- preprocess_count_matrix(count_matrix)
#> Discarding 7711 genes 
#> Keeping 24833 genes


pca_result <- do_pca(preprocessed_count_matrix, meta, top_n_var_genes = 2000)
#> left_join: added 3 columns (time, treatment, group)
#>            > rows only in x    0
#>            > rows only in y  ( 0)
#>            > matched rows     36
#>            >                 ====
#>            > rows total       36

plot_pca(pca_result, feature = "time") +
  my_theme()

Version Author Date
7bb9aab christianholland 2020-12-18
plot_pca(pca_result, feature = "treatment") +
  my_theme()

Version Author Date
7bb9aab christianholland 2020-12-18

Data processing

Normalization

count_matrix <- readRDS(here(data_path, "count_matrix.rds"))
meta <- readRDS(here(data_path, "meta_data.rds"))

stopifnot(meta$sample == colnames(count_matrix))

dge_obj <- DGEList(count_matrix, group = meta$group)

# filter low read counts, TMM normalization and logCPM transformation
norm <- voom_normalization(dge_obj)
#> Discarding 17206 genes 
#> Keeping 15338 genes

saveRDS(norm, here(output_path, "normalized_expression.rds"))

PCA of normalized data

expr <- readRDS(here(output_path, "normalized_expression.rds"))
meta <- readRDS(here(data_path, "meta_data.rds"))

pca_result <- do_pca(expr, meta, top_n_var_genes = 1000)
#> left_join: added 3 columns (time, treatment, group)
#>            > rows only in x    0
#>            > rows only in y  ( 0)
#>            > matched rows     36
#>            >                 ====
#>            > rows total       36

saveRDS(pca_result, here(output_path, "pca_result.rds"))

### PC1 vs PC2
plot_pca(pca_result, feature = "time") +
  my_theme()

Version Author Date
7bb9aab christianholland 2020-12-18

plot_pca(pca_result, feature = "treatment") +
  my_theme()

Version Author Date
7bb9aab christianholland 2020-12-18

Differential gene expression analysis

Running limma

# load expression and meta data
expr <- readRDS(here(output_path, "normalized_expression.rds"))
meta <- readRDS(here(data_path, "meta_data.rds"))

stopifnot(colnames(expr) == meta$sample)

# build design matrix
design <- model.matrix(~ 0 + group, data = meta)
rownames(design) <- meta$sample
colnames(design) <- levels(meta$group)

# define contrasts
contrasts <- makeContrasts(
  # effect of olive oil
  oil_2m_vs_0m = oil.2 - wt,
  oil_12m_vs_0m = oil.12 - wt,
  oil_12m_vs_2m = oil.12 - oil.2,

  # treatment vs control ignoring the effect of oil
  ccl_2m_vs_0m = ccl4.2 - wt,
  ccl_6m_vs_0m = ccl4.6 - wt,
  ccl_12m_vs_0m = ccl4.12 - wt,

  # treatment vs control regressing out the effect of oil
  pure_ccl_2m_vs_0m = (ccl4.2 - wt) - (oil.2 - wt),
  pure_ccl_6m_vs_0m = (ccl4.6 - wt) - ((oil.2 + oil.12) / 2 - wt),
  pure_ccl_12m_vs_0m = (ccl4.12 - wt) - (oil.12 - wt),

  # consecutive time point comparison
  consec_12m_vs_6m = ccl4.12 - ccl4.6,
  consec_12m_vs_2m = ccl4.12 - ccl4.2,
  # consec_48w_vs_8w_2 = (ccl4.48 - oil.48) - (ccl4.8 - oil.8),
  consec_6m_vs_2m = ccl4.6 - ccl4.2,
  levels = design
)

limma_result <- run_limma(expr, design, contrasts) %>%
  assign_deg()
#> Warning: `tbl_df()` is deprecated as of dplyr 1.0.0.
#> Please use `tibble::as_tibble()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> select: renamed 3 variables (contrast, logFC, pval) and dropped one variable
#> group_by: one grouping variable (contrast)
#> mutate (grouped): new variable 'fdr' (double) with 115,674 unique values and 0% NA
#> ungroup: no grouping variables
#> mutate: new variable 'regulation' (character) with 3 unique values and 0% NA
#> mutate: converted 'regulation' from character to factor (0 new NA)

deg_df <- limma_result %>%
  mutate(contrast = factor(contrast, levels = c(
    "ccl_2m_vs_0m", "ccl_6m_vs_0m",
    "ccl_12m_vs_0m",
    "pure_ccl_2m_vs_0m",
    "pure_ccl_6m_vs_0m",
    "pure_ccl_12m_vs_0m",
    "consec_6m_vs_2m",
    "consec_12m_vs_2m",
    "consec_12m_vs_6m",
    "oil_2m_vs_0m", "oil_12m_vs_0m",
    "oil_12m_vs_2m"
  ))) %>%
  mutate(contrast_reference = case_when(
    str_detect(contrast, "oil") ~ "oil",
    str_detect(contrast, "^pure_ccl") ~ "pure_ccl4",
    str_detect(contrast, "^ccl") ~ "ccl4",
    str_detect(contrast, "consec") ~ "consec"
  ))
#> mutate: changed 0 values (0%) of 'contrast' (0 new NA)
#> mutate: new variable 'contrast_reference' (character) with 4 unique values and 0% NA

saveRDS(deg_df, here(output_path, "limma_result.rds"))

Volcano plots

df <- readRDS(here(output_path, "limma_result.rds"))

df %>%
  filter(contrast_reference == "pure_ccl4") %>%
  plot_volcano() +
  my_theme(grid = "y")
#> filter: removed 138,042 rows (75%), 46,014 rows remaining
#> rename: renamed one variable (p)

Translation to HGNC symbols

For later comparisons to human data the mouse gene symbols are mapped to their human orthologs

df <- readRDS(here(output_path, "limma_result.rds"))

mapped_df <- df %>%
  translate_gene_ids(from = "symbol_mgi", to = "symbol_hgnc") %>%
  drop_na() %>%
  # for duplicated genes, keep the one with the highest absolute logFC
  group_by(contrast_reference, contrast, gene) %>%
  slice_max(order_by = abs(logFC), n = 1, with_ties = F) %>%
  ungroup()
#> select: dropped 6 variables (ensembl_mgi, ensembl_v_mgi, entrez_mgi, ensembl_hgnc, ensembl_v_hgnc, …)
#> drop_na: removed 1,905 rows (6%), 30,461 rows remaining
#> rename: renamed one variable (symbol_mgi)
#> left_join: added one column (symbol_hgnc)
#>            > rows only in x    22,992
#>            > rows only in y  ( 16,094)
#>            > matched rows     172,404    (includes duplicates)
#>            >                 =========
#>            > rows total       195,396
#> select: renamed one variable (gene) and dropped one variable
#> drop_na: removed 22,992 rows (12%), 172,404 rows remaining
#> group_by: 3 grouping variables (contrast_reference, contrast, gene)
#> slice_max (grouped): removed 11,328 rows (7%), 161,076 rows remaining
#> ungroup: no grouping variables

saveRDS(mapped_df, here(output_path, "limma_result_hs.rds"))

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] lemon_0.4.5              cowplot_1.1.0            AachenColorPalette_1.1.2
#>  [4] biobroom_1.22.0          broom_0.7.3              edgeR_3.32.0            
#>  [7] limma_3.46.0             here_1.0.1               tidylog_1.0.2           
#> [10] forcats_0.5.0            stringr_1.4.0            dplyr_1.0.2             
#> [13] purrr_0.3.4              readr_1.4.0              tidyr_1.1.2             
#> [16] tibble_3.0.4             ggplot2_3.3.2            tidyverse_1.3.0         
#> [19] workflowr_1.6.2         
#> 
#> loaded via a namespace (and not attached):
#>  [1] Biobase_2.50.0      httr_1.4.2          viridisLite_0.3.0  
#>  [4] jsonlite_1.7.2      modelr_0.1.8        assertthat_0.2.1   
#>  [7] renv_0.12.3         cellranger_1.1.0    yaml_2.2.1         
#> [10] pillar_1.4.7        backports_1.2.1     lattice_0.20-41    
#> [13] glue_1.4.2          digest_0.6.27       promises_1.1.1     
#> [16] rvest_0.3.6         colorspace_2.0-0    htmltools_0.5.0    
#> [19] httpuv_1.5.4        plyr_1.8.6          clisymbols_1.2.0   
#> [22] pkgconfig_2.0.3     haven_2.3.1         scales_1.1.1       
#> [25] whisker_0.4         later_1.1.0.1       git2r_0.27.1       
#> [28] farver_2.0.3        generics_0.1.0      ellipsis_0.3.1     
#> [31] withr_2.3.0         BiocGenerics_0.36.0 cli_2.2.0          
#> [34] magrittr_2.0.1      crayon_1.3.4        readxl_1.3.1       
#> [37] evaluate_0.14       fs_1.5.0            fansi_0.4.1        
#> [40] xml2_1.3.2          tools_4.0.2         hms_0.5.3          
#> [43] lifecycle_0.2.0     munsell_0.5.0       reprex_0.3.0       
#> [46] locfit_1.5-9.4      compiler_4.0.2      rlang_0.4.9        
#> [49] grid_4.0.2          rstudioapi_0.13     labeling_0.4.2     
#> [52] rmarkdown_2.6       gtable_0.3.0        DBI_1.1.0          
#> [55] R6_2.5.0            gridExtra_2.3       lubridate_1.7.9.2  
#> [58] knitr_1.30          rprojroot_2.0.2     stringi_1.5.3      
#> [61] parallel_4.0.2      Rcpp_1.0.5          vctrs_0.3.6        
#> [64] dbplyr_2.0.0        tidyselect_1.1.0    xfun_0.19