A Split-Apply-Combine strategy to parallelize the evaluation of a function on each SNP, independently.

snp_split(infos.chr, FUN, combine, ncores = 1, ...)

Arguments

infos.chr

Vector of integers specifying each SNP's chromosome.
Typically <bigSNP>$map$chromosome.

FUN

The function to be applied. It must take a FBM.code256 as first argument and ind.chr, an another argument to provide subsetting over SNPs. You can access the number of the chromosome by using attr(ind.chr, "chr").

combine

function that is used by foreach to process the tasks results as they generated. This can be specified as either a function or a non-empty character string naming the function. Specifying 'c' is useful for concatenating the results into a vector, for example. The values 'cbind' and 'rbind' can combine vectors into a matrix. The values '+' and '*' can be used to process numeric data. By default, the results are returned in a list.

ncores

Number of cores used. Default doesn't use parallelism. You may use nb_cores.

...

Extra arguments to be passed to FUN.

Value

The result of foreach.

Details

This function splits indices for each chromosome, then apply a given function to each part (chromosome) and finally combine the results.

Examples

# parallelize over chromosomes made easy # examples of functions from this package snp_pruning
#> function (G, infos.chr, ind.row = rows_along(G), size = 49, is.size.in.bp = FALSE, #> infos.pos = NULL, thr.r2 = 0.2, exclude = NULL, nploidy = 2, #> ncores = 1) #> { #> check_args() #> warning2("Pruning is deprecated; using clumping (on MAF) instead..\n%s", #> "See why there: https://goo.gl/Td5YYv.") #> args <- c(as.list(environment()), list(S = NULL)) #> args[["nploidy"]] <- NULL #> do.call(what = snp_split, args = c(args, FUN = clumpingChr, #> combine = "c")) #> } #> <bytecode: 0x000000002b5ad278> #> <environment: namespace:bigsnpr>
snp_clumping
#> function (G, infos.chr, ind.row = rows_along(G), S = NULL, thr.r2 = 0.2, #> size = 100/thr.r2, infos.pos = NULL, is.size.in.bp = NULL, #> exclude = NULL, ncores = 1) #> { #> check_args() #> if (!missing(is.size.in.bp)) #> warning2("Parameter 'is.size.in.bp' is deprecated.") #> args <- as.list(environment()) #> if (!is.null(S)) #> assert_lengths(infos.chr, S) #> do.call(what = snp_split, args = c(args, FUN = clumpingChr, #> combine = "c")) #> } #> <bytecode: 0x00000000247aecc8> #> <environment: namespace:bigsnpr>
snp_fastImpute
#> function (Gna, infos.chr, alpha = 1e-04, size = 200, p.train = 0.8, #> n.cor = nrow(Gna), seed = NA, ncores = 1) #> { #> if (!requireNamespace("xgboost", quietly = TRUE)) #> stop2("Please install package 'xgboost'.") #> check_args(infos.chr = "assert_lengths(infos.chr, cols_along(Gna))") #> infos.imp <- FBM_infos(Gna) #> if (!is.na(seed)) #> seed <- seq_len(max(infos.chr)) + seed #> args <- as.list(environment()) #> do.call(what = snp_split, args = c(args, FUN = imputeChr, #> combine = "c")) #> infos.imp #> } #> <bytecode: 0x000000002dd164f0> #> <environment: namespace:bigsnpr>