Mercurial > repos > sblanck > mpagenomics_wrappers
comparison segmentFracB.R @ 8:d5ed62b4d3ac draft default tip
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233
author | sblanck |
---|---|
date | Tue, 12 May 2020 13:40:07 +0000 |
parents | af4f63f27c77 |
children |
comparison
equal
deleted
inserted
replaced
7:f2d24110f65a | 8:d5ed62b4d3ac |
---|---|
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("--chrom",type="character",default=NULL, dest="chrom"), | |
13 make_option("--input",type="character",default=NULL, dest="input"), | |
14 make_option("--output",type="character",default=NULL, dest="output"), | |
15 make_option("--new_file_path",type="character",default=NULL, dest="new_file_path"), | |
16 make_option("--settings_type",type="character",default=NULL, dest="settingsType"), | |
17 make_option("--output_graph",type="character",default=NULL, dest="outputgraph"), | |
18 make_option("--zip_figures",type="character",default=NULL, dest="zipfigures"), | |
19 make_option("--settings_tumor",type="character",default=NULL, dest="settingsTypeTumor"), | |
20 make_option("--outputlog",type="character",default=NULL, dest="outputlog"), | |
21 make_option("--log",type="character",default=NULL, dest="log"), | |
22 make_option("--userid",type="character",default=NULL, dest="userid"), | |
23 make_option("--method",type="character",default=NULL, dest="method") | |
24 ); | |
25 | |
26 opt_parser = OptionParser(option_list=option_list); | |
27 opt = parse_args(opt_parser); | |
28 | |
29 if(is.null(opt$input)){ | |
30 print_help(opt_parser) | |
31 stop("input required.", call.=FALSE) | |
32 } | |
33 | |
34 #loading libraries | |
35 | |
1 args<-commandArgs(TRUE) | 36 args<-commandArgs(TRUE) |
2 | 37 |
3 chrom=args[1] | 38 chrom=opt$chrom |
4 dataset=args[2] | 39 datasetFile=opt$input |
5 output=args[3] | 40 output=opt$output |
6 tmp_dir=args[4] | 41 tmp_dir=opt$new_file_path |
7 input=args[5] | 42 input=opt$settingsType |
8 outputfigures=type.convert(args[6]) | 43 outputfigures=type.convert(opt$outputgraph) |
9 tumorcsv=args[7] | 44 tumorcsv=opt$settingsTypeTumor |
10 user=args[8] | 45 user=opt$userid |
11 method=args[9] | 46 method=opt$method |
47 log=opt$log | |
48 outputlog=opt$outputlog | |
49 outputgraph=opt$outputgraph | |
50 zipfigures=opt$zipfigures | |
51 | |
52 #chrom=opt$chrom | |
53 #datasetFile=opt$input | |
54 #output=opt$output | |
55 #tmp_dir=opt$new_file_path | |
56 #nbcall=as.numeric(opt$nbcall) | |
57 #settingsType=opt$settingsType | |
58 #outputfigures=type.convert(opt$outputgraph) | |
59 #snp=type.convert(opt$snp) | |
60 #tumorcsv=opt$settingsTypeTumor | |
61 #cellularity=as.numeric(opt$cellularity) | |
62 #user=opt$userid | |
63 #method=opt$method | |
64 #log=opt$log | |
65 #outputlog=opt$outputlog | |
66 #outputgraph=opt$outputgraph | |
67 #zipfigures=opt$zipfigures | |
12 | 68 |
13 library(MPAgenomics) | 69 library(MPAgenomics) |
14 workdir=file.path(tmp_dir, "mpagenomics",user) | 70 workdir=file.path(tmp_dir, "mpagenomics",user) |
15 setwd(workdir) | 71 setwd(workdir) |
16 | 72 |
20 chrom_tmp <- strsplit(chrom,",") | 76 chrom_tmp <- strsplit(chrom,",") |
21 chrom_vecstring <-unlist(chrom_tmp) | 77 chrom_vecstring <-unlist(chrom_tmp) |
22 chrom_vec <- as.numeric(chrom_vecstring) | 78 chrom_vec <- as.numeric(chrom_vecstring) |
23 } | 79 } |
24 | 80 |
25 input_tmp <- strsplit(input,",") | 81 |
26 input_tmp_vecstring <-unlist(input_tmp) | 82 if (outputlog){ |
83 sinklog <- file(log, open = "wt") | |
84 sink(sinklog ,type = "output") | |
85 sink(sinklog, type = "message") | |
86 } | |
27 | 87 |
28 | 88 |
29 input_vecstring = sub("^([^.]*).*", "\\1", input_tmp_vecstring) | 89 inputDataset=read.table(file=datasetFile,stringsAsFactors=FALSE) |
90 dataset=inputDataset[1,2] | |
30 | 91 |
31 if (dataset == input) { | 92 |
93 | |
94 library(MPAgenomics) | |
95 workdir=file.path(tmp_dir, "mpagenomics",user) | |
96 setwd(workdir) | |
97 | |
98 if (grepl("all",tolower(chrom)) | chrom=="None") { | |
99 chrom_vec=c(1:25) | |
100 } else { | |
101 chrom_tmp <- strsplit(chrom,",") | |
102 chrom_vecstring <-unlist(chrom_tmp) | |
103 chrom_vec <- as.numeric(chrom_vecstring) | |
104 } | |
105 | |
106 fig_dir = file.path("mpagenomics", user, "figures", dataset, "segmentation","fracB") | |
107 abs_fig_dir = file.path(tmp_dir, fig_dir) | |
108 | |
109 if (outputgraph) { | |
110 if (dir.exists(abs_fig_dir)) { | |
111 system(paste0("rm -r ", abs_fig_dir)) | |
112 } | |
113 } | |
114 | |
115 if (input == 'dataset') { | |
32 segcall=segFracBSignal(dataset,chromosome=chrom_vec, normalTumorArray=tumorcsv, savePlot=outputfigures, method=method) | 116 segcall=segFracBSignal(dataset,chromosome=chrom_vec, normalTumorArray=tumorcsv, savePlot=outputfigures, method=method) |
33 | 117 |
34 } else { | 118 } else { |
119 input_tmp <- strsplit(input,",") | |
120 input_tmp_vecstring <-unlist(input_tmp) | |
121 input_vecstring = sub("^([^.]*).*", "\\1", input_tmp_vecstring) | |
35 segcall=segFracBSignal(dataset,chromosome=chrom_vec, normalTumorArray=tumorcsv, listOfFiles=input_vecstring, savePlot=outputfigures, method=method) | 122 segcall=segFracBSignal(dataset,chromosome=chrom_vec, normalTumorArray=tumorcsv, listOfFiles=input_vecstring, savePlot=outputfigures, method=method) |
36 | 123 |
37 } | 124 } |
38 sink(output) | 125 write.table(segcall,output,row.names = FALSE, quote=FALSE, sep = "\t") |
39 print(format(segcall)) | |
40 sink() | |
41 #write.table(segcall,output,row.names = FALSE, quote=FALSE, sep = "\t") | |
42 | 126 |
43 quit() | 127 if (outputgraph) { |
128 setwd(abs_fig_dir) | |
129 files2zip <- dir(abs_fig_dir) | |
130 zip(zipfile = "figures.zip", files = files2zip) | |
131 file.rename("figures.zip",zipfigures) | |
132 } | |
133 | |
134 if (outputlog){ | |
135 sink(type="output") | |
136 sink(type="message") | |
137 close(sinklog) | |
138 } | |
139 | |
140 #sink(output) | |
141 #print(format(segcall)) | |
142 #sink() | |
143 | |
144 |