Mercurial > repos > sblanck > mpagenomics
comparison preprocess.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("--summary",type="character",default=NULL, dest="summary"), | |
13 make_option("--dataSetName",type="character",default=NULL, dest="dataSetName"), | |
14 make_option("--new_file_path",type="character",default=NULL, dest="new_file_path"), | |
15 make_option("--inputcdffull_name",type="character",default=NULL, dest="inputcdffull_name"), | |
16 make_option("--inputufl_name",type="character",default=NULL, dest="inputufl_name"), | |
17 make_option("--inputugp_name",type="character",default=NULL, dest="inputugp_name"), | |
18 make_option("--inputacs_name",type="character",default=NULL, dest="inputacs_name"), | |
19 make_option("--inputcdffull",type="character",default=NULL, dest="inputcdffull"), | |
20 make_option("--inputufl",type="character",default=NULL, dest="inputufl"), | |
21 make_option("--inputugp",type="character",default=NULL, dest="inputugp"), | |
22 make_option("--inputacs",type="character",default=NULL, dest="inputacs"), | |
23 make_option("--tumorcsv",type="character",default=NULL, dest="tumorcsv"), | |
24 make_option("--settingsType",type="character",default=NULL, dest="settingsType"), | |
25 make_option("--outputgraph",type="character",default=NULL, dest="outputgraph"), | |
26 make_option("--zipfigures",type="character",default=NULL, dest="zipfigures"), | |
27 make_option("--outputlog",type="character",default=NULL, dest="outputlog"), | |
28 make_option("--log",type="character",default=NULL, dest="log"), | |
29 make_option("--user_id",type="character",default=NULL, dest="user_id"), | |
30 make_option("--input",type="character",default=NULL, dest="input") | |
31 ); | |
32 | |
33 opt_parser = OptionParser(option_list=option_list); | |
34 opt = parse_args(opt_parser); | |
35 | |
36 if(is.null(opt$input)){ | |
37 print_help(opt_parser) | |
38 stop("input required.", call.=FALSE) | |
39 } | |
40 | |
41 #loading libraries | |
42 | |
43 summary=opt$summary | |
44 dataSetName=opt$dataSetName | |
45 newFilePath=opt$new_file_path | |
46 inputCDFName=opt$inputcdffull_name | |
47 inputUFLName=opt$inputufl_name | |
48 inputUGPName=opt$inputugp_name | |
49 inputACSName=opt$inputacs_name | |
50 inputCDF=opt$inputcdffull | |
51 inputUFL=opt$inputufl | |
52 inputUGP=opt$inputugp | |
53 inputACS=opt$inputacs | |
54 tumorcsv=opt$tumorcsv | |
55 settingsType=opt$settingsType | |
56 outputGraph=opt$outputgraph | |
57 zipfigures=opt$zipfigures | |
58 outputlog=opt$outputlog | |
59 log=opt$log | |
60 userId=opt$user_id | |
61 | |
62 destinationPath=file.path(newFilePath, userId, dataSetName) | |
63 mpagenomicsDir = file.path(newFilePath,"mpagenomics",userId) | |
64 dataDir = file.path(newFilePath, userId) | |
65 chipDir = file.path(newFilePath,"mpagenomics",userId,"annotationData","chipTypes") | |
66 createArchitecture=TRUE | |
67 | |
68 if (dir.exists(chipDir)) | |
69 system(paste0("rm -r ", chipDir)) | |
70 | |
71 if (!dir.exists(mpagenomicsDir)) | |
72 dir.create(mpagenomicsDir, showWarnings = TRUE, recursive = TRUE) | |
73 | |
74 if (!dir.exists(dataDir)) | |
75 dir.create(dataDir, showWarnings = TRUE, recursive = TRUE) | |
76 | |
77 listInput <- trimws( unlist( strsplit(trimws(opt$input), ",") ) ) | |
78 if(length(listInput)<2){ | |
79 stop("To few .CEL files selected : At least 2 .CEL files are required", call.=FALSE) | |
80 } | |
81 | |
82 | |
83 celList=vector() | |
84 celFileNameList=vector() | |
85 | |
86 for (i in 1:length(listInput)) | |
87 { | |
88 inputFileInfo <- unlist( strsplit( listInput[i], ';' ) ) | |
89 celList=c(celList,inputFileInfo[1]) | |
90 celFileNameList=c(celFileNameList,inputFileInfo[2]) | |
91 } | |
92 | |
93 | |
94 for (i in 1:length(celFileNameList)) | |
95 { | |
96 source = celList[i] | |
97 destination=file.path(dataDir,celFileNameList[i]) | |
98 file.copy(source, destination) | |
99 } | |
100 split=unlist(strsplit(inputCDFName,",",fixed=TRUE)) | |
101 tag=NULL | |
102 if (length(split) != 0) { | |
103 chipType=split[1] | |
104 tagExt=split[2] | |
105 tag=unlist(strsplit(tagExt,".",fixed=TRUE))[1] | |
106 } else { | |
107 chipType=split[1] | |
108 } | |
109 | |
110 if(!file.exists(file.path(dataDir,inputCDFName))) | |
111 file.symlink(inputCDF,file.path(dataDir,inputCDFName)) | |
112 if(!file.exists(file.path(dataDir,inputACSName))) | |
113 file.symlink(inputACS,file.path(dataDir,inputACSName)) | |
114 if(!file.exists(file.path(dataDir,inputUFLName))) | |
115 file.symlink(inputUFL,file.path(dataDir,inputUFLName)) | |
116 if(!file.exists(file.path(dataDir,inputUGPName))) | |
117 file.symlink(inputUGP,file.path(dataDir,inputUGPName)) | |
118 | |
119 fig_dir = file.path("mpagenomics", userId, "figures", dataSetName, "signal") | |
120 abs_fig_dir = file.path(newFilePath, fig_dir) | |
121 | |
122 chip=chipType | |
123 dataset=dataSetName | |
124 workdir=mpagenomicsDir | |
125 celPath=dataDir | |
126 chipPath=dataDir | |
127 tumor=tumorcsv | |
128 outputgraph=type.convert(outputGraph) | |
129 | |
130 | |
131 library(MPAgenomics) | |
132 setwd(workdir) | |
133 | |
134 if (outputlog){ | |
135 sinklog <- file(log, open = "wt") | |
136 sink(sinklog ,type = "output") | |
137 sink(sinklog, type = "message") | |
138 } | |
139 | |
140 if (settingsType=="standard") | |
141 { | |
142 signalPreProcess(dataSetName=dataset, chipType=chip, dataSetPath=celPath,chipFilesPath=chipPath, path=workdir,createArchitecture=createArchitecture, savePlot=outputgraph, tags=tag) | |
143 } else { | |
144 signalPreProcess(dataSetName=dataset, chipType=chip, dataSetPath=celPath,chipFilesPath=chipPath, normalTumorArray=tumor, path=workdir,createArchitecture=createArchitecture, savePlot=outputgraph, tags=tag) | |
145 } | |
146 setwd(abs_fig_dir) | |
147 files2zip <- dir(abs_fig_dir) | |
148 zip(zipfile = "figures.zip", files = files2zip) | |
149 file.rename("figures.zip",zipfigures) | |
150 summarydf=data.frame(celFileNameList,rep(dataSetName,length(celFileNameList)),rep(chipType,length(celFileNameList))) | |
151 write.table(summarydf,file=summary,quote=FALSE,row.names=FALSE,col.names=FALSE,sep="\t") | |
152 | |
153 if (outputlog){ | |
154 sink(type="output") | |
155 sink(type="message") | |
156 close(sinklog) | |
157 } | |
158 |