#' create new task
#'
#' https://docs.cancergenomicscloud.org/docs/create-a-new-task
#'
#' @param project The project ID in the following format: {project_owner}/{project}.
#' @param app The ID for the app you are querying.
#' @param inputs The list of input parameters for the App.
#' @param batch_input The ID from the inputs for batch run.
#' @param batch_by The type of batch.
#' @param extlist The other requests in a list.
#' @return A response list.
#' @importFrom methods is
#' @importFrom jsonlite toJSON
#' @export
new_task <- function(project, app, inputs, batch_input = NULL, batch_by = NULL,
extlist = NULL){
keys <- .check_auth()
key <- keys[[1]]
api <- keys[[2]]
inputsList <- lapply(inputs, function(x){
if(is(x, "list") & "id" %in% names(x)){
if(!"class" %in% names(x)){
ctype <- "File"
}else{
ctype <- x$class
}
if(length(x$id) > 1 | is(x$id, "list")){
lapply(x$id, function(i)list(class = ctype, path = i))
}else{
list(class = ctype,
path = x$id)
}
}else{
x
}
})
if(!grepl("\\/", app)){
app <- paste(project, app, sep = "/")
}
Inputs <- list(name = paste(sub(".*\\/", "", app), date()),
project = project,
app = app,
inputs = inputsList,
batch_input = batch_input,
batch_by = batch_by)
if(!is.null(extlist)){
Inputs <- c(Inputs, extlist)
}
Inputs <- Inputs[lengths(Inputs)>0]
post_task <- POST(paste0("https://", api, "-api.sbgenomics.com/v2/tasks"),
add_headers("X-SBG-Auth-Token" = key,
"Content-Type" = "application/json"),
body = toJSON(Inputs, auto_unbox = T),
encode = "json", verbose())
responseList(content(post_task))
}
#' Run a task
#'
#' @param task The response list with task ID.
#' @export
run_task <- function(task){
keys <- .check_auth()
key <- keys[[1]]
api <- keys[[2]]
run <- POST(paste0(paste0("https://", api, "-api.sbgenomics.com/v2/tasks/"),
task$id, "/actions/run"),
add_headers("X-SBG-Auth-Token" = key,
"Content-Type" = "application/json"))
responseList(content(run))
}
#' execution_settings
#'
#' @param instance_type The instance to run task.
#' @param max_parallel_instances Max number of parallel instances.
#' @param use_memoization Automatic reuse of precomputed results.
#' @export
exec_setting <- function(instance_type = "c4.2xlarge",
max_parallel_instances = 1,
use_memoization = FALSE){
list(execution_settings =
list(instance_type = instance_type,
max_parallel_instances = max_parallel_instances,
use_memoization = use_memoization)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.