From 36cd0b0475b2cc361de48fe5a0e689f766ebef76 Mon Sep 17 00:00:00 2001 From: Stevie Ped Date: Tue, 23 Jul 2024 02:14:28 +0930 Subject: [PATCH] Tests after bugfix --- DESCRIPTION | 6 ++--- R/fitAssayDiff.R | 32 ++++++++++++----------- man/fitAssayDiff-methods.Rd | 12 +++++---- vignettes/differential_signal_sliding.Rmd | 3 +-- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bd5b551..0981252 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: extraChIPs -Version: 1.8.2 +Version: 1.8.3 Title: Additional functions for working with ChIP-Seq data Authors@R: person("Stevie", "Pederson", email = "stephen.pederson.au@gmail.com", @@ -59,9 +59,9 @@ Imports: vctrs, VennDiagram Suggests: + apeglm, BiocStyle, covr, - cqn, DESeq2, EnrichedHeatmap, Gviz, @@ -79,5 +79,5 @@ biocViews: ChIPSeq, HiC, Sequencing, Coverage BiocType: Software VignetteBuilder: knitr Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Config/testthat/edition: 3 diff --git a/R/fitAssayDiff.R b/R/fitAssayDiff.R index 95b0c92..cb5cfa2 100644 --- a/R/fitAssayDiff.R +++ b/R/fitAssayDiff.R @@ -19,13 +19,15 @@ #' No normalisation is applied when using the limma-trend model, as this allows #' for previous normalisation strategies to be performed on the data. #' -#' When applying the \link[DESeq2]{nbinomWaldTest}, without groups and using -#' colSums for library sizes (instead of total alignments), the standard -#' normalisation factors from \link[DESeq2]{estimateSizeFactorsForMatrix} will -#' be used. In all other scenarios, normalisation factors as returned by +#' When applying the \link[DESeq2]{nbinomWaldTest}, applying RLE normalisation +#' without groups, and using colSums for library sizes (instead of total +#' alignments), the standard normalisation factors from +#' \link[DESeq2]{estimateSizeFactors} will be used. +#' In all other scenarios, normalisation factors as returned by #' \link[edgeR]{normLibSizes} will be used. #' The fitType is set to 'local' when estimating dispersions, and this can be #' easily modified by passing fitType via the dot arguments. +#' Results are additionally returned after applying \link[DESeq2]{lfcShrink}. #' #' Normalising to ChIP Input samples is not yet implemented. #' Similarly, the use of offsets when applying the Wald test is not yet @@ -125,7 +127,8 @@ setMethod( norm = c("none", "TMM", "RLE", "TMMwsp", "upperquartile"), groups = NULL, fc = 1, lfc = log2(fc), asRanges = FALSE, offset = NULL, weighted = FALSE, ..., - null = c("interval", "worst.case"), robust = FALSE, type = "apeglm" + null = c("interval", "worst.case"), robust = FALSE, + type = c("apeglm", "ashr", "normal") ) { method <- match.arg(method) norm <- match.arg(norm) @@ -186,20 +189,19 @@ setMethod( if (method == "wald") { if (!requireNamespace('DESeq2', quietly = TRUE)) stop("Please install 'DESeq2' to use this function.") + type <- match.arg(type) dds <- .se2Wald( x, assay, design, lib.size, norm, groups, offset, weighted, ... ) res <- DESeq2::results(dds) p_mu0 <- res$pvalue pval <- p_mu0 - ## Apply lfcShrink as default - if (lfc != 0) { - res <- DESeq2::lfcShrink( - dds, coef = colnames(design)[ncol(design)], res = res, - type = type, lfcThreshold = abs(lfc), svalue = TRUE - ) - pval <- res$svalue - } + ## Apply lfcShrink as the default + res <- DESeq2::lfcShrink( + dds, coef = coef, res = res, type = type, + lfcThreshold = abs(lfc), svalue = TRUE + ) + if (abs(lfc) > 0) pval <- res$svalue ## Reformat for standard edgeR column layout res <- data.frame( logFC = res$log2FoldChange, logCPM = log2(res$baseMean), @@ -327,7 +329,7 @@ setMethod( nf <- rep_len(NA, ncol(mat)) # Should error out if something fails below if (is.null(lib.size) & norm == "RLE" & is.null(groups)) { message("Calculating default DESeq2 normalisation factors...") - nf <- DESeq2::estimateSizeFactorsForMatrix(mat) + dds <- DESeq2::estimateSizeFactors(dds) } else { if (is.null(groups)) { message("Calculating ", norm, " normalisation factors...") @@ -346,8 +348,8 @@ setMethod( ) } } + DESeq2::sizeFactors(dds) <- nf } - DESeq2::sizeFactors(dds) <- nf ## 3. Estimate dispersions ft <- "local" diff --git a/man/fitAssayDiff-methods.Rd b/man/fitAssayDiff-methods.Rd index 3bfcf7d..c418057 100644 --- a/man/fitAssayDiff-methods.Rd +++ b/man/fitAssayDiff-methods.Rd @@ -24,7 +24,7 @@ fitAssayDiff(x, ...) ..., null = c("interval", "worst.case"), robust = FALSE, - type = "apeglm" + type = c("apeglm", "ashr", "normal") ) } \arguments{ @@ -112,13 +112,15 @@ called by column name. No normalisation is applied when using the limma-trend model, as this allows for previous normalisation strategies to be performed on the data. -When applying the \link[DESeq2]{nbinomWaldTest}, without groups and using -colSums for library sizes (instead of total alignments), the standard -normalisation factors from \link[DESeq2]{estimateSizeFactorsForMatrix} will -be used. In all other scenarios, normalisation factors as returned by +When applying the \link[DESeq2]{nbinomWaldTest}, applying RLE normalisation +without groups, and using colSums for library sizes (instead of total +alignments), the standard normalisation factors from +\link[DESeq2]{estimateSizeFactors} will be used. +In all other scenarios, normalisation factors as returned by \link[edgeR]{normLibSizes} will be used. The fitType is set to 'local' when estimating dispersions, and this can be easily modified by passing fitType via the dot arguments. +Results are additionally returned after applying \link[DESeq2]{lfcShrink}. Normalising to ChIP Input samples is not yet implemented. Similarly, the use of offsets when applying the Wald test is not yet diff --git a/vignettes/differential_signal_sliding.Rmd b/vignettes/differential_signal_sliding.Rmd index 84ae240..a079e4a 100644 --- a/vignettes/differential_signal_sliding.Rmd +++ b/vignettes/differential_signal_sliding.Rmd @@ -65,7 +65,7 @@ if (!"BiocManager" %in% rownames(installed.packages())) pkg <- c( "tidyverse", "Rsamtools", "csaw", "BiocParallel", "rtracklayer", "edgeR", "patchwork", "extraChIPs", "plyranges", "scales", "glue", "here", "quantro", - "cqn", "ggrepel", "BSgenome.Hsapiens.UCSC.hg19" + "ggrepel", "BSgenome.Hsapiens.UCSC.hg19" ) BiocManager::install(pkg, update = FALSE) ``` @@ -87,7 +87,6 @@ library(glue) library(here) library(magrittr) library(quantro) -library(cqn) library(ggrepel) theme_set(theme_bw()) ```