comparison selectionExtracted.R @ 0:4d539083cf7f draft

planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
author sblanck
date Tue, 12 May 2020 10:40:36 -0400
parents
children 3fcbb8030fcc
comparison
equal deleted inserted replaced
-1:000000000000 0:4d539083cf7f
1 #!/usr/bin/env Rscript
2 # setup R error handling to go to stderr
3 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
4
5 # we need that to not crash galaxy with an UTF8 error on German LC settings.
6 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
7
8 library("optparse")
9
10 ##### Read options
11 option_list=list(
12 make_option("--input",type="character",default=NULL, dest="input"),
13 make_option("--output",type="character",default=NULL, dest="output"),
14 make_option("--new_file_path",type="character",default=NULL, dest="new_file_path"),
15 make_option("--response",type="character",default=NULL, dest="response"),
16 make_option("--loss",type="character",default=NULL, dest="loss"),
17 make_option("--folds",type="character",default=NULL, dest="folds"),
18 make_option("--outputlog",type="character",default=NULL, dest="outputlog"),
19 make_option("--log",type="character",default=NULL, dest="log")
20 );
21
22 opt_parser = OptionParser(option_list=option_list);
23 opt = parse_args(opt_parser);
24
25 if(is.null(opt$input)){
26 print_help(opt_parser)
27 stop("input required.", call.=FALSE)
28 }
29
30 #loading libraries
31
32
33 input=opt$input
34 response=opt$response
35 output=opt$output
36 tmp_dir=opt$new_file_path
37 nbFolds=as.numeric(opt$folds)
38 loss=opt$loss
39 log=opt$log
40 outputlog=opt$outputlog
41
42
43 #args<-commandArgs(TRUE)
44 #
45 #input=args[1]
46 #response=args[2]
47 #tmp_dir=args[3]
48 #nbFolds=as.numeric(args[4])
49 #loss=args[5]
50 #output=args[6]
51
52 library(MPAgenomics)
53 workdir=file.path(tmp_dir, "mpagenomics")
54 setwd(workdir)
55
56 if (outputlog){
57 sinklog <- file(log, open = "wt")
58 sink(sinklog ,type = "output")
59 sink(sinklog, type = "message")
60 }
61
62 CN=read.table(input,header=TRUE,check.names=FALSE)
63 drops=c("chromosome","position","probeName")
64 CNsignal=CN[,!(names(CN)%in% drops)]
65 samples=names(CNsignal)
66 CNsignalMatrix=t(data.matrix(CNsignal))
67 resp=read.table(response,header=TRUE,sep=",")
68 listOfFile=resp[[1]]
69 responseValue=resp[[2]]
70 index = match(listOfFile,rownames(CNsignalMatrix))
71 responseValueOrder=responseValue[index]
72
73 result=variableSelection(CNsignalMatrix,responseValueOrder,nbFolds=nbFolds,loss=loss,plot=TRUE)
74
75 CNsignalResult=CN[result$markers.index,(names(CN)%in% drops)]
76
77 CNsignalResult["coefficient"]=result$coefficient
78 CNsignalResult["index"]=result$markers.index
79
80 if (outputlog){
81 sink(type="output")
82 sink(type="message")
83 close(sinklog)
84 }
85
86 #sink(output)
87 #print(format(CNsignalResult),row.names=FALSE)
88 #sink()
89 write.table(CNsignalResult,output,row.names = FALSE, quote=FALSE, sep = "\t")