comparison metaMS_cmd_annotate.r @ 0:dffc38727496

initial commit
author pieter.lukasse@wur.nl
date Sat, 07 Feb 2015 22:02:00 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dffc38727496
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 args.mass_error_function <- args[5]
14 if (args.mass_error_function == "0")
15 args.mass_error_function <- NULL
16 ## report files
17 args.htmlReportFile <- args[6]
18 args.htmlReportFile.files_path <- args[7]
19
20 if (length(args) == 8)
21 {
22 args.outLogFile <- args[8]
23 # suppress messages:
24 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888
25 msg <- file(args.outLogFile, open="wt")
26 sink(msg, type="message")
27 sink(msg, type="output")
28 }
29
30 cat("\nSettings used===============:\n")
31 cat(readChar(args.settings, 1e5))
32
33
34 tryCatch(
35 {
36 library(metaMS)
37
38 ## load the constructed DB :
39 tempEnv <- new.env()
40 testDB <- load(args.constructedDB, envir=tempEnv)
41 xsetData <- readRDS(args.xsetData)
42
43 ## load settings "script" into "customMetaMSsettings"
44 source(args.settings, local=tempEnv)
45 message(paste(" loaded : ", args.settings))
46
47 # Just to highlight: if you want to use more than one
48 # trigger runLC:
49 LC <- runLC(xset=xsetData, settings = tempEnv[["customMetaMSsettings"]], DB = tempEnv[[testDB[1]]]$DB, errf=args.mass_error_function, nSlaves=20, returnXset = TRUE)
50
51 # write out runLC annotation results:
52 write.table(LC$PeakTable, args.outAnnotationTable, sep="\t", row.names=FALSE)
53
54 # the used constructed DB (write to log):
55 cat("\nConstructed DB info===============:\n")
56 str(tempEnv[[testDB[1]]]$Info)
57 cat("\nConstructed DB table===============:\n")
58 if (length(args) == 8)
59 {
60 write.table(tempEnv[[testDB[1]]]$DB, args.outLogFile, append=TRUE, row.names=FALSE)
61 write.table(tempEnv[[testDB[1]]]$Reftable, args.outLogFile, sep="\t", append=TRUE, row.names=FALSE)
62 }
63
64 message("\nGenerating report.........")
65 # report
66 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE, recursive = TRUE)
67 html <- "<html><body><h1>Summary of annotation results:</h1>"
68 nrTotalFeatures <- nrow(LC$PeakTable)
69 nrAnnotatedFeatures <- nrow(LC$Annotation$annotation.table)
70 html <- paste(html,"<p>Total nr of features: ", nrTotalFeatures,"</p>", sep="")
71 html <- paste(html,"<p>Total nr of annotated features: ", nrAnnotatedFeatures,"</p>", sep="")
72
73 html <- paste(html,"</body><html>")
74 message("finished generating report")
75 write(html,file=args.htmlReportFile)
76 # unlink(args.htmlReportFile)
77 cat("\nWarnings================:\n")
78 str( warnings() )
79 },
80 error=function(cond) {
81 sink(NULL, type="message") # default setting
82 sink(stderr(), type="output")
83 message("\nERROR: ===========\n")
84 print(cond)
85 }
86 )