6
|
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
|
33
|
13 # create fold by picking at random row indexes
|
6
|
14 createFolds <- function(nbObs, n) {
|
33
|
15 # pick indexes
|
6
|
16 index <- sample(1:n, size=nbObs, replace = T)
|
33
|
17 # populate folds
|
6
|
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 #############################
|
33
|
26 # load arguments
|
6
|
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
|
33 # fold creation
|
6
|
34 nObs <- nrow(read.table(genotype, sep="\t", h=T))
|
|
35 folds <- createFolds(nObs, as.numeric(n))
|
33
|
36 # save them into a rds and send back to galaxy the path
|
6
|
37 out <- paste(out,".rds",sep="")
|
|
38 saveRDS(folds, file=out)
|
|
39 cat(paste(out, "\n", sep="")) |