Last updated: 2021-03-12

Checks: 6 1

Knit directory: hesc-epigenomics/

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.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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(20210202) 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 ef20c53. 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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/bed/
    Ignored:    data/bw
    Ignored:    data/igv/
    Ignored:    data/meta/
    Ignored:    data/peaks
    Ignored:    data/rnaseq/

Untracked files:
    Untracked:  analysis/fig_01_quantitative_chip.Rmd
    Untracked:  analysis/global_bins.Rmd
    Untracked:  analysis/histone_marks_vs_expression.Rmd
    Untracked:  output/annotations/

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   data/README.md

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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Summary

This notebook includes the figures related to the quantitative side of ChIP:

  • Global Read count levels.
  • ChromHMM descriptive plots per mark (+ EZH2i?)

Supplementary possibles:

  • Global ChIP comparison bin-based to other datasets, correlations.

Helper functions

#' Calculate INRC from a mapped read counts table, and append such values
#' to it.
#'
#' @param counts Counts table. Corresponding file is provided as part of the 
#'   included metadata.
#' @param selector Counts column used. Final_mapped represents the final number
#'   of reads after deduplication and blacklisting.

#' @return A table including INRC and INRC norm to naive reference
calculate_inrc <- function(counts, selector = "final_mapped") {
  counts$condition <- paste(counts$celltype, counts$treatment, sep="_")
  
  inputs <- counts[counts$ip == "Input", c("library", selector)]
  colnames(inputs) <- c("library", "input_reads")
  
  non_inputs <- counts[counts$ip != "Input",]
  counts <- merge(non_inputs, inputs, by.x="input", by.y="library")
  counts$inrc <- counts[, selector] / counts[, "input_reads"]
  
  references <- counts[grepl("_Ni_pooled", counts$library), c("ip", "inrc")]
  colnames(references) <- c("ip", "ref_inrc")
  
  counts <- merge(counts, references, by="ip")
  counts$norm_to_naive <- log2(counts$inrc / counts$ref_inrc)
  
  id_vars <- c("ip", "treatment", "celltype", "condition", "replicate", "norm_to_naive")
  inrc <- counts[, c(id_vars)]
  
  inrc$condition <- factor(inrc$condition, levels = c("Naive_Untreated", "Primed_Untreated", "Naive_EZH2i", "Primed_EZH2i"))
  
  inrc
}

#' Barplot INRC pooled vs replicates per condition
#'
#' @param inrc Table with the INRC values
#' @param ip Which IP to plot
#' @param colors Corresponding colors
inrc_barplot <- function(inrc, ip, colors, font = 12) {
  inrc <- inrc[inrc$ip == ip, ]
  
  max_v <- max(abs(inrc$norm_to_naive))
  
  aesthetics <- aes(x = .data[["condition"]],
                    y = .data[["norm_to_naive"]],
                    color = .data[["condition"]])
  
  ggplot(inrc[inrc$replicate!='pooled',], aesthetics) +
  geom_point() +
  geom_bar(data=inrc[inrc$replicate=='pooled',],
           stat='identity', alpha=0.6, aes(fill=condition)) +
  scale_fill_manual(values = colors) +
  scale_color_manual(values = colors) +
  labs(x = "", y = 'log2(INRC vs Naïve)', title = paste(ip, "MINUTE-ChIP")) +
  theme_classic(base_size=font) +
  theme(axis.text.x = element_text(angle=45, hjust=1)) + ylim(-max_v, max_v)
}

colors_list <- c("Naive_EZH2i"="#5F9EA0",
                 "Naive_Untreated"="#278b8b",
                 "Primed_EZH2i"="#f47770",
                 "Primed_Untreated"="#f44b34")

Global read counts

H2AUb levels

counts_file <- file.path(params$datadir, "meta", "Kumar_2020_stats_summary.csv")
counts <- read.table(counts_file, sep="\t", header = T, na.strings = "NA", stringsAsFactors = F)

inrc <- calculate_inrc(counts) 
ip <- "H2Aub"

inrc_barplot(inrc, "H2Aub", colors_list)

You can download data values here: download plot data.

H3K27m3 levels

inrc_barplot(inrc, "H3K27m3", colors_list)

You can download data values here: download plot data.

H3K4m3 levels

inrc_barplot(inrc, "H3K4m3", colors_list)

You can download data values here: download plot data.

ChromHMM global

Here global average per ChromHMM categories are shown.

H3K27m3

bwfiles <- list.files(file.path(params$datadir, "bw/Kumar_2020"), pattern = "H3K27m3.*pooled.*hg38.scaled", full.names = T)
labels <- gsub("_pooled.hg38.scaled.bw", "", basename(bwfiles))
labels <- gsub("_H9", "", labels)

chromhmm <- params$chromhmm

plot_bw_loci_summary_heatmap(bwfiles, chromhmm, labels = labels, remove_top=0.001)

H3K4m3

bwfiles <- list.files(file.path(params$datadir, "bw/Kumar_2020"), pattern = "H3K4m3.*pooled.*hg38.scaled", full.names = T)
labels <- gsub("_pooled.hg38.scaled.bw", "", basename(bwfiles))
labels <- gsub("_H9", "", labels)

plot_bw_loci_summary_heatmap(bwfiles, chromhmm, labels = labels, remove_top=0.001)

H2AUb

bwfiles <- list.files(file.path(params$datadir, "bw/Kumar_2020"), pattern = "H2Aub.*pooled.*hg38.scaled", full.names = T)
labels <- gsub("_pooled.hg38.scaled.bw", "", basename(bwfiles))
labels <- gsub("_H9", "", labels)

chromhmm <- params$chromhmm

plot_bw_loci_summary_heatmap(bwfiles, chromhmm, labels = labels, remove_top=0.001)


sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=sv_SE.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=sv_SE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=sv_SE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=sv_SE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] purrr_0.3.4        knitr_1.31         dplyr_1.0.4        reshape2_1.4.4    
[5] ggplot2_3.3.3      wigglescout_0.12.8 workflowr_1.6.2   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6                  lattice_0.20-41            
 [3] listenv_0.8.0               Rsamtools_2.6.0            
 [5] Biostrings_2.58.0           assertthat_0.2.1           
 [7] rprojroot_2.0.2             digest_0.6.27              
 [9] parallelly_1.23.0           R6_2.5.0                   
[11] GenomeInfoDb_1.26.2         plyr_1.8.6                 
[13] stats4_4.0.4                evaluate_0.14              
[15] highr_0.8                   pillar_1.4.7               
[17] zlibbioc_1.36.0             rlang_0.4.10               
[19] furrr_0.2.2                 S4Vectors_0.28.1           
[21] Matrix_1.3-2                rmarkdown_2.6              
[23] labeling_0.4.2              BiocParallel_1.24.1        
[25] stringr_1.4.0               RCurl_1.98-1.2             
[27] munsell_0.5.0               DelayedArray_0.16.0        
[29] compiler_4.0.4              httpuv_1.5.5               
[31] rtracklayer_1.50.0          xfun_0.21                  
[33] askpass_1.1                 pkgconfig_2.0.3            
[35] BiocGenerics_0.36.0         globals_0.14.0             
[37] htmltools_0.5.1.1           openssl_1.4.3              
[39] tidyselect_1.1.0            SummarizedExperiment_1.20.0
[41] tibble_3.0.6                GenomeInfoDbData_1.2.4     
[43] IRanges_2.24.1              codetools_0.2-18           
[45] matrixStats_0.58.0          XML_3.99-0.5               
[47] future_1.21.0               withr_2.4.1                
[49] crayon_1.4.1                later_1.1.0.1              
[51] GenomicAlignments_1.26.0    bitops_1.0-6               
[53] grid_4.0.4                  gtable_0.3.0               
[55] lifecycle_1.0.0             DBI_1.1.1                  
[57] git2r_0.28.0                magrittr_2.0.1             
[59] scales_1.1.1                stringi_1.5.3              
[61] farver_2.0.3                XVector_0.30.0             
[63] fs_1.5.0                    promises_1.2.0.1           
[65] ellipsis_0.3.1              generics_0.1.0             
[67] vctrs_0.3.6                 RColorBrewer_1.1-2         
[69] tools_4.0.4                 Biobase_2.50.0             
[71] glue_1.4.2                  MatrixGenerics_1.2.0       
[73] parallel_4.0.4              yaml_2.2.1                 
[75] colorspace_2.0-0            GenomicRanges_1.42.0