Previous changeset 76:f89df98bb81f (2016-10-28) Next changeset 78:5a56e1e3b235 (2016-10-28) |
Commit message:
Uploaded |
added:
folds.R |
b |
diff -r f89df98bb81f -r d388ee8c2d87 folds.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/folds.R Fri Oct 28 08:46:16 2016 -0400 |
[ |
@@ -0,0 +1,39 @@ +######################################################## +# +# creation date : 05/01/16 +# last modification : 27/06/16 +# author : Dr Nicolas Beaume +# owner : IRRI +# +######################################################## + + +############################ main function ####################### + +# create fold by picking at random row indexes +createFolds <- function(nbObs, n) { + # pick indexes + index <- sample(1:n, size=nbObs, replace = T) + # populate folds + folds <- NULL + for(i in 1:n) { + folds <- c(folds, list(which(index==i))) + } + return(folds) +} + +############################ main ############################# +# load arguments +cmd <- commandArgs(trailingOnly = T) +source(cmd[1]) +# load data and merge them +con = file(genotype) +genotype <- readLines(con = con, n = 1, ok=T) +close(con) +# fold creation +nObs <- nrow(read.table(genotype, sep="\t", h=T)) +folds <- createFolds(nObs, as.numeric(n)) +# save them into a rds and send back to galaxy the path +out <- paste(out,".rds",sep="") +saveRDS(folds, file=out) +cat(paste(out, "\n", sep="")) \ No newline at end of file |