File: test-rename_nmf_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 (77 lines) | stat: -rw-r--r-- 3,304 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
context("test-rename_nmf_signatures")


# Load NMF data
nmf_res <- readRDS(system.file("states/nmf_res_data.rds",
  package = "MutationalPatterns"
))

# Load signatures
signatures <- get_known_signatures()

# Run function
output <- rename_nmf_signatures(nmf_res, signatures)

# Run without a suffix
output_suffix <- rename_nmf_signatures(nmf_res, signatures, suffix = "")

# Change how similar the signatures have to be, before they are considered similar.
output_strict <- rename_nmf_signatures(nmf_res, signatures, cutoff = 0.95)

# Change the base_name of the signatures that end up with a letter name.
output_basename <- rename_nmf_signatures(nmf_res, signatures, cutoff = 0.95, base_name = "Signature_")

# Tests that nmf_res is still nmf_res
test_that("Outputs a list", {
  expect_true(inherits(output, c("list")))
  expect_true(inherits(output_suffix, c("list")))
  expect_true(inherits(output_strict, c("list")))
  expect_true(inherits(output_basename, c("list")))
})

test_that("Output contains signatures, contribution and reconstructed", {
  expect_identical(names(output), c("signatures", "contribution", "reconstructed"))
  expect_identical(names(output_suffix), c("signatures", "contribution", "reconstructed"))
  expect_identical(names(output_strict), c("signatures", "contribution", "reconstructed"))
  expect_identical(names(output_basename), 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_suffix$signatures, "matrix"))
  expect_true(inherits(output_suffix$contribution, "matrix"))
  expect_true(inherits(output_suffix$reconstructed, "matrix"))
  expect_true(inherits(output_strict$signatures, "matrix"))
  expect_true(inherits(output_strict$contribution, "matrix"))
  expect_true(inherits(output_strict$reconstructed, "matrix"))
  expect_true(inherits(output_basename$signatures, "matrix"))
  expect_true(inherits(output_basename$contribution, "matrix"))
  expect_true(inherits(output_basename$reconstructed, "matrix"))
})

# Test that names are correctly changed
test_that("New signature names are correct", {
  expect_equal(colnames(output$signatures), c("SBS5-like", "SBS1-like"))
  expect_equal(rownames(output$contribution), c("SBS5-like", "SBS1-like"))
  expect_equal(colnames(output_suffix$signatures), c("SBS5", "SBS1"))
  expect_equal(rownames(output_suffix$contribution), c("SBS5", "SBS1"))
  expect_equal(colnames(output_strict$signatures), c("SBSA", "SBSB"))
  expect_equal(rownames(output_strict$contribution), c("SBSA", "SBSB"))
  expect_equal(colnames(output_basename$signatures), c("Signature_A", "Signature_B"))
  expect_equal(rownames(output_basename$contribution), c("Signature_A", "Signature_B"))
})


# Test that an error is given when multiple signatures are matched to the same reference.
nmf_res2 <- nmf_res
nmf_res2$signatures[, 1] <- nmf_res2$signatures[, 2]
test_that("An error is given when multiple sigs are matched to the same ref sig", {
  expect_error(
    {
      rename_nmf_signatures(nmf_res2, signatures)
    },
    "You have multiple NMF signatures that are linked to the same existing signature"
  )
})