Mercurial > repos > lecorguille > camera_annotate
comparison CAMERA.r @ 9:c02d80efba80 draft
planemo upload commit d8cc436fd91f5748dc396d0527a0a303d3221835
author | lecorguille |
---|---|
date | Sun, 10 Apr 2016 08:14:59 -0400 |
parents | |
children | d33e0ed5f32a |
comparison
equal
deleted
inserted
replaced
8:821f2d271ea8 | 9:c02d80efba80 |
---|---|
1 #!/usr/bin/env Rscript | |
2 # CAMERA.r version="2.2.1" | |
3 | |
4 | |
5 | |
6 # ----- PACKAGE ----- | |
7 cat("\tPACKAGE INFO\n") | |
8 | |
9 #pkgs=c("xcms","batch") | |
10 pkgs=c("parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "tcltk","igraph", "xcms","snow","CAMERA","multtest","batch") | |
11 for(p in pkgs) { | |
12 suppressPackageStartupMessages(suppressWarnings(library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE))) | |
13 cat(p,"\t",as.character(packageVersion(p)),"\n",sep="") | |
14 } | |
15 source_local <- function(fname){ argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | |
16 | |
17 cat("\n\n"); | |
18 | |
19 | |
20 | |
21 # ----- ARGUMENTS ----- | |
22 cat("\tARGUMENTS INFO\n") | |
23 | |
24 listArguments = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | |
25 write.table(as.matrix(listArguments), col.names=F, quote=F, sep='\t') | |
26 | |
27 cat("\n\n"); | |
28 | |
29 | |
30 # ----- PROCESSING INFILE ----- | |
31 cat("\tINFILE PROCESSING INFO\n") | |
32 | |
33 #image is an .RData file necessary to use xset variable given by previous tools | |
34 if (!is.null(listArguments[["image"]])){ | |
35 load(listArguments[["image"]]); listArguments[["image"]]=NULL | |
36 } | |
37 | |
38 if (listArguments[["xfunction"]] %in% c("combinexsAnnos")) { | |
39 load(listArguments[["image_pos"]]) | |
40 xaP=xa | |
41 if (exists("xsAnnotate_object")) xaP=xsAnnotate_object | |
42 | |
43 diffrepP=NULL | |
44 if (exists("diffrep")) diffrepP=diffrep | |
45 | |
46 load(listArguments[["image_neg"]]) | |
47 xaN=xa | |
48 if (exists("xsAnnotate_object")) xaN=xsAnnotate_object | |
49 | |
50 diffrepN=NULL | |
51 if (exists("diffrep")) diffrepN=diffrep | |
52 } | |
53 | |
54 | |
55 cat("\n\n") | |
56 | |
57 | |
58 # ----- ARGUMENTS PROCESSING ----- | |
59 cat("\tARGUMENTS PROCESSING INFO\n") | |
60 | |
61 # Save arguments to generate a report | |
62 if (!exists("listOFlistArguments")) listOFlistArguments=list() | |
63 listOFlistArguments[[paste(format(Sys.time(), "%y%m%d-%H:%M:%S_"),listArguments[["xfunction"]],sep="")]] = listArguments | |
64 | |
65 | |
66 #saving the commun parameters | |
67 thefunction = listArguments[["xfunction"]] | |
68 listArguments[["xfunction"]]=NULL #delete from the list of arguments | |
69 | |
70 xsetRdataOutput = paste(thefunction,"RData",sep=".") | |
71 if (!is.null(listArguments[["xsetRdataOutput"]])){ | |
72 xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL | |
73 } | |
74 | |
75 rplotspdf = "Rplots.pdf" | |
76 if (!is.null(listArguments[["rplotspdf"]])){ | |
77 rplotspdf = listArguments[["rplotspdf"]]; listArguments[["rplotspdf"]]=NULL | |
78 } | |
79 | |
80 dataMatrixOutput = "dataMatrix.tsv" | |
81 if (!is.null(listArguments[["dataMatrixOutput"]])){ | |
82 dataMatrixOutput = listArguments[["dataMatrixOutput"]]; listArguments[["dataMatrixOutput"]]=NULL | |
83 } | |
84 | |
85 variableMetadataOutput = "variableMetadata.tsv" | |
86 if (!is.null(listArguments[["variableMetadataOutput"]])){ | |
87 variableMetadataOutput = listArguments[["variableMetadataOutput"]]; listArguments[["variableMetadataOutput"]]=NULL | |
88 } | |
89 | |
90 if (!is.null(listArguments[["new_file_path"]])){ | |
91 new_file_path = listArguments[["new_file_path"]]; listArguments[["new_file_path"]]=NULL | |
92 } | |
93 | |
94 #Import the different functions | |
95 source_local("lib.r") | |
96 | |
97 # We unzip automatically the chromatograms from the zip files. | |
98 if (thefunction == "annotatediff") { | |
99 if(exists("zipfile") && (zipfile!="")) { | |
100 suppressWarnings(unzip(zipfile, unzip="unzip")) | |
101 } | |
102 } | |
103 | |
104 | |
105 #addition of xset object to the list of arguments in the first position | |
106 if (exists("xset") != 0){ | |
107 listArguments=append(list(xset), listArguments) | |
108 } | |
109 | |
110 cat("\n\n") | |
111 | |
112 | |
113 | |
114 | |
115 # ----- PROCESSING INFO ----- | |
116 cat("\tMAIN PROCESSING INFO\n") | |
117 | |
118 #change the default display settings | |
119 pdf(file=rplotspdf, width=16, height=12) | |
120 | |
121 | |
122 if (thefunction %in% c("annotatediff")) { | |
123 results_list=annotatediff(xset=xset,listArguments=listArguments,variableMetadataOutput=variableMetadataOutput,dataMatrixOutput=dataMatrixOutput,new_file_path=new_file_path) | |
124 xa=results_list[["xa"]] | |
125 diffrep=results_list[["diffrep"]] | |
126 variableMetadata=results_list[["variableMetadata"]] | |
127 | |
128 cat("\n\n") | |
129 cat("\tXSET OBJECT INFO\n") | |
130 print(xa) | |
131 } | |
132 | |
133 if (thefunction %in% c("combinexsAnnos")) { | |
134 cAnnot=combinexsAnnos_function(xaP=xaP,xaN=xaN,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) | |
135 } | |
136 | |
137 dev.off() | |
138 | |
139 | |
140 #saving R data in .Rdata file to save the variables used in the present tool | |
141 objects2save = c("xa","variableMetadata","diffrep","cAnnot","listOFlistArguments","zipfile") | |
142 save(list=objects2save[objects2save %in% ls()], file=xsetRdataOutput) | |
143 | |
144 cat("\n\n") | |
145 | |
146 cat("\tDONE\n") |