Mercurial > repos > pieterlukasse > prims_metabolomics
annotate metaMS_cmd_pick_and_group.r @ 50:93102202ab79
Added more options and better documentation.
Added MsClust support for parsing XCMS alignment results.
Improved output reports for XCMS wrappers.
New tools.
author | pieter.lukasse@wur.nl |
---|---|
date | Wed, 10 Dec 2014 22:04:33 +0100 |
parents | f772a5caa86a |
children | 684d2341968c |
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 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
14 ## report files |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
15 args.htmlReportFile <- args[5] |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
16 args.htmlReportFile.files_path <- args[6] |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
17 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
18 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
19 if (length(args) == 7) |
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 args.outLogFile <- args[7] |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
22 # suppress messages: |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
23 # 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
|
24 msg <- file(args.outLogFile, open="wt") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
25 sink(msg, type="message") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
26 sink(msg, type="output") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
27 } |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
28 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
29 cat("\nSettings used===============:\n") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
30 cat(readChar(args.settings, 1e5)) |
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 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
33 tryCatch( |
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 library(metaMS) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
36 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
37 ## load the data files from a zip file |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
38 files <- unzip(args.dataZip, exdir=args.zipExtrDir) |
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 settings "script" into "customMetaMSsettings" |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
41 tempEnv <- new.env() |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
42 source(args.settings, local=tempEnv) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
43 message(paste(" loaded : ", args.settings)) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
44 allSettings <- tempEnv[["customMetaMSsettings"]] |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
45 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
46 # trigger runLC: |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
47 LC <- runLC(files, settings = allSettings, nSlaves=20, returnXset = TRUE) |
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 # write out runLC annotation results: |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
50 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
|
51 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
52 # save xset as rdata: |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
53 xsAnnotatePreparedData <- LC$xset |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
54 saveRDS(xsAnnotatePreparedData, file=args.xsetOut) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
55 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
56 message("\nGenerating report.........") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
57 # report |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
58 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
|
59 html <- "<html><body><h1>Info on alignment quality </h1>" |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
60 # TODO add (nr and mass error) and group size |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
61 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
62 message("\nPlotting figures... ") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
63 figureName <- paste(args.htmlReportFile.files_path, "/figure_retcor.png", sep="") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
64 html <- paste(html,"<img src='figure_retcor.png' /><br/>", sep="") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
65 png( figureName, type="cairo", width=1100,height=600 ) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
66 retcor(LC$xset@xcmsSet, method="peakgroups", plottype = "mdevden") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
67 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
|
68 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
|
69 this option is added in metaMS API. </a><br/>", sep="") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
70 devname = dev.off() |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
71 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
72 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
73 gt <- groups(LC$xset@xcmsSet) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
74 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
|
75 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
76 html <- paste(html,"</body><html>") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
77 message("finished generating report") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
78 write(html,file=args.htmlReportFile) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
79 # unlink(args.htmlReportFile) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
80 cat("\nWarnings================:\n") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
81 str( warnings() ) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
82 }, |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
83 error=function(cond) { |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
84 sink(NULL, type="message") # default setting |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
85 sink(stderr(), type="output") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
86 message("\nERROR: ===========\n") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
87 print(cond) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
88 } |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff
changeset
|
89 ) |