This repository was archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmetaMS_plot.r
More file actions
173 lines (145 loc) · 5.92 KB
/
Copy pathmetaMS_plot.r
File metadata and controls
173 lines (145 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env Rscript
# metaMS_plot.r version="1.0.1"
#created by Yann GUITTON and updated by Julien SAINT-VANNE
# ----- LOG FILE -----
#log_file <- file("log.txt", open = "wt")
#sink(log_file)
#sink(log_file, type = "output")
# ----- PACKAGE -----
cat("\tSESSION INFO\n")
#Import the different functions
source_local <- function(fname) {
argv <- commandArgs(trailingOnly = FALSE)
base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
source(paste(base_dir, fname, sep="/"))
}
#This function is made to replace r-batch package dependencie
#@author L. Pavot
parse_args <- function() {
args <- commandArgs()
start <- which(args == "--args")[1] + 1
if (is.na(start)) {
return(list())
}
seq_by2 <- seq(start, length(args), by = 2)
result <- as.list(args[seq_by2 + 1])
names(result) <- args[seq_by2]
return(result)
}
source_local("lib_metams.r")
pkgs <- c("metaMS") #remove "batch" dependencies
loadAndDisplayPackages(pkgs)
cat("\n")
modNamC <- "plot_metaMS" ## module name
cat("\nStart of the '", modNamC, "' Galaxy module call: ", format(Sys.time(), "%a %d %b %Y %X"), "\n\n", sep="")
# ----- ARGUMENTS -----
cat("\tARGUMENTS INFO\n\n")
args <- parse_args() #interpretation of arguments given in command line as an R list of objects
#write.table(as.matrix(args), col.names=F, quote=F, sep='\t\t')
print(cbind(value = unlist(args)))
# ----- PROCESSING INFILE -----
cat("\n\n\tARGUMENTS PROCESSING INFO\n\n")
# Loading RData file
load(args$metaMS)
if (!exists("resGC")) stop("\n\nERROR: The RData doesn't contain any object called 'resGC' which is provided by the tool: new_metaMS.runGC")
if(args$selecteic) {
#Unknown EIC parameter
if (args$unkn[1] != "NULL") {
#When unkn = 0 user want to process all unknowns
if(args$unkn[1] == 0) {
args$unkn <- c(1:nrow(resGC$PeakTable))
print("User want to process on all unknown(s) found in metaMS process")
}
#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
#Verify that there is not more user's unkn than metaMS unkn (find in resGC$PeakTable)
cat("Number of unknown after metaMS process :",nrow(resGC$PeakTable),"\n")
cat("Number of the last unknown ask by user :",args$unkn[length(args$unkn)],"\n")
cat("Number of unknown ask by user :",length(args$unkn),"\n")
if(args$unkn[length(args$unkn)] <= nrow(resGC$PeakTable)) {
unknarg <- args$unkn
} else {
error_message="Too much unkn compare metaMS results"
print(error_message)
stop(error_message)
}
} else {
error_message <- "No EIC selected !"
print(error_message)
stop(error_message)
}
}
cat("\n\n")
# ----- INFILE PROCESSING -----
cat("\tINFILE PROCESSING INFO\n\n")
# Handle infiles
if (!exists("singlefile")) singlefile <- NULL
if (!exists("zipfile")) zipfile <- NULL
rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args)
zipfile <- rawFilePath$zipfile
singlefile <- rawFilePath$singlefile
directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile)
# ----- MAIN PROCESSING INFO -----
cat("\n\n\tMAIN PROCESSING INFO\n")
cat("\t\tCOMPUTE\n")
#Use getTIC2s and getBPC2s because getTICs and getBPCs can exists due to transfert of function in Rdata
if(!is.null(singlefile)) {
files <- paste("./",names(singlefile),sep="")
#WARNING if user has CDF files (not yet good for plotting)
if(MSnbase:::isCdfFile(files)){
warning_message <- "You have CDF files, for the moment you can't obtain plot after runGC! A new update will follow with the good correction\n"
warning(warning_message)
cat(paste("\n","/!\\Warning/!\\",warning_message,sep="\n"))
}
if(!is.null(files)){
if(args$selectbpc){
cat("\n\tProcessing BPC(s) from XCMS files...\n")
c <- getBPC2s(files = files, xset = xset, rt="raw", pdfname="BPCs_raw.pdf")
cat("BPC(s) created...\n")
}
if(args$selecttic){
cat("\n\tProcessing TIC(s) from XCMS files...\n")
b <- getTIC2s(files = files, xset = xset, rt="raw", pdfname="TICs_raw.pdf")
cat("TIC(s) created...\n")
}
if(args$selecteic){
cat("\n\tProcessing EIC(s) from XCMS files...\n")
cat(length(unknarg),"unknown(s) will be process !\n")
plotUnknowns(resGC=resGC, unkn=unknarg, DB=DBgc, fileFrom="singlefile")
cat("EIC(s) created...\n")
#Merge pdf
system(paste('gs -o GCMS_EIC.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress Unknown_*.pdf'))
}
} else {
error_message <- paste("Can't find",files,"!")
print(error_message)
stop(error_message)
}
}
if(!is.null(zipfile)) {
files <- getMSFiles(directory)
if(!is.null(files)) {
if(args$selectbpc) {
cat("\n\tProcessing BPC(s) from raw files...\n")
c <- getBPC2s(files = files, rt="raw", pdfname="BPCs_raw.pdf")
cat("BPC(s) created...\n")
}
if(args$selecttic) {
cat("\n\tProcessing TIC(s) from raw files...\n")
b <- getTIC2s(files = files, rt="raw", pdfname="TICs_raw.pdf")
cat("TIC(s) created...\n")
}
if(args$selecteic) {
cat("\n\tProcessing EIC(s) from XCMS files...\n")
cat(length(unknarg),"unknown(s) will be process !\n")
plotUnknowns(resGC=resGC, unkn=unknarg, DB=DBgc, fileFrom="zipfile")
cat("EIC(s) created...\n")
#Merge pdf
system(paste('gs -sOutputFile=GCMS_EIC.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress Unknown_*.pdf'))
}
} else {
error_message <- paste("Can't find",files,"!")
print(error_message)
stop(error_message)
}
}
cat("\nEnd of '", modNamC, "' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "")