comparison filter.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("--nbcall",type="character",default=NULL, dest="nbcall"),
16 make_option("--length",type="character",default=NULL, dest="length"),
17 make_option("--probes",type="character",default=NULL, dest="probes"),
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 input=opt$input
33 output=opt$output
34 tmp_dir=opt$new_file_path
35 nbcall=opt$nbcall
36 length=as.numeric(opt$length)
37 probes=as.numeric(opt$probes)
38 log=opt$log
39 outputlog=opt$outputlog
40
41 if (outputlog){
42 sinklog <- file(log, open = "wt")
43 sink(sinklog ,type = "output")
44 sink(sinklog, type = "message")
45 }
46
47 nbcall_tmp <- strsplit(nbcall,",")
48 nbcall_vecstring <-unlist(nbcall_tmp)
49
50 nbcall_vecstring
51
52 library(MPAgenomics)
53 workdir=file.path(tmp_dir, "mpagenomics")
54 setwd(workdir)
55
56 segcall = read.table(input, header = TRUE)
57 filtercall=filterSeg(segcall,length,probes,nbcall_vecstring)
58 #sink(output)
59 #print(format(filtercall),row.names=FALSE)
60 #sink()
61 if (outputlog){
62 sink(type="output")
63 sink(type="message")
64 close(sinklog)
65 }
66 write.table(filtercall,output,row.names = FALSE, quote = FALSE, sep = "\t")
67