diff --git a/R/registration_wrapper.R b/R/registration_wrapper.R index b134c72b..910b929d 100644 --- a/R/registration_wrapper.R +++ b/R/registration_wrapper.R @@ -47,13 +47,19 @@ #' ## Compute all modeling results #' example_modeling_results <- registration_wrapper( #' sce, -#' var_regustration ="Cell_Cycle", -#' var_sample_id ="sample_id", +#' var_registration = "Cell_Cycle", +#' var_sample_id = "sample_id", #' covars = c("age"), -#' gene_ensembl = "ensembl", -#' gene_name = "gene_name", +#' gene_ensembl = "ensembl", +#' gene_name = "gene_name", #' suffix = "wrapper" #' ) +#' +#' ## Explore the results from registration_wrapper() +#' class(example_modeling_results) +#' length(example_modeling_results) +#' names(example_modeling_results) +#' lapply(example_modeling_results, head) registration_wrapper <- function(sce, var_registration, @@ -69,7 +75,8 @@ registration_wrapper <- ## Pseudobulk sce_pseudo <- - registration_pseudobulk(sce, + registration_pseudobulk( + sce, var_registration = var_registration, var_sample_id = var_sample_id, min_ncells = min_ncells, @@ -81,11 +88,14 @@ registration_wrapper <- block_cor <- registration_block_cor(sce_pseudo, registration_model = registration_mod) - + ## test if registration var has two groups registration_var_k2 <- length(grep("^registration_variable", colnames(registration_mod))) == 2 if (registration_var_k2) { - warning("You need 'var_registration' to have at least 3 different values to compute an F-statistic, returning Enrichment statistics only", call. = FALSE) + warning( + "You need 'var_registration' to have at least 3 unique values to compute an F-statistic and thus ANOVA modeling results cannot be computed.", + call. = FALSE + ) } results_enrichment <- @@ -96,40 +106,36 @@ registration_wrapper <- gene_ensembl = gene_ensembl, gene_name = gene_name ) - - ## with more than 2 groups run ANOVA and pairwise data - if(!registration_var_k2){ - results_pairwise <- + + results_pairwise <- registration_stats_pairwise( - sce_pseudo, - registration_model = registration_mod, - block_cor = block_cor, - gene_ensembl = gene_ensembl, - gene_name = gene_name - ) - results_anova <- - registration_stats_anova( - sce_pseudo, - block_cor = block_cor, - covars = covars, - gene_ensembl = gene_ensembl, - gene_name = gene_name, - suffix = suffix + sce_pseudo, + registration_model = registration_mod, + block_cor = block_cor, + gene_ensembl = gene_ensembl, + gene_name = gene_name ) - - modeling_results <- list( - "anova" = results_anova, - "enrichment" = results_enrichment, - "pairwise" = results_pairwise - ) + + ## with more than 2 groups run ANOVA model + if (!registration_var_k2) { + results_anova <- + registration_stats_anova( + sce_pseudo, + block_cor = block_cor, + covars = covars, + gene_ensembl = gene_ensembl, + gene_name = gene_name, + suffix = suffix + ) } else { - modeling_results <- list( - "anova" = NULL, - "enrichment" = results_enrichment, - "pairwise" = NULL - ) + results_anova <- NULL } - + ## Bundle results together + modeling_results <- list( + "anova" = NULL, + "enrichment" = results_enrichment, + "pairwise" = results_pairwise + ) return(modeling_results) } diff --git a/man/registration_wrapper.Rd b/man/registration_wrapper.Rd index 2fc3f852..76a2da32 100644 --- a/man/registration_wrapper.Rd +++ b/man/registration_wrapper.Rd @@ -92,13 +92,19 @@ rowData(sce)$gene_name <- paste0("gene", seq_len(nrow(sce))) ## Compute all modeling results example_modeling_results <- registration_wrapper( sce, - var_regustration ="Cell_Cycle", - var_sample_id ="sample_id", + var_registration = "Cell_Cycle", + var_sample_id = "sample_id", covars = c("age"), - gene_ensembl = "ensembl", - gene_name = "gene_name", + gene_ensembl = "ensembl", + gene_name = "gene_name", suffix = "wrapper" ) + +## Explore the results from registration_wrapper() +class(example_modeling_results) +length(example_modeling_results) +names(example_modeling_results) +lapply(example_modeling_results, head) } \seealso{ Other spatial registration and statistical modeling functions: diff --git a/tests/testthat/test-registration_wrapper.R b/tests/testthat/test-registration_wrapper.R index 1fc1b983..b7deec09 100644 --- a/tests/testthat/test-registration_wrapper.R +++ b/tests/testthat/test-registration_wrapper.R @@ -20,16 +20,17 @@ rowData(sce)$ensembl <- paste0("ENSG", seq_len(nrow(sce))) rowData(sce)$gene_name <- paste0("gene", seq_len(nrow(sce))) -test_that("warning for k=2 variable", - example_modeling_results <- expect_warning( - registration_wrapper( - sce, - var_registration ="Treatment", - var_sample_id ="sample_id", - covars = c("age"), - gene_ensembl = "ensembl", - gene_name = "gene_name", - suffix = "wrapper" - ) - ) +test_that( + "warning for k=2 variable", + example_modeling_results <- expect_warning( + registration_wrapper( + sce, + var_registration = "Treatment", + var_sample_id = "sample_id", + covars = c("age"), + gene_ensembl = "ensembl", + gene_name = "gene_name", + suffix = "wrapper" + ) + ) )