Diff of /R/api_higher.R [000000] .. [0bdad5]

Switch to unified view

a b/R/api_higher.R
1
# FUN: higher API functions
2
3
##' Get hosts of XenaHub object
4
##' @param x a [XenaHub] object
5
##' @importFrom methods slot
6
##' @return a character vector contains hosts
7
##' @export
8
##' @examples xe = XenaGenerate(subset = XenaHostNames == "tcgaHub"); hosts(xe)
9
hosts <- function(x) {
10
  unname(slot(x, "hosts"))
11
}
12
##' Get cohorts of XenaHub object
13
##' @param x a [XenaHub] object
14
##' @return a character vector contains cohorts
15
##' @importFrom methods slot
16
##' @export
17
##' @examples xe = XenaGenerate(subset = XenaHostNames == "tcgaHub"); cohorts(xe)
18
cohorts <- function(x) {
19
  slot(x, "cohorts")
20
}
21
##' Get datasets of XenaHub object
22
##' @param x a [XenaHub] object
23
##' @return a character vector contains datasets
24
##' @importFrom methods slot
25
##' @export
26
##' @examples xe = XenaGenerate(subset = XenaHostNames == "tcgaHub"); datasets(xe)
27
datasets <- function(x) {
28
  slot(x, "datasets")
29
}
30
31
##' Get Samples of a XenaHub object according to 'by' and 'how' action arguments
32
##'
33
##' One is often interested in identifying samples or features present in each data set,
34
##' or shared by all data sets, or present in any of several data sets.
35
##' Identifying these samples, including samples in arbitrarily chosen data sets.
36
##' @param x a [XenaHub] object
37
##' @param i default is a empty character, it is used to specify
38
##' the host, cohort or dataset by `by` option otherwise
39
##' info will be automatically extracted by code
40
##' @param by a character specify `by` action
41
##' @param how a character specify `how` action
42
##' @return a list include samples
43
##' @export
44
##' @examples
45
##' \dontrun{
46
##' xe = XenaHub(cohorts = "Cancer Cell Line Encyclopedia (CCLE)")
47
##' # samples in each dataset, first host
48
##' x = samples(xe, by="datasets", how="each")[[1]]
49
##' lengths(x)        # data sets in ccle cohort on first (only) host
50
##' }
51
52
samples <- function(x,
53
                    i = character(),
54
                    by = c("hosts", "cohorts", "datasets"),
55
                    how = c("each", "any", "all")) {
56
  stopifnot(methods::is(x, "XenaHub"), is.character(i))
57
  by <- match.arg(by)
58
  how <- match.arg(how)
59
60
  fun <- switch(
61
    match.arg(by),
62
    hosts = .samples_by_host,
63
    cohorts = .samples_by_cohort,
64
    datasets = .samples_by_dataset
65
  )
66
  fun(x, i, how)
67
}