Mercurial > repos > koash > test
changeset 3:3d7aaffea9f8 default tip
commit test2
author | ana0gramg+galaxytd@gmail.com |
---|---|
date | Wed, 19 Nov 2014 13:14:01 +0900 |
parents | df838f5c0c61 |
children | |
files | addTwoNumbers.R addTwoNumbers.xml |
diffstat | 2 files changed, 88 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/addTwoNumbers.R Wed Nov 19 13:14:01 2014 +0900 @@ -0,0 +1,56 @@ +#!/usr/bin/env Rscript + +## 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$number1 <- make_option('--number1', type='numeric') +option_list$number2 <- make_option('--number2', type='numeric') +option_list$sum <- make_option('--sum', type='character') + + +opt <- parse_args(OptionParser(option_list=option_list)) + +suppressPackageStartupMessages(library(RSclient)) + +## function body not needed here, it is in package + +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))) +} + + +c <- RS.connect(host='localhost', port=6311) +RS.eval(c, options('useFancyQuotes' = FALSE)) +RS.eval(c, suppressPackageStartupMessages(library(RGalaxy))) +RS.assign(c, 'params', params) +RS.assign(c, 'wrappedFunction', wrappedFunction) +RS.eval(c, setClass('GalaxyRemoteError', contains='character')) +res <- RS.eval(c, wrappedFunction(addTwoNumbers)) +RS.close(c) +if(is(res, 'GalaxyRemoteError'))RGalaxy::gstop(res) + +## end warning handler +}, warning = function(w) { + cat(paste("Warning:", conditionMessage(w), "\n")) + invokeRestart("muffleWarning") +})
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/addTwoNumbers.xml Wed Nov 19 13:14:01 2014 +0900 @@ -0,0 +1,32 @@ +<tool id="addTwoNumbers" name="Add Two Numbers" version="1.10.0"> + <description>Add two numbers</description> + <command interpreter="Rscript --vanilla">addTwoNumbers.R + #if str($number1).strip() != "": + --number1="$number1" + #end if + #if str($number2).strip() != "": + --number2="$number2" + #end if + #if str($sum).strip() != "": + --sum="$sum" + #end if + +2>&1</command> + <inputs> + <param optional="false" name="number1" type="float" value="" help="The first number to add." label="[required] Number1"> + <validator type="empty_field" message="This field is required."/> + </param> + <param optional="false" name="number2" type="float" value="" help="The second number to add." label="[required] Number2"> + <validator type="empty_field" message="This field is required."/> + </param> + </inputs> + <outputs> + <data format="txt" name="sum" label="sum.txt"/> + </outputs> + <help> +**Description** + +An example function that can be made into a Galaxy tool. Takes +two numbers, adds them, and returns a file containing the result. +</help> +</tool> \ No newline at end of file