Mercurial > repos > pieterlukasse > prims_metabolomics2
view metaMS/metaMS_cmd_annotate.r @ 24:2ab40f9266e4 draft
An update to the core of galaxy prevents the way the code is trying to write files. This patch fixes this.
author | linda-bakker |
---|---|
date | Tue, 20 Feb 2018 07:59:47 -0500 |
parents | 4393f982d18f |
children |
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] args.mass_error_function <- args[5] if (args.mass_error_function == "0") args.mass_error_function <- NULL ## report files args.htmlReportFile <- args[6] args.htmlReportFile.files_path <- args[7] if (length(args) == 8) { args.outLogFile <- args[8] # 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, errf=args.mass_error_function, 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) == 8) { 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) } )