comparison xcms_differential_analysis.r @ 41:e67149fbff20

small changes/improvements; new metams and xcms tools
author pieter.lukasse@wur.nl
date Thu, 06 Nov 2014 16:14:44 +0100
parents
children f772a5caa86a
comparison
equal deleted inserted replaced
40:a7b609941846 41:e67149fbff20
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 args.outLogFile <- args[6]
18 #cat(paste("args.outLogFile <- \"", args[6], "\"\n", sep=""))
19
20 ## report files
21 args.htmlReportFile <- args[7]
22 args.htmlReportFile.files_path <- args[8]
23 #cat(paste("args.htmlReportFile <- \"", args[7], "\"\n", sep=""))
24 #cat(paste("args.htmlReportFile.files_path <- \"", args[8], "\"\n", sep=""))
25
26 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888
27 msg <- file(args.outLogFile, open="wt")
28 sink(msg, type="message")
29 sink(msg, type="output")
30
31 tryCatch(
32 {
33 library(metaMS)
34 library(xcms)
35 #library("R2HTML")
36
37 ## load the constructed DB :
38 xcmsSet <- readRDS(args.xsetData)
39
40 # info: levels(xcmsSet@phenoData$class) also gives access to the class names
41 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE)
42 reporttab <- diffreport(xcmsSet, args.class1, args.class2, paste(args.htmlReportFile.files_path,"/fig", sep=""), args.topcount, metlin = 0.15, h=480, w=640)
43
44 # write out tsv table:
45 write.table(reporttab, args.outTable, sep="\t", row.names=FALSE)
46
47 message("\nGenerating report.........")
48
49 cat("<html><body><h1>Differential analysis report</h1>", file= args.htmlReportFile)
50 #HTML(reporttab[1:args.topcount,], file= args.htmlReportFile)
51 figuresPath <- paste(args.htmlReportFile.files_path, "/fig_eic", sep="")
52 message(figuresPath)
53 listOfFiles <- list.files(path = figuresPath)
54 for (i in 1:length(listOfFiles))
55 {
56 figureName <- listOfFiles[i]
57 # maybe we still need to copy the figures to the args.htmlReportFile.files_path
58 cat(paste("<img src='fig_eic/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE)
59 cat(paste("<img src='fig_box/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE)
60 }
61
62 message("finished generating report")
63 cat("\nWarnings================:\n")
64 str( warnings() )
65 },
66 error=function(cond) {
67 sink(NULL, type="message") # default setting
68 sink(stderr(), type="output")
69 message("\nERROR: ===========\n")
70 print(cond)
71 }
72 )