## Loading required package: knitr
In this little tutorial, I am going to use the sevenbridges
R package to develop a small tool that does a download of a URL to a file on the local disk. I will be wrapping that tool in a common workflow language wrapper and then uploading the resulting tool into the SevenBridges system. Finally, I will execute that tool on the cloud via an API call.
The SevenBridges Cancer Genomics Cloud is built around the concept of reproducible workflows based on the Common Workflow Language standard. SevenBridges has an Application Programming Interface API that allows programmatic access and control of the platform. The combination of an industrial workflow engine running on cloud infrastructure, available tools and workflows, and a programming language like R.
Before loading the sevenbridges
library, it is useful (but not required) to set up a small credentials file called .sbg.auth.yam
in your HOME directory. The file should look like:
cgc:
url: https://cgc-api.sbgenomics.com/v2/
user:
sdavis2:
token: YOUR_AUTH_TOKEN_FROM_SBG
On loading the library, this file will be read, allowing you to write code without including your AUTH_TOKEN in the actual code.
library(sevenbridges)
The common workflow language describes in some detail the details of the YAML file that describes a tool. The approach that is used in the sevenbridges
package is to allow the developer to describe the tool using R
code. In the next code block, I am describing the inputs and outputs of our very simple tool, a command-line R script.
in.lst = list(input(id='url',
description='URL of the download',
type='string',
position=1),
input(id='ofname',
description='output filename',
type='string',
position=2))
out.lst = list(output(id='file',
glob=('output/*')))
The tool that I am going to be wrapping is a simple script that uses the httr library to download a file from a URL to a local file. In order to ensure that the correct R environment is available where this is run, I will specify that the docker image rocker/hadleyverse
is a requirement. Note that this docker image already has the necessary pieces needed to run the script–in particular, it has httr
installed.
I use the input list and output list from above in the Tool
specification. The fileDef
allows me to directly include the script from the disk; the location of the file is relative to the working directory.
fl = system.file("scripts/get_http_file.R", package='cgcR')
library(readr)
fd = fileDef(name='get_http_file.R',
content=read_file(fl))
rbx <- Tool(id = "get_http_file",
label = "get_http_file",
hints = requirements(docker(pull = "rocker/hadleyverse"),
cpu(1), mem(2000)),
requirements = requirements(fd),
baseCommand = "Rscript get_http_file.R",
inputs = in.lst,
outputs = out.lst)
The next few lines are the first to actually interact with the SevenBridges API. For the authentication, you will need to get a “developer token” and specify that in your call to Auth()
below. I had already created a project called “temp-batch”. If you already have a project, specify that project name instead of mine. If you do not already have a project, you will need to create one via the API or the web interface first.
a <- Auth(platform = "cgc", username = "sdavis2")
p = a$project('mytestproject')
app.txfr = p$app_add("txfr", rbx)
## create new revision 5
aid <- app.txfr$id
Now, we can use the app that we just created to create a task; in other words, we will run the app. We need to specify the URL and FILE name.
tsk = p$task_add(name='transfer test',
description='transfer test desc',
app=aid,
inputs=list(
url='http://hgdownload.cse.ucsc.edu/goldenPath/hg38/bigZips/hg38.trf.bed.gz',
ofname='hg38.trf.bed.gz'))
## checking inputs ...
## API: getting app input information ...
## checking ...
## check id match
## Task drafting ...
## Done
After submitting the task, we can list all tasks that remain in the draft
state. These tasks are ready to run, but awaiting an official run
command from us.
p$task(status='draft')
## [[1]]
## == Task ==
## id : c3b5072a-c0ec-4b28-8c93-63f070528ac7
## name : transfer test
## project : sdavis2/mytestproject
## [[2]]
## == Task ==
## id : 9aee85aa-110e-43c2-b37a-04d5e35aa10b
## name : transfer test
## project : sdavis2/mytestproject
Finally, we run the task.
tsk$run()
## == Task ==
## id : 9aee85aa-110e-43c2-b37a-04d5e35aa10b
## name : transfer test
## description : transfer test desc
## status : QUEUED
## app : sdavis2/mytestproject/txfr/5
## type : v2
## created_by : sdavis2
## executed_by : sdavis2
## start_time : 2016-08-19T00:41:59Z
## execution_status:
## message : In queue
## inputs:
## ofname : hg38.trf.bed.gz
## url : http://hgdownload.cse.ucsc.edu/goldenPath/hg38/bigZips/hg38.trf.bed.gz
## outputs:
## project : sdavis2/mytestproject
## batch : FALSE
sessionInfo()
## R version 3.3.1 (2016-06-21)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: OS X 10.11.6 (El Capitan)
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] readr_0.2.2 sevenbridges_1.3.6 knitr_1.14
## [4] dplyr_0.5.0 bigrquery_0.3.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.5 rstudioapi_0.6 magrittr_1.5
## [4] BiocGenerics_0.19.2 uuid_0.1-2 docopt_0.4.5
## [7] R6_2.1.2 stringr_1.0.0 liftr_0.4
## [10] httr_1.2.1 tools_3.3.1 parallel_3.3.1
## [13] DBI_0.4-1 htmltools_0.3.5 lazyeval_0.2.0
## [16] openssl_0.9.4 yaml_2.1.13 assertthat_0.1
## [19] digest_0.6.10 tibble_1.0 tidyr_0.5.1
## [22] formatR_1.4 S4Vectors_0.11.13 objectSignals_0.10.2
## [25] rsconnect_0.4.3 curl_1.2 mime_0.5
## [28] evaluate_0.9 rmarkdown_1.0 stringi_1.1.1
## [31] objectProperties_0.6.5 stats4_3.3.1 jsonlite_1.0