0

我有这段代码,我想并行但是我似乎无法让它工作。这个想法是,对于每个值 chr,snp_sel(geno_data,k, bl) 给我一个由 k 列组成的矩阵,这些列随后被一一写入文件。我怎样才能 %dopar% 这个循环?

foreach(chr=1:length(chrs_raw)) %dopar% 
{
    start = Sys.time() 
    print(start) 

    print(chr) 

    # get .raw file name + path 
    rawfile = paste(RAWfolder, chrs_raw[chr],sep="/") 
    # get .bim file name + path 
    bimfile = paste(RAWfolder, chrs_bim[chr],sep="/") 

    # Read in genetype data in raw format 
    geno_data = fread(rawfile, data.table=FALSE, showProgress = FALSE) 
    # Remove first 7 columns 
    geno_data = as.matrix(geno_data[,c(7:ncol(geno_data))]) 

    # Apply LD subsetting function Lubke et al 2012 
    LDsubset = snp_sel(geno_data,k, bl) 
    rm(geno_data) 

    snp_data = fread(bimfile, data.table=FALSE, showProgress = FALSE) 

    for(subsets in 1:ncol(LDsubset)) 
    { 
            dataout = snp_data[LDsubset[,subsets][LDsubset[,subsets] != 0],2] 
            outfile = paste(gsub(".bim","",basename(chrs_bim[chr])), "S",subsets, sep="") 
            pathout = paste("folderOut/Data/Subsets/",outfile, sep="") 

            write.table(dataout, pathout, col.names=FALSE, row.names=F) 
    } 
    rm(snp_data); rm(LDsubset) 
    stop = Sys.time() 
    print(stop-start) 
}
4

1 回答 1

0

该行:

pathout = paste(folderOut/Data/Subsets/",outfile, sep="") 

缺少一个开头的双引号。它应该是:

pathout = paste("folderOut/Data/Subsets/", outfile, sep="") 

我不确定这是否可以完全解决您的问题,但这应该会有所帮助。

于 2017-03-28T21:05:38.323 回答