# Set working directory:
setwd("~/")


# Accession numbers of datasets:

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")
 

# Make table of settings: 
 
size <- c("large", "small", "verysmall")

scenariogridsep <- expand.grid(size=size, accnumber=accnumber, stringsAsFactors=FALSE)[,2:1, drop=FALSE]

set.seed(1234)
seeds <- sample(1000:10000000, size=nrow(scenariogridsep))

scenariogridsep$seed <- seeds


scenariogrid <- expand.grid(size=size, accnumbertest=accnumber, accnumbertrain=accnumber, stringsAsFactors=FALSE)[,3:1]

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

scenariogrid$seed <- apply(scenariogrid, 1, function(x) scenariogridsep$seed[(scenariogridsep$accnumber==x[2]) & (scenariogridsep$size==x[3])])


# Source the functions to perform the calculations on the server:

source("./ICSVCodeData/Functions/FunctionsForClusters.R") 


# Export all objects to the CPUs:

sfExportAll()


# Perform the addon normalization:

Results <- sfLapply(1:nrow(scenariogrid), function(z) return(list(acctrain=scenariogrid$accnumbertrain[z], 
  acctest=scenariogrid$accnumbertest[z], size=scenariogrid$size[z],
  errormessage=try({NormalizeAddonTest(z)}))))

# Stop the cluster:

sfStop()


# In case errors occured, these are contained in the list "Results".
# Store the latter:

save(Results, file="./ICSVCodeData/InterimResults/NormalizationAddonScriptOut.Rda")


# Clear the workspace:

rm(list=ls())
