# HG changeset patch # User nicolas # Date 1477420892 14400 # Node ID 8112bc6428585f3ec5b5bbbd3fa67a892fde4f9d # Parent 6b5c0c7b4585395adc763461c322309e1ec89a96 Uploaded diff -r 6b5c0c7b4585 -r 8112bc642858 prediction.R --- a/prediction.R Tue Oct 25 14:41:18 2016 -0400 +++ b/prediction.R Tue Oct 25 14:41:32 2016 -0400 @@ -6,34 +6,17 @@ # owner : IRRI # ######################################################## -log <- file(paste(getwd(), "log_prediction.txt", sep="/"), open = "wt") -sink(file = log, type="message") library(rrBLUP) -library(randomForest) +suppressWarnings(suppressMessages(library(randomForest))) library(e1071) -library(glmnet) +suppressWarnings(suppressMessages(library(glmnet))) library(methods) -############################ helper functions ####################### - -################################## main function ########################### ############################ main ############################# -# running from terminal (supposing the OghmaGalaxy/bin directory is in your path) : -# predict.sh -i genotype_file -m model_file -n name -o path_to_result_directory -## -i : path to the file that contains the genotypes. -# please note that the table must be called "genotype" when your datafile is saved into .rda (automatic if encode.R is used) - -## -m : model build through any methods -# please note that the table must be called "model" when your datafile is saved into .rda -# (automatic if classifiers from this pipeline were used) - -## -n : prefix of the names of all result files - -## -o : path to the directory where the evaluation results are stored. - classifierNames <- c("list", "randomForest", "svm", "glmnet") +# load argument cmd <- commandArgs(trailingOnly = T) source(cmd[1]) # load data @@ -50,13 +33,16 @@ stop(paste(class(model), "is not recognized as a valid model. Valid models are : ", classifierNames)) } # run prediction according to the classifier +# rrBLUP prediction if(any(class(model) == "list")) { predictions <- as.matrix(genotype) %*% as.matrix(model$u) predictions <- predictions[,1]+model$beta predictions <- data.frame(lines=rownames(genotype), predictions=predictions) +# LASSO prediction } else if(any(class(model) == "glmnet")) { predictions <- predict(model, as.matrix(genotype), type = "response") predictions <- data.frame(lines=rownames(genotype), predictions=predictions) +# SVM or RandomForest prediction (predict is a wrapper for many machine learning function) } else { predictions <- predict(model, genotype) predictions <- data.frame(lines=names(predictions), predictions=predictions)