library(parallel)
# choose an appropriate cluster size or number of cores
seqParallelSetup(2)
# the GDS file
(gds.fn <- seqExampleFileName("gds"))
# display
(gdsfile <- seqOpen(gds.fn))
# the uniprocessor version
afreq1 <- seqParallel(, gdsfile, FUN = function(f) {
seqApply(f, "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(, gdsfile, FUN = function(f) {
seqApply(f, "genotype", as.is="double",
FUN=function(x) mean(x==0, na.rm=TRUE))
}, split = "by.variant")
length(afreq2)
summary(afreq2)
# check
length(afreq1) # 1348
all(afreq1 == afreq2)
################################################################
# check -- variant splits
seqParallel(, gdsfile, FUN = function(f) {
v <- seqGetFilter(f)
sum(v$variant.sel)
}, split = "by.variant")
# [1] 674 674
################################################################
seqParallel(, NULL, FUN = function() {
paste(SeqArray:::process_index, SeqArray:::process_count, sep=" / ")
}, split = "none")
################################################################
# close the GDS file
seqClose(gdsfile)
seqParallelSetup(FALSE)
Run the code above in your browser using DataLab