annotate metaMS_cmd_annotate.r @ 56:9404c688f42d

fix for xcms support in msclust
author pieter.lukasse@wur.nl
date Fri, 12 Dec 2014 12:04:16 +0100
parents 70574a6381ea
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 ## the constructed DB, e.g. "E:/Rworkspace/metaMS/data/LCDBtest.RData"
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
4 args.constructedDB <- args[1]
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
5 ## data file in xset format:
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
6 args.xsetData <- args[2]
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[3]
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.outAnnotationTable <- args[4]
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
12
53
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
13 args.mass_error_function <- args[5]
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
14 if (args.mass_error_function == "0")
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
15 args.mass_error_function <- NULL
49
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
16 ## report files
53
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
17 args.htmlReportFile <- args[6]
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
18 args.htmlReportFile.files_path <- args[7]
49
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
19
53
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
20 if (length(args) == 8)
49
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
21 {
53
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
22 args.outLogFile <- args[8]
49
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
23 # suppress messages:
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
24 # 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
25 msg <- file(args.outLogFile, open="wt")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
26 sink(msg, type="message")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
27 sink(msg, type="output")
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
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
30 cat("\nSettings used===============:\n")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
31 cat(readChar(args.settings, 1e5))
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
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
34 tryCatch(
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 library(metaMS)
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 ## load the constructed DB :
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
39 tempEnv <- new.env()
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
40 testDB <- load(args.constructedDB, envir=tempEnv)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
41 xsetData <- readRDS(args.xsetData)
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 source(args.settings, local=tempEnv)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
45 message(paste(" loaded : ", args.settings))
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
46
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
47 # Just to highlight: if you want to use more than one
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
48 # trigger runLC:
53
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
49 LC <- runLC(xset=xsetData, settings = tempEnv[["customMetaMSsettings"]], DB = tempEnv[[testDB[1]]]$DB, errf=args.mass_error_function, nSlaves=20, returnXset = TRUE)
49
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
50
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
51 # write out runLC annotation results:
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
52 write.table(LC$PeakTable, args.outAnnotationTable, sep="\t", row.names=FALSE)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
53
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
54 # the used constructed DB (write to log):
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
55 cat("\nConstructed DB info===============:\n")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
56 str(tempEnv[[testDB[1]]]$Info)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
57 cat("\nConstructed DB table===============:\n")
53
70574a6381ea small fixes
pieter.lukasse@wur.nl
parents: 49
diff changeset
58 if (length(args) == 8)
49
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
59 {
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
60 write.table(tempEnv[[testDB[1]]]$DB, args.outLogFile, append=TRUE, row.names=FALSE)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
61 write.table(tempEnv[[testDB[1]]]$Reftable, args.outLogFile, sep="\t", append=TRUE, row.names=FALSE)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
62 }
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
63
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
64 message("\nGenerating report.........")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
65 # report
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
66 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
67 html <- "<html><body><h1>Summary of annotation results:</h1>"
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
68 nrTotalFeatures <- nrow(LC$PeakTable)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
69 nrAnnotatedFeatures <- nrow(LC$Annotation$annotation.table)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
70 html <- paste(html,"<p>Total nr of features: ", nrTotalFeatures,"</p>", sep="")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
71 html <- paste(html,"<p>Total nr of annotated features: ", nrAnnotatedFeatures,"</p>", sep="")
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 html <- paste(html,"</body><html>")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
74 message("finished generating report")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
75 write(html,file=args.htmlReportFile)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
76 # unlink(args.htmlReportFile)
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
77 cat("\nWarnings================:\n")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
78 str( warnings() )
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
79 },
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
80 error=function(cond) {
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
81 sink(NULL, type="message") # default setting
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
82 sink(stderr(), type="output")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
83 message("\nERROR: ===========\n")
f772a5caa86a Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
diff changeset
84 print(cond)
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 )