Diff of /tests/testthat/test-MRE.R [000000] .. [28e211]

Switch to unified view

a b/tests/testthat/test-MRE.R
1
# ---------------------------------------------------------------------------- #
2
#                              Data pre-processing                             #
3
# ---------------------------------------------------------------------------- #
4
5
context("Data loading and pre-processing")
6
7
sc <- DISCBIO(valuesG1msTest) # Reduced dataset used for testing
8
9
test_that("Loading datasets generate the expected output", {
10
  expect_equal(dim(valuesG1msTest), c(800, 15))
11
})
12
13
test_that("Data signature changes", {
14
  expect_equal(class(sc)[1], "DISCBIO")
15
  expect_equal(attr(class(sc), "package"), "DIscBIO")
16
})
17
18
# This function will be used only if the dataset has ERCC
19
sc <- NoiseFiltering(sc, plot = FALSE, export = FALSE, quiet = TRUE)
20
21
test_that("Noise filtering is added", {
22
  expect_equal(length(sc@noiseF), 163)
23
})
24
25
# In this case this function is used to normalize the reads
26
sc <- Normalizedata(
27
  sc,
28
  mintotal = 1000, minexpr = 0, minnumber = 0, maxexpr = Inf,
29
  downsample = FALSE, dsn = 1, rseed = 17000
30
)
31
32
test_that("Data is normalized", {
33
  expect_equal(class(sc@fdata), "data.frame")
34
  expect_output(str(sc@fdata), "708 obs. of  15 variables")
35
})
36
37
# This function can be used for:
38
# 1 - filtering and normalizing the dataset that has no ERCC.
39
# 2 - to normalize and filter genes and cells after the noise filtering.
40
sc <- FinalPreprocessing(
41
  sc,
42
  GeneFlitering = "NoiseF", export = FALSE, quiet = TRUE
43
)
44
45
test_that("Data is normalized", {
46
  expect_equal(dim(sc@fdata), c(163, 15))
47
})
48
49
# ---------------------------------------------------------------------------- #
50
#                              K-means clustering                              #
51
# ---------------------------------------------------------------------------- #
52
53
context("K-means clustering")
54
55
sc <- Clustexp(
56
  sc,
57
  clustnr = 2, cln = 2, bootnr = 10, quiet = TRUE, rseed = 17000
58
)
59
sc <- comptSNE(sc, rseed = 15555, quiet = TRUE, max_iter = 1, epoch = 10)
60
61
test_that("tSNE is computed", {
62
  expect_equal(class(sc@tsne), "data.frame")
63
  expect_output(str(sc@tsne), "15 obs. of  2 variables")
64
})
65
66
test_that("Cluster plots output is as expexted", {
67
  expect_equivalent(
68
    object = Jaccard(sc, Clustering = "K-means", K = 2, plot = FALSE, R = 5),
69
    expected = c(.683, .624),
70
    tolerance = .01
71
  )
72
  expect_equal(
73
    object = clustheatmap(sc, hmethod = "single", plot = FALSE),
74
    expected = c(1, 2)
75
  )
76
})
77
78
# --------------------------------- Outliers --------------------------------- #
79
80
context("Outliers")
81
82
Outliers <- FindOutliers(
83
  sc,
84
  K = 2, outminc = 5, outlg = 2, probthr = .5 * 1e-3, thr = 2^(-1:-40),
85
  outdistquant = .75, plot = FALSE, quiet = TRUE
86
)
87
Order <- pseudoTimeOrdering(sc, quiet = TRUE, export = FALSE)
88
89
test_that("Outliers are the expected", {
90
  expect_equivalent(Outliers, c(3, 10, 13))
91
  expect_equivalent(
92
    object = Order@kordering,
93
    expected = c(
94
      5, 6, 13, 2, 3, 1, 4, 7, 12, 9, 15, 8, 10, 11, 14
95
    )
96
  )
97
})