Switch to unified view

a b/tests/testthat/test-full-tests.R
1
# This extends tests in test-basic-workflow.R
2
# Skip these tests on CRAN
3
skip_on_cran()
4
5
xe <- XenaGenerate(subset = grepl("BRCA", XenaCohorts))
6
xe2 <- XenaHub(hostName = "tcgaHub")
7
xe3 <- XenaHub(
8
  hosts = "https://tcga.xenahubs.net",
9
  cohorts = "TCGA Breast Cancer (BRCA)",
10
  datasets = "TCGA.BRCA.sampleMap/HiSeqV2"
11
)
12
13
14
all_hosts <- c(
15
    "https://ucscpublic.xenahubs.net",
16
    "https://tcga.xenahubs.net",
17
    "https://gdc.xenahubs.net",
18
    "https://gdcV18.xenahubs.net",
19
    "https://icgc.xenahubs.net",
20
    "https://toil.xenahubs.net",
21
    "https://pancanatlas.xenahubs.net",
22
    "https://xena.treehouse.gi.ucsc.edu:443",
23
    "https://pcawg.xenahubs.net",
24
    "https://atacseq.xenahubs.net",
25
    "https://singlecellnew.xenahubs.net",
26
    "https://kidsfirst.xenahubs.net",
27
    "https://tdi.xenahubs.net"
28
)
29
30
31
# XenaHub-class.R ---------------------------------------------------------
32
33
test_that("show method for XenaHub object works", {
34
  expect_output(show(xe), "class: XenaHub")
35
})
36
37
test_that("fun xena_default_hosts works", {
38
  expect_identical(xena_default_hosts(), all_hosts)
39
})
40
41
test_that("fun XenaHub works", {
42
  expect_output(show(xe2), "class: XenaHub")
43
  expect_error(XenaHub(hostName = "xxx"))
44
  expect_output(show(xe3), "class: XenaHub")
45
})
46
47
test_that("fun .collapse_list works", {
48
  expect_identical(.collapse_list(c("a", "b")), "a,b")
49
})
50
51
52
# api-higher --------------------------------------------------------------
53
54
test_that("funs to get hosts, cohorts, datasets and samples work", {
55
  expect_identical("https://tcga.xenahubs.net", hosts(xe3))
56
  expect_identical("TCGA Breast Cancer (BRCA)", cohorts(xe3))
57
  expect_identical("TCGA.BRCA.sampleMap/HiSeqV2", datasets(xe3))
58
  samples <- samples(xe3)[[1]]
59
  expect_true("TCGA-GI-A2C8-01" %in% samples)
60
})
61
62
63
# Fetch -------------------------------------------------------------------
64
65
host <- "https://toil.xenahubs.net"
66
dataset <- "tcga_RSEM_gene_tpm"
67
samples <- c("TCGA-02-0047-01", "TCGA-02-0055-01", "TCGA-02-2483-01", "TCGA-02-2485-01")
68
probes <- c("ENSG00000282740.1", "ENSG00000000005.5", "ENSG00000000419.12")
69
genes <- c("TP53", "RB1", "PIK3CA")
70
71
72
fetch()
73
# Fetch samples
74
fetch_dataset_samples(host, dataset, 2)
75
# Fetch identifiers
76
tryCatch({
77
  fetch_dataset_identifiers(host, dataset)
78
}, error = function(e) {
79
  if (grepl("500", e$message)) {
80
    message("Bad network, skipping check")
81
  } else {
82
    stop(e$message)
83
  }
84
})
85
86
87
# Fetch expression value by probes
88
tryCatch({
89
  fetch_dense_values(host, dataset, probes, samples, check = FALSE)
90
}, error = function(e) {
91
  if (grepl("500", e$message)) {
92
    message("Bad network, skipping check")
93
  } else {
94
    stop(e$message)
95
  }
96
})
97
98
tryCatch({
99
  fetch_dense_values(host, dataset, probes, samples[1], check = TRUE)
100
}, error = function(e) {
101
  if (grepl("500", e$message)) {
102
    message("Bad network, skipping check")
103
  } else {
104
    stop(e$message)
105
  }
106
})
107
108
tryCatch({
109
  fetch_dense_values(host, dataset, probes[1], samples[1], check = TRUE)
110
}, error = function(e) {
111
  if (grepl("500", e$message)) {
112
    message("Bad network, skipping check")
113
  } else {
114
    stop(e$message)
115
  }
116
})
117
118
tryCatch({
119
  fetch_dense_values(host, dataset, probes[1], samples[1], check = TRUE)
120
}, error = function(e) {
121
  if (grepl("500", e$message)) {
122
    message("Bad network, skipping check")
123
  } else {
124
    stop(e$message)
125
  }
126
})
127
128
tryCatch({
129
  expect_error(fetch_dense_values(host, dataset, probes[1], 33, check = TRUE))
130
}, error = function(e) {
131
  if (grepl("500", e$message)) {
132
    message("Bad network, skipping check")
133
  } else {
134
    stop(e$message)
135
  }
136
})
137
138
tryCatch({
139
  fetch_dense_values(host, dataset, c(probes[1], "xxx"), c(samples[1], "xxx"), check = TRUE)
140
}, error = function(e) {
141
  if (grepl("500", e$message)) {
142
    message("Bad network, skipping check")
143
  } else {
144
    stop(e$message)
145
  }
146
})
147
148
# The following two are two time consuming
149
# fetch_dense_values(host, dataset, probes[1], check = TRUE)
150
# fetch_dense_values(host, dataset, samples = samples[1], check = TRUE)
151
152
# Fetch expression value by gene symbol (if the dataset has probeMap)
153
tryCatch({
154
  fetch_dense_values(host, dataset, genes, samples, check = TRUE, use_probeMap = TRUE)
155
}, error = function(e) {
156
  if (grepl("500", e$message)) {
157
    message("Bad network, skipping check")
158
  } else {
159
    stop(e$message)
160
  }
161
})
162
163
# Workflow ----------------------------------------------------------------
164
expect_warning(XenaFilter(xe))
165
expect_warning(XenaFilter(xe2, filterCohorts = "TCGA Breast Cancer (BRCA)"))
166
XenaQueryProbeMap(xe3)
167
168
# clean all
169
rm(list = ls())