annotate 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
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 ## the constructed DB, e.g. "E:/Rworkspace/metaMS/data/LCDBtest.RData"
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
4 args.constructedDB <- args[1]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
5 ## data file in xset format:
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
6 args.xsetData <- args[2]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
7 ## settings file, e.g. "E:/Rworkspace/metaMS/data/settings.r", should contain assignment to an object named "customMetaMSsettings"
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
8 args.settings <- args[3]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
9
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
10 ## output file names, e.g. "E:/Rworkspace/metaMS/data/out.txt"
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
11 args.outAnnotationTable <- args[4]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
12
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
13 args.mass_error_function <- args[5]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
14 if (args.mass_error_function == "0")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
15 args.mass_error_function <- NULL
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
16 ## report files
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
17 args.htmlReportFile <- args[6]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
18 args.htmlReportFile.files_path <- args[7]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
19
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
20 if (length(args) == 8)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
21 {
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
22 args.outLogFile <- args[8]
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
23 # suppress messages:
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
24 # Send all STDERR to STDOUT using sink() see http://mazamascience.com/WorkingWithData/?p=888
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
25 msg <- file(args.outLogFile, open="wt")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
26 sink(msg, type="message")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
27 sink(msg, type="output")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
28 }
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
29
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
30 cat("\nSettings used===============:\n")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
31 cat(readChar(args.settings, 1e5))
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
32
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
33
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
34 tryCatch(
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
35 {
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
36 library(metaMS)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
37
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
38 ## load the constructed DB :
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
39 tempEnv <- new.env()
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
40 testDB <- load(args.constructedDB, envir=tempEnv)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
41 xsetData <- readRDS(args.xsetData)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
42
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
43 ## load settings "script" into "customMetaMSsettings"
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
44 source(args.settings, local=tempEnv)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
45 message(paste(" loaded : ", args.settings))
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
46
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
47 # Just to highlight: if you want to use more than one
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
48 # trigger runLC:
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
49 LC <- runLC(xset=xsetData, settings = tempEnv[["customMetaMSsettings"]], DB = tempEnv[[testDB[1]]]$DB, errf=args.mass_error_function, nSlaves=20, returnXset = TRUE)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
50
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
51 # write out runLC annotation results:
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
52 write.table(LC$PeakTable, args.outAnnotationTable, sep="\t", row.names=FALSE)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
53
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
54 # the used constructed DB (write to log):
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
55 cat("\nConstructed DB info===============:\n")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
56 str(tempEnv[[testDB[1]]]$Info)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
57 cat("\nConstructed DB table===============:\n")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
58 if (length(args) == 8)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
59 {
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
60 write.table(tempEnv[[testDB[1]]]$DB, args.outLogFile, append=TRUE, row.names=FALSE)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
61 write.table(tempEnv[[testDB[1]]]$Reftable, args.outLogFile, sep="\t", append=TRUE, row.names=FALSE)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
62 }
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
63
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
64 message("\nGenerating report.........")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
65 # report
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
66 dir.create(file.path(args.htmlReportFile.files_path), showWarnings = FALSE, recursive = TRUE)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
67 html <- "<html><body><h1>Summary of annotation results:</h1>"
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
68 nrTotalFeatures <- nrow(LC$PeakTable)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
69 nrAnnotatedFeatures <- nrow(LC$Annotation$annotation.table)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
70 html <- paste(html,"<p>Total nr of features: ", nrTotalFeatures,"</p>", sep="")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
71 html <- paste(html,"<p>Total nr of annotated features: ", nrAnnotatedFeatures,"</p>", sep="")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
72
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
73 html <- paste(html,"</body><html>")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
74 message("finished generating report")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
75 write(html,file=args.htmlReportFile)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
76 # unlink(args.htmlReportFile)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
77 cat("\nWarnings================:\n")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
78 str( warnings() )
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
79 },
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
80 error=function(cond) {
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
81 sink(NULL, type="message") # default setting
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
82 sink(stderr(), type="output")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
83 message("\nERROR: ===========\n")
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
84 print(cond)
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
85 }
4393f982d18f reorganized sources
pieter.lukasse@wur.nl
parents:
diff changeset
86 )