annotate xcms_retcor.r @ 22:972e76582173 draft

"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit f1caf2a3bf23cf319a75dd12c86402555dd02617"
author workflow4metabolomics
date Wed, 12 Feb 2020 08:30:30 -0500
parents c914743e3f2f
children faf4a6b67304
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
1 #!/usr/bin/env Rscript
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
2
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
3 # ----- LOG FILE -----
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
4 log_file=file("log.txt", open = "wt")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
5 sink(log_file)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
6 sink(log_file, type = "output")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
7
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
8
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
9 # ----- PACKAGE -----
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
10 cat("\tSESSION INFO\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
11
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
12 #Import the different functions
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
13 source_local <- function(fname){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) }
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
14 source_local("lib.r")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
15
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
16 pkgs <- c("xcms","batch","RColorBrewer")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
17 loadAndDisplayPackages(pkgs)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
18 cat("\n\n");
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
19
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
20
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
21 # ----- ARGUMENTS -----
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
22 cat("\tARGUMENTS INFO\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
23 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
24 write.table(as.matrix(args), col.names=F, quote=F, sep='\t')
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
25
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
26 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
27
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
28 # ----- PROCESSING INFILE -----
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
29 cat("\tARGUMENTS PROCESSING INFO\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
30
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
31 #saving the specific parameters
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
32 method <- args$method
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
33
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
34 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
35
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
36
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
37 # ----- ARGUMENTS PROCESSING -----
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
38 cat("\tINFILE PROCESSING INFO\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
39
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
40 #image is an .RData file necessary to use xset variable given by previous tools
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
41 load(args$image); args$image=NULL
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
42 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.*")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
43
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
44 # Handle infiles
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
45 if (!exists("singlefile")) singlefile <- NULL
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
46 if (!exists("zipfile")) zipfile <- NULL
22
972e76582173 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit f1caf2a3bf23cf319a75dd12c86402555dd02617"
workflow4metabolomics
parents: 20
diff changeset
47 rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args)
10
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
48 zipfile <- rawFilePath$zipfile
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
49 singlefile <- rawFilePath$singlefile
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
50
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
51 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
52
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
53
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
54 # ----- MAIN PROCESSING INFO -----
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
55 cat("\tMAIN PROCESSING INFO\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
56
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
57
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
58 cat("\t\tCOMPUTE\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
59
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
60 cat("\t\t\tAlignment/Retention Time correction\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
61 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ...
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
62 args <- args[names(args) %in% slotNames(do.call(paste0(method,"Param"), list()))]
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
63
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
64 adjustRtimeParam <- do.call(paste0(method,"Param"), args)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
65 print(adjustRtimeParam)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
66 xdata <- adjustRtime(xdata, param=adjustRtimeParam)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
67
20
c914743e3f2f planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 6f3e71bbe985b4c6af622c9395762b17416062ca
lecorguille
parents: 18
diff changeset
68 #cat("\t\t\tCompute and Store TIC and BPI\n")
c914743e3f2f planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 6f3e71bbe985b4c6af622c9395762b17416062ca
lecorguille
parents: 18
diff changeset
69 #chromTIC_adjusted = chromatogram(xdata, aggregationFun = "sum")
c914743e3f2f planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 6f3e71bbe985b4c6af622c9395762b17416062ca
lecorguille
parents: 18
diff changeset
70 #chromBPI_adjusted = chromatogram(xdata, aggregationFun = "max")
10
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
71
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
72 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
73
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
74
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
75 # -- TIC --
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
76 cat("\t\tDRAW GRAPHICS\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
77 getPlotAdjustedRtime(xdata)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
78
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
79 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
80
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
81 # ----- EXPORT -----
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
82
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
83 cat("\tXCMSnExp OBJECT INFO\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
84 print(xdata)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
85 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
86
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
87 cat("\txcmsSet OBJECT INFO\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
88 # Get the legacy xcmsSet object
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
89 xset <- getxcmsSetObject(xdata)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
90 print(xset)
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
91 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
92
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
93 #saving R data in .Rdata file to save the variables used in the present tool
18
62171c2b2834 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 8ed93601e09e1db2fbaef5af29d58464b639f2a8
lecorguille
parents: 15
diff changeset
94 objects2save = c("xdata","zipfile","singlefile","md5sumList","sampleNamesList") #, "chromTIC", "chromBPI", "chromTIC_adjusted", "chromBPI_adjusted")
10
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
95 save(list=objects2save[objects2save %in% ls()], file="retcor.RData")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
96
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
97 cat("\n\n")
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
98
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
99
8828cba9aedd planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
lecorguille
parents:
diff changeset
100 cat("\tDONE\n")