Mercurial > repos > pieterlukasse > prims_metabolomics
comparison metaMS_cmd_annotate.r @ 49:f772a5caa86a
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:03:27 +0100 |
parents | |
children | 70574a6381ea |
comparison
equal
deleted
inserted
replaced
48:26b93438f30e | 49:f772a5caa86a |
---|---|
1 ## read args: | |
2 args <- commandArgs(TRUE) | |
3 ## the constructed DB, e.g. "E:/Rworkspace/metaMS/data/LCDBtest.RData" | |
4 args.constructedDB <- args[1] | |
5 ## data file in xset format: | |
6 args.xsetData <- args[2] | |
7 ## settings file, e.g. "E:/Rworkspace/metaMS/data/settings.r", should contain assignment to an object named "customMetaMSsettings" | |
8 args.settings <- args[3] | |
9 | |
10 ## output file names, e.g. "E:/Rworkspace/metaMS/data/out.txt" | |
11 args.outAnnotationTable <- args[4] | |
12 | |
13 ## report files | |
14 args.htmlReportFile <- args[5] | |
15 args.htmlReportFile.files_path <- args[6] | |
16 | |
17 if (length(args) == 7) | |
18 { | |
19 args.outLogFile <- args[7] | |
20 # suppress messages: | |
21 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888 | |
22 msg <- file(args.outLogFile, open="wt") | |
23 sink(msg, type="message") | |
24 sink(msg, type="output") | |
25 } | |
26 | |
27 cat("\nSettings used===============:\n") | |
28 cat(readChar(args.settings, 1e5)) | |
29 | |
30 | |
31 tryCatch( | |
32 { | |
33 library(metaMS) | |
34 | |
35 ## load the constructed DB : | |
36 tempEnv <- new.env() | |
37 testDB <- load(args.constructedDB, envir=tempEnv) | |
38 xsetData <- readRDS(args.xsetData) | |
39 | |
40 ## load settings "script" into "customMetaMSsettings" | |
41 source(args.settings, local=tempEnv) | |
42 message(paste(" loaded : ", args.settings)) | |
43 | |
44 # Just to highlight: if you want to use more than one | |
45 # trigger runLC: | |
46 LC <- runLC(xset=xsetData, settings = tempEnv[["customMetaMSsettings"]], DB = tempEnv[[testDB[1]]]$DB, nSlaves=20, returnXset = TRUE) | |
47 | |
48 # write out runLC annotation results: | |
49 write.table(LC$PeakTable, args.outAnnotationTable, sep="\t", row.names=FALSE) | |
50 | |
51 # the used constructed DB (write to log): | |
52 cat("\nConstructed DB info===============:\n") | |
53 str(tempEnv[[testDB[1]]]$Info) | |
54 cat("\nConstructed DB table===============:\n") | |
55 if (length(args) == 7) | |
56 { | |
57 write.table(tempEnv[[testDB[1]]]$DB, args.outLogFile, append=TRUE, row.names=FALSE) | |
58 write.table(tempEnv[[testDB[1]]]$Reftable, args.outLogFile, sep="\t", append=TRUE, row.names=FALSE) | |
59 } | |
60 | |
61 message("\nGenerating report.........") | |
62 # report | |
63 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE, recursive = TRUE) | |
64 html <- "<html><body><h1>Summary of annotation results:</h1>" | |
65 nrTotalFeatures <- nrow(LC$PeakTable) | |
66 nrAnnotatedFeatures <- nrow(LC$Annotation$annotation.table) | |
67 html <- paste(html,"<p>Total nr of features: ", nrTotalFeatures,"</p>", sep="") | |
68 html <- paste(html,"<p>Total nr of annotated features: ", nrAnnotatedFeatures,"</p>", sep="") | |
69 | |
70 html <- paste(html,"</body><html>") | |
71 message("finished generating report") | |
72 write(html,file=args.htmlReportFile) | |
73 # unlink(args.htmlReportFile) | |
74 cat("\nWarnings================:\n") | |
75 str( warnings() ) | |
76 }, | |
77 error=function(cond) { | |
78 sink(NULL, type="message") # default setting | |
79 sink(stderr(), type="output") | |
80 message("\nERROR: ===========\n") | |
81 print(cond) | |
82 } | |
83 ) |