Mercurial > repos > nicolas > oghma
view folds.R @ 103:e7115e44d8d8 draft default tip
Uploaded
author | nicolas |
---|---|
date | Mon, 31 Oct 2016 07:20:49 -0400 |
parents | d388ee8c2d87 |
children |
line wrap: on
line source
######################################################## # # 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=""))