From f3ff3364a8bb19d40be36a297187c37c8be95146 Mon Sep 17 00:00:00 2001 From: Stefano Mangiola Date: Wed, 7 Feb 2024 10:00:19 +1100 Subject: [PATCH] fix tests --- DESCRIPTION | 2 +- R/glmmSeq.R | 10 ++-- R/methods.R | 50 +++++++++---------- tests/testthat/test-bulk_methods.R | 7 +-- .../test-bulk_methods_SummarizedExperiment.R | 5 +- 5 files changed, 38 insertions(+), 36 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/glmmSeq.R b/R/glmmSeq.R index 61145689..9eb0b9db 100644 --- a/R/glmmSeq.R +++ b/R/glmmSeq.R @@ -567,7 +567,7 @@ glmmSeq = function (modelFormula, countdata, metadata, id = NULL, dispersion = N resultList <- lapply(fullList, function(geneList) { glmerCore(geneList, fullFormula, reduced, subsetMetadata, control, offset, modelData, - designMatrix, hyp.matrix,, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) + designMatrix, hyp.matrix, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) }) } else if (Sys.info()["sysname"] == "Windows" & cores > 1) { @@ -618,7 +618,7 @@ glmmSeq = function (modelFormula, countdata, metadata, id = NULL, dispersion = N } else { if(avoid_forking){ - library(parallel) + #library(parallel) cl = parallel::makeCluster(cores, type = "PSOCK") #parallel::clusterEvalQ(cl,c(library(dplyr),library(glmmSeq))) #clusterExport(cl, list("varname1", "varname2"),envir=environment()) @@ -628,7 +628,7 @@ glmmSeq = function (modelFormula, countdata, metadata, id = NULL, dispersion = N function(geneList) { glmerCore(geneList, fullFormula, reduced, subsetMetadata, control, offset, modelData, - designMatrix, hyp.matrix,, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) + designMatrix, hyp.matrix, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) } ) } @@ -645,7 +645,7 @@ glmmSeq = function (modelFormula, countdata, metadata, id = NULL, dispersion = N resultList <- pbmcapply::pbmclapply(fullList, function(geneList) { glmerCore(geneList, fullFormula, reduced, subsetMetadata, control, offset, modelData, - designMatrix, hyp.matrix, , max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) + designMatrix, hyp.matrix, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) }, mc.cores = cores) if ("value" %in% names(resultList)) resultList <- resultList$value @@ -654,7 +654,7 @@ glmmSeq = function (modelFormula, countdata, metadata, id = NULL, dispersion = N resultList <- mclapply(fullList, function(geneList) { glmerCore(geneList, fullFormula, reduced, subsetMetadata, control, offset, modelData, - designMatrix, hyp.matrix,, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) + designMatrix, hyp.matrix, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...) }, mc.cores = cores) } diff --git a/R/methods.R b/R/methods.R index 75f8d598..1dde4008 100755 --- a/R/methods.R +++ b/R/methods.R @@ -8,7 +8,7 @@ setOldClass("tidybulk") #' #' @importFrom rlang enquo #' @importFrom rlang quo_is_missing -#' @importFrom magrittr "%>%" +#' #' @import readr #' @import SummarizedExperiment #' @import methods @@ -302,7 +302,7 @@ setMethod("as_SummarizedExperiment", "tidybulk", .as_SummarizedExperiment) #' @description tidybulk_SAM_BAM() creates a `tt` object from A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name tidybulk_SAM_BAM #' @@ -352,7 +352,7 @@ setMethod("tidybulk_SAM_BAM", c(file_names = "character", genome = "character"), #' @description scale_abundance() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and Scales transcript abundance compansating for sequencing depth (e.g., with TMM algorithm, Robinson and Oshlack doi.org/10.1186/gb-2010-11-3-r25). #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' @importFrom stats median #' #' @name scale_abundance @@ -576,7 +576,7 @@ setMethod("scale_abundance", "tidybulk", .scale_abundance) #' @description quantile_normalise_abundance() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and Scales transcript abundance compansating for sequencing depth (e.g., with TMM algorithm, Robinson and Oshlack doi.org/10.1186/gb-2010-11-3-r25). #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' @importFrom stats median #' @importFrom dplyr join_by #' @@ -781,7 +781,7 @@ setMethod("quantile_normalise_abundance", "tidybulk", .quantile_normalise_abunda #' @description cluster_elements() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and identify clusters in the data. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name cluster_elements #' @@ -998,7 +998,7 @@ setMethod("cluster_elements", "tidybulk", .cluster_elements) #' @description reduce_dimensions() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and calculates the reduced dimensional space of the transcript abundance. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name reduce_dimensions #' @@ -1285,7 +1285,7 @@ setMethod("reduce_dimensions", "tidybulk", .reduce_dimensions) #' @description rotate_dimensions() takes as input a `tbl` formatted as | | | <...> | and calculates the rotated dimensional space of the transcript abundance. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name rotate_dimensions #' @@ -1464,7 +1464,7 @@ setMethod("rotate_dimensions", "tidybulk", .rotate_dimensions) #' @description remove_redundancy() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) for correlation method or | | | <...> | for reduced_dimensions method, and returns a consistent object (to the input) with dropped elements (e.g., samples). #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name remove_redundancy #' @@ -1681,7 +1681,7 @@ setMethod("remove_redundancy", "tidybulk", .remove_redundancy) #' @description adjust_abundance() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with an additional adjusted abundance column. This method uses scaled counts if present. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name adjust_abundance #' @@ -1943,7 +1943,7 @@ setMethod("adjust_abundance", "tidybulk", .adjust_abundance) #' @description aggregate_duplicates() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with aggregated transcripts that were duplicated. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name aggregate_duplicates #' @@ -2093,7 +2093,7 @@ setMethod("aggregate_duplicates", "tidybulk", .aggregate_duplicates) #' @description deconvolve_cellularity() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with the estimated cell type abundance for each sample #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name deconvolve_cellularity #' @@ -2455,7 +2455,7 @@ setMethod("describe_transcript", "tidybulk", .describe_transcript) #' @description ensembl_to_symbol() takes as input a `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with the additional transcript symbol column #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name ensembl_to_symbol #' @@ -2573,7 +2573,7 @@ setMethod("ensembl_to_symbol", "tidybulk", .ensembl_to_symbol) #' @description test_differential_abundance() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with additional columns for the statistics from the hypothesis test. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name test_differential_abundance #' @@ -2993,7 +2993,7 @@ setMethod("test_differential_abundance", #' @description keep_variable() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with additional columns for the statistics from the hypothesis test. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name keep_variable #' @@ -3120,7 +3120,7 @@ setMethod("keep_variable", "tidybulk", .keep_variable) #' @description identify_abundant() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with additional columns for the statistics from the hypothesis test. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' @importFrom dplyr filter #' @importFrom tidyr drop_na #' @@ -3339,7 +3339,7 @@ setMethod("identify_abundant", "tidybulk", .identify_abundant) #' @description keep_abundant() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with additional columns for the statistics from the hypothesis test. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' @importFrom dplyr filter #' #' @name keep_abundant @@ -3472,7 +3472,7 @@ setMethod("keep_abundant", "tidybulk", .keep_abundant) #' @description test_gene_enrichment() takes as input a `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a `tbl` of gene set information #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name test_gene_enrichment #' @@ -3706,7 +3706,7 @@ setMethod("test_gene_enrichment", #' #' @importFrom rlang enquo #' @importFrom rlang quo_is_missing -#' @importFrom magrittr "%>%" +#' #' #' @name test_gene_overrepresentation #' @@ -3865,7 +3865,7 @@ setMethod("test_gene_overrepresentation", #' #' @importFrom rlang enquo #' @importFrom rlang quo_is_missing -#' @importFrom magrittr "%>%" +#' #' #' @name test_gene_rank #' @@ -4074,7 +4074,7 @@ setMethod("test_gene_rank", #' #' @description pivot_sample() takes as input a `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a `tbl` with only sample-related columns #' -#' @importFrom magrittr "%>%" +#' #' #' @name pivot_sample #' @@ -4163,7 +4163,7 @@ setMethod("pivot_sample", #' #' @description pivot_transcript() takes as input a `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a `tbl` with only transcript-related columns #' -#' @importFrom magrittr "%>%" +#' #' #' @name pivot_transcript #' @@ -4254,7 +4254,7 @@ setMethod("pivot_transcript", #' @description fill_missing_abundance() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with new observations #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name fill_missing_abundance #' @@ -4361,7 +4361,7 @@ setMethod("fill_missing_abundance", "tidybulk", .fill_missing_abundance) #' @description impute_missing_abundance() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with additional sample-transcript pairs with imputed transcript abundance. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name impute_missing_abundance #' @@ -4658,7 +4658,7 @@ setMethod("test_differential_cellularity", #' @description test_stratification_cellularity() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with additional columns for the statistics from the hypothesis test. #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' @importFrom stringr str_detect #' #' @name test_stratification_cellularity @@ -4802,7 +4802,7 @@ setMethod("test_stratification_cellularity", #' @description get_bibliography() takes as input a `tidybulk` #' #' @importFrom rlang enquo -#' @importFrom magrittr "%>%" +#' #' #' @name get_bibliography #' diff --git a/tests/testthat/test-bulk_methods.R b/tests/testthat/test-bulk_methods.R index 8ea1506d..5a51e291 100755 --- a/tests/testthat/test-bulk_methods.R +++ b/tests/testthat/test-bulk_methods.R @@ -842,6 +842,7 @@ test_that("differential trancript abundance - random effects",{ filter(b %in% c("ABCB4" , "ABCB9" , "ACAP1", "ACHE", "ACP5" , "ADAM28")) + set.seed(42) my_input |> test_differential_abundance( ~ condition + (1 + condition | time), @@ -855,7 +856,7 @@ test_that("differential trancript abundance - random effects",{ pull(P_condition_adjusted) |> head(4) |> expect_equal( - c(0.03643414, 0.02938584, 0.02938584, 0.03643414), + c(0.02658234, 0.02658234, 0.02658234, 0.04139992), tolerance=1e-3 ) @@ -867,7 +868,7 @@ test_that("differential trancript abundance - random effects",{ by = join_by(b, entrez, .abundant) ) - + set.seed(42) my_input |> test_differential_abundance( ~ condition + (1 + condition | time), @@ -882,7 +883,7 @@ test_that("differential trancript abundance - random effects",{ pull(P_condition_adjusted) |> head(4) |> expect_equal( - c(0.1081176, 0.1303558, 0.1303558, 0.1693276), + c(0.08686834, 0.14384610, 0.14384610, 0.19750844), tolerance=1e-2 ) diff --git a/tests/testthat/test-bulk_methods_SummarizedExperiment.R b/tests/testthat/test-bulk_methods_SummarizedExperiment.R index 5230714e..f6d1c140 100755 --- a/tests/testthat/test-bulk_methods_SummarizedExperiment.R +++ b/tests/testthat/test-bulk_methods_SummarizedExperiment.R @@ -480,6 +480,7 @@ test_that("Voom with treat method",{ test_that("differential trancript abundance - random effects SE",{ + set.seed(42) res = se_mini[1:10,] |> identify_abundant(factor_of_interest = condition) |> @@ -493,7 +494,7 @@ test_that("differential trancript abundance - random effects SE",{ rowData(res)[,"P_condition_adjusted"] |> head(4) |> expect_equal( - c(0.03394914, 0.03394914, 0.03394914, NA), + c(0.1578695, 0.1221392, 0.1221392, 0.2262688), tolerance=1e-2 ) @@ -517,7 +518,7 @@ test_that("differential trancript abundance - random effects SE",{ rowData(res)[,"P_condition_adjusted"] |> head(4) |> expect_equal( - c(0.1153254, 0.1668555, 0.1668555 , NA), + c(0.2633982, 0.2633982, 0.2633982, 0.5028348), tolerance=1e-2 )