@@ -116,7 +116,8 @@ XenaFilter = function(x,
116
116
# #' Query URL of Datasets before Downloading
117
117
# #' @author Shixiang Wang <w_shixiang@163.com>
118
118
# #' @param x a [XenaHub] object
119
- # #' @return a `tibble` contains hosts, datasets and url
119
+ # #' @return a `data.frame` contains hosts, datasets and url
120
+ # #' @importFrom dplyr filter select pull rename mutate
120
121
# #' @export
121
122
# #' @examples
122
123
# #' \donttest{
@@ -125,42 +126,54 @@ XenaFilter = function(x,
125
126
# #' xe_query = XenaQuery(xe)
126
127
# #' }
127
128
XenaQuery = function (x ) {
128
- hostsName = hosts( x )
129
+ message( " This will check url status, please be patient. " )
129
130
datasetsName = datasets(x )
131
+ query = UCSCXenaTools :: XenaData %> %
132
+ dplyr :: filter(XenaDatasets %in% datasetsName ) %> %
133
+ dplyr :: rename(hosts = XenaHosts , datasets = XenaDatasets ) %> %
134
+ dplyr :: mutate(url = file.path(hosts , " download" , datasets )) %> %
135
+ dplyr :: mutate(url = ifelse(! sapply(url , httr :: http_error ),
136
+ url , paste0(url , " .gz" ))) %> %
137
+ dplyr :: select(hosts , datasets , url ) %> %
138
+ as.data.frame()
130
139
131
- message(" This will check url status, please be patient." )
132
- if (length(hostsName ) == 1 ) {
133
- urls = file.path(hostsName , " download" , datasetsName )
134
- # if file and file.gz all exist, download file # see issue#2
135
- dlink = ifelse(! sapply(urls , httr :: http_error ),
136
- urls , paste0(urls , " .gz" ))
137
- query = data.frame (
138
- hosts = hostsName ,
139
- datasets = datasetsName ,
140
- url = dlink ,
141
- stringsAsFactors = FALSE
142
- )
143
- } else {
144
- # identify relationship of hosts and datasets
145
- query = data.frame (
146
- hosts = " NA" ,
147
- datasets = datasetsName ,
148
- url = " NA" ,
149
- stringsAsFactors = FALSE
150
- )
151
- for (onehost in hostsName ) {
152
- xe = XenaHub(hosts = onehost )
153
- dataset_list = datasets(xe )
154
- query $ hosts [query $ datasets %in% dataset_list ] = hosts(xe )
155
- }
156
- urls = paste0(query $ hosts , " /download/" , query $ datasets )
157
- # if file and file.gz all exist, download file # see issue#2
158
- query $ url = ifelse(! sapply(urls , httr :: http_error ),
159
- urls , paste0(urls , " .gz" ))
140
+ invisible (query )
141
+ }
160
142
161
- }
143
+ # #' Query ProbeMap URL of Datasets
144
+ # #'
145
+ # #' If dataset has no ProbeMap, it will be ignored.
146
+ # #'
147
+ # #' @author Shixiang Wang <w_shixiang@163.com>
148
+ # #' @param x a [XenaHub] object
149
+ # #' @return a `data.frame` contains hosts, datasets and url
150
+ # #' @importFrom dplyr filter select pull rename mutate
151
+ # #' @export
152
+ # #' @examples
153
+ # #' \donttest{
154
+ # #' xe = XenaGenerate(subset = XenaHostNames == "tcgaHub")
155
+ # #' hosts(xe)
156
+ # #' xe_query = XenaQueryProbeMap(xe)
157
+ # #' }
158
+ XenaQueryProbeMap = function (x ) {
159
+ message(" Check ProbeMap urls of datasets." )
160
+ datasetsName = datasets(x )
161
+ query = UCSCXenaTools :: XenaData %> %
162
+ dplyr :: filter((XenaDatasets %in% datasetsName ) & (! is.na(ProbeMap )))
162
163
163
- invisible (query )
164
+ if (nrow(query ) == 0 ) {
165
+ invisible (data.frame (stringsAsFactors = FALSE ))
166
+ } else {
167
+ query = query %> %
168
+ dplyr :: rename(hosts = XenaHosts , datasets = ProbeMap ) %> %
169
+ dplyr :: mutate(url = file.path(hosts , " download" , datasets )) %> %
170
+ dplyr :: mutate(url = ifelse(! sapply(url , httr :: http_error ),
171
+ url , paste0(url , " .gz" ))) %> %
172
+ dplyr :: select(hosts , datasets , url ) %> %
173
+ as.data.frame()
174
+
175
+ invisible (unique(query ))
176
+ }
164
177
}
165
178
166
179
# #' Download Datasets from UCSC Xena Hubs
@@ -170,6 +183,7 @@ XenaQuery = function(x) {
170
183
# #' @author Shixiang Wang <w_shixiang@163.com>
171
184
# #' @param xquery a tibble object generated by [XenaQuery] function.
172
185
# #' @param destdir specify a location to store download data. Default is system temp directory.
186
+ # #' @param download_probeMap if `TRUE`, also download ProbeMap data, which used for id mapping.
173
187
# #' @param trans_slash logical, default is `FALSE`. If `TRUE`, transform slash '/' in dataset id
174
188
# #' to '__'. This option is for backwards compatibility.
175
189
# #' @param force logical. if `TRUE`, force to download data no matter whether files exist.
@@ -178,6 +192,7 @@ XenaQuery = function(x) {
178
192
# #' @return a `tibble`
179
193
# #' @export
180
194
# #' @importFrom utils download.file
195
+ # #' @importFrom dplyr filter
181
196
# #' @examples
182
197
# #' \donttest{
183
198
# #' xe = XenaGenerate(subset = XenaHostNames == "tcgaHub")
@@ -188,10 +203,19 @@ XenaQuery = function(x) {
188
203
189
204
XenaDownload = function (xquery ,
190
205
destdir = tempdir(),
206
+ download_probeMap = FALSE ,
191
207
trans_slash = FALSE ,
192
208
force = FALSE ,
193
209
... ) {
194
- stopifnot(is.data.frame(xquery ), c(" url" ) %in% names(xquery ))
210
+ stopifnot(is.data.frame(xquery ), c(" url" ) %in% names(xquery ), is.logical(download_probeMap ))
211
+
212
+ if (download_probeMap ) {
213
+ xquery_probe = UCSCXenaTools :: XenaData %> %
214
+ dplyr :: filter(XenaDatasets %in% xquery $ datasets ) %> %
215
+ XenaGenerate() %> %
216
+ XenaQueryProbeMap()
217
+ xquery = rbind(xquery , xquery_probe )
218
+ }
195
219
196
220
if (trans_slash ) {
197
221
xquery $ fileNames = gsub(pattern = " /" ,
@@ -592,3 +616,4 @@ XenaBrowse = function(x, type = c("dataset", "cohort"), multiple=FALSE) {
592
616
invisible (NULL )
593
617
}
594
618
619
+ utils :: globalVariables(c(" XenaDatasets" , " XenaHosts" , " ProbeMap" ))
0 commit comments