Skip to content

Commit 9b1c722

Browse files
authored
Merge pull request #86 from LieberInstitute/registration_wrapper_k2
Registration wrapper k2
2 parents 97dffb7 + ae8fb4a commit 9b1c722

File tree

3 files changed

+80
-18
lines changed

3 files changed

+80
-18
lines changed

R/registration_wrapper.R

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@
4747
#' ## Compute all modeling results
4848
#' example_modeling_results <- registration_wrapper(
4949
#' sce,
50-
#' "Cell_Cycle", "sample_id", c("age"), "ensembl", "gene_name", "wrapper"
50+
#' var_regustration ="Cell_Cycle",
51+
#' var_sample_id ="sample_id",
52+
#' covars = c("age"),
53+
#' gene_ensembl = "ensembl",
54+
#' gene_name = "gene_name",
55+
#' suffix = "wrapper"
5156
#' )
5257
registration_wrapper <-
5358
function(sce,
@@ -76,6 +81,12 @@ registration_wrapper <-
7681

7782
block_cor <-
7883
registration_block_cor(sce_pseudo, registration_model = registration_mod)
84+
85+
## test if registration var has two groups
86+
registration_var_k2 <- length(grep("^registration_variable", colnames(registration_mod))) == 2
87+
if (registration_var_k2) {
88+
warning("You need 'var_registration' to have at least 3 different values to compute an F-statistic, returning Enrichment statistics only", call. = FALSE)
89+
}
7990

8091
results_enrichment <-
8192
registration_stats_enrichment(
@@ -85,29 +96,40 @@ registration_wrapper <-
8596
gene_ensembl = gene_ensembl,
8697
gene_name = gene_name
8798
)
88-
results_pairwise <-
99+
100+
## with more than 2 groups run ANOVA and pairwise data
101+
if(!registration_var_k2){
102+
results_pairwise <-
89103
registration_stats_pairwise(
90-
sce_pseudo,
91-
registration_model = registration_mod,
92-
block_cor = block_cor,
93-
gene_ensembl = gene_ensembl,
94-
gene_name = gene_name
104+
sce_pseudo,
105+
registration_model = registration_mod,
106+
block_cor = block_cor,
107+
gene_ensembl = gene_ensembl,
108+
gene_name = gene_name
95109
)
96-
results_anova <-
110+
results_anova <-
97111
registration_stats_anova(
98-
sce_pseudo,
99-
block_cor = block_cor,
100-
covars = covars,
101-
gene_ensembl = gene_ensembl,
102-
gene_name = gene_name,
103-
suffix = suffix
112+
sce_pseudo,
113+
block_cor = block_cor,
114+
covars = covars,
115+
gene_ensembl = gene_ensembl,
116+
gene_name = gene_name,
117+
suffix = suffix
104118
)
105-
106-
modeling_results <- list(
119+
120+
modeling_results <- list(
107121
"anova" = results_anova,
108122
"enrichment" = results_enrichment,
109123
"pairwise" = results_pairwise
110-
)
124+
)
125+
} else {
126+
modeling_results <- list(
127+
"anova" = NULL,
128+
"enrichment" = results_enrichment,
129+
"pairwise" = NULL
130+
)
131+
}
132+
111133

112134
return(modeling_results)
113135
}

man/registration_wrapper.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Ensure reproducibility of example data
2+
set.seed(20220907)
3+
4+
## Generate example data
5+
sce <- scuttle::mockSCE()
6+
7+
## Add some sample IDs
8+
sce$sample_id <- sample(LETTERS[1:5], ncol(sce), replace = TRUE)
9+
10+
## Add a sample-level covariate: age
11+
ages <- rnorm(5, mean = 20, sd = 4)
12+
names(ages) <- LETTERS[1:5]
13+
sce$age <- ages[sce$sample_id]
14+
15+
## add variable with one group
16+
sce$batch <- "batch1"
17+
18+
## Add gene-level information
19+
rowData(sce)$ensembl <- paste0("ENSG", seq_len(nrow(sce)))
20+
rowData(sce)$gene_name <- paste0("gene", seq_len(nrow(sce)))
21+
22+
23+
test_that("warning for k=2 variable",
24+
example_modeling_results <- expect_warning(
25+
registration_wrapper(
26+
sce,
27+
var_registration ="Treatment",
28+
var_sample_id ="sample_id",
29+
covars = c("age"),
30+
gene_ensembl = "ensembl",
31+
gene_name = "gene_name",
32+
suffix = "wrapper"
33+
)
34+
)
35+
)

0 commit comments

Comments
 (0)