Last updated: 2025-08-12

Checks: 7 0

Knit directory: DXR_continue/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). 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(20250701) 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 0f14098. 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/DER_data/

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/peak_width.Rmd) and HTML (docs/peak_width.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
html 7eebdc0 infurnoheat 2025-08-01 Build site.
html 5e15e43 infurnoheat 2025-08-01 Build site.
html fee3a00 infurnoheat 2025-07-30 Build site.
Rmd 97db120 infurnoheat 2025-07-30 wflow_publish("analysis/peak_width.Rmd")

Peak Anaylsis

Loading Packages

library(tidyverse)
library(readr)
library(edgeR)
library(ComplexHeatmap)
library(data.table)
library(dplyr)
library(stringr)
library(ggplot2)
library(viridis)
library(DT)
library(kableExtra)
library(genomation)
library(GenomicRanges)
library(chromVAR) ## For FRiP analysis and differential analysis
library(DESeq2) ## For differential analysis section
library(ggpubr) ## For customizing figures
library(corrplot) ## For correlation plot
library(ggpmisc)
library(gcplyr)
library(Rsubread)

Data Initialization

sampleinfo <- read_delim("data/sample_info.tsv", delim = "\t")

Functions

drug_pal <- c("#8B006D","#DF707E","#F1B72B", "#3386DD","#707031","#41B333")
pca_plot <-
  function(df,
           col_var = NULL,
           shape_var = NULL,
           title = "") {
    ggplot(df) + geom_point(aes_string(
      x = "PC1",
      y = "PC2",
      color = col_var,
      shape = shape_var
    ),
    size = 5) +
      labs(title = title, x = "PC 1", y = "PC 2") +
      scale_color_manual(values = c(
        "#8B006D",
        "#DF707E",
        "#F1B72B",
        "#3386DD",
        "#707031",
        "#41B333"
      ))
  }
pca_var_plot <- function(pca) {
  # x: class == prcomp
  pca.var <- pca$sdev ^ 2
  pca.prop <- pca.var / sum(pca.var)
  var.plot <-
    qplot(PC, prop, data = data.frame(PC = 1:length(pca.prop),
                                      prop = pca.prop)) +
    labs(title = 'Variance contributed by each PC',
         x = 'PC', y = 'Proportion of variance')
  plot(var.plot)
}

calc_pca <- function(x) {
  # Performs principal components analysis with prcomp
  # x: a sample-by-gene numeric matrix
  prcomp(x, scale. = TRUE, retx = TRUE)
}

get_regr_pval <- function(mod) {
  # Returns the p-value for the Fstatistic of a linear model
  # mod: class lm
  stopifnot(class(mod) == "lm")
  fstat <- summary(mod)$fstatistic
  pval <- 1 - pf(fstat[1], fstat[2], fstat[3])
  return(pval)
}

plot_versus_pc <- function(df, pc_num, fac) {
  # df: data.frame
  # pc_num: numeric, specific PC for plotting
  # fac: column name of df for plotting against PC
  pc_char <- paste0("PC", pc_num)
  # Calculate F-statistic p-value for linear model
  pval <- get_regr_pval(lm(df[, pc_char] ~ df[, fac]))
  if (is.numeric(df[, f])) {
    ggplot(df, aes_string(x = f, y = pc_char)) + geom_point() +
      geom_smooth(method = "lm") + labs(title = sprintf("p-val: %.2f", pval))
  } else {
    ggplot(df, aes_string(x = f, y = pc_char)) + geom_boxplot() +
      labs(title = sprintf("p-val: %.2f", pval))
  }
}
x_axis_labels = function(labels, every_nth = 1, ...) {
  axis(side = 1,
       at = seq_along(labels),
       labels = F)
  text(
    x = (seq_along(labels))[seq_len(every_nth) == 1],
    y = par("usr")[3] - 0.075 * (par("usr")[4] - par("usr")[3]),
    labels = labels[seq_len(every_nth) == 1],
    xpd = TRUE,
    ...
  )
}

Peak Widths

Peak Width Function

histone_list <- c("H3K27ac", "H3K27me3", "H3K9me3", "H3K36me3")
get_peak_widths_long_split <- function(histone, var) {
  path <- file.path("data/peaks", histone)
  if (var == "all") {
    file_list = list.files(path = path, pattern = "FINAL_merged.bed", full.names = TRUE)
  } else if (histone == "H3K27ac"){
    file_list = list.files(path = path, pattern = "picard_peaks.narrowPeak$", full.names = TRUE)
  } else {
    file_list = list.files(path = path, pattern = paste0(var,"_peaks.(narrowPeak|broadPeak)$", sep=""), full.names = TRUE)
  }
  process_peak <- function(file_path, label) {
    filename <- basename(file_path)
    peak_df <- fread(file_path, header = FALSE) %>%
      transmute(
        row = row_number(),
        width = abs(V3 - V2),
        file = paste0(histone, "-", filename),
        group = label
      )
    return(peak_df)
  }
  peak_list <- list(map(file_list, process_peak, label = var)) %>% flatten()
  bind_rows(peak_list)
}

Broad Visualization

all_peak_widths <- purrr::map_df(histone_list, get_peak_widths_long_split, var = "picard_broad")

anno_peak_width_long <- all_peak_widths %>% 
  mutate(file= gsub("_picard_broad_peaks.broadPeak","",file)) %>%
  separate_wider_delim(., cols=file, delim="-",names=c("histone","sample")) %>% 
  left_join(sampleinfo, by =c("sample"="Library ID"))

anno_peak_width_long %>%
  # distinct(histone)
  ggplot(.,aes(x=histone, y = width, fill = histone))+
  geom_violin()+
  # scale_fill_viridis_a(discrete = TRUE, begin = 0.1, end = 0.55, option = "magma", alpha = 0.8) +
  #   scale_color_viridis_a(discrete = TRUE, begin = 0.1, end = 0.9) +
    scale_y_continuous(trans = "log", breaks = c(400, 3000, 22000)) +
    theme_bw(base_size = 18) +
    ylab("Width of Peaks") +
    xlab("")+
  ggtitle("Width of all peaks with Broad Peaks")

Version Author Date
fee3a00 infurnoheat 2025-07-30

Broad as Narrow Visualization

all_peak_widths <- purrr::map_df(histone_list, get_peak_widths_long_split, var = "picard_narrow")

anno_peak_width_long <- all_peak_widths %>% 
  mutate(file= gsub("_picard_narrow_peaks.narrowPeak","",file)) %>%
  separate_wider_delim(., cols=file, delim="-",names=c("histone","sample")) %>% 
  left_join(sampleinfo, by =c("sample"="Library ID"))

anno_peak_width_long %>%
  # distinct(histone)
  ggplot(.,aes(x=histone, y = width, fill = histone))+
  geom_violin()+
  # scale_fill_viridis_a(discrete = TRUE, begin = 0.1, end = 0.55, option = "magma", alpha = 0.8) +
  #   scale_color_viridis_a(discrete = TRUE, begin = 0.1, end = 0.9) +
    scale_y_continuous(trans = "log", breaks = c(400, 3000, 22000)) +
    theme_bw(base_size = 18) +
    ylab("Width of Peaks") +
    xlab("")+
  ggtitle("Width of all peaks with Broad as Narrow")

Version Author Date
fee3a00 infurnoheat 2025-07-30

Broad as Narrow Stringent Visualization

all_peak_widths <- purrr::map_df(histone_list, get_peak_widths_long_split, var = "1e3_narrow")

anno_peak_width_long <- all_peak_widths %>% 
  mutate(file= gsub("_1e3_narrow_peaks.narrowPeak","",file)) %>%
  separate_wider_delim(., cols=file, delim="-",names=c("histone","sample")) %>% 
  left_join(sampleinfo, by =c("sample"="Library ID"))

anno_peak_width_long %>%
  # distinct(histone)
  ggplot(.,aes(x=histone, y = width, fill = histone))+
  geom_violin()+
  # scale_fill_viridis_a(discrete = TRUE, begin = 0.1, end = 0.55, option = "magma", alpha = 0.8) +
  #   scale_color_viridis_a(discrete = TRUE, begin = 0.1, end = 0.9) +
    scale_y_continuous(trans = "log", breaks = c(400, 3000, 22000)) +
    theme_bw(base_size = 18) +
    ylab("Width of Peaks") +
    xlab("")+
  ggtitle("Width of all peaks with Broad as Stringent Narrow")

Version Author Date
fee3a00 infurnoheat 2025-07-30

Broad as Stringent Narrow without Picard

all_peak_widths <- purrr::map_df(histone_list, get_peak_widths_long_split, var = "FINAL")

anno_peak_width_long <- all_peak_widths %>% 
  mutate(file= gsub("_picard_narrow_peaks.narrowPeak","",file)) %>%
  separate_wider_delim(., cols=file, delim="-",names=c("histone","sample")) %>% 
  left_join(sampleinfo, by =c("sample"="Library ID"))

anno_peak_width_long %>%
  # distinct(histone)
  ggplot(.,aes(x=histone, y = width, fill = histone))+
  geom_violin()+
  # scale_fill_viridis_a(discrete = TRUE, begin = 0.1, end = 0.55, option = "magma", alpha = 0.8) +
  #   scale_color_viridis_a(discrete = TRUE, begin = 0.1, end = 0.9) +
    scale_y_continuous(trans = "log", breaks = c(400, 3000, 22000)) +
    theme_bw(base_size = 18) +
    ylab("Width of Peaks") +
    xlab("")+
  ggtitle("0.001 Narrow Without Picard")

Version Author Date
fee3a00 infurnoheat 2025-07-30
all_peak_widths <- purrr::map_df(histone_list, get_peak_widths_long_split, var = "all")

anno_peak_width_long <- all_peak_widths %>% 
  mutate(file= gsub("_FINAL_merged.bed","",file)) %>%
  separate_wider_delim(., cols=file, delim="-",names=c("histone","sample")) %>% 
  left_join(sampleinfo, by =c("sample"="Library ID"))

anno_peak_width_long %>%
  # distinct(histone)
  ggplot(.,aes(x=histone, y = width, fill = histone))+
  geom_violin()+
  # scale_fill_viridis_a(discrete = TRUE, begin = 0.1, end = 0.55, option = "magma", alpha = 0.8) +
  #   scale_color_viridis_a(discrete = TRUE, begin = 0.1, end = 0.9) +
    scale_y_continuous(trans = "log", breaks = c(400, 3000, 22000)) +
    theme_bw(base_size = 18) +
    ylab("Width of Peaks") +
    xlab("")+
  ggtitle("Merged")

Version Author Date
fee3a00 infurnoheat 2025-07-30

sessionInfo()
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

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

other attached packages:
 [1] Rsubread_2.20.0             gcplyr_1.12.0              
 [3] ggpmisc_0.6.2               ggpp_0.5.9                 
 [5] corrplot_0.95               ggpubr_0.6.1               
 [7] DESeq2_1.46.0               SummarizedExperiment_1.36.0
 [9] Biobase_2.66.0              MatrixGenerics_1.18.1      
[11] matrixStats_1.5.0           chromVAR_1.28.0            
[13] GenomicRanges_1.58.0        GenomeInfoDb_1.42.3        
[15] IRanges_2.40.1              S4Vectors_0.44.0           
[17] BiocGenerics_0.52.0         genomation_1.38.0          
[19] kableExtra_1.4.0            DT_0.33                    
[21] viridis_0.6.5               viridisLite_0.4.2          
[23] data.table_1.17.8           ComplexHeatmap_2.22.0      
[25] edgeR_4.4.2                 limma_3.62.2               
[27] lubridate_1.9.4             forcats_1.0.0              
[29] stringr_1.5.1               dplyr_1.1.4                
[31] purrr_1.1.0                 readr_2.1.5                
[33] tidyr_1.3.1                 tibble_3.3.0               
[35] ggplot2_3.5.2               tidyverse_2.0.0            
[37] workflowr_1.7.1            

loaded via a namespace (and not attached):
  [1] splines_4.4.2               later_1.4.2                
  [3] BiocIO_1.16.0               bitops_1.0-9               
  [5] R.oo_1.27.1                 XML_3.99-0.18              
  [7] DirichletMultinomial_1.48.0 lifecycle_1.0.4            
  [9] rstatix_0.7.2               pwalign_1.2.0              
 [11] doParallel_1.0.17           rprojroot_2.1.0            
 [13] vroom_1.6.5                 MASS_7.3-65                
 [15] processx_3.8.6              lattice_0.22-7             
 [17] backports_1.5.0             magrittr_2.0.3             
 [19] plotly_4.11.0               sass_0.4.10                
 [21] rmarkdown_2.29              jquerylib_0.1.4            
 [23] yaml_2.3.10                 plotrix_3.8-4              
 [25] httpuv_1.6.16               DBI_1.2.3                  
 [27] CNEr_1.42.0                 RColorBrewer_1.1-3         
 [29] abind_1.4-8                 zlibbioc_1.52.0            
 [31] R.utils_2.13.0              RCurl_1.98-1.17            
 [33] git2r_0.36.2                circlize_0.4.16            
 [35] GenomeInfoDbData_1.2.13     seqLogo_1.72.0             
 [37] MatrixModels_0.5-4          annotate_1.84.0            
 [39] svglite_2.2.1               codetools_0.2-20           
 [41] DelayedArray_0.32.0         xml2_1.3.8                 
 [43] tidyselect_1.2.1            shape_1.4.6.1              
 [45] UCSC.utils_1.2.0            farver_2.1.2               
 [47] GenomicAlignments_1.42.0    jsonlite_2.0.0             
 [49] GetoptLong_1.0.5            Formula_1.2-5              
 [51] survival_3.8-3              iterators_1.0.14           
 [53] systemfonts_1.2.3           foreach_1.5.2              
 [55] tools_4.4.2                 TFMPvalue_0.0.9            
 [57] Rcpp_1.1.0                  glue_1.8.0                 
 [59] gridExtra_2.3               SparseArray_1.6.2          
 [61] xfun_0.52                   withr_3.0.2                
 [63] fastmap_1.2.0               SparseM_1.84-2             
 [65] callr_3.7.6                 caTools_1.18.3             
 [67] digest_0.6.37               timechange_0.3.0           
 [69] R6_2.6.1                    mime_0.13                  
 [71] seqPattern_1.38.0           textshaping_1.0.1          
 [73] colorspace_2.1-1            GO.db_3.20.0               
 [75] gtools_3.9.5                poweRlaw_1.0.0             
 [77] dichromat_2.0-0.1           RSQLite_2.4.2              
 [79] R.methodsS3_1.8.2           generics_0.1.4             
 [81] rtracklayer_1.66.0          httr_1.4.7                 
 [83] htmlwidgets_1.6.4           S4Arrays_1.6.0             
 [85] TFBSTools_1.44.0            whisker_0.4.1              
 [87] pkgconfig_2.0.3             gtable_0.3.6               
 [89] blob_1.2.4                  impute_1.80.0              
 [91] XVector_0.46.0              htmltools_0.5.8.1          
 [93] carData_3.0-5               clue_0.3-66                
 [95] scales_1.4.0                png_0.1-8                  
 [97] knitr_1.50                  rstudioapi_0.17.1          
 [99] tzdb_0.5.0                  reshape2_1.4.4             
[101] rjson_0.2.23                curl_6.4.0                 
[103] cachem_1.1.0                GlobalOptions_0.1.2        
[105] KernSmooth_2.23-26          parallel_4.4.2             
[107] miniUI_0.1.2                AnnotationDbi_1.68.0       
[109] restfulr_0.0.16             pillar_1.11.0              
[111] vctrs_0.6.5                 promises_1.3.3             
[113] car_3.1-3                   xtable_1.8-4               
[115] cluster_2.1.8.1             evaluate_1.0.4             
[117] cli_3.6.5                   locfit_1.5-9.12            
[119] compiler_4.4.2              Rsamtools_2.22.0           
[121] rlang_1.1.6                 crayon_1.5.3               
[123] ggsignif_0.6.4              ps_1.9.1                   
[125] getPass_0.2-4               plyr_1.8.9                 
[127] fs_1.6.6                    stringi_1.8.7              
[129] gridBase_0.4-7              BiocParallel_1.40.2        
[131] Biostrings_2.74.1           lazyeval_0.2.2             
[133] quantreg_6.1                Matrix_1.7-3               
[135] BSgenome_1.74.0             hms_1.1.3                  
[137] bit64_4.6.0-1               KEGGREST_1.46.0            
[139] statmod_1.5.0               shiny_1.11.1               
[141] broom_1.0.9                 memoise_2.0.1              
[143] bslib_0.9.0                 bit_4.6.0                  
[145] polynom_1.4-1