Mercurial > repos > lecorguille > xcms_retcor
comparison xcms_retcor.r @ 10:8828cba9aedd draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
author | lecorguille |
---|---|
date | Tue, 18 Sep 2018 16:12:29 -0400 |
parents | |
children | 950b97b679c6 |
comparison
equal
deleted
inserted
replaced
9:e4e0254a3c0a | 10:8828cba9aedd |
---|---|
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){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | |
14 source_local("lib.r") | |
15 source_local("lib-xcms3.x.x.r") | |
16 | |
17 pkgs <- c("xcms","batch","RColorBrewer") | |
18 loadAndDisplayPackages(pkgs) | |
19 cat("\n\n"); | |
20 | |
21 | |
22 # ----- ARGUMENTS ----- | |
23 cat("\tARGUMENTS INFO\n") | |
24 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | |
25 write.table(as.matrix(args), col.names=F, quote=F, sep='\t') | |
26 | |
27 cat("\n\n") | |
28 | |
29 # ----- PROCESSING INFILE ----- | |
30 cat("\tARGUMENTS PROCESSING INFO\n") | |
31 | |
32 #saving the specific parameters | |
33 method <- args$method | |
34 | |
35 cat("\n\n") | |
36 | |
37 | |
38 # ----- ARGUMENTS PROCESSING ----- | |
39 cat("\tINFILE PROCESSING INFO\n") | |
40 | |
41 #image is an .RData file necessary to use xset variable given by previous tools | |
42 load(args$image); args$image=NULL | |
43 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.*") | |
44 | |
45 # Handle infiles | |
46 if (!exists("singlefile")) singlefile <- NULL | |
47 if (!exists("zipfile")) zipfile <- NULL | |
48 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) | |
49 zipfile <- rawFilePath$zipfile | |
50 singlefile <- rawFilePath$singlefile | |
51 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | |
52 | |
53 cat("\n\n") | |
54 | |
55 | |
56 # ----- MAIN PROCESSING INFO ----- | |
57 cat("\tMAIN PROCESSING INFO\n") | |
58 | |
59 | |
60 cat("\t\tCOMPUTE\n") | |
61 | |
62 cat("\t\t\tAlignment/Retention Time correction\n") | |
63 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ... | |
64 args <- args[names(args) %in% slotNames(do.call(paste0(method,"Param"), list()))] | |
65 | |
66 adjustRtimeParam <- do.call(paste0(method,"Param"), args) | |
67 print(adjustRtimeParam) | |
68 xdata <- adjustRtime(xdata, param=adjustRtimeParam) | |
69 | |
70 cat("\t\t\tCompute and Store TIC and BPI\n") | |
71 chromTIC_adjusted = chromatogram(xdata, aggregationFun = "sum") | |
72 chromBPI_adjusted = chromatogram(xdata, aggregationFun = "max") | |
73 | |
74 cat("\n\n") | |
75 | |
76 | |
77 # -- TIC -- | |
78 cat("\t\tDRAW GRAPHICS\n") | |
79 getPlotAdjustedRtime(xdata) | |
80 | |
81 cat("\n\n") | |
82 | |
83 # ----- EXPORT ----- | |
84 | |
85 cat("\tXCMSnExp OBJECT INFO\n") | |
86 print(xdata) | |
87 cat("\n\n") | |
88 | |
89 cat("\txcmsSet OBJECT INFO\n") | |
90 # Get the legacy xcmsSet object | |
91 xset <- getxcmsSetObject(xdata) | |
92 print(xset) | |
93 cat("\n\n") | |
94 | |
95 #saving R data in .Rdata file to save the variables used in the present tool | |
96 objects2save = c("xdata","zipfile","singlefile","md5sumList","sampleNamesList", "chromTIC", "chromBPI", "chromTIC_adjusted", "chromBPI_adjusted") | |
97 save(list=objects2save[objects2save %in% ls()], file="retcor.RData") | |
98 | |
99 cat("\n\n") | |
100 | |
101 | |
102 cat("\tDONE\n") |