File: test-lengthen_mut_matrix.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 (54 lines) | stat: -rw-r--r-- 1,366 bytes parent folder | download | duplicates (3)
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
context("test-lengthen_mut_matrix")

# Read in mut_matrix
input <- readRDS(system.file("states/mut_mat_splitregions.rds",
  package = "MutationalPatterns"
))

# Read in indel
input_indel <- readRDS(system.file("states/blood_indels_counts_split_region.rds",
  package = "MutationalPatterns"
))

## Lengthen the matrix

# Run function
output <- lengthen_mut_matrix(input)
output_indel <- lengthen_mut_matrix(input_indel)



test_that("Output has correct class", {
  expect_true(inherits(output, "matrix"))
  expect_true(inherits(output_indel, "matrix"))
})

nr_regions <- input %>%
  colnames() %>%
  stringr::str_remove(".*\\.") %>%
  unique() %>%
  length()

nr_regions_indel <- input_indel %>%
  colnames() %>%
  stringr::str_remove(".*\\.") %>%
  unique() %>%
  length()

test_that("Output has correct size", {
  expect_equal(dim(output), c(nrow(input) * nr_regions, ncol(input) / nr_regions))
  expect_equal(dim(output_indel), c(nrow(input_indel) * nr_regions_indel, ncol(input_indel) / nr_regions_indel))
})

expected <- readRDS(system.file("states/mut_mat_longregions.rds",
  package = "MutationalPatterns"
))

expected_indel <- readRDS(system.file("states/blood_indels_longmatrix_split_region.rds",
  package = "MutationalPatterns"
))

test_that("Output transforms correctly", {
  expect_equal(output, expected)
  expect_equal(output_indel, expected_indel)
})