Mercurial > repos > sblanck > mpagenomics
annotate filter.R @ 6:7076911e5c64 draft default tip
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit a644ed69951bcc1ac46426c5e6c9a0af1003a9a8-dirty"
author | sblanck |
---|---|
date | Tue, 20 Apr 2021 15:00:42 +0000 |
parents | 3fcbb8030fcc |
children |
rev | line source |
---|---|
0
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
1 #!/usr/bin/env Rscript |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
2 # setup R error handling to go to stderr |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
3 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
4 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
5 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
6 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
7 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
8 library("optparse") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
9 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
10 ##### Read options |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
11 option_list=list( |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
12 make_option("--input",type="character",default=NULL, dest="input"), |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
13 make_option("--output",type="character",default=NULL, dest="output"), |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
14 make_option("--new_file_path",type="character",default=NULL, dest="new_file_path"), |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
15 make_option("--nbcall",type="character",default=NULL, dest="nbcall"), |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
16 make_option("--length",type="character",default=NULL, dest="length"), |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
17 make_option("--probes",type="character",default=NULL, dest="probes"), |
4
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
18 make_option("--settings_signal",type="character",default=NULL, dest="settings_signal"), |
0
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
19 make_option("--outputlog",type="character",default=NULL, dest="outputlog"), |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
20 make_option("--log",type="character",default=NULL, dest="log") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
21 ); |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
22 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
23 opt_parser = OptionParser(option_list=option_list); |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
24 opt = parse_args(opt_parser); |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
25 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
26 if(is.null(opt$input)){ |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
27 print_help(opt_parser) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
28 stop("input required.", call.=FALSE) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
29 } |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
30 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
31 #loading libraries |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
32 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
33 input=opt$input |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
34 output=opt$output |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
35 tmp_dir=opt$new_file_path |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
36 nbcall=opt$nbcall |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
37 length=as.numeric(opt$length) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
38 probes=as.numeric(opt$probes) |
4
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
39 signal=opt$settings_signal |
0
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
40 log=opt$log |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
41 outputlog=opt$outputlog |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
42 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
43 if (outputlog){ |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
44 sinklog <- file(log, open = "wt") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
45 sink(sinklog ,type = "output") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
46 sink(sinklog, type = "message") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
47 } |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
48 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
49 nbcall_tmp <- strsplit(nbcall,",") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
50 nbcall_vecstring <-unlist(nbcall_tmp) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
51 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
52 library(MPAgenomics) |
4
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
53 workdir=file.path(tmp_dir) |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
54 if (!dir.exists(workdir)) |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
55 dir.create(workdir, showWarnings = TRUE, recursive = TRUE) |
0
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
56 setwd(workdir) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
57 |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
58 segcall = read.table(input, header = TRUE) |
4
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
59 if (signal=="fracB") { |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
60 segcall=cbind(segcall,calls=rep("normal",nrow(segcall))) |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
61 filtercall=filterSeg(segcall,length,probes,nbcall_vecstring) |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
62 filtercall=filtercall[,1:(ncol(filtercall)-1)] |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
63 } else { |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
64 filtercall=filterSeg(segcall,length,probes,nbcall_vecstring) |
3fcbb8030fcc
"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
sblanck
parents:
0
diff
changeset
|
65 } |
0
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
66 #sink(output) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
67 #print(format(filtercall),row.names=FALSE) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
68 #sink() |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
69 if (outputlog){ |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
70 sink(type="output") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
71 sink(type="message") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
72 close(sinklog) |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
73 } |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
74 write.table(filtercall,output,row.names = FALSE, quote = FALSE, sep = "\t") |
4d539083cf7f
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233-dirty
sblanck
parents:
diff
changeset
|
75 |