annotate metaMS/xcms_differential_analysis.r @ 15:05ff1c55db84

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