From fc8225154bca966a63e0066963cd091fe85911e9 Mon Sep 17 00:00:00 2001 From: Stefano Mangiola Date: Wed, 7 Feb 2024 12:17:56 +1100 Subject: [PATCH] add column renaming --- DESCRIPTION | 2 +- R/functions.R | 6 +++++ R/functions_SE.R | 6 +++++ .../test-bulk_methods_SummarizedExperiment.R | 23 +++++++++++-------- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index eb5346e6..34a0aa9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -95,7 +95,7 @@ Biarch: true biocViews: AssayDomain, Infrastructure, RNASeq, DifferentialExpression, GeneExpression, Normalization, Clustering, QualityControl, Sequencing, Transcription, Transcriptomics Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 LazyDataCompression: xz URL: https://github.com/stemangiola/tidybulk BugReports: https://github.com/stemangiola/tidybulk/issues diff --git a/R/functions.R b/R/functions.R index ed5d0087..ded23a79 100755 --- a/R/functions.R +++ b/R/functions.R @@ -465,6 +465,12 @@ get_differential_transcript_abundance_bulk <- function(.data, data = df_for_edgeR %>% select(!!.sample, one_of(parse_formula(.formula))) %>% distinct %>% arrange(!!.sample) ) + # Replace `:` with ___ because it creates error with edgeR + if(design |> colnames() |> str_detect(":") |> any()) { + message("tidybulk says: the interaction term `:` has been replaced with `___` in the design matrix, in order to work with edgeR.") + colnames(design) = design |> colnames() |> str_replace(":", "___") + } + # Print the design column names in case I want contrasts message( sprintf( diff --git a/R/functions_SE.R b/R/functions_SE.R index 557cb5e4..262d1468 100755 --- a/R/functions_SE.R +++ b/R/functions_SE.R @@ -741,6 +741,12 @@ get_differential_transcript_abundance_bulk_SE <- function(.data, data = sample_annotation ) + # Replace `:` with ___ because it creates error with edgeR + if(design |> colnames() |> str_detect(":") |> any()) { + message("tidybulk says: the interaction term `:` has been replaced with `___` in the design matrix, in order to work with edgeR.") + colnames(design) = design |> colnames() |> str_replace(":", "___") + } + # Print the design column names in case I want contrasts message( sprintf( diff --git a/tests/testthat/test-bulk_methods_SummarizedExperiment.R b/tests/testthat/test-bulk_methods_SummarizedExperiment.R index 5230714e..3cfbf273 100755 --- a/tests/testthat/test-bulk_methods_SummarizedExperiment.R +++ b/tests/testthat/test-bulk_methods_SummarizedExperiment.R @@ -64,7 +64,6 @@ test_that("tidybulk SummarizedExperiment normalisation",{ }) - test_that("quantile normalisation",{ res = se_mini |> quantile_normalise_abundance() @@ -109,7 +108,6 @@ test_that("quantile normalisation",{ }) - test_that("tidybulk SummarizedExperiment normalisation subset",{ res = se |> identify_abundant() |> scale_abundance( @@ -124,10 +122,6 @@ test_that("tidybulk SummarizedExperiment normalisation subset",{ }) - - - - test_that("tidybulk SummarizedExperiment clustering",{ res = cluster_elements(se, method="kmeans", centers = 2) @@ -357,7 +351,6 @@ test_that("differential trancript abundance - SummarizedExperiment",{ }) - test_that("differential trancript abundance - SummarizedExperiment - alternative .abundance",{ assays(se_mini) = list(counts = assay(se_mini), bla = assay(se_mini)) @@ -437,6 +430,20 @@ test_that("differential trancript abundance - SummarizedExperiment - alternative }) +test_that("DE interaction effects", { + + # Att interaction factor + col_data = colData(breast_tcga_mini_SE) + set.seed(42) + col_data$interaction_term = sample(c(0,1), size = nrow(col_data), replace = TRUE) + colData(breast_tcga_mini_SE) = col_data + + res = + breast_tcga_mini_SE |> + identify_abundant(factor_of_interest = Call) |> + test_differential_abundance( ~ Call * interaction_term, contrasts = "CallHer2" ) + +}) test_that("Voom with treat method",{ @@ -523,8 +530,6 @@ test_that("differential trancript abundance - random effects SE",{ }) - - test_that("filter abundant - SummarizedExperiment",{ res = keep_abundant( se )