Last updated: 2025-08-27

Checks: 7 0

Knit directory: DTU-code/analysis/

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(20240501) 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 5951235. 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:    .gitignore
    Ignored:    .renvignore
    Ignored:    DTU-code.Rproj
    Ignored:    code/.RData
    Ignored:    code/mouse/data/slurm-16691239.out
    Ignored:    code/mouse/salmon-index/slurm-16693056.out
    Ignored:    code/mouse/salmon/slurm-16693640.out
    Ignored:    code/mouse/subread-index/.RData
    Ignored:    code/mouse/subread-index/buildindex.Rout
    Ignored:    code/mouse/subread-index/slurm-19350188.out
    Ignored:    code/mouse/subread/.nextflow.log
    Ignored:    code/mouse/subread/.nextflow/
    Ignored:    code/mouse/subread/log/
    Ignored:    code/mouse/subread/report.html
    Ignored:    code/mouse/subread/slurm-19356012.out
    Ignored:    code/mouse/subread/timeline.html
    Ignored:    code/mouse/subread/trace-20241127-50139746.txt
    Ignored:    code/pkg/.Rbuildignore
    Ignored:    code/pkg/.Rhistory
    Ignored:    code/pkg/.Rproj.user/
    Ignored:    code/pkg/src/.gitignore
    Ignored:    code/pkg/src/RcppExports.o
    Ignored:    code/pkg/src/pkg.so
    Ignored:    code/pkg/src/rcpparma_hello_world.o
    Ignored:    code/simulation-no-trend/
    Ignored:    data/annotation/mm39/GRCm39.genome.fa.gz
    Ignored:    data/annotation/mm39/gencode.vM35.annotation.gtf.gz
    Ignored:    data/annotation/mm39/gencode.vM35.metadata.EntrezGene.gz
    Ignored:    data/annotation/mm39/gencode.vM35.transcripts.fa.gz
    Ignored:    data/mouse/fastq/
    Ignored:    ignore/
    Ignored:    output/mouse/
    Ignored:    output/simulation-lenient/
    Ignored:    output/simulation-no-trend/
    Ignored:    renv/

Untracked files:
    Untracked:  code/simulation-lenient-no-trend/
    Untracked:  misc/main-casestudy.Rmd/
    Untracked:  misc/main-simulation.Rmd/
    Untracked:  misc/supp-bcv.Rmd/
    Untracked:  misc/supp-simulation-dividedcounts.Rmd/
    Untracked:  misc/supp-simulation-lenient.Rmd/
    Untracked:  misc/supp-simulation-rawcounts.Rmd/
    Untracked:  output/old-simulation-lenient/
    Untracked:  output/old-simulation/
    Untracked:  output/simulation-lenient-no-trend/
    Untracked:  output/simulation/

Unstaged changes:
    Deleted:    analysis/about.Rmd
    Deleted:    analysis/mouse.Rmd
    Deleted:    analysis/simulation-lenient-supp.Rmd
    Deleted:    analysis/simulation-paper.Rmd
    Deleted:    analysis/simulation-supp.Rmd
    Modified:   code/pkg/R/simulation-summary.R
    Modified:   code/pkg/R/simulation.R
    Deleted:    code/readme.txt
    Deleted:    code/simulation-lenient/main.R
    Deleted:    code/simulation-lenient/parameters.R
    Deleted:    code/simulation-lenient/parameters.txt
    Deleted:    code/simulation-lenient/readme.txt
    Deleted:    code/simulation-lenient/run.sh
    Deleted:    code/simulation-lenient/summarize.R
    Deleted:    code/simulation/main.R
    Deleted:    code/simulation/parameters.R
    Deleted:    code/simulation/parameters.txt
    Deleted:    code/simulation/readme.txt
    Deleted:    code/simulation/run.sh
    Deleted:    code/simulation/summarize.R
    Deleted:    misc/mouse.Rmd/Figure-CaseStudy.pdf
    Deleted:    misc/simulation-lenient-supp.Rmd/SuppTable-Filtering-Gene.tex
    Deleted:    misc/simulation-lenient-supp.Rmd/SuppTable-Filtering-Transcript.tex
    Deleted:    misc/simulation-paper.Rmd/Figure-FDR.pdf
    Deleted:    misc/simulation-paper.Rmd/Figure-Power.pdf
    Deleted:    misc/simulation-paper.Rmd/Figure-Pval.pdf
    Deleted:    misc/simulation-paper.Rmd/Figure-Time.pdf
    Deleted:    misc/simulation-supp.Rmd/SuppFigure-ErrorRate.pdf
    Deleted:    misc/simulation-supp.Rmd/SuppFigure-FDR.pdf
    Deleted:    misc/simulation-supp.Rmd/SuppFigure-FP-SecondaryTranscripts-Unbalanced.pdf
    Deleted:    misc/simulation-supp.Rmd/SuppFigure-Power.pdf
    Deleted:    misc/simulation-supp.Rmd/SuppFigure-Pval-Gene-Unbalanced.pdf
    Deleted:    misc/simulation-supp.Rmd/SuppFigure-Pval-Transcript-Unbalanced.pdf
    Deleted:    misc/simulation-supp.Rmd/SuppFigure-ROC.pdf

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/supp-bcv.Rmd) and HTML (docs/supp-bcv.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 5951235 Pedro Baldoni 2025-08-27 DTU paper revision

Introduction

Setup

knitr::opts_chunk$set(dev = "png",
                      dpi = 300,
                      dev.args = list(type = "cairo-png"),
                      root.dir = '.',
                      autodep = TRUE)

options(knitr.kable.NA = "-")
library(edgeR)
library(data.table)
library(patchwork)
library(ggplot2)
path.misc <- file.path('../misc/supp-bcv.Rmd')
dir.create(path.misc,recursive = TRUE,showWarnings = FALSE)
bs <- 8
foo.bcv <- function (y,
                     xlab = "Average log CPM",
                     ylab = "Biological coefficient of variation",
                     pch = 16, cex = 0.2,
                     col.common = "red",
                     col.trend = "blue",
                     col.tagwise = "black",
                     fontsize = 8, ...) {
  if (!is(y, "DGEList"))
    stop("y must be a DGEList.")
  A <- y$AveLogCPM
  if (is.null(A))
    A <- aveLogCPM(y$counts, offset = getOffset(y))
  disp <- getDispersion(y)
  if (is.null(disp))
    stop("No dispersions to plot")
  if (attr(disp, "type") == "common")
    disp <- rep_len(disp, length(A))
  par(mar = c(3, 3, 0.5, 0.25),mgp = c(1.25,0.5,0))
  plot(A, sqrt(disp), xlab = xlab, ylab = ylab, type = "n",
       cex.lab = fontsize/12,
       cex.axis = fontsize/12,
       cex.main = fontsize/12,
       ...)
  labels <- cols <- lty <- pt <- NULL
  if (!is.null(y$tagwise.dispersion)) {
    points(A, sqrt(y$tagwise.dispersion), pch = pch, cex = cex,
           col = col.tagwise)
    labels <- c(labels, "Tagwise")
    cols <- c(cols, col.tagwise)
    lty <- c(lty, -1)
    pt <- c(pt, pch)
  }
  if (!is.null(y$common.dispersion)) {
    abline(h = sqrt(y$common.dispersion), col = col.common,
           lwd = 2)
    labels <- c(labels, "Common")
    cols <- c(cols, col.common)
    lty <- c(lty, 1)
    pt <- c(pt, -1)
  }
  if (!is.null(y$trended.dispersion)) {
    o <- order(A)
    lines(A[o], sqrt(y$trended.dispersion)[o], col = col.trend,
          lwd = 2)
    labels <- c(labels, "Trend")
    cols <- c(cols, col.trend)
    lty <- c(lty, 1)
    pt <- c(pt, -1)
  }
  legend("topright", legend = labels, lty = lty, pch = pt,
         pt.cex = cex, lwd = 2, col = cols,cex = fontsize/12)
}

plot.voom <- function(fit,fontsize = 8,...){
  par(mar = c(3, 3, 0.5, 0.25),mgp = c(1.25,0.5,0))
  plot(x = fit$voom.xy$x,
       y = fit$voom.xy$y,
       xlab = fit$voom.xy$xlab,
       ylab = fit$voom.xy$ylab,
       pch = fit$voom.xy$pch,
       cex = fit$voom.xy$cex,
       cex.lab = fontsize/12,
       cex.axis = fontsize/12,
       cex.main = fontsize/12,...)
  lines(fit$voom.line,col="red",lty=1)
}

Data loading

cs.5 <- catchSalmon(list.dirs('../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon',recursive = FALSE))
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupA_rep1_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupA_rep2_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupA_rep3_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupA_rep4_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupA_rep5_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupB_rep1_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupB_rep2_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupB_rep3_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupB_rep4_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/5libsPerGroup/simulation-1/quant-salmon/groupB_rep5_R1, 147556 transcripts, 100 gibbs samples
cs.3 <- catchSalmon(list.dirs('../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/3libsPerGroup/simulation-1/quant-salmon',recursive = FALSE))
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/3libsPerGroup/simulation-1/quant-salmon/groupA_rep1_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/3libsPerGroup/simulation-1/quant-salmon/groupA_rep2_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/3libsPerGroup/simulation-1/quant-salmon/groupA_rep3_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/3libsPerGroup/simulation-1/quant-salmon/groupB_rep1_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/3libsPerGroup/simulation-1/quant-salmon/groupB_rep2_R1, 147556 transcripts, 100 gibbs samples
Reading ../output/simulation-no-trend/data/mm39/readlen-100/fc2/paired-end/unbalanced/3libsPerGroup/simulation-1/quant-salmon/groupB_rep3_R1, 147556 transcripts, 100 gibbs samples
cs.real <- catchSalmon(list.dirs('../output/mouse/salmon',recursive = FALSE)[1:6])
Reading ../output/mouse/salmon/GSM7106766, 147556 transcripts, 100 gibbs samples
Reading ../output/mouse/salmon/GSM7106767, 147556 transcripts, 100 gibbs samples
Reading ../output/mouse/salmon/GSM7106768, 147556 transcripts, 100 gibbs samples
Reading ../output/mouse/salmon/GSM7106769, 147556 transcripts, 100 gibbs samples
Reading ../output/mouse/salmon/GSM7106770, 147556 transcripts, 100 gibbs samples
Reading ../output/mouse/salmon/GSM7106771, 147556 transcripts, 100 gibbs samples
min.count <- 10
min.total.count <- 15
span = 0.40

BCV plots

dge.3 <- DGEList(counts = cs.3$counts/cs.3$annotation$Overdispersion,group = gl(2,3),genes = cs.3$annotation)
rownames(dge.3) <- limma::strsplit2(rownames(dge.3),"\\|")[,1]
colnames(dge.3) <- basename(colnames(dge.3))

dge.3.raw <- DGEList(counts = cs.3$counts,group = gl(2,3))
rownames(dge.3.raw) <- limma::strsplit2(rownames(dge.3.raw),"\\|")[,1]
colnames(dge.3.raw) <- basename(colnames(dge.3.raw))

design.3 <- model.matrix(~0+group,dge.3$samples)

keep.3 <- filterByExpr(dge.3,min.count = min.count, min.total.count = min.total.count)
dge.3.filtr <- dge.3[keep.3,,keep.lib.sizes = FALSE]
dge.3.filtr <- normLibSizes(dge.3.filtr)
dge.3.filtr <- estimateDisp(dge.3.filtr,design = design.3,span = span)

keep.3.raw <- filterByExpr(dge.3.raw,min.count = min.count, min.total.count = min.total.count)
dge.3.raw.filtr <- dge.3.raw[keep.3.raw,,keep.lib.sizes = FALSE]
dge.3.raw.filtr <- normLibSizes(dge.3.raw.filtr)
dge.3.raw.filtr <- estimateDisp(dge.3.raw.filtr,design = design.3,span = span)

bcv.scaled.sim.3 <- wrap_elements(full = ~foo.bcv(dge.3.filtr))
bcv.raw.sim.3 <- wrap_elements(full = ~foo.bcv(dge.3.raw.filtr))
dge.5 <- DGEList(counts = cs.5$counts/cs.5$annotation$Overdispersion,group = gl(2,5),genes = cs.5$annotation)
rownames(dge.5) <- limma::strsplit2(rownames(dge.5),"\\|")[,1]
colnames(dge.5) <- basename(colnames(dge.5))

dge.5.raw <- DGEList(counts = cs.5$counts,group = gl(2,5))
rownames(dge.5.raw) <- limma::strsplit2(rownames(dge.5.raw),"\\|")[,1]
colnames(dge.5.raw) <- basename(colnames(dge.5.raw))

design.5 <- model.matrix(~0+group,dge.5$samples)

keep.5 <- filterByExpr(dge.5,min.count = min.count, min.total.count = min.total.count)
dge.5.filtr <- dge.5[keep.5,,keep.lib.sizes = FALSE]
dge.5.filtr <- normLibSizes(dge.5.filtr)
dge.5.filtr <- estimateDisp(dge.5.filtr,design = design.5,span = span)

keep.5.raw <- filterByExpr(dge.5.raw,min.count = min.count, min.total.count = min.total.count)
dge.5.raw.filtr <- dge.5.raw[keep.5.raw,,keep.lib.sizes = FALSE]
dge.5.raw.filtr <- normLibSizes(dge.5.raw.filtr)
dge.5.raw.filtr <- estimateDisp(dge.5.raw.filtr,design = design.5,span = span)

bcv.scaled.sim.5 <- wrap_elements(full = ~foo.bcv(dge.5.filtr))
bcv.raw.sim.5 <- wrap_elements(full = ~foo.bcv(dge.5.raw.filtr))
dge.real <- DGEList(counts = cs.real$counts/cs.real$annotation$Overdispersion,group = gl(2,3),genes = cs.real$annotation)
rownames(dge.real) <- limma::strsplit2(rownames(dge.real),"\\|")[,1]

design.real <- model.matrix(~0+group,dge.real$samples)

keep.real <- filterByExpr(dge.real,min.count = min.count, min.total.count = min.total.count)
dge.real.filtr <- dge.real[keep.real,,keep.lib.sizes = FALSE]
dge.real.filtr <- normLibSizes(dge.real.filtr)
dge.real.filtr <- estimateDisp(dge.real.filtr,design = design.real,span = span)

dge.real.raw <- DGEList(counts = cs.real$counts,group = gl(2,3))
keep.real.raw <- filterByExpr(dge.real.raw,min.count = min.count, min.total.count = min.total.count)
dge.real.raw.filtr <- dge.real.raw[keep.real.raw,,keep.lib.sizes = FALSE]
dge.real.raw.filtr <- normLibSizes(dge.real.raw.filtr)
dge.real.raw.filtr <- estimateDisp(dge.real.raw.filtr,design = design.real,span = span)

bcv.scaled.real <- wrap_elements(full = ~foo.bcv(dge.real.filtr,fontsize = bs))
bcv.raw.real <- wrap_elements(full = ~foo.bcv(dge.real.raw.filtr,fontsize = bs))
fig.edgeR <- wrap_plots(A = bcv.raw.real,
                        B = bcv.scaled.real,
                        C = bcv.raw.sim.3,
                        D = bcv.scaled.sim.3,
                        E = bcv.raw.sim.5,
                        `F` = bcv.scaled.sim.5,
                        design = c(area(1,1),area(1,2),
                                   area(2,1),area(2,2),
                                   area(3,1),area(3,2))) +
  plot_annotation(tag_levels = 'a')  &
  theme(plot.tag = element_text(size = bs))

fig.edgeR

Output files

ggsave(plot = fig.edgeR,
       filename = file.path(path.misc,'SuppFigure-BCVPlots.png'),
       device = 'png',width = 6,height = 9,units = 'in',dpi = 300)

sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Red Hat Enterprise Linux 9.3 (Plow)

Matrix products: default
BLAS:   /stornext/System/data/software/rhel/9/base/tools/R/4.4.1/lib64/R/lib/libRblas.so 
LAPACK: /stornext/System/data/software/rhel/9/base/tools/R/4.4.1/lib64/R/lib/libRlapack.so;  LAPACK version 3.12.0

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

time zone: Australia/Melbourne
tzcode source: system (glibc)

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

other attached packages:
[1] ggplot2_3.5.1     patchwork_1.3.0   data.table_1.17.0 edgeR_4.5.9      
[5] limma_3.63.9      workflowr_1.7.1  

loaded via a namespace (and not attached):
 [1] gtable_0.3.6        xfun_0.51           bslib_0.9.0        
 [4] processx_3.8.6      lattice_0.22-6      callr_3.7.6        
 [7] tzdb_0.4.0          vctrs_0.6.5         tools_4.4.1        
[10] ps_1.9.0            generics_0.1.3      parallel_4.4.1     
[13] tibble_3.2.1        pkgconfig_2.0.3     lifecycle_1.0.4    
[16] compiler_4.4.1      farver_2.1.2        stringr_1.5.1      
[19] git2r_0.35.0        textshaping_1.0.0   statmod_1.5.0      
[22] munsell_0.5.1       getPass_0.2-4       httpuv_1.6.15      
[25] htmltools_0.5.8.1   sass_0.4.9          yaml_2.3.10        
[28] later_1.4.1         pillar_1.10.1       crayon_1.5.3       
[31] jquerylib_0.1.4     whisker_0.4.1       cachem_1.1.0       
[34] tidyselect_1.2.1    locfit_1.5-9.12     digest_0.6.37      
[37] stringi_1.8.4       dplyr_1.1.4         splines_4.4.1      
[40] rprojroot_2.0.4     fastmap_1.2.0       grid_4.4.1         
[43] colorspace_2.1-1    cli_3.6.4           magrittr_2.0.3     
[46] readr_2.1.5         withr_3.0.2         scales_1.3.0       
[49] promises_1.3.2      bit64_4.6.0-1       rmarkdown_2.29     
[52] httr_1.4.7          bit_4.6.0           ragg_1.3.3         
[55] hms_1.1.3           evaluate_1.0.3      knitr_1.49         
[58] gridGraphics_0.5-1  rlang_1.1.5         Rcpp_1.0.14        
[61] glue_1.8.0          BiocManager_1.30.25 renv_1.1.2         
[64] rstudioapi_0.17.1   vroom_1.6.5         jsonlite_1.9.1     
[67] R6_2.6.1            systemfonts_1.2.1   fs_1.6.5