[1c0e03]: / tests / testthat / test-preprocess.R

Download this file

82 lines (65 with data), 2.9 kB

 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
context("preprocess")
test_that("Check preprocessing", {
#testthat::skip_if_not_installed("tensorflow")
testthat::skip_if_not(reticulate::py_module_available("tensorflow"))
z <- seq_encoding_lm(sequence = c(1,0,5,1,3,4,3,1,4,1,2),
maxlen = 5,
vocabulary = c("a", "c", "g", "t"),
start_ind = c(1,3),
ambiguous_nuc = "equal",
target_len = 1,
output_format = "target_right")
x <- z[[1]]
y <- z[[2]]
expect_equivalent(x[1,1,], c(1,0,0,0))
expect_equivalent(x[1,2,], c(0,0,0,0))
expect_equivalent(x[1,3,], rep(0.25, 4))
expect_equivalent(x[1,4,], c(1,0,0,0))
expect_equivalent(x[1,5,], c(0,0,1,0))
expect_equivalent(y[1,], c(0,0,0,1))
expect_equivalent(x[2,1,], rep(0.25, 4))
expect_equivalent(x[2,2,], c(1,0,0,0))
expect_equivalent(x[2,3,], c(0,0,1,0))
expect_equivalent(x[2,4,], c(0,0,0,1))
expect_equivalent(x[2,5,], c(0,0,1,0))
expect_equivalent(y[2,], c(1,0,0,0))
# use character string as input
z <- seq_encoding_lm(sequence = NULL,
maxlen = 5,
vocabulary = c("a", "c", "g", "t"),
start_ind = c(1,3),
ambiguous_nuc = "zero",
target_len = 1,
output_format = "target_right",
char_sequence = "ACTaaTNTNaZ")
x <- z[[1]]
y <- z[[2]]
expect_equivalent(apply(x[1,,], 1, which.max), c(1,2,4,1,1))
expect_equivalent(apply(x[2,,], 1, which.max), c(4,1,1,4,1))
expect_equivalent(y[1,], c(0,0,0,1))
expect_equivalent(y[2,], c(0,0,0,1))
x <- seq_encoding_label(sequence = c(1,0,5,1,3,4,3,1,4,1,2),
maxlen = 5,
vocabulary = c("a", "c", "g", "t"),
start_ind = c(1,3),
ambiguous_nuc = "equal")
expect_equivalent(x[1,1,], c(1,0,0,0))
expect_equivalent(x[1,2,], c(0,0,0,0))
expect_equivalent(x[1,3,], rep(0.25, 4))
expect_equivalent(x[1,4,], c(1,0,0,0))
expect_equivalent(x[1,5,], c(0,0,1,0))
expect_equivalent(x[2,1,], rep(0.25, 4))
expect_equivalent(x[2,2,], c(1,0,0,0))
expect_equivalent(x[2,3,], c(0,0,1,0))
expect_equivalent(x[2,4,], c(0,0,0,1))
expect_equivalent(x[2,5,], c(0,0,1,0))
# use character string as input
x <- seq_encoding_label(maxlen = 5,
vocabulary = c("a", "c", "g", "t"),
start_ind = c(1,3),
ambiguous_nuc = "equal",
char_sequence = "ACTaaTNTNaZ")
expect_equivalent(apply(x[1,,], 1, which.max), c(1,2,4,1,1))
expect_equivalent(apply(x[2,,], 1, which.max), c(4,1,1,4,1))
expect_equivalent(x[2,5,], rep(0.25, 4))
})