Mercurial > repos > pieterlukasse > prims_metabolomics
annotate xcms_differential_analysis.r @ 49:f772a5caa86a
Added more options and better documentation.
Added MsClust support for parsing XCMS alignment results.
Improved output reports for XCMS wrappers.
New tools.
author | pieter.lukasse@wur.nl |
---|---|
date | Wed, 10 Dec 2014 22:03:27 +0100 |
parents | e67149fbff20 |
children | 10f3cb998c4e |
rev | line source |
---|---|
41 | 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 | |
49
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
19 args.htmlReportFile <- args[6] |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
20 args.htmlReportFile.files_path <- args[7] |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
21 #cat(paste("args.htmlReportFile <- \"", args[6], "\"\n", sep="")) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
22 #cat(paste("args.htmlReportFile.files_path <- \"", args[7], "\"\n", sep="")) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
23 |
41 | 24 |
49
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
25 if (length(args) == 8) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
26 { |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
27 args.outLogFile <- args[8] |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
28 # suppress messages: |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
29 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888 |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
30 msg <- file(args.outLogFile, open="wt") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
31 sink(msg, type="message") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
32 sink(msg, type="output") |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
33 } |
41 | 34 |
35 tryCatch( | |
36 { | |
37 library(metaMS) | |
38 library(xcms) | |
39 #library("R2HTML") | |
40 | |
49
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
41 # load the xset data : |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
42 xsetData <- readRDS(args.xsetData) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
43 # if here to support both scenarios: |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
44 if ("xcmsSet" %in% slotNames(xsetData) ) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
45 { |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
46 xsetData <- xsetData@xcmsSet |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
47 } |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
48 |
41 | 49 |
50 # info: levels(xcmsSet@phenoData$class) also gives access to the class names | |
49
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
51 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE, recursive = TRUE) |
f772a5caa86a
Added more options and better documentation.
pieter.lukasse@wur.nl
parents:
41
diff
changeset
|
52 reporttab <- diffreport(xsetData, args.class1, args.class2, paste(args.htmlReportFile.files_path,"/fig", sep=""), args.topcount, metlin = 0.15, h=480, w=640) |
41 | 53 |
54 # write out tsv table: | |
55 write.table(reporttab, args.outTable, sep="\t", row.names=FALSE) | |
56 | |
57 message("\nGenerating report.........") | |
58 | |
59 cat("<html><body><h1>Differential analysis report</h1>", file= args.htmlReportFile) | |
60 #HTML(reporttab[1:args.topcount,], file= args.htmlReportFile) | |
61 figuresPath <- paste(args.htmlReportFile.files_path, "/fig_eic", sep="") | |
62 message(figuresPath) | |
63 listOfFiles <- list.files(path = figuresPath) | |
64 for (i in 1:length(listOfFiles)) | |
65 { | |
66 figureName <- listOfFiles[i] | |
67 # maybe we still need to copy the figures to the args.htmlReportFile.files_path | |
68 cat(paste("<img src='fig_eic/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE) | |
69 cat(paste("<img src='fig_box/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE) | |
70 } | |
71 | |
72 message("finished generating report") | |
73 cat("\nWarnings================:\n") | |
74 str( warnings() ) | |
75 }, | |
76 error=function(cond) { | |
77 sink(NULL, type="message") # default setting | |
78 sink(stderr(), type="output") | |
79 message("\nERROR: ===========\n") | |
80 print(cond) | |
81 } | |
82 ) |