diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xcms_differential_analysis.r	Thu Nov 06 16:14:44 2014 +0100
@@ -0,0 +1,72 @@
+## read args:
+args <- commandArgs(TRUE)
+#cat("args <- \"\"\n")
+## a xcms xset saved as .RData
+args.xsetData <- args[1]
+#cat(paste("args.xsetData <- \"", args[1], "\"\n", sep=""))
+
+args.class1 <- args[2]
+args.class2 <- args[3]
+#cat(paste("args.class1 <- \"", args[2], "\"\n", sep=""))
+#cat(paste("args.class2 <- \"", args[3], "\"\n", sep=""))
+
+args.topcount <- strtoi(args[4]) 
+#cat(paste("args.topcount <- ", args[4], "\n", sep=""))
+
+args.outTable <- args[5]
+args.outLogFile <- args[6]
+#cat(paste("args.outLogFile <- \"", args[6], "\"\n", sep=""))
+
+## report files
+args.htmlReportFile <- args[7]
+args.htmlReportFile.files_path <- args[8]
+#cat(paste("args.htmlReportFile <- \"", args[7], "\"\n", sep=""))
+#cat(paste("args.htmlReportFile.files_path <- \"", args[8], "\"\n", sep=""))
+
+# Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888
+msg <- file(args.outLogFile, open="wt")
+sink(msg, type="message") 
+sink(msg, type="output")
+
+tryCatch(
+        {
+        	library(metaMS)
+        	library(xcms)
+	        #library("R2HTML")
+	
+			## load the constructed DB :
+			xcmsSet <- readRDS(args.xsetData)
+			
+			# info: levels(xcmsSet@phenoData$class) also gives access to the class names
+			dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE)
+			reporttab <- diffreport(xcmsSet, args.class1, args.class2, paste(args.htmlReportFile.files_path,"/fig", sep=""), args.topcount, metlin = 0.15, h=480, w=640)
+			
+			# write out tsv table:
+			write.table(reporttab, args.outTable, sep="\t", row.names=FALSE)
+			
+			message("\nGenerating report.........")
+			
+			cat("<html><body><h1>Differential analysis report</h1>", file= args.htmlReportFile)
+			#HTML(reporttab[1:args.topcount,], file= args.htmlReportFile)
+			figuresPath <- paste(args.htmlReportFile.files_path, "/fig_eic", sep="")
+			message(figuresPath)
+			listOfFiles <- list.files(path = figuresPath)
+			for (i in 1:length(listOfFiles))  
+			{
+				figureName <- listOfFiles[i]
+				# maybe we still need to copy the figures to the args.htmlReportFile.files_path
+				cat(paste("<img src='fig_eic/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE)
+				cat(paste("<img src='fig_box/", figureName,"' />", sep=""), file= args.htmlReportFile, append=TRUE)
+			}
+			
+			message("finished generating report")
+			cat("\nWarnings================:\n")
+			str( warnings() ) 
+		},
+        error=function(cond) {
+            sink(NULL, type="message") # default setting
+			sink(stderr(), type="output")
+            message("\nERROR: ===========\n")
+            print(cond)
+        }
+    ) 			
\ No newline at end of file