Skip to content

Commit

Permalink
Fix typo on example for registration_wrapper(). Add a bit more about …
Browse files Browse the repository at this point in the history
…how to explore the results. Actually with k = 2 we can run the pairwise model, so I've re-enabled that. Updating the warning for k = 2 accordingly. Used RStudio's automatic code formatter + styler's addin for styling the active file. Re-ran devtools::document(). Related to #86.
  • Loading branch information
lcolladotor committed Oct 22, 2024
1 parent 9b1c722 commit f2ccc25
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 53 deletions.
80 changes: 43 additions & 37 deletions R/registration_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 <-
Expand All @@ -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)
}
14 changes: 10 additions & 4 deletions man/registration_wrapper.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions tests/testthat/test-registration_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
)

0 comments on commit f2ccc25

Please sign in to comment.