comparison CAMERA.r @ 9:7da9252dd983 draft

planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
author lecorguille
date Mon, 25 Apr 2016 11:06:25 -0400
parents
children 1c30ff90f3ae
comparison
equal deleted inserted replaced
8:8c5bb7b86df9 9:7da9252dd983
1 #!/usr/bin/env Rscript
2 # CAMERA.r version="2.2.1"
3
4
5
6 # ----- PACKAGE -----
7 cat("\tPACKAGE INFO\n")
8
9 setRepositories(graphics=F, ind=31)
10
11 #pkgs=c("xcms","batch")
12 pkgs=c("parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "xcms","snow","igraph","CAMERA","multtest","batch")
13 for(p in pkgs) {
14 suppressPackageStartupMessages(suppressWarnings(library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))
15 cat(p,"\t",as.character(packageVersion(p)),"\n",sep="")
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="/")) }
18
19 cat("\n\n");
20
21
22
23 # ----- ARGUMENTS -----
24 cat("\tARGUMENTS INFO\n")
25
26 listArguments = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
27 write.table(as.matrix(listArguments), col.names=F, quote=F, sep='\t')
28
29 cat("\n\n");
30
31
32 # ----- PROCESSING INFILE -----
33 cat("\tINFILE PROCESSING INFO\n")
34
35 #image is an .RData file necessary to use xset variable given by previous tools
36 if (!is.null(listArguments[["image"]])){
37 load(listArguments[["image"]]); listArguments[["image"]]=NULL
38 }
39
40 if (listArguments[["xfunction"]] %in% c("combinexsAnnos")) {
41 load(listArguments[["image_pos"]])
42 xaP=xa
43 listOFlistArgumentsP=listOFlistArguments
44 if (exists("xsAnnotate_object")) xaP=xsAnnotate_object
45
46 diffrepP=NULL
47 if (exists("diffrep")) diffrepP=diffrep
48
49 load(listArguments[["image_neg"]])
50 xaN=xa
51 listOFlistArgumentsN=listOFlistArguments
52 if (exists("xsAnnotate_object")) xaN=xsAnnotate_object
53
54 diffrepN=NULL
55 if (exists("diffrep")) diffrepN=diffrep
56 }
57
58
59 cat("\n\n")
60
61
62 # ----- ARGUMENTS PROCESSING -----
63 cat("\tARGUMENTS PROCESSING INFO\n")
64
65 # Save arguments to generate a report
66 if (!exists("listOFlistArguments")) listOFlistArguments=list()
67 listOFlistArguments[[paste(format(Sys.time(), "%y%m%d-%H:%M:%S_"),listArguments[["xfunction"]],sep="")]] = listArguments
68
69
70 #saving the commun parameters
71 thefunction = listArguments[["xfunction"]]
72 listArguments[["xfunction"]]=NULL #delete from the list of arguments
73
74 xsetRdataOutput = paste(thefunction,"RData",sep=".")
75 if (!is.null(listArguments[["xsetRdataOutput"]])){
76 xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL
77 }
78
79 rplotspdf = "Rplots.pdf"
80 if (!is.null(listArguments[["rplotspdf"]])){
81 rplotspdf = listArguments[["rplotspdf"]]; listArguments[["rplotspdf"]]=NULL
82 }
83
84 dataMatrixOutput = "dataMatrix.tsv"
85 if (!is.null(listArguments[["dataMatrixOutput"]])){
86 dataMatrixOutput = listArguments[["dataMatrixOutput"]]; listArguments[["dataMatrixOutput"]]=NULL
87 }
88
89 variableMetadataOutput = "variableMetadata.tsv"
90 if (!is.null(listArguments[["variableMetadataOutput"]])){
91 variableMetadataOutput = listArguments[["variableMetadataOutput"]]; listArguments[["variableMetadataOutput"]]=NULL
92 }
93
94 if (!is.null(listArguments[["new_file_path"]])){
95 new_file_path = listArguments[["new_file_path"]]; listArguments[["new_file_path"]]=NULL
96 }
97
98 #Import the different functions
99 source_local("lib.r")
100
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
103
104
105 if (!is.null(listArguments[["zipfile"]])){
106 zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL
107 }
108
109 # We unzip automatically the chromatograms from the zip files.
110 if (thefunction %in% c("annotatediff")) {
111 if(exists("zipfile") && (zipfile!="")) {
112 if(!file.exists(zipfile)){
113 error_message=paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!")
114 print(error_message)
115 stop(error_message)
116 }
117
118 #unzip
119 suppressWarnings(unzip(zipfile, unzip="unzip"))
120
121 #get the directory name
122 filesInZip=unzip(zipfile, list=T);
123 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1])));
124 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir]
125 directory = "."
126 if (length(directories) == 1) directory = directories
127
128 cat("files_root_directory\t",directory,"\n")
129 }
130 }
131
132
133
134 #addition of xset object to the list of arguments in the first position
135 if (exists("xset") != 0){
136 listArguments=append(list(xset), listArguments)
137 }
138
139 cat("\n\n")
140
141
142
143
144 # ----- PROCESSING INFO -----
145 cat("\tMAIN PROCESSING INFO\n")
146
147 #change the default display settings
148 pdf(file=rplotspdf, width=16, height=12)
149
150
151 if (thefunction %in% c("annotatediff")) {
152 results_list=annotatediff(xset=xset,listArguments=listArguments,variableMetadataOutput=variableMetadataOutput,dataMatrixOutput=dataMatrixOutput,new_file_path=new_file_path)
153 xa=results_list[["xa"]]
154 diffrep=results_list[["diffrep"]]
155 variableMetadata=results_list[["variableMetadata"]]
156
157 cat("\n\n")
158 cat("\tXSET OBJECT INFO\n")
159 print(xa)
160 }
161
162 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)
164 }
165
166 dev.off()
167
168
169 #saving R data in .Rdata file to save the variables used in the present tool
170 objects2save = c("xa","variableMetadata","diffrep","cAnnot","listOFlistArguments","zipfile")
171 save(list=objects2save[objects2save %in% ls()], file=xsetRdataOutput)
172
173 cat("\n\n")
174
175 cat("\tDONE\n")