changeset 1:4b54bb0e5958 draft

Uploaded
author deepakjadmin
date Tue, 27 Sep 2016 06:44:59 -0400
parents 9c0e0cc778f8
children e6d9c3fac3c4
files Preold_advance.R
diffstat 1 files changed, 70 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Preold_advance.R	Fri Jan 22 12:09:17 2016 -0500
+++ b/Preold_advance.R	Tue Sep 27 06:44:59 2016 -0400
@@ -5,7 +5,8 @@
 arg3 <- args[3]
 #source("~/galaxy-dist/tools/mpdstoolsV2/tool3/Preold.R")
 #pre(arg1,arg2,arg3)
-set.seed(1)
+set.seed(1234)
+
 pre <- function(args1,args2,args3){
 #args <- commandArgs(TRUE)
 nTrain <- read.csv(args1,row.names= 1, header = T) # example nTrain.csv file of unknown activity
@@ -35,20 +36,21 @@
 allcolumnmissing <- which(fop)
 if (length(allcolumnmissing) > 0){
 newdata[,allcolumnmissing] <- 0
-newdata[,allcolumnmissing] <- newdata[,allcolumnmissing] + runif(3,0,0.00000000000000000000000000000001) ### add noise}
+newdata[,allcolumnmissing] <- newdata[,allcolumnmissing] + runif(3,0,0.00001) ### add noise}
 }
 
 library(caret)
-
+if(exists('ppInfo')){
 #if(as.character(!isS4(Fit$finalModel == "TRUE")))
 if((Fit$method != "svmRadial") && (Fit$method != "svmLinear"))
 {
         reqcol <- Fit$finalModel$xNames
         newdata <- newdata[,reqcol]
         newdata <- apply(newdata,2,f)
-        newdata <- newdata + runif(3,0,0.01) ### add noise to overcome from NZV error
-        newdata1 <- preProcess(newdata, method = c("center", "scale"))
-        newdata11 <- predict(newdata1,newdata)
+        newdata <- newdata + runif(3,0,0.0001) ### add noise to overcome from NZV error
+        #newdata1 <- preProcess(newdata, method = c("center", "scale"))
+        #newdata1 <- preProcess(newdata, ppInfo)
+        newdata11 <- predict(ppInfo,newdata)
 ###########
         library(stats)
         testpredict <- predict(modelFit,newdata11)
@@ -64,6 +66,9 @@
         Prob <- as.data.frame(probpredict)
         dw <- format(cbind(names,Prob,activity),justify="centre")
         write.table(dw,file=args3,row.names=FALSE,sep="\t")
+        
+        
+        
 } else if((Fit$method == "svmRadial") | (Fit$method == "svmLinear")){       
         library(stats)
         reqcol <- colnames(Fit$trainingData)
@@ -71,9 +76,10 @@
         newdata <- newdata[,reqcol]
 
         newdata <- apply(newdata,2,f)
-        newdata <- newdata + runif(3,0,0.01) ### add little noise to overcome from NZV problem
-        newdata1 <- preProcess(newdata, method = c("center", "scale"))
-        newdata11 <- predict(newdata1,newdata)
+        newdata <- newdata + runif(3,0,0.0001) ### add little noise to overcome from NZV problem
+        #newdata1 <- preProcess(newdata, method = c("center", "scale"))
+        #newdata1 <- preProcess(newdata,ppInfo)
+        newdata11 <- predict(ppInfo,newdata)
         testpredict <- predict(modelFit,newdata11)
         Label <- levels(testpredict)
         a1 <- Label[1]
@@ -91,5 +97,60 @@
       dw <- "There is something wrong in data or model"
 	 write.csv(dw,file=args3,row.names=FALSE)
 }
+} else{
+
+#if(as.character(!isS4(Fit$finalModel == "TRUE")))
+if((Fit$method != "svmRadial") && (Fit$method != "svmLinear"))
+{
+        reqcol <- Fit$finalModel$xNames
+        newdata <- newdata[,reqcol]
+        newdata <- apply(newdata,2,f)
+        newdata <- newdata + runif(3,0,0.0001) ### add noise to overcome from NZV error
+       
+###########
+        library(stats)
+        testpredict <- predict(modelFit,newdata)
+        Label <- levels(testpredict)
+        a1 <- Label[1]
+        a2 <- Label[2]
+        probpredict <- predict(modelFit,newdata,type="prob")
+        names <- as.data.frame(rownames(nTrain))
+        colnames(names) <- "COMPOUND"
+        activity <- as.data.frame(testpredict)
+        colnames(activity) <- "PREDICTED ACTIVITY"
+        colnames(probpredict) <- c(eval(a1),eval(a2))
+        Prob <- as.data.frame(probpredict)
+        dw <- format(cbind(names,Prob,activity),justify="centre")
+        write.table(dw,file=args3,row.names=FALSE,sep="\t")
+        
+        
+        
+} else if((Fit$method == "svmRadial") | (Fit$method == "svmLinear")){       
+        library(stats)
+        reqcol <- colnames(Fit$trainingData)
+        reqcol <- reqcol[1:length(reqcol)-1]
+        newdata <- newdata[,reqcol]
+
+        newdata <- apply(newdata,2,f)
+        newdata <- newdata + runif(3,0,0.0001) ### add little noise to overcome from NZV problem
+              
+        testpredict <- predict(modelFit,newdata)
+        Label <- levels(testpredict)
+        a1 <- Label[1]
+        a2 <- Label[2]
+        probpredict <- predict(modelFit,newdata,type="prob")
+        names <- as.data.frame(rownames(nTrain))
+        colnames(names) <- "COMPOUND"
+        activity <- as.data.frame(testpredict)
+        colnames(activity) <- "PREDICTED ACTIVITY"
+        colnames(probpredict) <- c(eval(a1),eval(a2))
+        Prob <- as.data.frame(probpredict)
+        dw <- format(cbind(names,Prob,activity),justify="centre")
+        write.table(dw,file=args3,row.names=FALSE,sep="\t")
+}else {
+      dw <- "There is something wrong in data or model"
+	 write.csv(dw,file=args3,row.names=FALSE)
+}
+}
 }
 pre(arg1,arg2,arg3)