## ------------------------------------------------------------------------ library(sevenbridges) rbx <- Tool(id = "runif", label = "runif", hints = requirements(docker(pull = "rocker/r-base"), cpu(1), mem(2000)), baseCommand = "Rscript -e 'runif(100)'", stdout = "output.txt", outputs = output(id = "random", glob = "*.txt")) rbx rbx$toJSON() ## ------------------------------------------------------------------------ rbx$toJSON() rbx$toJSON(pretty = TRUE) rbx$toYAML() ## ------------------------------------------------------------------------ ## Make a new file fd <- fileDef(name = "runif.R", content = "set.seed(1) runif(100)") ## or simply readLines .srcfile <- system.file("docker/sevenbridges/src/runif.R", package = "sevenbridges") fd <- fileDef(name = "runif.R", content = paste(readLines(.srcfile), collapse = "\n")) ## or read via reader library(readr) fd <- fileDef(name = "runif.R", content = read_file(.srcfile)) rbx <- Tool(id = "runif", label = "runif", hints = requirements(docker(pull = "rocker/r-base"), cpu(1), mem(2000)), requirements = requirements(fd), baseCommand = "Rscript runif.R", stdout = "output.txt", outputs = output(id = "random", glob = "*.txt")) ## ------------------------------------------------------------------------ ## or simply readLines .srcfile <- system.file("docker/sevenbridges/src/runif.R", package = "sevenbridges") fd1 <- fileDef(name = "runif.R", content = paste(readLines(.srcfile), collapse = "\n")) fd2 <- fileDef(name = "runif2.R", content = "set.seed(1) runif(100)") rbx <- Tool(id = "runif_twoscript", label = "runif_twoscript", hints = requirements(docker(pull = "rocker/r-base"), cpu(1), mem(2000)), requirements = requirements(fd1, fd2), baseCommand = "Rscript runif.R", stdout = "output.txt", outputs = output(id = "random", glob = "*.txt")) ## ------------------------------------------------------------------------ ## pass a input list in.lst <- list(input(id = "number", description = "number of observations", type = "integer", label = "number", prefix = "--n", default = 1, required = TRUE, cmdInclude = TRUE), input(id = "min", description = "lower limits of the distribution", type = "float", label = "min", prefix = "--min", default = 0), input(id = "max", description = "upper limits of the distribution", type = "float", label = "max", prefix = "--max", default = 1), input(id = "seed", description = "seed with set.seed", type = "float", label = "seed", prefix = "--seed", default = 1)) ## the same method for outputs out.lst <- list(output(id = "random", type = "file", label = "output", description = "random number file", glob = "*.txt"), output(id = "report", type = "file", label = "report", glob = "*.html")) rbx <- Tool(id = "runif", label = "Random number generator", hints = requirements(docker(pull = "tengfei/runif"), cpu(1), mem(2000)), baseCommand = "runif.R", inputs = in.lst, ## or ins.df outputs = out.lst) ## ------------------------------------------------------------------------ in.df <- data.frame(id = c("number", "min", "max", "seed"), description = c("number of observation", "lower limits of the distribution", "upper limits of the distribution", "seed with set.seed"), type = c("integer", "float", "float", "float"), label = c("number" ,"min", "max", "seed"), prefix = c("--n", "--min", "--max", "--seed"), default = c(1, 0, 10, 123), required = c(TRUE, FALSE, FALSE, FALSE)) out.df <- data.frame(id = c("random", "report"), type = c("file", "file"), glob = c("*.txt", "*.html")) rbx <- Tool(id = "runif", label = "Random number generator", hints = requirements(docker(pull = "tengfei/runif"), cpu(1), mem(2000)), baseCommand = "runif.R", inputs = in.df, ## or ins.df outputs = out.df) ## ---- eval = TRUE, comment=''-------------------------------------------- fl <- system.file("docker/sevenbridges/src", "runif2spin.R", package = "sevenbridges") cat(readLines(fl), sep = '\n') ## ------------------------------------------------------------------------ library(readr) fd <- fileDef(name = "runif.R", content = read_file(fl)) rbx <- Tool(id = "runif", label = "runif", hints = requirements(docker(pull = "rocker/r-base"), cpu(1), mem(2000)), requirements = requirements(fd), baseCommand = "Rscript runif.R", stdout = "output.txt", inputs = list(input(id = "number", type = "integer", position = 1), input(id = "min", type = "float", position = 2), input(id = "max", type = "float", position = 3)), outputs = output(id = "random", glob = "output.txt")) ## ---- eval = TRUE, comment=''-------------------------------------------- fl <- system.file("docker/sevenbridges/src", "runif_args.R", package = "sevenbridges") cat(readLines(fl), sep = '\n') ## ------------------------------------------------------------------------ library(readr) fd <- fileDef(name = "runif.R", content = read_file(fl)) rbx <- Tool(id = "runif", label = "runif", hints = requirements(docker(pull = "rocker/r-base"), cpu(1), mem(2000)), requirements = requirements(fd), baseCommand = "Rscript runif.R", stdout = "output.txt", inputs = list(input(id = "number", type = "integer", separate = FALSE, prefix = "--n="), input(id = "min", type = "float", separate = FALSE, prefix = "--min="), input(id = "max", type = "float", separate = FALSE, prefix = "--max=")), outputs = output(id = "random", glob = "output.txt")) ## ---- eval = TRUE, comment=''-------------------------------------------- fl <- system.file("docker/sevenbridges/src", "runif_args.R", package = "sevenbridges") cat(readLines(fl), sep = '\n') ## ------------------------------------------------------------------------ library(readr) fd <- fileDef(name = "runif.R", content = read_file(fl)) rbx <- Tool(id = "runif", label = "runif", hints = requirements(docker(pull = "rocker/hadleyverse"), cpu(1), mem(2000)), requirements = requirements(fd), baseCommand = "Rscript -e \"rmarkdown::render(knitr::spin('runif.R', FALSE))\" --args", stdout = "output.txt", inputs = list(input(id = "number", type = "integer", separate = FALSE, prefix = "--n="), input(id = "min", type = "float", separate = FALSE, prefix = "--min="), input(id = "max", type = "float", separate = FALSE, prefix = "--max=")), outputs = list(output(id = "stdout", type = "file", glob = "output.txt"), output(id = "random", type = "file", glob = "*.csv"), output(id = "report", type = "file", glob = "*.html"))) ## ------------------------------------------------------------------------ out.lst <- list(output(id = "random", type = "file", label = "output", description = "random number file", glob = "*.txt"), output(id = "report", type = "file", label = "report", glob = "*.html", inheritMetadataFrom = "bam_file", metadata = list(author = "tengfei", sample = "random"))) out.lst ## ---- eval = FALSE------------------------------------------------------- # a <- Auth(platform = "cgc", username = "tengfei") # p <- a$project("demo") # app.runif <- p$app_add("runif555", rbx) # aid <- app.runif$id # p$task_add(name = "Draft runif simple", # description = "Description for runif", # app = aid, # inputs = list(min = 1, max = 10)) # ## confirm, show all task status is draft # (tsk <- p$task(status = "draft")) # tsk$run() # tsk$download("~/Downloads/") ## ---- eval=F------------------------------------------------------------- # library(sevenbridges) # # in.df <- data.frame(id = c("number", "min", "max", "seed"), # description = c("number of observation", # "lower limits of the distribution", # "upper limits of the distribution", # "seed with set.seed"), # type = c("integer", "float", "float", "float"), # label = c("number" ,"min", "max", "seed"), # prefix = c("--n", "--min", "--max", "--seed"), # default = c(1, 0, 10, 123), # required = c(TRUE, FALSE, FALSE, FALSE)) # out.df <- data.frame(id = c("random", "report"), # type = c("file", "file"), # glob = c("*.txt", "*.html")) # rbx <- Tool(id = "runif", # label = "Random number generator", # hints = requirements(docker(pull = "tengfei/runif"), # cpu(1), mem(2000)), # baseCommand = "runif.R", # inputs = in.df, ## or ins.df # outputs = out.df) # params <- list(number=3, max=5) # # set_test_env("tengfei/testenv", "mount_dir") # test_tool(rbx, params) ## ------------------------------------------------------------------------ library(sevenbridges) ## A tool that generate a 100 random number t1 <- Tool(id = "runif new test 3", label = "random number", hints = requirements(docker(pull = "rocker/r-base")), baseCommand = "Rscript -e 'x = runif(100); write.csv(x, file = 'random.txt', row.names = FALSE)'", outputs = output(id = "random", type = "file", glob = "random.txt")) ## A tool that take log fd <- fileDef(name = "log.R", content = "args = commandArgs(TRUE) x = read.table(args[1], header = TRUE)[,'x'] x = log(x) write.csv(x, file = 'random_log.txt', row.names = FALSE) ") t2 <- Tool(id = "log new test 3", label = "get log", hints = requirements(docker(pull = "rocker/r-base")), requirements = requirements(fd), baseCommand = "Rscript log.R", inputs = input(id = "number", type = "file"), outputs = output(id = "log", type = "file", glob = "*.txt")) ## A tool that do a mean fd <- fileDef(name = "mean.R", content = "args = commandArgs(TRUE) x = read.table(args[1], header = TRUE)[,'x'] x = mean(x) write.csv(x, file = 'random_mean.txt', row.names = FALSE) ") t3 <- Tool(id = "mean new test 3", label = "get mean", hints = requirements(docker(pull = "rocker/r-base")), requirements = requirements(fd), baseCommand = "Rscript mean.R", inputs = input(id = "number", type = "file"), outputs = output(id = "mean", type = "file", glob = "*.txt")) steplist <- t1 + t2 + t3 steplist ## ------------------------------------------------------------------------ f <- Flow(id = "Random-log-mean-new-test-2", label = "random log mean new test", steps = steplist) f$toJSON() f$toJSON(pretty = TRUE) ## ------------------------------------------------------------------------ f <- t1 %>>% t2 %>>% t3 f$toJSON() ## ---- eval = FALSE------------------------------------------------------- # ## need id, full, sbg:id # library(sevenbridges) # # a <- Auth(platform = "cgc", username = "tengfei") # p <- a$project(id = "tengfei/helloworld") # app.runif <- p$app_add("new_flow", f) # aid <- app.runif$id # p$task_add(name = "Draft flow", # description = "Flow test", # app = aid) # ## confirm, show all task status is draft # (tsk <- p$task('Draft flow')) # tsk$run() ## ---- eval = FALSE------------------------------------------------------- # app1 <- p$app(id = "tengfei/helloworld/runif_new_test/0") # app2 <- p$app(id = "tengfei/quickstart/log_new_test_3/0") # app3 <- p$app(id = "tengfei/quickstart/log_new_test_3/0") # # f <- app1 %>>% app2 %>>% app3 # # f$id <- "randome number test flow 2" # f$"sbg:id" <- "tengfei/helloworld/testtesttest" # f$toJSON(pretty = TRUE)