annotate predict_activity.R @ 0:7d5a86725094 draft

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