Previous changeset 32:9230fde1d48e (2016-10-25) Next changeset 34:b57cf5ccc108 (2016-10-25) |
Commit message:
Uploaded |
modified:
folds.R |
b |
diff -r 9230fde1d48e -r ff82ecfb509e folds.R --- a/folds.R Tue Oct 25 14:39:48 2016 -0400 +++ b/folds.R Tue Oct 25 14:40:02 2016 -0400 |
[ |
@@ -8,12 +8,13 @@ ######################################################## -############################ helper function #################### - ############################ 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))) @@ -22,28 +23,17 @@ } ############################ main ############################# -# running from terminal (supposing the OghmaGalaxy/bin directory is in your path) : -# folds.sh -i path_to_data [-n nfold] -p phenotype_file [-k nb_classes] -o output_file -## -i : path to the file that contains the genotypes, must be a .rda file (as outputed by loadGenotype.R). -# please note that the table must be called "genotype" when your datafile is saved into .rda (automatic if loadGenotype.R was used) - -## -k : [optional] number of classes of phenotype. This information is used to equilibrate the folds -# if omitted, 2 classes are assumed - -## -p : file that contains the phenotype must be a .rda file (as outputed by loadGenotype.R). -# please note that the table must be called "phenotype" when your datafile is saved into .rda (automatic if loadGenotype.R was used) - -## -n : [optional] number of folds for cross validation. if ommited, n will be setted to 10 - -## -o : path to the file of encoded genotype. the .rda extension is automatically added +# 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 |