Mercurial > repos > lecorguille > camera_annotate
comparison CAMERA.r @ 25:230f0bc9e792 draft
planemo upload commit a634879c0e651eb0eb7b435a107ee40cf30524fa
author | lecorguille |
---|---|
date | Fri, 10 Feb 2017 11:11:27 -0500 |
parents | 77a191e37af4 |
children | 04e32b9a5486 |
comparison
equal
deleted
inserted
replaced
24:10176a940ec6 | 25:230f0bc9e792 |
---|---|
9 setRepositories(graphics=F, ind=31) | 9 setRepositories(graphics=F, ind=31) |
10 | 10 |
11 #pkgs=c("xcms","batch") | 11 #pkgs=c("xcms","batch") |
12 pkgs=c("parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "xcms","snow","igraph","CAMERA","multtest","batch") | 12 pkgs=c("parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "xcms","snow","igraph","CAMERA","multtest","batch") |
13 for(p in pkgs) { | 13 for(p in pkgs) { |
14 suppressPackageStartupMessages(suppressWarnings(library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE))) | 14 suppressPackageStartupMessages(suppressWarnings(library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE))) |
15 cat(p,"\t",as.character(packageVersion(p)),"\n",sep="") | 15 cat(p,"\t",as.character(packageVersion(p)),"\n",sep="") |
16 } | 16 } |
17 source_local <- function(fname){ argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | 17 source_local <- function(fname){ argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } |
18 | 18 |
19 cat("\n\n"); | 19 cat("\n\n"); |
20 | 20 |
21 | 21 |
22 | 22 |
23 # ----- ARGUMENTS ----- | 23 # ----- ARGUMENTS ----- |
24 cat("\tARGUMENTS INFO\n") | 24 cat("\tARGUMENTS INFO\n") |
32 # ----- PROCESSING INFILE ----- | 32 # ----- PROCESSING INFILE ----- |
33 cat("\tINFILE PROCESSING INFO\n") | 33 cat("\tINFILE PROCESSING INFO\n") |
34 | 34 |
35 #image is an .RData file necessary to use xset variable given by previous tools | 35 #image is an .RData file necessary to use xset variable given by previous tools |
36 if (!is.null(listArguments[["image"]])){ | 36 if (!is.null(listArguments[["image"]])){ |
37 load(listArguments[["image"]]); listArguments[["image"]]=NULL | 37 load(listArguments[["image"]]); listArguments[["image"]]=NULL |
38 } | 38 } |
39 | 39 |
40 if (listArguments[["xfunction"]] %in% c("combinexsAnnos")) { | 40 if (listArguments[["xfunction"]] %in% c("combinexsAnnos")) { |
41 load(listArguments[["image_pos"]]) | 41 load(listArguments[["image_pos"]]) |
42 xaP=xa | 42 xaP=xa |
43 listOFlistArgumentsP=listOFlistArguments | 43 listOFlistArgumentsP=listOFlistArguments |
44 if (exists("xsAnnotate_object")) xaP=xsAnnotate_object | 44 if (exists("xsAnnotate_object")) xaP=xsAnnotate_object |
45 | 45 |
46 diffrepP=NULL | 46 diffrepP=NULL |
47 if (exists("diffrep")) diffrepP=diffrep | 47 if (exists("diffrep")) diffrepP=diffrep |
48 | 48 |
49 load(listArguments[["image_neg"]]) | 49 load(listArguments[["image_neg"]]) |
50 xaN=xa | 50 xaN=xa |
51 listOFlistArgumentsN=listOFlistArguments | 51 listOFlistArgumentsN=listOFlistArguments |
52 if (exists("xsAnnotate_object")) xaN=xsAnnotate_object | 52 if (exists("xsAnnotate_object")) xaN=xsAnnotate_object |
53 | 53 |
54 diffrepN=NULL | 54 diffrepN=NULL |
55 if (exists("diffrep")) diffrepN=diffrep | 55 if (exists("diffrep")) diffrepN=diffrep |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 cat("\n\n") | 59 cat("\n\n") |
60 | 60 |
71 thefunction = listArguments[["xfunction"]] | 71 thefunction = listArguments[["xfunction"]] |
72 listArguments[["xfunction"]]=NULL #delete from the list of arguments | 72 listArguments[["xfunction"]]=NULL #delete from the list of arguments |
73 | 73 |
74 xsetRdataOutput = paste(thefunction,"RData",sep=".") | 74 xsetRdataOutput = paste(thefunction,"RData",sep=".") |
75 if (!is.null(listArguments[["xsetRdataOutput"]])){ | 75 if (!is.null(listArguments[["xsetRdataOutput"]])){ |
76 xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL | 76 xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL |
77 } | 77 } |
78 | 78 |
79 rplotspdf = "Rplots.pdf" | 79 rplotspdf = "Rplots.pdf" |
80 if (!is.null(listArguments[["rplotspdf"]])){ | 80 if (!is.null(listArguments[["rplotspdf"]])){ |
81 rplotspdf = listArguments[["rplotspdf"]]; listArguments[["rplotspdf"]]=NULL | 81 rplotspdf = listArguments[["rplotspdf"]]; listArguments[["rplotspdf"]]=NULL |
82 } | 82 } |
83 | 83 |
84 dataMatrixOutput = "dataMatrix.tsv" | 84 dataMatrixOutput = "dataMatrix.tsv" |
85 if (!is.null(listArguments[["dataMatrixOutput"]])){ | 85 if (!is.null(listArguments[["dataMatrixOutput"]])){ |
86 dataMatrixOutput = listArguments[["dataMatrixOutput"]]; listArguments[["dataMatrixOutput"]]=NULL | 86 dataMatrixOutput = listArguments[["dataMatrixOutput"]]; listArguments[["dataMatrixOutput"]]=NULL |
87 } | 87 } |
88 | 88 |
89 variableMetadataOutput = "variableMetadata.tsv" | 89 variableMetadataOutput = "variableMetadata.tsv" |
90 if (!is.null(listArguments[["variableMetadataOutput"]])){ | 90 if (!is.null(listArguments[["variableMetadataOutput"]])){ |
91 variableMetadataOutput = listArguments[["variableMetadataOutput"]]; listArguments[["variableMetadataOutput"]]=NULL | 91 variableMetadataOutput = listArguments[["variableMetadataOutput"]]; listArguments[["variableMetadataOutput"]]=NULL |
92 } | 92 } |
93 | 93 |
94 if (!is.null(listArguments[["new_file_path"]])){ | 94 if (!is.null(listArguments[["new_file_path"]])){ |
95 new_file_path = listArguments[["new_file_path"]]; listArguments[["new_file_path"]]=NULL | 95 new_file_path = listArguments[["new_file_path"]]; listArguments[["new_file_path"]]=NULL |
96 } | 96 } |
97 | 97 |
98 #Import the different functions | 98 #Import the different functions |
99 source_local("lib.r") | 99 source_local("lib.r") |
100 | 100 |
101 #necessary to unzip .zip file uploaded to Galaxy | 101 #necessary to unzip .zip file uploaded to Galaxy |
102 #thanks to .zip file it's possible to upload many file as the same time conserving the tree hierarchy of directories | 102 #thanks to .zip file it's possible to upload many file as the same time conserving the tree hierarchy of directories |
103 | 103 |
104 | |
105 if (!is.null(listArguments[["zipfile"]])){ | 104 if (!is.null(listArguments[["zipfile"]])){ |
106 zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL | 105 zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL |
106 } | |
107 | |
108 if (!is.null(listArguments[["singlefile_galaxyPath"]])){ | |
109 singlefile_galaxyPaths = unlist(strsplit(listArguments[["singlefile_galaxyPath"]],",")); listArguments[["singlefile_galaxyPath"]]=NULL | |
110 singlefile_sampleNames = unlist(strsplit(listArguments[["singlefile_sampleName"]],",")); listArguments[["singlefile_sampleName"]]=NULL | |
111 | |
112 singlefile=NULL | |
113 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) { | |
114 singlefile_galaxyPath=singlefile_galaxyPaths[singlefile_galaxyPath_i] | |
115 singlefile_sampleName=singlefile_sampleNames[singlefile_galaxyPath_i] | |
116 singlefile[[singlefile_sampleName]] = singlefile_galaxyPath | |
117 } | |
107 } | 118 } |
108 | 119 |
109 # We unzip automatically the chromatograms from the zip files. | 120 # We unzip automatically the chromatograms from the zip files. |
110 if (thefunction %in% c("annotatediff")) { | 121 if (thefunction %in% c("annotatediff")) { |
111 if(exists("zipfile") && (zipfile!="")) { | 122 if(exists("singlefile") && (length("singlefile")>0)) { |
112 if(!file.exists(zipfile)){ | 123 for (singlefile_sampleName in names(singlefile)) { |
113 error_message=paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!") | 124 singlefile_galaxyPath = singlefile[[singlefile_sampleName]] |
114 print(error_message) | 125 if(!file.exists(singlefile_galaxyPath)){ |
115 stop(error_message) | 126 error_message=paste("Cannot access the sample:",singlefile_sampleName,"located:",singlefile_galaxyPath,". Please, contact your administrator ... if you have one!") |
127 print(error_message); stop(error_message) | |
128 } | |
129 | |
130 file.symlink(singlefile_galaxyPath,singlefile_sampleName) | |
131 } | |
132 directory = "." | |
133 | |
134 | |
116 } | 135 } |
117 | 136 if(exists("zipfile") && (zipfile!="")) { |
118 #unzip | 137 if(!file.exists(zipfile)){ |
119 suppressWarnings(unzip(zipfile, unzip="unzip")) | 138 error_message=paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!") |
120 | 139 print(error_message) |
121 #get the directory name | 140 stop(error_message) |
122 filesInZip=unzip(zipfile, list=T); | 141 } |
123 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1]))); | 142 |
124 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir] | 143 #list all file in the zip file |
125 directory = "." | 144 #zip_files=unzip(zipfile,list=T)[,"Name"] |
126 if (length(directories) == 1) directory = directories | 145 |
127 | 146 #unzip |
128 cat("files_root_directory\t",directory,"\n") | 147 suppressWarnings(unzip(zipfile, unzip="unzip")) |
129 } | 148 |
130 } | 149 #get the directory name |
131 | 150 filesInZip=unzip(zipfile, list=T); |
151 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1]))); | |
152 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir] | |
153 directory = "." | |
154 if (length(directories) == 1) directory = directories | |
155 | |
156 cat("files_root_directory\t",directory,"\n") | |
157 | |
158 } | |
159 } | |
132 | 160 |
133 | 161 |
134 #addition of xset object to the list of arguments in the first position | 162 #addition of xset object to the list of arguments in the first position |
135 if (exists("xset") != 0){ | 163 if (exists("xset") != 0){ |
136 listArguments=append(list(xset), listArguments) | 164 listArguments=append(list(xset), listArguments) |
137 } | 165 } |
138 | 166 |
139 cat("\n\n") | 167 cat("\n\n") |
140 | 168 |
141 | 169 |
147 #change the default display settings | 175 #change the default display settings |
148 pdf(file=rplotspdf, width=16, height=12) | 176 pdf(file=rplotspdf, width=16, height=12) |
149 | 177 |
150 | 178 |
151 if (thefunction %in% c("annotatediff")) { | 179 if (thefunction %in% c("annotatediff")) { |
152 results_list=annotatediff(xset=xset,listArguments=listArguments,variableMetadataOutput=variableMetadataOutput,dataMatrixOutput=dataMatrixOutput,new_file_path=new_file_path) | 180 results_list=annotatediff(xset=xset,listArguments=listArguments,variableMetadataOutput=variableMetadataOutput,dataMatrixOutput=dataMatrixOutput,new_file_path=new_file_path) |
153 xa=results_list[["xa"]] | 181 xa=results_list[["xa"]] |
154 diffrep=results_list[["diffrep"]] | 182 diffrep=results_list[["diffrep"]] |
155 variableMetadata=results_list[["variableMetadata"]] | 183 variableMetadata=results_list[["variableMetadata"]] |
156 | 184 |
157 cat("\n\n") | 185 cat("\n\n") |
158 cat("\tXSET OBJECT INFO\n") | 186 cat("\tXSET OBJECT INFO\n") |
159 print(xa) | 187 print(xa) |
160 } | 188 } |
161 | 189 |
162 if (thefunction %in% c("combinexsAnnos")) { | 190 if (thefunction %in% c("combinexsAnnos")) { |
163 cAnnot=combinexsAnnos_function(xaP=xaP,xaN=xaN,listOFlistArgumentsP=listOFlistArgumentsP,listOFlistArgumentsN=listOFlistArgumentsN,diffrepP=diffrepP,diffrepN=diffrepN,convert_param=listArguments[["convert_param"]],pos=listArguments[["pos"]],tol=listArguments[["tol"]],ruleset=listArguments[["ruleset"]],keep_meta=listArguments[["keep_meta"]],variableMetadataOutput=variableMetadataOutput) | 191 cAnnot=combinexsAnnos_function( |
192 xaP=xaP,xaN=xaN, | |
193 listOFlistArgumentsP=listOFlistArgumentsP,listOFlistArgumentsN=listOFlistArgumentsN, | |
194 diffrepP=diffrepP,diffrepN=diffrepN, | |
195 pos=listArguments[["pos"]],tol=listArguments[["tol"]],ruleset=listArguments[["ruleset"]],keep_meta=listArguments[["keep_meta"]], | |
196 intval=listArguments[["intval"]], convertRTMinute=listArguments[["convertRTMinute"]], numDigitsMZ=listArguments[["numDigitsMZ"]], numDigitsRT=listArguments[["numDigitsRT"]], | |
197 variableMetadataOutput=variableMetadataOutput | |
198 ) | |
164 } | 199 } |
165 | 200 |
166 dev.off() | 201 dev.off() |
167 | 202 |
168 | 203 |