comparison customProDB.R @ 3:7e078d4e40f8 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/bumbershoot/customProDB commit 141369f97aa2804d2bbfd9ed620ea2a5574994c2-dirty
author galaxyp
date Fri, 29 Jan 2016 14:26:25 -0500
parents
children 61e45c111ef7
comparison
equal deleted inserted replaced
2:e6f488178a45 3:7e078d4e40f8
1 #!/usr/bin/env Rscript
2
3 initial.options <- commandArgs(trailingOnly = FALSE)
4 script_parent_dir <- dirname(sub("--file=", "", initial.options[grep("--file=", initial.options)]))
5
6 ## begin warning handler
7 withCallingHandlers({
8
9 library(methods) # Because Rscript does not always do this
10
11 options('useFancyQuotes' = FALSE)
12
13 suppressPackageStartupMessages(library("optparse"))
14 suppressPackageStartupMessages(library("RGalaxy"))
15
16
17 option_list <- list()
18
19 option_list$bam <- make_option('--bam', type='character')
20 option_list$vcf <- make_option('--vcf', type='character')
21 option_list$exon_anno <- make_option('--exon_anno', type='character')
22 option_list$proteinseq <- make_option('--proteinseq', type='character')
23 option_list$procodingseq <- make_option('--procodingseq', type='character')
24 option_list$outputFile <- make_option('--outputFile', type='character')
25
26
27 opt <- parse_args(OptionParser(option_list=option_list))
28
29
30 customProDB <- function(
31 bam_file = GalaxyInputFile(required=TRUE),
32 vcf_file = GalaxyInputFile(required=TRUE),
33 exon_anno_file = GalaxyInputFile(required=TRUE),
34 proteinseq_file = GalaxyInputFile(required=TRUE),
35 procodingseq_file = GalaxyInputFile(required=TRUE),
36 outputFile = GalaxyOutput("FASTA","fasta"))
37 {
38 if (dirname(exon_anno_file) != dirname(proteinseq_file) ||
39 dirname(exon_anno_file) != dirname(procodingseq_file))
40 {
41 gstop("parent directory of annotation files must all be the same")
42 }
43
44 if (file.exists(outputFile))
45 {
46 if (file.info(outputFile)$size > 0) { gstop("output file already exists") }
47 else
48 {
49 tryCatch(
50 {
51 file.remove(outputFile)
52 }, error=function(err)
53 {
54 gstop("failed to remove empty existing file")
55 })
56 }
57 }
58
59 suppressPackageStartupMessages(library(customProDB))
60
61 easyRun(bamFile=bamFile, vcfFile=vcfFile, annotation_path=dirname(exon_anno_file), outfile_path=dirname(outputFile), outfile_name=basename(outputFile))
62 }
63
64
65 params <- list()
66 for(param in names(opt))
67 {
68 if (!param == "help")
69 params[param] <- opt[param]
70 }
71
72 setClass("GalaxyRemoteError", contains="character")
73 wrappedFunction <- function(f)
74 {
75 tryCatch(do.call(f, params),
76 error=function(e) new("GalaxyRemoteError", conditionMessage(e)))
77 }
78
79
80 suppressPackageStartupMessages(library(RGalaxy))
81 do.call(customProDB, params)
82
83 ## end warning handler
84 }, warning = function(w) {
85 cat(paste("Warning:", conditionMessage(w), "\n"))
86 invokeRestart("muffleWarning")
87 })