41
|
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 files, e.g. "E:/Rworkspace/metaMS/data/data.zip" (with e.g. .CDF files) and unzip output dir, e.g. "E:/"
|
|
6 args.dataZip <- args[2]
|
|
7 args.zipExtrDir <- paste(args[2],"dir/")
|
|
8 ## settings file, e.g. "E:/Rworkspace/metaMS/data/settings.r", should contain assignment to an object named "customMetaMSsettings"
|
|
9 args.settings <- args[3]
|
|
10
|
|
11 ## output file names, e.g. "E:/Rworkspace/metaMS/data/out.txt"
|
|
12 args.outAnnotationTable <- args[4]
|
|
13 args.outLogFile <- args[5]
|
|
14 args.xsetOut <- args[6]
|
|
15
|
|
16 ## report files
|
|
17 args.htmlReportFile <- args[7]
|
|
18 args.htmlReportFile.files_path <- args[8]
|
|
19
|
|
20 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888
|
|
21 msg <- file(args.outLogFile, open="wt")
|
|
22 sink(msg, type="message")
|
|
23 sink(msg, type="output")
|
|
24
|
|
25 cat("\nSettings used===============:\n")
|
|
26 cat(readChar(args.settings, 1e5))
|
|
27
|
|
28
|
|
29 tryCatch(
|
|
30 {
|
|
31 library(metaMS)
|
|
32
|
|
33 ## load the constructed DB :
|
|
34 tempEnv <- new.env()
|
|
35 testDB <- load(args.constructedDB, envir=tempEnv)
|
|
36
|
|
37 ## load the data files from a zip file
|
|
38 files <- unzip(args.dataZip, exdir=args.zipExtrDir)
|
|
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(files, settings = tempEnv[["customMetaMSsettings"]], DB = tempEnv[[testDB[1]]]$DB, nSlaves=20, returnXset = TRUE)
|
|
47
|
|
48 # write out runLC annotation results:
|
|
49 write.table(LC$Annotation$annotation.table, 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 write.table(tempEnv[[testDB[1]]]$DB, args.outLogFile, append=TRUE, row.names=FALSE)
|
|
56 write.table(tempEnv[[testDB[1]]]$Reftable, args.outLogFile, sep="\t", append=TRUE, row.names=FALSE)
|
|
57 # save xset as rdata:
|
|
58 xsetData <- LC$xset@xcmsSet
|
|
59 saveRDS(xsetData, file=args.xsetOut)
|
|
60
|
|
61 message("\nGenerating report.........")
|
|
62 # report
|
|
63 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE)
|
|
64 setwd(file.path(args.htmlReportFile.files_path))
|
|
65 html <- "<html><body><h1>Extracted Ion Chromatograms of groups with more than 3 peaks</h1>"
|
|
66
|
|
67 LC$xset@xcmsSet
|
|
68 gt <- groups(LC$xset@xcmsSet)
|
|
69 colnames(gt)
|
|
70 groupidx1 <- which(gt[,"rtmed"] > 0 & gt[,"rtmed"] < 3000 & gt[,"npeaks"] > 3)
|
|
71 if (length(groupidx1) > 0)
|
|
72 {
|
|
73 eiccor <- getEIC(LC$xset@xcmsSet, groupidx = c(groupidx1))
|
|
74 eicraw <- getEIC(LC$xset@xcmsSet, groupidx = c(groupidx1), rt = "raw")
|
|
75 for (i in 1:length(groupidx1))
|
|
76 {
|
|
77 figureName <- paste(args.htmlReportFile.files_path, "/figure", i,".png", sep="")
|
|
78 html <- paste(html,"<img src='", "figure", i,".png' />", sep="")
|
42
|
79 png( figureName, type="cairo" )
|
41
|
80 plot(eiccor, LC$xset@xcmsSet, groupidx = i)
|
|
81 devname = dev.off()
|
|
82 }
|
|
83 }
|
|
84
|
|
85
|
|
86 html <- paste(html,"</body><html>")
|
|
87 message("finished generating report")
|
|
88 write(html,file=args.htmlReportFile)
|
|
89 # unlink(args.htmlReportFile)
|
|
90 cat("\nWarnings================:\n")
|
|
91 str( warnings() )
|
|
92 },
|
|
93 error=function(cond) {
|
|
94 sink(NULL, type="message") # default setting
|
|
95 sink(stderr(), type="output")
|
|
96 message("\nERROR: ===========\n")
|
|
97 print(cond)
|
|
98 }
|
|
99 )
|