comparison xcms_retcor.r @ 27:8242376d9f35 draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics/ commit cc13a2654ccf6f9e55bc0120ea5518df3b045712
author workflow4metabolomics
date Thu, 14 Mar 2024 15:35:44 +0000
parents
children
comparison
equal deleted inserted replaced
26:36480435e92b 27:8242376d9f35
1 #!/usr/bin/env Rscript
2
3 # ----- LOG FILE -----
4 log_file <- file("log.txt", open = "wt")
5 sink(log_file)
6 sink(log_file, type = "output")
7
8
9 # ----- PACKAGE -----
10 cat("\tSESSION INFO\n")
11
12 #Import the different functions
13 source_local <- function(fname) {
14 argv <- commandArgs(trailingOnly = FALSE)
15 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
16 source(paste(base_dir, fname, sep = "/"))
17 }
18 source_local("lib.r")
19
20 pkgs <- c("xcms", "batch", "RColorBrewer")
21 loadAndDisplayPackages(pkgs)
22 cat("\n\n")
23
24
25 # ----- ARGUMENTS -----
26 cat("\tARGUMENTS INFO\n")
27 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects
28 write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t")
29
30 cat("\n\n")
31
32 # ----- PROCESSING INFILE -----
33 cat("\tARGUMENTS PROCESSING INFO\n")
34
35 #saving the specific parameters
36 method <- args$method
37
38 cat("\n\n")
39
40
41 # ----- ARGUMENTS PROCESSING -----
42 cat("\tINFILE PROCESSING INFO\n")
43
44 #image is an .RData file necessary to use xset variable given by previous tools
45 load(args$image)
46 args$image <- NULL
47 if (!exists("xdata")) stop("\n\nERROR: The RData doesn't contain any object called 'xdata'. This RData should have been created by an old version of XMCS 2.*")
48
49 # Handle infiles
50 if (!exists("singlefile")) singlefile <- NULL
51 if (!exists("zipfile")) zipfile <- NULL
52 rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args)
53 zipfile <- rawFilePath$zipfile
54 singlefile <- rawFilePath$singlefile
55
56 cat("\n\n")
57
58
59 # ----- MAIN PROCESSING INFO -----
60 cat("\tMAIN PROCESSING INFO\n")
61
62
63 cat("\t\tCOMPUTE\n")
64
65 cat("\t\t\tAlignment/Retention Time correction\n")
66 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ...
67 args <- args[names(args) %in% slotNames(do.call(paste0(method, "Param"), list()))]
68
69 adjustRtimeParam <- do.call(paste0(method, "Param"), args)
70 print(adjustRtimeParam)
71
72 if (hasAdjustedRtime(xdata)) {
73 cat("WARNING: a retention time ajustment had already been applied to your data.\nThe function applyAdjustedRtime was processed to cumulate the ajustment")
74 cat("Replace raw retention times with adjusted retention times.\n")
75 xdata <- applyAdjustedRtime(xdata)
76 }
77 xdata <- adjustRtime(xdata, param = adjustRtimeParam)
78
79 cat("\n\n")
80
81
82 # -- TIC --
83 cat("\t\tDRAW GRAPHICS\n")
84 getPlotAdjustedRtime(xdata)
85
86 cat("\n\n")
87
88 # ----- EXPORT -----
89
90 cat("\tXCMSnExp OBJECT INFO\n")
91 print(xdata)
92 cat("\n\n")
93
94 cat("\txcmsSet OBJECT INFO\n")
95 # Get the legacy xcmsSet object
96 xset <- getxcmsSetObject(xdata)
97 print(xset)
98 cat("\n\n")
99
100 #saving R data in .Rdata file to save the variables used in the present tool
101 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList")
102 save(list = objects2save[objects2save %in% ls()], file = "retcor.RData")
103
104 cat("\n\n")
105
106
107 cat("\tDONE\n")