Skip to content

Commit

Permalink
Merge pull request #303 from stemangiola/de-no-forking
Browse files Browse the repository at this point in the history
De no forking
  • Loading branch information
stemangiola committed Nov 17, 2023
2 parents 85fc313 + 7e55e53 commit 512a534
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: tidybulk
Title: Brings transcriptomics to the tidyverse
Version: 1.15.1
Version: 1.15.2
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
role = c("aut", "cre")),
person("Maria", "Doyle", email = "[email protected]",
Expand Down
25 changes: 20 additions & 5 deletions R/glmmSeq.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ glmmSeq = function (modelFormula, countdata, metadata, id = NULL, dispersion = N
sizeFactors = NULL, reduced = NULL, modelData = NULL, designMatrix = NULL,
method = c("lme4", "glmmTMB"), control = NULL, family = glmmTMB::nbinom2,
cores = 1, removeSingles = FALSE, zeroCount = 0.125, verbose = TRUE,
returnList = FALSE, progress = FALSE, max_rows_for_matrix_multiplication = Inf, ...)
returnList = FALSE, progress = FALSE, max_rows_for_matrix_multiplication = Inf, avoid_forking = FALSE, ...)
{
glmmcall <- match.call(expand.dots = TRUE)
method <- match.arg(method)
Expand Down Expand Up @@ -617,23 +617,38 @@ glmmSeq = function (modelFormula, countdata, metadata, id = NULL, dispersion = N
}
}
else {
if (progress) {

if(avoid_forking){
library(parallel)
cl = parallel::makeCluster(cores, type = "PSOCK")
#parallel::clusterEvalQ(cl,c(library(dplyr),library(glmmSeq)))
#clusterExport(cl, list("varname1", "varname2"),envir=environment())
resultList <- parallel::clusterApply(
cl,
fullList,
function(geneList) {
glmerCore(geneList, fullFormula, reduced,
subsetMetadata, control, offset, modelData,
designMatrix, hyp.matrix,, max_rows_for_matrix_multiplication = max_rows_for_matrix_multiplication, ...)
}
)
}
else if (progress) {

# Check if package is installed, otherwise install
if (find.package("pbmcapply", quiet = TRUE) %>% length %>% equals(0)) {
message("tidybulk says: Installing pbmcapply needed for differential transcript abundance analyses")
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager", repos = "https://cloud.r-project.org")
BiocManager::install("pbmcapply", ask = FALSE)
}

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, ...)
}, mc.cores = cores)
if ("value" %in% names(resultList)) resultList <- resultList$value

}
else {
resultList <- mclapply(fullList, function(geneList) {
Expand Down

0 comments on commit 512a534

Please sign in to comment.