From 7df194c754eed9eadf98fb0297bce82ea5a91591 Mon Sep 17 00:00:00 2001 From: stemangiola Date: Thu, 26 Jan 2023 17:24:25 +1100 Subject: [PATCH 1/3] deprecate default method --- R/methods.R | 21 +++++++++++++++---- man/test_differential_abundance-methods.Rd | 15 ++++++------- tests/testthat/test-bulk_methods.R | 1 + .../test-bulk_methods_SummarizedExperiment.R | 7 +++++-- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/R/methods.R b/R/methods.R index 75f8d598..8c4ed046 100755 --- a/R/methods.R +++ b/R/methods.R @@ -2676,7 +2676,7 @@ setMethod("ensembl_to_symbol", "tidybulk", .ensembl_to_symbol) #' #' tidybulk::se_mini |> #' identify_abundant() |> -#' test_differential_abundance( ~ condition ) +#' test_differential_abundance( ~ condition, method = "edgeR_quasi_likelihood" ) #' #' # The function `test_differential_abundance` operates with contrasts too #' @@ -2684,6 +2684,7 @@ setMethod("ensembl_to_symbol", "tidybulk", .ensembl_to_symbol) #' identify_abundant(factor_of_interest = condition) |> #' test_differential_abundance( #' ~ 0 + condition, +#' method = "edgeR_quasi_likelihood", #' contrasts = c( "conditionTRUE - conditionFALSE") #' ) #' @@ -2742,7 +2743,7 @@ setGeneric("test_differential_abundance", function(.data, .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -2765,7 +2766,7 @@ setGeneric("test_differential_abundance", function(.data, .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -2793,11 +2794,23 @@ setGeneric("test_differential_abundance", function(.data, .transcript = col_names$.transcript .abundance = col_names$.abundance + + + + # DEPRECATION OF method = "edgeR_quasi_likelihood" + if (is.null(method)) { + + # Signal the deprecation to the user + warning("In Jannuary 2024 the `method` argument will need to be specified and must NOT be empty. Until then method = NULL will be defaulted to \"edgeR_quasi_likelihood\" as for consistency with old version.") + + method = "edgeR_quasi_likelihood" + } + # DEPRECATION OF significance_threshold if (is_present(significance_threshold) & !is.null(significance_threshold)) { # Signal the deprecation to the user - deprecate_warn("1.1.7", "tidybulk::test_differential_abundance(significance_threshold = )", details = "The argument significance_threshold is now deprecated, tigether with the column significance.") + deprecate_warn("1.1.7", "tidybulk::test_differential_abundance(significance_threshold = )", details = "The argument significance_threshold is now deprecated, together with the column significance.") } diff --git a/man/test_differential_abundance-methods.Rd b/man/test_differential_abundance-methods.Rd index d21594b9..739565be 100755 --- a/man/test_differential_abundance-methods.Rd +++ b/man/test_differential_abundance-methods.Rd @@ -17,7 +17,7 @@ test_differential_abundance( .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -36,7 +36,7 @@ test_differential_abundance( .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -55,7 +55,7 @@ test_differential_abundance( .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -74,7 +74,7 @@ test_differential_abundance( .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -93,7 +93,7 @@ test_differential_abundance( .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -112,7 +112,7 @@ test_differential_abundance( .transcript = NULL, .abundance = NULL, contrasts = NULL, - method = "edgeR_quasi_likelihood", + method = NULL, test_above_log2_fold_change = NULL, scaling_method = "TMM", omit_contrast_in_colnames = FALSE, @@ -250,7 +250,7 @@ dispersion = counts |> edgeR::estimateDisp(design = design) %$% tagwise.dispersi tidybulk::se_mini |> identify_abundant() |> - test_differential_abundance( ~ condition ) + test_differential_abundance( ~ condition, method = "edgeR_quasi_likelihood" ) # The function `test_differential_abundance` operates with contrasts too @@ -258,6 +258,7 @@ dispersion = counts |> edgeR::estimateDisp(design = design) %$% tagwise.dispersi identify_abundant(factor_of_interest = condition) |> test_differential_abundance( ~ 0 + condition, + method = "edgeR_quasi_likelihood", contrasts = c( "conditionTRUE - conditionFALSE") ) diff --git a/tests/testthat/test-bulk_methods.R b/tests/testthat/test-bulk_methods.R index 8ea1506d..8712bf72 100755 --- a/tests/testthat/test-bulk_methods.R +++ b/tests/testthat/test-bulk_methods.R @@ -807,6 +807,7 @@ test_that("DESeq2 differential trancript abundance - no object",{ .sample = a, .transcript = b, .abundance = c, + method = "edgeR_quasi_likelihood", contrasts = "conditionTRUE - conditionFALSE", action="only" ) diff --git a/tests/testthat/test-bulk_methods_SummarizedExperiment.R b/tests/testthat/test-bulk_methods_SummarizedExperiment.R index 5230714e..abdcba92 100755 --- a/tests/testthat/test-bulk_methods_SummarizedExperiment.R +++ b/tests/testthat/test-bulk_methods_SummarizedExperiment.R @@ -284,7 +284,9 @@ test_that("differential trancript abundance - SummarizedExperiment",{ res = test_differential_abundance( se_mini |> identify_abundant(factor_of_interest = condition), - ~ condition + ~ condition, + method = "edgeR_quasi_likelihood" + ) w = match( c("CLEC7A" , "FAM198B", "FCN1" , "HK3" ), rownames(res) ) @@ -293,7 +295,8 @@ test_that("differential trancript abundance - SummarizedExperiment",{ res_tibble = test_differential_abundance( input_df |> identify_abundant(a, b, c, factor_of_interest = condition), ~ condition , - a, b, c + a, b, c, + method = "edgeR_quasi_likelihood" ) expect_equal( From 32b7488fab029445a480a58041b3e48c1917bf61 Mon Sep 17 00:00:00 2001 From: stemangiola Date: Thu, 26 Jan 2023 18:39:57 +1100 Subject: [PATCH 2/3] change pipe --- .../test-bulk_methods_SummarizedExperiment.R | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-bulk_methods_SummarizedExperiment.R b/tests/testthat/test-bulk_methods_SummarizedExperiment.R index abdcba92..05bc5b1b 100755 --- a/tests/testthat/test-bulk_methods_SummarizedExperiment.R +++ b/tests/testthat/test-bulk_methods_SummarizedExperiment.R @@ -3,8 +3,19 @@ context('Bulk methods SummarizedExperiment') data("se_mini") data("breast_tcga_mini_SE") -input_df = se_mini |> tidybulk() |> as_tibble() |> setNames( c( "b","a", "c", "Cell type", "time" , "condition", "days", "dead", "entrez")) -input_df_breast = setNames( breast_tcga_mini_SE |> tidybulk() |> as_tibble(), c( "b", "a","c", "c norm", "call" )) + +input_df = + se_mini |> + tidybulk() |> + as_tibble() |> + setNames( c( "b","a", "c", "Cell type", "time" , "condition", "days", "dead", "entrez")) + +input_df_breast = + breast_tcga_mini_SE |> + tidybulk() |> + as_tibble() |> + setNames( c( "b", "a","c", "c norm", "call" )) + test_that("tidybulk SummarizedExperiment conversion",{ @@ -28,12 +39,28 @@ test_that("tidybulk SummarizedExperiment conversion",{ test_that("tidybulk SummarizedExperiment normalisation manual",{ - res = tidybulk(tidybulk:::tidybulk_to_SummarizedExperiment(scale_abundance(tidybulk(se) |> identify_abundant()))) - res2 = tidybulk(se) |> identify_abundant() |> scale_abundance() + res = se |> + tidybulk() |> + identify_abundant() |> + scale_abundance() |> + tidybulk:::tidybulk_to_SummarizedExperiment() |> + tidybulk() + + res2 = + se |> + tidybulk() |> + identify_abundant() |> + scale_abundance() + + res |> + distinct(.sample, multiplier) |> + pull(multiplier) + + res2 |> + distinct(.sample, multiplier) |> + pull(multiplier) - res |> distinct(.sample, multiplier) |> pull(multiplier) - res2 |> distinct(.sample, multiplier) |> pull(multiplier) expect_equal( @@ -55,6 +82,7 @@ test_that("tidybulk SummarizedExperiment normalisation manual",{ test_that("tidybulk SummarizedExperiment normalisation",{ + res = se |> identify_abundant() |> scale_abundance() expect_equal( @@ -565,6 +593,7 @@ test_that("impute missing",{ tidybulk:::tidybulk_to_SummarizedExperiment(a, b, c) |> impute_missing_abundance( ~ condition ) + list_SE = SummarizedExperiment::assays(res) |> as.list() list_SE[[1]]["TNFRSF4", "SRR1740034"] |> From bb2699b3b37302f0fe221b5f42a894c455759596 Mon Sep 17 00:00:00 2001 From: stemangiola Date: Thu, 26 Jan 2023 21:09:09 +1100 Subject: [PATCH 3/3] update vignettes --- dev/manuscript_differential_transcript_abundance.Rmd | 2 +- vignettes/introduction.Rmd | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dev/manuscript_differential_transcript_abundance.Rmd b/dev/manuscript_differential_transcript_abundance.Rmd index c5038614..48d6e8ed 100644 --- a/dev/manuscript_differential_transcript_abundance.Rmd +++ b/dev/manuscript_differential_transcript_abundance.Rmd @@ -156,7 +156,7 @@ tt_mds_adj_mds %>% ``` ```{r} -tt_test <- tt_adj %>% test_differential_abundance(~ condition + type) +tt_test <- tt_adj %>% test_differential_abundance(~ condition + type, method = "edgeR_quasi_likelihood") # MA plot tt_test %>% diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index 55d6e1fb..68d32b6e 100755 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -439,7 +439,7 @@ TidyTranscriptomics ```{r de, message=FALSE, warning=FALSE, results='hide'} se_mini.de = se_mini |> - test_differential_abundance( ~ condition, action="get") + test_differential_abundance( ~ condition, method = "edgeR_quasi_likelihood", action="get") se_mini.de ``` @@ -468,6 +468,7 @@ se_mini.de = identify_abundant(factor_of_interest = condition) |> test_differential_abundance( ~ 0 + condition, + method = "edgeR_quasi_likelihood", .contrasts = c( "conditionTRUE - conditionFALSE"), action="get" ) @@ -681,6 +682,7 @@ se_mini.norm.SNN |> mutate(factor_of_interest = `cluster_SNN` == 3) |> test_differential_abundance( ~ factor_of_interest, + method = "edgeR_quasi_likelihood", action="get" ) ```