using doparallel and foreach in R for nested loops and continuously printing output -


i trying compute auc multiple gene expression combinations. have ~2000 upregulated genes , ~1500 downregulated genes. need use parallel code taking long compute. tried change code little(below) output not how want it.

desired output:

{pos.gene1}{neg.gene1}, {pos.gene2}{neg.gene2} x1 x2 x3 x4

{pos.gene1}{neg.gene1}, {pos.gene2}{neg.gene3} x1 x2 x3 x4

....

output getting: {pos.gene1}{neg.gene1}, {pos.gene2}{neg.gene2} x1 x2 x3 x4{pos.gene2}{neg.gene4}, {pos.gene3}{neg.gene4} x1 x2 x3 x4

basically, not in order looking , not formatted.

i new parallel computing using r. can me fix code?

thanks!

library(foreach) library(doparallel)  #setup parallel backend use many processors cores=detectcores() cl <- makecluster(cores[1]-1) #not overload computer registerdoparallel(cl)  validation = readrds("file 5 lists each having sublists")  path = "xxx" source(paste0(path,"functions.r")) # importing functions use in script   genes = readrds("list 2 sublists") pos.genes = genes$pos # list of upregulated genes neg.genes = genes$neg # list of downregulated genes  mat = matrix(nrow = 1, ncol = 5) #creating empty matrix fileconn = "validation_parallel.tsv"   foreach( i=1 : length(pos.genes)%:%   {   foreach( j=1: length(neg.genes) %:%   {     foreach( k=(j+1): length(neg.genes) %dopar%     {        score <- function(data){######} # function returns matrix of 1 row , 4 columns having numbers         pair1 = paste0("{",c(pos.genes[i], pos.genes[i+1]),"}","{",c(neg.genes[j],neg.genes[k]),"}",collapse = ',')        # each iteration in k, calculating score , continuously writing output file       mat[1,1] = pair1       mat[1,2] = score[1,1]       mat[1,3] = score[1,2]       mat[1,4] = score[1,3]       mat[1,5] = score[1,4]        cat(mat,file = fileconn, sep = "\t", append = true)       cat(file = fileconn, sep = "\n", append = true)          }   } } #stop cluster stopcluster(cl) 


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -