changeset 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 e6f488178a45
children 5bf19713c281
files customProDB.R customProDB.xml
diffstat 2 files changed, 119 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/customProDB.R	Fri Jan 29 14:26:25 2016 -0500
@@ -0,0 +1,87 @@
+#!/usr/bin/env Rscript
+
+initial.options <- commandArgs(trailingOnly = FALSE)
+script_parent_dir <- dirname(sub("--file=", "", initial.options[grep("--file=", initial.options)]))
+
+## begin warning handler
+withCallingHandlers({
+
+library(methods) # Because Rscript does not always do this
+
+options('useFancyQuotes' = FALSE)
+
+suppressPackageStartupMessages(library("optparse"))
+suppressPackageStartupMessages(library("RGalaxy"))
+
+
+option_list <- list()
+
+option_list$bam <- make_option('--bam', type='character')
+option_list$vcf <- make_option('--vcf', type='character')
+option_list$exon_anno <- make_option('--exon_anno', type='character')
+option_list$proteinseq <- make_option('--proteinseq', type='character')
+option_list$procodingseq <- make_option('--procodingseq', type='character')
+option_list$outputFile <- make_option('--outputFile', type='character')
+
+
+opt <- parse_args(OptionParser(option_list=option_list))
+
+
+customProDB <- function(
+	bam_file = GalaxyInputFile(required=TRUE), 
+	vcf_file = GalaxyInputFile(required=TRUE), 
+	exon_anno_file = GalaxyInputFile(required=TRUE),
+	proteinseq_file = GalaxyInputFile(required=TRUE),
+	procodingseq_file = GalaxyInputFile(required=TRUE),
+	outputFile = GalaxyOutput("FASTA","fasta"))
+{
+    if (dirname(exon_anno_file) != dirname(proteinseq_file) ||
+        dirname(exon_anno_file) != dirname(procodingseq_file))
+    {
+        gstop("parent directory of annotation files must all be the same")
+    }
+
+    if (file.exists(outputFile))
+    {
+        if (file.info(outputFile)$size > 0) { gstop("output file already exists") }
+        else
+        {
+            tryCatch(
+            {
+                file.remove(outputFile)
+            }, error=function(err)
+            {
+                gstop("failed to remove empty existing file")
+            })
+        }
+    }
+
+    suppressPackageStartupMessages(library(customProDB))
+
+    easyRun(bamFile=bamFile, vcfFile=vcfFile, annotation_path=dirname(exon_anno_file), outfile_path=dirname(outputFile), outfile_name=basename(outputFile))
+}
+
+
+params <- list()
+for(param in names(opt))
+{
+    if (!param == "help")
+        params[param] <- opt[param]
+}
+
+setClass("GalaxyRemoteError", contains="character")
+wrappedFunction <- function(f)
+{
+    tryCatch(do.call(f, params),
+        error=function(e) new("GalaxyRemoteError", conditionMessage(e)))
+}
+
+
+suppressPackageStartupMessages(library(RGalaxy))
+do.call(customProDB, params)
+
+## end warning handler
+}, warning = function(w) {
+    cat(paste("Warning:", conditionMessage(w), "\n"))
+    invokeRestart("muffleWarning")
+})
--- a/customProDB.xml	Thu Jan 14 18:12:22 2016 -0500
+++ b/customProDB.xml	Fri Jan 29 14:26:25 2016 -0500
@@ -4,44 +4,48 @@
     <exit_code range="1:" level="fatal" description="Job Failed" />
   </stdio>
   <command interpreter="Rscript --vanilla">PSM2SAM.R
-       #if str($input).strip() != "":
-          --passedPSM="$input"
-       #end if
-       #if str($scoreColumn).strip() != "":
-          --XScolumn="$scoreColumn"
-       #end if
-       #if str($optionalUserInput.exonAnno).strip() != "None":
-          --exon_anno="$optionalUserInput.exonAnno"
-       #end if
-       #if str($optionalUserInput.proteinSeq).strip() != "None":
-          --proteinseq="$optionalUserInput.proteinSeq"
-       #end if
-       #if str($optionalUserInput.proCodingSeq).strip() != "None":
-          --procodingseq="$optionalUserInput.proCodingSeq"
-       #end if
-       #if str($optionalUserInput.header).strip() != "None":
-          --header="$optionalUserInput.header"
-       #end if
-       #if str($output).strip() != "":
-          --OutputFile="$output"
+
+       --bam="$bamInput"
+       --vcf="$vcfInput"
+       --outputFile="$output"
+
+       #if str($genome_annotation.source) == "history":
+            --exon_anno="$genome_annotation.exonAnno"
+            --proteinseq="$genome_annotation.proteinSeq"
+            --procodingseq="$genome_annotation.proCodingSeq"
+       #else:
+            #set index_path = $genome_annotation.builtin.fields.path
+            --exon_anno="$index_path/exon_anno.RData"
+            --proteinseq="$index_path/proseq.RData"
+            --procodingseq="$index_path/procodingseq.RData"
        #end if
 
 2&gt;&amp;1</command>
   <inputs>
-    <param name="input" type="data" format="bam" help="A BAM file to translate to FASTA." label="Input BAMs">
+    <param name="bamInput" type="data" format="bam" help="A BAM file to translate to FASTA." label="Input BAM">
       <validator type="empty_field" message="This field is required."/>
     </param>
     <param name="vcfInput" type="data" format="vcf" help="A VCF file to create variant proteins based on individual variation." label="Input Variant Calls">
       <validator type="empty_field" message="This field is required."/>
     </param>
-    <conditional name="optionalUserInput">
-      <param name="optionalUserInputCondition" type="boolean" label="Override Default Exon Annotation and Coding Sequences" />
-      <when value="true">
-        <param name="exonAnno" type="data" format="RData" help="A dataframe of exon annotations in an RData file" label="Exon Annotations" optional="true" />
-        <param name="proteinSeq" type="data" format="RData" help="A dataframe containing protein ids and protein sequences in an RData file" label="Protein Sequences" optional="true" />
-        <param name="proCodingSeq" type="data" format="RData" help="A dataframe cotaining coding sequences for each protein in an RData file" label="Protein Coding Sequences" optional="true" />
+
+    <conditional name="genome_annotation">
+      <param name="source" type="select" label="Will you select a genome annotation from your history or use a built-in annotation?" help="See `Annotations` section of help below">
+        <option value="builtin">Use a built-in genome annotation</option>
+        <option value="history">Use a genome from the history and build index</option>
+      </param>
+      <when value="builtin">
+        <param name="builtin" type="select" label="Select genome annotation" help="If your genome of interest is not listed, contact the Galaxy team">
+          <options from_data_table="customProDB">
+            <filter type="sort_by" column="2"/>
+            <validator type="no_options" message="No annotations are available for the selected input dataset"/>
+          </options>
+        </param>
       </when>
-      <when value="false">
+      <when value="history">
+        <param name="exonAnno" type="data" format="RData" metadata_name="dbkey" help="A dataframe of exon annotations in an RData file" label="Exon Annotations" optional="true" />
+        <param name="proteinSeq" type="data" format="RData" metadata_name="dbkey" help="A dataframe containing protein ids and protein sequences in an RData file" label="Protein Sequences" optional="true" />
+        <param name="proCodingSeq" type="data" format="RData" metadata_name="dbkey" help="A dataframe cotaining coding sequences for each protein in an RData file" label="Protein Coding Sequences" optional="true" />
       </when>
     </conditional>
   </inputs>