view metaMS_cmd_annotate.r @ 51:684d2341968c

moved polarity parameter
author pieter.lukasse@wur.nl
date Thu, 11 Dec 2014 10:10:18 +0100
parents f772a5caa86a
children 70574a6381ea
line wrap: on
line source

## read args:
args <- commandArgs(TRUE)
## the constructed DB, e.g. "E:/Rworkspace/metaMS/data/LCDBtest.RData"
args.constructedDB <- args[1]
## data file in xset format:
args.xsetData <- args[2]
## settings file, e.g. "E:/Rworkspace/metaMS/data/settings.r", should contain assignment to an object named "customMetaMSsettings" 
args.settings <- args[3]

## output file names, e.g. "E:/Rworkspace/metaMS/data/out.txt"
args.outAnnotationTable <- args[4]

## report files
args.htmlReportFile <- args[5]
args.htmlReportFile.files_path <- args[6]

if (length(args) == 7)
{
	args.outLogFile <- args[7]
	# suppress messages:
	# 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")
}

cat("\nSettings used===============:\n")
cat(readChar(args.settings, 1e5))


tryCatch(
        {
	        library(metaMS)
	
			## load the constructed DB :
			tempEnv <- new.env()
			testDB <- load(args.constructedDB, envir=tempEnv)
			xsetData <- readRDS(args.xsetData)
			
			## load settings "script" into "customMetaMSsettings" 
			source(args.settings, local=tempEnv)
			message(paste(" loaded : ", args.settings))
			
			# Just to highlight: if you want to use more than one 
			# trigger runLC: 
			LC <- runLC(xset=xsetData, settings = tempEnv[["customMetaMSsettings"]], DB = tempEnv[[testDB[1]]]$DB, nSlaves=20, returnXset = TRUE)
			
			# write out runLC annotation results:
			write.table(LC$PeakTable, args.outAnnotationTable, sep="\t", row.names=FALSE)
			
			# the used constructed DB (write to log):
			cat("\nConstructed DB info===============:\n")
			str(tempEnv[[testDB[1]]]$Info)
			cat("\nConstructed DB table===============:\n") 
			if (length(args) == 7)
			{
				write.table(tempEnv[[testDB[1]]]$DB, args.outLogFile, append=TRUE, row.names=FALSE)
				write.table(tempEnv[[testDB[1]]]$Reftable, args.outLogFile, sep="\t", append=TRUE, row.names=FALSE)
			}
			
			message("\nGenerating report.........")
			# report
			dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE, recursive = TRUE)
			html <- "<html><body><h1>Summary of annotation results:</h1>" 
			nrTotalFeatures <- nrow(LC$PeakTable)
			nrAnnotatedFeatures <- nrow(LC$Annotation$annotation.table)
			html <- paste(html,"<p>Total nr of features: ", nrTotalFeatures,"</p>", sep="") 
			html <- paste(html,"<p>Total nr of annotated features: ", nrAnnotatedFeatures,"</p>", sep="")
			
			html <- paste(html,"</body><html>")
			message("finished generating report")
			write(html,file=args.htmlReportFile)
			# unlink(args.htmlReportFile)
			cat("\nWarnings================:\n")
			str( warnings() ) 
		},
        error=function(cond) {
            sink(NULL, type="message") # default setting
			sink(stderr(), type="output")
            message("\nERROR: ===========\n")
            print(cond)
        }
    )