| 1 |
context("Test extract au") |
| 2 |
|
| 3 |
test_that("extract au", { |
| 4 |
suppressWarnings(RNGversion("3.5.0")) |
| 5 |
library(pvclust) |
| 6 |
set.seed(123) |
| 7 |
capture.output(suppressWarnings(dend <- USArrests[1:5, ] %>% pvclust())) |
| 8 |
# plot(dend) |
| 9 |
# pvclust_edges(dend) |
| 10 |
expect_identical(as.character(pvclust_edges(dend)[, 1]), c("Assault", "UrbanPop", "Murder")) |
| 11 |
expect_identical(as.character(pvclust_edges(dend)[, 2]), c("Rape", "1", "2")) |
| 12 |
# expect_identical(round(pvclust_edges(dend)[, 3], digits = 2), c(0.97, 1.00, 1.00)) # there is a stochastic element to the outcome so while it works using test_that it may be causing error with travis-ci checks |
| 13 |
}) |
| 14 |
|
| 15 |
|
| 16 |
test_that("na_locf works", { |
| 17 |
|
| 18 |
# replace NA values with value prior to it |
| 19 |
x <- c(NA,1,2,NA,4,NA,6) |
| 20 |
result <- na_locf(x) |
| 21 |
expect_identical(result, c(0,1,2,2,4,4,6)) |
| 22 |
|
| 23 |
result <- na_locf(x, recursive = F) |
| 24 |
expect_identical(result, c(0,1,2,2,4,4,6)) |
| 25 |
|
| 26 |
}) |
| 27 |
|
| 28 |
|
| 29 |
test_that("text.pvclust works", { |
| 30 |
|
| 31 |
# add same text to dendrogram object as normally comes with pvclust |
| 32 |
suppressWarnings(RNGversion("3.5.0")) |
| 33 |
library(pvclust) |
| 34 |
set.seed(123) |
| 35 |
capture.output(suppressWarnings(dend <- mtcars[1:5, ] %>% pvclust())) |
| 36 |
|
| 37 |
plot(as.dendrogram(dend)) |
| 38 |
expect_no_error( |
| 39 |
text.pvclust(dend) |
| 40 |
) |
| 41 |
|
| 42 |
}) |
| 43 |
|
| 44 |
|
| 45 |
test_that("pvrect2 works", { |
| 46 |
|
| 47 |
# add rect dendrogram object to highlight consistent clusters |
| 48 |
suppressWarnings(RNGversion("3.5.0")) |
| 49 |
library(pvclust) |
| 50 |
set.seed(123) |
| 51 |
capture.output(suppressWarnings(dend <- mtcars[1:5, ] %>% pvclust())) |
| 52 |
|
| 53 |
plot(as.dendrogram(dend)) |
| 54 |
expect_no_error( |
| 55 |
pvrect2(dend, type = "geq") |
| 56 |
) |
| 57 |
expect_no_error( |
| 58 |
pvrect2(dend, type = "leq") |
| 59 |
) |
| 60 |
expect_no_error( |
| 61 |
pvrect2(dend, type = "gt") |
| 62 |
) |
| 63 |
expect_no_error( |
| 64 |
pvrect2(dend, type = "lt") |
| 65 |
) |
| 66 |
expect_error( |
| 67 |
pvrect2(dend, type = NA) |
| 68 |
) |
| 69 |
}) |
| 70 |
|
| 71 |
|
| 72 |
test_that("pvclust_show_signif works", { |
| 73 |
|
| 74 |
# bold branches to highlight consistent clusters |
| 75 |
suppressWarnings(RNGversion("3.5.0")) |
| 76 |
library(pvclust) |
| 77 |
data(lung) # 916 genes for 73 subjects |
| 78 |
set.seed(13134) |
| 79 |
capture.output(result <- pvclust(lung[, 1:20], method.dist = "cor", method.hclust = "average", nboot = 100)) |
| 80 |
dend <- as.dendrogram(result) |
| 81 |
|
| 82 |
expect_no_error( |
| 83 |
pvclust_show_signif(dend, result) %>% plot() |
| 84 |
) |
| 85 |
|
| 86 |
}) |
| 87 |
|
| 88 |
|
| 89 |
test_that("pvclust_show_signif_gradient works", { |
| 90 |
|
| 91 |
# color branches to highlight consistent clusters |
| 92 |
suppressWarnings(RNGversion("3.5.0")) |
| 93 |
library(pvclust) |
| 94 |
data(lung) # 916 genes for 73 subjects |
| 95 |
set.seed(13134) |
| 96 |
capture.output(result <- pvclust(lung[, 1:20], method.dist = "cor", method.hclust = "average", nboot = 100)) |
| 97 |
dend <- as.dendrogram(result) |
| 98 |
|
| 99 |
expect_no_error( |
| 100 |
pvclust_show_signif_gradient(dend, result) %>% plot() |
| 101 |
) |
| 102 |
|
| 103 |
}) |
| 104 |
|
| 105 |
|
| 106 |
test_that("strwidth2 works", { |
| 107 |
|
| 108 |
# test that adjusted string widths are numeric |
| 109 |
suppressWarnings(RNGversion("3.5.0")) |
| 110 |
library(pvclust) |
| 111 |
set.seed(123) |
| 112 |
capture.output(suppressWarnings(dend <- mtcars[1:5, ] %>% pvclust())) |
| 113 |
|
| 114 |
expect_true( |
| 115 |
is.numeric(strwidth2(dend)) |
| 116 |
) |
| 117 |
|
| 118 |
}) |
| 119 |
|
| 120 |
|
| 121 |
test_that("as.hclust.pvclust works", { |
| 122 |
|
| 123 |
library(pvclust) |
| 124 |
set.seed(123) |
| 125 |
capture.output(suppressWarnings(dend <- mtcars[1:5, ] %>% pvclust())) |
| 126 |
result <- as.hclust.pvclust(dend) |
| 127 |
|
| 128 |
# should convert pvclust to hclust object |
| 129 |
expect_identical( |
| 130 |
attributes(result)$class, |
| 131 |
"hclust" |
| 132 |
) |
| 133 |
|
| 134 |
}) |
| 135 |
|
| 136 |
|
| 137 |
test_that("as.dendrogram.pvclust works", { |
| 138 |
|
| 139 |
library(pvclust) |
| 140 |
set.seed(123) |
| 141 |
capture.output(suppressWarnings(dend <- mtcars[1:5, ] %>% pvclust())) |
| 142 |
result <- as.dendrogram.pvclust(dend) |
| 143 |
|
| 144 |
# should convert pvclust to hclust object |
| 145 |
expect_identical( |
| 146 |
attributes(result)$class, |
| 147 |
"dendrogram" |
| 148 |
) |
| 149 |
|
| 150 |
}) |