6
|
1 ## read args:
|
|
2 args <- commandArgs(TRUE)
|
|
3 ## data files, e.g. "E:/Rworkspace/metaMS/data/data.zip" (with e.g. .CDF files) and unzip output dir, e.g. "E:/"
|
|
4 args.dataZip <- args[1]
|
|
5 args.zipExtrDir <- sub("\\.","_",paste(args[1],"dir", sep=""))
|
|
6 dir.create(file.path(args.zipExtrDir), showWarnings = FALSE, recursive = TRUE)
|
|
7 ## settings file, e.g. "E:/Rworkspace/metaMS/data/settings.r", should contain assignment to an object named "customMetaMSsettings"
|
|
8 args.settings <- args[2]
|
|
9
|
|
10 ## output file names, e.g. "E:/Rworkspace/metaMS/data/out.txt"
|
|
11 args.outPeakTable <- args[3]
|
|
12 args.xsetOut <- args[4]
|
|
13
|
|
14 # polarity as explicit parameter:
|
|
15 args.runLC_polarity <- args[5]
|
|
16
|
|
17 ## report files
|
|
18 args.htmlReportFile <- args[6]
|
|
19 args.htmlReportFile.files_path <- args[7]
|
|
20
|
|
21
|
|
22 if (length(args) == 8)
|
|
23 {
|
|
24 args.outLogFile <- args[8]
|
|
25 # suppress messages:
|
|
26 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888
|
|
27 msg <- file(args.outLogFile, open="wt")
|
|
28 sink(msg, type="message")
|
|
29 sink(msg, type="output")
|
|
30 }
|
|
31
|
|
32 cat("\nSettings used===============:\n")
|
|
33 cat(readChar(args.settings, 1e5))
|
|
34
|
|
35
|
|
36 tryCatch(
|
|
37 {
|
|
38 library(metaMS)
|
|
39
|
|
40 ## load the data files from a zip file
|
|
41 files <- unzip(args.dataZip, exdir=args.zipExtrDir)
|
|
42
|
|
43 ## load settings "script" into "customMetaMSsettings"
|
|
44 tempEnv <- new.env()
|
|
45 source(args.settings, local=tempEnv)
|
|
46 message(paste(" loaded : ", args.settings))
|
|
47 allSettings <- tempEnv[["customMetaMSsettings"]]
|
|
48
|
|
49 # trigger runLC:
|
|
50 LC <- runLC(files, settings = allSettings, polarity=args.runLC_polarity, nSlaves=20, returnXset = TRUE)
|
|
51
|
|
52 # write out runLC annotation results:
|
|
53 write.table(LC$PeakTable, args.outPeakTable, sep="\t", row.names=FALSE)
|
|
54
|
|
55 # save xset as rdata:
|
|
56 xsAnnotatePreparedData <- LC$xset
|
|
57 saveRDS(xsAnnotatePreparedData, file=args.xsetOut)
|
|
58
|
|
59 message("\nGenerating report.........")
|
|
60 # report
|
|
61 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE, recursive = TRUE)
|
|
62 html <- "<html><body><h1>Info on alignment quality </h1>"
|
|
63 # TODO add (nr and mass error) and group size
|
|
64
|
|
65 message("\nPlotting figures... ")
|
|
66 figureName <- paste(args.htmlReportFile.files_path, "/figure_retcor.png", sep="")
|
|
67 html <- paste(html,"<img src='figure_retcor.png' /><br/>", sep="")
|
|
68 png( figureName, type="cairo", width=1100,height=600 )
|
|
69 retcor(LC$xset@xcmsSet, method="peakgroups", plottype = "mdevden")
|
|
70 html <- paste(html,"<a>*NB: retention time correction plot based on 'peakgroups' option with default settings. This is not the plot matching the exact settings used in the run,
|
|
71 but just intended to give a rough estimate of the retention time shifts present in the data. A more accurate plot will be available once
|
|
72 this option is added in metaMS API. </a><br/>", sep="")
|
|
73 devname = dev.off()
|
|
74
|
|
75
|
|
76 gt <- groups(LC$xset@xcmsSet)
|
|
77 groupidx1 <- which(gt[,"rtmed"] > 0 & gt[,"rtmed"] < 3000 & gt[,"npeaks"] > 3)
|
|
78
|
|
79 html <- paste(html,"</body><html>")
|
|
80 message("finished generating report")
|
|
81 write(html,file=args.htmlReportFile)
|
|
82 # unlink(args.htmlReportFile)
|
|
83 cat("\nWarnings================:\n")
|
|
84 str( warnings() )
|
|
85 },
|
|
86 error=function(cond) {
|
|
87 sink(NULL, type="message") # default setting
|
|
88 sink(stderr(), type="output")
|
|
89 message("\nERROR: ===========\n")
|
|
90 print(cond)
|
|
91 }
|
|
92 )
|