| 77 | 1 ######################################################## | 
|  | 2 # | 
|  | 3 # creation date : 05/01/16 | 
|  | 4 # last modification : 27/06/16 | 
|  | 5 # author : Dr Nicolas Beaume | 
|  | 6 # owner : IRRI | 
|  | 7 # | 
|  | 8 ######################################################## | 
|  | 9 | 
|  | 10 | 
|  | 11 ############################ main function ####################### | 
|  | 12 | 
|  | 13 # create fold by picking at random row indexes | 
|  | 14 createFolds <- function(nbObs, n) { | 
|  | 15   # pick indexes | 
|  | 16   index <- sample(1:n, size=nbObs, replace = T) | 
|  | 17   # populate folds | 
|  | 18   folds <- NULL | 
|  | 19   for(i in 1:n) { | 
|  | 20     folds <- c(folds, list(which(index==i))) | 
|  | 21   } | 
|  | 22   return(folds) | 
|  | 23 } | 
|  | 24 | 
|  | 25 ############################ main ############################# | 
|  | 26 # load arguments | 
|  | 27 cmd <- commandArgs(trailingOnly = T) | 
|  | 28 source(cmd[1]) | 
|  | 29 # load data and merge them | 
|  | 30 con = file(genotype) | 
|  | 31 genotype <- readLines(con = con, n = 1, ok=T) | 
|  | 32 close(con) | 
|  | 33 # fold creation | 
|  | 34 nObs <- nrow(read.table(genotype, sep="\t", h=T)) | 
|  | 35 folds <- createFolds(nObs, as.numeric(n)) | 
|  | 36 # save them into a rds and send back to galaxy the path | 
|  | 37 out <- paste(out,".rds",sep="") | 
|  | 38 saveRDS(folds, file=out) | 
|  | 39 cat(paste(out, "\n", sep="")) |