# Real data study - Part 2 (for annotation see Part 1, i.e. "LargeDataStudy_1.R")


setwd("~/")
savepath <- "~/"


accnumber <- c("E-GEOD-60542",  
 "E-GEOD-71571",  
 "E-GEOD-64415",  
 "E-GEOD-48278",  
 "E-GEOD-58697",  
 "E-GEOD-68720",  
 "E-GEOD-67851",  
 "E-GEOD-64857",  
 "E-GEOD-53224",  
 "E-GEOD-49697",  
 "E-GEOD-28654",  
 "E-GEOD-54543",  
 "E-GEOD-63626",  
 "E-GEOD-57065",  
 "E-GEOD-61804",  
 "E-GEOD-33532",  
 "E-GEOD-19722",  
 "E-GEOD-59312",  
 "E-GEOD-39084",  
 "E-GEOD-60028",  
 "E-GEOD-45670",  
 "E-GEOD-38662",  
 "E-GEOD-58558",  
 "E-GEOD-49243",  
 "E-GEOD-54837",  
 "E-GEOD-50774",  
 "E-GEOD-46474",  
 "E-GEOD-48780",  
 "E-GEOD-48350",  
 "E-GEOD-53890",  
 "E-GEOD-45216",  
 "E-GEOD-53987",  
 "E-GEOD-29623",  
 "E-GEOD-45867")

 
 
setting <- c("sepnorm", "addonnorm")
batchremmethod <- c("none", "fabatch", "combat", "fsvafast", "fsvaexact", "meancenter", 
  "standardize", "ratioa", "ratiog")
traintestsetsize <- c("trainsmalltestverysmall", "trainsmalltestsmall", 
 "trainsmalltestlarge", "trainlargetestverysmall", "trainlargetestsmall", 
 "trainlargetestlarge")
  
scenariogrid <- expand.grid(accnumbertest=accnumber, accnumbertrain=accnumber, traintestsetsize=traintestsetsize,
  batchremmethod=batchremmethod, setting=setting, stringsAsFactors = FALSE)[,5:1]
  
set.seed(1234)
seeds <- sample(1000:10000000, size=length(accnumber)^2)

scenariogrid$seed <- rep(seeds, times=length(batchremmethod)*length(setting)*length(traintestsetsize))

scenariogrid <- scenariogrid[apply(scenariogrid, 1, function(x) x[4]!=x[5]),]



set.seed(1234)
reorderind <- sample(1:nrow(scenariogrid))
scenariogrid <- scenariogrid[reorderind,]
 
njobs <- 4

numberits <- floor(nrow(scenariogrid)/njobs)
nrest <- nrow(scenariogrid) - njobs*numberits

nitervec <- rep(numberits, njobs)

if(nrest > 0)
  nitervec[1:nrest] <- nitervec[1:nrest] + 1
 
startinds <- c(1, cumsum(nitervec)+1)
startinds <- startinds[-length(startinds)]
stopinds <- cumsum(nitervec)


indjob <- 2
scenariogrid <- scenariogrid[startinds[indjob]:stopinds[indjob],] 
 
 
source(paste(savepath, "ICSVCodeData/Functions/FunctionsForClusters.R", sep=""))


sfExportAll()

Results <- sfLapply(1:nrow(scenariogrid), function(z) try({evaluatesetting(z)}))

sfStop()

save(Results, file=paste(savepath, "ICSVCodeData/Results/ResultsLargeDataStudy_2.Rda", sep=""))

rm(list=ls());gc()
