annotate metaMS_cmd_pick_and_group.r @ 51:684d2341968c

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