Last updated: 2021-09-10

Checks: 7 0

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.


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(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 8e2ab66. 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:    analysis/figure/
    Ignored:    data/bed/
    Ignored:    data/bw/
    Ignored:    data/rnaseq/
    Ignored:    data_backup/
    Ignored:    figures_data/

Untracked files:
    Untracked:  Kumar_2021_hESC_data.zip
    Untracked:  analysis/sup_01_replicates.Rmd
    Untracked:  data/Lanner_lineagemarker_genes.csv
    Untracked:  data/Messmer_intermediate_down_top50.txt
    Untracked:  data/Messmer_intermediate_up_top50.txt
    Untracked:  data/meta/Kumar_2020_master_bins_10kb_table_final_raw.tsv
    Untracked:  data/meta/Kumar_2020_master_gene_table_rnaseq_shrunk_annotated.tsv
    Untracked:  output/

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/master_bins_table.Rmd
    Modified:   analysis/master_gene_table.Rmd
    Modified:   analysis/rnaseq_comparison.Rmd
    Deleted:    data/README.md
    Deleted:    data/meta/Court_2017_gene_names_uniq.txt
    Deleted:    data/meta/Kumar_2020_master_gene_table_rnaseq_shrunk_annotated.zip
    Deleted:    data/meta/Kumar_2020_public_data_plus_layout.csv
    Deleted:    data/meta/biblio.bib
    Deleted:    data/meta/colors.R
    Deleted:    data/meta/style_info.csv
    Deleted:    data/other/Messmer_2019/Messmer_intermediate_down_top50.txt
    Deleted:    data/other/Messmer_2019/Messmer_intermediate_up_top50.txt

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/fig_01_quantitative_chip.Rmd) and HTML (docs/fig_01_quantitative_chip.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 8e2ab66 C. Navarro 2021-09-10 Fig 1 clean
html e4f9f1e C. Navarro 2021-07-01 Build site.
Rmd 5976105 C. Navarro 2021-07-01 wflow_publish(“./analysis/fig_01_quantitative_chip.Rmd”, verbose = T)
Rmd 9e8b1a9 cnluzon 2021-05-26 Metadata folder added
html 9e8b1a9 cnluzon 2021-05-26 Metadata folder added
html a9d0a78 cnluzon 2021-04-13 Build site.
Rmd dcfe4a4 cnluzon 2021-04-13 wflow_publish(“./analysis/fig_01_quantitative_chip.Rmd”)
html 054d3f5 cnluzon 2021-03-22 Build site.
Rmd 07bb6d9 cnluzon 2021-03-22 H9 ChromHMM annotation
html a6a00b6 cnluzon 2021-03-12 Fig1 with ttest
Rmd 8f01ba6 cnluzon 2021-03-12 Stat tests in global counts
Rmd 0f37941 cnluzon 2021-03-12 Fig1 fresh
html 0f37941 cnluzon 2021-03-12 Fig1 fresh

Summary

Supplementary code for panel 1 figures.

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 <- 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 = 16) {
  inrc <- inrc[inrc$ip == ip, ]
  
  # So paired test takes right replicates
  inrc <- inrc[order(inrc$condition, inrc$replicate), ]
  
  max_v <- max(abs(inrc$norm_to_naive))
  
  aesthetics <- aes(x = .data[["condition"]],
                    y = .data[["norm_to_naive"]],
                    color = .data[["condition"]])
  
  my_comp <- list(c("Naive_Untreated", "Primed_Untreated"),
                  c("Naive_Untreated", "Naive_EZH2i"),
                  c("Primed_Untreated", "Primed_EZH2i"),
                  c("Naive_EZH2i", "Primed_EZH2i"))
  
  stats_method <- "t.test"
  
  ggplot(inrc[inrc$replicate != 'pooled',], aesthetics) +
    geom_point() +
    stat_compare_means(
      method = stats_method,
      paired = TRUE,
      comparisons = my_comp,
      label = "p.format"
    ) +
    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 = 'INRC fraction vs Naïve',
      title = paste(ip, "MINUTE-ChIP"),
      caption = paste(stats_method, "signif. test, paired")
    ) +
    theme_classic(base_size = font) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    ylim(0, 1.5)
}

colors_list <- c("Naive_EZH2i"="#82c5c6",
                 "Naive_Untreated"="#278b8b",
                 "Primed_EZH2i"="#f49797",
                 "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)

Version Author Date
e4f9f1e C. Navarro 2021-07-01
9e8b1a9 cnluzon 2021-05-26
a9d0a78 cnluzon 2021-04-13
a6a00b6 cnluzon 2021-03-12
0f37941 cnluzon 2021-03-12

You can download data values here: download plot data.

H3K27m3 levels

inrc_barplot(inrc, "H3K27m3", colors_list)
Warning: Removed 3 rows containing missing values (geom_signif).

Version Author Date
e4f9f1e C. Navarro 2021-07-01
9e8b1a9 cnluzon 2021-05-26
a9d0a78 cnluzon 2021-04-13
a6a00b6 cnluzon 2021-03-12
0f37941 cnluzon 2021-03-12

You can download data values here: download plot data.

H3K4m3 levels

inrc_barplot(inrc, "H3K4m3", colors_list)

Version Author Date
e4f9f1e C. Navarro 2021-07-01
9e8b1a9 cnluzon 2021-05-26
a9d0a78 cnluzon 2021-04-13
a6a00b6 cnluzon 2021-03-12
0f37941 cnluzon 2021-03-12

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)

Attaching package: 'purrr'
The following object is masked from 'package:GenomicRanges':

    reduce
The following object is masked from 'package:IRanges':

    reduce

Version Author Date
e4f9f1e C. Navarro 2021-07-01
9e8b1a9 cnluzon 2021-05-26
a9d0a78 cnluzon 2021-04-13
054d3f5 cnluzon 2021-03-22
a6a00b6 cnluzon 2021-03-12
0f37941 cnluzon 2021-03-12

You can download data values here: download plot data.

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)

Version Author Date
e4f9f1e C. Navarro 2021-07-01
9e8b1a9 cnluzon 2021-05-26
a9d0a78 cnluzon 2021-04-13
054d3f5 cnluzon 2021-03-22
a6a00b6 cnluzon 2021-03-12
0f37941 cnluzon 2021-03-12

You can download data values here: download plot data.

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)

Version Author Date
e4f9f1e C. Navarro 2021-07-01
9e8b1a9 cnluzon 2021-05-26
a9d0a78 cnluzon 2021-04-13
054d3f5 cnluzon 2021-03-22
a6a00b6 cnluzon 2021-03-12
0f37941 cnluzon 2021-03-12

You can download data values here: download plot data.

Genome-wide 10kb bins

H3K27m3 Naïve vs Primed

bins_table <- "./data/meta/Kumar_2020_master_bins_10kb_table_final_raw.tsv"
bins <- read.table(bins_table, header = T, sep = "\t")
points_color <- "#112233"
points_shape <- "."
raster_dpi <- 300

ggplot(bins, aes(x=log2(H3K27m3_Ni_mean_cov), y=log2(H3K27m3_Pr_mean_cov))) +
    rasterise(geom_point(size = 1, alpha = 0.2, color = points_color, shape = points_shape), dpi = raster_dpi) +
    geom_density2d(binwidth = 0.1) +
    geom_abline(slope = 1, linetype = "dashed") +
    theme_default() +
    labs(x = "Log2 H3K27m3 Naïve - FPGC",
         y = "Log2 H3K27m3 Primed - FPGC", title = "H3K27m3", subtitle = "10kb bins") + 
    coord_cartesian(xlim = c(-8, 8), ylim = c(-8, 8))

H2AUb Naïve vs Primed

ggplot(bins, aes(x=log2(H2Aub_Ni_mean_cov), y=log2(H2Aub_Pr_mean_cov))) +
    rasterise(geom_point(size = 1, alpha = 0.2, color = "#2f1547", shape = points_shape), dpi = raster_dpi) +
    geom_abline(slope = 1, linetype = "dashed") +
    geom_density2d(binwidth = 0.1) +
    theme_default() +
    labs(x = "Log2 H2Aub Naïve - FPGC",
         y = "Log2 H2Aub Primed - FPGC", title = "H2Aub", subtitle = "10kb bins") + 
    coord_cartesian(xlim = c(-8, 8), ylim = c(-8, 8))

H3K4m3 Naïve vs Primed

ggplot(bins, aes(x=log2(H3K4m3_Ni_mean_cov), y=log2(H3K4m3_Pr_mean_cov))) +
    rasterise(geom_point(size = 1, alpha = 0.2, color = "#614925", shape = points_shape), dpi = raster_dpi) +
    geom_abline(slope = 1, linetype = "dashed") +
    geom_density2d(binwidth = 0.1) +
    theme_default() +
    labs(x = "Log2 H3K4m3 Naïve - FPGC",
         y = "Log2 H3K4m3 Primed - FPGC", title = "H3K4m3", subtitle = "10kb bins") + 
    coord_cartesian(xlim = c(-8, 8), ylim = c(-8, 8))

H2Aub EZH2i vs Naïve

genes_file <- "./data/bed/Kumar_2020/Kumar_2020_genes_hg38_UCSC.bed"
court_file <- "./data/bed/Bivalent_Court2017.hg38.bed"
genes_tss <- promoters(import(genes_file), upstream = 2500, downstream = 2500)
court_peaks <- import(court_file)
court_tss <- subsetByOverlaps(genes_tss, court_peaks)
bins_gr <- makeGRangesFromDataFrame(bins, keep.extra.columns = T)
bivalent_bins <- subsetByOverlaps(bins_gr, court_tss)
bivalent_df <- data.frame(bivalent_bins)
signif_df <- bins %>% filter(as.numeric(H2Aub_DS_EZH2i_vs_Ni_padj) < 0.05)

ggplot(bins, aes(x=log2(H2Aub_Ni_mean_cov), y=log2(H2Aub_Ni_EZH2i_mean_cov))) +
    rasterise(geom_point(size = 1, alpha = 0.2, color = "#2f1547", shape = points_shape), dpi = raster_dpi) +
    rasterise(geom_point(data=signif_df, size = 1.2, alpha = 0.8, color = "#d4797f", shape = points_shape), dpi = raster_dpi) +
    rasterise(geom_point(data=bivalent_df, size = 1.2, alpha = 0.8, color = "#4dbfb4", shape = points_shape), dpi = raster_dpi) +
    geom_abline(slope = 1, linetype = "dashed") +
    theme_default() +
    labs(x = "Log2 H2Aub Naïve - FPGC",
         y = "Log2 H2Aub Naïve + EZH2i - FPGC", title = "H2Aub", subtitle = "10kb bins") + 
    coord_cartesian(xlim = c(-8, 8), ylim = c(-8, 8))


sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 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] parallel  stats4    stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] purrr_0.3.4          svglite_2.0.0        rtracklayer_1.52.0  
 [4] GenomicRanges_1.44.0 GenomeInfoDb_1.28.1  IRanges_2.26.0      
 [7] S4Vectors_0.30.0     BiocGenerics_0.38.0  knitr_1.33          
[10] ggrastr_0.2.3        ggpubr_0.4.0         dplyr_1.0.7         
[13] reshape2_1.4.4       ggplot2_3.3.5        wigglescout_0.13.1  
[16] workflowr_1.6.2     

loaded via a namespace (and not attached):
  [1] ggbeeswarm_0.6.0            colorspace_2.0-2           
  [3] ggsignif_0.6.2              rjson_0.2.20               
  [5] ellipsis_0.3.2              rio_0.5.27                 
  [7] rprojroot_2.0.2             XVector_0.32.0             
  [9] fs_1.5.0                    listenv_0.8.0              
 [11] furrr_0.2.3                 farver_2.1.0               
 [13] fansi_0.5.0                 codetools_0.2-18           
 [15] jsonlite_1.7.2              Cairo_1.5-12.2             
 [17] Rsamtools_2.8.0             broom_0.7.8                
 [19] compiler_4.1.1              backports_1.2.1            
 [21] assertthat_0.2.1            Matrix_1.3-4               
 [23] fastmap_1.1.0               later_1.3.0                
 [25] htmltools_0.5.2             tools_4.1.1                
 [27] gtable_0.3.0                glue_1.4.2                 
 [29] GenomeInfoDbData_1.2.6      Rcpp_1.0.7                 
 [31] carData_3.0-4               Biobase_2.52.0             
 [33] cellranger_1.1.0            jquerylib_0.1.4            
 [35] vctrs_0.3.8                 Biostrings_2.60.2          
 [37] xfun_0.24                   stringr_1.4.0              
 [39] globals_0.14.0              openxlsx_4.2.4             
 [41] lifecycle_1.0.0             restfulr_0.0.13            
 [43] rstatix_0.7.0               XML_3.99-0.7               
 [45] future_1.21.0               MASS_7.3-54                
 [47] zlibbioc_1.38.0             scales_1.1.1               
 [49] hms_1.1.0                   promises_1.2.0.1           
 [51] MatrixGenerics_1.4.0        SummarizedExperiment_1.22.0
 [53] RColorBrewer_1.1-2          yaml_2.2.1                 
 [55] curl_4.3.2                  sass_0.4.0                 
 [57] stringi_1.7.4               highr_0.9                  
 [59] BiocIO_1.2.0                zip_2.2.0                  
 [61] BiocParallel_1.26.0         rlang_0.4.11               
 [63] pkgconfig_2.0.3             systemfonts_1.0.2          
 [65] matrixStats_0.60.1          bitops_1.0-7               
 [67] evaluate_0.14               lattice_0.20-44            
 [69] GenomicAlignments_1.28.0    labeling_0.4.2             
 [71] tidyselect_1.1.1            parallelly_1.26.1          
 [73] plyr_1.8.6                  magrittr_2.0.1             
 [75] R6_2.5.1                    generics_0.1.0             
 [77] DelayedArray_0.18.0         DBI_1.1.1                  
 [79] pillar_1.6.2                haven_2.4.1                
 [81] whisker_0.4                 foreign_0.8-81             
 [83] withr_2.4.2                 abind_1.4-5                
 [85] RCurl_1.98-1.4              tibble_3.1.4               
 [87] crayon_1.4.1                car_3.0-11                 
 [89] utf8_1.2.2                  rmarkdown_2.9              
 [91] isoband_0.2.5               grid_4.1.1                 
 [93] readxl_1.3.1                data.table_1.14.0          
 [95] git2r_0.28.0                forcats_0.5.1              
 [97] digest_0.6.27               tidyr_1.1.3                
 [99] httpuv_1.6.2                openssl_1.4.4              
[101] munsell_0.5.0               beeswarm_0.4.0             
[103] vipor_0.4.5                 bslib_0.2.5.1              
[105] askpass_1.1