require(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('temp-batch') app.txfr = p$app_add("txfr", rbx) 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'))
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')
Finally, we run the task.
tsk$run()
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.