Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel computation #15

Closed
peicai opened this issue Jan 17, 2022 · 2 comments
Closed

Parallel computation #15

peicai opened this issue Jan 17, 2022 · 2 comments

Comments

@peicai
Copy link

peicai commented Jan 17, 2022

Hi Jean and team,

Thanks for your work! I'm wondering if I can use MERINGUE with multicore properly. I'd like to compare the computational effeiciency of MERINGUE with other approaches.

Thanks in advance!

@JEFworks
Copy link
Collaborator

JEFworks commented Jan 17, 2022

Great question.

To identify spatially heterogenous genes, MERINGUE evaluates each gene independently. So one potential approach to multicore processing would be to split genes into groups and evaluate each group in parallel.

Here is an example starting from the MOB analysis tutorial:

dim(mat)
[1] 7365  260
# Identify sigificantly spatially auto-correlated genes
start_time <- Sys.time()
I <- getSpatialPatterns(mat, w, verbose = FALSE)
end_time <- Sys.time()
print(end_time - start_time)
Time difference of 6.233067 secs
## Alternative parallelized version
## split genes into 4 groups
ncore <- 4
groups <- split(rownames(mat), sample(1:ncore,nrow(mat),replace=TRUE))
length(groups)
[1] 4
sapply(groups, length)
   1    2    3    4 
1886 1860 1820 1799 
## parallelize groups 4 cores
start_time <- Sys.time()
I <- do.call(rbind, parallel::mclapply(groups, function(gs) {
+   I <- getSpatialPatterns(mat[gs,], w, verbose=FALSE)
+ }, mc.cores=ncore))
end_time <- Sys.time()
print(end_time - start_time)
Time difference of 2.453482 secs

Hope that helps,
Jean

@peicai
Copy link
Author

peicai commented Feb 1, 2022

Hi Jean,

Thanks! It works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants