|
20 | 20 | #' |
21 | 21 | #' @import Matrix |
22 | 22 | #' @importFrom future.apply future_lapply |
| 23 | +#' @importFrom future nbrOfWorkers |
23 | 24 | #' @importFrom stats model.matrix p.adjust pchisq |
24 | 25 | #' |
25 | 26 | compare_expression <- function(x, umi, group, val1, val2, method = 'LRT', bin_size = 256, |
26 | 27 | cell_attr = x$cell_attr, y = x$y, min_cells = 5, |
27 | 28 | weighted = TRUE, randomize = FALSE, verbosity = 2, |
28 | 29 | verbose = NULL, show_progress = NULL) { |
| 30 | + if (nbrOfWorkers() == 1){ |
| 31 | + my.lapply <- function(X, FUN, future.seed = TRUE) lapply(X, FUN) |
| 32 | + } else { |
| 33 | + my.lapply <- future_lapply |
| 34 | + } |
29 | 35 | # Take care of deprecated arguments |
30 | 36 | if (!is.null(verbose)) { |
31 | 37 | warning("The 'verbose' argument is deprecated as of v0.3. Use 'verbosity' instead. (in sctransform::vst)", immediate. = TRUE, call. = FALSE) |
@@ -93,15 +99,15 @@ compare_expression <- function(x, umi, group, val1, val2, method = 'LRT', bin_si |
93 | 99 | for (i in 1:max_bin) { |
94 | 100 | genes_bin <- genes[bin_ind == i] |
95 | 101 | if (method == 't_test') { |
96 | | - bin_res <- future_lapply( |
| 102 | + bin_res <- my.lapply( |
97 | 103 | X = genes_bin, |
98 | 104 | FUN = function(gene) {model_comparison_ttest(y[gene, use_cells], group)}, |
99 | 105 | future.seed = TRUE) |
100 | 106 | } |
101 | 107 | if (method == 'LRT') { |
102 | 108 | mu <- x$model_pars_fit[genes_bin, -1, drop=FALSE] %*% t(regressor_data) # in log space |
103 | 109 | y <- as.matrix(umi[genes_bin, use_cells]) |
104 | | - bin_res <- future_lapply( |
| 110 | + bin_res <- my.lapply( |
105 | 111 | X = genes_bin, |
106 | 112 | FUN = function(gene) { |
107 | 113 | model_comparison_lrt(y[gene, ], mu[gene, ], x$model_pars_fit[gene, 'theta'], group, weights)}, |
@@ -175,7 +181,7 @@ compare_expression <- function(x, umi, group, val1, val2, method = 'LRT', bin_si |
175 | 181 | y_theta[o] <- 10 ^ ksmooth(x = x$genes_log_mean_step1, y = log10(x$model_pars[, 'theta']), |
176 | 182 | x.points = y_log_mean, bandwidth = bw, kernel='normal')$y |
177 | 183 | names(y_theta) <- genes_bin |
178 | | - bin_res <- future_lapply( |
| 184 | + bin_res <- my.lapply( |
179 | 185 | X = genes_bin, |
180 | 186 | FUN = function(gene) { |
181 | 187 | return(model_comparison_lrt_free3(gene, y[gene, ], y_theta[gene], x$model_str, cell_attr, group, weights, randomize)) |
|
0 commit comments