changeset 38:8112bc642858 draft

Uploaded
author nicolas
date Tue, 25 Oct 2016 14:41:32 -0400
parents 6b5c0c7b4585
children f818e787d0c0
files prediction.R
diffstat 1 files changed, 6 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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)