Mercurial > repos > pieterlukasse > prims_metabolomics
comparison xcms_differential_analysis.r @ 1:071a185c2ced
new tools
author | pieter.lukasse@wur.nl |
---|---|
date | Fri, 24 Oct 2014 12:52:56 +0200 |
parents | |
children | 627ddbd15823 |
comparison
equal
deleted
inserted
replaced
0:4b94bb2d381c | 1:071a185c2ced |
---|---|
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(xcms) | |
34 #library("R2HTML") | |
35 | |
36 ## load the constructed DB : | |
37 xcmsSet <- readRDS(args.xsetData) | |
38 | |
39 # info: levels(xcmsSet@phenoData$class) also gives access to the class names | |
40 | |
41 reporttab <- diffreport(xcmsSet, args.class1, args.class2, args.htmlReportFile.files_path, args.topcount, metlin = 0.15, h=480, w=640) | |
42 | |
43 # write out tsv table: | |
44 write.table(reporttab, args.outTable, sep="\t", row.names=FALSE) | |
45 | |
46 message("\nGenerating report.........") | |
47 # report | |
48 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE) | |
49 # setwd(file.path(args.htmlReportFile.files_path)) | |
50 | |
51 cat("<html><body><h1>Differential analysis report</h1>", file= args.htmlReportFile) | |
52 #HTML(reporttab[1:args.topcount,], file= args.htmlReportFile) | |
53 figuresPath <- paste(args.htmlReportFile.files_path, "_eic", sep="") | |
54 message(figuresPath) | |
55 listOfFiles <- list.files(path = figuresPath) | |
56 for (i in 1:length(listOfFiles)) | |
57 { | |
58 figureName <- listOfFiles[i] | |
59 # maybe we still need to copy the figures to the args.htmlReportFile.files_path | |
60 cat(paste("<img src='fig_eic/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE) | |
61 } | |
62 | |
63 message("finished generating report") | |
64 cat("\nWarnings================:\n") | |
65 str( warnings() ) | |
66 }, | |
67 error=function(cond) { | |
68 sink(NULL, type="message") # default setting | |
69 sink(stderr(), type="output") | |
70 message("\nERROR: ===========\n") | |
71 print(cond) | |
72 } | |
73 ) |