annotate xcms_differential_analysis.r @ 44:bae899b9dd39

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