# HG changeset patch # User ana0gramg+galaxytd@gmail.com # Date 1416370441 -32400 # Node ID 3d7aaffea9f86a68f5d8d0e1c2e912261c80e465 # Parent df838f5c0c61308258acd62e797ccd158f723de9 commit test2 diff -r df838f5c0c61 -r 3d7aaffea9f8 addTwoNumbers.R --- /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") +}) diff -r df838f5c0c61 -r 3d7aaffea9f8 addTwoNumbers.xml --- /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 @@ + + Add two numbers + 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 + + + + + + + + + + + + +**Description** + +An example function that can be made into a Galaxy tool. Takes +two numbers, adds them, and returns a file containing the result. + + \ No newline at end of file