/
XenaBrowse.R
83 lines (79 loc) · 2.38 KB
/
XenaBrowse.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
#' View Info of Dataset or Cohort at UCSC Xena Website Using Web browser
#'
#' This will open dataset/cohort link of UCSC Xena
#' in user's default browser.
#' @param x a [XenaHub] object.
#' @param type one of "dataset" and "cohort".
#' @param multiple if `TRUE`, browse multiple links instead of throwing error.
#' @importFrom utils URLencode browseURL
#' @export
#'
#' @examples
#' \donttest{
#' XenaGenerate(subset = XenaHostNames == "tcgaHub") %>%
#' XenaFilter(filterDatasets = "clinical") %>%
#' XenaFilter(filterDatasets = "LUAD") -> to_browse
#' }
XenaBrowse <- function(x, type = c("dataset", "cohort"), multiple = FALSE) { # nocov start
if (!inherits(x, "XenaHub")) {
stop("Input x must be a XenaHub object.")
}
type <- match.arg(type)
if (type == "dataset") {
all_datasets <- datasets(x)
if (length(all_datasets) != 1) {
if (!multiple) stop("This function limite 1 dataset to browse.\n Set multiple to TRUE if you want to browse multiple links.")
for (i in all_datasets) {
xe_tmp <- XenaFilter(x,
filterDatasets = i,
ignore.case = FALSE, fixed = TRUE
)
y <- utils::URLencode(
paste0(
"https://xenabrowser.net/datapages/?",
"dataset=", datasets(xe_tmp),
"&host=", hosts(xe_tmp)
)
)
utils::browseURL(y)
}
} else {
y <- utils::URLencode(
paste0(
"https://xenabrowser.net/datapages/?",
"dataset=", datasets(x),
"&host=", hosts(x)
)
)
utils::browseURL(y)
}
} else {
all_cohorts <- cohorts(x)
if (length(all_cohorts) != 1) {
if (!multiple) stop("This function limite 1 cohort to browse. \n Set multiple to TRUE if you want to browse multiple links.")
for (i in all_cohorts) {
xe_tmp <- XenaFilter(x,
filterCohorts = i,
ignore.case = FALSE, fixed = TRUE
)
y <- utils::URLencode(
paste0(
"https://xenabrowser.net/datapages/?",
"cohort=", cohorts(xe_tmp)
)
)
utils::browseURL(y)
}
} else {
y <- utils::URLencode(
paste0(
"https://xenabrowser.net/datapages/?",
"cohort=", cohorts(x)
)
)
utils::browseURL(y)
}
}
invisible(NULL)
} # nocov end
utils::globalVariables(c("XenaDatasets", "XenaHosts", "ProbeMap"))