Mercurial > repos > anmoljh > csv_to_rdata
annotate csv2rdata.R @ 0:49d7eb9e1092 draft default tip
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
author | anmoljh |
---|---|
date | Thu, 31 May 2018 11:40:01 -0400 |
parents | |
children |
rev | line source |
---|---|
0
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
1 args <- commandArgs(TRUE) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
2 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
3 csv2rdatatrain <- function(arg1,arg2) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
4 { |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
5 file <- read.csv(arg1,row.names =1, header=T) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
6 col <- ncol(file) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
7 stopifnot(is.null(file) | col > 2 ) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
8 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
9 #cat("the Outcome column is not a factor vector.\n",file=stderr()) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
10 stopifnot(is.factor(file[,col])) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
11 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
12 if(levels(file[,col])[1] != ""){ |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
13 dataX <- file[,1:(col-1)] |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
14 dataY <- file[,col] |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
15 stopifnot(nrow(dataX) == length(dataY)) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
16 save(dataX,dataY,file=arg2) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
17 } |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
18 else{ |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
19 cat("the Outcome column has less number of entry than number of compounds.please check input file.\n",file=stderr()) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
20 } |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
21 } |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
22 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
23 csv2rdatatrain(args[1],args[2]) |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
24 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
25 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
26 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
27 |
49d7eb9e1092
planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff
changeset
|
28 |