Mercurial > repos > anmoljh > activity_predict
annotate predict_activity.R @ 0:20df9782b07a draft
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
author | anmoljh |
---|---|
date | Thu, 31 May 2018 11:33:23 -0400 |
parents | |
children |
rev | line source |
---|---|
0
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
1 ########## |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
2 args <- commandArgs(T) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
3 arg1 <- args[1] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
4 arg2 <- args[2] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
5 arg3 <- args[3] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
6 #source("~/galaxy-dist/tools/mpdstoolsV2/tool3/Preold.R") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
7 #pre(arg1,arg2,arg3 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
8 set.seed(1) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
9 pre <- function(args1,args2,args3){ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
10 #args <- commandArgs(TRUE) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
11 nTrain <- read.csv(args1,row.names= 1, header = T) # example nTrain.csv file of unknown activity |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
12 #save(nTrain,file = "nTrain.RData") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
13 #load("nTrain.RData") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
14 load(args2) # model generated from previous programn |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
15 newdata <- nTrain |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
16 modelFit <- Fit |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
17 ########### |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
18 # input csv file must contaion the exact same column as used in model building # |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
19 # Also do pre-proccessing by means of centering and scaling |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
20 ## problem in s4 object so first check that the given model has s4 object in |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
21 ## >isS4(Fit$finalmodel) if it is s4 than add in with elseif loop |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
22 ## eg . isS4(plsFit$finalModel) == TRUE |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
23 f=function(x){ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
24 x<-as.numeric(as.character(x)) #first convert each column into numeric if it is from factor |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
25 x[is.na(x) | is.nan(x) | is.infinite(x)] = median(x, na.rm=TRUE) #convert the item with NA to median value from the column |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
26 x #display the column |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
27 } |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
28 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
29 f2=function(x){ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
30 all(is.na(x)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
31 } |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
32 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
33 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
34 fop <- apply(newdata,2,f2) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
35 allcolumnmissing <- which(fop) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
36 if (length(allcolumnmissing) > 0){ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
37 newdata[,allcolumnmissing] <- 0 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
38 newdata[,allcolumnmissing] <- newdata[,allcolumnmissing] + runif(3,0,0.00001) ### add noise} |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
39 } |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
40 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
41 library(caret) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
42 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
43 #if(as.character(!isS4(Fit$finalModel == "TRUE"))) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
44 if(exists('ppInfo')){ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
45 #if(as.character(!isS4(Fit$finalModel == "TRUE"))) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
46 if((Fit$method != "svmRadial") && (Fit$method != "svmLinear")) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
47 { |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
48 reqcol <- Fit$finalModel$xNames |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
49 newdata <- newdata[,reqcol] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
50 newdata <- apply(newdata,2,f) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
51 #newdata <- newdata + runif(3,0,0.0001) ### add noise to overcome from NZV error |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
52 #newdata1 <- preProcess(newdata, method = c("center", "scale")) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
53 #newdata1 <- preProcess(newdata, ppInfo) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
54 newdata11 <- predict(ppInfo,newdata) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
55 ########### |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
56 library(stats) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
57 testpredict <- predict(modelFit,newdata11) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
58 Label <- levels(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
59 a1 <- Label[1] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
60 a2 <- Label[2] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
61 probpredict <- predict(modelFit,newdata11,type="prob") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
62 names <- as.data.frame(rownames(nTrain)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
63 colnames(names) <- "COMPOUND" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
64 activity <- as.data.frame(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
65 colnames(activity) <- "PREDICTED ACTIVITY" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
66 colnames(probpredict) <- c(eval(a1),eval(a2)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
67 Prob <- as.data.frame(probpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
68 dw <- format(cbind(names,Prob,activity),justify="centre") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
69 write.table(dw,file=args3,row.names=FALSE,sep="\t") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
70 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
71 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
72 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
73 } else if((Fit$method == "svmRadial") | (Fit$method == "svmLinear")){ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
74 library(stats) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
75 reqcol <- colnames(Fit$trainingData) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
76 reqcol <- reqcol[1:length(reqcol)-1] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
77 newdata <- newdata[,reqcol] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
78 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
79 newdata <- apply(newdata,2,f) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
80 #newdata <- newdata + runif(3,0,0.0001) ### add little noise to overcome from NZV problem |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
81 #newdata1 <- preProcess(newdata, method = c("center", "scale")) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
82 #newdata1 <- preProcess(newdata,ppInfo) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
83 newdata11 <- predict(ppInfo,newdata) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
84 testpredict <- predict(modelFit,newdata11) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
85 Label <- levels(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
86 a1 <- Label[1] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
87 a2 <- Label[2] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
88 probpredict <- predict(modelFit,newdata11,type="prob") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
89 names <- as.data.frame(rownames(nTrain)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
90 colnames(names) <- "COMPOUND" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
91 activity <- as.data.frame(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
92 colnames(activity) <- "PREDICTED ACTIVITY" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
93 colnames(probpredict) <- c(eval(a1),eval(a2)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
94 Prob <- as.data.frame(probpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
95 dw <- format(cbind(names,Prob,activity),justify="centre") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
96 write.table(dw,file=args3,row.names=FALSE,sep="\t") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
97 }else { |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
98 dw <- "There is something wrong in data or model" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
99 write.csv(dw,file=args3,row.names=FALSE) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
100 } |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
101 } else{ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
102 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
103 #if(as.character(!isS4(Fit$finalModel == "TRUE"))) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
104 if((Fit$method != "svmRadial") && (Fit$method != "svmLinear")) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
105 { |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
106 reqcol <- Fit$finalModel$xNames |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
107 newdata <- newdata[,reqcol] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
108 newdata <- apply(newdata,2,f) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
109 #newdata <- newdata + runif(3,0,0.0001) ### add noise to overcome from NZV error |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
110 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
111 ########### |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
112 library(stats) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
113 testpredict <- predict(modelFit,newdata) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
114 Label <- levels(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
115 a1 <- Label[1] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
116 a2 <- Label[2] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
117 probpredict <- predict(modelFit,newdata,type="prob") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
118 names <- as.data.frame(rownames(nTrain)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
119 colnames(names) <- "COMPOUND" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
120 activity <- as.data.frame(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
121 colnames(activity) <- "PREDICTED ACTIVITY" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
122 colnames(probpredict) <- c(eval(a1),eval(a2)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
123 Prob <- as.data.frame(probpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
124 dw <- format(cbind(names,Prob,activity),justify="centre") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
125 write.table(dw,file=args3,row.names=FALSE,sep="\t") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
126 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
127 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
128 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
129 } else if((Fit$method == "svmRadial") | (Fit$method == "svmLinear")){ |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
130 library(stats) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
131 reqcol <- colnames(Fit$trainingData) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
132 reqcol <- reqcol[1:length(reqcol)-1] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
133 newdata <- newdata[,reqcol] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
134 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
135 newdata <- apply(newdata,2,f) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
136 #newdata <- newdata + runif(3,0,0.0001) ### add little noise to overcome from NZV problem |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
137 |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
138 testpredict <- predict(modelFit,newdata) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
139 Label <- levels(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
140 a1 <- Label[1] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
141 a2 <- Label[2] |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
142 probpredict <- predict(modelFit,newdata,type="prob") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
143 names <- as.data.frame(rownames(nTrain)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
144 colnames(names) <- "COMPOUND" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
145 activity <- as.data.frame(testpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
146 colnames(activity) <- "PREDICTED ACTIVITY" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
147 colnames(probpredict) <- c(eval(a1),eval(a2)) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
148 Prob <- as.data.frame(probpredict) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
149 dw <- format(cbind(names,Prob,activity),justify="centre") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
150 write.table(dw,file=args3,row.names=FALSE,sep="\t") |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
151 }else { |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
152 dw <- "There is something wrong in data or model" |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
153 write.csv(dw,file=args3,row.names=FALSE) |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
154 } |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
155 } |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
156 } |
20df9782b07a
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
157 pre(arg1,arg2,arg3) |