annotate metaMS_cmd_annotate.r @ 1:223d1167de58

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