6
|
1 ## read args:
|
|
2 args <- commandArgs(TRUE)
|
|
3 #cat("args <- \"\"\n")
|
|
4 ## a xcms xset saved as .RData
|
|
5 args.xsetData <- args[1]
|
|
6 #cat(paste("args.xsetData <- \"", args[1], "\"\n", sep=""))
|
|
7
|
|
8 args.class1 <- args[2]
|
|
9 args.class2 <- args[3]
|
|
10 #cat(paste("args.class1 <- \"", args[2], "\"\n", sep=""))
|
|
11 #cat(paste("args.class2 <- \"", args[3], "\"\n", sep=""))
|
|
12
|
|
13 args.topcount <- strtoi(args[4])
|
|
14 #cat(paste("args.topcount <- ", args[4], "\n", sep=""))
|
|
15
|
|
16 args.outTable <- args[5]
|
|
17
|
|
18 ## report files
|
|
19 args.htmlReportFile <- args[6]
|
|
20 args.htmlReportFile.files_path <- args[7]
|
|
21 #cat(paste("args.htmlReportFile <- \"", args[6], "\"\n", sep=""))
|
|
22 #cat(paste("args.htmlReportFile.files_path <- \"", args[7], "\"\n", sep=""))
|
|
23
|
|
24
|
|
25 if (length(args) == 8)
|
|
26 {
|
|
27 args.outLogFile <- args[8]
|
|
28 # suppress messages:
|
|
29 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888
|
|
30 msg <- file(args.outLogFile, open="wt")
|
|
31 sink(msg, type="message")
|
|
32 sink(msg, type="output")
|
|
33 }
|
|
34
|
|
35 tryCatch(
|
|
36 {
|
|
37 library(metaMS)
|
|
38 library(xcms)
|
|
39 #library("R2HTML")
|
|
40
|
|
41 # load the xset data :
|
|
42 xsetData <- readRDS(args.xsetData)
|
|
43 # if here to support both scenarios:
|
|
44 if ("xcmsSet" %in% slotNames(xsetData) )
|
|
45 {
|
|
46 xsetData <- xsetData@xcmsSet
|
|
47 }
|
|
48
|
|
49
|
|
50 # info: levels(xcmsSet@phenoData$class) also gives access to the class names
|
|
51 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE, recursive = TRUE)
|
|
52 # set cairo as default for png plots:
|
|
53 png = function (...) grDevices::png(...,type='cairo')
|
|
54 # run diffreport
|
|
55 reporttab <- diffreport(xsetData, args.class1, args.class2, paste(args.htmlReportFile.files_path,"/fig", sep=""), args.topcount, metlin = 0.15, h=480, w=640)
|
|
56
|
|
57 # write out tsv table:
|
|
58 write.table(reporttab, args.outTable, sep="\t", row.names=FALSE)
|
|
59
|
|
60 message("\nGenerating report.........")
|
|
61
|
|
62 cat("<html><body><h1>Differential analysis report</h1>", file= args.htmlReportFile)
|
|
63 #HTML(reporttab[1:args.topcount,], file= args.htmlReportFile)
|
|
64 figuresPath <- paste(args.htmlReportFile.files_path, "/fig_eic", sep="")
|
|
65 message(figuresPath)
|
|
66 listOfFiles <- list.files(path = figuresPath)
|
|
67 for (i in 1:length(listOfFiles))
|
|
68 {
|
|
69 figureName <- listOfFiles[i]
|
|
70 # maybe we still need to copy the figures to the args.htmlReportFile.files_path
|
|
71 cat(paste("<img src='fig_eic/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE)
|
|
72 cat(paste("<img src='fig_box/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE)
|
|
73 }
|
|
74
|
|
75 message("finished generating report")
|
|
76 cat("\nWarnings================:\n")
|
|
77 str( warnings() )
|
|
78 },
|
|
79 error=function(cond) {
|
|
80 sink(NULL, type="message") # default setting
|
|
81 sink(stderr(), type="output")
|
|
82 message("\nERROR: ===========\n")
|
|
83 print(cond)
|
|
84 }
|
|
85 ) |