library(parallel)
# Use option cl.core to choose an appropriate cluster size or number of cores
cl <- makeCluster(getOption("cl.cores", 2))
# the file of GDS
gds.fn <- seqExampleFileName("gds")
# or gds.fn <- "C:/YourFolder/Your_GDS_File.gds"
# display
(f <- seqOpen(gds.fn))
# the uniprocessor version
afreq1 <- seqParallel(NULL, f, FUN = function(gdsfile) {
seqApply(gdsfile, "genotype", as.is="double",
FUN=function(x) mean(x==0, na.rm=TRUE))
}, split = "by.variant")
length(afreq1)
summary(afreq1)
# run in parallel
afreq2 <- seqParallel(cl, f, FUN = function(gdsfile) {
seqApply(gdsfile, "genotype", as.is="double",
FUN=function(x) mean(x==0, na.rm=TRUE))
}, split = "by.variant")
length(afreq2)
summary(afreq2)
# check
all(afreq1 == afreq2)
################################################################
# check -- variant splits
seqParallel(cl, f, FUN = function(gdsfile) {
v <- seqGetFilter(gdsfile)
sum(v$variant.sel)
}, split = "by.variant")
# [1] 674 674
################################################################
stopCluster(cl)
# close the GDS file
seqClose(f)
Run the code above in your browser using DataLab