Mercurial > repos > workflow4metabolomics > metams_plot
comparison metaMS_plot.r @ 0:b60dc620bd14 draft
planemo upload for repository https://github.com/workflow4metabolomics/metaMS commit 174a1713024f246c1485cbd75218577e89353522
author | workflow4metabolomics |
---|---|
date | Wed, 03 Jul 2019 05:08:14 -0400 |
parents | |
children | 96debae917e4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b60dc620bd14 |
---|---|
1 #!/usr/bin/env Rscript | |
2 # metaMS_plot.r version="1.0.0" | |
3 #created by Yann GUITTON and updated by Julien SAINT-VANNE | |
4 | |
5 | |
6 # ----- LOG FILE ----- | |
7 #log_file <- file("log.txt", open = "wt") | |
8 #sink(log_file) | |
9 #sink(log_file, type = "output") | |
10 | |
11 | |
12 # ----- PACKAGE ----- | |
13 cat("\tSESSION INFO\n") | |
14 | |
15 #Import the different functions | |
16 source_local <- function(fname) { | |
17 argv <- commandArgs(trailingOnly = FALSE) | |
18 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | |
19 source(paste(base_dir, fname, sep="/")) | |
20 } | |
21 source_local("lib_metams.r") | |
22 | |
23 pkgs <- c("metaMS","batch") #"batch" necessary for parseCommandArgs function | |
24 loadAndDisplayPackages(pkgs) | |
25 | |
26 cat("\n") | |
27 | |
28 modNamC <- "plot_metaMS" ## module name | |
29 | |
30 cat("\nStart of the '", modNamC, "' Galaxy module call: ", format(Sys.time(), "%a %d %b %Y %X"), "\n\n", sep="") | |
31 | |
32 | |
33 # ----- ARGUMENTS ----- | |
34 cat("\tARGUMENTS INFO\n\n") | |
35 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | |
36 #write.table(as.matrix(args), col.names=F, quote=F, sep='\t\t') | |
37 print(cbind(value = unlist(args))) | |
38 | |
39 | |
40 # ----- PROCESSING INFILE ----- | |
41 cat("\n\n\tARGUMENTS PROCESSING INFO\n\n") | |
42 | |
43 # Loading RData file | |
44 load(args$metaMS) | |
45 if (!exists("resGC")) stop("\n\nERROR: The RData doesn't contain any object called 'resGC' which is provided by the tool: new_metaMS.runGC") | |
46 | |
47 if(args$selecteic) { | |
48 #Unknown EIC parameter | |
49 if (args$unkn[1] != "NULL") { | |
50 #When unkn = 0 user want to process all unknowns | |
51 if(args$unkn[1] == 0) { | |
52 args$unkn <- c(1:nrow(resGC$PeakTable)) | |
53 print("User want to process on all unknown(s) found in metaMS process") | |
54 } | |
55 #TODO find the biggest number of unkn ask by user cause it can write "1,15,9,8" with a max of 11 unkn. With this code it finds the 8 and it will pass | |
56 #Verify that there is not more user's unkn than metaMS unkn (find in resGC$PeakTable) | |
57 cat("Number of unknown after metaMS process :",nrow(resGC$PeakTable),"\n") | |
58 cat("Number of the last unknown ask by user :",args$unkn[length(args$unkn)],"\n") | |
59 cat("Number of unknown ask by user :",length(args$unkn),"\n") | |
60 if(args$unkn[length(args$unkn)] <= nrow(resGC$PeakTable)) { | |
61 unknarg <- args$unkn | |
62 } else { | |
63 error_message="Too much unkn compare metaMS results" | |
64 print(error_message) | |
65 stop(error_message) | |
66 } | |
67 } else { | |
68 error_message <- "No EIC selected !" | |
69 print(error_message) | |
70 stop(error_message) | |
71 } | |
72 } | |
73 | |
74 cat("\n\n") | |
75 | |
76 | |
77 # ----- INFILE PROCESSING ----- | |
78 cat("\tINFILE PROCESSING INFO\n\n") | |
79 | |
80 # Handle infiles | |
81 if (!exists("singlefile")) singlefile <- NULL | |
82 if (!exists("zipfile")) zipfile <- NULL | |
83 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) | |
84 zipfile <- rawFilePath$zipfile | |
85 singlefile <- rawFilePath$singlefile | |
86 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | |
87 | |
88 | |
89 # ----- MAIN PROCESSING INFO ----- | |
90 cat("\n\n\tMAIN PROCESSING INFO\n") | |
91 | |
92 | |
93 cat("\t\tCOMPUTE\n") | |
94 | |
95 #Use getTIC2s and getBPC2s because getTICs and getBPCs can exists due to transfert of function in Rdata | |
96 | |
97 if(!is.null(singlefile)) { | |
98 files <- paste("./",names(singlefile),sep="") | |
99 if(!is.null(files)){ | |
100 if(args$selectbpc){ | |
101 cat("\n\tProcessing BPC(s) from XCMS files...\n") | |
102 c <- getBPC2s(files = files, xset = xset, rt="raw", pdfname="BPCs_raw.pdf") | |
103 cat("BPC(s) created...\n") | |
104 } | |
105 if(args$selecttic){ | |
106 cat("\n\tProcessing TIC(s) from XCMS files...\n") | |
107 b <- getTIC2s(files = files, xset = xset, rt="raw", pdfname="TICs_raw.pdf") | |
108 cat("TIC(s) created...\n") | |
109 } | |
110 if(args$selecteic){ | |
111 cat("\n\tProcessing EIC(s) from XCMS files...\n") | |
112 cat(length(unknarg),"unknown(s) will be process !\n") | |
113 plotUnknowns(resGC=resGC, unkn=unknarg, DB=DBgc, fileFrom="singlefile") | |
114 cat("EIC(s) created...\n") | |
115 #Merge pdf | |
116 system(paste('gs -o GCMS_EIC.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress Unknown_*.pdf')) | |
117 } | |
118 } else { | |
119 error_message <- paste("Can't find",files,"!") | |
120 print(error_message) | |
121 stop(error_message) | |
122 } | |
123 } | |
124 if(!is.null(zipfile)) { | |
125 files <- getMSFiles(directory) | |
126 if(!is.null(files)) { | |
127 if(args$selectbpc) { | |
128 cat("\n\tProcessing BPC(s) from raw files...\n") | |
129 c <- getBPC2s(files = files, rt="raw", pdfname="BPCs_raw.pdf") | |
130 cat("BPC(s) created...\n") | |
131 } | |
132 if(args$selecttic) { | |
133 cat("\n\tProcessing TIC(s) from raw files...\n") | |
134 b <- getTIC2s(files = files, rt="raw", pdfname="TICs_raw.pdf") | |
135 cat("TIC(s) created...\n") | |
136 } | |
137 if(args$selecteic) { | |
138 cat("\n\tProcessing EIC(s) from XCMS files...\n") | |
139 cat(length(unknarg),"unknown(s) will be process !\n") | |
140 plotUnknowns(resGC=resGC, unkn=unknarg, DB=DBgc, fileFrom="zipfile") | |
141 cat("EIC(s) created...\n") | |
142 #Merge pdf | |
143 system(paste('gs -sOutputFile=GCMS_EIC.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress Unknown_*.pdf')) | |
144 } | |
145 } else { | |
146 error_message <- paste("Can't find",files,"!") | |
147 print(error_message) | |
148 stop(error_message) | |
149 } | |
150 } | |
151 | |
152 cat("\nEnd of '", modNamC, "' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "") |