/
06-tasks.R
189 lines (168 loc) · 6.54 KB
/
06-tasks.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# 6. Tasks
#' Returns the list of all the tasks for a project
#'
#' Returns the list of all the tasks for a project.
#'
#' This function returns general information and status of a task,
#' in case you want to get a details, including the inputs, outputs
#' and parameters set for that task, you will have to use task details
#' resource referencing the \code{task_id} of a task that you want to
#' get information about.
#'
#' @param auth_token auth token
#' @param project_id ID of a project you want to access.
#' @param ... parameters passed to sbgapi function
#'
#' @return parsed list of the returned json
#'
#' @export task_list
#'
#'
#' @examples
#' token = '420b4672ebfc43bab48dc0d18a32fb6f'
#' \donttest{req = task_list(token,
#' '1c1d06d2-5862-48f6-b595-e0099b20937e')}
task_list = function (auth_token = NULL, project_id = NULL, ...) {
if (is.null(project_id)) stop('project_id must be both provided')
req = sbgapi(auth_token = auth_token,
path = paste0('project/', project_id, '/task'),
method = 'GET', ...)
return(status_check(req))
}
#' Runs a task as a part of a project
#'
#' Runs a task as a part of a project.
#'
#' All the details, including the pipeline ID and runtime parameters,
#' are specified via a list. See the example for details.
#'
#' @param auth_token auth token
#' @param project_id ID of a project you want to access.
#' @param task_details A list with the following components:
#' \itemize{
#' \item \code{pipeline_id} - ID of the pipeline you wish to execute
#' \item \code{pipeline_revision} - Revision of the pipeline you wish
#' to execute. If not specified, latest revision is used.
#' \item \code{name} - Name of the task you wish to execute
#' \item \code{description} - Description of the task you wish to execute
#' \item \code{inputs} - Named list containing mappings of pipeline input
#' node ID to file IDs. Note that file IDs always need to be specified as
#' an list, even if empty or with one element.
#' \item \code{parameters} - Named list containing mappings of node IDs
#' to apps specific parameters. Note that parameters are always specified
#' as an list, even if empty or with one element.}
#' @param ... parameters passed to sbgapi function
#'
#' @return parsed list of the returned json
#'
#' @export task_run
#'
#'
#' @examples
#' token = '58aeb140-1970-0130-6386-001f5b34aa78'
#' details = list(
#' 'name' = 'Test 2 of C. Elegans VC',
#' 'description' = 'Testing Caenorhabditis elegans Exome Variant Calling',
#' 'pipeline_id' = '422',
#' 'inputs' = list('309485' = 13645,
#' '317344' = 13646,
#' '318662' = 13645,
#' '699018' = 13647),
#' 'parameters' = list('393463' = list('read_trimming_qual' = 30,
#' 'rg_seq_tech' = 'Illumina'),
#' '677492' = list()))
#'
#' \donttest{req = task_run(token,
#' project_id = '7f7a72d0-da77-4f51-9416-99f14f7316ab',
#' task_details = details)}
task_run = function (auth_token = NULL,
project_id = NULL, task_details = NULL, ...) {
if (is.null(project_id) || is.null(task_details))
stop('project_id and task_details must be both provided')
body = task_details
req = sbgapi(auth_token = auth_token,
path = paste0('project/', project_id, '/task'),
body = body, method = 'POST', ...)
return(status_check(req))
}
#' Returns information about the task
#'
#' Returns information about the task.
#'
#' Each task has a status and status message, containing the more detailed
#' information about the task status, associated with it. This is a list of
#' all values that task status can have:
#' \itemize{
#' \item \code{active} - Task is currently running.
#' \item \code{completed} - Task has finished successfully.
#' \item \code{aborted} - Task was aborted by user.
#' \item \code{failed} - Task has failed to finish due to
#' either bad inputs and/or parameters, or because of the
#' internal infrastructure failures.}
#'
#' @param auth_token auth token
#' @param project_id ID of a project you want to access.
#' @param task_id ID of a task you want to access.
#' @param download.url Logical. Return the download URL or not.
#' @param ... parameters passed to sbgapi function
#'
#' @return parsed list of the returned json
#'
#' @export task_details
#'
#'
#' @examples
#' token = '420b4672ebfc43bab48dc0d18a32fb6f'
#' \donttest{req1 = task_details(token,
#' project_id = '1c1d06d2-5862-48f6-b595-e0099b20937e',
#' task_id = '22237')
#' req2 = task_details(token,
#' project_id = '1c1d06d2-5862-48f6-b595-e0099b20937e',
#' task_id = '22237', download.url = TRUE)}
task_details = function (auth_token = NULL,
project_id = NULL, task_id = NULL,
download.url = FALSE, ...) {
if (is.null(project_id) || is.null(task_id))
stop('project_id and task_id must be both provided')
if (download.url == FALSE) {
req = sbgapi(auth_token = auth_token,
path = paste0('project/', project_id, '/task/', task_id),
method = 'GET', ...)
} else {
req = sbgapi(auth_token = auth_token,
path = paste0('project/', project_id, '/task/', task_id),
query = list('action' = 'download'), method = 'GET', ...)
}
return(status_check(req))
}
#' Performs action on the task
#'
#' Performs action on the task.
#'
#' @param auth_token auth token
#' @param project_id ID of a project you want to access.
#' @param task_id ID of a task you want to access.
#' @param action Character string specifying the action.
#' Currently, only supported action is \code{'abort'}.
#' @param ... parameters passed to sbgapi function
#'
#' @return parsed list of the returned json
#'
#' @export task_action
#'
#'
#' @examples
#' token = '420b4672ebfc43bab48dc0d18a32fb6f'
#' \donttest{req = task_action(token,
#' project_id = '7f7a72d0-da77-4f51-9416-99f14f7316ab',
#' task_id = '5506a44ae4b04a4ab3ae7250',
#' action = 'abort')}
task_action = function (auth_token = NULL, project_id = NULL,
task_id = NULL, action = 'abort', ...) {
if (is.null(project_id) || is.null(task_id))
stop('project_id and task_id must be both provided')
req = sbgapi(auth_token = auth_token,
path = paste0('project/', project_id, '/task/', task_id),
query = list('action' = action), method = 'POST', ...)
return(status_check(req))
}