File: test-extract_signatures.R

package info (click to toggle)
r-bioc-mutationalpatterns 3.8.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,336 kB
  • sloc: sh: 8; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 2,932 bytes parent folder | download | duplicates (2)
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("test-extract_signatures")

# Load mutation matrix
mut_mat <- readRDS(system.file("states/mut_mat_data.rds",
  package = "MutationalPatterns"
))
mut_mat <- mut_mat[1:10,]

# extract signatures
output <- extract_signatures(mut_mat, rank = 2, nrun = 1)

# Check it also works with indels
indel_counts <- readRDS(system.file("states/blood_indel_counts.rds",
  package = "MutationalPatterns"
))
indel_counts <- indel_counts[1:8,]

output_indel <- extract_signatures(indel_counts, rank = 2, nrun = 1)

# Check that the variational bayes method works
output_bayes <- extract_signatures(mut_mat, rank = 2, nrun = 1, nmf_type = "variational_bayes")

# Tests
test_that("Outputs a list", {
  expect_true(inherits(output, c("list")))
  expect_true(inherits(output_indel, c("list")))
  expect_true(inherits(output_bayes, c("list")))
})

test_that("Output contains signatures, contribution and reconstructed", {
  expect_identical(names(output), c("signatures", "contribution", "reconstructed"))
  expect_identical(names(output_indel), c("signatures", "contribution", "reconstructed"))
  expect_identical(names(output_bayes), c("signatures", "contribution", "reconstructed"))
})

test_that("Output elements are matrixes", {
  expect_true(inherits(output$signatures, "matrix"))
  expect_true(inherits(output$contribution, "matrix"))
  expect_true(inherits(output$reconstructed, "matrix"))
  expect_true(inherits(output_indel$signatures, "matrix"))
  expect_true(inherits(output_indel$contribution, "matrix"))
  expect_true(inherits(output_indel$reconstructed, "matrix"))
  expect_true(inherits(output_bayes$signatures, "matrix"))
  expect_true(inherits(output_bayes$contribution, "matrix"))
  expect_true(inherits(output_bayes$reconstructed, "matrix"))
})

test_that("Output elements have correct size", {
  expect_equal(dim(output$signatures), c(10, 2))
  expect_equal(dim(output$contribution), c(2, 9))
  expect_equal(dim(output$reconstructed), c(10, 9))
  expect_equal(dim(output_indel$signatures), c(8, 2))
  expect_equal(dim(output_indel$contribution), c(2, 3))
  expect_equal(dim(output_indel$reconstructed), c(8, 3))
  expect_equal(dim(output_bayes$signatures), c(10, 2))
  expect_equal(dim(output_bayes$contribution), c(2, 9))
  expect_equal(dim(output_bayes$reconstructed), c(10, 9))
})

# Test that an error is given when using a incorrect rank
test_that("An error is given when used with incorrect rank", {
  expect_error(
    {
      extract_signatures(mut_mat, rank = 2.5, nrun = 1)
    },
    "Rank should be a positive integer"
  )
})

# Test that an error is given when using a rank higher than the number of columns in the mut_mat
test_that("An error is given when rank is higher than the number of mut_mat columns", {
  expect_error(
    {
      extract_signatures(mut_mat, rank = 30, nrun = 1)
    },
    paste0(
      "The rank should be smaller than the number of ",
      "samples in the input matrix."
    )
  )
})